gem5  v22.1.0.0
interrupts.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 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  * Copyright (c) 2007 The Hewlett-Packard Development Company
15  * All rights reserved.
16  *
17  * The license below extends only to copyright in the software and shall
18  * not be construed as granting a license to any other intellectual
19  * property including but not limited to intellectual property relating
20  * to a hardware implementation of the functionality of the software
21  * licensed hereunder. You may use the software subject to the license
22  * terms below provided that you ensure that this notice is replicated
23  * unmodified and in its entirety in all distributions of the software,
24  * modified or unmodified, in source code or in binary form.
25  *
26  * Redistribution and use in source and binary forms, with or without
27  * modification, are permitted provided that the following conditions are
28  * met: redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer;
30  * redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in the
32  * documentation and/or other materials provided with the distribution;
33  * neither the name of the copyright holders nor the names of its
34  * contributors may be used to endorse or promote products derived from
35  * this software without specific prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  */
49 
50 #ifndef __ARCH_X86_INTERRUPTS_HH__
51 #define __ARCH_X86_INTERRUPTS_HH__
52 
54 #include "arch/x86/faults.hh"
55 #include "arch/x86/intmessage.hh"
56 #include "arch/x86/regs/apic.hh"
57 #include "base/bitfield.hh"
58 #include "cpu/thread_context.hh"
59 #include "dev/intpin.hh"
60 #include "dev/io_device.hh"
61 #include "dev/x86/intdev.hh"
62 #include "params/X86LocalApic.hh"
63 #include "sim/eventq.hh"
64 
65 namespace gem5
66 {
67 
68 class ThreadContext;
69 class BaseCPU;
70 
71 int divideFromConf(uint32_t conf);
72 
73 namespace X86ISA
74 {
75 
77 
78 class Interrupts : public BaseInterrupts
79 {
80  protected:
81  System *sys = nullptr;
83 
84  // Storage for the APIC registers
85  uint32_t regs[NUM_APIC_REGS] = {};
86 
87  BitUnion32(LVTEntry)
88  Bitfield<7, 0> vector;
89  Bitfield<10, 8> deliveryMode;
90  Bitfield<12> status;
91  Bitfield<13> polarity;
92  Bitfield<14> remoteIRR;
93  Bitfield<15> trigger;
94  Bitfield<16> masked;
95  Bitfield<17> periodic;
96  EndBitUnion(LVTEntry)
97 
98  /*
99  * Timing related stuff.
100  */
101  EventFunctionWrapper apicTimerEvent;
102  void processApicTimerEvent();
103 
104  /*
105  * A set of variables to keep track of interrupts that don't go through
106  * the IRR.
107  */
108  bool pendingSmi = false;
109  uint8_t smiVector = 0;
110  bool pendingNmi = false;
111  uint8_t nmiVector = 0;
112  bool pendingExtInt = false;
113  uint8_t extIntVector = 0;
114  bool pendingInit = false;
115  uint8_t initVector = 0;
116  bool pendingStartup = false;
117  uint8_t startupVector = 0;
118  bool startedUp = false;
119 
120  // This is a quick check whether any of the above (except ExtInt) are set.
121  bool pendingUnmaskableInt = false;
122 
123  // A count of how many IPIs are in flight.
124  int pendingIPIs = 0;
125 
126  /*
127  * IRR and ISR maintenance.
128  */
129  uint8_t IRRV = 0;
130  uint8_t ISRV = 0;
131 
132  int
134  {
135  int offset = 7;
136  do {
137  if (regs[base + offset] != 0) {
138  return offset * 32 + findMsbSet(regs[base + offset]);
139  }
140  } while (offset--);
141  return 0;
142  }
143 
144  void
146  {
148  }
149 
150  void
152  {
154  }
155 
156  void
158  {
159  regs[base + (vector / 32)] |= (1 << (vector % 32));
160  }
161 
162  void
164  {
165  regs[base + (vector / 32)] &= ~(1 << (vector % 32));
166  }
167 
168  bool
170  {
171  return bits(regs[base + (vector / 32)], vector % 32);
172  }
173 
174  Tick clockPeriod() const { return clockDomain.clockPeriod(); }
175 
176  void requestInterrupt(uint8_t vector, uint8_t deliveryMode, bool level);
177 
178  int initialApicId = 0;
179 
180  // Ports for interrupt messages.
183 
184  // Pins for wired interrupts.
187 
188  // Port for memory mapped register accesses.
190 
193 
194  public:
195 
196  int getInitialApicId() { return initialApicId; }
197 
198  /*
199  * Params stuff.
200  */
201  using Params = X86LocalApicParams;
202 
203  void setThreadContext(ThreadContext *_tc) override;
204 
205  /*
206  * Initialize this object by registering it with the IO APIC.
207  */
208  void init() override;
209 
210  /*
211  * Functions to interact with the interrupt port.
212  */
213  Tick read(PacketPtr pkt);
214  Tick write(PacketPtr pkt);
216  void completeIPI(PacketPtr pkt);
217 
218  bool
220  {
221  LVTEntry entry = regs[APIC_LVT_TIMER];
222  if (!entry.masked)
223  requestInterrupt(entry.vector, entry.deliveryMode, entry.trigger);
224  return entry.periodic;
225  }
226 
229 
230  void raiseInterruptPin(int number);
231  void lowerInterruptPin(int number);
232 
233  Port &
234  getPort(const std::string &if_name,
235  PortID idx=InvalidPortID) override
236  {
237  if (if_name == "int_requestor") {
238  return intRequestPort;
239  } else if (if_name == "int_responder") {
240  return intResponsePort;
241  } else if (if_name == "pio") {
242  return pioPort;
243  } else if (if_name == "lint0") {
244  return lint0Pin;
245  } else if (if_name == "lint1") {
246  return lint1Pin;
247  } else {
248  return SimObject::getPort(if_name, idx);
249  }
250  }
251 
252  /*
253  * Functions to access and manipulate the APIC's registers.
254  */
255 
256  uint32_t readReg(ApicRegIndex miscReg);
257  void setReg(ApicRegIndex reg, uint32_t val);
258  void
260  {
261  regs[reg] = val;
262  }
263 
264  /*
265  * Constructor.
266  */
267 
268  Interrupts(const Params &p);
269 
270  /*
271  * Functions for retrieving interrupts for the CPU to handle.
272  */
273 
274  bool checkInterrupts() const override;
281  bool checkInterruptsRaw() const;
288  Fault getInterrupt() override;
289  void updateIntrInfo() override;
290 
291  /*
292  * Serialization.
293  */
294  void serialize(CheckpointOut &cp) const override;
295  void unserialize(CheckpointIn &cp) override;
296 
297  /*
298  * Old functions needed for compatability but which will be phased out
299  * eventually.
300  */
301  void
302  post(int int_num, int index) override
303  {
304  panic("Interrupts::post unimplemented!\n");
305  }
306 
307  void
308  clear(int int_num, int index) override
309  {
310  panic("Interrupts::clear unimplemented!\n");
311  }
312 
313  void
314  clearAll() override
315  {
316  panic("Interrupts::clearAll unimplemented!\n");
317  }
318 };
319 
320 } // namespace X86ISA
321 } // namespace gem5
322 
323 #endif // __ARCH_X86_INTERRUPTS_HH__
BaseInterruptsParams Params
Definition: interrupts.hh:47
The ClockDomain provides clock to group of clocked objects bundled under the same clock domain.
Definition: clock_domain.hh:72
Tick clockPeriod() const
Get the clock period.
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
The PioPort class is a programmed i/o port that all devices that are sensitive to an address range us...
Definition: io_device.hh:64
Ports are used to interface objects to each other.
Definition: port.hh:62
ThreadContext is the external interface to all thread state for anything outside of the CPU.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: interrupts.cc:790
Interrupts(const Params &p)
Definition: interrupts.cc:635
Bitfield< 15 > trigger
Definition: interrupts.hh:93
void completeIPI(PacketPtr pkt)
Definition: interrupts.cc:369
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: interrupts.cc:328
void post(int int_num, int index) override
Definition: interrupts.hh:302
Bitfield< 12 > status
Definition: interrupts.hh:90
bool checkInterrupts() const override
Definition: interrupts.cc:666
void clearAll() override
Definition: interrupts.hh:314
int findRegArrayMSB(ApicRegIndex base)
Definition: interrupts.hh:133
void clear(int int_num, int index) override
Definition: interrupts.hh:308
void setRegArrayBit(ApicRegIndex base, uint8_t vector)
Definition: interrupts.hh:157
AddrRangeList getIntAddrRange() const
Definition: interrupts.cc:393
Bitfield< 10, 8 > deliveryMode
Definition: interrupts.hh:89
void setReg(ApicRegIndex reg, uint32_t val)
Definition: interrupts.cc:442
AddrRangeList getAddrRanges() const
Definition: interrupts.cc:383
X86LocalApicParams Params
Definition: interrupts.hh:201
IntRequestPort< Interrupts > intRequestPort
Definition: interrupts.hh:182
Tick read(PacketPtr pkt)
Definition: interrupts.cc:194
bool getRegArrayBit(ApicRegIndex base, uint8_t vector)
Definition: interrupts.hh:169
uint32_t regs[NUM_APIC_REGS]
Definition: interrupts.hh:85
void updateIntrInfo() override
Definition: interrupts.cc:730
bool checkInterruptsRaw() const
Check if there are pending interrupts without ignoring the interrupts disabled flag.
Definition: interrupts.cc:688
Tick recvMessage(PacketPtr pkt)
Definition: interrupts.cc:341
EndBitUnion(LVTEntry) EventFunctionWrapper apicTimerEvent
void raiseInterruptPin(int number)
Definition: interrupts.cc:278
IntSinkPin< Interrupts > lint1Pin
Definition: interrupts.hh:186
void clearRegArrayBit(ApicRegIndex base, uint8_t vector)
Definition: interrupts.hh:163
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: interrupts.hh:234
Bitfield< 16 > masked
Definition: interrupts.hh:94
Bitfield< 14 > remoteIRR
Definition: interrupts.hh:92
IntSinkPin< Interrupts > lint0Pin
Definition: interrupts.hh:185
void requestInterrupt(uint8_t vector, uint8_t deliveryMode, bool level)
Definition: interrupts.cc:228
PioPort< Interrupts > pioPort
Definition: interrupts.hh:189
Bitfield< 13 > polarity
Definition: interrupts.hh:91
Bitfield< 17 > periodic
Definition: interrupts.hh:95
ClockDomain & clockDomain
Definition: interrupts.hh:82
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: interrupts.cc:765
Tick write(PacketPtr pkt)
Definition: interrupts.cc:211
void setThreadContext(ThreadContext *_tc) override
Definition: interrupts.cc:312
BitUnion32(LVTEntry) Bitfield< 7
bool hasPendingUnmaskable() const
Check if there are pending unmaskable interrupts.
Definition: interrupts.hh:287
IntResponsePort< Interrupts > intResponsePort
Definition: interrupts.hh:181
void setRegNoEffect(ApicRegIndex reg, uint32_t val)
Definition: interrupts.hh:259
Tick clockPeriod() const
Definition: interrupts.hh:174
Fault getInterrupt() override
Definition: interrupts.cc:696
uint32_t readReg(ApicRegIndex miscReg)
Definition: interrupts.cc:404
void lowerInterruptPin(int number)
Definition: interrupts.cc:303
constexpr int findMsbSet(uint64_t val)
Returns the bit position of the MSB that is set in the input.
Definition: bitfield.hh:260
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:76
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:126
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
Bitfield< 63 > val
Definition: misc.hh:776
Bitfield< 20 > level
Definition: intmessage.hh:51
ApicRegIndex
Definition: apic.hh:40
@ APIC_INTERRUPT_REQUEST_BASE
Definition: apic.hh:55
@ NUM_APIC_REGS
Definition: apic.hh:72
@ APIC_LVT_TIMER
Definition: apic.hh:60
@ APIC_IN_SERVICE_BASE
Definition: apic.hh:51
Bitfield< 0 > p
Definition: pagetable.hh:151
Bitfield< 5, 3 > index
Definition: types.hh:98
ApicRegIndex decodeAddr(Addr paddr)
Definition: interrupts.cc:85
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
Definition: types.hh:248
const PortID InvalidPortID
Definition: types.hh:246
std::ostream CheckpointOut
Definition: serialize.hh:66
int divideFromConf(uint32_t conf)
Definition: interrupts.cc:71
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
uint64_t Tick
Tick count type.
Definition: types.hh:58
const Addr MaxAddr
Definition: types.hh:171

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