port.cc revision 5494
12405SN/A/*
22405SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32405SN/A * All rights reserved.
42405SN/A *
52405SN/A * Redistribution and use in source and binary forms, with or without
62405SN/A * modification, are permitted provided that the following conditions are
72405SN/A * met: redistributions of source code must retain the above copyright
82405SN/A * notice, this list of conditions and the following disclaimer;
92405SN/A * redistributions in binary form must reproduce the above copyright
102405SN/A * notice, this list of conditions and the following disclaimer in the
112405SN/A * documentation and/or other materials provided with the distribution;
122405SN/A * neither the name of the copyright holders nor the names of its
132405SN/A * contributors may be used to endorse or promote products derived from
142405SN/A * this software without specific prior written permission.
152405SN/A *
162405SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172405SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182405SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192405SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202405SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212405SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222405SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232405SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242405SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252405SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262405SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
292405SN/A */
302405SN/A
312405SN/A/**
322982Sstever@eecs.umich.edu * @file
332982Sstever@eecs.umich.edu * Port object definitions.
342405SN/A */
353918Ssaidi@eecs.umich.edu#include <cstring>
362405SN/A
372405SN/A#include "base/chunk_generator.hh"
382642Sstever@eecs.umich.edu#include "base/trace.hh"
394190Ssaidi@eecs.umich.edu#include "mem/mem_object.hh"
402405SN/A#include "mem/port.hh"
412405SN/A
425476Snate@binkert.orgclass DefaultPeerPort : public Port
435283Sgblack@eecs.umich.edu{
445283Sgblack@eecs.umich.edu  protected:
455283Sgblack@eecs.umich.edu    void blowUp()
465283Sgblack@eecs.umich.edu    {
475494Sstever@gmail.com        fatal("%s: Unconnected port!", peer->name());
485283Sgblack@eecs.umich.edu    }
495283Sgblack@eecs.umich.edu
505283Sgblack@eecs.umich.edu  public:
515494Sstever@gmail.com    DefaultPeerPort()
525494Sstever@gmail.com        : Port("default_port")
535476Snate@binkert.org    { }
545283Sgblack@eecs.umich.edu
555283Sgblack@eecs.umich.edu    bool recvTiming(PacketPtr)
565283Sgblack@eecs.umich.edu    {
575283Sgblack@eecs.umich.edu        blowUp();
585283Sgblack@eecs.umich.edu        return false;
595283Sgblack@eecs.umich.edu    }
605283Sgblack@eecs.umich.edu
615283Sgblack@eecs.umich.edu    Tick recvAtomic(PacketPtr)
625283Sgblack@eecs.umich.edu    {
635283Sgblack@eecs.umich.edu        blowUp();
645283Sgblack@eecs.umich.edu        return 0;
655283Sgblack@eecs.umich.edu    }
665283Sgblack@eecs.umich.edu
675283Sgblack@eecs.umich.edu    void recvFunctional(PacketPtr)
685283Sgblack@eecs.umich.edu    {
695283Sgblack@eecs.umich.edu        blowUp();
705283Sgblack@eecs.umich.edu    }
715283Sgblack@eecs.umich.edu
725283Sgblack@eecs.umich.edu    void recvStatusChange(Status)
735283Sgblack@eecs.umich.edu    {
745283Sgblack@eecs.umich.edu        blowUp();
755283Sgblack@eecs.umich.edu    }
765283Sgblack@eecs.umich.edu
775283Sgblack@eecs.umich.edu    int deviceBlockSize()
785283Sgblack@eecs.umich.edu    {
795283Sgblack@eecs.umich.edu        blowUp();
805283Sgblack@eecs.umich.edu        return 0;
815283Sgblack@eecs.umich.edu    }
825283Sgblack@eecs.umich.edu
835283Sgblack@eecs.umich.edu    void getDeviceAddressRanges(AddrRangeList &, bool &)
845283Sgblack@eecs.umich.edu    {
855283Sgblack@eecs.umich.edu        blowUp();
865283Sgblack@eecs.umich.edu    }
875283Sgblack@eecs.umich.edu
885476Snate@binkert.org    bool isDefaultPort() const { return true; }
895476Snate@binkert.org};
905283Sgblack@eecs.umich.edu
915494Sstever@gmail.comDefaultPeerPort defaultPeerPort;
925283Sgblack@eecs.umich.edu
935494Sstever@gmail.comPort::Port()
945494Sstever@gmail.com    : peer(&defaultPeerPort), owner(NULL)
955494Sstever@gmail.com{
965494Sstever@gmail.com}
975494Sstever@gmail.com
985494Sstever@gmail.comPort::Port(const std::string &_name, MemObject *_owner)
995494Sstever@gmail.com    : portName(_name), peer(&defaultPeerPort), owner(_owner)
1005476Snate@binkert.org{
1015476Snate@binkert.org}
1025476Snate@binkert.org
1035476Snate@binkert.orgPort::~Port()
1045283Sgblack@eecs.umich.edu{
1055283Sgblack@eecs.umich.edu}
1065283Sgblack@eecs.umich.edu
1072405SN/Avoid
1082642Sstever@eecs.umich.eduPort::setPeer(Port *port)
1092642Sstever@eecs.umich.edu{
1105494Sstever@gmail.com    DPRINTF(Config, "setting peer to %s\n", port->name());
1115476Snate@binkert.org
1122642Sstever@eecs.umich.edu    peer = port;
1132642Sstever@eecs.umich.edu}
1142642Sstever@eecs.umich.edu
1152642Sstever@eecs.umich.eduvoid
1165494Sstever@gmail.comPort::removeConn()
1175494Sstever@gmail.com{
1185494Sstever@gmail.com    if (peer->getOwner())
1195494Sstever@gmail.com        peer->getOwner()->deletePortRefs(peer);
1205494Sstever@gmail.com    peer = NULL;
1215494Sstever@gmail.com}
1225494Sstever@gmail.com
1235494Sstever@gmail.comvoid
1244022Sstever@eecs.umich.eduPort::blobHelper(Addr addr, uint8_t *p, int size, MemCmd cmd)
1252405SN/A{
1262663Sstever@eecs.umich.edu    Request req;
1272405SN/A
1282406SN/A    for (ChunkGenerator gen(addr, size, peerBlockSize());
1292406SN/A         !gen.done(); gen.next()) {
1302663Sstever@eecs.umich.edu        req.setPhys(gen.addr(), gen.size(), 0);
1314870Sstever@eecs.umich.edu        Packet pkt(&req, cmd, Packet::Broadcast);
1322566SN/A        pkt.dataStatic(p);
1332630SN/A        sendFunctional(&pkt);
1342405SN/A        p += gen.size();
1352405SN/A    }
1362405SN/A}
1372405SN/A
1382405SN/Avoid
1392461SN/APort::writeBlob(Addr addr, uint8_t *p, int size)
1402405SN/A{
1414022Sstever@eecs.umich.edu    blobHelper(addr, p, size, MemCmd::WriteReq);
1422405SN/A}
1432405SN/A
1442405SN/Avoid
1452461SN/APort::readBlob(Addr addr, uint8_t *p, int size)
1462405SN/A{
1474022Sstever@eecs.umich.edu    blobHelper(addr, p, size, MemCmd::ReadReq);
1482405SN/A}
1492405SN/A
1502420SN/Avoid
1512461SN/APort::memsetBlob(Addr addr, uint8_t val, int size)
1522420SN/A{
1532420SN/A    // quick and dirty...
1542420SN/A    uint8_t *buf = new uint8_t[size];
1552420SN/A
1563918Ssaidi@eecs.umich.edu    std::memset(buf, val, size);
1574022Sstever@eecs.umich.edu    blobHelper(addr, buf, size, MemCmd::WriteReq);
1582421SN/A
1592548SN/A    delete [] buf;
1602420SN/A}
1615314Sstever@gmail.com
1625314Sstever@gmail.com
1635314Sstever@gmail.comvoid
1645314Sstever@gmail.comPort::printAddr(Addr a)
1655314Sstever@gmail.com{
1665314Sstever@gmail.com    Request req(a, 1, 0);
1675314Sstever@gmail.com    Packet pkt(&req, MemCmd::PrintReq, Packet::Broadcast);
1685314Sstever@gmail.com    Packet::PrintReqState prs(std::cerr);
1695314Sstever@gmail.com    pkt.senderState = &prs;
1705314Sstever@gmail.com
1715314Sstever@gmail.com    sendFunctional(&pkt);
1725314Sstever@gmail.com}
173