summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-07-11 19:18:18 +0200
committerAnton Kling <anton@kling.gg>2024-07-11 19:18:18 +0200
commit06d1028e33735ff925983bdda4b7abe89d19c4fa (patch)
tree71fb721d57bd159be532532372d919dbc8106901 /kernel
parente49d2a9fa5a485c33a250ce843d44fc6dedea8b5 (diff)
PCI: Fix bug not account for different bar index
Diffstat (limited to 'kernel')
-rw-r--r--kernel/drivers/pci.c13
-rw-r--r--kernel/drivers/pci.h5
2 files changed, 14 insertions, 4 deletions
diff --git a/kernel/drivers/pci.c b/kernel/drivers/pci.c
index 464d400..1dc7047 100644
--- a/kernel/drivers/pci.c
+++ b/kernel/drivers/pci.c
@@ -18,6 +18,12 @@ u8 pci_get_bar(const struct PCI_DEVICE *device, u8 bar_index,
}
u8 offset = 0x10 + bar_index * sizeof(u32);
u32 physical_bar = pci_config_read32(device, 0, offset);
+ u8 type;
+ if (physical_bar & 0x1) {
+ type = PCI_BAR_IO;
+ } else {
+ type = PCI_BAR_MEM;
+ }
u32 original_bar = physical_bar;
physical_bar &= 0xFFFFFFF0;
// Now we do the konami code of PCI devices to figure out the size of what
@@ -26,9 +32,9 @@ u8 pci_get_bar(const struct PCI_DEVICE *device, u8 bar_index,
// Comments taken from https://wiki.osdev.org/PCI#Address_and_size_of_the_BAR
// write a value of all 1's to the register,
- pci_config_write32(device, 0, 0x24, 0xFFFFFFFF);
+ pci_config_write32(device, 0, offset, 0xFFFFFFFF);
// then read it back.
- u32 bar_result = pci_config_read32(device, 0, 0x24);
+ u32 bar_result = pci_config_read32(device, 0, offset);
// The amount of memory can then be determined by masking the information
// bits,
@@ -43,10 +49,11 @@ u8 pci_get_bar(const struct PCI_DEVICE *device, u8 bar_index,
bar_result++;
// Restore the old result
- pci_config_write32(device, 0, 0x24, original_bar);
+ pci_config_write32(device, 0, offset, original_bar);
bar->address = physical_bar;
bar->size = bar_result;
+ bar->type = type;
return 1;
}
diff --git a/kernel/drivers/pci.h b/kernel/drivers/pci.h
index 274e950..ea1cf14 100644
--- a/kernel/drivers/pci.h
+++ b/kernel/drivers/pci.h
@@ -1,9 +1,12 @@
#include <typedefs.h>
+#define PCI_BAR_MEM 1
+#define PCI_BAR_IO 2
+
struct PCI_BaseAddressRegister {
u32 address;
u32 size;
- // TODO: Add a "type".
+ u8 type;
};
struct GENERAL_DEVICE {