abstract_mem.hh revision 2462
12391SN/A/*
213998Stiago.muck@arm.com * Copyright (c) 2001-2005 The Regents of The University of Michigan
38931Sandreas.hansson@arm.com * All rights reserved.
48931Sandreas.hansson@arm.com *
58931Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without
68931Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are
78931Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright
88931Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer;
98931Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright
108931Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the
118931Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution;
128931Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its
138931Sandreas.hansson@arm.com * 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"
362391SN/A#include "mem/mem_object.hh"
372391SN/A#include "mem/packet.hh"
382391SN/A#include "mem/port.hh"
392665SN/A#include "sim/eventq.hh"
402665SN/A#include <map>
418931Sandreas.hansson@arm.com#include <string>
422391SN/A
432391SN/A//
448931Sandreas.hansson@arm.com// Functional model for a contiguous block of physical memory. (i.e. RAM)
458931Sandreas.hansson@arm.com//
468931Sandreas.hansson@arm.comclass PhysicalMemory : public MemObject
472391SN/A{
482391SN/A    class MemoryPort : public Port
4912492Sodanrc@yahoo.com.br    {
5012492Sodanrc@yahoo.com.br        PhysicalMemory *memory;
512391SN/A
5213853Sgabeblack@google.com      public:
5313892Sgabeblack@google.com
548931Sandreas.hansson@arm.com        MemoryPort(PhysicalMemory *_memory);
5513892Sgabeblack@google.com
568719SN/A      protected:
572462SN/A
589053Sdam.sunwoo@arm.com        virtual bool recvTiming(Packet &pkt);
599053Sdam.sunwoo@arm.com
609053Sdam.sunwoo@arm.com        virtual Tick recvAtomic(Packet &pkt);
618931Sandreas.hansson@arm.com
629293Sandreas.hansson@arm.com        virtual void recvFunctional(Packet &pkt);
639293Sandreas.hansson@arm.com
649293Sandreas.hansson@arm.com        virtual void recvStatusChange(Status status);
659293Sandreas.hansson@arm.com
669293Sandreas.hansson@arm.com        virtual void getDeviceAddressRanges(AddrRangeList &range_list,
679293Sandreas.hansson@arm.com                                            bool &owner);
689293Sandreas.hansson@arm.com
699293Sandreas.hansson@arm.com        virtual int deviceBlockSize();
709293Sandreas.hansson@arm.com    };
719293Sandreas.hansson@arm.com
729293Sandreas.hansson@arm.com    virtual Port * getPort(const char *if_name);
739293Sandreas.hansson@arm.com
749293Sandreas.hansson@arm.com    int numPorts;
759293Sandreas.hansson@arm.com
769293Sandreas.hansson@arm.com    int lat;
779293Sandreas.hansson@arm.com
789293Sandreas.hansson@arm.com    struct MemResponseEvent : public Event
7911005Sandreas.sandberg@arm.com    {
809293Sandreas.hansson@arm.com        Packet &pkt;
819293Sandreas.hansson@arm.com        MemoryPort *memoryPort;
829293Sandreas.hansson@arm.com
839293Sandreas.hansson@arm.com        MemResponseEvent(Packet &pkt, MemoryPort *memoryPort);
8412749Sgiacomo.travaglini@arm.com        void process();
859293Sandreas.hansson@arm.com        const char *description();
8613998Stiago.muck@arm.com    };
8713998Stiago.muck@arm.com
889293Sandreas.hansson@arm.com  private:
899293Sandreas.hansson@arm.com    // prevent copying of a MainMemory object
909293Sandreas.hansson@arm.com    PhysicalMemory(const PhysicalMemory &specmem);
9112749Sgiacomo.travaglini@arm.com    const PhysicalMemory &operator=(const PhysicalMemory &specmem);
9212749Sgiacomo.travaglini@arm.com
939293Sandreas.hansson@arm.com  protected:
949293Sandreas.hansson@arm.com    Addr base_addr;
959293Sandreas.hansson@arm.com    Addr pmem_size;
969293Sandreas.hansson@arm.com    uint8_t *pmem_addr;
979293Sandreas.hansson@arm.com    int page_ptr;
989293Sandreas.hansson@arm.com
999293Sandreas.hansson@arm.com  public:
1009293Sandreas.hansson@arm.com    Addr new_page();
1018931Sandreas.hansson@arm.com    uint64_t size() { return pmem_size; }
1028931Sandreas.hansson@arm.com
1038931Sandreas.hansson@arm.com  public:
10413892Sgabeblack@google.com    PhysicalMemory(const std::string &n);
10513892Sgabeblack@google.com    virtual ~PhysicalMemory();
1068931Sandreas.hansson@arm.com
10713892Sgabeblack@google.com  public:
1082391SN/A    int deviceBlockSize();
1096107SN/A
1106107SN/A    // fast back-door memory access for vtophys(), remote gdb, etc.
1118931Sandreas.hansson@arm.com    // uint64_t phys_read_qword(Addr addr) const;
1129235Sandreas.hansson@arm.com  private:
1132413SN/A    bool doTimingAccess(Packet &pkt, MemoryPort *memoryPort);
1148931Sandreas.hansson@arm.com    Tick doAtomicAccess(Packet &pkt);
1158931Sandreas.hansson@arm.com    void doFunctionalAccess(Packet &pkt);
1162413SN/A
11713853Sgabeblack@google.com    void recvStatusChange(Port::Status status);
11813853Sgabeblack@google.com
11913853Sgabeblack@google.com  public:
1208931Sandreas.hansson@arm.com    virtual void serialize(std::ostream &os);
12111614Sdavid.j.hashe@gmail.com    virtual void unserialize(Checkpoint *cp, const std::string &section);
1222413SN/A};
1238931Sandreas.hansson@arm.com
12411614Sdavid.j.hashe@gmail.com/*uint64_t
12511614Sdavid.j.hashe@gmail.comPhysicalMemory::phys_read_qword(Addr addr) const
12611614Sdavid.j.hashe@gmail.com{
12711614Sdavid.j.hashe@gmail.com    if (addr + sizeof(uint64_t) > pmem_size)
1283170SN/A        return 0;
1293170SN/A
1303170SN/A    return *(uint64_t *)(pmem_addr + addr);
1313170SN/A}*/
1323170SN/A
1333170SN/A
1343170SN/A#endif //__PHYSICAL_MEMORY_HH__
1354626SN/A