gpu_nomali.hh revision 11619:8bc53d5565ba
13534Sgblack@eecs.umich.edu/* 23534Sgblack@eecs.umich.edu * Copyright (c) 2014-2016 ARM Limited 33534Sgblack@eecs.umich.edu * All rights reserved 43534Sgblack@eecs.umich.edu * 53534Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall 63534Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual 73534Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating 83534Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software 93534Sgblack@eecs.umich.edu * licensed hereunder. You may use the software subject to the license 103534Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated 113534Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software, 123534Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form. 133534Sgblack@eecs.umich.edu * 143534Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 153534Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 163534Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 173534Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 183534Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 193534Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 203534Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 213534Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 223534Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 233534Sgblack@eecs.umich.edu * this software without specific prior written permission. 243534Sgblack@eecs.umich.edu * 253534Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 263534Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 273534Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 283534Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 293534Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 303534Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 313534Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 324202Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 333534Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 344202Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 354486Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 364486Sbinkertn@umich.edu * 374202Sbinkertn@umich.edu * Authors: Andreas Sandberg 384202Sbinkertn@umich.edu */ 394202Sbinkertn@umich.edu 404202Sbinkertn@umich.edu#ifndef __DEV_ARM_NOMALI_GPU_HH__ 41#define __DEV_ARM_NOMALI_GPU_HH__ 42 43#include <map> 44 45#include "dev/io_device.hh" 46#include "libnomali/nomali.h" 47 48class NoMaliGpuParams; 49class CustomNoMaliGpuParams; 50class RealView; 51 52class NoMaliGpu : public PioDevice 53{ 54 public: 55 NoMaliGpu(const NoMaliGpuParams *p); 56 virtual ~NoMaliGpu(); 57 58 void init() override; 59 60 public: /* Checkpointing */ 61 void serialize(CheckpointOut &cp) const override; 62 void unserialize(CheckpointIn &cp) override; 63 64 public: /* IO device interfaces */ 65 Tick read(PacketPtr pkt) override; 66 Tick write(PacketPtr pkt) override; 67 AddrRangeList getAddrRanges() const override; 68 69 protected: /* API wrappers/helpers */ 70 /** 71 * @{ 72 * @name API wrappers 73 */ 74 75 /** Wrapper around nomali_reset(). */ 76 void reset(); 77 78 /** Wrapper around nomali_reg_read(). */ 79 uint32_t readReg(nomali_addr_t reg); 80 /** Wrapper around nomali_reg_write(). */ 81 void writeReg(nomali_addr_t reg, uint32_t value); 82 83 /** Wrapper around nomali_reg_read_raw(). */ 84 uint32_t readRegRaw(nomali_addr_t reg) const; 85 /** Wrapper around nomali_reg_write_raw(). */ 86 void writeRegRaw(nomali_addr_t reg, uint32_t value); 87 88 /** 89 * Wrapper around nomali_int_state() 90 * 91 * @param intno Interrupt number 92 * @return True if asserted, false otherwise. 93 */ 94 bool intState(nomali_int_t intno); 95 96 /** @} */ 97 98 /** 99 * Format a NoMali error into an error message and panic. 100 * 101 * @param err Error code from the NoMali library. 102 * @param msg Message to print. 103 */ 104 static void gpuPanic(nomali_error_t err, const char *msg) M5_ATTR_NORETURN; 105 /** 106 * Panic if the NoMali returned an error, do nothing otherwise. 107 * 108 * @param err Error code from the NoMali library. 109 * @param msg Message to print when panicking. 110 */ 111 static void panicOnErr(nomali_error_t err, const char *msg) { 112 if (err != NOMALI_E_OK) 113 gpuPanic(err, msg); 114 } 115 116 protected: /* Callbacks */ 117 /** 118 * @{ 119 * @name Callbacks 120 */ 121 122 /** 123 * Interrupt callback from the NoMali library 124 * 125 * This method is called whenever there is an interrupt state change. 126 * 127 * @param intno Interrupt number 128 * @param set True is the interrupt is being asserted, false otherwise. 129 */ 130 virtual void onInterrupt(nomali_int_t intno, bool set); 131 132 /** 133 * Reset callback from the NoMali library 134 * 135 * This method is called whenever the GPU is reset through the 136 * register interface or the API (reset() or nomali_reset()). 137 */ 138 virtual void onReset(); 139 140 /** @} */ 141 142 private: /* Callback helpers */ 143 /** Wrapper around nomali_set_callback() */ 144 void setCallback(const nomali_callback_t &callback); 145 146 /** 147 * Interrupt callback from the NoMali library. 148 * 149 * This method calls onInterrupt() on the NoMaliGpu owning this 150 * device. 151 * 152 * @param h NoMali library handle. 153 * @param usr Pointer to an instance of the NoMaliGpu 154 * @param intno GPU interrupt type 155 * @param set Was the interrupt raised (1) or lowered (0)? 156 */ 157 static void _interrupt(nomali_handle_t h, void *usr, 158 nomali_int_t intno, int set); 159 160 /** 161 * Reset callback from the NoMali library. 162 * 163 * This method calls onReset() on the NoMaliGpu owning this 164 * device. 165 * 166 * @param h NoMali library handle. 167 * @param usr Pointer to an instance of the NoMaliGpu 168 */ 169 static void _reset(nomali_handle_t h, void *usr); 170 171 protected: 172 /** Device base address */ 173 const Addr pioAddr; 174 175 /** Platform, used to discover GIC */ 176 RealView *const platform; 177 178 /** Map between NoMali interrupt types and actual GIC 179 * interrupts */ 180 const std::map<nomali_int_t, uint32_t> interruptMap; 181 182 /** Cached information struct from the NoMali library */ 183 nomali_info_t nomaliInfo; 184 185 /** Handle of a NoMali library instance */ 186 nomali_handle_t nomali; 187}; 188 189 190class CustomNoMaliGpu : public NoMaliGpu 191{ 192 public: 193 CustomNoMaliGpu(const CustomNoMaliGpuParams *p); 194 virtual ~CustomNoMaliGpu(); 195 196 protected: 197 void onReset() override; 198 199 private: 200 /** Map between GPU registers and their custom reset values */ 201 std::map<nomali_addr_t, uint32_t> idRegs; 202}; 203 204#endif // __DEV_ARM_NOMALI_GPU_HH__ 205