|
1 |
|
2 /* This header only makes sense when included in a 2.0 compile */ |
|
3 |
|
4 /* |
|
5 * Copyright (C) 2001 Alessandro Rubini and Jonathan Corbet |
|
6 * Copyright (C) 2001 O'Reilly & Associates |
|
7 * |
|
8 * The source code in this file can be freely used, adapted, |
|
9 * and redistributed in source or binary form, so long as an |
|
10 * acknowledgment appears in derived source files. The citation |
|
11 * should list that the code comes from the book "Linux Device |
|
12 * Drivers" by Alessandro Rubini and Jonathan Corbet, published |
|
13 * by O'Reilly & Associates. No warranty is attached; |
|
14 * we cannot take responsibility for errors or fitness for use. |
|
15 */ |
|
16 |
|
17 #ifndef _PCI_COMPAT_H_ |
|
18 #define _PCI_COMPAT_H_ |
|
19 |
|
20 #ifdef __KERNEL__ |
|
21 |
|
22 /* |
|
23 * This only makes sense if <linux/pci.h> is already included, *and* |
|
24 * we are using 2.0. |
|
25 */ |
|
26 #if defined(LINUX_PCI_H) && (LINUX_VERSION_CODE & 0xffff00) == 0x020000 |
|
27 |
|
28 #include <linux/bios32.h> /* pcibios_* */ |
|
29 #include <linux/malloc.h> /* kmalloc */ |
|
30 |
|
31 /* fake the new pci interface based on the old one: encapsulate bus/devfn */ |
|
32 struct pci_fake_dev { |
|
33 int index; |
|
34 unsigned short vendor, device; |
|
35 void *driver_data; /* net i.f. drivers make it point to net_device */ |
|
36 u8 bus; |
|
37 u8 devfn; |
|
38 }; |
|
39 #define pci_dev pci_fake_dev /* the other pci_dev is unused by 2.0 drivers */ |
|
40 |
|
41 |
|
42 #ifndef PCI_HEADER_TYPE_NORMAL /* These definitions are missing from 2.0 */ |
|
43 # define PCI_HEADER_TYPE_NORMAL 0 |
|
44 # define PCI_HEADER_TYPE_BRIDGE 1 |
|
45 # define PCI_PRIMARY_BUS 0x18 /* Primary bus number */ |
|
46 # define PCI_SECONDARY_BUS 0x19 /* Secondary bus number */ |
|
47 # define PCI_SUBORDINATE_BUS 0x1a /* Highest bus behind the bridge */ |
|
48 # define PCI_HEADER_TYPE_CARDBUS 2 |
|
49 # define PCI_CB_PRIMARY_BUS 0x18 /* PCI bus number */ |
|
50 # define PCI_CB_CARD_BUS 0x19 /* CardBus bus number */ |
|
51 # define PCI_CB_SUBORDINATE_BUS 0x1a /* Subordinate bus number */ |
|
52 #endif |
|
53 |
|
54 extern inline struct pci_dev *pci_find_device(unsigned int vendorid, |
|
55 unsigned int devid, |
|
56 struct pci_dev *from) |
|
57 { |
|
58 struct pci_dev *pptr = kmalloc(sizeof(*pptr), GFP_KERNEL); |
|
59 int index = 0; |
|
60 int ret; |
|
61 |
|
62 if (!pptr) return NULL; |
|
63 if (from) index = from->index + 1; |
|
64 pptr->index = index; |
|
65 ret = pcibios_find_device(vendorid, devid, index, |
|
66 &pptr->bus, &pptr->devfn); |
|
67 if (ret) { kfree(pptr); return NULL; } |
|
68 /* fill other fields */ |
|
69 pcibios_read_config_word(pptr->bus, pptr->devfn, |
|
70 PCI_VENDOR_ID, &pptr->vendor); |
|
71 pcibios_read_config_word(pptr->bus, pptr->devfn, |
|
72 PCI_DEVICE_ID, &pptr->device); |
|
73 return pptr; |
|
74 } |
|
75 |
|
76 #if 0 |
|
77 /* this used to be only the base class, Hmm... better not offer it*/ |
|
78 extern inline struct pci_dev *pci_find_class(unsigned int class, |
|
79 struct pci_dev *from) |
|
80 { |
|
81 struct pci_dev *pptr = kmalloc(sizeof(*pptr), GFP_KERNEL); |
|
82 int index = 0; |
|
83 int ret; |
|
84 |
|
85 if (!pptr) return NULL; |
|
86 if (from) index = from->index + 1; |
|
87 pptr->index = index; |
|
88 ret = pcibios_find_class(class, index, |
|
89 &pptr->bus, &pptr->devfn); |
|
90 if (ret) { kfree(pptr); return NULL; } |
|
91 /* fill other fields */ |
|
92 pcibios_read_config_word(pptr->bus, pptr->devfn, |
|
93 PCI_VENDOR_ID, &pptr->vendor); |
|
94 pcibios_read_config_word(pptr->bus, pptr->devfn, |
|
95 PCI_DEVICE_ID, &pptr->device); |
|
96 return pptr; |
|
97 } |
|
98 #endif |
|
99 |
|
100 /* this is used by pciregions instead */ |
|
101 extern inline struct pci_dev *pci_find_slot (unsigned int bus, |
|
102 unsigned int devfn) |
|
103 { |
|
104 struct pci_dev *pptr = kmalloc(sizeof(*pptr), GFP_KERNEL); |
|
105 int index = 0; |
|
106 unsigned short vendor; |
|
107 int ret; |
|
108 |
|
109 if (!pptr) return NULL; |
|
110 pptr->index = index; /* 0 */ |
|
111 ret = pcibios_read_config_word(bus, devfn, PCI_VENDOR_ID, &vendor); |
|
112 if (ret /* == PCIBIOS_DEVICE_NOT_FOUND or whatever error */ |
|
113 || vendor==0xffff || vendor==0x0000) { |
|
114 kfree(pptr); return NULL; |
|
115 } |
|
116 printk("ok (%i, %i %x)\n", bus, devfn, vendor); |
|
117 /* fill other fields */ |
|
118 pptr->bus = bus; |
|
119 pptr->devfn = devfn; |
|
120 pcibios_read_config_word(pptr->bus, pptr->devfn, |
|
121 PCI_VENDOR_ID, &pptr->vendor); |
|
122 pcibios_read_config_word(pptr->bus, pptr->devfn, |
|
123 PCI_DEVICE_ID, &pptr->device); |
|
124 return pptr; |
|
125 } |
|
126 |
|
127 |
|
128 |
|
129 /* this is not used in the real (2.2, 2.4) implementation, but we need it */ |
|
130 extern inline void pci_release_device(struct pci_dev *dev) |
|
131 { |
|
132 kfree(dev); |
|
133 } |
|
134 |
|
135 /* struct pci_dev *pci_find_slot (unsigned int bus, unsigned int devfn); */ |
|
136 |
|
137 #define pci_present pcibios_present |
|
138 |
|
139 extern inline int |
|
140 pci_read_config_byte(struct pci_dev *dev, u8 where, u8 *val) |
|
141 { |
|
142 return pcibios_read_config_byte(dev->bus, dev->devfn, where, val); |
|
143 } |
|
144 |
|
145 extern inline int |
|
146 pci_read_config_word(struct pci_dev *dev, u8 where, u16 *val) |
|
147 { |
|
148 return pcibios_read_config_word(dev->bus, dev->devfn, where, val); |
|
149 } |
|
150 |
|
151 extern inline int |
|
152 pci_read_config_dword(struct pci_dev *dev, u8 where, u32 *val) |
|
153 { |
|
154 return pcibios_read_config_dword(dev->bus, dev->devfn, where, val); |
|
155 } |
|
156 |
|
157 extern inline int |
|
158 pci_write_config_byte(struct pci_dev *dev, u8 where, u8 val) |
|
159 { |
|
160 return pcibios_write_config_byte(dev->bus, dev->devfn, where, val); |
|
161 } |
|
162 |
|
163 extern inline int |
|
164 pci_write_config_word(struct pci_dev *dev, u8 where, u16 val) |
|
165 { |
|
166 return pcibios_write_config_word(dev->bus, dev->devfn, where, val); |
|
167 } |
|
168 |
|
169 extern inline int |
|
170 pci_write_config_dword(struct pci_dev *dev, u8 where, u32 val) |
|
171 { |
|
172 return pcibios_write_config_dword(dev->bus, dev->devfn, where, val); |
|
173 } |
|
174 |
|
175 extern inline void pci_set_master(struct pci_dev *dev) |
|
176 { |
|
177 u16 cmd; |
|
178 pcibios_read_config_word(dev->bus, dev->devfn, PCI_COMMAND, &cmd); |
|
179 cmd |= PCI_COMMAND_MASTER; |
|
180 pcibios_write_config_word(dev->bus, dev->devfn, PCI_COMMAND, cmd); |
|
181 } |
|
182 |
|
183 #endif /* version 2.0 and pci.h included */ |
|
184 #endif /* __KERNEL__ */ |
|
185 #endif /* _PCI_COMPAT_H_ */ |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |