Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 1 | /* |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 2 | * PCI defines and function prototypes |
| 3 | * Copyright 1994, Drew Eckhardt |
| 4 | * Copyright 1997--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz> |
| 5 | * |
| 6 | * For more information, please consult the following manuals (look at |
| 7 | * http://www.pcisig.com/ for how to get them): |
| 8 | * |
| 9 | * PCI BIOS Specification |
| 10 | * PCI Local Bus Specification |
| 11 | * PCI to PCI Bridge Specification |
| 12 | * PCI System Design Guide |
| 13 | */ |
| 14 | |
| 15 | #ifndef PCI_H |
| 16 | #define PCI_H |
| 17 | |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 18 | #include <device/pci_def.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 19 | #include <device/resource.h> |
| 20 | #include <device/device.h> |
| 21 | #include <device/pci_ops.h> |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 22 | #include <device/pci_rom.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 23 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 24 | /* Common pci operations without a standard interface */ |
| 25 | struct pci_operations { |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 26 | /* set the Subsystem IDs for the PCI device */ |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 27 | void (*set_subsystem)(device_t dev, unsigned vendor, unsigned device); |
| 28 | }; |
| 29 | |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 30 | /* Common pci bus operations */ |
| 31 | struct pci_bus_operations { |
| 32 | uint8_t (*read8) (struct bus *pbus, unsigned char bus, int devfn, int where); |
| 33 | uint16_t (*read16) (struct bus *pbus, unsigned char bus, int devfn, int where); |
| 34 | uint32_t (*read32) (struct bus *pbus, unsigned char bus, int devfn, int where); |
| 35 | void (*write8) (struct bus *pbus, unsigned char bus, int devfn, int where, uint8_t val); |
| 36 | void (*write16) (struct bus *pbus, unsigned char bus, int devfn, int where, uint16_t val); |
| 37 | void (*write32) (struct bus *pbus, unsigned char bus, int devfn, int where, uint32_t val); |
| 38 | }; |
| 39 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 40 | struct pci_driver { |
| 41 | struct device_operations *ops; |
| 42 | unsigned short vendor; |
| 43 | unsigned short device; |
| 44 | }; |
| 45 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 46 | #define __pci_driver __attribute__ ((used,__section__(".rodata.pci_driver"))) |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 47 | /** start of compile time generated pci driver array */ |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 48 | extern struct pci_driver pci_drivers[]; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 49 | /** end of compile time generated pci driver array */ |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 50 | extern struct pci_driver epci_drivers[]; |
| 51 | |
| 52 | |
| 53 | struct device_operations default_pci_ops_dev; |
| 54 | struct device_operations default_pci_ops_bus; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 55 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 56 | void pci_dev_read_resources(device_t dev); |
| 57 | void pci_bus_read_resources(device_t dev); |
| 58 | void pci_dev_set_resources(device_t dev); |
| 59 | void pci_dev_enable_resources(device_t dev); |
| 60 | void pci_bus_enable_resources(device_t dev); |
| 61 | unsigned int pci_scan_bridge(device_t bus, unsigned int max); |
| 62 | unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn, unsigned max_devfn, unsigned int max); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 63 | struct resource *pci_get_resource(struct device *dev, unsigned long index); |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 64 | void pci_dev_set_subsystem(device_t dev, unsigned vendor, unsigned device); |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 65 | |
| 66 | #define PCI_IO_BRIDGE_ALIGN 4096 |
| 67 | #define PCI_MEM_BRIDGE_ALIGN (1024*1024) |
| 68 | |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 69 | static inline const struct pci_operations *ops_pci(device_t dev) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 70 | { |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 71 | const struct pci_operations *pops; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 72 | pops = 0; |
| 73 | if (dev && dev->ops) { |
| 74 | pops = dev->ops->ops_pci; |
| 75 | } |
| 76 | return pops; |
| 77 | } |
| 78 | |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 79 | static inline const struct pci_bus_operations *ops_pci_bus(struct bus *bus) |
| 80 | { |
| 81 | const struct pci_bus_operations *bops; |
| 82 | bops = 0; |
| 83 | if (bus && bus->dev && bus->dev->ops) { |
| 84 | bops = bus->dev->ops->ops_pci_bus; |
| 85 | } |
| 86 | return bops; |
| 87 | } |
| 88 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 89 | #endif /* PCI_H */ |