Device IRQs WIP
This commit is contained in:
@@ -4,8 +4,10 @@
|
||||
#include <device/pci_info.h>
|
||||
#include <libk/lengthof.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/smp.h>
|
||||
|
||||
static const struct pci_driver_info pci_driver_infos[] = {
|
||||
{.class = 0x01, .subclass = 0x01, .init = &pci_ide_init},
|
||||
@@ -91,9 +93,9 @@ void pci_write8 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint8_
|
||||
spin_unlock (&pci_lock);
|
||||
}
|
||||
|
||||
static void pci_check_bus (uint8_t bus, pci_cb_func_t cb);
|
||||
static void pci_check_bus (struct proc* proc, struct reschedule_ctx* rctx, uint8_t bus, pci_cb_func_t cb);
|
||||
|
||||
static void pci_check_func (uint8_t bus, uint8_t slot, uint8_t func, pci_cb_func_t cb) {
|
||||
static void pci_check_func (struct proc* proc, struct reschedule_ctx* rctx, uint8_t bus, uint8_t slot, uint8_t func, pci_cb_func_t cb) {
|
||||
uint32_t reg0 = pci_read32 (bus, slot, func, PCI_VENDOR_ID);
|
||||
uint16_t vendor = (uint16_t)(reg0 & 0xFFFF);
|
||||
|
||||
@@ -112,47 +114,47 @@ static void pci_check_func (uint8_t bus, uint8_t slot, uint8_t func, pci_cb_func
|
||||
.subclass = ((uint8_t)(reg8 >> 16)),
|
||||
};
|
||||
|
||||
cb (pci_info);
|
||||
cb (proc, rctx, pci_info);
|
||||
|
||||
/* PCI 2 PCI bridge */
|
||||
if (pci_info.class == 0x06 && pci_info.subclass == 0x04) {
|
||||
uint32_t reg18 = pci_read32 (bus, slot, func, 0x18);
|
||||
uint8_t secondary = (uint8_t)(reg18 >> 8);
|
||||
pci_check_bus (secondary, cb);
|
||||
pci_check_bus (proc, rctx, secondary, cb);
|
||||
}
|
||||
}
|
||||
|
||||
static void pci_check_device (uint8_t bus, uint8_t slot, pci_cb_func_t cb) {
|
||||
static void pci_check_device (struct proc* proc, struct reschedule_ctx* rctx, uint8_t bus, uint8_t slot, pci_cb_func_t cb) {
|
||||
uint32_t reg0 = pci_read32 (bus, slot, 0, PCI_VENDOR_ID);
|
||||
|
||||
if ((uint16_t)(reg0 & 0xFFFF) == 0xFFFF)
|
||||
return;
|
||||
|
||||
pci_check_func (bus, slot, 0, cb);
|
||||
pci_check_func (proc, rctx, bus, slot, 0, cb);
|
||||
|
||||
/* multifunc device */
|
||||
uint32_t reg0xc = pci_read32 (bus, slot, 0, PCI_CACHELINE);
|
||||
if ((reg0xc >> 16) & 0x80) {
|
||||
for (uint8_t func = 1; func < 8; func++)
|
||||
pci_check_func (bus, slot, func, cb);
|
||||
pci_check_func (proc, rctx, bus, slot, func, cb);
|
||||
}
|
||||
}
|
||||
|
||||
static void pci_check_bus (uint8_t bus, pci_cb_func_t cb) {
|
||||
static void pci_check_bus (struct proc* proc, struct reschedule_ctx* rctx, uint8_t bus, pci_cb_func_t cb) {
|
||||
for (uint8_t slot = 0; slot < 32; slot++)
|
||||
pci_check_device (bus, slot, cb);
|
||||
pci_check_device (proc, rctx, bus, slot, cb);
|
||||
}
|
||||
|
||||
static void pci_enumerate (pci_cb_func_t cb) {
|
||||
static void pci_enumerate (struct proc* proc, struct reschedule_ctx* rctx, pci_cb_func_t cb) {
|
||||
uint32_t reg0xc = pci_read32 (0, 0, 0, PCI_CACHELINE);
|
||||
bool is_multictrl = (reg0xc >> 16) & 0x80;
|
||||
|
||||
if (!is_multictrl)
|
||||
pci_check_bus (0, cb);
|
||||
pci_check_bus (proc, rctx, 0, cb);
|
||||
else {
|
||||
for (uint8_t func = 0; func < 8; func++) {
|
||||
if ((pci_read32 (0, 0, func, PCI_VENDOR_ID) & 0xFFFF) != 0xFFFF)
|
||||
pci_check_bus (func, cb);
|
||||
pci_check_bus (proc, rctx, func, cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,7 +188,7 @@ static void pci_string_identifiers (uint16_t vendor_id, uint16_t device_id, uint
|
||||
}
|
||||
}
|
||||
|
||||
static void pci_discovery_cb (struct pci_info pci_info) {
|
||||
static void pci_discovery_cb (struct proc* proc, struct reschedule_ctx* rctx, struct pci_info pci_info) {
|
||||
const char *vname, *dname, *cname;
|
||||
pci_string_identifiers (pci_info.vendor, pci_info.device, pci_info.class, pci_info.subclass,
|
||||
&vname, &dname, &cname);
|
||||
@@ -198,9 +200,14 @@ static void pci_discovery_cb (struct pci_info pci_info) {
|
||||
for (size_t driver = 0; driver < lengthof (pci_driver_infos); driver++) {
|
||||
if (pci_driver_infos[driver].class == pci_info.class &&
|
||||
pci_driver_infos[driver].subclass == pci_info.subclass) {
|
||||
pci_driver_infos[driver].init (pci_info);
|
||||
pci_driver_infos[driver].init (proc, rctx, pci_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pci_init (void) { pci_enumerate (&pci_discovery_cb); }
|
||||
void pci_init (void) {
|
||||
struct reschedule_ctx rctx;
|
||||
memset (&rctx, 0, sizeof (rctx));
|
||||
|
||||
pci_enumerate (thiscpu->kproc, &rctx, &pci_discovery_cb);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user