Subversion Repositories HelenOS

Rev

Rev 4438 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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