commit b689c798238981e206011b47bf539c4873967814
parent 7c09a754504b84d0c556b28252cdbcfa0402d606
Author: Matsuda Kenji <info@mtkn.jp>
Date: Thu, 11 Apr 2024 17:48:37 +0900
scan pci recursively
Diffstat:
4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/sys/include/console.h b/sys/include/console.h
@@ -1,4 +1,5 @@
// #include <libc.h>
+// #include <uefi.h>
// #include <draw.h>
typedef struct AsciiFont {
diff --git a/sys/src/kernel/amd64/pci.c b/sys/src/kernel/amd64/pci.c
@@ -1,5 +1,8 @@
#include <libc.h>
#include "pci.h"
+#include <uefi.h>
+#include <draw.h>
+#include <console.h>
const uint16 pci_config_address = 0xcf8;
const uint16 pci_config_data = 0xcfc;
@@ -87,6 +90,7 @@ pci_scan_dev(uint8 bus, uint8 dev)
int
pci_scan_func(uint8 bus, uint8 dev, uint8 func)
{
+ uint8 sub_bus;
if (num_pci_dev >= MaxPCIDev) {
return -1;
}
@@ -97,5 +101,12 @@ pci_scan_func(uint8 bus, uint8 dev, uint8 func)
pci_dev[num_pci_dev].prog = pci_config_read16(bus, dev, func, 0x8) >> 8;
num_pci_dev++;
+ // pci-pci bridge
+ if (pci_dev[num_pci_dev-1].base_class == 0x06 &&
+ pci_dev[num_pci_dev-1].sub_class == 0x04) {
+ sub_bus = pci_config_read16(bus, dev, func, 0x18) >> 8;
+ return pci_scan_bus(sub_bus);
+ }
+
return 0;
}
\ No newline at end of file
diff --git a/sys/src/kernel/amd64/pci.h b/sys/src/kernel/amd64/pci.h
@@ -7,7 +7,7 @@ typedef struct PCIDev {
uint8 sub_class;
uint8 prog;
} PCIDev;
-#define MaxPCIDev 32
+#define MaxPCIDev 128
extern const uint16 pci_config_address;
extern const uint16 pci_config_data;
diff --git a/sys/src/kernel/main.c b/sys/src/kernel/main.c
@@ -34,8 +34,8 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
Console con0 = {
.win = &win0,
.font = &asciifont,
- .w = 80,
- .h = 24,
+ .w = win0.size.x / 8,
+ .h = win0.size.y / 16,
.pos = (Point){0, 0}
};
Point p = {0, 0};
@@ -53,7 +53,7 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
cons_printf(&con0, "pixel at {%d, %d}: %x\n", p.x, p.y, get_pixel(&root_window, p));
pci_scan_all_bus();
for (int i = 0; i < num_pci_dev; i++) {
- cons_printf(&con0, "%d: %x\t%x\t%x\t%x\t%x\n", i,
+ cons_printf(&con0, "%d:\t%x\t%x\t%x\t%x\t%x\n", i,
pci_dev[i].vendor_id, pci_dev[i].device_id,
pci_dev[i].base_class, pci_dev[i].sub_class,
pci_dev[i].prog);