Subversion Repositories HelenOS

Rev

Rev 4221 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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