[6a347b1e] | 1 | /*
|
---|
[4a7c273] | 2 | * HelenOS PCI driver.
|
---|
[6a347b1e] | 3 | *
|
---|
[4a7c273] | 4 | * Copyright (C) 1997-2003 Martin Mares
|
---|
| 5 | * Copyright (C) 2006 Jakub Jermar
|
---|
[6a347b1e] | 6 | *
|
---|
[4a7c273] | 7 | * (Based on libpci example.c written by Martin Mares.)
|
---|
[6a347b1e] | 8 | *
|
---|
[4a7c273] | 9 | * Can be freely distributed and used under the terms of the GNU GPL.
|
---|
[6a347b1e] | 10 | */
|
---|
| 11 |
|
---|
[231a60a] | 12 | /**
|
---|
| 13 | * @addtogroup pci
|
---|
| 14 | * @{
|
---|
| 15 | */
|
---|
| 16 |
|
---|
[6a347b1e] | 17 | #include <stdio.h>
|
---|
| 18 | #include <ddi.h>
|
---|
| 19 | #include <task.h>
|
---|
| 20 | #include <stdlib.h>
|
---|
[38edb96] | 21 | #include <ipc/ipc.h>
|
---|
| 22 | #include <ipc/services.h>
|
---|
[babe786] | 23 | #include <errno.h>
|
---|
[6a347b1e] | 24 |
|
---|
[4a7c273] | 25 | #include "libpci/pci.h"
|
---|
| 26 |
|
---|
| 27 | #define PCI_CONF1 0xcf8
|
---|
| 28 | #define PCI_CONF1_SIZE 8
|
---|
| 29 |
|
---|
[babe786] | 30 | #define NAME "PCI"
|
---|
| 31 |
|
---|
[250717cc] | 32 | static struct pci_access *pacc;
|
---|
| 33 |
|
---|
[6a347b1e] | 34 | int main(int argc, char *argv[])
|
---|
| 35 | {
|
---|
[4a7c273] | 36 | struct pci_dev *dev;
|
---|
| 37 | unsigned int c;
|
---|
| 38 | char buf[80];
|
---|
[043dcc27] | 39 | ipcarg_t ns_in_phone_hash;
|
---|
[babe786] | 40 |
|
---|
| 41 | printf("%s: HelenOS PCI driver\n", NAME);
|
---|
[4a7c273] | 42 |
|
---|
| 43 | /*
|
---|
| 44 | * Gain control over PCI configuration ports.
|
---|
| 45 | */
|
---|
| 46 | iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE);
|
---|
| 47 |
|
---|
| 48 | pacc = pci_alloc(); /* Get the pci_access structure */
|
---|
| 49 | pci_init(pacc); /* Initialize the PCI library */
|
---|
| 50 | pci_scan_bus(pacc); /* We want to get the list of devices */
|
---|
| 51 | for(dev=pacc->devices; dev; dev=dev->next) { /* Iterate over all devices */
|
---|
[8071af9f] | 52 | pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_IRQ);
|
---|
[4a7c273] | 53 | c = pci_read_word(dev, PCI_CLASS_DEVICE); /* Read config register directly */
|
---|
| 54 | printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d base0=%lx\n",
|
---|
| 55 | dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id,
|
---|
| 56 | c, dev->irq, dev->base_addr[0]);
|
---|
| 57 | printf("\t%s\n", pci_lookup_name(pacc, buf, sizeof(buf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
|
---|
| 58 | dev->vendor_id, dev->device_id));
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[babe786] | 61 | printf("%s: registering at naming service.\n", NAME);
|
---|
[250717cc] | 62 | if (ipc_connect_to_me(PHONE_NS, SERVICE_PCI, 0, &ns_in_phone_hash) != 0) {
|
---|
[babe786] | 63 | printf("Failed to register %s at naming service.\n", NAME);
|
---|
| 64 | return -1;
|
---|
| 65 | }
|
---|
[250717cc] | 66 |
|
---|
[babe786] | 67 | printf("%s: accepting connections\n", NAME);
|
---|
[250717cc] | 68 | while (1) {
|
---|
[babe786] | 69 | ipc_call_t call;
|
---|
| 70 | ipc_callid_t callid;
|
---|
[250717cc] | 71 |
|
---|
[04a73cdf] | 72 | callid = ipc_wait_for_call(&call);
|
---|
[250717cc] | 73 | switch(IPC_GET_METHOD(call)) {
|
---|
| 74 | case IPC_M_CONNECT_ME_TO:
|
---|
| 75 | IPC_SET_RETVAL(call, 0);
|
---|
| 76 | break;
|
---|
| 77 | }
|
---|
| 78 | if (! (callid & IPC_CALLID_NOTIFICATION)) {
|
---|
| 79 | ipc_answer(callid, &call);
|
---|
| 80 | }
|
---|
| 81 | printf("%s: received call from %lX\n", NAME, call.in_phone_hash);
|
---|
[babe786] | 82 | }
|
---|
[250717cc] | 83 |
|
---|
| 84 | pci_cleanup(pacc);
|
---|
[6a347b1e] | 85 | return 0;
|
---|
| 86 | }
|
---|
[231a60a] | 87 |
|
---|
| 88 | /**
|
---|
| 89 | * @}
|
---|
| 90 | */
|
---|