2 * Copyright (c) 2018 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.
28 * Authors: Daniel Carvalho
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.
36 #ifndef __MEM_CACHE_SECTOR_BLK_HH__
37 #define __MEM_CACHE_SECTOR_BLK_HH__
41 #include "mem/cache/blk.hh"
42 #include "mem/cache/replacement_policies/base.hh"
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.
50 class SectorSubBlk : public CacheBlk
54 * Sector block associated to this block.
56 SectorBlk* _sectorBlk;
59 * The offset of this sub-block in the sector.
64 SectorSubBlk() : CacheBlk(), _sectorBlk(nullptr), _sectorOffset(0) {}
65 SectorSubBlk(const SectorSubBlk&) = delete;
66 SectorSubBlk& operator=(const SectorSubBlk&) = delete;
70 * Set sector block associated to this block.
72 * @param sector_blk The sector block pointer.
74 void setSectorBlock(SectorBlk* sector_blk);
77 * Get sector block associated to this block.
79 * @return The sector block pointer.
81 const SectorBlk* getSectorBlock() const;
84 * Set offset of this sub-block within the sector.
86 * @param sector_offset The block's offset.
88 void setSectorOffset(const int sector_offset);
91 * Get offset of this sub-block within the sector.
93 * @return sector_offset The block's offset.
95 int getSectorOffset() const;
98 * Get tag associated to this block.
100 * @return The tag value.
105 * Set member variables when a block insertion occurs. Resets reference
106 * count to 1 (the insertion counts as a reference), and touch block if
107 * it hadn't been touched previously. Sets the insertion tick to the
108 * current tick. Does not make block valid.
110 * @param tag Block address tag.
111 * @param is_secure Whether the block is in secure space or not.
112 * @param src_master_ID The source requestor ID.
113 * @param task_ID The new task ID.
115 void insert(const Addr tag, const bool is_secure, const int src_master_ID,
116 const uint32_t task_ID) override;
119 * Pretty-print sector offset and other CacheBlk information.
121 * @return string with basic state information
123 std::string print() const override;
127 * A Basic Sector block.
128 * Contains the tag and a list of blocks associated to this sector.
130 class SectorBlk : public ReplaceableEntry
134 * Sector tag value. A sector's tag is the tag of all its sub-blocks.
139 SectorBlk() : ReplaceableEntry(), _tag(MaxAddr) {}
140 SectorBlk(const SectorBlk&) = delete;
141 SectorBlk& operator=(const SectorBlk&) = delete;
144 /** List of blocks associated to this sector. */
145 std::vector<SectorSubBlk*> blks;
148 * Checks that a sector block is valid.
150 * @return True if any of the blocks in the sector is valid.
152 bool isValid() const;
155 * Checks that a sector block is secure. A single secure block suffices
156 * to imply that the whole sector is secure, as the insertion proccess
157 * asserts that different secure spaces can't coexist in the same sector.
159 * @return True if any of the blocks in the sector is secure.
161 bool isSecure() const;
164 * Set tag associated to this block.
166 * @param The tag value.
168 void setTag(const Addr tag);
171 * Get tag associated to this block.
173 * @return The tag value.
178 #endif //__MEM_CACHE_SECTOR_BLK_HH__