cea3d6529dccd1537cc31749dbeeb7cf3d35473c
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.
30 * Implementation 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 #include "mem/cache/tags/sector_blk.hh"
38 #include "base/cprintf.hh"
39 #include "base/logging.hh"
42 SectorSubBlk::setSectorBlock(SectorBlk
* sector_blk
)
44 assert(sector_blk
!= nullptr);
45 _sectorBlk
= sector_blk
;
49 SectorSubBlk::getSectorBlock() const
55 SectorSubBlk::setSectorOffset(const int sector_offset
)
57 _sectorOffset
= sector_offset
;
61 SectorSubBlk::getSectorOffset() const
67 SectorSubBlk::getTag() const
69 return _sectorBlk
->getTag();
73 SectorSubBlk::setValid()
76 _sectorBlk
->validateSubBlk();
80 SectorSubBlk::setSecure()
82 CacheBlk::setSecure();
83 _sectorBlk
->setSecure();
87 SectorSubBlk::invalidate()
89 CacheBlk::invalidate();
90 _sectorBlk
->invalidateSubBlk();
94 SectorSubBlk::insert(const Addr tag
, const bool is_secure
,
95 const int src_master_ID
, const uint32_t task_ID
)
97 // Make sure it is not overwriting another sector
98 panic_if((_sectorBlk
&& _sectorBlk
->isValid()) &&
99 ((_sectorBlk
->getTag() != tag
) ||
100 (_sectorBlk
->isSecure() != is_secure
)),
101 "Overwriting valid sector!");
103 CacheBlk::insert(tag
, is_secure
, src_master_ID
, task_ID
);
106 _sectorBlk
->setTag(tag
);
110 SectorSubBlk::print() const
112 return csprintf("%s sector offset: %#x", CacheBlk::print(),
116 SectorBlk::SectorBlk()
117 : ReplaceableEntry(), _validCounter(0), _tag(MaxAddr
), _secureBit(false)
122 SectorBlk::isValid() const
124 // If any of the blocks in the sector is valid, so is the sector
125 return _validCounter
> 0;
129 SectorBlk::getNumValid() const
131 return _validCounter
;
135 SectorBlk::isSecure() const
137 // If any of the valid blocks in the sector is secure, so is the sector
142 SectorBlk::setTag(const Addr tag
)
148 SectorBlk::getTag() const
154 SectorBlk::validateSubBlk()
160 SectorBlk::invalidateSubBlk()
162 // If all sub-blocks have been invalidated, the sector becomes invalid,
163 // so clear secure bit
164 if (--_validCounter
== 0) {
170 SectorBlk::setSecure()
176 SectorBlk::setPosition(const uint32_t set
, const uint32_t way
)
178 ReplaceableEntry::setPosition(set
, way
);
179 for (auto& blk
: blks
) {
180 blk
->setPosition(set
, way
);