external_master.cc revision 13892
113322Sgabeblack@google.com/* 213322Sgabeblack@google.com * Copyright (c) 2012-2014 ARM Limited 313322Sgabeblack@google.com * All rights reserved 413322Sgabeblack@google.com * 513322Sgabeblack@google.com * The license below extends only to copyright in the software and shall 613322Sgabeblack@google.com * not be construed as granting a license to any other intellectual 713322Sgabeblack@google.com * property including but not limited to intellectual property relating 813322Sgabeblack@google.com * to a hardware implementation of the functionality of the software 913322Sgabeblack@google.com * licensed hereunder. You may use the software subject to the license 1013322Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated 1113322Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software, 1213322Sgabeblack@google.com * modified or unmodified, in source code or in binary form. 1313322Sgabeblack@google.com * 1413322Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 1513322Sgabeblack@google.com * modification, are permitted provided that the following conditions are 1613322Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 1713322Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 1813322Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1913322Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 2013322Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 2113322Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 2213322Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 2313322Sgabeblack@google.com * this software without specific prior written permission. 2413322Sgabeblack@google.com * 2513322Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2613322Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2713322Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2813322Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2913322Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3013322Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3113322Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3213322Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3313322Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3413322Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3513322Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3613322Sgabeblack@google.com * 3713322Sgabeblack@google.com * Authors: Andrew Bardsley 3813322Sgabeblack@google.com * Curtis Dunham 3913322Sgabeblack@google.com * Christian Menard 4013322Sgabeblack@google.com */ 4113322Sgabeblack@google.com 4213322Sgabeblack@google.com#include "mem/external_master.hh" 4313322Sgabeblack@google.com 4413322Sgabeblack@google.com#include <cctype> 4513322Sgabeblack@google.com#include <iomanip> 4613322Sgabeblack@google.com 4713322Sgabeblack@google.com#include "base/trace.hh" 4813322Sgabeblack@google.com#include "debug/ExternalPort.hh" 4913322Sgabeblack@google.com#include "sim/system.hh" 5013322Sgabeblack@google.com 5113322Sgabeblack@google.comstd::map<std::string, ExternalMaster::Handler *> 5213322Sgabeblack@google.com ExternalMaster::portHandlers; 5313322Sgabeblack@google.com 5413322Sgabeblack@google.comExternalMaster::ExternalMaster(ExternalMasterParams *params) : 5513322Sgabeblack@google.com SimObject(params), 56 externalPort(NULL), 57 portName(params->name + ".port"), 58 portType(params->port_type), 59 portData(params->port_data), 60 masterId(params->system->getMasterId(this)) 61{} 62 63Port & 64ExternalMaster::getPort(const std::string &if_name, PortID idx) 65{ 66 if (if_name == "port") { 67 DPRINTF(ExternalPort, "Trying to bind external port: %s %s\n", 68 portType, portName); 69 70 if (!externalPort) { 71 auto handlerIter = portHandlers.find(portType); 72 73 if (handlerIter == portHandlers.end()) 74 fatal("Can't find port handler type '%s'\n", portType); 75 76 externalPort = portHandlers[portType]->getExternalPort(portName, 77 *this, portData); 78 79 if (!externalPort) { 80 fatal("%s: Can't find external port type: %s" 81 " port_data: '%s'\n", portName, portType, portData); 82 } 83 } 84 return *externalPort; 85 } else { 86 return SimObject::getPort(if_name, idx); 87 } 88} 89 90void 91ExternalMaster::init() 92{ 93 if (!externalPort) { 94 fatal("ExternalMaster %s: externalPort not set!\n", name()); 95 } else if (!externalPort->isConnected()) { 96 fatal("ExternalMaster %s is unconnected!\n", name()); 97 } 98} 99 100ExternalMaster * 101ExternalMasterParams::create() 102{ 103 return new ExternalMaster(this); 104} 105 106void 107ExternalMaster::registerHandler(const std::string &handler_name, 108 Handler *handler) 109{ 110 portHandlers[handler_name] = handler; 111} 112