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 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 18 | #include <stdint.h> |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 19 | #include <device/pci_def.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 20 | #include <device/resource.h> |
| 21 | #include <device/device.h> |
| 22 | #include <device/pci_ops.h> |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 23 | #include <device/pci_rom.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 24 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 25 | /* Common pci operations without a standard interface */ |
| 26 | struct pci_operations { |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 27 | /* set the Subsystem IDs for the PCI device */ |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 28 | void (*set_subsystem)(device_t dev, unsigned vendor, unsigned device); |
| 29 | }; |
| 30 | |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 31 | /* Common pci bus operations */ |
| 32 | struct pci_bus_operations { |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 33 | uint8_t (*read8) (struct bus *pbus, int bus, int devfn, int where); |
| 34 | uint16_t (*read16) (struct bus *pbus, int bus, int devfn, int where); |
| 35 | uint32_t (*read32) (struct bus *pbus, int bus, int devfn, int where); |
| 36 | void (*write8) (struct bus *pbus, int bus, int devfn, int where, uint8_t val); |
| 37 | void (*write16) (struct bus *pbus, int bus, int devfn, int where, uint16_t val); |
| 38 | void (*write32) (struct bus *pbus, int bus, int devfn, int where, uint32_t val); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 41 | struct pci_driver { |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 42 | const struct device_operations *ops; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 43 | unsigned short vendor; |
| 44 | unsigned short device; |
Vadim Bendebury | 8049fc9 | 2012-04-24 12:53:19 -0700 | [diff] [blame] | 45 | const unsigned short *devices; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 48 | #define __pci_driver __attribute__ ((used,__section__(".rodata.pci_driver"))) |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 49 | /** start of compile time generated pci driver array */ |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 50 | extern struct pci_driver pci_drivers[]; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 51 | /** end of compile time generated pci driver array */ |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 52 | extern struct pci_driver epci_drivers[]; |
| 53 | |
| 54 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 55 | extern struct device_operations default_pci_ops_dev; |
| 56 | extern struct device_operations default_pci_ops_bus; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 57 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 58 | void pci_dev_read_resources(device_t dev); |
| 59 | void pci_bus_read_resources(device_t dev); |
| 60 | void pci_dev_set_resources(device_t dev); |
| 61 | void pci_dev_enable_resources(device_t dev); |
| 62 | void pci_bus_enable_resources(device_t dev); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 63 | void pci_bus_reset(struct bus *bus); |
| 64 | device_t pci_probe_dev(device_t dev, struct bus *bus, unsigned devfn); |
| 65 | unsigned int do_pci_scan_bridge(device_t bus, unsigned int max, |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 66 | unsigned int (*do_scan_bus)(struct bus *bus, |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 67 | unsigned min_devfn, unsigned max_devfn, unsigned int max)); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 68 | unsigned int pci_scan_bridge(device_t bus, unsigned int max); |
| 69 | unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn, unsigned max_devfn, unsigned int max); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 70 | uint8_t pci_moving_config8(struct device *dev, unsigned reg); |
| 71 | uint16_t pci_moving_config16(struct device *dev, unsigned reg); |
| 72 | uint32_t pci_moving_config32(struct device *dev, unsigned reg); |
| 73 | unsigned pci_find_next_capability(device_t dev, unsigned cap, unsigned last); |
| 74 | unsigned pci_find_capability(device_t dev, unsigned cap); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 75 | struct resource *pci_get_resource(struct device *dev, unsigned long index); |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 76 | void pci_dev_set_subsystem(device_t dev, unsigned vendor, unsigned device); |
Myles Watson | 43bb9cd | 2008-12-18 18:24:11 +0000 | [diff] [blame] | 77 | void pci_dev_init(struct device *dev); |
Stefan Reinauer | 4d933dd | 2009-07-21 21:36:41 +0000 | [diff] [blame] | 78 | |
Myles Watson | 43bb9cd | 2008-12-18 18:24:11 +0000 | [diff] [blame] | 79 | void pci_assign_irqs(unsigned bus, unsigned slot, |
| 80 | const unsigned char pIntAtoD[4]); |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 81 | |
| 82 | #define PCI_IO_BRIDGE_ALIGN 4096 |
| 83 | #define PCI_MEM_BRIDGE_ALIGN (1024*1024) |
| 84 | |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 85 | static inline const struct pci_operations *ops_pci(device_t dev) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 86 | { |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 87 | const struct pci_operations *pops; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 88 | pops = 0; |
| 89 | if (dev && dev->ops) { |
| 90 | pops = dev->ops->ops_pci; |
| 91 | } |
| 92 | return pops; |
| 93 | } |
| 94 | |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 95 | static inline const struct pci_bus_operations *ops_pci_bus(struct bus *bus) |
| 96 | { |
| 97 | const struct pci_bus_operations *bops; |
| 98 | bops = 0; |
| 99 | if (bus && bus->dev && bus->dev->ops) { |
| 100 | bops = bus->dev->ops->ops_pci_bus; |
| 101 | } |
Carl-Daniel Hailfinger | 00003ae | 2009-09-22 00:09:41 +0000 | [diff] [blame] | 102 | if (!bops) |
Ronald G. Minnich | 97de28d | 2012-07-02 09:41:10 -0700 | [diff] [blame^] | 103 | bops = pci_config_default(); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 104 | return bops; |
| 105 | } |
| 106 | |
Patrick Georgi | 87fcffa | 2011-02-03 09:14:40 +0000 | [diff] [blame] | 107 | unsigned mainboard_pci_subsystem_vendor_id(struct device *dev); |
| 108 | unsigned mainboard_pci_subsystem_device_id(struct device *dev); |
| 109 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 110 | #endif /* PCI_H */ |