physical.hh revision 2640
14030Sktlim@umich.edu/*
23096Sstever@eecs.umich.edu * Copyright (c) 2001-2005 The Regents of The University of Michigan
33096Sstever@eecs.umich.edu * All rights reserved.
43096Sstever@eecs.umich.edu *
53096Sstever@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
63096Sstever@eecs.umich.edu * modification, are permitted provided that the following conditions are
73096Sstever@eecs.umich.edu * met: redistributions of source code must retain the above copyright
83096Sstever@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
93096Sstever@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
103096Sstever@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
113096Sstever@eecs.umich.edu * documentation and/or other materials provided with the distribution;
123096Sstever@eecs.umich.edu * neither the name of the copyright holders nor the names of its
133096Sstever@eecs.umich.edu * contributors may be used to endorse or promote products derived from
143096Sstever@eecs.umich.edu * this software without specific prior written permission.
153096Sstever@eecs.umich.edu *
163096Sstever@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173096Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183096Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193096Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203096Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213096Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223096Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233096Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243096Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253096Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263096Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273096Sstever@eecs.umich.edu */
283096Sstever@eecs.umich.edu
293096Sstever@eecs.umich.edu/* @file
303096Sstever@eecs.umich.edu */
313096Sstever@eecs.umich.edu
323096Sstever@eecs.umich.edu#ifndef __PHYSICAL_MEMORY_HH__
333096Sstever@eecs.umich.edu#define __PHYSICAL_MEMORY_HH__
343096Sstever@eecs.umich.edu
353096Sstever@eecs.umich.edu#include "base/range.hh"
363096Sstever@eecs.umich.edu#include "mem/mem_object.hh"
373096Sstever@eecs.umich.edu#include "mem/packet.hh"
383096Sstever@eecs.umich.edu#include "mem/port.hh"
393096Sstever@eecs.umich.edu#include "sim/eventq.hh"
404030Sktlim@umich.edu#include <map>
413096Sstever@eecs.umich.edu#include <string>
423096Sstever@eecs.umich.edu
434390Sktlim@umich.edu//
443096Sstever@eecs.umich.edu// Functional model for a contiguous block of physical memory. (i.e. RAM)
453096Sstever@eecs.umich.edu//
463096Sstever@eecs.umich.educlass PhysicalMemory : public MemObject
473096Sstever@eecs.umich.edu{
483096Sstever@eecs.umich.edu    class MemoryPort : public Port
493096Sstever@eecs.umich.edu    {
503096Sstever@eecs.umich.edu        PhysicalMemory *memory;
513096Sstever@eecs.umich.edu
52      public:
53
54        MemoryPort(const std::string &_name, PhysicalMemory *_memory);
55
56      protected:
57
58        virtual bool recvTiming(Packet *pkt);
59
60        virtual Tick recvAtomic(Packet *pkt);
61
62        virtual void recvFunctional(Packet *pkt);
63
64        virtual void recvStatusChange(Status status);
65
66        virtual void getDeviceAddressRanges(AddrRangeList &resp,
67                                            AddrRangeList &snoop);
68
69        virtual int deviceBlockSize();
70    };
71
72    int numPorts;
73
74
75    struct MemResponseEvent : public Event
76    {
77        Packet *pkt;
78        MemoryPort *memoryPort;
79
80        MemResponseEvent(Packet *pkt, MemoryPort *memoryPort);
81        void process();
82        const char *description();
83    };
84
85  private:
86    // prevent copying of a MainMemory object
87    PhysicalMemory(const PhysicalMemory &specmem);
88    const PhysicalMemory &operator=(const PhysicalMemory &specmem);
89
90  protected:
91    Addr base_addr;
92    Addr pmem_size;
93    uint8_t *pmem_addr;
94    MemoryPort *port;
95    int page_ptr;
96    Tick lat;
97
98  public:
99    Addr new_page();
100    uint64_t size() { return pmem_size; }
101
102  public:
103    PhysicalMemory(const std::string &n, Tick latency);
104    virtual ~PhysicalMemory();
105
106  public:
107    int deviceBlockSize();
108    void getAddressRanges(AddrRangeList &resp, AddrRangeList &snoop);
109    virtual Port *getPort(const std::string &if_name);
110    void virtual init();
111
112    // fast back-door memory access for vtophys(), remote gdb, etc.
113    // uint64_t phys_read_qword(Addr addr) const;
114  private:
115    bool doTimingAccess(Packet *pkt, MemoryPort *memoryPort);
116    Tick doAtomicAccess(Packet *pkt);
117    void doFunctionalAccess(Packet *pkt);
118
119    void recvStatusChange(Port::Status status);
120
121  public:
122    virtual void serialize(std::ostream &os);
123    virtual void unserialize(Checkpoint *cp, const std::string &section);
124
125};
126
127#endif //__PHYSICAL_MEMORY_HH__
128