io_device.cc revision 9294
18889Sgeoffrey.blake@arm.com/* 28889Sgeoffrey.blake@arm.com * Copyright (c) 2012 ARM Limited 38889Sgeoffrey.blake@arm.com * All rights reserved. 410036SAli.Saidi@ARM.com * 58889Sgeoffrey.blake@arm.com * The license below extends only to copyright in the software and shall 610036SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual 78889Sgeoffrey.blake@arm.com * property including but not limited to intellectual property relating 88889Sgeoffrey.blake@arm.com * to a hardware implementation of the functionality of the software 98889Sgeoffrey.blake@arm.com * licensed hereunder. You may use the software subject to the license 108889Sgeoffrey.blake@arm.com * terms below provided that you ensure that this notice is replicated 118889Sgeoffrey.blake@arm.com * unmodified and in its entirety in all distributions of the software, 128889Sgeoffrey.blake@arm.com * modified or unmodified, in source code or in binary form. 139885Sstever@gmail.com * 148889Sgeoffrey.blake@arm.com * Copyright (c) 2006 The Regents of The University of Michigan 159885Sstever@gmail.com * All rights reserved. 169885Sstever@gmail.com * 1710036SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without 188889Sgeoffrey.blake@arm.com * modification, are permitted provided that the following conditions are 198889Sgeoffrey.blake@arm.com * met: redistributions of source code must retain the above copyright 208889Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer; 218889Sgeoffrey.blake@arm.com * redistributions in binary form must reproduce the above copyright 229481Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer in the 238889Sgeoffrey.blake@arm.com * documentation and/or other materials provided with the distribution; 248889Sgeoffrey.blake@arm.com * neither the name of the copyright holders nor the names of its 258889Sgeoffrey.blake@arm.com * contributors may be used to endorse or promote products derived from 268889Sgeoffrey.blake@arm.com * this software without specific prior written permission. 278889Sgeoffrey.blake@arm.com * 288889Sgeoffrey.blake@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 298889Sgeoffrey.blake@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 308889Sgeoffrey.blake@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 318889Sgeoffrey.blake@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 328889Sgeoffrey.blake@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 338889Sgeoffrey.blake@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 348889Sgeoffrey.blake@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 358889Sgeoffrey.blake@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 369885Sstever@gmail.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 379885Sstever@gmail.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 389885Sstever@gmail.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3910036SAli.Saidi@ARM.com * 409885Sstever@gmail.com * Authors: Ali Saidi 419885Sstever@gmail.com * Nathan Binkert 428889Sgeoffrey.blake@arm.com */ 438889Sgeoffrey.blake@arm.com 449481Snilay@cs.wisc.edu#include "base/trace.hh" 458889Sgeoffrey.blake@arm.com#include "debug/BusAddrRanges.hh" 469885Sstever@gmail.com#include "dev/io_device.hh" 478889Sgeoffrey.blake@arm.com#include "sim/system.hh" 488889Sgeoffrey.blake@arm.com 498889Sgeoffrey.blake@arm.comPioPort::PioPort(PioDevice *dev) 508889Sgeoffrey.blake@arm.com : SimpleTimingPort(dev->name() + ".pio", dev), device(dev) 518889Sgeoffrey.blake@arm.com{ 5210036SAli.Saidi@ARM.com} 538983Snate@binkert.org 548889Sgeoffrey.blake@arm.comTick 558889Sgeoffrey.blake@arm.comPioPort::recvAtomic(PacketPtr pkt) 568889Sgeoffrey.blake@arm.com{ 579481Snilay@cs.wisc.edu return pkt->isRead() ? device->read(pkt) : device->write(pkt); 588889Sgeoffrey.blake@arm.com} 598889Sgeoffrey.blake@arm.com 608889Sgeoffrey.blake@arm.comAddrRangeList 618889Sgeoffrey.blake@arm.comPioPort::getAddrRanges() const 628889Sgeoffrey.blake@arm.com{ 638889Sgeoffrey.blake@arm.com return device->getAddrRanges(); 648889Sgeoffrey.blake@arm.com} 658889Sgeoffrey.blake@arm.com 669885Sstever@gmail.comPioDevice::PioDevice(const Params *p) 679885Sstever@gmail.com : MemObject(p), sys(p->system), pioPort(this) 689885Sstever@gmail.com{} 699885Sstever@gmail.com 708889Sgeoffrey.blake@arm.comPioDevice::~PioDevice() 718889Sgeoffrey.blake@arm.com{ 729481Snilay@cs.wisc.edu} 738889Sgeoffrey.blake@arm.com 748889Sgeoffrey.blake@arm.comvoid 758889Sgeoffrey.blake@arm.comPioDevice::init() 768889Sgeoffrey.blake@arm.com{ 778889Sgeoffrey.blake@arm.com if (!pioPort.isConnected()) 788889Sgeoffrey.blake@arm.com panic("Pio port of %s not connected to anything!", name()); 798889Sgeoffrey.blake@arm.com pioPort.sendRangeChange(); 808889Sgeoffrey.blake@arm.com} 818889Sgeoffrey.blake@arm.com 829481Snilay@cs.wisc.eduBaseSlavePort & 838889Sgeoffrey.blake@arm.comPioDevice::getSlavePort(const std::string &if_name, PortID idx) 849885Sstever@gmail.com{ 858889Sgeoffrey.blake@arm.com if (if_name == "pio") { 868889Sgeoffrey.blake@arm.com return pioPort; 878889Sgeoffrey.blake@arm.com } 888889Sgeoffrey.blake@arm.com return MemObject::getSlavePort(if_name, idx); 898889Sgeoffrey.blake@arm.com} 9010036SAli.Saidi@ARM.com 919885Sstever@gmail.comunsigned int 928889Sgeoffrey.blake@arm.comPioDevice::drain(Event *de) 938889Sgeoffrey.blake@arm.com{ 948889Sgeoffrey.blake@arm.com unsigned int count; 959481Snilay@cs.wisc.edu count = pioPort.drain(de); 968889Sgeoffrey.blake@arm.com if (count) 978889Sgeoffrey.blake@arm.com changeState(Draining); 988889Sgeoffrey.blake@arm.com else 998889Sgeoffrey.blake@arm.com changeState(Drained); 1008889Sgeoffrey.blake@arm.com return count; 1018889Sgeoffrey.blake@arm.com} 1028889Sgeoffrey.blake@arm.com 1038889Sgeoffrey.blake@arm.comBasicPioDevice::BasicPioDevice(const Params *p) 1049885Sstever@gmail.com : PioDevice(p), pioAddr(p->pio_addr), pioSize(0), 1059481Snilay@cs.wisc.edu pioDelay(p->pio_latency) 1068889Sgeoffrey.blake@arm.com{} 1078889Sgeoffrey.blake@arm.com 1089885Sstever@gmail.comAddrRangeList 1099885Sstever@gmail.comBasicPioDevice::getAddrRanges() const 1108889Sgeoffrey.blake@arm.com{ 1118889Sgeoffrey.blake@arm.com assert(pioSize != 0); 1128889Sgeoffrey.blake@arm.com AddrRangeList ranges; 1138889Sgeoffrey.blake@arm.com DPRINTF(BusAddrRanges, "registering range: %#x-%#x\n", pioAddr, pioSize); 1148889Sgeoffrey.blake@arm.com ranges.push_back(RangeSize(pioAddr, pioSize)); 11510036SAli.Saidi@ARM.com return ranges; 1168889Sgeoffrey.blake@arm.com} 1178889Sgeoffrey.blake@arm.com