io_device.cc revision 9342
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{ 573091Sstever@eecs.umich.edu return pkt->isRead() ? device->read(pkt) : device->write(pkt); 582489SN/A} 592489SN/A 608711Sandreas.hansson@arm.comAddrRangeList 619090Sandreas.hansson@arm.comPioPort::getAddrRanges() const 622489SN/A{ 638711Sandreas.hansson@arm.com return device->getAddrRanges(); 642489SN/A} 652489SN/A 664762Snate@binkert.orgPioDevice::PioDevice(const Params *p) 678914Sandreas.hansson@arm.com : MemObject(p), sys(p->system), pioPort(this) 684762Snate@binkert.org{} 694762Snate@binkert.org 70545SN/APioDevice::~PioDevice() 71545SN/A{ 72545SN/A} 73545SN/A 742542SN/Avoid 752541SN/APioDevice::init() 762541SN/A{ 778851Sandreas.hansson@arm.com if (!pioPort.isConnected()) 788674Snilay@cs.wisc.edu panic("Pio port of %s not connected to anything!", name()); 798851Sandreas.hansson@arm.com pioPort.sendRangeChange(); 802541SN/A} 812541SN/A 829294Sandreas.hansson@arm.comBaseSlavePort & 839294Sandreas.hansson@arm.comPioDevice::getSlavePort(const std::string &if_name, PortID idx) 848598Ssteve.reinhardt@amd.com{ 858598Ssteve.reinhardt@amd.com if (if_name == "pio") { 868922Swilliam.wang@arm.com return pioPort; 878598Ssteve.reinhardt@amd.com } 888922Swilliam.wang@arm.com return MemObject::getSlavePort(if_name, idx); 898598Ssteve.reinhardt@amd.com} 902901Ssaidi@eecs.umich.edu 912901Ssaidi@eecs.umich.eduunsigned int 929342SAndreas.Sandberg@arm.comPioDevice::drain(DrainManager *dm) 932901Ssaidi@eecs.umich.edu{ 942901Ssaidi@eecs.umich.edu unsigned int count; 959342SAndreas.Sandberg@arm.com count = pioPort.drain(dm); 962901Ssaidi@eecs.umich.edu if (count) 979342SAndreas.Sandberg@arm.com setDrainState(Drainable::Draining); 982901Ssaidi@eecs.umich.edu else 999342SAndreas.Sandberg@arm.com setDrainState(Drainable::Drained); 1002901Ssaidi@eecs.umich.edu return count; 1012901Ssaidi@eecs.umich.edu} 1022901Ssaidi@eecs.umich.edu 1034762Snate@binkert.orgBasicPioDevice::BasicPioDevice(const Params *p) 1044762Snate@binkert.org : PioDevice(p), pioAddr(p->pio_addr), pioSize(0), 1054762Snate@binkert.org pioDelay(p->pio_latency) 1064762Snate@binkert.org{} 1074762Snate@binkert.org 1088711Sandreas.hansson@arm.comAddrRangeList 1099090Sandreas.hansson@arm.comBasicPioDevice::getAddrRanges() const 1102539SN/A{ 1112539SN/A assert(pioSize != 0); 1128711Sandreas.hansson@arm.com AddrRangeList ranges; 1137729SAli.Saidi@ARM.com DPRINTF(BusAddrRanges, "registering range: %#x-%#x\n", pioAddr, pioSize); 1148711Sandreas.hansson@arm.com ranges.push_back(RangeSize(pioAddr, pioSize)); 1158711Sandreas.hansson@arm.com return ranges; 1162539SN/A} 117