io_device.cc revision 9808
1545SN/A/*
28948Sandreas.hansson@arm.com * Copyright (c) 2012 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
442657Ssaidi@eecs.umich.edu#include "base/trace.hh"
458232Snate@binkert.org#include "debug/BusAddrRanges.hh"
46545SN/A#include "dev/io_device.hh"
472901Ssaidi@eecs.umich.edu#include "sim/system.hh"
48545SN/A
498914Sandreas.hansson@arm.comPioPort::PioPort(PioDevice *dev)
509095Sandreas.hansson@arm.com    : SimpleTimingPort(dev->name() + ".pio", dev), device(dev)
518914Sandreas.hansson@arm.com{
528914Sandreas.hansson@arm.com}
532489SN/A
542489SN/ATick
553349Sbinkertn@umich.eduPioPort::recvAtomic(PacketPtr pkt)
562489SN/A{
579549Sandreas.hansson@arm.com    // @todo: We need to pay for this and not just zero it out
589549Sandreas.hansson@arm.com    pkt->busFirstWordDelay = pkt->busLastWordDelay = 0;
599549Sandreas.hansson@arm.com
603091Sstever@eecs.umich.edu    return pkt->isRead() ? device->read(pkt) : device->write(pkt);
612489SN/A}
622489SN/A
638711Sandreas.hansson@arm.comAddrRangeList
649090Sandreas.hansson@arm.comPioPort::getAddrRanges() const
652489SN/A{
668711Sandreas.hansson@arm.com    return device->getAddrRanges();
672489SN/A}
682489SN/A
694762Snate@binkert.orgPioDevice::PioDevice(const Params *p)
708914Sandreas.hansson@arm.com    : MemObject(p), sys(p->system), pioPort(this)
714762Snate@binkert.org{}
724762Snate@binkert.org
73545SN/APioDevice::~PioDevice()
74545SN/A{
75545SN/A}
76545SN/A
772542SN/Avoid
782541SN/APioDevice::init()
792541SN/A{
808851Sandreas.hansson@arm.com    if (!pioPort.isConnected())
818674Snilay@cs.wisc.edu        panic("Pio port of %s not connected to anything!", name());
828851Sandreas.hansson@arm.com    pioPort.sendRangeChange();
832541SN/A}
842541SN/A
859294Sandreas.hansson@arm.comBaseSlavePort &
869294Sandreas.hansson@arm.comPioDevice::getSlavePort(const std::string &if_name, PortID idx)
878598Ssteve.reinhardt@amd.com{
888598Ssteve.reinhardt@amd.com    if (if_name == "pio") {
898922Swilliam.wang@arm.com        return pioPort;
908598Ssteve.reinhardt@amd.com    }
918922Swilliam.wang@arm.com    return MemObject::getSlavePort(if_name, idx);
928598Ssteve.reinhardt@amd.com}
932901Ssaidi@eecs.umich.edu
942901Ssaidi@eecs.umich.eduunsigned int
959342SAndreas.Sandberg@arm.comPioDevice::drain(DrainManager *dm)
962901Ssaidi@eecs.umich.edu{
972901Ssaidi@eecs.umich.edu    unsigned int count;
989342SAndreas.Sandberg@arm.com    count = pioPort.drain(dm);
992901Ssaidi@eecs.umich.edu    if (count)
1009342SAndreas.Sandberg@arm.com        setDrainState(Drainable::Draining);
1012901Ssaidi@eecs.umich.edu    else
1029342SAndreas.Sandberg@arm.com        setDrainState(Drainable::Drained);
1032901Ssaidi@eecs.umich.edu    return count;
1042901Ssaidi@eecs.umich.edu}
1052901Ssaidi@eecs.umich.edu
1069808Sstever@gmail.comBasicPioDevice::BasicPioDevice(const Params *p, Addr size)
1079808Sstever@gmail.com    : PioDevice(p), pioAddr(p->pio_addr), pioSize(size),
1084762Snate@binkert.org      pioDelay(p->pio_latency)
1094762Snate@binkert.org{}
1104762Snate@binkert.org
1118711Sandreas.hansson@arm.comAddrRangeList
1129090Sandreas.hansson@arm.comBasicPioDevice::getAddrRanges() const
1132539SN/A{
1142539SN/A    assert(pioSize != 0);
1158711Sandreas.hansson@arm.com    AddrRangeList ranges;
1167729SAli.Saidi@ARM.com    DPRINTF(BusAddrRanges, "registering range: %#x-%#x\n", pioAddr, pioSize);
1178711Sandreas.hansson@arm.com    ranges.push_back(RangeSize(pioAddr, pioSize));
1188711Sandreas.hansson@arm.com    return ranges;
1192539SN/A}
120