Subversion Repositories HelenOS

Rev

Rev 4537 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4399 trochtova 1
#ifndef PCI_H
2
#define PCI_H
3
 
4537 trochtova 4
#include <adt/list.h>
4399 trochtova 5
#include <stdio.h>
4438 trochtova 6
#include <stdlib.h>
4537 trochtova 7
#include <string.h>
4399 trochtova 8
 
9
struct pci_drv;
10
struct pci_dev;
11
struct pci_bus;
12
struct pci_drv_ops;
13
 
14
typedef struct pci_drv pci_drv_t;
15
typedef struct pci_dev pci_dev_t;
16
typedef struct pci_bus pci_bus_t;
17
typedef struct pci_drv_ops pci_drv_ops_t;
18
 
19
struct pci_drv {
4667 trochtova 20
    const char *name;
4399 trochtova 21
    link_t link;
22
    int vendor_id;
23
    int device_id; 
24
    pci_drv_ops_t *ops;
25
};
26
 
27
struct pci_dev{
28
    link_t link;
29
    pci_bus_t *bus;
30
    int dev;
31
    int fn;
32
 
33
    int vendor_id;
34
    int device_id;
35
    pci_drv_t *driver; 
36
};
37
 
38
struct pci_drv_ops {
39
    int (*add_device)(pci_dev_t *dev);
40
 
41
};
42
 
43
struct pci_bus {
44
    link_t link;
45
    int num;
46
    // architecture-specific usage
47
    void *data;
48
};
49
 
50
void pci_bus_register(pci_bus_t *bus);
51
void pci_device_register(pci_dev_t *dev);
52
void pci_driver_register(pci_drv_t *drv);
53
 
54
void pci_bus_scan(pci_bus_t *bus);
55
 
56
static inline pci_bus_t* pci_alloc_bus()
57
{
58
    pci_bus_t *bus = (pci_bus_t *)malloc(sizeof(pci_bus_t));
59
    link_initialize(&bus->link);
60
    bus->num = 0;
61
    bus->data = NULL;
62
    return bus;
63
}
64
 
65
// arch. spec. initialization of pci bus structure - of its data member
66
void pci_init_bus_data(pci_bus_t *bus, pci_bus_t *parent);
67
 
68
static inline void pci_init_bus(pci_bus_t *bus, pci_bus_t *parent, int bus_num)
69
{
70
    bus->num = bus_num;
71
    pci_init_bus_data(bus, parent);
72
}
73
 
74
static inline void pci_free_bus(pci_bus_t *bus)
75
{
76
    free(bus);
77
}
78
 
79
static inline pci_dev_t* pci_alloc_dev()
80
{
81
    pci_dev_t *dev = (pci_dev_t *)malloc(sizeof(pci_dev_t));
82
    bzero(dev, sizeof(pci_dev_t));
83
    link_initialize(&dev->link);   
84
    return dev;
85
}
86
 
87
static inline void pci_init_dev(pci_dev_t *dev, pci_bus_t *bus, int devnum, int fn)
88
{
89
    dev->bus = bus;
90
    dev->dev = devnum;
91
    dev->fn = fn;
92
}
93
 
94
static inline void pci_free_dev(pci_dev_t *dev)
95
{
96
    free(dev);
97
}
98
 
99
#endif