3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * Description: See DirectoryMemory.h
39 #include "mem/ruby/system/System.hh"
40 #include "mem/ruby/common/Driver.hh"
41 #include "mem/ruby/system/DirectoryMemory.hh"
42 #include "mem/ruby/slicc_interface/RubySlicc_Util.hh"
43 #include "mem/ruby/config/RubyConfig.hh"
44 #include "mem/protocol/Chip.hh"
46 DirectoryMemory::DirectoryMemory(Chip
* chip_ptr
, int version
)
48 m_chip_ptr
= chip_ptr
;
50 // THIS DOESN'T SEEM TO WORK -- MRM
51 // m_size = RubyConfig::memoryModuleBlocks()/RubyConfig::numberOfDirectory();
52 m_size
= RubyConfig::memoryModuleBlocks();
54 /*********************************************************************
55 // allocates an array of directory entry pointers & sets them to NULL
56 m_entries = new Directory_Entry*[m_size];
57 if (m_entries == NULL) {
58 ERROR_MSG("Directory Memory: unable to allocate memory.");
61 for (int i=0; i < m_size; i++) {
64 */////////////////////////////////////////////////////////////////////
67 DirectoryMemory::~DirectoryMemory()
69 /*********************************************************************
70 // free up all the directory entries
71 for (int i=0; i < m_size; i++) {
72 if (m_entries[i] != NULL) {
78 // free up the array of directory entries
80 *//////////////////////////////////////////////////////////////////////
85 void DirectoryMemory::printConfig(ostream
& out
)
87 out
<< "Memory config:" << endl
;
88 out
<< " memory_bits: " << RubyConfig::memorySizeBits() << endl
;
89 out
<< " memory_size_bytes: " << RubyConfig::memorySizeBytes() << endl
;
90 out
<< " memory_size_Kbytes: " << double(RubyConfig::memorySizeBytes()) / (1<<10) << endl
;
91 out
<< " memory_size_Mbytes: " << double(RubyConfig::memorySizeBytes()) / (1<<20) << endl
;
92 out
<< " memory_size_Gbytes: " << double(RubyConfig::memorySizeBytes()) / (1<<30) << endl
;
94 out
<< " module_bits: " << RubyConfig::memoryModuleBits() << endl
;
95 out
<< " module_size_lines: " << RubyConfig::memoryModuleBlocks() << endl
;
96 out
<< " module_size_bytes: " << RubyConfig::memoryModuleBlocks() * RubyConfig::dataBlockBytes() << endl
;
97 out
<< " module_size_Kbytes: " << double(RubyConfig::memoryModuleBlocks() * RubyConfig::dataBlockBytes()) / (1<<10) << endl
;
98 out
<< " module_size_Mbytes: " << double(RubyConfig::memoryModuleBlocks() * RubyConfig::dataBlockBytes()) / (1<<20) << endl
;
102 bool DirectoryMemory::isPresent(PhysAddress address
)
104 return (map_Address_to_DirectoryNode(address
) == m_chip_ptr
->getID()*RubyConfig::numberOfDirectoryPerChip()+m_version
);
107 void DirectoryMemory::readPhysMem(uint64 address
, int size
, void * data
)
111 Directory_Entry
& DirectoryMemory::lookup(PhysAddress address
)
113 assert(isPresent(address
));
114 Index index
= address
.memoryModuleIndex();
116 if (index
< 0 || index
> m_size
) {
117 WARN_EXPR(m_chip_ptr
->getID());
118 WARN_EXPR(address
.getAddress());
121 ERROR_MSG("Directory Memory Assertion: accessing memory out of range.");
124 map
<Index
, Directory_Entry
*>::iterator iter
= m_entries
.find(index
);
125 Directory_Entry
* entry
= m_entries
.find(index
)->second
;
127 // allocate the directory entry on demand.
128 if (iter
== m_entries
.end()) {
129 entry
= new Directory_Entry
;
131 // entry->getProcOwner() = m_chip_ptr->getID(); // FIXME - This should not be hard coded
132 // entry->getDirOwner() = true; // FIXME - This should not be hard-coded
134 // load the data from physicalMemory when first initalizing
135 physical_address_t physAddr
= address
.getAddress();
136 int8
* dataArray
= (int8
* )malloc(RubyConfig::dataBlockBytes() * sizeof(int8
));
137 readPhysMem(physAddr
, RubyConfig::dataBlockBytes(), dataArray
);
139 for(int j
=0; j
< RubyConfig::dataBlockBytes(); j
++) {
140 entry
->getDataBlk().setByte(j
, dataArray
[j
]);
142 DEBUG_EXPR(NODE_COMP
, MedPrio
,entry
->getDataBlk());
143 // store entry to the table
144 m_entries
.insert(make_pair(index
, entry
));
150 void DirectoryMemory::invalidateBlock(PhysAddress address)
152 assert(isPresent(address));
154 Index index = address.memoryModuleIndex();
156 if (index < 0 || index > m_size) {
157 ERROR_MSG("Directory Memory Assertion: accessing memory out of range.");
160 if(m_entries[index] != NULL){
161 delete m_entries[index];
162 m_entries[index] = NULL;
168 void DirectoryMemory::print(ostream
& out
) const
170 out
<< "Directory dump: " << endl
;
171 for(map
<Index
, Directory_Entry
*>::const_iterator it
= m_entries
.begin(); it
!= m_entries
.end(); ++it
) {
172 out
<< it
->first
<< ": ";
173 out
<< *(it
->second
) << endl
;