瀏覽代碼

Matches new pci.c interface.

tags/v0.9.3
Michael Brown 19 年之前
父節點
當前提交
6343381e25
共有 1 個文件被更改,包括 82 次插入114 次删除
  1. 82
    114
      src/include/pci.h

+ 82
- 114
src/include/pci.h 查看文件

@@ -21,8 +21,14 @@
21 21
  * your option) any later version.
22 22
  */
23 23
 
24
+#include "stdint.h"
24 25
 #include "pci_ids.h"
25 26
 
27
+/*
28
+ * PCI constants
29
+ *
30
+ */
31
+
26 32
 #define PCI_COMMAND_IO			0x1	/* Enable response in I/O space */
27 33
 #define PCI_COMMAND_MEM			0x2	/* Enable response in mem space */
28 34
 #define PCI_COMMAND_MASTER		0x4	/* Enable bus mastering */
@@ -35,17 +41,6 @@
35 41
 #define  PCI_COMMAND_SERR	0x100	/* Enable SERR */
36 42
 #define  PCI_COMMAND_FAST_BACK	0x200	/* Enable back-to-back writes */
37 43
 
38
-#define PCIBIOS_PCI_FUNCTION_ID         0xb1XX
39
-#define PCIBIOS_PCI_BIOS_PRESENT        0xb101
40
-#define PCIBIOS_FIND_PCI_DEVICE         0xb102
41
-#define PCIBIOS_FIND_PCI_CLASS_CODE     0xb103
42
-#define PCIBIOS_GENERATE_SPECIAL_CYCLE  0xb106
43
-#define PCIBIOS_READ_CONFIG_BYTE        0xb108
44
-#define PCIBIOS_READ_CONFIG_WORD        0xb109
45
-#define PCIBIOS_READ_CONFIG_DWORD       0xb10a
46
-#define PCIBIOS_WRITE_CONFIG_BYTE       0xb10b
47
-#define PCIBIOS_WRITE_CONFIG_WORD       0xb10c
48
-#define PCIBIOS_WRITE_CONFIG_DWORD      0xb10d
49 44
 
50 45
 #define PCI_VENDOR_ID           0x00    /* 16 bits */
51 46
 #define PCI_DEVICE_ID           0x02    /* 16 bits */
@@ -238,125 +233,98 @@
238 233
 #define PCI_MSI_DATA_32		8	/* 16 bits of data for 32-bit devices */
239 234
 #define PCI_MSI_DATA_64		12	/* 16 bits of data for 64-bit devices */
240 235
 
241
-#define PCI_SLOT(devfn)		  ((devfn) >> 3)
242
-#define PCI_FUNC(devfn)           ((devfn) & 0x07)
243
-
244
-#define BIOS32_SIGNATURE        (('_' << 0) + ('3' << 8) + ('2' << 16) + ('_' << 24))
245
-
246
-/* PCI signature: "PCI " */
247
-#define PCI_SIGNATURE           (('P' << 0) + ('C' << 8) + ('I' << 16) + (' ' << 24))
248
-
249
-/* PCI service signature: "$PCI" */
250
-#define PCI_SERVICE             (('$' << 0) + ('P' << 8) + ('C' << 16) + ('I' << 24))
251
-
252
-union bios32 {
253
-	struct {
254
-		unsigned long signature;	/* _32_ */
255
-		unsigned long entry;		/* 32 bit physical address */
256
-		unsigned char revision;		/* Revision level, 0 */
257
-		unsigned char length;		/* Length in paragraphs should be 01 */
258
-		unsigned char checksum;		/* All bytes must add up to zero */
259
-		unsigned char reserved[5];	/* Must be zero */
260
-	} fields;
261
-	char chars[16];
262
-};
263
-
264
-struct pci_device;
265
-struct dev;
266
-typedef int (*pci_probe_t)(struct dev *, struct pci_device *);
267
-
236
+/*
237
+ * A physical PCI device
238
+ *
239
+ */
268 240
 struct pci_device {
269
-	uint32_t		class;
241
+	uint32_t		membase;	/* BAR 1 */
242
+	uint32_t		ioaddr;		/* first IO BAR */
270 243
 	uint16_t		vendor, dev_id;
271
-	const char		*name;
272
-	/* membase and ioaddr are silly and depricated */
273
-	unsigned int		membase;
274
-	unsigned int		ioaddr;
275
-	unsigned int		romaddr;
276
-	unsigned char		irq;
277
-	unsigned char		devfn;
278
-	unsigned char		bus;
279
-	unsigned char		use_specified;
280
-	const struct pci_driver	*driver;
244
+	uint16_t		class;
245
+	uint16_t		busdevfn;
246
+	uint8_t			revision;
247
+	uint8_t			irq;
281 248
 };
249
+#define PCI_BUS(busdevfn)	( ( (busdevfn) >> 8 ) & 0xff )
250
+#define PCI_DEV(busdevfn)	( ( (busdevfn) >> 3 ) & 0x1f )
251
+#define PCI_FUNC(busdevfn)      ( (busdevfn) & 0x07 )
282 252
 
283
-extern void scan_pci_bus(int type, struct pci_device *dev);
284
-extern void find_pci(int type, struct pci_device *dev);
285
-
286
-extern int pcibios_read_config_byte(unsigned int bus, unsigned int device_fn, unsigned int where, uint8_t *value);
287
-extern int pcibios_write_config_byte (unsigned int bus, unsigned int device_fn, unsigned int where, uint8_t value);
288
-extern int pcibios_read_config_word(unsigned int bus, unsigned int device_fn, unsigned int where, uint16_t *value);
289
-extern int pcibios_write_config_word (unsigned int bus, unsigned int device_fn, unsigned int where, uint16_t value);
290
-extern int pcibios_read_config_dword(unsigned int bus, unsigned int device_fn, unsigned int where, uint32_t *value);
291
-extern int pcibios_write_config_dword(unsigned int bus, unsigned int device_fn, unsigned int where, uint32_t value);
292
-extern unsigned long pcibios_bus_base(unsigned int bus);
293
-extern void adjust_pci_device(struct pci_device *p);
294
-
295
-
296
-static inline int 
297
-pci_read_config_byte(struct pci_device *dev, unsigned int where, uint8_t *value)
298
-{
299
-	return pcibios_read_config_byte(dev->bus, dev->devfn, where, value);
300
-}
301
-static inline int 
302
-pci_write_config_byte(struct pci_device *dev, unsigned int where, uint8_t value)
303
-{
304
-	return pcibios_write_config_byte(dev->bus, dev->devfn, where, value);
305
-}
306
-static inline int 
307
-pci_read_config_word(struct pci_device *dev, unsigned int where, uint16_t *value)
308
-{
309
-	return pcibios_read_config_word(dev->bus, dev->devfn, where, value);
310
-}
311
-static inline int 
312
-pci_write_config_word(struct pci_device *dev, unsigned int where, uint16_t value)
313
-{
314
-	return pcibios_write_config_word(dev->bus, dev->devfn, where, value);
315
-}
316
-static inline int 
317
-pci_read_config_dword(struct pci_device *dev, unsigned int where, uint32_t *value)
318
-{
319
-	return pcibios_read_config_dword(dev->bus, dev->devfn, where, value);
320
-}
321
-static inline int 
322
-pci_write_config_dword(struct pci_device *dev, unsigned int where, uint32_t value)
323
-{
324
-	return pcibios_write_config_dword(dev->bus, dev->devfn, where, value);
325
-}
326
-
327
-/* Helper functions to find the size of a pci bar */
328
-extern unsigned long pci_bar_start(struct pci_device *dev, unsigned int bar);
329
-extern unsigned long pci_bar_size(struct pci_device *dev, unsigned int bar);
330
-/* Helper function to find pci capabilities */
331
-extern int pci_find_capability(struct pci_device *dev, int cap);
253
+/*
254
+ * An individual PCI device identified by vendor and device IDs
255
+ *
256
+ */
332 257
 struct pci_id {
333 258
 	unsigned short vendor, dev_id;
334 259
 	const char *name;
335 260
 };
336 261
 
337
-struct dev;
338
-/* Most pci drivers will use this */
262
+/*
263
+ * PCI_ROM is used to build up entries in a struct pci_id array.  It
264
+ * is also parsed by parserom.pl to generate Makefile rules and files
265
+ * for rom-o-matic.
266
+ */
267
+#define PCI_ROM( rom_vendor, rom_dev_id, rom_name, rom_description ) {	\
268
+	.vendor = rom_vendor,						\
269
+	.dev_id = rom_dev_id,						\
270
+	.name = rom_name,						\
271
+}
272
+
273
+/*
274
+ * A PCI driver, with a device ID (struct pci_id) table and an
275
+ * optional class.
276
+ *
277
+ * Set the class to something other than PCI_NO_CLASS if the driver
278
+ * can handle an entire class of devices.
279
+ *
280
+ */
339 281
 struct pci_driver {
340
-	int type;
341 282
 	const char *name;
342
-	pci_probe_t probe;
343 283
 	struct pci_id *ids;
344 284
 	int id_count;
285
+	uint16_t class;
286
+};
287
+#define PCI_NO_CLASS 0
345 288
 
346
-/* On a few occasions the hardware is standardized enough that
347
- * we only need to know the class of the device and not the exact
348
- * type to drive the device correctly.  If this is the case
349
- * set a class value other than 0.
289
+/*
290
+ * Define a PCI driver.
291
+ *
350 292
  */
351
-	unsigned short class;
352
-};
293
+#define PCI_DRIVER( driver_name, pci_ids, pci_class ) {			\
294
+	.name = driver_name,						\
295
+	.ids = pci_ids,							\
296
+	.id_count = sizeof ( pci_ids ) / sizeof ( pci_ids[0] ),		\
297
+	.class = pci_class,						\
298
+}
353 299
 
354
-#define __pci_driver	__attribute__ ((used,__section__(".drivers.pci")))
355
-/* Defined by the linker... */
356
-extern const struct pci_driver pci_drivers[];
357
-extern const struct pci_driver pci_drivers_end[];
300
+/*
301
+ * These are the functions we expect pci_io.c to provide.
302
+ *
303
+ */
304
+extern int pci_read_config_byte	( struct pci_device *dev, unsigned int where,
305
+				  uint8_t *value );
306
+extern int pci_write_config_byte ( struct pci_device *dev, unsigned int where,
307
+				   uint8_t value );
308
+extern int pci_read_config_word ( struct pci_device *dev, unsigned int where,
309
+				  uint16_t *value );
310
+extern int pci_write_config_word ( struct pci_device *dev, unsigned int where,
311
+				   uint16_t value );
312
+extern int pci_read_config_dword ( struct pci_device *dev, unsigned int where,
313
+				   uint32_t *value );
314
+extern int pci_write_config_dword ( struct pci_device *dev, unsigned int where,
315
+				    uint32_t value );
316
+extern unsigned long pci_bus_base ( struct pci_device *dev );
358 317
 
359
-#define PCI_ROM(VENDOR_ID, DEVICE_ID, IMAGE, DESCRIPTION) \
360
-	{ VENDOR_ID, DEVICE_ID, IMAGE, }
318
+/*
319
+ * Functions in pci.c
320
+ *
321
+ */
322
+extern void set_pci_device ( uint16_t busdevfn );
323
+extern struct pci_device * find_pci_device ( struct pci_driver *driver,
324
+					     struct dev *dev );
325
+extern unsigned long pci_bar_start ( struct pci_device *pci,
326
+				     unsigned int bar );
327
+extern unsigned long pci_bar_size ( struct pci_device *pci, unsigned int bar );
328
+extern int pci_find_capability ( struct pci_device *pci, int capability );
361 329
 
362 330
 #endif	/* PCI_H */

Loading…
取消
儲存