Rev 1301 | Rev 1335 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1301 | Rev 1324 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * HelenOS PCI driver. |
2 | * HelenOS PCI driver. |
3 | * |
3 | * |
4 | * Copyright (C) 1997-2003 Martin Mares |
4 | * Copyright (C) 1997-2003 Martin Mares |
5 | * Copyright (C) 2006 Jakub Jermar |
5 | * Copyright (C) 2006 Jakub Jermar |
6 | * |
6 | * |
7 | * (Based on libpci example.c written by Martin Mares.) |
7 | * (Based on libpci example.c written by Martin Mares.) |
8 | * |
8 | * |
9 | * Can be freely distributed and used under the terms of the GNU GPL. |
9 | * Can be freely distributed and used under the terms of the GNU GPL. |
10 | */ |
10 | */ |
11 | 11 | ||
12 | #include <stdio.h> |
12 | #include <stdio.h> |
13 | #include <ddi.h> |
13 | #include <ddi.h> |
14 | #include <task.h> |
14 | #include <task.h> |
15 | #include <stdlib.h> |
15 | #include <stdlib.h> |
16 | 16 | ||
17 | #include "libpci/pci.h" |
17 | #include "libpci/pci.h" |
18 | 18 | ||
19 | #define PCI_CONF1 0xcf8 |
19 | #define PCI_CONF1 0xcf8 |
20 | #define PCI_CONF1_SIZE 8 |
20 | #define PCI_CONF1_SIZE 8 |
21 | 21 | ||
22 | int main(int argc, char *argv[]) |
22 | int main(int argc, char *argv[]) |
23 | { |
23 | { |
24 | struct pci_access *pacc; |
24 | struct pci_access *pacc; |
25 | struct pci_dev *dev; |
25 | struct pci_dev *dev; |
26 | unsigned int c; |
26 | unsigned int c; |
27 | char buf[80]; |
27 | char buf[80]; |
28 | 28 | ||
29 | printf("HelenOS PCI driver\n"); |
29 | printf("HelenOS PCI driver\n"); |
30 | 30 | ||
31 | /* |
31 | /* |
32 | * Gain control over PCI configuration ports. |
32 | * Gain control over PCI configuration ports. |
33 | */ |
33 | */ |
34 | iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE); |
34 | iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE); |
35 | 35 | ||
36 | pacc = pci_alloc(); /* Get the pci_access structure */ |
36 | pacc = pci_alloc(); /* Get the pci_access structure */ |
37 | pci_init(pacc); /* Initialize the PCI library */ |
37 | pci_init(pacc); /* Initialize the PCI library */ |
38 | pci_scan_bus(pacc); /* We want to get the list of devices */ |
38 | pci_scan_bus(pacc); /* We want to get the list of devices */ |
39 | for(dev=pacc->devices; dev; dev=dev->next) { /* Iterate over all devices */ |
39 | for(dev=pacc->devices; dev; dev=dev->next) { /* Iterate over all devices */ |
40 | pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES); /* Fill in header info we need */ |
40 | pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_IRQ); |
41 | c = pci_read_word(dev, PCI_CLASS_DEVICE); /* Read config register directly */ |
41 | c = pci_read_word(dev, PCI_CLASS_DEVICE); /* Read config register directly */ |
42 | printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d base0=%lx\n", |
42 | printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d base0=%lx\n", |
43 | dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id, |
43 | dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id, |
44 | c, dev->irq, dev->base_addr[0]); |
44 | c, dev->irq, dev->base_addr[0]); |
45 | printf("\t%s\n", pci_lookup_name(pacc, buf, sizeof(buf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, |
45 | printf("\t%s\n", pci_lookup_name(pacc, buf, sizeof(buf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, |
46 | dev->vendor_id, dev->device_id)); |
46 | dev->vendor_id, dev->device_id)); |
47 | } |
47 | } |
48 | pci_cleanup(pacc); /* Close everything */ |
48 | pci_cleanup(pacc); /* Close everything */ |
49 | 49 | ||
50 | return 0; |
50 | return 0; |
51 | } |
51 | } |
52 | 52 |