1/** 2 * Copyright (c) 2018 Inria 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Daniel Carvalho 29 */ 30 31/** @file 32 * Definition of a simple sector block class. Each sector consists of a 33 * sequence of cache blocks that may or may not be present in the cache. 34 */ 35 36#ifndef __MEM_CACHE_TAGS_SECTOR_BLK_HH__ 37#define __MEM_CACHE_TAGS_SECTOR_BLK_HH__ 38 39#include <vector> 40 41#include "mem/cache/cache_blk.hh" 42#include "mem/cache/replacement_policies/replaceable_entry.hh" 43 44class SectorBlk; 45 46/** 47 * A sector is composed of sub-blocks, and each sub-block has information 48 * regarding its sector and a pointer to its sector tag. 49 */ 50class SectorSubBlk : public CacheBlk 51{ 52 protected: 53 /** 54 * Sector block associated to this block. 55 */ 56 SectorBlk* _sectorBlk; 57 58 /** 59 * The offset of this sub-block in the sector. 60 */ 61 int _sectorOffset; 62 63 public: 64 SectorSubBlk() : CacheBlk(), _sectorBlk(nullptr), _sectorOffset(0) {} 65 SectorSubBlk(const SectorSubBlk&) = delete; 66 SectorSubBlk& operator=(const SectorSubBlk&) = delete; 67 ~SectorSubBlk() {}; 68 69 /** 70 * Set sector block associated to this block. 71 * 72 * @param sector_blk The sector block pointer. 73 */ 74 void setSectorBlock(SectorBlk* sector_blk); 75 76 /** 77 * Get sector block associated to this block. 78 * 79 * @return The sector block pointer. 80 */ 81 const SectorBlk* getSectorBlock() const; 82 83 /** 84 * Set offset of this sub-block within the sector. 85 * 86 * @param sector_offset The block's offset. 87 */ 88 void setSectorOffset(const int sector_offset); 89 90 /** 91 * Get offset of this sub-block within the sector. 92 * 93 * @return sector_offset The block's offset. 94 */ 95 int getSectorOffset() const; 96 97 /** 98 * Get tag associated to this block. 99 * 100 * @return The tag value. 101 */ 102 Addr getTag() const; 103 104 /** 105 * Set valid bit and inform sector block. 106 */ 107 void setValid() override; 108 109 /** 110 * Set secure bit and inform sector block. 111 */ 112 void setSecure() override; 113 114 /** 115 * Invalidate the block and inform sector block. 116 */ 117 void invalidate() override; 118 119 /** 120 * Set member variables when a block insertion occurs. Resets reference 121 * count to 1 (the insertion counts as a reference), and touch block if 122 * it hadn't been touched previously. Sets the insertion tick to the 123 * current tick. Marks the block valid. 124 * 125 * @param tag Block address tag. 126 * @param is_secure Whether the block is in secure space or not. 127 * @param src_master_ID The source requestor ID. 128 * @param task_ID The new task ID. 129 */ 130 void insert(const Addr tag, const bool is_secure, const int src_master_ID, 131 const uint32_t task_ID) override; 132 133 /** 134 * Pretty-print sector offset and other CacheBlk information. 135 * 136 * @return string with basic state information 137 */ 138 std::string print() const override; 139}; 140 141/** 142 * A Basic Sector block. 143 * Contains the tag and a list of blocks associated to this sector. 144 */ 145class SectorBlk : public ReplaceableEntry 146{ 147 protected: 148 /** 149 * Sector tag value. A sector's tag is the tag of all its sub-blocks. 150 */ 151 Addr _tag; 152 153 /** 154 * Counter of the number of valid sub-blocks. The sector is valid if any 155 * of its sub-blocks is valid. 156 */ 157 uint8_t _validCounter; 158 159 /** 160 * Whether sector blk is in secure-space or not. 161 */ 162 bool _secureBit; 163 164 public: 165 SectorBlk(); 166 SectorBlk(const SectorBlk&) = delete; 167 SectorBlk& operator=(const SectorBlk&) = delete; 168 ~SectorBlk() {}; 169 170 /** List of blocks associated to this sector. */ 171 std::vector<SectorSubBlk*> blks; 172 173 /** 174 * Checks that a sector block is valid. 175 * 176 * @return True if any of the blocks in the sector is valid. 177 */ 178 bool isValid() const; 179 180 /** 181 * Checks that a sector block is secure. A single secure block suffices 182 * to imply that the whole sector is secure, as the insertion proccess 183 * asserts that different secure spaces can't coexist in the same sector. 184 * 185 * @return True if any of the blocks in the sector is secure. 186 */ 187 bool isSecure() const; 188 189 /** 190 * Set tag associated to this block. 191 * 192 * @param The tag value. 193 */ 194 void setTag(const Addr tag); 195 196 /** 197 * Get tag associated to this block. 198 * 199 * @return The tag value. 200 */ 201 Addr getTag() const; 202 203 /** 204 * Increase the number of valid sub-blocks. 205 */ 206 void validateSubBlk(); 207 208 /** 209 * Decrease the number of valid sub-blocks. 210 */ 211 void invalidateSubBlk(); 212 213 /** 214 * Set secure bit. 215 */ 216 void setSecure(); 217 218 /** 219 * Sets the position of the sub-entries, besides its own. 220 * 221 * @param set The set of this entry and sub-entries. 222 * @param way The way of this entry and sub-entries. 223 */ 224 void setPosition(const uint32_t set, const uint32_t way) override; 225}; 226 227#endif //__MEM_CACHE_TAGS_SECTOR_BLK_HH__ 228