port.cc revision 5605
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()
525605Snate@binkert.org        : Port("default_port", NULL)
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(const std::string &_name, MemObject *_owner)
945605Snate@binkert.org    : EventManager(_owner), portName(_name), peer(&defaultPeerPort),
955605Snate@binkert.org      owner(_owner)
965476Snate@binkert.org{
975476Snate@binkert.org}
985476Snate@binkert.org
995476Snate@binkert.orgPort::~Port()
1005283Sgblack@eecs.umich.edu{
1015283Sgblack@eecs.umich.edu}
1025283Sgblack@eecs.umich.edu
1032405SN/Avoid
1042642Sstever@eecs.umich.eduPort::setPeer(Port *port)
1052642Sstever@eecs.umich.edu{
1065494Sstever@gmail.com    DPRINTF(Config, "setting peer to %s\n", port->name());
1075476Snate@binkert.org
1082642Sstever@eecs.umich.edu    peer = port;
1092642Sstever@eecs.umich.edu}
1102642Sstever@eecs.umich.edu
1112642Sstever@eecs.umich.eduvoid
1125605Snate@binkert.orgPort::setOwner(MemObject *_owner)
1135605Snate@binkert.org{
1145605Snate@binkert.org    eventq = _owner->queue();
1155605Snate@binkert.org    owner = _owner;
1165605Snate@binkert.org}
1175605Snate@binkert.org
1185605Snate@binkert.orgvoid
1195494Sstever@gmail.comPort::removeConn()
1205494Sstever@gmail.com{
1215494Sstever@gmail.com    if (peer->getOwner())
1225494Sstever@gmail.com        peer->getOwner()->deletePortRefs(peer);
1235494Sstever@gmail.com    peer = NULL;
1245494Sstever@gmail.com}
1255494Sstever@gmail.com
1265494Sstever@gmail.comvoid
1274022Sstever@eecs.umich.eduPort::blobHelper(Addr addr, uint8_t *p, int size, MemCmd cmd)
1282405SN/A{
1292663Sstever@eecs.umich.edu    Request req;
1302405SN/A
1312406SN/A    for (ChunkGenerator gen(addr, size, peerBlockSize());
1322406SN/A         !gen.done(); gen.next()) {
1332663Sstever@eecs.umich.edu        req.setPhys(gen.addr(), gen.size(), 0);
1344870Sstever@eecs.umich.edu        Packet pkt(&req, cmd, Packet::Broadcast);
1352566SN/A        pkt.dataStatic(p);
1362630SN/A        sendFunctional(&pkt);
1372405SN/A        p += gen.size();
1382405SN/A    }
1392405SN/A}
1402405SN/A
1412405SN/Avoid
1422461SN/APort::writeBlob(Addr addr, uint8_t *p, int size)
1432405SN/A{
1444022Sstever@eecs.umich.edu    blobHelper(addr, p, size, MemCmd::WriteReq);
1452405SN/A}
1462405SN/A
1472405SN/Avoid
1482461SN/APort::readBlob(Addr addr, uint8_t *p, int size)
1492405SN/A{
1504022Sstever@eecs.umich.edu    blobHelper(addr, p, size, MemCmd::ReadReq);
1512405SN/A}
1522405SN/A
1532420SN/Avoid
1542461SN/APort::memsetBlob(Addr addr, uint8_t val, int size)
1552420SN/A{
1562420SN/A    // quick and dirty...
1572420SN/A    uint8_t *buf = new uint8_t[size];
1582420SN/A
1593918Ssaidi@eecs.umich.edu    std::memset(buf, val, size);
1604022Sstever@eecs.umich.edu    blobHelper(addr, buf, size, MemCmd::WriteReq);
1612421SN/A
1622548SN/A    delete [] buf;
1632420SN/A}
1645314Sstever@gmail.com
1655314Sstever@gmail.com
1665314Sstever@gmail.comvoid
1675314Sstever@gmail.comPort::printAddr(Addr a)
1685314Sstever@gmail.com{
1695314Sstever@gmail.com    Request req(a, 1, 0);
1705314Sstever@gmail.com    Packet pkt(&req, MemCmd::PrintReq, Packet::Broadcast);
1715314Sstever@gmail.com    Packet::PrintReqState prs(std::cerr);
1725314Sstever@gmail.com    pkt.senderState = &prs;
1735314Sstever@gmail.com
1745314Sstever@gmail.com    sendFunctional(&pkt);
1755314Sstever@gmail.com}
176