gem5  v22.1.0.0
plic.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Huawei International
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 
38 #ifndef __DEV_RISCV_PLIC_HH__
39 #define __DEV_RISCV_PLIC_HH__
40 
41 #include <bitset>
42 #include <map>
43 
44 #include "arch/riscv/interrupts.hh"
45 #include "dev/io_device.hh"
46 #include "dev/reg_bank.hh"
47 #include "mem/packet.hh"
48 #include "mem/packet_access.hh"
49 #include "params/Plic.hh"
50 #include "sim/system.hh"
51 
52 namespace gem5
53 {
54 
55 using namespace RiscvISA;
91 struct PlicOutput
92 {
95 };
96 
97 class Plic : public BasicPioDevice
98 {
99  // Params
100  protected:
102 
103  // Number of interrupt sources
104  int nSrc;
109  int nSrc32;
117  int nContext;
118 
119  public:
120  typedef PlicParams Params;
121  Plic(const Params &params);
122 
123  // External API
124  public:
128  void post(int src_id);
129  void clear(int src_id);
130 
134  void init() override;
135  void serialize(CheckpointOut &cp) const override;
136  void unserialize(CheckpointIn &cp) override;
137 
138  protected:
142  Tick read(PacketPtr pkt) override;
143  Tick write(PacketPtr pkt) override;
144 
145  // Register bank
146  private:
147 
188  {
189  public:
190  const Addr pendingStart = 0x1000;
191  const Addr enableStart = 0x2000;
192  const Addr thresholdStart = 0x0200000;
193  const Addr enablePadding = 0x80;
194  const Addr thresholdPadding = 0x1000;
195  const Addr maxBankSize = 0x4000000;
196 
197 
206 
207  PlicRegisters(const std::string &name, Addr base, Plic* plic) :
209  plic(plic) {}
210 
212 
213  void init();
214 
215  } registers;
216 
218 
222  void writePriority(Register32& reg, const uint32_t& data,
223  const int src_id);
224 
225  void writeEnable(Register32& reg, const uint32_t& data,
226  const int src32_id, const int context_id);
227 
228  void writeThreshold(Register32& reg, const uint32_t& data,
229  const int context_id);
230 
231  uint32_t readClaim(Register32& reg, const int context_id);
232 
233  void writeClaim(Register32& reg, const uint32_t& data,
234  const int context_id);
235 
236  // Latency Model
237  private:
238 
239  // Internal states
240  // per-source pending * priority
242  // per-context, per-source pendingPriority * enable
244  // per-context last-claimed id
247 
259  void propagateOutput();
260  std::map<Tick, PlicOutput> outputQueue;
262 
271  void updateOutput();
272 
282  void updateInt();
283 };
284 
285 } // namespace gem5
286 
287 #endif // __DEV_RISCV_PLIC_HH__
const char data[]
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
PioDeviceParams Params
Definition: io_device.hh:134
MMIO Registers.
Definition: plic.hh:188
std::vector< Register32 > priority
Definition: plic.hh:198
std::vector< Register32 > pending
Definition: plic.hh:199
std::vector< RegisterRaz > enable_holes
Definition: plic.hh:203
PlicRegisters(const std::string &name, Addr base, Plic *plic)
Definition: plic.hh:207
std::vector< Register32 > threshold
Definition: plic.hh:201
std::vector< std::vector< Register32 > > enable
Definition: plic.hh:200
std::vector< RegisterRaz > reserved
Definition: plic.hh:205
std::vector< RegisterRaz > claim_holes
Definition: plic.hh:204
std::vector< Register32 > claim
Definition: plic.hh:202
int nSrc
Definition: plic.hh:104
std::vector< uint32_t > lastID
Definition: plic.hh:245
int nContext
Number of interrupt contexts = nThread * 2 e.g.
Definition: plic.hh:117
std::map< Tick, PlicOutput > outputQueue
Definition: plic.hh:260
PlicOutput output
Definition: plic.hh:246
EventFunctionWrapper update
Definition: plic.hh:261
PlicRegisters::Register32 Register32
Definition: plic.hh:217
System * system
Definition: plic.hh:101
std::vector< std::vector< uint32_t > > effPriority
Definition: plic.hh:243
int nSrc32
Number of 32-bit pending registers needed = ceil(nSrc / 32)
Definition: plic.hh:109
PlicParams Params
Definition: plic.hh:120
std::vector< uint32_t > pendingPriority
Definition: plic.hh:241
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
const FlagsType init
This Stat is Initialized.
Definition: info.hh:56
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::ostream CheckpointOut
Definition: serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
void unserialize(ThreadContext &tc, CheckpointIn &cp)
uint64_t Tick
Tick count type.
Definition: types.hh:58
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
Declaration of the Packet class.
NOTE: This implementation of CLINT is based on the SiFive U54MC datasheet: https://sifive....
Definition: plic.hh:92
std::vector< uint32_t > maxPriority
Definition: plic.hh:94
std::vector< uint32_t > maxID
Definition: plic.hh:93
const std::string & name()
Definition: trace.cc:49

Generated on Wed Dec 21 2022 10:22:34 for gem5 by doxygen 1.9.1