gpu_nomali.hh (11349:9e46b77e5e56) gpu_nomali.hh (11350:ef6e57ac0d70)
1/*
2 * Copyright (c) 2014-2016 ARM Limited
3 * All rights reserved
4 *
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.
13 *
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.
24 *
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.
36 *
37 * Authors: Andreas Sandberg
38 */
39
40#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 RealView;
50
51class NoMaliGpu : public PioDevice
52{
53 public:
54 NoMaliGpu(const NoMaliGpuParams *p);
55 virtual ~NoMaliGpu();
56
1/*
2 * Copyright (c) 2014-2016 ARM Limited
3 * All rights reserved
4 *
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.
13 *
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.
24 *
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.
36 *
37 * Authors: Andreas Sandberg
38 */
39
40#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 RealView;
50
51class NoMaliGpu : public PioDevice
52{
53 public:
54 NoMaliGpu(const NoMaliGpuParams *p);
55 virtual ~NoMaliGpu();
56
57 void init() override;
58
57 public: /* Checkpointing */
58 void serialize(CheckpointOut &cp) const override;
59 void unserialize(CheckpointIn &cp) override;
60
61 public: /* IO device interfaces */
62 Tick read(PacketPtr pkt) override;
63 Tick write(PacketPtr pkt) override;
64 AddrRangeList getAddrRanges() const override;
65
66 protected: /* API wrappers/helpers */
67 /**
68 * @{
69 * @name API wrappers
70 */
71
72 /** Wrapper around nomali_reset(). */
73 void reset();
74
75 /** Wrapper around nomali_reg_read(). */
76 uint32_t readReg(nomali_addr_t reg);
77 /** Wrapper around nomali_reg_write(). */
78 void writeReg(nomali_addr_t reg, uint32_t value);
79
80 /** Wrapper around nomali_reg_read_raw(). */
81 uint32_t readRegRaw(nomali_addr_t reg) const;
82 /** Wrapper around nomali_reg_write_raw(). */
83 void writeRegRaw(nomali_addr_t reg, uint32_t value);
84
85 /**
86 * Wrapper around nomali_int_state()
87 *
88 * @param intno Interrupt number
89 * @return True if asserted, false otherwise.
90 */
91 bool intState(nomali_int_t intno);
92
93 /** @} */
94
95 /**
96 * Format a NoMali error into an error message and panic.
97 *
98 * @param err Error code from the NoMali library.
99 * @param msg Message to print.
100 */
101 static void gpuPanic(nomali_error_t err, const char *msg) M5_ATTR_NORETURN;
102 /**
103 * Panic if the NoMali returned an error, do nothing otherwise.
104 *
105 * @param err Error code from the NoMali library.
106 * @param msg Message to print when panicking.
107 */
108 static void panicOnErr(nomali_error_t err, const char *msg) {
109 if (err != NOMALI_E_OK)
110 gpuPanic(err, msg);
111 }
112
113 protected: /* Callbacks */
114 /**
115 * @{
116 * @name Callbacks
117 */
118
119 /**
120 * Interrupt callback from the NoMali library
121 *
122 * This method is called whenever there is an interrupt state change.
123 *
124 * @param intno Interrupt number
125 * @param set True is the interrupt is being asserted, false otherwise.
126 */
127 virtual void onInterrupt(nomali_int_t intno, bool set);
128
59 public: /* Checkpointing */
60 void serialize(CheckpointOut &cp) const override;
61 void unserialize(CheckpointIn &cp) override;
62
63 public: /* IO device interfaces */
64 Tick read(PacketPtr pkt) override;
65 Tick write(PacketPtr pkt) override;
66 AddrRangeList getAddrRanges() const override;
67
68 protected: /* API wrappers/helpers */
69 /**
70 * @{
71 * @name API wrappers
72 */
73
74 /** Wrapper around nomali_reset(). */
75 void reset();
76
77 /** Wrapper around nomali_reg_read(). */
78 uint32_t readReg(nomali_addr_t reg);
79 /** Wrapper around nomali_reg_write(). */
80 void writeReg(nomali_addr_t reg, uint32_t value);
81
82 /** Wrapper around nomali_reg_read_raw(). */
83 uint32_t readRegRaw(nomali_addr_t reg) const;
84 /** Wrapper around nomali_reg_write_raw(). */
85 void writeRegRaw(nomali_addr_t reg, uint32_t value);
86
87 /**
88 * Wrapper around nomali_int_state()
89 *
90 * @param intno Interrupt number
91 * @return True if asserted, false otherwise.
92 */
93 bool intState(nomali_int_t intno);
94
95 /** @} */
96
97 /**
98 * Format a NoMali error into an error message and panic.
99 *
100 * @param err Error code from the NoMali library.
101 * @param msg Message to print.
102 */
103 static void gpuPanic(nomali_error_t err, const char *msg) M5_ATTR_NORETURN;
104 /**
105 * Panic if the NoMali returned an error, do nothing otherwise.
106 *
107 * @param err Error code from the NoMali library.
108 * @param msg Message to print when panicking.
109 */
110 static void panicOnErr(nomali_error_t err, const char *msg) {
111 if (err != NOMALI_E_OK)
112 gpuPanic(err, msg);
113 }
114
115 protected: /* Callbacks */
116 /**
117 * @{
118 * @name Callbacks
119 */
120
121 /**
122 * Interrupt callback from the NoMali library
123 *
124 * This method is called whenever there is an interrupt state change.
125 *
126 * @param intno Interrupt number
127 * @param set True is the interrupt is being asserted, false otherwise.
128 */
129 virtual void onInterrupt(nomali_int_t intno, bool set);
130
131 /**
132 * Reset callback from the NoMali library
133 *
134 * This method is called whenever the GPU is reset through the
135 * register interface or the API (reset() or nomali_reset()).
136 */
137 virtual void onReset();
138
129 /** @} */
130
131 private: /* Callback helpers */
132 /** Wrapper around nomali_set_callback() */
133 void setCallback(const nomali_callback_t &callback);
134
135 /**
136 * Interrupt callback from the NoMali library.
137 *
138 * This method calls onInterrupt() on the NoMaliGpu owning this
139 * device.
140 *
141 * @param h NoMali library handle.
142 * @param usr Pointer to an instance of the NoMaliGpu
143 * @param intno GPU interrupt type
144 * @param set Was the interrupt raised (1) or lowered (0)?
145 */
146 static void _interrupt(nomali_handle_t h, void *usr,
147 nomali_int_t intno, int set);
139 /** @} */
140
141 private: /* Callback helpers */
142 /** Wrapper around nomali_set_callback() */
143 void setCallback(const nomali_callback_t &callback);
144
145 /**
146 * Interrupt callback from the NoMali library.
147 *
148 * This method calls onInterrupt() on the NoMaliGpu owning this
149 * device.
150 *
151 * @param h NoMali library handle.
152 * @param usr Pointer to an instance of the NoMaliGpu
153 * @param intno GPU interrupt type
154 * @param set Was the interrupt raised (1) or lowered (0)?
155 */
156 static void _interrupt(nomali_handle_t h, void *usr,
157 nomali_int_t intno, int set);
158
159 /**
160 * Reset callback from the NoMali library.
161 *
162 * This method calls onReset() on the NoMaliGpu owning this
163 * device.
164 *
165 * @param h NoMali library handle.
166 * @param usr Pointer to an instance of the NoMaliGpu
167 */
168 static void _reset(nomali_handle_t h, void *usr);
169
148 protected:
149 /** Device base address */
150 const Addr pioAddr;
151
152 /** Platform, used to discover GIC */
153 RealView *const platform;
154
155 /** Map between NoMali interrupt types and actual GIC
156 * interrupts */
157 const std::map<nomali_int_t, uint32_t> interruptMap;
158
159 /** Cached information struct from the NoMali library */
160 nomali_info_t nomaliInfo;
161
162 /** Handle of a NoMali library instance */
163 nomali_handle_t nomali;
164};
165
166
167#endif // __DEV_ARM_NOMALI_GPU_HH__
170 protected:
171 /** Device base address */
172 const Addr pioAddr;
173
174 /** Platform, used to discover GIC */
175 RealView *const platform;
176
177 /** Map between NoMali interrupt types and actual GIC
178 * interrupts */
179 const std::map<nomali_int_t, uint32_t> interruptMap;
180
181 /** Cached information struct from the NoMali library */
182 nomali_info_t nomaliInfo;
183
184 /** Handle of a NoMali library instance */
185 nomali_handle_t nomali;
186};
187
188
189#endif // __DEV_ARM_NOMALI_GPU_HH__