blob: 89265840726ef2591261d7432af1707452bceeba [file] [log] [blame]
Kevin O'Connorfaa8b6f2008-03-21 13:32:34 -04001#ifndef __PCI_H
2#define __PCI_H
3
Kevin O'Connora0dc2962008-03-16 14:29:32 -04004#include "types.h" // u32
5
Kevin O'Connor5fdaa032008-08-31 11:06:27 -04006static inline u8 pci_bdf_to_bus(u16 bdf) {
7 return bdf >> 8;
8}
Kevin O'Connorbe19cdc2008-11-09 15:33:47 -05009static inline u8 pci_bdf_to_devfn(u16 bdf) {
10 return bdf & 0xff;
11}
Kevin O'Connor5fdaa032008-08-31 11:06:27 -040012static inline u8 pci_bdf_to_dev(u16 bdf) {
13 return (bdf >> 3) & 0x1f;
14}
15static inline u8 pci_bdf_to_fn(u16 bdf) {
16 return bdf & 0x07;
17}
Kevin O'Connor423a04d2009-02-05 21:16:39 -050018static inline u16 pci_to_bdf(int bus, int dev, int fn) {
19 return (bus<<8) | (dev<<3) | fn;
20}
Kevin O'Connor0f803e42008-05-24 23:07:16 -040021
Kevin O'Connorbe19cdc2008-11-09 15:33:47 -050022void pci_config_writel(u16 bdf, u32 addr, u32 val);
23void pci_config_writew(u16 bdf, u32 addr, u16 val);
24void pci_config_writeb(u16 bdf, u32 addr, u8 val);
25u32 pci_config_readl(u16 bdf, u32 addr);
26u16 pci_config_readw(u16 bdf, u32 addr);
27u8 pci_config_readb(u16 bdf, u32 addr);
Kevin O'Connor0f803e42008-05-24 23:07:16 -040028
Kevin O'Connor04eece22009-07-19 19:05:30 -040029int pci_find_vga();
Kevin O'Connor4132e022008-12-04 19:39:10 -050030int pci_find_device(u16 vendid, u16 devid);
31int pci_find_class(u16 classid);
Kevin O'Connorbe19cdc2008-11-09 15:33:47 -050032
Kevin O'Connore6338322008-11-29 20:31:49 -050033int pci_next(int bdf, int *pmax);
Kevin O'Connor4132e022008-12-04 19:39:10 -050034#define foreachpci(BDF, MAX) \
35 for (MAX=0x0100, BDF=pci_next(0, &MAX) \
36 ; BDF >= 0 \
Kevin O'Connore6338322008-11-29 20:31:49 -050037 ; BDF=pci_next(BDF+1, &MAX))
Kevin O'Connorfaa8b6f2008-03-21 13:32:34 -040038
Kevin O'Connord25810a2008-06-12 22:16:35 -040039// pirtable.c
40void create_pirtable();
41
Kevin O'Connor061d1372008-06-11 22:39:46 -040042
43/****************************************************************
44 * PIR table
45 ****************************************************************/
46
Kevin O'Connor51358db2008-12-28 21:50:29 -050047extern u16 PirOffset;
48
Kevin O'Connor061d1372008-06-11 22:39:46 -040049struct link_info {
50 u8 link;
51 u16 bitmap;
52} PACKED;
53
54struct pir_slot {
55 u8 bus;
56 u8 dev;
57 struct link_info links[4];
58 u8 slot_nr;
59 u8 reserved;
60} PACKED;
61
Kevin O'Connord25810a2008-06-12 22:16:35 -040062struct pir_header {
63 u32 signature;
64 u16 version;
65 u16 size;
66 u8 router_bus;
67 u8 router_devfunc;
68 u16 exclusive_irqs;
69 u32 compatible_devid;
70 u32 miniport_data;
71 u8 reserved[11];
72 u8 checksum;
73 struct pir_slot slots[0];
74} PACKED;
75
76#define PIR_SIGNATURE 0x52495024 // $PIR
77
Kevin O'Connor061d1372008-06-11 22:39:46 -040078
Kevin O'Connorfaa8b6f2008-03-21 13:32:34 -040079#endif