21 #include "pedigree/kernel/Log.h" 22 #include "pedigree/kernel/compiler.h" 23 #include "pedigree/kernel/debugger/Debugger.h" 24 #include "pedigree/kernel/machine/Device.h" 25 #include "pedigree/kernel/machine/openfirmware/Device.h" 31 irq_id_t OpenPic::registerIsaIrqHandler(uint8_t irq,
IrqHandler *handler)
44 irq_id_t OpenPic::registerPciIrqHandler(
IrqHandler *handler)
68 void OpenPic::searchNode(
Device *pDev)
73 OFDevice ofDev(pChild->getOFHandle());
75 ofDev.getProperty(
"device_type", type);
76 if (type ==
"open-pic")
79 ofDev.getProperty(
"reg", reg, 8);
82 for (
unsigned int j = 0; j < pDev->
addresses().count(); j++)
84 if (!StringCompare(pDev->
addresses()[j]->m_Name,
"bar0"))
86 uintptr_t regAddr =
static_cast<uintptr_t
>(reg[0]) +
88 size_t regSize =
static_cast<size_t>(reg[1]);
91 String(
"reg"), regAddr, regSize,
115 ERROR(
"OpenPic: Device not found!");
120 m_pPort->
write32(HOST_TO_LITTLE32(OPENPIC_FLAG_CONF0_P), OPENPIC_REG_CONF0);
128 uint32_t feature = LITTLE_TO_HOST32(
m_pPort->
read32(OPENPIC_REG_FEATURE));
135 ERROR(
"OpenPIC: invalid version returned: " <<
Hex << f.version);
142 for (
int i = 0; i <
m_nIrqs; i++)
144 uintptr_t reg = i * 0x20 + OPENPIC_SOURCE_START;
148 HOST_TO_LITTLE32(OPENPIC_SOURCE_MASK | OPENPIC_SOURCE_PRIORITY | i),
151 #ifdef MULTIPROCESSOR 152 #error Problems here. 157 asm volatile(
"sync");
168 for (
size_t i = 0; i < 64; i++)
174 uint32_t irq = LITTLE_TO_HOST32(
m_pPort->
read32(OPENPIC_REG_ACK));
179 NOTICE(
"PIC: spurious IRQ255");
187 if (
m_Handler[irq]->irq(irq, state) ==
false)
196 NOTICE(
"PIC: unhandled irq #" << irq <<
" occurred");
200 str +=
"Unhandled IRQ: #";
210 void OpenPic::eoi(uint8_t irq)
214 void OpenPic::enable(uint8_t irq,
bool enable)
216 uintptr_t reg = irq * 0x20 + OPENPIC_SOURCE_START;
218 uintptr_t receivedReg = LITTLE_TO_HOST32(
m_pPort->
read32(reg));
222 HOST_TO_LITTLE32(receivedReg & ~OPENPIC_SOURCE_MASK), reg);
225 HOST_TO_LITTLE32(receivedReg | OPENPIC_SOURCE_MASK), reg);
227 asm volatile(
"sync; isync");
229 void OpenPic::enableAll(
bool enable)
231 for (
int i = 0; i <
m_nIrqs; i++)
232 this->enable(i, enable);
virtual bool registerInterruptHandler(size_t nInterruptNumber, InterruptHandler *pHandler)=0
Device * getChild(size_t n)
OpenPic() INITIALISATION_ONLY
static OpenPic m_Instance
static Debugger & instance()
virtual Vector< Address * > & addresses()
Handles interrupts and interrupt registrations from kernel components.
virtual void acknowledgeIrq(irq_id_t Id)
bool initialise() INITIALISATION_ONLY
virtual void interrupt(size_t interruptNumber, InterruptState &state)
void start(InterruptState &state, LargeStaticString &description)
IrqHandler * m_Handler[64]
virtual uint32_t read32(size_t offset=0)=0
virtual void unregisterHandler(irq_id_t Id, IrqHandler *handler)
static InterruptManager & instance()
virtual void write32(uint32_t value, size_t offset=0)=0