external_master.hh revision 11817:594d96c093d0
12391SN/A/*
28931Sandreas.hansson@arm.com * Copyright (c) 2012-2014 ARM Limited
37733SN/A * All rights reserved
47733SN/A *
57733SN/A * The license below extends only to copyright in the software and shall
67733SN/A * not be construed as granting a license to any other intellectual
77733SN/A * property including but not limited to intellectual property relating
87733SN/A * to a hardware implementation of the functionality of the software
97733SN/A * licensed hereunder.  You may use the software subject to the license
107733SN/A * terms below provided that you ensure that this notice is replicated
117733SN/A * unmodified and in its entirety in all distributions of the software,
127733SN/A * modified or unmodified, in source code or in binary form.
137733SN/A *
142391SN/A * Redistribution and use in source and binary forms, with or without
152391SN/A * modification, are permitted provided that the following conditions are
162391SN/A * met: redistributions of source code must retain the above copyright
172391SN/A * notice, this list of conditions and the following disclaimer;
182391SN/A * redistributions in binary form must reproduce the above copyright
192391SN/A * notice, this list of conditions and the following disclaimer in the
202391SN/A * documentation and/or other materials provided with the distribution;
212391SN/A * neither the name of the copyright holders nor the names of its
222391SN/A * contributors may be used to endorse or promote products derived from
232391SN/A * this software without specific prior written permission.
242391SN/A *
252391SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
262391SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
272391SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
282391SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
292391SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
302391SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
312391SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
322391SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
332391SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
342391SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
352391SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
362391SN/A *
372391SN/A * Authors: Andrew Bardsley
382391SN/A *          Curtis Dunham
392665SN/A *          Christian Menard
402665SN/A */
412914SN/A
428931Sandreas.hansson@arm.com/**
432391SN/A * @file
442391SN/A *
4510466Sandreas.hansson@arm.com * ExternalMaster is a memory object representing a binding from
4610466Sandreas.hansson@arm.com * a gem5 slave to a master port in a system external to gem5.
4710102Sali.saidi@arm.com *
4810102Sali.saidi@arm.com * During initialisation, a `handler' for the port type specified in the
498232SN/A * port's port_type parameter is found from the registered port handlers
508232SN/A * provided with registerHandler.  Once a handler is found, it is passed the
518931Sandreas.hansson@arm.com * port_data parameter of the port which can be used to identify the external
523879SN/A * port which is to be bound to.  A port handler will usually construct a
539053Sdam.sunwoo@arm.com * bridge object in the external system to accomodate the port-to-port
542394SN/A * mapping but this bridge is not exposed to gem5 other than be the
552391SN/A * presentation of the MasterPort which can be bound.
562391SN/A *
578931Sandreas.hansson@arm.com * The external port must provide a gem5 MasterPort interface.
588931Sandreas.hansson@arm.com */
599053Sdam.sunwoo@arm.com
609053Sdam.sunwoo@arm.com#ifndef __MEM_EXTERNAL_MASTER__
612391SN/A#define __MEM_EXTERNAL_MASTER__
6210466Sandreas.hansson@arm.com
6310466Sandreas.hansson@arm.com#include "mem/mem_object.hh"
6410466Sandreas.hansson@arm.com#include "params/ExternalMaster.hh"
6510466Sandreas.hansson@arm.com
6610466Sandreas.hansson@arm.comclass ExternalMaster : public MemObject
6710466Sandreas.hansson@arm.com{
6810466Sandreas.hansson@arm.com  public:
6910466Sandreas.hansson@arm.com    /** Derive from this class to create an external port interface */
702391SN/A    class Port : public MasterPort
712391SN/A    {
722391SN/A      protected:
739293Sandreas.hansson@arm.com        ExternalMaster &owner;
749293Sandreas.hansson@arm.com
752391SN/A      public:
769293Sandreas.hansson@arm.com        Port(const std::string &name_,
772391SN/A            ExternalMaster &owner_) :
782391SN/A            MasterPort(name_, &owner_), owner(owner_)
798719SN/A        { }
808931Sandreas.hansson@arm.com
818719SN/A        ~Port() { }
828719SN/A
838719SN/A        /** Any or all of recv... can be overloaded to provide the port's
849053Sdam.sunwoo@arm.com         *  functionality */
859053Sdam.sunwoo@arm.com    };
868719SN/A
879053Sdam.sunwoo@arm.com    /* Handlers are specific to *types* of port not specific port
888719SN/A     * instantiations.  A handler will typically build a bridge to the
898719SN/A     * external port from gem5 and provide gem5 with a MasterPort that can be
909053Sdam.sunwoo@arm.com     * bound to for each call to Handler::getExternalPort.*/
918719SN/A    class Handler
929053Sdam.sunwoo@arm.com    {
939053Sdam.sunwoo@arm.com      public:
949053Sdam.sunwoo@arm.com        /** Create or find an external port which can be bound.  Returns
958719SN/A         *  NULL on failure */
969053Sdam.sunwoo@arm.com        virtual Port *getExternalPort(
978719SN/A            const std::string &name, ExternalMaster &owner,
988719SN/A            const std::string &port_data) = 0;
999053Sdam.sunwoo@arm.com    };
1008719SN/A
1019053Sdam.sunwoo@arm.com  protected:
1029053Sdam.sunwoo@arm.com    /** The peer port for the gem5 port "port" */
1039053Sdam.sunwoo@arm.com    Port *externalPort;
1048719SN/A
1059053Sdam.sunwoo@arm.com    /** Name of the bound port.  This will be name() + ".port" */
1068719SN/A    std::string portName;
1078719SN/A
1089053Sdam.sunwoo@arm.com    /** Key to select a port handler */
1098719SN/A    std::string portType;
1109053Sdam.sunwoo@arm.com
1119053Sdam.sunwoo@arm.com    /** Handler-specific port configuration */
1129053Sdam.sunwoo@arm.com    std::string portData;
1138719SN/A
1149053Sdam.sunwoo@arm.com    /** Registered handlers.  Handlers are chosen using the port_type
1158719SN/A     *  parameter on ExternalMasters.  port_types form a global namespace
1168719SN/A     *  across the simulation and so handlers are registered into a global
1179053Sdam.sunwoo@arm.com     *  structure */
1188719SN/A    static std::map<std::string, Handler *> portHandlers;
1199053Sdam.sunwoo@arm.com
1209053Sdam.sunwoo@arm.com  public:
1219053Sdam.sunwoo@arm.com    ExternalMaster(ExternalMasterParams *params);
1228719SN/A
1239053Sdam.sunwoo@arm.com    /** MasterPort interface.  Responds only to port "port" */
1248719SN/A    BaseMasterPort &getMasterPort(const std::string &if_name,
1258719SN/A        PortID idx = InvalidPortID);
1269053Sdam.sunwoo@arm.com
1278719SN/A    /** Register a handler which can provide ports with port_type ==
1289053Sdam.sunwoo@arm.com     *  handler_name */
1299053Sdam.sunwoo@arm.com    static void registerHandler(const std::string &handler_name,
1309053Sdam.sunwoo@arm.com        Handler *handler);
1318719SN/A
1329053Sdam.sunwoo@arm.com    void init();
1338719SN/A
1348719SN/A    const MasterID masterId;
1359053Sdam.sunwoo@arm.com};
1368719SN/A
1379053Sdam.sunwoo@arm.com
1389053Sdam.sunwoo@arm.com#endif // __MEM_EXTERNAL_MASTER__
1399053Sdam.sunwoo@arm.com