113224Sodanrc@yahoo.com.br/** 213224Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria 313224Sodanrc@yahoo.com.br * All rights reserved. 413224Sodanrc@yahoo.com.br * 513224Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 613224Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 713224Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 813224Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 913224Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 1013224Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 1113224Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 1213224Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 1313224Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 1413224Sodanrc@yahoo.com.br * this software without specific prior written permission. 1513224Sodanrc@yahoo.com.br * 1613224Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1713224Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1813224Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1913224Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2013224Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2113224Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2213224Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2313224Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2413224Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2513224Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2613224Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2713224Sodanrc@yahoo.com.br * 2813224Sodanrc@yahoo.com.br * Authors: Daniel Carvalho 2913224Sodanrc@yahoo.com.br */ 3013224Sodanrc@yahoo.com.br 3113224Sodanrc@yahoo.com.br/** @file 3213224Sodanrc@yahoo.com.br * Definition of a simple sector block class. Each sector consists of a 3313224Sodanrc@yahoo.com.br * sequence of cache blocks that may or may not be present in the cache. 3413224Sodanrc@yahoo.com.br */ 3513224Sodanrc@yahoo.com.br 3613224Sodanrc@yahoo.com.br#ifndef __MEM_CACHE_TAGS_SECTOR_BLK_HH__ 3713224Sodanrc@yahoo.com.br#define __MEM_CACHE_TAGS_SECTOR_BLK_HH__ 3813224Sodanrc@yahoo.com.br 3913224Sodanrc@yahoo.com.br#include <vector> 4013224Sodanrc@yahoo.com.br 4113224Sodanrc@yahoo.com.br#include "mem/cache/cache_blk.hh" 4213225Sodanrc@yahoo.com.br#include "mem/cache/replacement_policies/replaceable_entry.hh" 4313224Sodanrc@yahoo.com.br 4413224Sodanrc@yahoo.com.brclass SectorBlk; 4513224Sodanrc@yahoo.com.br 4613224Sodanrc@yahoo.com.br/** 4713224Sodanrc@yahoo.com.br * A sector is composed of sub-blocks, and each sub-block has information 4813224Sodanrc@yahoo.com.br * regarding its sector and a pointer to its sector tag. 4913224Sodanrc@yahoo.com.br */ 5013224Sodanrc@yahoo.com.brclass SectorSubBlk : public CacheBlk 5113224Sodanrc@yahoo.com.br{ 5213938Sodanrc@yahoo.com.br protected: 5313224Sodanrc@yahoo.com.br /** 5413224Sodanrc@yahoo.com.br * Sector block associated to this block. 5513224Sodanrc@yahoo.com.br */ 5613224Sodanrc@yahoo.com.br SectorBlk* _sectorBlk; 5713224Sodanrc@yahoo.com.br 5813224Sodanrc@yahoo.com.br /** 5913224Sodanrc@yahoo.com.br * The offset of this sub-block in the sector. 6013224Sodanrc@yahoo.com.br */ 6113224Sodanrc@yahoo.com.br int _sectorOffset; 6213224Sodanrc@yahoo.com.br 6313224Sodanrc@yahoo.com.br public: 6413224Sodanrc@yahoo.com.br SectorSubBlk() : CacheBlk(), _sectorBlk(nullptr), _sectorOffset(0) {} 6513224Sodanrc@yahoo.com.br SectorSubBlk(const SectorSubBlk&) = delete; 6613224Sodanrc@yahoo.com.br SectorSubBlk& operator=(const SectorSubBlk&) = delete; 6713224Sodanrc@yahoo.com.br ~SectorSubBlk() {}; 6813224Sodanrc@yahoo.com.br 6913224Sodanrc@yahoo.com.br /** 7013224Sodanrc@yahoo.com.br * Set sector block associated to this block. 7113224Sodanrc@yahoo.com.br * 7213224Sodanrc@yahoo.com.br * @param sector_blk The sector block pointer. 7313224Sodanrc@yahoo.com.br */ 7413224Sodanrc@yahoo.com.br void setSectorBlock(SectorBlk* sector_blk); 7513224Sodanrc@yahoo.com.br 7613224Sodanrc@yahoo.com.br /** 7713224Sodanrc@yahoo.com.br * Get sector block associated to this block. 7813224Sodanrc@yahoo.com.br * 7913224Sodanrc@yahoo.com.br * @return The sector block pointer. 8013224Sodanrc@yahoo.com.br */ 8113224Sodanrc@yahoo.com.br const SectorBlk* getSectorBlock() const; 8213224Sodanrc@yahoo.com.br 8313224Sodanrc@yahoo.com.br /** 8413224Sodanrc@yahoo.com.br * Set offset of this sub-block within the sector. 8513224Sodanrc@yahoo.com.br * 8613224Sodanrc@yahoo.com.br * @param sector_offset The block's offset. 8713224Sodanrc@yahoo.com.br */ 8813224Sodanrc@yahoo.com.br void setSectorOffset(const int sector_offset); 8913224Sodanrc@yahoo.com.br 9013224Sodanrc@yahoo.com.br /** 9113224Sodanrc@yahoo.com.br * Get offset of this sub-block within the sector. 9213224Sodanrc@yahoo.com.br * 9313224Sodanrc@yahoo.com.br * @return sector_offset The block's offset. 9413224Sodanrc@yahoo.com.br */ 9513224Sodanrc@yahoo.com.br int getSectorOffset() const; 9613224Sodanrc@yahoo.com.br 9713224Sodanrc@yahoo.com.br /** 9813224Sodanrc@yahoo.com.br * Get tag associated to this block. 9913224Sodanrc@yahoo.com.br * 10013224Sodanrc@yahoo.com.br * @return The tag value. 10113224Sodanrc@yahoo.com.br */ 10213224Sodanrc@yahoo.com.br Addr getTag() const; 10313224Sodanrc@yahoo.com.br 10413224Sodanrc@yahoo.com.br /** 10513473Sodanrc@yahoo.com.br * Set valid bit and inform sector block. 10613473Sodanrc@yahoo.com.br */ 10713473Sodanrc@yahoo.com.br void setValid() override; 10813473Sodanrc@yahoo.com.br 10913473Sodanrc@yahoo.com.br /** 11013473Sodanrc@yahoo.com.br * Set secure bit and inform sector block. 11113473Sodanrc@yahoo.com.br */ 11213473Sodanrc@yahoo.com.br void setSecure() override; 11313473Sodanrc@yahoo.com.br 11413473Sodanrc@yahoo.com.br /** 11513473Sodanrc@yahoo.com.br * Invalidate the block and inform sector block. 11613473Sodanrc@yahoo.com.br */ 11713473Sodanrc@yahoo.com.br void invalidate() override; 11813473Sodanrc@yahoo.com.br 11913473Sodanrc@yahoo.com.br /** 12013224Sodanrc@yahoo.com.br * Set member variables when a block insertion occurs. Resets reference 12113224Sodanrc@yahoo.com.br * count to 1 (the insertion counts as a reference), and touch block if 12213224Sodanrc@yahoo.com.br * it hadn't been touched previously. Sets the insertion tick to the 12313445Sodanrc@yahoo.com.br * current tick. Marks the block valid. 12413224Sodanrc@yahoo.com.br * 12513224Sodanrc@yahoo.com.br * @param tag Block address tag. 12613224Sodanrc@yahoo.com.br * @param is_secure Whether the block is in secure space or not. 12713224Sodanrc@yahoo.com.br * @param src_master_ID The source requestor ID. 12813224Sodanrc@yahoo.com.br * @param task_ID The new task ID. 12913224Sodanrc@yahoo.com.br */ 13013224Sodanrc@yahoo.com.br void insert(const Addr tag, const bool is_secure, const int src_master_ID, 13113224Sodanrc@yahoo.com.br const uint32_t task_ID) override; 13213224Sodanrc@yahoo.com.br 13313224Sodanrc@yahoo.com.br /** 13413224Sodanrc@yahoo.com.br * Pretty-print sector offset and other CacheBlk information. 13513224Sodanrc@yahoo.com.br * 13613224Sodanrc@yahoo.com.br * @return string with basic state information 13713224Sodanrc@yahoo.com.br */ 13813224Sodanrc@yahoo.com.br std::string print() const override; 13913224Sodanrc@yahoo.com.br}; 14013224Sodanrc@yahoo.com.br 14113224Sodanrc@yahoo.com.br/** 14213224Sodanrc@yahoo.com.br * A Basic Sector block. 14313224Sodanrc@yahoo.com.br * Contains the tag and a list of blocks associated to this sector. 14413224Sodanrc@yahoo.com.br */ 14513224Sodanrc@yahoo.com.brclass SectorBlk : public ReplaceableEntry 14613224Sodanrc@yahoo.com.br{ 14713938Sodanrc@yahoo.com.br protected: 14813224Sodanrc@yahoo.com.br /** 14913224Sodanrc@yahoo.com.br * Sector tag value. A sector's tag is the tag of all its sub-blocks. 15013224Sodanrc@yahoo.com.br */ 15113224Sodanrc@yahoo.com.br Addr _tag; 15213224Sodanrc@yahoo.com.br 15313473Sodanrc@yahoo.com.br /** 15413473Sodanrc@yahoo.com.br * Counter of the number of valid sub-blocks. The sector is valid if any 15513473Sodanrc@yahoo.com.br * of its sub-blocks is valid. 15613473Sodanrc@yahoo.com.br */ 15713473Sodanrc@yahoo.com.br uint8_t _validCounter; 15813473Sodanrc@yahoo.com.br 15913473Sodanrc@yahoo.com.br /** 16013473Sodanrc@yahoo.com.br * Whether sector blk is in secure-space or not. 16113473Sodanrc@yahoo.com.br */ 16213473Sodanrc@yahoo.com.br bool _secureBit; 16313473Sodanrc@yahoo.com.br 16413224Sodanrc@yahoo.com.br public: 16513473Sodanrc@yahoo.com.br SectorBlk(); 16613224Sodanrc@yahoo.com.br SectorBlk(const SectorBlk&) = delete; 16713224Sodanrc@yahoo.com.br SectorBlk& operator=(const SectorBlk&) = delete; 16813224Sodanrc@yahoo.com.br ~SectorBlk() {}; 16913224Sodanrc@yahoo.com.br 17013224Sodanrc@yahoo.com.br /** List of blocks associated to this sector. */ 17113224Sodanrc@yahoo.com.br std::vector<SectorSubBlk*> blks; 17213224Sodanrc@yahoo.com.br 17313224Sodanrc@yahoo.com.br /** 17413224Sodanrc@yahoo.com.br * Checks that a sector block is valid. 17513224Sodanrc@yahoo.com.br * 17613224Sodanrc@yahoo.com.br * @return True if any of the blocks in the sector is valid. 17713224Sodanrc@yahoo.com.br */ 17813224Sodanrc@yahoo.com.br bool isValid() const; 17913224Sodanrc@yahoo.com.br 18013224Sodanrc@yahoo.com.br /** 18113224Sodanrc@yahoo.com.br * Checks that a sector block is secure. A single secure block suffices 18213224Sodanrc@yahoo.com.br * to imply that the whole sector is secure, as the insertion proccess 18313224Sodanrc@yahoo.com.br * asserts that different secure spaces can't coexist in the same sector. 18413224Sodanrc@yahoo.com.br * 18513224Sodanrc@yahoo.com.br * @return True if any of the blocks in the sector is secure. 18613224Sodanrc@yahoo.com.br */ 18713224Sodanrc@yahoo.com.br bool isSecure() const; 18813224Sodanrc@yahoo.com.br 18913224Sodanrc@yahoo.com.br /** 19013224Sodanrc@yahoo.com.br * Set tag associated to this block. 19113224Sodanrc@yahoo.com.br * 19213224Sodanrc@yahoo.com.br * @param The tag value. 19313224Sodanrc@yahoo.com.br */ 19413224Sodanrc@yahoo.com.br void setTag(const Addr tag); 19513224Sodanrc@yahoo.com.br 19613224Sodanrc@yahoo.com.br /** 19713224Sodanrc@yahoo.com.br * Get tag associated to this block. 19813224Sodanrc@yahoo.com.br * 19913224Sodanrc@yahoo.com.br * @return The tag value. 20013224Sodanrc@yahoo.com.br */ 20113224Sodanrc@yahoo.com.br Addr getTag() const; 20213473Sodanrc@yahoo.com.br 20313473Sodanrc@yahoo.com.br /** 20413473Sodanrc@yahoo.com.br * Increase the number of valid sub-blocks. 20513473Sodanrc@yahoo.com.br */ 20613473Sodanrc@yahoo.com.br void validateSubBlk(); 20713473Sodanrc@yahoo.com.br 20813473Sodanrc@yahoo.com.br /** 20913473Sodanrc@yahoo.com.br * Decrease the number of valid sub-blocks. 21013473Sodanrc@yahoo.com.br */ 21113473Sodanrc@yahoo.com.br void invalidateSubBlk(); 21213473Sodanrc@yahoo.com.br 21313473Sodanrc@yahoo.com.br /** 21413473Sodanrc@yahoo.com.br * Set secure bit. 21513473Sodanrc@yahoo.com.br */ 21613473Sodanrc@yahoo.com.br void setSecure(); 21714117Sodanrc@yahoo.com.br 21814117Sodanrc@yahoo.com.br /** 21914117Sodanrc@yahoo.com.br * Sets the position of the sub-entries, besides its own. 22014117Sodanrc@yahoo.com.br * 22114117Sodanrc@yahoo.com.br * @param set The set of this entry and sub-entries. 22214117Sodanrc@yahoo.com.br * @param way The way of this entry and sub-entries. 22314117Sodanrc@yahoo.com.br */ 22414117Sodanrc@yahoo.com.br void setPosition(const uint32_t set, const uint32_t way) override; 22513224Sodanrc@yahoo.com.br}; 22613224Sodanrc@yahoo.com.br 22713224Sodanrc@yahoo.com.br#endif //__MEM_CACHE_TAGS_SECTOR_BLK_HH__ 228