summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-06-07 13:28:16 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-06-07 13:28:16 +0200
commitbf8813b5bf010458504e24e29f684a191d8a9706 (patch)
tree9841005437f7e3af6af95e635927531eef0d91fa
parent03b54c5ab504e8a9abafaf60c7b4fed4f8629ea6 (diff)
downloadabaos-bf8813b5bf010458504e24e29f684a191d8a9706.tar.gz
abaos-bf8813b5bf010458504e24e29f684a191d8a9706.tar.bz2
scanning and printing PCI bus devices
-rw-r--r--doc/LINKS.TODO1
-rw-r--r--doc/README.PCI23
-rw-r--r--src/Makefile4
-rw-r--r--src/kernel.c3
-rw-r--r--src/mouse.c2
-rw-r--r--src/pci.c43
-rw-r--r--src/pci.h11
7 files changed, 83 insertions, 4 deletions
diff --git a/doc/LINKS.TODO b/doc/LINKS.TODO
index 66aa777..463d524 100644
--- a/doc/LINKS.TODO
+++ b/doc/LINKS.TODO
@@ -55,6 +55,7 @@ PCI:
http://wiki.osdev.org/PCI
https://www.lowlevel.eu/wiki/Peripheral_Component_Interconnect
http://www.ics.uci.edu/~harris/ics216/pci/PCI_22.pdf
+/usr/share/hwdata/pci.ids
assembly:
NASM
diff --git a/doc/README.PCI b/doc/README.PCI
new file mode 100644
index 0000000..b73c282
--- /dev/null
+++ b/doc/README.PCI
@@ -0,0 +1,23 @@
+0:0.0: 8086:1237 (class 6:0, rev: 2)
+8086 Intel
+1237 440FX - 82441FX PMC [Natoma]
+ 1af4 1100 Qemu virtual machine
+
+0:1.0: 8086:7000 (class 6:1, rev: 0)
+8086 Intel
+7000 82371SB PIIX3 ISA [Natoma/Triton II]
+ 1af4 1100 Qemu virtual machine
+
+0:1.1: 8086:7010 (class 1:1, rev: 0)
+8086 Intel
+7010 82371SB PIIX3 IDE [Natoma/Triton II]
+ 1af4 1100 Qemu virtual machine
+
+0:2.0: 1234:1111 (class 3:0, rev: 2)
+1234 Technical Corp
+ 1111 QEMU Standard VGA
+
+0:3.0: 10EC:8029 (class 2:0, rev: 0)
+10ec Realtek Semiconductor Co., Ltd.
+ 8029 RTL-8029(AS)
+ 1af4 1100 QEMU Virtual Machine
diff --git a/src/Makefile b/src/Makefile
index 9c793df..f258160 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -90,11 +90,11 @@ clean:
-rm -f boot.bin kernel.bin kernel.sym kernel.elf image.bin magic.bin *.o boot.map image.tmp
run-qemu: image.bin
- qemu-system-i386 -d guest_errors -m 32 -drive "file=image.bin,if=ide,format=raw" \
+ qemu-system-i386 -net nic,model=ne2k_pci -d guest_errors -m 32 -drive "file=image.bin,if=ide,format=raw" \
-serial file:serial.log
run-qemu-debug: image.bin
- qemu-system-i386 -S -s -d guest_errors -m 32 -drive "file=image.bin,if=ide,format=raw" \
+ qemu-system-i386 -net nic,model=ne2k_pci -S -s -d guest_errors -m 32 -drive "file=image.bin,if=ide,format=raw" \
-serial file:serial.log
run-bochs:
diff --git a/src/kernel.c b/src/kernel.c
index c84d28c..9a33644 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -40,7 +40,7 @@ void entry( void )
console_add_vga_output( &console, &vga );
// TODO: breaks on real hardware, we need proper interrupt handling
// and driver implementation as for the mouse and the keyboard
-// console_add_serial_output( &console, &serial );
+ console_add_serial_output( &console, &serial );
// initialize the early console of the kernel
stdio_set_console( &console );
@@ -77,6 +77,7 @@ void entry( void )
puts( "Detecting devices via PCI.." );
pci_controller_t pci_controller;
pci_controller_init( &pci_controller );
+ pci_controller_scan( &pci_controller );
puts( "Running.." );
diff --git a/src/mouse.c b/src/mouse.c
index d9d36e9..4e1e162 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -112,7 +112,7 @@ void mouse_init( mouse_t *mouse, mouse_event_handler_t handler, void *context, u
write_data( mouse, MOUSE_COMMAND_GET_DEVICE_ID );
read_ack( mouse );
uint8_t id = read_data( mouse );
- printf( "PS/2 model ID 0x%X\n", id );
+ printf( "PS/2 mouse model id is 0x%X\n", id );
if( id == 0x03 ) {
mouse->nof_packets = 4;
}
diff --git a/src/pci.c b/src/pci.c
index fce20df..3edb78a 100644
--- a/src/pci.c
+++ b/src/pci.c
@@ -1,6 +1,11 @@
#include "pci.h"
#include "string.h"
+#include "stdio.h"
+
+#define NOF_BUSES 8
+#define NOF_DEVICES_PER_BUS 32
+#define NOF_FUNCTIONS_PER_DEVICE 8
void pci_controller_init( pci_controller_t *controller )
{
@@ -46,3 +51,41 @@ void pci_controller_write( pci_controller_t *controller, uint16_t bus, uint16_t
port32_write( &controller->data_port, data );
}
+void pci_controller_scan( pci_controller_t *controller )
+{
+ for( int bus = 0; bus < NOF_BUSES; bus++ ) {
+ for( int device = 0; device < NOF_DEVICES_PER_BUS; device++ ) {
+ // TODO: detect single/multi function device from header
+ for( int function = 0; function < NOF_FUNCTIONS_PER_DEVICE; function++ ) {
+ pci_device_descriptor_t device_descriptor;
+ pci_device_descriptor_init( &device_descriptor, controller, bus, device, function );
+
+ // no device
+ if( device_descriptor.device_id == 0xFFFF ) {
+ break;
+ }
+
+ printf( "%X:%X.%d: %X:%X (class %X:%X, rev: %d)\n",
+ bus, device, function,
+ device_descriptor.vendor_id,
+ device_descriptor.device_id,
+ device_descriptor.class_id,
+ device_descriptor.subclass_id,
+ device_descriptor.revision_id );
+ }
+ }
+ }
+}
+
+void pci_device_descriptor_init( pci_device_descriptor_t *descriptor, pci_controller_t *controller, uint16_t bus, uint16_t device, uint16_t function )
+{
+ memset( descriptor, 0, sizeof( pci_device_descriptor_t ) );
+
+ descriptor->vendor_id = pci_controller_read( controller, bus, device, function, 0x00 );
+ descriptor->device_id = pci_controller_read( controller, bus, device, function, 0x02 );
+ descriptor->class_id = pci_controller_read( controller, bus, device, function, 0x0B );
+ descriptor->subclass_id = pci_controller_read( controller, bus, device, function, 0x0A );
+ descriptor->revision_id = pci_controller_read( controller, bus, device, function, 0x08 );
+}
+
+
diff --git a/src/pci.h b/src/pci.h
index 2381fc3..6f82f12 100644
--- a/src/pci.h
+++ b/src/pci.h
@@ -4,6 +4,14 @@
#include "port.h"
typedef struct {
+ uint16_t vendor_id;
+ uint16_t device_id;
+ uint8_t class_id;
+ uint8_t subclass_id;
+ uint8_t revision_id;
+} pci_device_descriptor_t;
+
+typedef struct {
port32_t command_port;
port32_t data_port;
} pci_controller_t;
@@ -12,5 +20,8 @@ void pci_controller_init( pci_controller_t *controller );
uint16_t pci_controller_read( pci_controller_t *controller, uint16_t bus, uint16_t device, uint16_t function, uint32_t offset );
void pci_controller_write( pci_controller_t *controller, uint16_t bus, uint16_t device, uint16_t function, uint32_t offset, uint32_t data );
+void pci_controller_scan( pci_controller_t *controller );
+
+void pci_device_descriptor_init( pci_device_descriptor_t *descriptor, pci_controller_t *controller, uint16_t bus, uint16_t device, uint16_t function );
#endif // PCI_H