gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
plic.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Huawei International
3  * Copyright (c) 2023 Google LLC
4  * All rights reserved
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are
17  * met: redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer;
19  * redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution;
22  * neither the name of the copyright holders nor the names of its
23  * contributors may be used to endorse or promote products derived from
24  * this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #ifndef __DEV_RISCV_PLIC_HH__
40 #define __DEV_RISCV_PLIC_HH__
41 
42 #include <bitset>
43 #include <map>
44 
45 #include "arch/riscv/interrupts.hh"
46 #include "dev/io_device.hh"
47 #include "dev/reg_bank.hh"
48 #include "mem/packet.hh"
49 #include "mem/packet_access.hh"
50 #include "params/Plic.hh"
51 #include "params/PlicBase.hh"
52 #include "sim/system.hh"
53 
54 namespace gem5
55 {
56 
57 using namespace RiscvISA;
93 struct PlicOutput
94 {
97 };
98 
99 class PlicBase : public BasicPioDevice
100 {
101  public:
102  typedef PlicBaseParams Params;
103  PlicBase(const Params &params) :
104  BasicPioDevice(params, params.pio_size)
105  {}
106 
107  // Interrupt interface to send signal to PLIC
108  virtual void post(int src_id) = 0;
109  // Interrupt interface to clear signal to PLIC
110  virtual void clear(int src_id) = 0;
111 };
112 
113 class Plic : public PlicBase
114 {
115  // Params
116  protected:
118 
119  // Number of interrupt sources
120  int nSrc;
125  int nSrc32;
133  int nContext;
134 
135  public:
136  typedef PlicParams Params;
137  Plic(const Params &params);
138 
139  // External API
140  public:
144  void post(int src_id) override;
145  void clear(int src_id) override;
146 
150  void init() override;
151  void serialize(CheckpointOut &cp) const override;
152  void unserialize(CheckpointIn &cp) override;
153 
154  protected:
158  Tick read(PacketPtr pkt) override;
159  Tick write(PacketPtr pkt) override;
160 
161  // Register bank
162  private:
163 
204  {
205  public:
206  const Addr pendingStart = 0x1000;
207  const Addr enableStart = 0x2000;
208  const Addr thresholdStart = 0x0200000;
209  const Addr enablePadding = 0x80;
210  const Addr thresholdPadding = 0x1000;
211  const Addr maxBankSize = 0x4000000;
212 
213 
222 
223  PlicRegisters(const std::string &name, Addr base, Plic* plic) :
225  plic(plic) {}
226 
228 
229  void init();
230 
231  } registers;
232 
234 
238  void writePriority(Register32& reg, const uint32_t& data,
239  const int src_id);
240 
241  void writeEnable(Register32& reg, const uint32_t& data,
242  const int src32_id, const int context_id);
243 
244  void writeThreshold(Register32& reg, const uint32_t& data,
245  const int context_id);
246 
247  uint32_t readClaim(Register32& reg, const int context_id);
248 
249  void writeClaim(Register32& reg, const uint32_t& data,
250  const int context_id);
251 
252  // Latency Model
253  private:
254 
255  // Internal states
256  // per-source pending * priority
258  // per-context, per-source pendingPriority * enable
260  // per-context last-claimed id
263 
275  void propagateOutput();
276  std::map<Tick, PlicOutput> outputQueue;
278 
287  void updateOutput();
288 
298  void updateInt();
299 };
300 
301 } // namespace gem5
302 
303 #endif // __DEV_RISCV_PLIC_HH__
gem5::unserialize
void unserialize(ThreadContext &tc, CheckpointIn &cp)
Definition: thread_context.cc:222
gem5::Plic::nSrc32
int nSrc32
Number of 32-bit pending registers needed = ceil(nSrc / 32)
Definition: plic.hh:125
io_device.hh
gem5::Plic::PlicRegisters::enable_holes
std::vector< RegisterRaz > enable_holes
Definition: plic.hh:219
system.hh
gem5::Plic::nContext
int nContext
Number of interrupt contexts = nThread * 2 e.g.
Definition: plic.hh:133
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::Plic::PlicRegisters::enable
std::vector< std::vector< Register32 > > enable
Definition: plic.hh:216
gem5::Plic::outputQueue
std::map< Tick, PlicOutput > outputQueue
Definition: plic.hh:276
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::PlicBase::PlicBase
PlicBase(const Params &params)
Definition: plic.hh:103
gem5::Plic::nSrc
int nSrc
Definition: plic.hh:120
gem5::PlicBase
Definition: plic.hh:99
gem5::Plic::pendingPriority
std::vector< uint32_t > pendingPriority
Definition: plic.hh:257
interrupts.hh
gem5::Plic
Definition: plic.hh:113
gem5::Plic::PlicRegisters::pending
std::vector< Register32 > pending
Definition: plic.hh:215
std::vector< uint32_t >
gem5::X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
packet.hh
gem5::PlicBase::Params
PlicBaseParams Params
Definition: plic.hh:102
gem5::PioDevice::Params
PioDeviceParams Params
Definition: io_device.hh:134
gem5::Plic::PlicRegisters::reserved
std::vector< RegisterRaz > reserved
Definition: plic.hh:221
gem5::System
Definition: system.hh:74
gem5::Plic::system
System * system
Definition: plic.hh:117
gem5::Plic::PlicRegisters::threshold
std::vector< Register32 > threshold
Definition: plic.hh:217
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::PlicOutput::maxID
std::vector< uint32_t > maxID
Definition: plic.hh:95
gem5::Plic::Params
PlicParams Params
Definition: plic.hh:136
gem5::Plic::effPriority
std::vector< std::vector< uint32_t > > effPriority
Definition: plic.hh:259
gem5::serialize
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
Definition: thread_context.cc:194
gem5::PlicOutput
NOTE: This implementation of CLINT is based on the SiFive U54MC datasheet: https://sifive....
Definition: plic.hh:93
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
name
const std::string & name()
Definition: trace.cc:48
gem5::Plic::PlicRegisters::claim
std::vector< Register32 > claim
Definition: plic.hh:218
packet_access.hh
gem5::PlicOutput::maxPriority
std::vector< uint32_t > maxPriority
Definition: plic.hh:96
gem5::Plic::output
PlicOutput output
Definition: plic.hh:262
gem5::X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:92
gem5::EventFunctionWrapper
Definition: eventq.hh:1136
gem5::Plic::PlicRegisters::PlicRegisters
PlicRegisters(const std::string &name, Addr base, Plic *plic)
Definition: plic.hh:223
gem5::Plic::PlicRegisters::priority
std::vector< Register32 > priority
Definition: plic.hh:214
gem5::Plic::PlicRegisters
MMIO Registers.
Definition: plic.hh:203
gem5::Plic::update
EventFunctionWrapper update
Definition: plic.hh:277
gem5::Plic::PlicRegisters::plic
Plic * plic
Definition: plic.hh:227
gem5::RegisterBank< ByteOrder::little >
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::statistics::init
const FlagsType init
This Stat is Initialized.
Definition: info.hh:55
gem5::Plic::PlicRegisters::claim_holes
std::vector< RegisterRaz > claim_holes
Definition: plic.hh:220
gem5::Plic::lastID
std::vector< uint32_t > lastID
Definition: plic.hh:261
gem5::RegisterBank< ByteOrder::little >::Register32
Register< uint32_t > Register32
Definition: reg_bank.hh:879
gem5::Plic::Register32
PlicRegisters::Register32 Register32
Definition: plic.hh:233
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::BasicPioDevice
Definition: io_device.hh:147
reg_bank.hh

Generated on Sun Jul 30 2023 01:56:56 for gem5 by doxygen 1.8.17