pci.c

Go to the documentation of this file.
00001 /*
00002  * HelenOS PCI driver.
00003  *
00004  * Copyright (C) 1997-2003 Martin Mares
00005  * Copyright (C) 2006 Jakub Jermar
00006  *
00007  * (Based on libpci example.c written by Martin Mares.)
00008  *
00009  * Can be freely distributed and used under the terms of the GNU GPL.
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          * Gain control over PCI configuration ports.
00045          */
00046         iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE);
00047 
00048         pacc = pci_alloc();           /* Get the pci_access structure */
00049         pci_init(pacc);               /* Initialize the PCI library */
00050         pci_scan_bus(pacc);           /* We want to get the list of devices */
00051         for(dev=pacc->devices; dev; dev=dev->next) {   /* Iterate over all devices */
00052                 pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_IRQ);
00053                 c = pci_read_word(dev, PCI_CLASS_DEVICE); /* Read config register directly */
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 

Generated on Sun Jun 18 17:54:21 2006 for HelenOS Userspace (ia32) by  doxygen 1.4.6