external_master.hh revision 13799
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 3911817SChristian.Menard@tu-dresden.de * Christian Menard 4010478SAndrew.Bardsley@arm.com */ 4110478SAndrew.Bardsley@arm.com 4210478SAndrew.Bardsley@arm.com/** 4310478SAndrew.Bardsley@arm.com * @file 4410478SAndrew.Bardsley@arm.com * 4510478SAndrew.Bardsley@arm.com * ExternalMaster is a memory object representing a binding from 4610478SAndrew.Bardsley@arm.com * a gem5 slave to a master port in a system external to gem5. 4710478SAndrew.Bardsley@arm.com * 4810478SAndrew.Bardsley@arm.com * During initialisation, a `handler' for the port type specified in the 4910478SAndrew.Bardsley@arm.com * port's port_type parameter is found from the registered port handlers 5010478SAndrew.Bardsley@arm.com * provided with registerHandler. Once a handler is found, it is passed the 5110478SAndrew.Bardsley@arm.com * port_data parameter of the port which can be used to identify the external 5210478SAndrew.Bardsley@arm.com * port which is to be bound to. A port handler will usually construct a 5310478SAndrew.Bardsley@arm.com * bridge object in the external system to accomodate the port-to-port 5410478SAndrew.Bardsley@arm.com * mapping but this bridge is not exposed to gem5 other than be the 5510478SAndrew.Bardsley@arm.com * presentation of the MasterPort which can be bound. 5610478SAndrew.Bardsley@arm.com * 5710478SAndrew.Bardsley@arm.com * The external port must provide a gem5 MasterPort interface. 5810478SAndrew.Bardsley@arm.com */ 5910478SAndrew.Bardsley@arm.com 6012492Sodanrc@yahoo.com.br#ifndef __MEM_EXTERNAL_MASTER_HH__ 6112492Sodanrc@yahoo.com.br#define __MEM_EXTERNAL_MASTER_HH__ 6210478SAndrew.Bardsley@arm.com 6310478SAndrew.Bardsley@arm.com#include "mem/mem_object.hh" 6410478SAndrew.Bardsley@arm.com#include "params/ExternalMaster.hh" 6510478SAndrew.Bardsley@arm.com 6610478SAndrew.Bardsley@arm.comclass ExternalMaster : public MemObject 6710478SAndrew.Bardsley@arm.com{ 6810478SAndrew.Bardsley@arm.com public: 6910478SAndrew.Bardsley@arm.com /** Derive from this class to create an external port interface */ 7013784Sgabeblack@google.com class ExternalPort : public MasterPort 7110478SAndrew.Bardsley@arm.com { 7210478SAndrew.Bardsley@arm.com protected: 7310478SAndrew.Bardsley@arm.com ExternalMaster &owner; 7410478SAndrew.Bardsley@arm.com 7510478SAndrew.Bardsley@arm.com public: 7613784Sgabeblack@google.com ExternalPort(const std::string &name_, 7710478SAndrew.Bardsley@arm.com ExternalMaster &owner_) : 7810478SAndrew.Bardsley@arm.com MasterPort(name_, &owner_), owner(owner_) 7910478SAndrew.Bardsley@arm.com { } 8010478SAndrew.Bardsley@arm.com 8113784Sgabeblack@google.com ~ExternalPort() { } 8210478SAndrew.Bardsley@arm.com 8310478SAndrew.Bardsley@arm.com /** Any or all of recv... can be overloaded to provide the port's 8410478SAndrew.Bardsley@arm.com * functionality */ 8510478SAndrew.Bardsley@arm.com }; 8610478SAndrew.Bardsley@arm.com 8710478SAndrew.Bardsley@arm.com /* Handlers are specific to *types* of port not specific port 8810478SAndrew.Bardsley@arm.com * instantiations. A handler will typically build a bridge to the 8910478SAndrew.Bardsley@arm.com * external port from gem5 and provide gem5 with a MasterPort that can be 9010478SAndrew.Bardsley@arm.com * bound to for each call to Handler::getExternalPort.*/ 9110478SAndrew.Bardsley@arm.com class Handler 9210478SAndrew.Bardsley@arm.com { 9310478SAndrew.Bardsley@arm.com public: 9410478SAndrew.Bardsley@arm.com /** Create or find an external port which can be bound. Returns 9510478SAndrew.Bardsley@arm.com * NULL on failure */ 9613784Sgabeblack@google.com virtual ExternalPort *getExternalPort( 9710478SAndrew.Bardsley@arm.com const std::string &name, ExternalMaster &owner, 9810478SAndrew.Bardsley@arm.com const std::string &port_data) = 0; 9910478SAndrew.Bardsley@arm.com }; 10010478SAndrew.Bardsley@arm.com 10110478SAndrew.Bardsley@arm.com protected: 10210478SAndrew.Bardsley@arm.com /** The peer port for the gem5 port "port" */ 10313784Sgabeblack@google.com ExternalPort *externalPort; 10410478SAndrew.Bardsley@arm.com 10510478SAndrew.Bardsley@arm.com /** Name of the bound port. This will be name() + ".port" */ 10610478SAndrew.Bardsley@arm.com std::string portName; 10710478SAndrew.Bardsley@arm.com 10810478SAndrew.Bardsley@arm.com /** Key to select a port handler */ 10910478SAndrew.Bardsley@arm.com std::string portType; 11010478SAndrew.Bardsley@arm.com 11110478SAndrew.Bardsley@arm.com /** Handler-specific port configuration */ 11210478SAndrew.Bardsley@arm.com std::string portData; 11310478SAndrew.Bardsley@arm.com 11410478SAndrew.Bardsley@arm.com /** Registered handlers. Handlers are chosen using the port_type 11510478SAndrew.Bardsley@arm.com * parameter on ExternalMasters. port_types form a global namespace 11610478SAndrew.Bardsley@arm.com * across the simulation and so handlers are registered into a global 11710478SAndrew.Bardsley@arm.com * structure */ 11810478SAndrew.Bardsley@arm.com static std::map<std::string, Handler *> portHandlers; 11910478SAndrew.Bardsley@arm.com 12010478SAndrew.Bardsley@arm.com public: 12110478SAndrew.Bardsley@arm.com ExternalMaster(ExternalMasterParams *params); 12210478SAndrew.Bardsley@arm.com 12313784Sgabeblack@google.com /** Port interface. Responds only to port "port" */ 12413784Sgabeblack@google.com Port &getPort(const std::string &if_name, 12513784Sgabeblack@google.com PortID idx=InvalidPortID) override; 12610478SAndrew.Bardsley@arm.com 12710478SAndrew.Bardsley@arm.com /** Register a handler which can provide ports with port_type == 12810478SAndrew.Bardsley@arm.com * handler_name */ 12910478SAndrew.Bardsley@arm.com static void registerHandler(const std::string &handler_name, 13010478SAndrew.Bardsley@arm.com Handler *handler); 13110478SAndrew.Bardsley@arm.com 13213799SAndrea.Mondelli@ucf.edu void init() override; 13311817SChristian.Menard@tu-dresden.de 13411817SChristian.Menard@tu-dresden.de const MasterID masterId; 13510478SAndrew.Bardsley@arm.com}; 13610478SAndrew.Bardsley@arm.com 13710478SAndrew.Bardsley@arm.com 13812492Sodanrc@yahoo.com.br#endif //__MEM_EXTERNAL_MASTER_HH__ 139