base_gic.cc revision 13531:e6f1bf55d038
1298SN/A/* 22188SN/A * Copyright (c) 2012, 2017-2018 ARM Limited 3298SN/A * All rights reserved 4298SN/A * 5298SN/A * The license below extends only to copyright in the software and shall 6298SN/A * not be construed as granting a license to any other intellectual 7298SN/A * property including but not limited to intellectual property relating 8298SN/A * to a hardware implementation of the functionality of the software 9298SN/A * licensed hereunder. You may use the software subject to the license 10298SN/A * terms below provided that you ensure that this notice is replicated 11298SN/A * unmodified and in its entirety in all distributions of the software, 12298SN/A * modified or unmodified, in source code or in binary form. 13298SN/A * 14298SN/A * Redistribution and use in source and binary forms, with or without 15298SN/A * modification, are permitted provided that the following conditions are 16298SN/A * met: redistributions of source code must retain the above copyright 17298SN/A * notice, this list of conditions and the following disclaimer; 18298SN/A * redistributions in binary form must reproduce the above copyright 19298SN/A * notice, this list of conditions and the following disclaimer in the 20298SN/A * documentation and/or other materials provided with the distribution; 21298SN/A * neither the name of the copyright holders nor the names of its 22298SN/A * contributors may be used to endorse or promote products derived from 23298SN/A * this software without specific prior written permission. 24298SN/A * 25298SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26298SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 272665Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 282665Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29298SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30298SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 311642SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32954SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33956SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34956SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 354078Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36299SN/A * 37299SN/A * Authors: Andreas Sandberg 386118Snate@binkert.org */ 396118Snate@binkert.org 402170SN/A#include "dev/arm/base_gic.hh" 415882Snate@binkert.org 421717SN/A#include "cpu/thread_context.hh" 432680Sktlim@umich.edu#include "dev/arm/realview.hh" 442313SN/A#include "params/ArmInterruptPin.hh" 455529Snate@binkert.org#include "params/ArmPPI.hh" 463565Sgblack@eecs.umich.edu#include "params/ArmSPI.hh" 47298SN/A#include "params/BaseGic.hh" 485606Snate@binkert.org 49298SN/ABaseGic::BaseGic(const Params *p) 50695SN/A : PioDevice(p), 51695SN/A platform(p->platform) 52954SN/A{ 536118Snate@binkert.org RealView *const rv(dynamic_cast<RealView*>(p->platform)); 545780Ssteve.reinhardt@amd.com // The platform keeps track of the GIC that is hooked up to the 556118Snate@binkert.org // system. Due to quirks in gem5's configuration system, the 562080SN/A // platform can't take a GIC as parameter. Instead, we need to 575780Ssteve.reinhardt@amd.com // register with the platform when a new GIC is created. If we 58298SN/A // can't find a platform, something is seriously wrong. 59299SN/A fatal_if(!rv, "GIC model can't register with platform code"); 601052SN/A rv->setGic(this); 61729SN/A} 622107SN/A 63298SN/ABaseGic::~BaseGic() 645504Snate@binkert.org{ 655504Snate@binkert.org} 665780Ssteve.reinhardt@amd.com 675780Ssteve.reinhardt@amd.comvoid 685504Snate@binkert.orgBaseGic::init() 695504Snate@binkert.org{ 70298SN/A PioDevice::init(); 715504Snate@binkert.org getSystem()->setGIC(this); 725504Snate@binkert.org} 735504Snate@binkert.org 745504Snate@binkert.orgconst BaseGic::Params * 755504Snate@binkert.orgBaseGic::params() const 765504Snate@binkert.org{ 775504Snate@binkert.org return dynamic_cast<const Params *>(_params); 785529Snate@binkert.org} 795504Snate@binkert.org 805504Snate@binkert.orgArmInterruptPinGen::ArmInterruptPinGen(const ArmInterruptPinParams *p) 815504Snate@binkert.org : SimObject(p) 825504Snate@binkert.org{ 835504Snate@binkert.org} 845504Snate@binkert.org 855504Snate@binkert.orgArmSPIGen::ArmSPIGen(const ArmSPIParams *p) 865504Snate@binkert.org : ArmInterruptPinGen(p), pin(new ArmSPI(p->platform, p->num)) 875504Snate@binkert.org{ 885504Snate@binkert.org} 895504Snate@binkert.org 905504Snate@binkert.orgArmInterruptPin* 915529Snate@binkert.orgArmSPIGen::get(ThreadContext* tc) 925504Snate@binkert.org{ 935504Snate@binkert.org return pin; 945504Snate@binkert.org} 955504Snate@binkert.org 965504Snate@binkert.orgArmPPIGen::ArmPPIGen(const ArmPPIParams *p) 975504Snate@binkert.org : ArmInterruptPinGen(p) 985606Snate@binkert.org{ 995504Snate@binkert.org} 1005504Snate@binkert.org 1015504Snate@binkert.orgArmInterruptPin* 1025504Snate@binkert.orgArmPPIGen::get(ThreadContext* tc) 1035504Snate@binkert.org{ 1045504Snate@binkert.org panic_if(!tc, "Invalid Thread Context\n"); 1055504Snate@binkert.org ContextID cid = tc->contextId(); 1065504Snate@binkert.org 1075504Snate@binkert.org auto pin_it = pins.find(cid); 1085504Snate@binkert.org 1095504Snate@binkert.org if (pin_it != pins.end()) { 1105504Snate@binkert.org // PPI Pin Already generated 1115529Snate@binkert.org return pin_it->second; 1125504Snate@binkert.org } else { 1135504Snate@binkert.org // Generate PPI Pin 1145504Snate@binkert.org auto p = static_cast<const ArmPPIParams *>(_params); 1155504Snate@binkert.org ArmPPI *pin = new ArmPPI(p->platform, tc, p->num); 1165504Snate@binkert.org 1175504Snate@binkert.org pins.insert({cid, pin}); 1185606Snate@binkert.org 1195504Snate@binkert.org return pin; 1205504Snate@binkert.org } 1215504Snate@binkert.org} 1225504Snate@binkert.org 1235504Snate@binkert.orgArmInterruptPin::ArmInterruptPin( 1245504Snate@binkert.org Platform *_platform, ThreadContext *tc, uint32_t int_num) 1255504Snate@binkert.org : threadContext(tc), platform(dynamic_cast<RealView*>(_platform)), 1265504Snate@binkert.org intNum(int_num) 1275504Snate@binkert.org{ 1285504Snate@binkert.org fatal_if(!platform, "Interrupt not connected to a RealView platform"); 1295504Snate@binkert.org} 1305504Snate@binkert.org 1315504Snate@binkert.orgvoid 1325504Snate@binkert.orgArmInterruptPin::setThreadContext(ThreadContext *tc) 1335504Snate@binkert.org{ 1345780Ssteve.reinhardt@amd.com panic_if(threadContext, 1355780Ssteve.reinhardt@amd.com "InterruptLine::setThreadContext called twice\n"); 1365741Snate@binkert.org 1375741Snate@binkert.org threadContext = tc; 1385741Snate@binkert.org} 1395741Snate@binkert.org 1405741Snate@binkert.orgContextID 1415741Snate@binkert.orgArmInterruptPin::targetContext() const 1425504Snate@binkert.org{ 1435808Snate@binkert.org panic_if(!threadContext, "Per-context interrupt triggered without a " \ 1445808Snate@binkert.org "call to InterruptLine::setThreadContext.\n"); 1455808Snate@binkert.org return threadContext->contextId(); 1465808Snate@binkert.org} 1475808Snate@binkert.org 1485808Snate@binkert.orgArmSPI::ArmSPI( 1495808Snate@binkert.org Platform *_platform, uint32_t int_num) 1505808Snate@binkert.org : ArmInterruptPin(_platform, nullptr, int_num) 1515808Snate@binkert.org{ 1525504Snate@binkert.org} 1535504Snate@binkert.org 1545504Snate@binkert.orgvoid 1555606Snate@binkert.orgArmSPI::raise() 1565606Snate@binkert.org{ 1575504Snate@binkert.org platform->gic->sendInt(intNum); 1585504Snate@binkert.org} 1595780Ssteve.reinhardt@amd.com 1605780Ssteve.reinhardt@amd.comvoid 1615504Snate@binkert.orgArmSPI::clear() 1625504Snate@binkert.org{ 1635504Snate@binkert.org platform->gic->clearInt(intNum); 1645504Snate@binkert.org} 1655504Snate@binkert.org 1665504Snate@binkert.orgArmPPI::ArmPPI( 167711SN/A Platform *_platform, ThreadContext *tc, uint32_t int_num) 168711SN/A : ArmInterruptPin(_platform, tc, int_num) 1695504Snate@binkert.org{ 1705504Snate@binkert.org} 171310SN/A 1725504Snate@binkert.orgvoid 1735504Snate@binkert.orgArmPPI::raise() 1743373Sstever@eecs.umich.edu{ 1755504Snate@binkert.org platform->gic->sendPPInt(intNum, targetContext()); 1765504Snate@binkert.org} 1775504Snate@binkert.org 1785504Snate@binkert.orgvoid 1795504Snate@binkert.orgArmPPI::clear() 1805504Snate@binkert.org{ 1815504Snate@binkert.org platform->gic->clearPPInt(intNum, targetContext()); 1825504Snate@binkert.org} 1835504Snate@binkert.org 1845504Snate@binkert.orgArmSPIGen * 1855504Snate@binkert.orgArmSPIParams::create() 1865504Snate@binkert.org{ 1875504Snate@binkert.org return new ArmSPIGen(this); 1885504Snate@binkert.org} 1895504Snate@binkert.org 1905504Snate@binkert.orgArmPPIGen * 1915504Snate@binkert.orgArmPPIParams::create() 1925504Snate@binkert.org{ 1935504Snate@binkert.org return new ArmPPIGen(this); 1945504Snate@binkert.org} 1955504Snate@binkert.org