Rev 1721 | Rev 1787 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1721 | Rev 1740 | ||
---|---|---|---|
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 | /** |
|
- | 13 | * @addtogroup pci |
|
- | 14 | * @{ |
|
- | 15 | */ |
|
- | 16 | ||
12 | #include <stdio.h> |
17 | #include <stdio.h> |
13 | #include <ddi.h> |
18 | #include <ddi.h> |
14 | #include <task.h> |
19 | #include <task.h> |
15 | #include <stdlib.h> |
20 | #include <stdlib.h> |
16 | #include <ipc/ipc.h> |
21 | #include <ipc/ipc.h> |
17 | #include <ipc/services.h> |
22 | #include <ipc/services.h> |
18 | #include <errno.h> |
23 | #include <errno.h> |
19 | 24 | ||
20 | #include "libpci/pci.h" |
25 | #include "libpci/pci.h" |
21 | 26 | ||
22 | #define PCI_CONF1 0xcf8 |
27 | #define PCI_CONF1 0xcf8 |
23 | #define PCI_CONF1_SIZE 8 |
28 | #define PCI_CONF1_SIZE 8 |
24 | 29 | ||
25 | #define NAME "PCI" |
30 | #define NAME "PCI" |
26 | 31 | ||
27 | static struct pci_access *pacc; |
32 | static struct pci_access *pacc; |
28 | 33 | ||
29 | int main(int argc, char *argv[]) |
34 | int main(int argc, char *argv[]) |
30 | { |
35 | { |
31 | struct pci_dev *dev; |
36 | struct pci_dev *dev; |
32 | unsigned int c; |
37 | unsigned int c; |
33 | char buf[80]; |
38 | char buf[80]; |
34 | ipcarg_t ns_in_phone_hash; |
39 | ipcarg_t ns_in_phone_hash; |
35 | 40 | ||
36 | printf("%s: HelenOS PCI driver\n", NAME); |
41 | printf("%s: HelenOS PCI driver\n", NAME); |
37 | 42 | ||
38 | /* |
43 | /* |
39 | * Gain control over PCI configuration ports. |
44 | * Gain control over PCI configuration ports. |
40 | */ |
45 | */ |
41 | iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE); |
46 | iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE); |
42 | 47 | ||
43 | pacc = pci_alloc(); /* Get the pci_access structure */ |
48 | pacc = pci_alloc(); /* Get the pci_access structure */ |
44 | pci_init(pacc); /* Initialize the PCI library */ |
49 | pci_init(pacc); /* Initialize the PCI library */ |
45 | pci_scan_bus(pacc); /* We want to get the list of devices */ |
50 | pci_scan_bus(pacc); /* We want to get the list of devices */ |
46 | for(dev=pacc->devices; dev; dev=dev->next) { /* Iterate over all devices */ |
51 | for(dev=pacc->devices; dev; dev=dev->next) { /* Iterate over all devices */ |
47 | pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_IRQ); |
52 | pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_IRQ); |
48 | c = pci_read_word(dev, PCI_CLASS_DEVICE); /* Read config register directly */ |
53 | c = pci_read_word(dev, PCI_CLASS_DEVICE); /* Read config register directly */ |
49 | printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d base0=%lx\n", |
54 | printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d base0=%lx\n", |
50 | dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id, |
55 | dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id, |
51 | c, dev->irq, dev->base_addr[0]); |
56 | c, dev->irq, dev->base_addr[0]); |
52 | printf("\t%s\n", pci_lookup_name(pacc, buf, sizeof(buf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, |
57 | printf("\t%s\n", pci_lookup_name(pacc, buf, sizeof(buf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, |
53 | dev->vendor_id, dev->device_id)); |
58 | dev->vendor_id, dev->device_id)); |
54 | } |
59 | } |
55 | 60 | ||
56 | printf("%s: registering at naming service.\n", NAME); |
61 | printf("%s: registering at naming service.\n", NAME); |
57 | if (ipc_connect_to_me(PHONE_NS, SERVICE_PCI, 0, &ns_in_phone_hash) != 0) { |
62 | if (ipc_connect_to_me(PHONE_NS, SERVICE_PCI, 0, &ns_in_phone_hash) != 0) { |
58 | printf("Failed to register %s at naming service.\n", NAME); |
63 | printf("Failed to register %s at naming service.\n", NAME); |
59 | return -1; |
64 | return -1; |
60 | } |
65 | } |
61 | 66 | ||
62 | printf("%s: accepting connections\n", NAME); |
67 | printf("%s: accepting connections\n", NAME); |
63 | while (1) { |
68 | while (1) { |
64 | ipc_call_t call; |
69 | ipc_call_t call; |
65 | ipc_callid_t callid; |
70 | ipc_callid_t callid; |
66 | 71 | ||
67 | callid = ipc_wait_for_call(&call); |
72 | callid = ipc_wait_for_call(&call); |
68 | switch(IPC_GET_METHOD(call)) { |
73 | switch(IPC_GET_METHOD(call)) { |
69 | case IPC_M_CONNECT_ME_TO: |
74 | case IPC_M_CONNECT_ME_TO: |
70 | IPC_SET_RETVAL(call, 0); |
75 | IPC_SET_RETVAL(call, 0); |
71 | break; |
76 | break; |
72 | } |
77 | } |
73 | if (! (callid & IPC_CALLID_NOTIFICATION)) { |
78 | if (! (callid & IPC_CALLID_NOTIFICATION)) { |
74 | ipc_answer(callid, &call); |
79 | ipc_answer(callid, &call); |
75 | } |
80 | } |
76 | printf("%s: received call from %lX\n", NAME, call.in_phone_hash); |
81 | printf("%s: received call from %lX\n", NAME, call.in_phone_hash); |
77 | } |
82 | } |
78 | 83 | ||
79 | pci_cleanup(pacc); |
84 | pci_cleanup(pacc); |
80 | return 0; |
85 | return 0; |
81 | } |
86 | } |
- | 87 | ||
- | 88 | /** |
|
- | 89 | * @} |
|
- | 90 | */ |
|
82 | 91 |