gem5  v22.1.0.0
i82094aa.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 The Regents of The University of Michigan
3  * All rights reserved.
4  *
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.
15  *
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.
27  */
28 
29 #include "dev/x86/i82094aa.hh"
30 
31 #include <list>
32 
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"
41 
42 namespace gem5
43 {
44 
46  : BasicPioDevice(p, 20), lowestPriorityOffset(0),
47  intRequestPort(name() + ".int_request", this, this, p.int_latency)
48 {
49  // This assumes there's only one I/O APIC in the system and since the apic
50  // id is stored in a 8-bit field with 0xff meaning broadcast, the id must
51  // be less than 0xff
52 
53  assert(p.apic_id < 0xff);
54  initialApicId = id = p.apic_id;
55  arbId = id;
56  regSel = 0;
57  RedirTableEntry entry = 0;
58  entry.mask = 1;
59  for (int i = 0; i < TableSize; i++) {
60  redirTable[i] = entry;
61  pinStates[i] = false;
62  }
63 
64  for (int i = 0; i < p.port_inputs_connection_count; i++)
65  inputs.push_back(new IntSinkPin<I82094AA>(
66  csprintf("%s.inputs[%d]", name(), i), i, this));
67 }
68 
69 void
71 {
72  // The io apic must register its address range with its pio port via
73  // the piodevice init() function.
75 
76  // If the request port isn't connected, we can't send interrupts anywhere.
77  panic_if(!intRequestPort.isConnected(),
78  "Int port not connected to anything!");
79 }
80 
81 Port &
82 X86ISA::I82094AA::getPort(const std::string &if_name, PortID idx)
83 {
84  if (if_name == "int_requestor")
85  return intRequestPort;
86  if (if_name == "inputs")
87  return *inputs.at(idx);
88  else
89  return BasicPioDevice::getPort(if_name, idx);
90 }
91 
92 Tick
94 {
95  assert(pkt->getSize() == 4);
96  Addr offset = pkt->getAddr() - pioAddr;
97  switch(offset) {
98  case 0:
99  pkt->setLE<uint32_t>(regSel);
100  break;
101  case 16:
102  pkt->setLE<uint32_t>(readReg(regSel));
103  break;
104  default:
105  panic("Illegal read from I/O APIC.\n");
106  }
107  pkt->makeAtomicResponse();
108  return pioDelay;
109 }
110 
111 Tick
113 {
114  assert(pkt->getSize() == 4);
115  Addr offset = pkt->getAddr() - pioAddr;
116  switch(offset) {
117  case 0:
118  regSel = pkt->getLE<uint32_t>();
119  break;
120  case 16:
121  writeReg(regSel, pkt->getLE<uint32_t>());
122  break;
123  default:
124  panic("Illegal write to I/O APIC.\n");
125  }
126  pkt->makeAtomicResponse();
127  return pioDelay;
128 }
129 
130 void
131 X86ISA::I82094AA::writeReg(uint8_t offset, uint32_t value)
132 {
133  if (offset == 0x0) {
134  id = bits(value, 31, 24);
135  } else if (offset == 0x1) {
136  // The IOAPICVER register is read only.
137  } else if (offset == 0x2) {
138  arbId = bits(value, 31, 24);
139  } else if (offset >= 0x10 && offset <= (0x10 + TableSize * 2)) {
140  int index = (offset - 0x10) / 2;
141  if (offset % 2) {
142  redirTable[index].topDW = value;
143  redirTable[index].topReserved = 0;
144  } else {
145  redirTable[index].bottomDW = value;
146  redirTable[index].bottomReserved = 0;
147  }
148  } else {
149  warn("Access to undefined I/O APIC register %#x.\n", offset);
150  }
152  "Wrote %#x to I/O APIC register %#x .\n", value, offset);
153 }
154 
155 uint32_t
157 {
158  uint32_t result = 0;
159  if (offset == 0x0) {
160  result = id << 24;
161  } else if (offset == 0x1) {
162  result = ((TableSize - 1) << 16) | APICVersion;
163  } else if (offset == 0x2) {
164  result = arbId << 24;
165  } else if (offset >= 0x10 && offset <= (0x10 + TableSize * 2)) {
166  int index = (offset - 0x10) / 2;
167  if (offset % 2) {
168  result = redirTable[index].topDW;
169  } else {
170  result = redirTable[index].bottomDW;
171  }
172  } else {
173  warn("Access to undefined I/O APIC register %#x.\n", offset);
174  }
176  "Read %#x from I/O APIC register %#x.\n", result, offset);
177  return result;
178 }
179 
180 void
182 {
183  DPRINTF(I82094AA, "Received interrupt %d.\n", line);
184  assert(line < TableSize);
185  RedirTableEntry entry = redirTable[line];
186  if (entry.mask) {
187  DPRINTF(I82094AA, "Entry was masked.\n");
188  return;
189  }
190 
191  TriggerIntMessage message = 0;
192 
193  message.destination = entry.dest;
194  message.deliveryMode = entry.deliveryMode;
195  message.destMode = entry.destMode;
196  message.level = entry.polarity;
197  message.trigger = entry.trigger;
198 
199  if (entry.deliveryMode == delivery_mode::ExtInt) {
200  // We need to ask the I8259 for the vector.
202  auto on_completion = [this, message](PacketPtr pkt) {
203  auto msg_copy = message;
204  msg_copy.vector = pkt->getLE<uint8_t>();
205  signalInterrupt(msg_copy);
206  delete pkt;
207  };
208  intRequestPort.sendMessage(pkt, sys->isTimingMode(),
209  on_completion);
210  } else {
211  message.vector = entry.vector;
212  signalInterrupt(message);
213  }
214 }
215 
216 void
217 X86ISA::I82094AA::signalInterrupt(TriggerIntMessage message)
218 {
219  std::list<int> apics;
220  int numContexts = sys->threads.size();
221  if (message.destMode == 0) {
222  if (message.deliveryMode == delivery_mode::LowestPriority) {
223  panic("Lowest priority delivery mode from the "
224  "IO APIC aren't supported in physical "
225  "destination mode.\n");
226  }
227  if (message.destination == 0xFF) {
228  for (int i = 0; i < numContexts; i++) {
229  apics.push_back(i);
230  }
231  } else {
232  apics.push_back(message.destination);
233  }
234  } else {
235  for (int i = 0; i < numContexts; i++) {
236  BaseInterrupts *base_int = sys->threads[i]->
237  getCpuPtr()->getInterruptController(0);
238  auto *localApic = dynamic_cast<Interrupts *>(base_int);
239  if ((localApic->readReg(APIC_LOGICAL_DESTINATION) >> 24) &
240  message.destination) {
241  apics.push_back(localApic->getInitialApicId());
242  }
243  }
244  if (message.deliveryMode == delivery_mode::LowestPriority &&
245  apics.size()) {
246  // The manual seems to suggest that the chipset just does
247  // something reasonable for these instead of actually using
248  // state from the local APIC. We'll just rotate an offset
249  // through the set of APICs selected above.
250  uint64_t modOffset = lowestPriorityOffset % apics.size();
251  lowestPriorityOffset++;
252  auto apicIt = apics.begin();
253  while (modOffset--) {
254  apicIt++;
255  assert(apicIt != apics.end());
256  }
257  int selected = *apicIt;
258  apics.clear();
259  apics.push_back(selected);
260  }
261  }
262  for (auto id: apics) {
263  PacketPtr pkt = buildIntTriggerPacket(id, message);
264  intRequestPort.sendMessage(pkt, sys->isTimingMode());
265  }
266 }
267 
268 void
270 {
271  assert(number < TableSize);
272  if (!pinStates[number])
273  requestInterrupt(number);
274  pinStates[number] = true;
275 }
276 
277 void
279 {
280  assert(number < TableSize);
281  pinStates[number] = false;
282 }
283 
284 void
286 {
287  uint64_t* redirTableArray = (uint64_t*)redirTable;
288  SERIALIZE_SCALAR(regSel);
289  SERIALIZE_SCALAR(initialApicId);
290  SERIALIZE_SCALAR(id);
291  SERIALIZE_SCALAR(arbId);
292  SERIALIZE_SCALAR(lowestPriorityOffset);
293  SERIALIZE_ARRAY(redirTableArray, TableSize);
294  SERIALIZE_ARRAY(pinStates, TableSize);
295 }
296 
297 void
299 {
300  uint64_t redirTableArray[TableSize];
301  UNSERIALIZE_SCALAR(regSel);
302  UNSERIALIZE_SCALAR(initialApicId);
303  UNSERIALIZE_SCALAR(id);
304  UNSERIALIZE_SCALAR(arbId);
305  UNSERIALIZE_SCALAR(lowestPriorityOffset);
306  UNSERIALIZE_ARRAY(redirTableArray, TableSize);
307  UNSERIALIZE_ARRAY(pinStates, TableSize);
308  for (int i = 0; i < TableSize; i++) {
309  redirTable[i] = (RedirTableEntry)redirTableArray[i];
310  }
311 }
312 
313 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
virtual std::string name() const
Definition: named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Addr getAddr() const
Definition: packet.hh:805
void setLE(T v)
Set the value in the data pointer to v as little endian.
unsigned getSize() const
Definition: packet.hh:815
void makeAtomicResponse()
Definition: packet.hh:1071
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: io_device.cc:67
PioDeviceParams Params
Definition: io_device.hh:134
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: io_device.cc:59
Ports are used to interface objects to each other.
Definition: port.hh:62
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: i82094aa.cc:298
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: i82094aa.cc:112
static const uint8_t TableSize
Definition: i82094aa.hh:76
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: i82094aa.cc:93
uint32_t readReg(uint8_t offset)
Definition: i82094aa.cc:156
void signalInterrupt(TriggerIntMessage message)
Definition: i82094aa.cc:217
void raiseInterruptPin(int number)
Definition: i82094aa.cc:269
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: i82094aa.cc:82
void lowerInterruptPin(int number)
Definition: i82094aa.cc:278
void requestInterrupt(int line)
Definition: i82094aa.cc:181
EndBitUnion(RedirTableEntry) protected uint8_t initialApicId
Definition: i82094aa.hh:66
bool pinStates[TableSize]
Definition: i82094aa.hh:82
std::vector< IntSinkPin< I82094AA > * > inputs
Definition: i82094aa.hh:84
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: i82094aa.cc:285
I82094AA(const Params &p)
Definition: i82094aa.cc:45
void writeReg(uint8_t offset, uint32_t value)
Definition: i82094aa.cc:131
RedirTableEntry redirTable[TableSize]
Definition: i82094aa.hh:81
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: i82094aa.cc:70
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
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
#define UNSERIALIZE_ARRAY(member, size)
Definition: serialize.hh:618
#define SERIALIZE_ARRAY(member, size)
Definition: serialize.hh:610
#define warn(...)
Definition: logging.hh:246
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 54 > p
Definition: pagetable.hh:70
static PacketPtr buildIntAcknowledgePacket()
Definition: intmessage.hh:92
static PacketPtr buildIntTriggerPacket(int id, TriggerIntMessage message)
Definition: intmessage.hh:85
@ APIC_LOGICAL_DESTINATION
Definition: apic.hh:47
Bitfield< 0 > p
Definition: pagetable.hh:151
Bitfield< 5, 3 > index
Definition: types.hh:98
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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
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
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
Declaration of the Packet class.
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:568
const std::string & name()
Definition: trace.cc:49

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