physical.hh revision 3029
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"
402914Ssaidi@eecs.umich.edu#include "mem/tport.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{
502914Ssaidi@eecs.umich.edu    class MemoryPort : public SimpleTimingPort
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
772391SN/A  private:
782391SN/A    // prevent copying of a MainMemory object
792391SN/A    PhysicalMemory(const PhysicalMemory &specmem);
802391SN/A    const PhysicalMemory &operator=(const PhysicalMemory &specmem);
812391SN/A
822391SN/A  protected:
833012Ssaidi@eecs.umich.edu    uint8_t *pmemAddr;
842499SN/A    MemoryPort *port;
853012Ssaidi@eecs.umich.edu    int pagePtr;
862565SN/A    Tick lat;
872391SN/A
882391SN/A  public:
892391SN/A    Addr new_page();
903012Ssaidi@eecs.umich.edu    uint64_t size() { return params()->addrRange.size(); }
913012Ssaidi@eecs.umich.edu
923012Ssaidi@eecs.umich.edu    struct Params
933012Ssaidi@eecs.umich.edu    {
943012Ssaidi@eecs.umich.edu        std::string name;
953012Ssaidi@eecs.umich.edu        Range<Addr> addrRange;
963012Ssaidi@eecs.umich.edu        Tick latency;
973012Ssaidi@eecs.umich.edu    };
983012Ssaidi@eecs.umich.edu
993012Ssaidi@eecs.umich.edu  protected:
1003012Ssaidi@eecs.umich.edu    Params *_params;
1012391SN/A
1022391SN/A  public:
1033012Ssaidi@eecs.umich.edu    const Params *params() const { return _params; }
1043012Ssaidi@eecs.umich.edu    PhysicalMemory(Params *p);
1052391SN/A    virtual ~PhysicalMemory();
1062391SN/A
1072391SN/A  public:
1082415SN/A    int deviceBlockSize();
1092521SN/A    void getAddressRanges(AddrRangeList &resp, AddrRangeList &snoop);
1102738Sstever@eecs.umich.edu    virtual Port *getPort(const std::string &if_name, int idx = -1);
1112541SN/A    void virtual init();
1122914Ssaidi@eecs.umich.edu    unsigned int drain(Event *de);
1132391SN/A
1143012Ssaidi@eecs.umich.edu  protected:
1153029Ssaidi@eecs.umich.edu    void doFunctionalAccess(Packet *pkt);
1163012Ssaidi@eecs.umich.edu    virtual Tick calculateLatency(Packet *pkt);
1172413SN/A    void recvStatusChange(Port::Status status);
1182391SN/A
1192391SN/A  public:
1202391SN/A    virtual void serialize(std::ostream &os);
1212391SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
1222497SN/A
1232391SN/A};
1242391SN/A
1252391SN/A#endif //__PHYSICAL_MEMORY_HH__
126