misc: Standardize the way create() constructs SimObjects.
[gem5.git] / src / mem / cache / tags / sector_blk.hh
1 /**
2 * Copyright (c) 2018, 2020 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
29 /** @file
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.
32 */
33
34 #ifndef __MEM_CACHE_TAGS_SECTOR_BLK_HH__
35 #define __MEM_CACHE_TAGS_SECTOR_BLK_HH__
36
37 #include <vector>
38
39 #include "mem/cache/cache_blk.hh"
40 #include "mem/cache/replacement_policies/replaceable_entry.hh"
41
42 class SectorBlk;
43
44 /**
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.
47 */
48 class SectorSubBlk : public CacheBlk
49 {
50 protected:
51 /**
52 * Sector block associated to this block.
53 */
54 SectorBlk* _sectorBlk;
55
56 /**
57 * The offset of this sub-block in the sector.
58 */
59 int _sectorOffset;
60
61 public:
62 SectorSubBlk() : CacheBlk(), _sectorBlk(nullptr), _sectorOffset(0) {}
63 SectorSubBlk(const SectorSubBlk&) = delete;
64 SectorSubBlk& operator=(const SectorSubBlk&) = delete;
65 ~SectorSubBlk() {};
66
67 /**
68 * Set sector block associated to this block.
69 *
70 * @param sector_blk The sector block pointer.
71 */
72 void setSectorBlock(SectorBlk* sector_blk);
73
74 /**
75 * Get sector block associated to this block.
76 *
77 * @return The sector block pointer.
78 */
79 const SectorBlk* getSectorBlock() const;
80
81 /**
82 * Set offset of this sub-block within the sector.
83 *
84 * @param sector_offset The block's offset.
85 */
86 void setSectorOffset(const int sector_offset);
87
88 /**
89 * Get offset of this sub-block within the sector.
90 *
91 * @return sector_offset The block's offset.
92 */
93 int getSectorOffset() const;
94
95 Addr getTag() const override;
96
97 /**
98 * Set valid bit and inform sector block.
99 */
100 void setValid() override;
101
102 void insert(const Addr tag, const bool is_secure) override;
103
104 /**
105 * Invalidate the block and inform sector block.
106 */
107 void invalidate() override;
108
109 /**
110 * Pretty-print sector offset and other CacheBlk information.
111 *
112 * @return string with basic state information
113 */
114 std::string print() const override;
115 };
116
117 /**
118 * A Basic Sector block.
119 * Contains the tag and a list of blocks associated to this sector.
120 */
121 class SectorBlk : public TaggedEntry
122 {
123 private:
124 /**
125 * Counter of the number of valid sub-blocks. The sector is valid if any
126 * of its sub-blocks is valid.
127 */
128 uint8_t _validCounter;
129
130 public:
131 SectorBlk();
132 SectorBlk(const SectorBlk&) = delete;
133 SectorBlk& operator=(const SectorBlk&) = delete;
134 ~SectorBlk() {};
135
136 /** List of blocks associated to this sector. */
137 std::vector<SectorSubBlk*> blks;
138
139 /**
140 * Checks that a sector block is valid.
141 *
142 * @return True if any of the blocks in the sector is valid.
143 */
144 bool isValid() const override;
145
146 /**
147 * Get the number of sub-blocks that have been validated.
148 *
149 * @return The number of valid sub-blocks.
150 */
151 uint8_t getNumValid() const;
152
153 /**
154 * Increase the number of valid sub-blocks.
155 */
156 void validateSubBlk();
157
158 /**
159 * Decrease the number of valid sub-blocks.
160 */
161 void invalidateSubBlk();
162
163 /**
164 * Sets the position of the sub-entries, besides its own.
165 *
166 * @param set The set of this entry and sub-entries.
167 * @param way The way of this entry and sub-entries.
168 */
169 void setPosition(const uint32_t set, const uint32_t way) override;
170 };
171
172 #endif //__MEM_CACHE_TAGS_SECTOR_BLK_HH__