external_master.cc revision 11800
110478SAndrew.Bardsley@arm.com/* 210478SAndrew.Bardsley@arm.com * Copyright (c) 2012-2014 ARM Limited 310478SAndrew.Bardsley@arm.com * All rights reserved 410478SAndrew.Bardsley@arm.com * 510478SAndrew.Bardsley@arm.com * The license below extends only to copyright in the software and shall 610478SAndrew.Bardsley@arm.com * not be construed as granting a license to any other intellectual 710478SAndrew.Bardsley@arm.com * property including but not limited to intellectual property relating 810478SAndrew.Bardsley@arm.com * to a hardware implementation of the functionality of the software 910478SAndrew.Bardsley@arm.com * licensed hereunder. You may use the software subject to the license 1010478SAndrew.Bardsley@arm.com * terms below provided that you ensure that this notice is replicated 1110478SAndrew.Bardsley@arm.com * unmodified and in its entirety in all distributions of the software, 1210478SAndrew.Bardsley@arm.com * modified or unmodified, in source code or in binary form. 1310478SAndrew.Bardsley@arm.com * 1410478SAndrew.Bardsley@arm.com * Redistribution and use in source and binary forms, with or without 1510478SAndrew.Bardsley@arm.com * modification, are permitted provided that the following conditions are 1610478SAndrew.Bardsley@arm.com * met: redistributions of source code must retain the above copyright 1710478SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer; 1810478SAndrew.Bardsley@arm.com * redistributions in binary form must reproduce the above copyright 1910478SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer in the 2010478SAndrew.Bardsley@arm.com * documentation and/or other materials provided with the distribution; 2110478SAndrew.Bardsley@arm.com * neither the name of the copyright holders nor the names of its 2210478SAndrew.Bardsley@arm.com * contributors may be used to endorse or promote products derived from 2310478SAndrew.Bardsley@arm.com * this software without specific prior written permission. 2410478SAndrew.Bardsley@arm.com * 2510478SAndrew.Bardsley@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2610478SAndrew.Bardsley@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2710478SAndrew.Bardsley@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2810478SAndrew.Bardsley@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2910478SAndrew.Bardsley@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3010478SAndrew.Bardsley@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3110478SAndrew.Bardsley@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3210478SAndrew.Bardsley@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3310478SAndrew.Bardsley@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3410478SAndrew.Bardsley@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3510478SAndrew.Bardsley@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3610478SAndrew.Bardsley@arm.com * 3710478SAndrew.Bardsley@arm.com * Authors: Andrew Bardsley 3810478SAndrew.Bardsley@arm.com * Curtis Dunham 3910478SAndrew.Bardsley@arm.com */ 4010478SAndrew.Bardsley@arm.com 4111793Sbrandon.potter@amd.com#include "mem/external_master.hh" 4211793Sbrandon.potter@amd.com 4310478SAndrew.Bardsley@arm.com#include <cctype> 4410478SAndrew.Bardsley@arm.com#include <iomanip> 4510478SAndrew.Bardsley@arm.com 4611800Sbrandon.potter@amd.com#include "base/trace.hh" 4710478SAndrew.Bardsley@arm.com#include "debug/ExternalPort.hh" 4810478SAndrew.Bardsley@arm.com 4910478SAndrew.Bardsley@arm.comstd::map<std::string, ExternalMaster::Handler *> 5010478SAndrew.Bardsley@arm.com ExternalMaster::portHandlers; 5110478SAndrew.Bardsley@arm.com 5210478SAndrew.Bardsley@arm.comExternalMaster::ExternalMaster(ExternalMasterParams *params) : 5310478SAndrew.Bardsley@arm.com MemObject(params), 5410478SAndrew.Bardsley@arm.com externalPort(NULL), 5510478SAndrew.Bardsley@arm.com portName(params->name + ".port"), 5610478SAndrew.Bardsley@arm.com portType(params->port_type), 5710478SAndrew.Bardsley@arm.com portData(params->port_data) 5810478SAndrew.Bardsley@arm.com{} 5910478SAndrew.Bardsley@arm.com 6010478SAndrew.Bardsley@arm.comBaseMasterPort & 6110478SAndrew.Bardsley@arm.comExternalMaster::getMasterPort(const std::string &if_name, 6210478SAndrew.Bardsley@arm.com PortID idx) 6310478SAndrew.Bardsley@arm.com{ 6410478SAndrew.Bardsley@arm.com if (if_name == "port") { 6510478SAndrew.Bardsley@arm.com DPRINTF(ExternalPort, "Trying to bind external port: %s %s\n", 6610478SAndrew.Bardsley@arm.com portType, portName); 6710478SAndrew.Bardsley@arm.com 6810478SAndrew.Bardsley@arm.com if (!externalPort) { 6910478SAndrew.Bardsley@arm.com auto handlerIter = portHandlers.find(portType); 7010478SAndrew.Bardsley@arm.com 7110478SAndrew.Bardsley@arm.com if (handlerIter == portHandlers.end()) 7210478SAndrew.Bardsley@arm.com fatal("Can't find port handler type '%s'\n", portType); 7310478SAndrew.Bardsley@arm.com 7410478SAndrew.Bardsley@arm.com externalPort = portHandlers[portType]->getExternalPort(portName, 7510478SAndrew.Bardsley@arm.com *this, portData); 7610478SAndrew.Bardsley@arm.com 7710478SAndrew.Bardsley@arm.com if (!externalPort) { 7810478SAndrew.Bardsley@arm.com fatal("%s: Can't find external port type: %s" 7910478SAndrew.Bardsley@arm.com " port_data: '%s'\n", portName, portType, portData); 8010478SAndrew.Bardsley@arm.com } 8110478SAndrew.Bardsley@arm.com } 8210478SAndrew.Bardsley@arm.com return *externalPort; 8310478SAndrew.Bardsley@arm.com } else { 8410478SAndrew.Bardsley@arm.com return MemObject::getMasterPort(if_name, idx); 8510478SAndrew.Bardsley@arm.com } 8610478SAndrew.Bardsley@arm.com} 8710478SAndrew.Bardsley@arm.com 8810478SAndrew.Bardsley@arm.comvoid 8910478SAndrew.Bardsley@arm.comExternalMaster::init() 9010478SAndrew.Bardsley@arm.com{ 9110478SAndrew.Bardsley@arm.com if (!externalPort) { 9210478SAndrew.Bardsley@arm.com fatal("ExternalMaster %s: externalPort not set!\n", name()); 9310478SAndrew.Bardsley@arm.com } else if (!externalPort->isConnected()) { 9410478SAndrew.Bardsley@arm.com fatal("ExternalMaster %s is unconnected!\n", name()); 9510478SAndrew.Bardsley@arm.com } 9610478SAndrew.Bardsley@arm.com} 9710478SAndrew.Bardsley@arm.com 9810478SAndrew.Bardsley@arm.comExternalMaster * 9910478SAndrew.Bardsley@arm.comExternalMasterParams::create() 10010478SAndrew.Bardsley@arm.com{ 10110478SAndrew.Bardsley@arm.com return new ExternalMaster(this); 10210478SAndrew.Bardsley@arm.com} 10310478SAndrew.Bardsley@arm.com 10410478SAndrew.Bardsley@arm.comvoid 10510478SAndrew.Bardsley@arm.comExternalMaster::registerHandler(const std::string &handler_name, 10610478SAndrew.Bardsley@arm.com Handler *handler) 10710478SAndrew.Bardsley@arm.com{ 10810478SAndrew.Bardsley@arm.com portHandlers[handler_name] = handler; 10910478SAndrew.Bardsley@arm.com} 110