physical.hh revision 2738
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. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Ron Dreslinski 292391SN/A */ 302391SN/A 312391SN/A/* @file 322391SN/A */ 332391SN/A 342391SN/A#ifndef __PHYSICAL_MEMORY_HH__ 352391SN/A#define __PHYSICAL_MEMORY_HH__ 362391SN/A 372391SN/A#include "base/range.hh" 382462SN/A#include "mem/mem_object.hh" 392414SN/A#include "mem/packet.hh" 402415SN/A#include "mem/port.hh" 412415SN/A#include "sim/eventq.hh" 422416SN/A#include <map> 432416SN/A#include <string> 442462SN/A 452391SN/A// 462391SN/A// Functional model for a contiguous block of physical memory. (i.e. RAM) 472391SN/A// 482462SN/Aclass PhysicalMemory : public MemObject 492391SN/A{ 502413SN/A class MemoryPort : public Port 512413SN/A { 522413SN/A PhysicalMemory *memory; 532413SN/A 542413SN/A public: 552413SN/A 562640Sstever@eecs.umich.edu MemoryPort(const std::string &_name, PhysicalMemory *_memory); 572413SN/A 582413SN/A protected: 592413SN/A 602630SN/A virtual bool recvTiming(Packet *pkt); 612413SN/A 622630SN/A virtual Tick recvAtomic(Packet *pkt); 632413SN/A 642630SN/A virtual void recvFunctional(Packet *pkt); 652413SN/A 662413SN/A virtual void recvStatusChange(Status status); 672413SN/A 682521SN/A virtual void getDeviceAddressRanges(AddrRangeList &resp, 692521SN/A AddrRangeList &snoop); 702413SN/A 712413SN/A virtual int deviceBlockSize(); 722413SN/A }; 732413SN/A 742416SN/A int numPorts; 752416SN/A 762413SN/A 772415SN/A struct MemResponseEvent : public Event 782415SN/A { 792630SN/A Packet *pkt; 802415SN/A MemoryPort *memoryPort; 812415SN/A 822630SN/A MemResponseEvent(Packet *pkt, MemoryPort *memoryPort); 832415SN/A void process(); 842415SN/A const char *description(); 852415SN/A }; 862413SN/A 872391SN/A private: 882391SN/A // prevent copying of a MainMemory object 892391SN/A PhysicalMemory(const PhysicalMemory &specmem); 902391SN/A const PhysicalMemory &operator=(const PhysicalMemory &specmem); 912391SN/A 922391SN/A protected: 932391SN/A Addr base_addr; 942391SN/A Addr pmem_size; 952391SN/A uint8_t *pmem_addr; 962499SN/A MemoryPort *port; 972391SN/A int page_ptr; 982565SN/A Tick lat; 992391SN/A 1002391SN/A public: 1012391SN/A Addr new_page(); 1022391SN/A uint64_t size() { return pmem_size; } 1032391SN/A 1042391SN/A public: 1052565SN/A PhysicalMemory(const std::string &n, Tick latency); 1062391SN/A virtual ~PhysicalMemory(); 1072391SN/A 1082391SN/A public: 1092415SN/A int deviceBlockSize(); 1102521SN/A void getAddressRanges(AddrRangeList &resp, AddrRangeList &snoop); 1112738Sstever@eecs.umich.edu virtual Port *getPort(const std::string &if_name, int idx = -1); 1122541SN/A void virtual init(); 1132391SN/A 1142391SN/A // fast back-door memory access for vtophys(), remote gdb, etc. 1152414SN/A // uint64_t phys_read_qword(Addr addr) const; 1162413SN/A private: 1172630SN/A bool doTimingAccess(Packet *pkt, MemoryPort *memoryPort); 1182630SN/A Tick doAtomicAccess(Packet *pkt); 1192630SN/A void doFunctionalAccess(Packet *pkt); 1202413SN/A 1212413SN/A void recvStatusChange(Port::Status status); 1222391SN/A 1232391SN/A public: 1242391SN/A virtual void serialize(std::ostream &os); 1252391SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 1262497SN/A 1272391SN/A}; 1282391SN/A 1292391SN/A#endif //__PHYSICAL_MEMORY_HH__ 130