~ubuntu-branches/ubuntu/oneiric/seabios/oneiric

« back to all changes in this revision

Viewing changes to .pc/0052-seabios-pci-introduce-helper-function-to-initialize-.patch/src/pci.h

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2010-10-22 11:04:31 UTC
  • Revision ID: james.westby@ubuntu.com-20101022110431-fnfj73ra6xkq623n
Tags: 0.6.0-0ubuntu2
Add all patches which were included in qemu-0.13.0-rc2 (per
commit on Jul 13, 2010).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __PCI_H
 
2
#define __PCI_H
 
3
 
 
4
#include "types.h" // u32
 
5
 
 
6
static inline u8 pci_bdf_to_bus(u16 bdf) {
 
7
    return bdf >> 8;
 
8
}
 
9
static inline u8 pci_bdf_to_devfn(u16 bdf) {
 
10
    return bdf & 0xff;
 
11
}
 
12
static inline u16 pci_bdf_to_busdev(u16 bdf) {
 
13
    return bdf & ~0x07;
 
14
}
 
15
static inline u8 pci_bdf_to_dev(u16 bdf) {
 
16
    return (bdf >> 3) & 0x1f;
 
17
}
 
18
static inline u8 pci_bdf_to_fn(u16 bdf) {
 
19
    return bdf & 0x07;
 
20
}
 
21
static inline u16 pci_to_bdf(int bus, int dev, int fn) {
 
22
    return (bus<<8) | (dev<<3) | fn;
 
23
}
 
24
static inline u16 pci_bus_devfn_to_bdf(int bus, u16 devfn) {
 
25
    return (bus << 8) | devfn;
 
26
}
 
27
 
 
28
static inline u32 pci_vd(u16 vendor, u16 device) {
 
29
    return (device << 16) | vendor;
 
30
}
 
31
static inline u16 pci_vd_to_ven(u32 vd) {
 
32
    return vd & 0xffff;
 
33
}
 
34
static inline u16 pci_vd_to_dev(u32 vd) {
 
35
    return vd >> 16;
 
36
}
 
37
 
 
38
void pci_config_writel(u16 bdf, u32 addr, u32 val);
 
39
void pci_config_writew(u16 bdf, u32 addr, u16 val);
 
40
void pci_config_writeb(u16 bdf, u32 addr, u8 val);
 
41
u32 pci_config_readl(u16 bdf, u32 addr);
 
42
u16 pci_config_readw(u16 bdf, u32 addr);
 
43
u8 pci_config_readb(u16 bdf, u32 addr);
 
44
void pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on);
 
45
 
 
46
int pci_find_vga(void);
 
47
int pci_find_device(u16 vendid, u16 devid);
 
48
int pci_find_class(u16 classid);
 
49
 
 
50
int pci_next(int bdf, int *pmax);
 
51
#define foreachpci(BDF, MAX)                    \
 
52
    for (MAX=0x0100, BDF=pci_next(0, &MAX)      \
 
53
         ; BDF >= 0                             \
 
54
         ; BDF=pci_next(BDF+1, &MAX))
 
55
 
 
56
#define foreachpci_in_bus(BDF, MAX, BUS)                                \
 
57
    for (MAX = pci_bus_devfn_to_bdf(BUS, 0) + 0x0100,                   \
 
58
         BDF = pci_next(pci_bus_devfn_to_bdf(BUS, 0), &MAX)             \
 
59
         ; BDF >= 0 && BDF < pci_bus_devfn_to_bdf(BUS, 0) + 0x0100      \
 
60
         ; MAX = pci_bus_devfn_to_bdf(BUS, 0) + 0x0100,                 \
 
61
           BDF = pci_next(BDF + 1, &MAX))
 
62
 
 
63
// pirtable.c
 
64
void create_pirtable(void);
 
65
 
 
66
 
 
67
/****************************************************************
 
68
 * PIR table
 
69
 ****************************************************************/
 
70
 
 
71
extern u16 PirOffset;
 
72
 
 
73
struct link_info {
 
74
    u8 link;
 
75
    u16 bitmap;
 
76
} PACKED;
 
77
 
 
78
struct pir_slot {
 
79
    u8 bus;
 
80
    u8 dev;
 
81
    struct link_info links[4];
 
82
    u8 slot_nr;
 
83
    u8 reserved;
 
84
} PACKED;
 
85
 
 
86
struct pir_header {
 
87
    u32 signature;
 
88
    u16 version;
 
89
    u16 size;
 
90
    u8 router_bus;
 
91
    u8 router_devfunc;
 
92
    u16 exclusive_irqs;
 
93
    u32 compatible_devid;
 
94
    u32 miniport_data;
 
95
    u8 reserved[11];
 
96
    u8 checksum;
 
97
    struct pir_slot slots[0];
 
98
} PACKED;
 
99
 
 
100
#define PIR_SIGNATURE 0x52495024 // $PIR
 
101
 
 
102
 
 
103
#endif