io_device.cc revision 11793
1545SN/A/*
211193Sandreas.hansson@arm.com * Copyright (c) 2012, 2015 ARM Limited
38948Sandreas.hansson@arm.com * All rights reserved.
48948Sandreas.hansson@arm.com *
58948Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68948Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78948Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88948Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98948Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108948Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118948Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128948Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138948Sandreas.hansson@arm.com *
142512SN/A * Copyright (c) 2006 The Regents of The University of Michigan
15545SN/A * All rights reserved.
16545SN/A *
17545SN/A * Redistribution and use in source and binary forms, with or without
18545SN/A * modification, are permitted provided that the following conditions are
19545SN/A * met: redistributions of source code must retain the above copyright
20545SN/A * notice, this list of conditions and the following disclaimer;
21545SN/A * redistributions in binary form must reproduce the above copyright
22545SN/A * notice, this list of conditions and the following disclaimer in the
23545SN/A * documentation and/or other materials provided with the distribution;
24545SN/A * neither the name of the copyright holders nor the names of its
25545SN/A * contributors may be used to endorse or promote products derived from
26545SN/A * this software without specific prior written permission.
27545SN/A *
28545SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29545SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30545SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31545SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32545SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33545SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34545SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35545SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36545SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37545SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38545SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665Ssaidi@eecs.umich.edu *
402665Ssaidi@eecs.umich.edu * Authors: Ali Saidi
412665Ssaidi@eecs.umich.edu *          Nathan Binkert
42545SN/A */
43545SN/A
4411793Sbrandon.potter@amd.com#include "dev/io_device.hh"
4511793Sbrandon.potter@amd.com
462657Ssaidi@eecs.umich.edu#include "base/trace.hh"
4710405Sandreas.hansson@arm.com#include "debug/AddrRanges.hh"
482901Ssaidi@eecs.umich.edu#include "sim/system.hh"
49545SN/A
508914Sandreas.hansson@arm.comPioPort::PioPort(PioDevice *dev)
519095Sandreas.hansson@arm.com    : SimpleTimingPort(dev->name() + ".pio", dev), device(dev)
528914Sandreas.hansson@arm.com{
538914Sandreas.hansson@arm.com}
542489SN/A
552489SN/ATick
563349Sbinkertn@umich.eduPioPort::recvAtomic(PacketPtr pkt)
572489SN/A{
5811193Sandreas.hansson@arm.com    // technically the packet only reaches us after the header delay,
5911193Sandreas.hansson@arm.com    // and typically we also need to deserialise any payload
6011193Sandreas.hansson@arm.com    Tick receive_delay = pkt->headerDelay + pkt->payloadDelay;
6110694SMarco.Balboni@ARM.com    pkt->headerDelay = pkt->payloadDelay = 0;
629549Sandreas.hansson@arm.com
6310603SAndreas.Sandberg@ARM.com    const Tick delay(pkt->isRead() ? device->read(pkt) : device->write(pkt));
6410603SAndreas.Sandberg@ARM.com    assert(pkt->isResponse() || pkt->isError());
6511193Sandreas.hansson@arm.com    return delay + receive_delay;
662489SN/A}
672489SN/A
688711Sandreas.hansson@arm.comAddrRangeList
699090Sandreas.hansson@arm.comPioPort::getAddrRanges() const
702489SN/A{
718711Sandreas.hansson@arm.com    return device->getAddrRanges();
722489SN/A}
732489SN/A
744762Snate@binkert.orgPioDevice::PioDevice(const Params *p)
758914Sandreas.hansson@arm.com    : MemObject(p), sys(p->system), pioPort(this)
764762Snate@binkert.org{}
774762Snate@binkert.org
78545SN/APioDevice::~PioDevice()
79545SN/A{
80545SN/A}
81545SN/A
822542SN/Avoid
832541SN/APioDevice::init()
842541SN/A{
858851Sandreas.hansson@arm.com    if (!pioPort.isConnected())
868674Snilay@cs.wisc.edu        panic("Pio port of %s not connected to anything!", name());
878851Sandreas.hansson@arm.com    pioPort.sendRangeChange();
882541SN/A}
892541SN/A
909294Sandreas.hansson@arm.comBaseSlavePort &
919294Sandreas.hansson@arm.comPioDevice::getSlavePort(const std::string &if_name, PortID idx)
928598Ssteve.reinhardt@amd.com{
938598Ssteve.reinhardt@amd.com    if (if_name == "pio") {
948922Swilliam.wang@arm.com        return pioPort;
958598Ssteve.reinhardt@amd.com    }
968922Swilliam.wang@arm.com    return MemObject::getSlavePort(if_name, idx);
978598Ssteve.reinhardt@amd.com}
982901Ssaidi@eecs.umich.edu
999808Sstever@gmail.comBasicPioDevice::BasicPioDevice(const Params *p, Addr size)
1009808Sstever@gmail.com    : PioDevice(p), pioAddr(p->pio_addr), pioSize(size),
1014762Snate@binkert.org      pioDelay(p->pio_latency)
1024762Snate@binkert.org{}
1034762Snate@binkert.org
1048711Sandreas.hansson@arm.comAddrRangeList
1059090Sandreas.hansson@arm.comBasicPioDevice::getAddrRanges() const
1062539SN/A{
1072539SN/A    assert(pioSize != 0);
1088711Sandreas.hansson@arm.com    AddrRangeList ranges;
10910405Sandreas.hansson@arm.com    DPRINTF(AddrRanges, "registering range: %#x-%#x\n", pioAddr, pioSize);
1108711Sandreas.hansson@arm.com    ranges.push_back(RangeSize(pioAddr, pioSize));
1118711Sandreas.hansson@arm.com    return ranges;
1122539SN/A}
113