libpci initial stuff
This commit is contained in:
parent
bf7f7a18f4
commit
3affd0ece8
11 changed files with 147 additions and 37 deletions
23
bus/pci.c
23
bus/pci.c
|
@ -21,41 +21,40 @@
|
|||
#include <grub/pci.h>
|
||||
|
||||
grub_pci_address_t
|
||||
grub_pci_make_address (int bus, int device, int function, int reg)
|
||||
grub_pci_make_address (grub_pci_device_t dev, int reg)
|
||||
{
|
||||
return (1 << 31) | (bus << 16) | (device << 11) | (function << 8) | (reg << 2);
|
||||
return (1 << 31) | (dev.bus << 16) | (dev.device << 11)
|
||||
| (dev.function << 8) | (reg << 2);
|
||||
}
|
||||
|
||||
void
|
||||
grub_pci_iterate (grub_pci_iteratefunc_t hook)
|
||||
{
|
||||
int bus;
|
||||
int dev;
|
||||
int func;
|
||||
grub_pci_device_t dev;
|
||||
grub_pci_address_t addr;
|
||||
grub_pci_id_t id;
|
||||
grub_uint32_t hdr;
|
||||
|
||||
for (bus = 0; bus < 256; bus++)
|
||||
for (dev.bus = 0; dev.bus < 256; dev.bus++)
|
||||
{
|
||||
for (dev = 0; dev < 32; dev++)
|
||||
for (dev.device = 0; dev.device < 32; dev.device++)
|
||||
{
|
||||
for (func = 0; func < 8; func++)
|
||||
for (dev.function = 0; dev.function < 8; dev.function++)
|
||||
{
|
||||
addr = grub_pci_make_address (bus, dev, func, 0);
|
||||
addr = grub_pci_make_address (dev, 0);
|
||||
id = grub_pci_read (addr);
|
||||
|
||||
/* Check if there is a device present. */
|
||||
if (id >> 16 == 0xFFFF)
|
||||
continue;
|
||||
|
||||
if (hook (bus, dev, func, id))
|
||||
if (hook (dev, id))
|
||||
return;
|
||||
|
||||
/* Probe only func = 0 if the device if not multifunction */
|
||||
if (func == 0)
|
||||
if (dev.function == 0)
|
||||
{
|
||||
addr = grub_pci_make_address (bus, dev, func, 3);
|
||||
addr = grub_pci_make_address (dev, 3);
|
||||
hdr = grub_pci_read (addr);
|
||||
if (!(hdr & 0x800000))
|
||||
break;
|
||||
|
|
|
@ -113,7 +113,7 @@ grub_ohci_writereg32 (struct grub_ohci *o,
|
|||
/* Iterate over all PCI devices. Determine if a device is an OHCI
|
||||
controller. If this is the case, initialize it. */
|
||||
static int NESTED_FUNC_ATTR
|
||||
grub_ohci_pci_iter (int bus, int device, int func,
|
||||
grub_ohci_pci_iter (grub_pci_device_t dev,
|
||||
grub_pci_id_t pciid __attribute__((unused)))
|
||||
{
|
||||
grub_uint32_t class_code;
|
||||
|
@ -126,7 +126,7 @@ grub_ohci_pci_iter (int bus, int device, int func,
|
|||
grub_uint32_t revision;
|
||||
grub_uint32_t frame_interval;
|
||||
|
||||
addr = grub_pci_make_address (bus, device, func, 2);
|
||||
addr = grub_pci_make_address (dev, 2);
|
||||
class_code = grub_pci_read (addr) >> 8;
|
||||
|
||||
interf = class_code & 0xFF;
|
||||
|
@ -138,7 +138,7 @@ grub_ohci_pci_iter (int bus, int device, int func,
|
|||
return 0;
|
||||
|
||||
/* Determine IO base address. */
|
||||
addr = grub_pci_make_address (bus, device, func, 4);
|
||||
addr = grub_pci_make_address (dev, 4);
|
||||
base = grub_pci_read (addr);
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -138,7 +138,7 @@ grub_uhci_portstatus (grub_usb_controller_t dev,
|
|||
/* Iterate over all PCI devices. Determine if a device is an UHCI
|
||||
controller. If this is the case, initialize it. */
|
||||
static int NESTED_FUNC_ATTR
|
||||
grub_uhci_pci_iter (int bus, int device, int func,
|
||||
grub_uhci_pci_iter (grub_pci_device_t dev,
|
||||
grub_pci_id_t pciid __attribute__((unused)))
|
||||
{
|
||||
grub_uint32_t class_code;
|
||||
|
@ -151,7 +151,7 @@ grub_uhci_pci_iter (int bus, int device, int func,
|
|||
struct grub_uhci *u;
|
||||
int i;
|
||||
|
||||
addr = grub_pci_make_address (bus, device, func, 2);
|
||||
addr = grub_pci_make_address (dev, 2);
|
||||
class_code = grub_pci_read (addr) >> 8;
|
||||
|
||||
interf = class_code & 0xFF;
|
||||
|
@ -163,7 +163,7 @@ grub_uhci_pci_iter (int bus, int device, int func,
|
|||
return 0;
|
||||
|
||||
/* Determine IO base address. */
|
||||
addr = grub_pci_make_address (bus, device, func, 8);
|
||||
addr = grub_pci_make_address (dev, 8);
|
||||
base = grub_pci_read (addr);
|
||||
/* Stop if there is no IO space base address defined. */
|
||||
if (! (base & 1))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue