Rev 1336 | Rev 1353 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1181 | jermar | 1 | /* |
1301 | jermar | 2 | * HelenOS PCI driver. |
3 | * |
||
4 | * Copyright (C) 1997-2003 Martin Mares |
||
1181 | jermar | 5 | * Copyright (C) 2006 Jakub Jermar |
6 | * |
||
1301 | jermar | 7 | * (Based on libpci example.c written by Martin Mares.) |
1181 | jermar | 8 | * |
1301 | jermar | 9 | * Can be freely distributed and used under the terms of the GNU GPL. |
1181 | jermar | 10 | */ |
11 | |||
12 | #include <stdio.h> |
||
13 | #include <ddi.h> |
||
14 | #include <task.h> |
||
15 | #include <stdlib.h> |
||
1335 | jermar | 16 | #include <ipc.h> |
1343 | jermar | 17 | #include <services.h> |
1335 | jermar | 18 | #include <errno.h> |
1181 | jermar | 19 | |
1301 | jermar | 20 | #include "libpci/pci.h" |
21 | |||
22 | #define PCI_CONF1 0xcf8 |
||
23 | #define PCI_CONF1_SIZE 8 |
||
24 | |||
1335 | jermar | 25 | #define NAME "PCI" |
26 | |||
1343 | jermar | 27 | static struct pci_access *pacc; |
28 | |||
1181 | jermar | 29 | int main(int argc, char *argv[]) |
30 | { |
||
1301 | jermar | 31 | struct pci_dev *dev; |
32 | unsigned int c; |
||
33 | char buf[80]; |
||
1336 | jermar | 34 | ipcarg_t ns_in_phone_hash; |
1301 | jermar | 35 | |
1335 | jermar | 36 | printf("%s: HelenOS PCI driver\n", NAME); |
37 | |||
1301 | jermar | 38 | /* |
39 | * Gain control over PCI configuration ports. |
||
40 | */ |
||
41 | iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE); |
||
42 | |||
43 | pacc = pci_alloc(); /* Get the pci_access structure */ |
||
44 | pci_init(pacc); /* Initialize the PCI library */ |
||
45 | 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 */ |
||
1324 | jermar | 47 | pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_IRQ); |
1301 | jermar | 48 | 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", |
||
50 | dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id, |
||
51 | 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, |
||
53 | dev->vendor_id, dev->device_id)); |
||
54 | } |
||
55 | |||
1335 | jermar | 56 | printf("%s: registering at naming service.\n", NAME); |
1343 | jermar | 57 | if (ipc_connect_to_me(PHONE_NS, SERVICE_PCI, 0, &ns_in_phone_hash) != 0) { |
1335 | jermar | 58 | printf("Failed to register %s at naming service.\n", NAME); |
59 | return -1; |
||
60 | } |
||
1343 | jermar | 61 | |
1335 | jermar | 62 | printf("%s: accepting connections\n", NAME); |
1343 | jermar | 63 | while (1) { |
1335 | jermar | 64 | ipc_call_t call; |
65 | ipc_callid_t callid; |
||
1343 | jermar | 66 | int retval; |
67 | |||
1335 | jermar | 68 | callid = ipc_wait_for_call(&call, 0); |
1343 | jermar | 69 | switch(IPC_GET_METHOD(call)) { |
70 | case IPC_M_CONNECT_ME_TO: |
||
71 | IPC_SET_RETVAL(call, 0); |
||
72 | break; |
||
73 | } |
||
74 | if (! (callid & IPC_CALLID_NOTIFICATION)) { |
||
75 | ipc_answer(callid, &call); |
||
76 | } |
||
77 | printf("%s: received call from %lX\n", NAME, call.in_phone_hash); |
||
1335 | jermar | 78 | } |
1343 | jermar | 79 | |
80 | pci_cleanup(pacc); |
||
1181 | jermar | 81 | return 0; |
82 | } |