physical.hh revision 10905
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 8810700Sandreas.hansson@arm.com // Let the user choose if we reserve swap space when calling mmap 8910700Sandreas.hansson@arm.com const bool mmapUsingNoReserve; 9010700Sandreas.hansson@arm.com 919293Sandreas.hansson@arm.com // The physical memory used to provide the memory in the simulated 929293Sandreas.hansson@arm.com // system 9310482Sandreas.hansson@arm.com std::vector<std::pair<AddrRange, uint8_t*>> backingStore; 949293Sandreas.hansson@arm.com 958931Sandreas.hansson@arm.com // Prevent copying 968931Sandreas.hansson@arm.com PhysicalMemory(const PhysicalMemory&); 973170Sstever@eecs.umich.edu 988931Sandreas.hansson@arm.com // Prevent assignment 998931Sandreas.hansson@arm.com PhysicalMemory& operator=(const PhysicalMemory&); 1008719SAli.Saidi@ARM.com 1019293Sandreas.hansson@arm.com /** 1029293Sandreas.hansson@arm.com * Create the memory region providing the backing store for a 1039293Sandreas.hansson@arm.com * given address range that corresponds to a set of memories in 1049293Sandreas.hansson@arm.com * the simulated system. 1059293Sandreas.hansson@arm.com * 1069293Sandreas.hansson@arm.com * @param range The address range covered 1079293Sandreas.hansson@arm.com * @param memories The memories this range maps to 1089293Sandreas.hansson@arm.com */ 1099293Sandreas.hansson@arm.com void createBackingStore(AddrRange range, 1109293Sandreas.hansson@arm.com const std::vector<AbstractMemory*>& _memories); 1119293Sandreas.hansson@arm.com 1122391SN/A public: 1132391SN/A 1148931Sandreas.hansson@arm.com /** 1158931Sandreas.hansson@arm.com * Create a physical memory object, wrapping a number of memories. 1168931Sandreas.hansson@arm.com */ 1179293Sandreas.hansson@arm.com PhysicalMemory(const std::string& _name, 11810700Sandreas.hansson@arm.com const std::vector<AbstractMemory*>& _memories, 11910700Sandreas.hansson@arm.com bool mmap_using_noreserve); 1202391SN/A 1218931Sandreas.hansson@arm.com /** 1229293Sandreas.hansson@arm.com * Unmap all the backing store we have used. 1238931Sandreas.hansson@arm.com */ 1249293Sandreas.hansson@arm.com ~PhysicalMemory(); 1259293Sandreas.hansson@arm.com 1269293Sandreas.hansson@arm.com /** 1279293Sandreas.hansson@arm.com * Return the name for debugging and for creation of sections for 1289293Sandreas.hansson@arm.com * checkpointing. 1299293Sandreas.hansson@arm.com */ 1309293Sandreas.hansson@arm.com const std::string name() const { return _name; } 1314762Snate@binkert.org 1328931Sandreas.hansson@arm.com /** 1338931Sandreas.hansson@arm.com * Check if a physical address is within a range of a memory that 1348931Sandreas.hansson@arm.com * is part of the global address map. 1358931Sandreas.hansson@arm.com * 1368931Sandreas.hansson@arm.com * @param addr A physical address 1378931Sandreas.hansson@arm.com * @return Whether the address corresponds to a memory 1388931Sandreas.hansson@arm.com */ 1398931Sandreas.hansson@arm.com bool isMemAddr(Addr addr) const; 1402391SN/A 1418931Sandreas.hansson@arm.com /** 1428931Sandreas.hansson@arm.com * Get the memory ranges for all memories that are to be reported 1439413Sandreas.hansson@arm.com * to the configuration table. The ranges are merged before they 1449413Sandreas.hansson@arm.com * are returned such that any interleaved ranges appear as a 1459413Sandreas.hansson@arm.com * single range. 1468931Sandreas.hansson@arm.com * 1478931Sandreas.hansson@arm.com * @return All configuration table memory ranges 1488931Sandreas.hansson@arm.com */ 1498931Sandreas.hansson@arm.com AddrRangeList getConfAddrRanges() const; 1508923Sandreas.hansson@arm.com 1518931Sandreas.hansson@arm.com /** 1528931Sandreas.hansson@arm.com * Get the total physical memory size. 1538931Sandreas.hansson@arm.com * 1548931Sandreas.hansson@arm.com * @return The sum of all memory sizes 1558931Sandreas.hansson@arm.com */ 1568931Sandreas.hansson@arm.com uint64_t totalSize() const { return size; } 1578923Sandreas.hansson@arm.com 1589293Sandreas.hansson@arm.com /** 1599293Sandreas.hansson@arm.com * Get the pointers to the backing store for external host 1609293Sandreas.hansson@arm.com * access. Note that memory in the guest should be accessed using 1619293Sandreas.hansson@arm.com * access() or functionalAccess(). This interface is primarily 1629293Sandreas.hansson@arm.com * intended for CPU models using hardware virtualization. Note 1639293Sandreas.hansson@arm.com * that memories that are null are not present, and that the 1649293Sandreas.hansson@arm.com * backing store may also contain memories that are not part of 1659293Sandreas.hansson@arm.com * the OS-visible global address map and thus are allowed to 1669293Sandreas.hansson@arm.com * overlap. 1679293Sandreas.hansson@arm.com * 1689293Sandreas.hansson@arm.com * @return Pointers to the memory backing store 1699293Sandreas.hansson@arm.com */ 17010482Sandreas.hansson@arm.com std::vector<std::pair<AddrRange, uint8_t*>> getBackingStore() const 1719293Sandreas.hansson@arm.com { return backingStore; } 1729293Sandreas.hansson@arm.com 1738931Sandreas.hansson@arm.com /** 1749293Sandreas.hansson@arm.com * Perform an untimed memory access and update all the state 1759293Sandreas.hansson@arm.com * (e.g. locked addresses) and statistics accordingly. The packet 1769293Sandreas.hansson@arm.com * is turned into a response if required. 1778931Sandreas.hansson@arm.com * 1789293Sandreas.hansson@arm.com * @param pkt Packet performing the access 1798719SAli.Saidi@ARM.com */ 1808931Sandreas.hansson@arm.com void access(PacketPtr pkt); 1819293Sandreas.hansson@arm.com 1829293Sandreas.hansson@arm.com /** 1839293Sandreas.hansson@arm.com * Perform an untimed memory read or write without changing 1849293Sandreas.hansson@arm.com * anything but the memory itself. No stats are affected by this 1859293Sandreas.hansson@arm.com * access. In addition to normal accesses this also facilitates 1869293Sandreas.hansson@arm.com * print requests. 1879293Sandreas.hansson@arm.com * 1889293Sandreas.hansson@arm.com * @param pkt Packet performing the access 1899293Sandreas.hansson@arm.com */ 1908931Sandreas.hansson@arm.com void functionalAccess(PacketPtr pkt); 1919293Sandreas.hansson@arm.com 1929293Sandreas.hansson@arm.com /** 1939293Sandreas.hansson@arm.com * Serialize all the memories in the system. This is independent 1949293Sandreas.hansson@arm.com * of the logical memory layout, and the serialization only sees 1959293Sandreas.hansson@arm.com * the contigous backing store, independent of how this maps to 1969293Sandreas.hansson@arm.com * logical memories in the guest system. 1979293Sandreas.hansson@arm.com * 1989293Sandreas.hansson@arm.com * @param os stream to serialize to 1999293Sandreas.hansson@arm.com */ 20010905Sandreas.sandberg@arm.com void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE; 2019293Sandreas.hansson@arm.com 2029293Sandreas.hansson@arm.com /** 2039293Sandreas.hansson@arm.com * Serialize a specific store. 2049293Sandreas.hansson@arm.com * 2059293Sandreas.hansson@arm.com * @param store_id Unique identifier of this backing store 2069293Sandreas.hansson@arm.com * @param range The address range of this backing store 2079293Sandreas.hansson@arm.com * @param pmem The host pointer to this backing store 2089293Sandreas.hansson@arm.com */ 20910905Sandreas.sandberg@arm.com void serializeStore(CheckpointOut &cp, unsigned int store_id, 21010905Sandreas.sandberg@arm.com AddrRange range, uint8_t* pmem) const; 2119293Sandreas.hansson@arm.com 2129293Sandreas.hansson@arm.com /** 2139293Sandreas.hansson@arm.com * Unserialize the memories in the system. As with the 2149293Sandreas.hansson@arm.com * serialization, this action is independent of how the address 2159293Sandreas.hansson@arm.com * ranges are mapped to logical memories in the guest system. 2169293Sandreas.hansson@arm.com */ 21710905Sandreas.sandberg@arm.com void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE; 2189293Sandreas.hansson@arm.com 2199293Sandreas.hansson@arm.com /** 2209293Sandreas.hansson@arm.com * Unserialize a specific backing store, identified by a section. 2219293Sandreas.hansson@arm.com */ 22210905Sandreas.sandberg@arm.com void unserializeStore(CheckpointIn &cp); 2239293Sandreas.hansson@arm.com 2242391SN/A}; 2252391SN/A 22610482Sandreas.hansson@arm.com#endif //__MEM_PHYSICAL_HH__ 227