2 * Copyright (c) 2013 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2009 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 * Declaration of an associative set
48 #ifndef __MEM_CACHE_TAGS_CACHESET_HH__
49 #define __MEM_CACHE_TAGS_CACHESET_HH__
54 #include "base/types.hh"
57 * An associative set of cache blocks.
59 template <class Blktype>
63 /** The associativity of this set. */
66 /** Cache blocks in this set, maintained in LRU order 0 = MRU. */
67 std::vector<Blktype*> blks;
70 * Find a block matching the tag in this set.
71 * @param way_id The id of the way that matches the tag.
72 * @param tag The Tag to find.
73 * @param is_secure True if the target memory space is secure.
74 * @return Pointer to the block if found. Set way_id to assoc if none found
76 Blktype* findBlk(Addr tag, bool is_secure, int& way_id) const ;
77 Blktype* findBlk(Addr tag, bool is_secure) const ;
80 * Move the given block to the head of the list.
81 * @param blk The block to move.
83 void moveToHead(Blktype *blk);
86 * Move the given block to the tail of the list.
87 * @param blk The block to move
89 void moveToTail(Blktype *blk);
93 template <class Blktype>
95 CacheSet<Blktype>::findBlk(Addr tag, bool is_secure, int& way_id) const
98 * Way_id returns the id of the way that matches the block
99 * If no block is found way_id is set to assoc.
102 for (int i = 0; i < assoc; ++i) {
103 if (blks[i]->tag == tag && blks[i]->isValid() &&
104 blks[i]->isSecure() == is_secure) {
112 template <class Blktype>
114 CacheSet<Blktype>::findBlk(Addr tag, bool is_secure) const
117 return findBlk(tag, is_secure, ignored_way_id);
120 template <class Blktype>
122 CacheSet<Blktype>::moveToHead(Blktype *blk)
124 // nothing to do if blk is already head
128 // write 'next' block into blks[i], moving up from MRU toward LRU
129 // until we overwrite the block we moved to head.
131 // start by setting up to write 'blk' into blks[0]
137 std::swap(blks[i], next);
139 } while (next != blk);
142 template <class Blktype>
144 CacheSet<Blktype>::moveToTail(Blktype *blk)
146 // nothing to do if blk is already tail
147 if (blks[assoc - 1] == blk)
150 // write 'next' block into blks[i], moving from LRU to MRU
151 // until we overwrite the block we moved to tail.
153 // start by setting up to write 'blk' into tail
159 std::swap(blks[i], next);
161 } while (next != blk);