blob: a0b6b9c3e3c356ec5afefedda167550b73a31971 [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'Connor59f02832009-10-12 10:09:15 -040028void pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on);
Kevin O'Connor0f803e42008-05-24 23:07:16 -040029
Kevin O'Connor04eece22009-07-19 19:05:30 -040030int pci_find_vga();
Kevin O'Connor4132e022008-12-04 19:39:10 -050031int pci_find_device(u16 vendid, u16 devid);
32int pci_find_class(u16 classid);
Kevin O'Connorbe19cdc2008-11-09 15:33:47 -050033
Kevin O'Connore6338322008-11-29 20:31:49 -050034int pci_next(int bdf, int *pmax);
Kevin O'Connor4132e022008-12-04 19:39:10 -050035#define foreachpci(BDF, MAX) \
36 for (MAX=0x0100, BDF=pci_next(0, &MAX) \
37 ; BDF >= 0 \
Kevin O'Connore6338322008-11-29 20:31:49 -050038 ; BDF=pci_next(BDF+1, &MAX))
Kevin O'Connorfaa8b6f2008-03-21 13:32:34 -040039
Kevin O'Connord25810a2008-06-12 22:16:35 -040040// pirtable.c
41void create_pirtable();
42
Kevin O'Connor061d1372008-06-11 22:39:46 -040043
44/****************************************************************
45 * PIR table
46 ****************************************************************/
47
Kevin O'Connor51358db2008-12-28 21:50:29 -050048extern u16 PirOffset;
49
Kevin O'Connor061d1372008-06-11 22:39:46 -040050struct link_info {
51 u8 link;
52 u16 bitmap;
53} PACKED;
54
55struct pir_slot {
56 u8 bus;
57 u8 dev;
58 struct link_info links[4];
59 u8 slot_nr;
60 u8 reserved;
61} PACKED;
62
Kevin O'Connord25810a2008-06-12 22:16:35 -040063struct pir_header {
64 u32 signature;
65 u16 version;
66 u16 size;
67 u8 router_bus;
68 u8 router_devfunc;
69 u16 exclusive_irqs;
70 u32 compatible_devid;
71 u32 miniport_data;
72 u8 reserved[11];
73 u8 checksum;
74 struct pir_slot slots[0];
75} PACKED;
76
77#define PIR_SIGNATURE 0x52495024 // $PIR
78
Kevin O'Connor061d1372008-06-11 22:39:46 -040079
Kevin O'Connorfaa8b6f2008-03-21 13:32:34 -040080#endif