external_master.cc revision 13784
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
4211793Sbrandon.potter@amd.com#include "mem/external_master.hh"
4311793Sbrandon.potter@amd.com
4410478SAndrew.Bardsley@arm.com#include <cctype>
4510478SAndrew.Bardsley@arm.com#include <iomanip>
4610478SAndrew.Bardsley@arm.com
4711800Sbrandon.potter@amd.com#include "base/trace.hh"
4810478SAndrew.Bardsley@arm.com#include "debug/ExternalPort.hh"
4911817SChristian.Menard@tu-dresden.de#include "sim/system.hh"
5010478SAndrew.Bardsley@arm.com
5110478SAndrew.Bardsley@arm.comstd::map<std::string, ExternalMaster::Handler *>
5210478SAndrew.Bardsley@arm.com    ExternalMaster::portHandlers;
5310478SAndrew.Bardsley@arm.com
5410478SAndrew.Bardsley@arm.comExternalMaster::ExternalMaster(ExternalMasterParams *params) :
5510478SAndrew.Bardsley@arm.com    MemObject(params),
5610478SAndrew.Bardsley@arm.com    externalPort(NULL),
5710478SAndrew.Bardsley@arm.com    portName(params->name + ".port"),
5810478SAndrew.Bardsley@arm.com    portType(params->port_type),
5911817SChristian.Menard@tu-dresden.de    portData(params->port_data),
6012680Sgiacomo.travaglini@arm.com    masterId(params->system->getMasterId(this))
6110478SAndrew.Bardsley@arm.com{}
6210478SAndrew.Bardsley@arm.com
6313784Sgabeblack@google.comPort &
6413784Sgabeblack@google.comExternalMaster::getPort(const std::string &if_name, PortID idx)
6510478SAndrew.Bardsley@arm.com{
6610478SAndrew.Bardsley@arm.com    if (if_name == "port") {
6710478SAndrew.Bardsley@arm.com        DPRINTF(ExternalPort, "Trying to bind external port: %s %s\n",
6810478SAndrew.Bardsley@arm.com            portType, portName);
6910478SAndrew.Bardsley@arm.com
7010478SAndrew.Bardsley@arm.com        if (!externalPort) {
7110478SAndrew.Bardsley@arm.com            auto handlerIter = portHandlers.find(portType);
7210478SAndrew.Bardsley@arm.com
7310478SAndrew.Bardsley@arm.com            if (handlerIter == portHandlers.end())
7410478SAndrew.Bardsley@arm.com                fatal("Can't find port handler type '%s'\n", portType);
7510478SAndrew.Bardsley@arm.com
7610478SAndrew.Bardsley@arm.com            externalPort = portHandlers[portType]->getExternalPort(portName,
7710478SAndrew.Bardsley@arm.com                *this, portData);
7810478SAndrew.Bardsley@arm.com
7910478SAndrew.Bardsley@arm.com            if (!externalPort) {
8010478SAndrew.Bardsley@arm.com                fatal("%s: Can't find external port type: %s"
8110478SAndrew.Bardsley@arm.com                    " port_data: '%s'\n", portName, portType, portData);
8210478SAndrew.Bardsley@arm.com            }
8310478SAndrew.Bardsley@arm.com        }
8410478SAndrew.Bardsley@arm.com        return *externalPort;
8510478SAndrew.Bardsley@arm.com    } else {
8613784Sgabeblack@google.com        return MemObject::getPort(if_name, idx);
8710478SAndrew.Bardsley@arm.com    }
8810478SAndrew.Bardsley@arm.com}
8910478SAndrew.Bardsley@arm.com
9010478SAndrew.Bardsley@arm.comvoid
9110478SAndrew.Bardsley@arm.comExternalMaster::init()
9210478SAndrew.Bardsley@arm.com{
9310478SAndrew.Bardsley@arm.com    if (!externalPort) {
9410478SAndrew.Bardsley@arm.com        fatal("ExternalMaster %s: externalPort not set!\n", name());
9510478SAndrew.Bardsley@arm.com    } else if (!externalPort->isConnected()) {
9610478SAndrew.Bardsley@arm.com        fatal("ExternalMaster %s is unconnected!\n", name());
9710478SAndrew.Bardsley@arm.com    }
9810478SAndrew.Bardsley@arm.com}
9910478SAndrew.Bardsley@arm.com
10010478SAndrew.Bardsley@arm.comExternalMaster *
10110478SAndrew.Bardsley@arm.comExternalMasterParams::create()
10210478SAndrew.Bardsley@arm.com{
10310478SAndrew.Bardsley@arm.com    return new ExternalMaster(this);
10410478SAndrew.Bardsley@arm.com}
10510478SAndrew.Bardsley@arm.com
10610478SAndrew.Bardsley@arm.comvoid
10710478SAndrew.Bardsley@arm.comExternalMaster::registerHandler(const std::string &handler_name,
10810478SAndrew.Bardsley@arm.com    Handler *handler)
10910478SAndrew.Bardsley@arm.com{
11010478SAndrew.Bardsley@arm.com    portHandlers[handler_name] = handler;
11110478SAndrew.Bardsley@arm.com}
112