2 * Copyright (c) 2014-2016 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Authors: Andreas Sandberg
40 #ifndef __DEV_ARM_NOMALI_GPU_HH__
41 #define __DEV_ARM_NOMALI_GPU_HH__
45 #include "dev/io_device.hh"
46 #include "libnomali/nomali.h"
48 class NoMaliGpuParams;
49 class CustomNoMaliGpuParams;
52 class NoMaliGpu : public PioDevice
55 NoMaliGpu(const NoMaliGpuParams *p);
60 public: /* Checkpointing */
61 void serialize(CheckpointOut &cp) const override;
62 void unserialize(CheckpointIn &cp) override;
64 public: /* IO device interfaces */
65 Tick read(PacketPtr pkt) override;
66 Tick write(PacketPtr pkt) override;
67 AddrRangeList getAddrRanges() const override;
69 protected: /* API wrappers/helpers */
75 /** Wrapper around nomali_reset(). */
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);
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);
89 * Wrapper around nomali_int_state()
91 * @param intno Interrupt number
92 * @return True if asserted, false otherwise.
94 bool intState(nomali_int_t intno);
99 * Format a NoMali error into an error message and panic.
101 * @param err Error code from the NoMali library.
102 * @param msg Message to print.
104 static void gpuPanic(nomali_error_t err, const char *msg) M5_ATTR_NORETURN;
106 * Panic if the NoMali returned an error, do nothing otherwise.
108 * @param err Error code from the NoMali library.
109 * @param msg Message to print when panicking.
111 static void panicOnErr(nomali_error_t err, const char *msg) {
112 if (err != NOMALI_E_OK)
116 protected: /* Callbacks */
123 * Interrupt callback from the NoMali library
125 * This method is called whenever there is an interrupt state change.
127 * @param intno Interrupt number
128 * @param set True is the interrupt is being asserted, false otherwise.
130 virtual void onInterrupt(nomali_int_t intno, bool set);
133 * Reset callback from the NoMali library
135 * This method is called whenever the GPU is reset through the
136 * register interface or the API (reset() or nomali_reset()).
138 virtual void onReset();
142 private: /* Callback helpers */
143 /** Wrapper around nomali_set_callback() */
144 void setCallback(const nomali_callback_t &callback);
147 * Interrupt callback from the NoMali library.
149 * This method calls onInterrupt() on the NoMaliGpu owning this
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)?
157 static void _interrupt(nomali_handle_t h, void *usr,
158 nomali_int_t intno, int set);
161 * Reset callback from the NoMali library.
163 * This method calls onReset() on the NoMaliGpu owning this
166 * @param h NoMali library handle.
167 * @param usr Pointer to an instance of the NoMaliGpu
169 static void _reset(nomali_handle_t h, void *usr);
172 /** Device base address */
175 /** Platform, used to discover GIC */
176 RealView *const platform;
178 /** Map between NoMali interrupt types and actual GIC
180 const std::map<nomali_int_t, uint32_t> interruptMap;
182 /** Cached information struct from the NoMali library */
183 nomali_info_t nomaliInfo;
185 /** Handle of a NoMali library instance */
186 nomali_handle_t nomali;
190 class CustomNoMaliGpu : public NoMaliGpu
193 CustomNoMaliGpu(const CustomNoMaliGpuParams *p);
194 virtual ~CustomNoMaliGpu();
197 void onReset() override;
200 /** Map between GPU registers and their custom reset values */
201 std::map<nomali_addr_t, uint32_t> idRegs;
204 #endif // __DEV_ARM_NOMALI_GPU_HH__