Subversion Repositories HelenOS

Rev

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

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