physical.hh revision 2416
1/* 2 * Copyright (c) 2001-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29/* @file 30 */ 31 32#ifndef __PHYSICAL_MEMORY_HH__ 33#define __PHYSICAL_MEMORY_HH__ 34 35#include "base/range.hh" 36#include "mem/memory.hh" 37#include "mem/packet.hh" 38#include "mem/port.hh" 39#include "sim/eventq.hh" 40#include <map> 41#include <string> 42// 43// Functional model for a contiguous block of physical memory. (i.e. RAM) 44// 45class PhysicalMemory : public Memory 46{ 47 class MemoryPort : public Port 48 { 49 PhysicalMemory *memory; 50 51 public: 52 53 MemoryPort(PhysicalMemory *_memory); 54 55 protected: 56 57 virtual bool recvTiming(Packet &pkt); 58 59 virtual Tick recvAtomic(Packet &pkt); 60 61 virtual void recvFunctional(Packet &pkt); 62 63 virtual void recvStatusChange(Status status); 64 65 virtual void getDeviceAddressRanges(AddrRangeList &range_list, 66 bool &owner); 67 68 virtual int deviceBlockSize(); 69 }; 70 71 std::map<std::string, MemoryPort*> memoryPortList; 72 73 Port * PhysicalMemory::getPort(const char *if_name); 74 75 Port * addPort(std::string portName); 76 77 int numPorts; 78 79 int lat; 80 81 struct MemResponseEvent : public Event 82 { 83 Packet pkt; 84 MemoryPort *memoryPort; 85 86 MemResponseEvent(Packet &pkt, MemoryPort *memoryPort); 87 void process(); 88 const char *description(); 89 }; 90 91 private: 92 // prevent copying of a MainMemory object 93 PhysicalMemory(const PhysicalMemory &specmem); 94 const PhysicalMemory &operator=(const PhysicalMemory &specmem); 95 96 protected: 97 Addr base_addr; 98 Addr pmem_size; 99 uint8_t *pmem_addr; 100 int page_ptr; 101 102 public: 103 Addr new_page(); 104 uint64_t size() { return pmem_size; } 105 106 public: 107 PhysicalMemory(const std::string &n); 108 virtual ~PhysicalMemory(); 109 110 protected: 111 // error handling for prot_* functions 112 void prot_access_error(Addr addr, int size, Command func); 113 114 public: 115 int deviceBlockSize(); 116 117 void prot_memset(Addr addr, uint8_t val, int size); 118 119 // fast back-door memory access for vtophys(), remote gdb, etc. 120 // uint64_t phys_read_qword(Addr addr) const; 121 private: 122 bool doTimingAccess(Packet &pkt, MemoryPort *memoryPort); 123 Tick doAtomicAccess(Packet &pkt); 124 void doFunctionalAccess(Packet &pkt); 125 126 void recvStatusChange(Port::Status status); 127 128 public: 129 virtual void serialize(std::ostream &os); 130 virtual void unserialize(Checkpoint *cp, const std::string §ion); 131}; 132 133/*uint64_t 134PhysicalMemory::phys_read_qword(Addr addr) const 135{ 136 if (addr + sizeof(uint64_t) > pmem_size) 137 return 0; 138 139 return *(uint64_t *)(pmem_addr + addr); 140}*/ 141 142 143#endif //__PHYSICAL_MEMORY_HH__ 144