2 * Copyright (c) 2018, 2020 Inria
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.
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.
30 * Definition of a simple sector block class. Each sector consists of a
31 * sequence of cache blocks that may or may not be present in the cache.
34 #ifndef __MEM_CACHE_TAGS_SECTOR_BLK_HH__
35 #define __MEM_CACHE_TAGS_SECTOR_BLK_HH__
39 #include "mem/cache/cache_blk.hh"
40 #include "mem/cache/replacement_policies/replaceable_entry.hh"
45 * A sector is composed of sub-blocks, and each sub-block has information
46 * regarding its sector and a pointer to its sector tag.
48 class SectorSubBlk : public CacheBlk
52 * Sector block associated to this block.
54 SectorBlk* _sectorBlk;
57 * The offset of this sub-block in the sector.
62 SectorSubBlk() : CacheBlk(), _sectorBlk(nullptr), _sectorOffset(0) {}
63 SectorSubBlk(const SectorSubBlk&) = delete;
64 SectorSubBlk& operator=(const SectorSubBlk&) = delete;
68 * Set sector block associated to this block.
70 * @param sector_blk The sector block pointer.
72 void setSectorBlock(SectorBlk* sector_blk);
75 * Get sector block associated to this block.
77 * @return The sector block pointer.
79 const SectorBlk* getSectorBlock() const;
82 * Set offset of this sub-block within the sector.
84 * @param sector_offset The block's offset.
86 void setSectorOffset(const int sector_offset);
89 * Get offset of this sub-block within the sector.
91 * @return sector_offset The block's offset.
93 int getSectorOffset() const;
95 Addr getTag() const override;
98 * Set valid bit and inform sector block.
100 void setValid() override;
102 void insert(const Addr tag, const bool is_secure) override;
105 * Invalidate the block and inform sector block.
107 void invalidate() override;
110 * Pretty-print sector offset and other CacheBlk information.
112 * @return string with basic state information
114 std::string print() const override;
118 * A Basic Sector block.
119 * Contains the tag and a list of blocks associated to this sector.
121 class SectorBlk : public TaggedEntry
125 * Counter of the number of valid sub-blocks. The sector is valid if any
126 * of its sub-blocks is valid.
128 uint8_t _validCounter;
132 SectorBlk(const SectorBlk&) = delete;
133 SectorBlk& operator=(const SectorBlk&) = delete;
136 /** List of blocks associated to this sector. */
137 std::vector<SectorSubBlk*> blks;
140 * Checks that a sector block is valid.
142 * @return True if any of the blocks in the sector is valid.
144 bool isValid() const override;
147 * Get the number of sub-blocks that have been validated.
149 * @return The number of valid sub-blocks.
151 uint8_t getNumValid() const;
154 * Increase the number of valid sub-blocks.
156 void validateSubBlk();
159 * Decrease the number of valid sub-blocks.
161 void invalidateSubBlk();
164 * Sets the position of the sub-entries, besides its own.
166 * @param set The set of this entry and sub-entries.
167 * @param way The way of this entry and sub-entries.
169 void setPosition(const uint32_t set, const uint32_t way) override;
172 #endif //__MEM_CACHE_TAGS_SECTOR_BLK_HH__