physical.hh revision 2665
11689SN/A/* 21689SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271689SN/A * 281689SN/A * Authors: Ron Dreslinski 291060SN/A */ 301060SN/A 311060SN/A/* @file 321060SN/A */ 331689SN/A 341060SN/A#ifndef __PHYSICAL_MEMORY_HH__ 351060SN/A#define __PHYSICAL_MEMORY_HH__ 361755SN/A 371755SN/A#include "base/range.hh" 381060SN/A#include "mem/mem_object.hh" 391060SN/A#include "mem/packet.hh" 401060SN/A#include "mem/port.hh" 411681SN/A#include "sim/eventq.hh" 421060SN/A#include <map> 431060SN/A#include <string> 441060SN/A 451858SN/A// 461717SN/A// Functional model for a contiguous block of physical memory. (i.e. RAM) 472190SN/A// 481717SN/Aclass PhysicalMemory : public MemObject 491717SN/A{ 501060SN/A class MemoryPort : public Port 511060SN/A { 522190SN/A PhysicalMemory *memory; 531060SN/A 541060SN/A public: 551060SN/A 561060SN/A MemoryPort(const std::string &_name, PhysicalMemory *_memory); 571060SN/A 581060SN/A protected: 591060SN/A 601464SN/A virtual bool recvTiming(Packet *pkt); 611061SN/A 621858SN/A virtual Tick recvAtomic(Packet *pkt); 631061SN/A 641061SN/A virtual void recvFunctional(Packet *pkt); 651061SN/A 661060SN/A virtual void recvStatusChange(Status status); 671681SN/A 681685SN/A virtual void getDeviceAddressRanges(AddrRangeList &resp, 691681SN/A AddrRangeList &snoop); 701060SN/A 711060SN/A virtual int deviceBlockSize(); 721060SN/A }; 731755SN/A 741060SN/A int numPorts; 751060SN/A 761060SN/A 771060SN/A struct MemResponseEvent : public Event 781060SN/A { 791061SN/A Packet *pkt; 801060SN/A MemoryPort *memoryPort; 811060SN/A 821060SN/A MemResponseEvent(Packet *pkt, MemoryPort *memoryPort); 831060SN/A void process(); 841060SN/A const char *description(); 851060SN/A }; 861060SN/A 871060SN/A private: 881060SN/A // prevent copying of a MainMemory object 891060SN/A PhysicalMemory(const PhysicalMemory &specmem); 901060SN/A const PhysicalMemory &operator=(const PhysicalMemory &specmem); 911060SN/A 921060SN/A protected: 931060SN/A Addr base_addr; 941060SN/A Addr pmem_size; 951755SN/A uint8_t *pmem_addr; 961060SN/A MemoryPort *port; 971060SN/A int page_ptr; 981755SN/A Tick lat; 991060SN/A 1001060SN/A public: 1011060SN/A Addr new_page(); 1021060SN/A uint64_t size() { return pmem_size; } 1031060SN/A 1041060SN/A public: 1051060SN/A PhysicalMemory(const std::string &n, Tick latency); 1061060SN/A virtual ~PhysicalMemory(); 1071060SN/A 1081060SN/A public: 1091060SN/A int deviceBlockSize(); 1101060SN/A void getAddressRanges(AddrRangeList &resp, AddrRangeList &snoop); 1111060SN/A virtual Port *getPort(const std::string &if_name); 1121060SN/A void virtual init(); 1131060SN/A 1141060SN/A // fast back-door memory access for vtophys(), remote gdb, etc. 1151060SN/A // uint64_t phys_read_qword(Addr addr) const; 1161060SN/A private: 1171060SN/A bool doTimingAccess(Packet *pkt, MemoryPort *memoryPort); 1181060SN/A Tick doAtomicAccess(Packet *pkt); 1191060SN/A void doFunctionalAccess(Packet *pkt); 1201060SN/A 1211060SN/A void recvStatusChange(Port::Status status); 1221755SN/A 1231755SN/A public: 1241060SN/A virtual void serialize(std::ostream &os); 1251684SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 1261684SN/A 1271684SN/A}; 1281684SN/A 1291060SN/A#endif //__PHYSICAL_MEMORY_HH__ 1301060SN/A