2 * Copyright (c) 2012 ARM Limited
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.
14 * Copyright (c) 2007 The Hewlett-Packard Development Company
15 * All rights reserved.
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.
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.
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.
50 #ifndef __ARCH_X86_INTERRUPTS_HH__
51 #define __ARCH_X86_INTERRUPTS_HH__
53 #include "arch/generic/interrupts.hh"
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/io_device.hh"
60 #include "dev/x86/intdev.hh"
61 #include "params/X86LocalApic.hh"
62 #include "sim/eventq.hh"
67 int divideFromConf(uint32_t conf);
72 ApicRegIndex decodeAddr(Addr paddr);
74 class Interrupts : public BaseInterrupts
78 ClockDomain &clockDomain;
80 // Storage for the APIC registers
81 uint32_t regs[NUM_APIC_REGS];
84 Bitfield<7, 0> vector;
85 Bitfield<10, 8> deliveryMode;
87 Bitfield<13> polarity;
88 Bitfield<14> remoteIRR;
91 Bitfield<17> periodic;
95 * Timing related stuff.
97 EventFunctionWrapper apicTimerEvent;
98 void processApicTimerEvent();
101 * A set of variables to keep track of interrupts that don't go through
109 uint8_t extIntVector;
113 uint8_t startupVector;
116 // This is a quick check whether any of the above (except ExtInt) are set.
117 bool pendingUnmaskableInt;
119 // A count of how many IPIs are in flight.
123 * IRR and ISR maintenance.
129 findRegArrayMSB(ApicRegIndex base)
133 if (regs[base + offset] != 0) {
134 return offset * 32 + findMsbSet(regs[base + offset]);
143 IRRV = findRegArrayMSB(APIC_INTERRUPT_REQUEST_BASE);
149 ISRV = findRegArrayMSB(APIC_IN_SERVICE_BASE);
153 setRegArrayBit(ApicRegIndex base, uint8_t vector)
155 regs[base + (vector / 32)] |= (1 << (vector % 32));
159 clearRegArrayBit(ApicRegIndex base, uint8_t vector)
161 regs[base + (vector / 32)] &= ~(1 << (vector % 32));
165 getRegArrayBit(ApicRegIndex base, uint8_t vector)
167 return bits(regs[base + (vector / 32)], vector % 32);
170 Tick clockPeriod() const { return clockDomain.clockPeriod(); }
172 void requestInterrupt(uint8_t vector, uint8_t deliveryMode, bool level);
176 // Ports for interrupts.
177 IntResponsePort<Interrupts> intResponsePort;
178 IntRequestPort<Interrupts> intRequestPort;
180 // Port for memory mapped register accesses.
181 PioPort<Interrupts> pioPort;
184 Addr pioAddr = MaxAddr;
188 int getInitialApicId() { return initialApicId; }
193 typedef X86LocalApicParams Params;
195 void setThreadContext(ThreadContext *_tc) override;
200 return dynamic_cast<const Params *>(_params);
204 * Initialize this object by registering it with the IO APIC.
206 void init() override;
209 * Functions to interact with the interrupt port.
211 Tick read(PacketPtr pkt);
212 Tick write(PacketPtr pkt);
213 Tick recvMessage(PacketPtr pkt);
214 void completeIPI(PacketPtr pkt);
217 triggerTimerInterrupt()
219 LVTEntry entry = regs[APIC_LVT_TIMER];
221 requestInterrupt(entry.vector, entry.deliveryMode, entry.trigger);
222 return entry.periodic;
225 AddrRangeList getAddrRanges() const;
226 AddrRangeList getIntAddrRange() const;
228 Port &getPort(const std::string &if_name,
229 PortID idx=InvalidPortID) override
231 if (if_name == "int_requestor") {
232 return intRequestPort;
233 } else if (if_name == "int_responder") {
234 return intResponsePort;
235 } else if (if_name == "pio") {
238 return SimObject::getPort(if_name, idx);
242 * Functions to access and manipulate the APIC's registers.
245 uint32_t readReg(ApicRegIndex miscReg);
246 void setReg(ApicRegIndex reg, uint32_t val);
248 setRegNoEffect(ApicRegIndex reg, uint32_t val)
257 Interrupts(Params * p);
260 * Functions for retrieving interrupts for the CPU to handle.
263 bool checkInterrupts() const override;
265 * Check if there are pending interrupts without ignoring the
266 * interrupts disabled flag.
268 * @return true if there are interrupts pending.
270 bool checkInterruptsRaw() const;
272 * Check if there are pending unmaskable interrupts.
274 * @return true there are unmaskable interrupts pending.
276 bool hasPendingUnmaskable() const { return pendingUnmaskableInt; }
277 Fault getInterrupt() override;
278 void updateIntrInfo() override;
283 void serialize(CheckpointOut &cp) const override;
284 void unserialize(CheckpointIn &cp) override;
287 * Old functions needed for compatability but which will be phased out
291 post(int int_num, int index) override
293 panic("Interrupts::post unimplemented!\n");
297 clear(int int_num, int index) override
299 panic("Interrupts::clear unimplemented!\n");
305 panic("Interrupts::clearAll unimplemented!\n");
309 } // namespace X86ISA
311 #endif // __ARCH_X86_INTERRUPTS_HH__