From: adar Date: Thu, 19 May 2005 10:32:13 +0000 (+0000) Subject: -Test commit\n-Add pci.[ch]\n X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=commitdiff_plain;h=c2edf1dc3e9a634fb7c68519d6cb6534a129e5b1 -Test commit\n-Add pci.[ch]\n --- diff --git a/src/Makefile.build b/src/Makefile.build index e124011..97edb71 100644 --- a/src/Makefile.build +++ b/src/Makefile.build @@ -28,6 +28,7 @@ devices_SRC += devices/vga.c # Video device. devices_SRC += devices/serial.c # Serial port device. devices_SRC += devices/disk.c # IDE disk device. devices_SRC += devices/intq.c # Interrupt queue. +devices_SRC += devices/pci.c # PCI device. # Library code shared between kernel and user programs. lib_SRC = lib/debug.c # Debug helpers. diff --git a/src/devices/pci.c b/src/devices/pci.c new file mode 100755 index 0000000..1fac33c --- /dev/null +++ b/src/devices/pci.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include "threads/io.h" +#include "devices/pci.h" + +static uint32_t +pci_read_config (unsigned bus, unsigned dev, unsigned func, unsigned reg) +{ + ASSERT (bus < 256); + ASSERT (dev < 32); + ASSERT (func < 8); + ASSERT (reg < 64); + + outl (0xcf8, + 0x80000000 | (bus << 16) | (dev << 11) | (func << 8) | (reg << 2)); + return inl (0xcfc); +} + +static bool +scan_device (int bus, int dev, int func) +{ + uint32_t cfg[16]; + int dev_id, vendor_id; + int line; + int reg; + + for (reg = 0; reg < 16; reg++) + cfg[reg] = pci_read_config (bus, dev, func, reg); + dev_id = cfg[0] >> 16; + vendor_id = cfg[0] & 0xffff; + + if (dev_id == 0 || dev_id == 0xffff + || vendor_id == 0 || vendor_id == 0xffff) + return 0; + + printf ("%04x:%02x:%02x.%x PCI device %04x:%04x\n", + 0, bus, dev, func, vendor_id, dev_id); + for (line = 0; line < 4; line++) + { + int byte; + + printf ("%02x:", line * 16); + for (byte = 0; byte < 16; byte++) + printf (" %02x", ((uint8_t *) cfg)[line * 16 + byte]); + printf ("\n"); + } + printf ("\n"); + + return cfg[3] & 0x00800000; +} + +void +pci_scan (void) +{ + int dev; + + printf ("PCI BUS: Scanning \n"); + + for (dev = 0; dev < 32; dev++) + { + if (scan_device (0, dev, 0)) + { + int func; + + for (func = 1; func < 8; func++) + scan_device (0, dev, func); + } + } + + printf ("PCI BUS: Done \n"); +} diff --git a/src/devices/pci.h b/src/devices/pci.h new file mode 100755 index 0000000..58fe4ea --- /dev/null +++ b/src/devices/pci.h @@ -0,0 +1 @@ +void pci_scan (void); diff --git a/src/threads/init.c b/src/threads/init.c index 51d6bdd..4d1aee8 100644 --- a/src/threads/init.c +++ b/src/threads/init.c @@ -28,6 +28,7 @@ #include "userprog/tss.h" #endif #ifdef FILESYS +#include "devices/pci.h" #include "devices/disk.h" #include "filesys/filesys.h" #include "filesys/fsutil.h" @@ -120,6 +121,8 @@ main (void) timer_calibrate (); #ifdef FILESYS + pci_scan (); + /* Initialize filesystem. */ disk_init (); filesys_init (format_filesys);