port.cc revision 4190
13560SN/A/*
23560SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
33560SN/A * All rights reserved.
43560SN/A *
53560SN/A * Redistribution and use in source and binary forms, with or without
63560SN/A * modification, are permitted provided that the following conditions are
73560SN/A * met: redistributions of source code must retain the above copyright
83560SN/A * notice, this list of conditions and the following disclaimer;
93560SN/A * redistributions in binary form must reproduce the above copyright
103560SN/A * notice, this list of conditions and the following disclaimer in the
113560SN/A * documentation and/or other materials provided with the distribution;
123560SN/A * neither the name of the copyright holders nor the names of its
133560SN/A * contributors may be used to endorse or promote products derived from
143560SN/A * this software without specific prior written permission.
153560SN/A *
163560SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173560SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183560SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193560SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203560SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213560SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223560SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233560SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243560SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253560SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263560SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273560SN/A *
283560SN/A * Authors: Steve Reinhardt
293560SN/A */
303560SN/A
313560SN/A/**
323560SN/A * @file
333560SN/A * Port object definitions.
343560SN/A */
353560SN/A#include <cstring>
365191Ssaidi@eecs.umich.edu
373565Sgblack@eecs.umich.edu#include "base/chunk_generator.hh"
383560SN/A#include "base/trace.hh"
393560SN/A#include "mem/mem_object.hh"
403560SN/A#include "mem/port.hh"
413560SN/A
423560SN/Avoid
433560SN/APort::setPeer(Port *port)
443560SN/A{
453560SN/A    DPRINTF(Config, "setting peer to %s\n", port->name());
463560SN/A    peer = port;
473560SN/A}
483560SN/A
493560SN/Avoid
503560SN/APort::removeConn()
513560SN/A{
523560SN/A    if (peer->getOwner())
533560SN/A        peer->getOwner()->deletePortRefs(peer);
543560SN/A    delete peer;
553560SN/A    peer = NULL;
563560SN/A}
573560SN/A
583560SN/Avoid
593560SN/APort::blobHelper(Addr addr, uint8_t *p, int size, MemCmd cmd)
603560SN/A{
613560SN/A    Request req;
623560SN/A    Packet pkt(&req, cmd, Packet::Broadcast);
633560SN/A
643560SN/A    for (ChunkGenerator gen(addr, size, peerBlockSize());
653560SN/A         !gen.done(); gen.next()) {
663560SN/A        req.setPhys(gen.addr(), gen.size(), 0);
673560SN/A        pkt.reinitFromRequest();
683560SN/A        pkt.dataStatic(p);
693560SN/A        sendFunctional(&pkt);
703560SN/A        p += gen.size();
713560SN/A    }
723560SN/A}
733560SN/A
743560SN/Avoid
753560SN/APort::writeBlob(Addr addr, uint8_t *p, int size)
763560SN/A{
773560SN/A    blobHelper(addr, p, size, MemCmd::WriteReq);
783560SN/A}
793560SN/A
803560SN/Avoid
813560SN/APort::readBlob(Addr addr, uint8_t *p, int size)
823560SN/A{
833560SN/A    blobHelper(addr, p, size, MemCmd::ReadReq);
843560SN/A}
853560SN/A
863560SN/Avoid
873560SN/APort::memsetBlob(Addr addr, uint8_t val, int size)
883560SN/A{
893560SN/A    // quick and dirty...
903560SN/A    uint8_t *buf = new uint8_t[size];
913560SN/A
923560SN/A    std::memset(buf, val, size);
933560SN/A    blobHelper(addr, buf, size, MemCmd::WriteReq);
943560SN/A
953560SN/A    delete [] buf;
963560SN/A}
973560SN/A