physical.hh revision 2640
12391SN/A/* 22391SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 32391SN/A * All rights reserved. 42391SN/A * 52391SN/A * Redistribution and use in source and binary forms, with or without 62391SN/A * modification, are permitted provided that the following conditions are 72391SN/A * met: redistributions of source code must retain the above copyright 82391SN/A * notice, this list of conditions and the following disclaimer; 92391SN/A * redistributions in binary form must reproduce the above copyright 102391SN/A * notice, this list of conditions and the following disclaimer in the 112391SN/A * documentation and/or other materials provided with the distribution; 122391SN/A * neither the name of the copyright holders nor the names of its 132391SN/A * contributors may be used to endorse or promote products derived from 142391SN/A * this software without specific prior written permission. 152391SN/A * 162391SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172391SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182391SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192391SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202391SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212391SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222391SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232391SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242391SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252391SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262391SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272391SN/A */ 282391SN/A 292391SN/A/* @file 302391SN/A */ 312391SN/A 322391SN/A#ifndef __PHYSICAL_MEMORY_HH__ 332391SN/A#define __PHYSICAL_MEMORY_HH__ 342391SN/A 352391SN/A#include "base/range.hh" 362462SN/A#include "mem/mem_object.hh" 372414SN/A#include "mem/packet.hh" 382415SN/A#include "mem/port.hh" 392415SN/A#include "sim/eventq.hh" 402416SN/A#include <map> 412416SN/A#include <string> 422462SN/A 432391SN/A// 442391SN/A// Functional model for a contiguous block of physical memory. (i.e. RAM) 452391SN/A// 462462SN/Aclass PhysicalMemory : public MemObject 472391SN/A{ 482413SN/A class MemoryPort : public Port 492413SN/A { 502413SN/A PhysicalMemory *memory; 512413SN/A 522413SN/A public: 532413SN/A 542640Sstever@eecs.umich.edu MemoryPort(const std::string &_name, PhysicalMemory *_memory); 552413SN/A 562413SN/A protected: 572413SN/A 582630SN/A virtual bool recvTiming(Packet *pkt); 592413SN/A 602630SN/A virtual Tick recvAtomic(Packet *pkt); 612413SN/A 622630SN/A virtual void recvFunctional(Packet *pkt); 632413SN/A 642413SN/A virtual void recvStatusChange(Status status); 652413SN/A 662521SN/A virtual void getDeviceAddressRanges(AddrRangeList &resp, 672521SN/A AddrRangeList &snoop); 682413SN/A 692413SN/A virtual int deviceBlockSize(); 702413SN/A }; 712413SN/A 722416SN/A int numPorts; 732416SN/A 742413SN/A 752415SN/A struct MemResponseEvent : public Event 762415SN/A { 772630SN/A Packet *pkt; 782415SN/A MemoryPort *memoryPort; 792415SN/A 802630SN/A MemResponseEvent(Packet *pkt, MemoryPort *memoryPort); 812415SN/A void process(); 822415SN/A const char *description(); 832415SN/A }; 842413SN/A 852391SN/A private: 862391SN/A // prevent copying of a MainMemory object 872391SN/A PhysicalMemory(const PhysicalMemory &specmem); 882391SN/A const PhysicalMemory &operator=(const PhysicalMemory &specmem); 892391SN/A 902391SN/A protected: 912391SN/A Addr base_addr; 922391SN/A Addr pmem_size; 932391SN/A uint8_t *pmem_addr; 942499SN/A MemoryPort *port; 952391SN/A int page_ptr; 962565SN/A Tick lat; 972391SN/A 982391SN/A public: 992391SN/A Addr new_page(); 1002391SN/A uint64_t size() { return pmem_size; } 1012391SN/A 1022391SN/A public: 1032565SN/A PhysicalMemory(const std::string &n, Tick latency); 1042391SN/A virtual ~PhysicalMemory(); 1052391SN/A 1062391SN/A public: 1072415SN/A int deviceBlockSize(); 1082521SN/A void getAddressRanges(AddrRangeList &resp, AddrRangeList &snoop); 1092521SN/A virtual Port *getPort(const std::string &if_name); 1102541SN/A void virtual init(); 1112391SN/A 1122391SN/A // fast back-door memory access for vtophys(), remote gdb, etc. 1132414SN/A // uint64_t phys_read_qword(Addr addr) const; 1142413SN/A private: 1152630SN/A bool doTimingAccess(Packet *pkt, MemoryPort *memoryPort); 1162630SN/A Tick doAtomicAccess(Packet *pkt); 1172630SN/A void doFunctionalAccess(Packet *pkt); 1182413SN/A 1192413SN/A void recvStatusChange(Port::Status status); 1202391SN/A 1212391SN/A public: 1222391SN/A virtual void serialize(std::ostream &os); 1232391SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 1242497SN/A 1252391SN/A}; 1262391SN/A 1272391SN/A#endif //__PHYSICAL_MEMORY_HH__ 128