gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
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
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
54namespace gem5
55{
56
57using namespace RiscvISA;
64
90
96
98{
99 public:
100 typedef PlicBaseParams Params;
102 BasicPioDevice(params, params.pio_size)
103 {}
104
105 // Interrupt interface to send signal to PLIC
106 virtual void post(int src_id) = 0;
107 // Interrupt interface to clear signal to PLIC
108 virtual void clear(int src_id) = 0;
109};
110
111class Plic : public PlicBase
112{
113 // Params
114 protected:
116
117 // Number of interrupt sources
118 int nSrc;
128
133
134 public:
135 typedef PlicParams Params;
136 Plic(const Params &params);
137
138 // External API
139 public:
143 void post(int src_id) override;
144 void clear(int src_id) override;
145
149 void init() override;
150 void serialize(CheckpointOut &cp) const override;
151 void unserialize(CheckpointIn &cp) override;
152
153 protected:
157 Tick read(PacketPtr pkt) override;
158 Tick write(PacketPtr pkt) override;
159
160 // Register bank
161 private:
162
231
233
237 void writePriority(Register32& reg, const uint32_t& data,
238 const int src_id);
239
240 void writeEnable(Register32& reg, const uint32_t& data,
241 const int src32_id, const int context_id);
242
243 void writeThreshold(Register32& reg, const uint32_t& data,
244 const int context_id);
245
246 uint32_t readClaim(Register32& reg, const int context_id);
247
248 void writeClaim(Register32& reg, const uint32_t& data,
249 const int context_id);
250
251 // Latency Model
252 private:
253
254 // Internal states
255 // per-source pending * priority
257 // per-context, per-source pendingPriority * enable
259 // per-context last-claimed id
262
266 void initContextFromNContexts(int n_contexts);
267 void initContextFromHartConfig(const std::string& hart_config);
268
280 void propagateOutput();
281 std::map<Tick, PlicOutput> outputQueue;
283
292 void updateOutput();
293
303 void updateInt();
304};
305
306} // namespace gem5
307
308#endif // __DEV_RISCV_PLIC_HH__
const char data[]
BasicPioDevice(const Params &p, Addr size)
Definition io_device.cc:75
virtual void post(int src_id)=0
PlicBaseParams Params
Definition plic.hh:100
PlicBase(const Params &params)
Definition plic.hh:101
virtual void clear(int src_id)=0
std::vector< Register32 > priority
Definition plic.hh:213
const Addr thresholdPadding
Definition plic.hh:209
std::vector< Register32 > pending
Definition plic.hh:214
const Addr enablePadding
Definition plic.hh:208
std::vector< RegisterRaz > enable_holes
Definition plic.hh:218
const Addr enableStart
Definition plic.hh:206
PlicRegisters(const std::string &name, Addr base, Plic *plic)
Definition plic.hh:222
const Addr maxBankSize
Definition plic.hh:210
const Addr thresholdStart
Definition plic.hh:207
std::vector< Register32 > threshold
Definition plic.hh:216
std::vector< std::vector< Register32 > > enable
Definition plic.hh:215
const Addr pendingStart
Definition plic.hh:205
std::vector< RegisterRaz > reserved
Definition plic.hh:220
std::vector< RegisterRaz > claim_holes
Definition plic.hh:219
std::vector< Register32 > claim
Definition plic.hh:217
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition plic.cc:155
int nSrc
Definition plic.hh:118
std::vector< uint32_t > lastID
Definition plic.hh:260
std::map< Tick, PlicOutput > outputQueue
Definition plic.hh:281
uint64_t outputLatency
Cycle latency from received interrupt signal to output.
Definition plic.hh:132
void updateOutput()
Trigger:
Definition plic.cc:467
gem5::Plic::PlicRegisters registers
Plic(const Params &params)
Definition plic.cc:56
void post(int src_id) override
Interrupt interface.
Definition plic.cc:76
PlicOutput output
Definition plic.hh:261
std::vector< std::pair< uint32_t, ExceptionCode > > contextConfigs
PLIC hart/pmode address configs, stored in the format {hartID, pmode}.
Definition plic.hh:127
EventFunctionWrapper update
Definition plic.hh:282
Tick read(PacketPtr pkt) override
PioDevice funcitons.
Definition plic.cc:133
PlicRegisters::Register32 Register32
Definition plic.hh:232
void writeEnable(Register32 &reg, const uint32_t &data, const int src32_id, const int context_id)
Definition plic.cc:325
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition plic.cc:554
void clear(int src_id) override
Definition plic.cc:105
void writeThreshold(Register32 &reg, const uint32_t &data, const int context_id)
Definition plic.cc:343
void updateInt()
Trigger:
Definition plic.cc:485
uint32_t readClaim(Register32 &reg, const int context_id)
Definition plic.cc:354
System * system
Definition plic.hh:115
void initContextFromHartConfig(const std::string &hart_config)
Definition plic.cc:444
std::vector< std::vector< uint32_t > > effPriority
Definition plic.hh:258
void propagateOutput()
Trigger:
Definition plic.cc:402
int nSrc32
Number of 32-bit pending registers needed = ceil(nSrc / 32)
Definition plic.hh:123
PlicParams Params
Definition plic.hh:135
void init() override
SimObject functions.
Definition plic.cc:175
std::vector< uint32_t > pendingPriority
Definition plic.hh:256
void writeClaim(Register32 &reg, const uint32_t &data, const int context_id)
Definition plic.cc:385
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition plic.cc:512
void initContextFromNContexts(int n_contexts)
The function for handling context config from params.
Definition plic.cc:434
void writePriority(Register32 &reg, const uint32_t &data, const int src_id)
Register read / write callbacks.
Definition plic.cc:302
const std::string & name() const
Definition reg_bank.hh:1028
STL vector class.
Definition stl.hh:37
const Params & params() const
Bitfield< 5, 3 > reg
Definition types.hh:92
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
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
uint64_t Tick
Tick count type.
Definition types.hh:58
Packet * PacketPtr
RegisterBank< ByteOrder::little > RegisterBankLE
Definition reg_bank.hh:1130
Declaration of the Packet class.
NOTE: This implementation of PLIC is based on he riscv-plic-spec repository: https://github....
Definition plic.hh:92
std::vector< uint32_t > maxPriority
Definition plic.hh:94
std::vector< uint32_t > maxID
Definition plic.hh:93

Generated on Mon Oct 27 2025 04:13:02 for gem5 by doxygen 1.14.0