Spinlock save cpu flags

This commit is contained in:
2026-03-12 22:48:34 +01:00
parent 19793e9126
commit 4760818118
50 changed files with 704 additions and 461 deletions

View File

@@ -16,86 +16,100 @@ static const struct pci_driver_info pci_driver_infos[] = {
static spin_lock_t pci_lock = SPIN_LOCK_INIT;
uint32_t pci_read32 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) {
uint64_t fpci;
uint32_t addr = (uint32_t)((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) |
(offset & 0xFC) | ((uint32_t)0x80000000);
spin_lock (&pci_lock);
spin_lock (&pci_lock, &fpci);
outl (PCI_CONFIG_ADDR, addr);
uint32_t r = inl (PCI_CONFIG_DATA);
spin_unlock (&pci_lock);
spin_unlock (&pci_lock, fpci);
return r;
}
void pci_write32 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint32_t value) {
uint64_t fpci;
uint32_t addr = (uint32_t)((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) |
(offset & 0xFC) | ((uint32_t)0x80000000);
spin_lock (&pci_lock);
spin_lock (&pci_lock, &fpci);
outl (PCI_CONFIG_ADDR, addr);
outl (PCI_CONFIG_DATA, value);
spin_unlock (&pci_lock);
spin_unlock (&pci_lock, fpci);
}
uint16_t pci_read16 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) {
uint64_t fpci;
uint32_t addr = (uint32_t)((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) |
(offset & 0xFC) | ((uint32_t)0x80000000);
spin_lock (&pci_lock);
spin_lock (&pci_lock, &fpci);
outl (PCI_CONFIG_ADDR, addr);
uint16_t r = inw (PCI_CONFIG_DATA + (offset & 2));
spin_unlock (&pci_lock);
spin_unlock (&pci_lock, fpci);
return r;
}
void pci_write16 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint16_t value) {
uint64_t fpci;
uint32_t addr = (uint32_t)((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) |
(offset & 0xFC) | ((uint32_t)0x80000000);
spin_lock (&pci_lock);
spin_lock (&pci_lock, &fpci);
outl (PCI_CONFIG_ADDR, addr);
outw (PCI_CONFIG_DATA + (offset & 2), value);
spin_unlock (&pci_lock);
spin_unlock (&pci_lock, fpci);
}
uint8_t pci_read8 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) {
uint64_t fpci;
uint32_t addr = (uint32_t)((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) |
(offset & 0xFC) | ((uint32_t)0x80000000);
spin_lock (&pci_lock);
spin_lock (&pci_lock, &fpci);
outl (PCI_CONFIG_ADDR, addr);
uint8_t r = inb (PCI_CONFIG_DATA + (offset & 3));
spin_unlock (&pci_lock);
spin_unlock (&pci_lock, fpci);
return r;
}
void pci_write8 (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint8_t value) {
uint64_t fpci;
uint32_t addr = (uint32_t)((uint32_t)bus << 16) | ((uint32_t)slot << 11) | ((uint32_t)func << 8) |
(offset & 0xFC) | ((uint32_t)0x80000000);
spin_lock (&pci_lock);
spin_lock (&pci_lock, &fpci);
outl (PCI_CONFIG_ADDR, addr);
outb (PCI_CONFIG_DATA + (offset & 3), value);
spin_unlock (&pci_lock);
spin_unlock (&pci_lock, fpci);
}
static void pci_check_bus (struct proc* proc, struct reschedule_ctx* rctx, 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 (struct proc* proc, struct reschedule_ctx* rctx, 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);
@@ -124,7 +138,8 @@ static void pci_check_func (struct proc* proc, struct reschedule_ctx* rctx, uint
}
}
static void pci_check_device (struct proc* proc, struct reschedule_ctx* rctx, 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)
@@ -140,7 +155,8 @@ static void pci_check_device (struct proc* proc, struct reschedule_ctx* rctx, ui
}
}
static void pci_check_bus (struct proc* proc, struct reschedule_ctx* rctx, 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 (proc, rctx, bus, slot, cb);
}
@@ -188,7 +204,8 @@ static void pci_string_identifiers (uint16_t vendor_id, uint16_t device_id, uint
}
}
static void pci_discovery_cb (struct proc* proc, struct reschedule_ctx* rctx, 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);