setos

拙OS
Log | Files | Refs | LICENSE

commit aba51baeb01f4d6930ec568bd6e452d015ac53ad
parent 0433f83eaeaea8676624893f8e8457f0045a30bd
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Wed, 17 Apr 2024 12:16:35 +0900

add fields to PCIDev

Diffstat:
Msys/include/pci.h | 53+++++++++++++++++++++++++++++++++++++++++++++++++++--
Asys/include/xhc.h | 7+++++++
Msys/src/Makefile | 17++++++++++++-----
Msys/src/kernel/main.c | 9+++++++++
Asys/src/kernel/xhc.c | 4++++
5 files changed, 83 insertions(+), 7 deletions(-)

diff --git a/sys/include/pci.h b/sys/include/pci.h @@ -3,9 +3,58 @@ typedef struct PCIDev { uint16 vendor_id; uint16 device_id; - uint8 base_class; - uint8 sub_class; + uint16 command; + uint16 status; + uint8 revision_id; uint8 prog; + uint8 sub_class; + uint8 base_class; + uint8 cache_line_size; + uint8 master_latenct_timer; + uint8 header_type; + uint8 bist; + union { + struct { + uint32 base_address_register[6]; + uint32 cardbus_cis_pointer; + uint16 subsystem_vendor_id; + uint16 subsystem_id; + uint32 expansion_rom_base_address; + } t0; + struct { + uint32 base_address_register[2]; + uint8 primary_bus_number; + uint8 secondary_bus_number; + uint8 subordinate_bus_number; + uint8 secondary_latency_timer; + uint8 io_base; + uint8 io_limit; + uint16 secondary_status; + uint16 memory_base; + uint16 memory_limit; + uint16 prefetchable_memory_base; + uint16 prefetchable_memory_limit; + uint32 prefetchable_base_upper_32_bits; + uint32 prefetchable_limit_upper_32_bits; + uint16 io_base_upper_16_bits; + uint16 io_limit_upper_16_bits; + } t1; + }; + uint8 capabilities_pointer; + uint8 reserved0[3]; + union { + uint32 reserved1; + uint32 expansion_rom_base_address; + }; + uint8 interrupt_line; + uint8 interrupt_pin; + union { + struct { + uint8 min_gnt; + uint8 max_lat; + }; + uint16 bridge_control; + }; } PCIDev; #define MaxPCIDev 128 diff --git a/sys/include/xhc.h b/sys/include/xhc.h @@ -0,0 +1,7 @@ +// #include <libc.h> + +typedef struct Xhc { + uintptr Base; +} Xhc; + +extern Xhc xhc; diff --git a/sys/src/Makefile b/sys/src/Makefile @@ -31,6 +31,7 @@ boot/boot.dll: boot/boot.c boot/utils.c kernel/main.elf: kernel/memmap.ld \ kernel/$(ARCH)/start.o kernel/main.o kernel/alloc.o kernel/console.o \ kernel/draw.o kernel/pci.o kernel/$(ARCH)/pci.o kernel/$(ARCH)/machine.o \ + kernel/xhc.o \ ../lib/libc.a \ kernel/alloc.o kernel/console.o kernel/draw.o \ kernel/$(ARCH)/machine.o kernel/$(ARCH)/pci.o @@ -38,24 +39,30 @@ kernel/main.elf: kernel/memmap.ld \ kernel/$(ARCH)/start.o kernel/main.o \ kernel/alloc.o kernel/console.o kernel/draw.o kernel/pci.o \ kernel/$(ARCH)/pci.o kernel/$(ARCH)/machine.o \ + kernel/xhc.o \ -lc kernel/$(ARCH)/start.o: kernel/$(ARCH)/start.s $(CC) $(CFLAGS) -c -o $@ kernel/$(ARCH)/start.s -kernel/main.o: kernel/main.c ../include/uefi.h ../include/libc.h ../include/draw.h ../include/console.h ../include/pci.h +kernel/main.o: kernel/main.c ../include/uefi.h ../include/libc.h \ + ../include/draw.h ../include/console.h ../include/pci.h ../include/xhc.h $(CC) $(CFLAGS) -c -o $@ kernel/main.c kernel/alloc.o: kernel/alloc.c ../include/libc.h $(CC) $(CFLAGS) -c -o $@ kernel/alloc.c -kernel/console.o: kernel/console.c ../include/uefi.h ../include/libc.h ../include/draw.h ../include/console.h +kernel/console.o: kernel/console.c ../include/uefi.h ../include/libc.h \ + ../include/draw.h ../include/console.h $(CC) $(CFLAGS) -c -o $@ kernel/console.c -kernel/draw.o: kernel/draw.c ../include/uefi.h ../include/libc.h ../include/draw.h ../include/console.h +kernel/draw.o: kernel/draw.c ../include/uefi.h ../include/libc.h \ + ../include/draw.h ../include/console.h $(CC) $(CFLAGS) -c -o $@ kernel/draw.c kernel/pci.o: kernel/pci.c ../include/libc.h ../include/pci.h $(CC) $(CFLAGS) -c -o $@ kernel/pci.c -kernel/$(ARCH)/pci.o: kernel/$(ARCH)/pci.c kernel/$(ARCH)/pci.h ../include/libc.h ../include/pci.h +kernel/$(ARCH)/pci.o: kernel/$(ARCH)/pci.c kernel/$(ARCH)/pci.h \ + ../include/libc.h ../include/pci.h $(CC) $(CFLAGS) -c -o $@ kernel/$(ARCH)/pci.c kernel/$(ARCH)/machine.o: kernel/$(ARCH)/machine.s $(CC) $(CFLAGS) -c -o $@ kernel/$(ARCH)/machine.s - +kernel/xhc.o: kernel/xhc.c ../include/xhc.h + $(CC) $(CFLAGS) -c -o $@ kernel/xhc.c ../lib/libc.a: libc/strcpy.o libc/memset.o ../lib ar rcs $@ libc/strcpy.o libc/memset.o diff --git a/sys/src/kernel/main.c b/sys/src/kernel/main.c @@ -3,6 +3,7 @@ #include <draw.h> #include <console.h> #include <pci.h> +#include <xhc.h> error err; uint8 kernel_main_stack[1024]; @@ -49,12 +50,20 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) cons_printf(&con0, "hello world!\n"); cons_printf(&con0, "pixel at {%d, %d}: %x\n", p.x, p.y, get_pixel(&root_window, p)); pci_scan_all_bus(); + cons_printf(&con0, "pci devices:\n"); for (int i = 0; i < num_pci_dev; 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); } + cons_printf(&con0, "xhci devices:\n"); + for (int i = 0; i < num_pci_dev; i++) { + if (pci_dev[i].base_class == 0xc && pci_dev[i].sub_class == 0x3 && + pci_dev[i].prog == 0x30) { + cons_printf(&con0, "sizeof PCIDev: %d\n", sizeof(PCIDev)); + } + } halt: for(;;) { __asm__("hlt"); } diff --git a/sys/src/kernel/xhc.c b/sys/src/kernel/xhc.c @@ -0,0 +1,4 @@ +#include <libc.h> +#include <xhc.h> + +Xhc xhc;