Subversion Repositories HelenOS

Rev

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

Rev 1335 Rev 1336
1
/*
1
/*
2
 * HelenOS PCI driver.
2
 * HelenOS PCI driver.
3
 *
3
 *
4
 * Copyright (C) 1997-2003 Martin Mares
4
 * Copyright (C) 1997-2003 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.)
7
 * (Based on libpci example.c written by Martin Mares.)
8
 *
8
 *
9
 * Can be freely distributed and used under the terms of the GNU GPL.
9
 * Can be freely distributed and used under the terms of the GNU GPL.
10
 */
10
 */
11
 
11
 
12
#include <stdio.h>
12
#include <stdio.h>
13
#include <ddi.h>
13
#include <ddi.h>
14
#include <task.h>
14
#include <task.h>
15
#include <stdlib.h>
15
#include <stdlib.h>
16
#include <ipc.h>
16
#include <ipc.h>
17
#include <errno.h>
17
#include <errno.h>
18
 
18
 
19
#include "libpci/pci.h"
19
#include "libpci/pci.h"
20
 
20
 
21
#define PCI_CONF1   0xcf8
21
#define PCI_CONF1   0xcf8
22
#define PCI_CONF1_SIZE  8
22
#define PCI_CONF1_SIZE  8
23
 
23
 
24
#define NAME        "PCI"
24
#define NAME        "PCI"
25
 
25
 
26
int main(int argc, char *argv[])
26
int main(int argc, char *argv[])
27
{
27
{
28
    struct pci_access *pacc;
28
    struct pci_access *pacc;
29
    struct pci_dev *dev;
29
    struct pci_dev *dev;
30
    unsigned int c;
30
    unsigned int c;
31
    char buf[80];
31
    char buf[80];
32
 
32
 
33
    int ipc_res;
33
    int ipc_res;
34
    ipcarg_t ns_phone_addr;
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
    /*
38
    /*
39
     * Gain control over PCI configuration ports.
39
     * Gain control over PCI configuration ports.
40
     */
40
     */
41
    iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE);
41
    iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE);
42
 
42
 
43
    pacc = pci_alloc();           /* Get the pci_access structure */
43
    pacc = pci_alloc();           /* Get the pci_access structure */
44
    pci_init(pacc);               /* Initialize the PCI library */
44
    pci_init(pacc);               /* Initialize the PCI library */
45
    pci_scan_bus(pacc);           /* We want to get the list of devices */
45
    pci_scan_bus(pacc);           /* We want to get the list of devices */
46
    for(dev=pacc->devices; dev; dev=dev->next) {   /* Iterate over all devices */
46
    for(dev=pacc->devices; dev; dev=dev->next) {   /* Iterate over all devices */
47
        pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_IRQ);
47
        pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_IRQ);
48
        c = pci_read_word(dev, PCI_CLASS_DEVICE); /* Read config register directly */
48
        c = pci_read_word(dev, PCI_CLASS_DEVICE); /* Read config register directly */
49
        printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d base0=%lx\n",
49
        printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d base0=%lx\n",
50
            dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id,
50
            dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id,
51
            c, dev->irq, dev->base_addr[0]);
51
            c, dev->irq, dev->base_addr[0]);
52
        printf("\t%s\n", pci_lookup_name(pacc, buf, sizeof(buf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
52
        printf("\t%s\n", pci_lookup_name(pacc, buf, sizeof(buf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
53
            dev->vendor_id, dev->device_id));
53
            dev->vendor_id, dev->device_id));
54
    }
54
    }
55
    pci_cleanup(pacc);            /* Close everything */
55
    pci_cleanup(pacc);            /* Close everything */
56
 
56
 
57
    printf("%s: registering at naming service.\n", NAME);
57
    printf("%s: registering at naming service.\n", NAME);
58
    if (ipc_connect_to_me(PHONE_NS, 40, 70, &ns_phone_addr) != 0) {
58
    if (ipc_connect_to_me(PHONE_NS, 40, 70, &ns_in_phone_hash) != 0) {
59
        printf("Failed to register %s at naming service.\n", NAME);
59
        printf("Failed to register %s at naming service.\n", NAME);
60
        return -1;
60
        return -1;
61
    }
61
    }
62
   
62
   
63
    printf("%s: accepting connections\n", NAME);
63
    printf("%s: accepting connections\n", NAME);
64
    while (1) {
64
    while (1) {
65
        ipc_call_t call;
65
        ipc_call_t call;
66
        ipc_callid_t callid;
66
        ipc_callid_t callid;
67
       
67
       
68
        callid = ipc_wait_for_call(&call, 0);
68
        callid = ipc_wait_for_call(&call, 0);
69
        ipc_answer(callid, EHANGUP, 0, 0);
69
        ipc_answer(callid, EHANGUP, 0, 0);
70
    }
70
    }
71
    return 0;
71
    return 0;
72
}
72
}
73
 
73