physical.hh revision 10699
12391SN/A/* 28931Sandreas.hansson@arm.com * Copyright (c) 2012 ARM Limited 38931Sandreas.hansson@arm.com * All rights reserved 48931Sandreas.hansson@arm.com * 58931Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68931Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78931Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88931Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98931Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108931Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118931Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128931Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 132391SN/A * 142391SN/A * Redistribution and use in source and binary forms, with or without 152391SN/A * modification, are permitted provided that the following conditions are 162391SN/A * met: redistributions of source code must retain the above copyright 172391SN/A * notice, this list of conditions and the following disclaimer; 182391SN/A * redistributions in binary form must reproduce the above copyright 192391SN/A * notice, this list of conditions and the following disclaimer in the 202391SN/A * documentation and/or other materials provided with the distribution; 212391SN/A * neither the name of the copyright holders nor the names of its 222391SN/A * contributors may be used to endorse or promote products derived from 232391SN/A * this software without specific prior written permission. 242391SN/A * 252391SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 262391SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 272391SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 282391SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 292391SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 302391SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 312391SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 322391SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 332391SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 342391SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 352391SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 362665Ssaidi@eecs.umich.edu * 378931Sandreas.hansson@arm.com * Authors: Andreas Hansson 382391SN/A */ 392391SN/A 4010482Sandreas.hansson@arm.com#ifndef __MEM_PHYSICAL_HH__ 4110482Sandreas.hansson@arm.com#define __MEM_PHYSICAL_HH__ 422391SN/A 439235Sandreas.hansson@arm.com#include "base/addr_range_map.hh" 4410482Sandreas.hansson@arm.com#include "mem/packet.hh" 459293Sandreas.hansson@arm.com 469293Sandreas.hansson@arm.com/** 479293Sandreas.hansson@arm.com * Forward declaration to avoid header dependencies. 489293Sandreas.hansson@arm.com */ 499293Sandreas.hansson@arm.comclass AbstractMemory; 504762Snate@binkert.org 518931Sandreas.hansson@arm.com/** 528931Sandreas.hansson@arm.com * The physical memory encapsulates all memories in the system and 538931Sandreas.hansson@arm.com * provides basic functionality for accessing those memories without 548931Sandreas.hansson@arm.com * going through the memory system and interconnect. 559293Sandreas.hansson@arm.com * 569293Sandreas.hansson@arm.com * The physical memory is also responsible for providing the host 579293Sandreas.hansson@arm.com * system backingstore used by the memories in the simulated guest 589293Sandreas.hansson@arm.com * system. When the system is created, the physical memory allocates 599293Sandreas.hansson@arm.com * the backing store based on the address ranges that are populated in 6010482Sandreas.hansson@arm.com * the system, and does so independent of how those map to actual 619293Sandreas.hansson@arm.com * memory controllers. Thus, the physical memory completely abstracts 629293Sandreas.hansson@arm.com * the mapping of the backing store of the host system and the address 639293Sandreas.hansson@arm.com * mapping in the guest system. This enables us to arbitrarily change 649293Sandreas.hansson@arm.com * the number of memory controllers, and their address mapping, as 659293Sandreas.hansson@arm.com * long as the ranges stay the same. 668931Sandreas.hansson@arm.com */ 679293Sandreas.hansson@arm.comclass PhysicalMemory : public Serializable 682391SN/A{ 692413SN/A 702391SN/A private: 712391SN/A 729293Sandreas.hansson@arm.com // Name for debugging 739293Sandreas.hansson@arm.com std::string _name; 749293Sandreas.hansson@arm.com 758931Sandreas.hansson@arm.com // Global address map 769235Sandreas.hansson@arm.com AddrRangeMap<AbstractMemory*> addrMap; 773170Sstever@eecs.umich.edu 7810699Sandreas.hansson@arm.com // a mutable cache for the last address map iterator that matched 7910699Sandreas.hansson@arm.com // an address 8010699Sandreas.hansson@arm.com mutable AddrRangeMap<AbstractMemory*>::const_iterator rangeCache; 813170Sstever@eecs.umich.edu 828931Sandreas.hansson@arm.com // All address-mapped memories 838931Sandreas.hansson@arm.com std::vector<AbstractMemory*> memories; 843170Sstever@eecs.umich.edu 858931Sandreas.hansson@arm.com // The total memory size 868931Sandreas.hansson@arm.com uint64_t size; 873170Sstever@eecs.umich.edu 889293Sandreas.hansson@arm.com // The physical memory used to provide the memory in the simulated 899293Sandreas.hansson@arm.com // system 9010482Sandreas.hansson@arm.com std::vector<std::pair<AddrRange, uint8_t*>> backingStore; 919293Sandreas.hansson@arm.com 928931Sandreas.hansson@arm.com // Prevent copying 938931Sandreas.hansson@arm.com PhysicalMemory(const PhysicalMemory&); 943170Sstever@eecs.umich.edu 958931Sandreas.hansson@arm.com // Prevent assignment 968931Sandreas.hansson@arm.com PhysicalMemory& operator=(const PhysicalMemory&); 978719SAli.Saidi@ARM.com 989293Sandreas.hansson@arm.com /** 999293Sandreas.hansson@arm.com * Create the memory region providing the backing store for a 1009293Sandreas.hansson@arm.com * given address range that corresponds to a set of memories in 1019293Sandreas.hansson@arm.com * the simulated system. 1029293Sandreas.hansson@arm.com * 1039293Sandreas.hansson@arm.com * @param range The address range covered 1049293Sandreas.hansson@arm.com * @param memories The memories this range maps to 1059293Sandreas.hansson@arm.com */ 1069293Sandreas.hansson@arm.com void createBackingStore(AddrRange range, 1079293Sandreas.hansson@arm.com const std::vector<AbstractMemory*>& _memories); 1089293Sandreas.hansson@arm.com 1092391SN/A public: 1102391SN/A 1118931Sandreas.hansson@arm.com /** 1128931Sandreas.hansson@arm.com * Create a physical memory object, wrapping a number of memories. 1138931Sandreas.hansson@arm.com */ 1149293Sandreas.hansson@arm.com PhysicalMemory(const std::string& _name, 1159293Sandreas.hansson@arm.com const std::vector<AbstractMemory*>& _memories); 1162391SN/A 1178931Sandreas.hansson@arm.com /** 1189293Sandreas.hansson@arm.com * Unmap all the backing store we have used. 1198931Sandreas.hansson@arm.com */ 1209293Sandreas.hansson@arm.com ~PhysicalMemory(); 1219293Sandreas.hansson@arm.com 1229293Sandreas.hansson@arm.com /** 1239293Sandreas.hansson@arm.com * Return the name for debugging and for creation of sections for 1249293Sandreas.hansson@arm.com * checkpointing. 1259293Sandreas.hansson@arm.com */ 1269293Sandreas.hansson@arm.com const std::string name() const { return _name; } 1274762Snate@binkert.org 1288931Sandreas.hansson@arm.com /** 1298931Sandreas.hansson@arm.com * Check if a physical address is within a range of a memory that 1308931Sandreas.hansson@arm.com * is part of the global address map. 1318931Sandreas.hansson@arm.com * 1328931Sandreas.hansson@arm.com * @param addr A physical address 1338931Sandreas.hansson@arm.com * @return Whether the address corresponds to a memory 1348931Sandreas.hansson@arm.com */ 1358931Sandreas.hansson@arm.com bool isMemAddr(Addr addr) const; 1362391SN/A 1378931Sandreas.hansson@arm.com /** 1388931Sandreas.hansson@arm.com * Get the memory ranges for all memories that are to be reported 1399413Sandreas.hansson@arm.com * to the configuration table. The ranges are merged before they 1409413Sandreas.hansson@arm.com * are returned such that any interleaved ranges appear as a 1419413Sandreas.hansson@arm.com * single range. 1428931Sandreas.hansson@arm.com * 1438931Sandreas.hansson@arm.com * @return All configuration table memory ranges 1448931Sandreas.hansson@arm.com */ 1458931Sandreas.hansson@arm.com AddrRangeList getConfAddrRanges() const; 1468923Sandreas.hansson@arm.com 1478931Sandreas.hansson@arm.com /** 1488931Sandreas.hansson@arm.com * Get the total physical memory size. 1498931Sandreas.hansson@arm.com * 1508931Sandreas.hansson@arm.com * @return The sum of all memory sizes 1518931Sandreas.hansson@arm.com */ 1528931Sandreas.hansson@arm.com uint64_t totalSize() const { return size; } 1538923Sandreas.hansson@arm.com 1549293Sandreas.hansson@arm.com /** 1559293Sandreas.hansson@arm.com * Get the pointers to the backing store for external host 1569293Sandreas.hansson@arm.com * access. Note that memory in the guest should be accessed using 1579293Sandreas.hansson@arm.com * access() or functionalAccess(). This interface is primarily 1589293Sandreas.hansson@arm.com * intended for CPU models using hardware virtualization. Note 1599293Sandreas.hansson@arm.com * that memories that are null are not present, and that the 1609293Sandreas.hansson@arm.com * backing store may also contain memories that are not part of 1619293Sandreas.hansson@arm.com * the OS-visible global address map and thus are allowed to 1629293Sandreas.hansson@arm.com * overlap. 1639293Sandreas.hansson@arm.com * 1649293Sandreas.hansson@arm.com * @return Pointers to the memory backing store 1659293Sandreas.hansson@arm.com */ 16610482Sandreas.hansson@arm.com std::vector<std::pair<AddrRange, uint8_t*>> getBackingStore() const 1679293Sandreas.hansson@arm.com { return backingStore; } 1689293Sandreas.hansson@arm.com 1698931Sandreas.hansson@arm.com /** 1709293Sandreas.hansson@arm.com * Perform an untimed memory access and update all the state 1719293Sandreas.hansson@arm.com * (e.g. locked addresses) and statistics accordingly. The packet 1729293Sandreas.hansson@arm.com * is turned into a response if required. 1738931Sandreas.hansson@arm.com * 1749293Sandreas.hansson@arm.com * @param pkt Packet performing the access 1758719SAli.Saidi@ARM.com */ 1768931Sandreas.hansson@arm.com void access(PacketPtr pkt); 1779293Sandreas.hansson@arm.com 1789293Sandreas.hansson@arm.com /** 1799293Sandreas.hansson@arm.com * Perform an untimed memory read or write without changing 1809293Sandreas.hansson@arm.com * anything but the memory itself. No stats are affected by this 1819293Sandreas.hansson@arm.com * access. In addition to normal accesses this also facilitates 1829293Sandreas.hansson@arm.com * print requests. 1839293Sandreas.hansson@arm.com * 1849293Sandreas.hansson@arm.com * @param pkt Packet performing the access 1859293Sandreas.hansson@arm.com */ 1868931Sandreas.hansson@arm.com void functionalAccess(PacketPtr pkt); 1879293Sandreas.hansson@arm.com 1889293Sandreas.hansson@arm.com /** 1899293Sandreas.hansson@arm.com * Serialize all the memories in the system. This is independent 1909293Sandreas.hansson@arm.com * of the logical memory layout, and the serialization only sees 1919293Sandreas.hansson@arm.com * the contigous backing store, independent of how this maps to 1929293Sandreas.hansson@arm.com * logical memories in the guest system. 1939293Sandreas.hansson@arm.com * 1949293Sandreas.hansson@arm.com * @param os stream to serialize to 1959293Sandreas.hansson@arm.com */ 1969293Sandreas.hansson@arm.com void serialize(std::ostream& os); 1979293Sandreas.hansson@arm.com 1989293Sandreas.hansson@arm.com /** 1999293Sandreas.hansson@arm.com * Serialize a specific store. 2009293Sandreas.hansson@arm.com * 2019293Sandreas.hansson@arm.com * @param store_id Unique identifier of this backing store 2029293Sandreas.hansson@arm.com * @param range The address range of this backing store 2039293Sandreas.hansson@arm.com * @param pmem The host pointer to this backing store 2049293Sandreas.hansson@arm.com */ 2059293Sandreas.hansson@arm.com void serializeStore(std::ostream& os, unsigned int store_id, 2069293Sandreas.hansson@arm.com AddrRange range, uint8_t* pmem); 2079293Sandreas.hansson@arm.com 2089293Sandreas.hansson@arm.com /** 2099293Sandreas.hansson@arm.com * Unserialize the memories in the system. As with the 2109293Sandreas.hansson@arm.com * serialization, this action is independent of how the address 2119293Sandreas.hansson@arm.com * ranges are mapped to logical memories in the guest system. 2129293Sandreas.hansson@arm.com */ 2139293Sandreas.hansson@arm.com void unserialize(Checkpoint* cp, const std::string& section); 2149293Sandreas.hansson@arm.com 2159293Sandreas.hansson@arm.com /** 2169293Sandreas.hansson@arm.com * Unserialize a specific backing store, identified by a section. 2179293Sandreas.hansson@arm.com */ 2189293Sandreas.hansson@arm.com void unserializeStore(Checkpoint* cp, const std::string& section); 2199293Sandreas.hansson@arm.com 2202391SN/A}; 2212391SN/A 22210482Sandreas.hansson@arm.com#endif //__MEM_PHYSICAL_HH__ 223