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