00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00017 #include <stdio.h>
00018 #include <ddi.h>
00019 #include <task.h>
00020 #include <stdlib.h>
00021 #include <ipc/ipc.h>
00022 #include <ipc/services.h>
00023 #include <errno.h>
00024
00025 #include "libpci/pci.h"
00026
00027 #define PCI_CONF1 0xcf8
00028 #define PCI_CONF1_SIZE 8
00029
00030 #define NAME "PCI"
00031
00032 static struct pci_access *pacc;
00033
00034 int main(int argc, char *argv[])
00035 {
00036 struct pci_dev *dev;
00037 unsigned int c;
00038 char buf[80];
00039 ipcarg_t ns_in_phone_hash;
00040
00041 printf("%s: HelenOS PCI driver\n", NAME);
00042
00043
00044
00045
00046 iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE);
00047
00048 pacc = pci_alloc();
00049 pci_init(pacc);
00050 pci_scan_bus(pacc);
00051 for(dev=pacc->devices; dev; dev=dev->next) {
00052 pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_IRQ);
00053 c = pci_read_word(dev, PCI_CLASS_DEVICE);
00054 printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d base0=%lx\n",
00055 dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id,
00056 c, dev->irq, dev->base_addr[0]);
00057 printf("\t%s\n", pci_lookup_name(pacc, buf, sizeof(buf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
00058 dev->vendor_id, dev->device_id));
00059 }
00060
00061 printf("%s: registering at naming service.\n", NAME);
00062 if (ipc_connect_to_me(PHONE_NS, SERVICE_PCI, 0, &ns_in_phone_hash) != 0) {
00063 printf("Failed to register %s at naming service.\n", NAME);
00064 return -1;
00065 }
00066
00067 printf("%s: accepting connections\n", NAME);
00068 while (1) {
00069 ipc_call_t call;
00070 ipc_callid_t callid;
00071
00072 callid = ipc_wait_for_call(&call);
00073 switch(IPC_GET_METHOD(call)) {
00074 case IPC_M_CONNECT_ME_TO:
00075 IPC_SET_RETVAL(call, 0);
00076 break;
00077 }
00078 if (! (callid & IPC_CALLID_NOTIFICATION)) {
00079 ipc_answer(callid, &call);
00080 }
00081 printf("%s: received call from %lX\n", NAME, call.in_phone_hash);
00082 }
00083
00084 pci_cleanup(pacc);
00085 return 0;
00086 }
00087