external_master.cc revision 11800:54436a1784dc
15664Sgblack@eecs.umich.edu/* 25664Sgblack@eecs.umich.edu * Copyright (c) 2012-2014 ARM Limited 35664Sgblack@eecs.umich.edu * All rights reserved 45664Sgblack@eecs.umich.edu * 55664Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall 65664Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual 75664Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating 85664Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software 95664Sgblack@eecs.umich.edu * licensed hereunder. You may use the software subject to the license 105664Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated 115664Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software, 125664Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form. 135664Sgblack@eecs.umich.edu * 145664Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 155664Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 165664Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 175664Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 185664Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 195664Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 205664Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 215664Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 225664Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 235664Sgblack@eecs.umich.edu * this software without specific prior written permission. 245664Sgblack@eecs.umich.edu * 255664Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 265664Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 275664Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 285664Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 295664Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 305664Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 315664Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 325664Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 335664Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 345664Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 355664Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 365664Sgblack@eecs.umich.edu * 375664Sgblack@eecs.umich.edu * Authors: Andrew Bardsley 385664Sgblack@eecs.umich.edu * Curtis Dunham 395664Sgblack@eecs.umich.edu */ 405664Sgblack@eecs.umich.edu 415664Sgblack@eecs.umich.edu#include "mem/external_master.hh" 425664Sgblack@eecs.umich.edu 435664Sgblack@eecs.umich.edu#include <cctype> 445664Sgblack@eecs.umich.edu#include <iomanip> 455664Sgblack@eecs.umich.edu 465664Sgblack@eecs.umich.edu#include "base/trace.hh" 475664Sgblack@eecs.umich.edu#include "debug/ExternalPort.hh" 485664Sgblack@eecs.umich.edu 495664Sgblack@eecs.umich.edustd::map<std::string, ExternalMaster::Handler *> 505664Sgblack@eecs.umich.edu ExternalMaster::portHandlers; 515664Sgblack@eecs.umich.edu 525664Sgblack@eecs.umich.eduExternalMaster::ExternalMaster(ExternalMasterParams *params) : 53 MemObject(params), 54 externalPort(NULL), 55 portName(params->name + ".port"), 56 portType(params->port_type), 57 portData(params->port_data) 58{} 59 60BaseMasterPort & 61ExternalMaster::getMasterPort(const std::string &if_name, 62 PortID idx) 63{ 64 if (if_name == "port") { 65 DPRINTF(ExternalPort, "Trying to bind external port: %s %s\n", 66 portType, portName); 67 68 if (!externalPort) { 69 auto handlerIter = portHandlers.find(portType); 70 71 if (handlerIter == portHandlers.end()) 72 fatal("Can't find port handler type '%s'\n", portType); 73 74 externalPort = portHandlers[portType]->getExternalPort(portName, 75 *this, portData); 76 77 if (!externalPort) { 78 fatal("%s: Can't find external port type: %s" 79 " port_data: '%s'\n", portName, portType, portData); 80 } 81 } 82 return *externalPort; 83 } else { 84 return MemObject::getMasterPort(if_name, idx); 85 } 86} 87 88void 89ExternalMaster::init() 90{ 91 if (!externalPort) { 92 fatal("ExternalMaster %s: externalPort not set!\n", name()); 93 } else if (!externalPort->isConnected()) { 94 fatal("ExternalMaster %s is unconnected!\n", name()); 95 } 96} 97 98ExternalMaster * 99ExternalMasterParams::create() 100{ 101 return new ExternalMaster(this); 102} 103 104void 105ExternalMaster::registerHandler(const std::string &handler_name, 106 Handler *handler) 107{ 108 portHandlers[handler_name] = handler; 109} 110