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 */ 3910478SAndrew.Bardsley@arm.com 4010478SAndrew.Bardsley@arm.com/** 4110478SAndrew.Bardsley@arm.com * @file 4210478SAndrew.Bardsley@arm.com * 4310478SAndrew.Bardsley@arm.com * ExternalSlave is a memory object representing a binding from 4410478SAndrew.Bardsley@arm.com * a gem5 master to a slave port in a system external to gem5. 4510478SAndrew.Bardsley@arm.com * 4610478SAndrew.Bardsley@arm.com * During initialisation, a `handler' for the port type specified in the 4710478SAndrew.Bardsley@arm.com * port's port_type parameter is found from the registered port handlers 4810478SAndrew.Bardsley@arm.com * provided with registerHandler. Once a handler is found, it is passed the 4910478SAndrew.Bardsley@arm.com * port_data parameter of the port which can be used to identify the external 5010478SAndrew.Bardsley@arm.com * port which is to be bound to. A port handler will usually construct a 5110478SAndrew.Bardsley@arm.com * bridge object in the external system to accomodate the port-to-port 5210478SAndrew.Bardsley@arm.com * mapping but this bridge is not exposed to gem5 other than be the 5310478SAndrew.Bardsley@arm.com * presentation of the SlavePort which can be bound. 5410478SAndrew.Bardsley@arm.com * 5510478SAndrew.Bardsley@arm.com * The external port must provide a gem5 SlavePort interface (with the 5610478SAndrew.Bardsley@arm.com * exception of getAddrRanges which is provided by the ExternalSlave 5710478SAndrew.Bardsley@arm.com * object). 5810478SAndrew.Bardsley@arm.com */ 5910478SAndrew.Bardsley@arm.com 6012492Sodanrc@yahoo.com.br#ifndef __MEM_EXTERNAL_SLAVE_HH__ 6112492Sodanrc@yahoo.com.br#define __MEM_EXTERNAL_SLAVE_HH__ 6210478SAndrew.Bardsley@arm.com 6313892Sgabeblack@google.com#include "mem/port.hh" 6410478SAndrew.Bardsley@arm.com#include "params/ExternalSlave.hh" 6513892Sgabeblack@google.com#include "sim/sim_object.hh" 6610478SAndrew.Bardsley@arm.com 6713892Sgabeblack@google.comclass ExternalSlave : public SimObject 6810478SAndrew.Bardsley@arm.com{ 6910478SAndrew.Bardsley@arm.com public: 7010478SAndrew.Bardsley@arm.com /** Derive from this class to create an external port interface */ 7113784Sgabeblack@google.com class ExternalPort : public SlavePort 7210478SAndrew.Bardsley@arm.com { 7310478SAndrew.Bardsley@arm.com protected: 7410478SAndrew.Bardsley@arm.com ExternalSlave &owner; 7510478SAndrew.Bardsley@arm.com 7610478SAndrew.Bardsley@arm.com public: 7713784Sgabeblack@google.com ExternalPort(const std::string &name_, 7810478SAndrew.Bardsley@arm.com ExternalSlave &owner_) : 7910478SAndrew.Bardsley@arm.com SlavePort(name_, &owner_), owner(owner_) 8010478SAndrew.Bardsley@arm.com { } 8110478SAndrew.Bardsley@arm.com 8213784Sgabeblack@google.com ~ExternalPort() { } 8310478SAndrew.Bardsley@arm.com 8410478SAndrew.Bardsley@arm.com /** Any or all of recv... can be overloaded to provide the port's 8510478SAndrew.Bardsley@arm.com * functionality */ 8610478SAndrew.Bardsley@arm.com 8710478SAndrew.Bardsley@arm.com AddrRangeList getAddrRanges() const; 8810478SAndrew.Bardsley@arm.com }; 8910478SAndrew.Bardsley@arm.com 9010478SAndrew.Bardsley@arm.com /* Handlers are specific to *types* of port not specific port 9110478SAndrew.Bardsley@arm.com * instantiations. A handler will typically build a bridge to the 9210478SAndrew.Bardsley@arm.com * external port from gem5 and provide gem5 with a SlavePort that can be 9310478SAndrew.Bardsley@arm.com * bound to for each call to Handler::getExternalPort.*/ 9410478SAndrew.Bardsley@arm.com class Handler 9510478SAndrew.Bardsley@arm.com { 9610478SAndrew.Bardsley@arm.com public: 9710478SAndrew.Bardsley@arm.com /** Create or find an external port which can be bound. Returns 9810478SAndrew.Bardsley@arm.com * NULL on failure */ 9913784Sgabeblack@google.com virtual ExternalPort *getExternalPort( 10010478SAndrew.Bardsley@arm.com const std::string &name, ExternalSlave &owner, 10110478SAndrew.Bardsley@arm.com const std::string &port_data) = 0; 10210478SAndrew.Bardsley@arm.com }; 10310478SAndrew.Bardsley@arm.com 10410478SAndrew.Bardsley@arm.com protected: 10510478SAndrew.Bardsley@arm.com /** The peer port for the gem5 port "port" */ 10613784Sgabeblack@google.com ExternalPort *externalPort; 10710478SAndrew.Bardsley@arm.com 10810478SAndrew.Bardsley@arm.com /** Name of the bound port. This will be name() + ".port" */ 10910478SAndrew.Bardsley@arm.com std::string portName; 11010478SAndrew.Bardsley@arm.com 11110478SAndrew.Bardsley@arm.com /** Key to select a port handler */ 11210478SAndrew.Bardsley@arm.com std::string portType; 11310478SAndrew.Bardsley@arm.com 11410478SAndrew.Bardsley@arm.com /** Handler-specific port configuration */ 11510478SAndrew.Bardsley@arm.com std::string portData; 11610478SAndrew.Bardsley@arm.com 11710478SAndrew.Bardsley@arm.com /** The Range of addresses supported by the devices on the external 11810478SAndrew.Bardsley@arm.com * side of this port */ 11910478SAndrew.Bardsley@arm.com AddrRangeList addrRanges; 12010478SAndrew.Bardsley@arm.com 12110478SAndrew.Bardsley@arm.com /** Registered handlers. Handlers are chosen using the port_type 12210478SAndrew.Bardsley@arm.com * parameter on ExternalSlaves. port_types form a global namespace 12310478SAndrew.Bardsley@arm.com * across the simulation and so handlers are registered into a global 12410478SAndrew.Bardsley@arm.com * structure */ 12510478SAndrew.Bardsley@arm.com static std::map<std::string, Handler *> portHandlers; 12610478SAndrew.Bardsley@arm.com 12710478SAndrew.Bardsley@arm.com public: 12810478SAndrew.Bardsley@arm.com ExternalSlave(ExternalSlaveParams *params); 12910478SAndrew.Bardsley@arm.com 13013784Sgabeblack@google.com /** Port interface. Responds only to port "port" */ 13113784Sgabeblack@google.com Port &getPort(const std::string &if_name, 13213784Sgabeblack@google.com PortID idx=InvalidPortID) override; 13310478SAndrew.Bardsley@arm.com 13410478SAndrew.Bardsley@arm.com /** Register a handler which can provide ports with port_type == 13510478SAndrew.Bardsley@arm.com * handler_name */ 13610478SAndrew.Bardsley@arm.com static void registerHandler(const std::string &handler_name, 13710478SAndrew.Bardsley@arm.com Handler *handler); 13810478SAndrew.Bardsley@arm.com 13913799SAndrea.Mondelli@ucf.edu void init() override; 14010478SAndrew.Bardsley@arm.com}; 14110478SAndrew.Bardsley@arm.com 14210478SAndrew.Bardsley@arm.com 14312492Sodanrc@yahoo.com.br#endif //__MEM_EXTERNAL_SLAVE_HH__ 144