2 * Copyright (c) 2008 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "dev/x86/i82094aa.hh"
33 #include "arch/x86/interrupts.hh"
34 #include "arch/x86/intmessage.hh"
35 #include "cpu/base.hh"
36 #include "debug/I82094AA.hh"
37 #include "dev/x86/i8259.hh"
38 #include "mem/packet.hh"
39 #include "mem/packet_access.hh"
40 #include "sim/system.hh"
42 X86ISA::I82094AA::I82094AA(Params
*p
)
43 : BasicPioDevice(p
, 20), IntDevice(this, p
->int_latency
),
44 extIntPic(p
->external_int_pic
), lowestPriorityOffset(0)
46 // This assumes there's only one I/O APIC in the system and since the apic
47 // id is stored in a 8-bit field with 0xff meaning broadcast, the id must
50 assert(p
->apic_id
< 0xff);
51 initialApicId
= id
= p
->apic_id
;
54 RedirTableEntry entry
= 0;
56 for (int i
= 0; i
< TableSize
; i
++) {
57 redirTable
[i
] = entry
;
63 X86ISA::I82094AA::init()
65 // The io apic must register its address ranges on both its pio port
66 // via the piodevice init() function and its int port that it inherited
67 // from IntDevice. Note IntDevice is not a SimObject itself.
69 BasicPioDevice::init();
74 X86ISA::I82094AA::getPort(const std::string
&if_name
, PortID idx
)
76 if (if_name
== "int_master")
78 return BasicPioDevice::getPort(if_name
, idx
);
82 X86ISA::I82094AA::getIntAddrRange() const
85 ranges
.push_back(RangeEx(x86InterruptAddress(initialApicId
, 0),
86 x86InterruptAddress(initialApicId
, 0) +
87 PhysAddrAPICRangeSize
));
92 X86ISA::I82094AA::recvResponse(PacketPtr pkt
)
94 // Packet instantiated calling sendMessage() in signalInterrupt()
100 X86ISA::I82094AA::read(PacketPtr pkt
)
102 assert(pkt
->getSize() == 4);
103 Addr offset
= pkt
->getAddr() - pioAddr
;
106 pkt
->setLE
<uint32_t>(regSel
);
109 pkt
->setLE
<uint32_t>(readReg(regSel
));
112 panic("Illegal read from I/O APIC.\n");
114 pkt
->makeAtomicResponse();
119 X86ISA::I82094AA::write(PacketPtr pkt
)
121 assert(pkt
->getSize() == 4);
122 Addr offset
= pkt
->getAddr() - pioAddr
;
125 regSel
= pkt
->getLE
<uint32_t>();
128 writeReg(regSel
, pkt
->getLE
<uint32_t>());
131 panic("Illegal write to I/O APIC.\n");
133 pkt
->makeAtomicResponse();
138 X86ISA::I82094AA::writeReg(uint8_t offset
, uint32_t value
)
141 id
= bits(value
, 31, 24);
142 } else if (offset
== 0x1) {
143 // The IOAPICVER register is read only.
144 } else if (offset
== 0x2) {
145 arbId
= bits(value
, 31, 24);
146 } else if (offset
>= 0x10 && offset
<= (0x10 + TableSize
* 2)) {
147 int index
= (offset
- 0x10) / 2;
149 redirTable
[index
].topDW
= value
;
150 redirTable
[index
].topReserved
= 0;
152 redirTable
[index
].bottomDW
= value
;
153 redirTable
[index
].bottomReserved
= 0;
156 warn("Access to undefined I/O APIC register %#x.\n", offset
);
159 "Wrote %#x to I/O APIC register %#x .\n", value
, offset
);
163 X86ISA::I82094AA::readReg(uint8_t offset
)
168 } else if (offset
== 0x1) {
169 result
= ((TableSize
- 1) << 16) | APICVersion
;
170 } else if (offset
== 0x2) {
171 result
= arbId
<< 24;
172 } else if (offset
>= 0x10 && offset
<= (0x10 + TableSize
* 2)) {
173 int index
= (offset
- 0x10) / 2;
175 result
= redirTable
[index
].topDW
;
177 result
= redirTable
[index
].bottomDW
;
180 warn("Access to undefined I/O APIC register %#x.\n", offset
);
183 "Read %#x from I/O APIC register %#x.\n", result
, offset
);
188 X86ISA::I82094AA::signalInterrupt(int line
)
190 DPRINTF(I82094AA
, "Received interrupt %d.\n", line
);
191 assert(line
< TableSize
);
192 RedirTableEntry entry
= redirTable
[line
];
194 DPRINTF(I82094AA
, "Entry was masked.\n");
197 TriggerIntMessage message
= 0;
198 message
.destination
= entry
.dest
;
199 if (entry
.deliveryMode
== DeliveryMode::ExtInt
) {
201 message
.vector
= extIntPic
->getVector();
203 message
.vector
= entry
.vector
;
205 message
.deliveryMode
= entry
.deliveryMode
;
206 message
.destMode
= entry
.destMode
;
207 message
.level
= entry
.polarity
;
208 message
.trigger
= entry
.trigger
;
210 int numContexts
= sys
->numContexts();
211 if (message
.destMode
== 0) {
212 if (message
.deliveryMode
== DeliveryMode::LowestPriority
) {
213 panic("Lowest priority delivery mode from the "
214 "IO APIC aren't supported in physical "
215 "destination mode.\n");
217 if (message
.destination
== 0xFF) {
218 for (int i
= 0; i
< numContexts
; i
++) {
222 apics
.push_back(message
.destination
);
225 for (int i
= 0; i
< numContexts
; i
++) {
226 Interrupts
*localApic
= sys
->getThreadContext(i
)->
227 getCpuPtr()->getInterruptController(0);
228 if ((localApic
->readReg(APIC_LOGICAL_DESTINATION
) >> 24) &
229 message
.destination
) {
230 apics
.push_back(localApic
->getInitialApicId());
233 if (message
.deliveryMode
== DeliveryMode::LowestPriority
&&
235 // The manual seems to suggest that the chipset just does
236 // something reasonable for these instead of actually using
237 // state from the local APIC. We'll just rotate an offset
238 // through the set of APICs selected above.
239 uint64_t modOffset
= lowestPriorityOffset
% apics
.size();
240 lowestPriorityOffset
++;
241 ApicList::iterator apicIt
= apics
.begin();
242 while (modOffset
--) {
244 assert(apicIt
!= apics
.end());
246 int selected
= *apicIt
;
248 apics
.push_back(selected
);
251 intMasterPort
.sendMessage(apics
, message
, sys
->isTimingMode());
256 X86ISA::I82094AA::raiseInterruptPin(int number
)
258 assert(number
< TableSize
);
259 if (!pinStates
[number
])
260 signalInterrupt(number
);
261 pinStates
[number
] = true;
265 X86ISA::I82094AA::lowerInterruptPin(int number
)
267 assert(number
< TableSize
);
268 pinStates
[number
] = false;
272 X86ISA::I82094AA::serialize(CheckpointOut
&cp
) const
274 uint64_t* redirTableArray
= (uint64_t*)redirTable
;
275 SERIALIZE_SCALAR(regSel
);
276 SERIALIZE_SCALAR(initialApicId
);
277 SERIALIZE_SCALAR(id
);
278 SERIALIZE_SCALAR(arbId
);
279 SERIALIZE_SCALAR(lowestPriorityOffset
);
280 SERIALIZE_ARRAY(redirTableArray
, TableSize
);
281 SERIALIZE_ARRAY(pinStates
, TableSize
);
285 X86ISA::I82094AA::unserialize(CheckpointIn
&cp
)
287 uint64_t redirTableArray
[TableSize
];
288 UNSERIALIZE_SCALAR(regSel
);
289 UNSERIALIZE_SCALAR(initialApicId
);
290 UNSERIALIZE_SCALAR(id
);
291 UNSERIALIZE_SCALAR(arbId
);
292 UNSERIALIZE_SCALAR(lowestPriorityOffset
);
293 UNSERIALIZE_ARRAY(redirTableArray
, TableSize
);
294 UNSERIALIZE_ARRAY(pinStates
, TableSize
);
295 for (int i
= 0; i
< TableSize
; i
++) {
296 redirTable
[i
] = (RedirTableEntry
)redirTableArray
[i
];
301 I82094AAParams::create()
303 return new X86ISA::I82094AA(this);