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 | |
Kyösti Mälkki | 318066f | 2014-02-12 14:18:50 +0200 | [diff] [blame] | 18 | #if CONFIG_PCI |
| 19 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 20 | #include <stdint.h> |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 21 | #include <stddef.h> |
Kyösti Mälkki | e8792be | 2014-02-26 15:19:04 +0200 | [diff] [blame] | 22 | #include <rules.h> |
Kyösti Mälkki | 2161c1d | 2014-02-11 19:56:57 +0200 | [diff] [blame] | 23 | #include <arch/io.h> |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 24 | #include <device/pci_def.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 25 | #include <device/resource.h> |
| 26 | #include <device/device.h> |
| 27 | #include <device/pci_ops.h> |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 28 | #include <device/pci_rom.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 29 | |
Kyösti Mälkki | ef84401 | 2013-06-25 23:17:43 +0300 | [diff] [blame] | 30 | #ifndef __SIMPLE_DEVICE__ |
| 31 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 32 | /* Common pci operations without a standard interface */ |
| 33 | struct pci_operations { |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 34 | /* set the Subsystem IDs for the PCI device */ |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 35 | void (*set_subsystem)(device_t dev, unsigned int vendor, |
| 36 | unsigned int device); |
Kenji Chen | 31c6e63 | 2014-10-04 01:14:44 +0800 | [diff] [blame] | 37 | void (*set_L1_ss_latency)(device_t dev, unsigned int off); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 40 | /* Common pci bus operations */ |
| 41 | struct pci_bus_operations { |
Lee Leahy | bab6bc4 | 2017-03-07 16:10:21 -0800 | [diff] [blame^] | 42 | uint8_t (*read8)(struct bus *pbus, int bus, int devfn, int where); |
| 43 | uint16_t (*read16)(struct bus *pbus, int bus, int devfn, int where); |
| 44 | uint32_t (*read32)(struct bus *pbus, int bus, int devfn, int where); |
| 45 | void (*write8)(struct bus *pbus, int bus, int devfn, int where, uint8_t val); |
| 46 | void (*write16)(struct bus *pbus, int bus, int devfn, int where, uint16_t val); |
| 47 | 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] | 48 | }; |
| 49 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 50 | struct pci_driver { |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 51 | const struct device_operations *ops; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 52 | unsigned short vendor; |
| 53 | unsigned short device; |
Vadim Bendebury | 8049fc9 | 2012-04-24 12:53:19 -0700 | [diff] [blame] | 54 | const unsigned short *devices; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
Lee Leahy | ae3fd34 | 2017-03-07 12:55:23 -0800 | [diff] [blame] | 57 | #define __pci_driver __attribute__ ((used, __section__(".rodata.pci_driver"))) |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 58 | /** start of compile time generated pci driver array */ |
Aaron Durbin | 0375815 | 2015-09-03 17:23:08 -0500 | [diff] [blame] | 59 | extern struct pci_driver _pci_drivers[]; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 60 | /** end of compile time generated pci driver array */ |
Aaron Durbin | 0375815 | 2015-09-03 17:23:08 -0500 | [diff] [blame] | 61 | extern struct pci_driver _epci_drivers[]; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 62 | |
| 63 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 64 | extern struct device_operations default_pci_ops_dev; |
| 65 | extern struct device_operations default_pci_ops_bus; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 66 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 67 | void pci_dev_read_resources(device_t dev); |
| 68 | void pci_bus_read_resources(device_t dev); |
| 69 | void pci_dev_set_resources(device_t dev); |
| 70 | void pci_dev_enable_resources(device_t dev); |
| 71 | void pci_bus_enable_resources(device_t dev); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 72 | void pci_bus_reset(struct bus *bus); |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 73 | device_t pci_probe_dev(device_t dev, struct bus *bus, unsigned int devfn); |
Kyösti Mälkki | de271a8 | 2015-03-18 13:09:47 +0200 | [diff] [blame] | 74 | |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 75 | void do_pci_scan_bridge(device_t bus, |
Kyösti Mälkki | de271a8 | 2015-03-18 13:09:47 +0200 | [diff] [blame] | 76 | void (*do_scan_bus)(struct bus *bus, |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 77 | unsigned int min_devfn, unsigned int max_devfn)); |
Kyösti Mälkki | de271a8 | 2015-03-18 13:09:47 +0200 | [diff] [blame] | 78 | |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 79 | void pci_scan_bridge(device_t bus); |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 80 | void pci_scan_bus(struct bus *bus, unsigned int min_devfn, |
| 81 | unsigned int max_devfn); |
Kyösti Mälkki | de271a8 | 2015-03-18 13:09:47 +0200 | [diff] [blame] | 82 | |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 83 | uint8_t pci_moving_config8(struct device *dev, unsigned int reg); |
| 84 | uint16_t pci_moving_config16(struct device *dev, unsigned int reg); |
| 85 | uint32_t pci_moving_config32(struct device *dev, unsigned int reg); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 86 | struct resource *pci_get_resource(struct device *dev, unsigned long index); |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 87 | void pci_dev_set_subsystem(device_t dev, unsigned int vendor, |
| 88 | unsigned int device); |
Myles Watson | 43bb9cd | 2008-12-18 18:24:11 +0000 | [diff] [blame] | 89 | void pci_dev_init(struct device *dev); |
Kyösti Mälkki | c73acdb | 2013-06-15 17:16:56 +0300 | [diff] [blame] | 90 | unsigned int pci_match_simple_dev(device_t dev, pci_devfn_t sdev); |
Stefan Reinauer | 4d933dd | 2009-07-21 21:36:41 +0000 | [diff] [blame] | 91 | |
Lee Leahy | 6d71a43 | 2017-03-07 15:24:16 -0800 | [diff] [blame] | 92 | const char *pin_to_str(int pin); |
Mike Loptien | 0f5cf5e | 2014-05-12 21:46:31 -0600 | [diff] [blame] | 93 | int get_pci_irq_pins(device_t dev, device_t *parent_bdg); |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 94 | void pci_assign_irqs(unsigned int bus, unsigned int slot, |
Myles Watson | 43bb9cd | 2008-12-18 18:24:11 +0000 | [diff] [blame] | 95 | const unsigned char pIntAtoD[4]); |
Lee Leahy | e1ba3da | 2015-03-31 17:30:01 -0700 | [diff] [blame] | 96 | const char *get_pci_class_name(device_t dev); |
| 97 | const char *get_pci_subclass_name(device_t dev); |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 98 | |
| 99 | #define PCI_IO_BRIDGE_ALIGN 4096 |
| 100 | #define PCI_MEM_BRIDGE_ALIGN (1024*1024) |
| 101 | |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 102 | static inline const struct pci_operations *ops_pci(device_t dev) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 103 | { |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 104 | const struct pci_operations *pops; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 105 | pops = 0; |
Lee Leahy | bfdb893 | 2017-03-07 15:17:04 -0800 | [diff] [blame] | 106 | if (dev && dev->ops) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 107 | pops = dev->ops->ops_pci; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 108 | return pops; |
| 109 | } |
| 110 | |
Kyösti Mälkki | ef84401 | 2013-06-25 23:17:43 +0300 | [diff] [blame] | 111 | #endif /* ! __SIMPLE_DEVICE__ */ |
Kyösti Mälkki | 318066f | 2014-02-12 14:18:50 +0200 | [diff] [blame] | 112 | |
Antonello Dettori | 45b3b82 | 2016-08-30 22:18:06 +0200 | [diff] [blame] | 113 | #ifdef __SIMPLE_DEVICE__ |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 114 | unsigned int pci_find_next_capability(pci_devfn_t dev, unsigned int cap, |
| 115 | unsigned int last); |
| 116 | unsigned int pci_find_capability(pci_devfn_t dev, unsigned int cap); |
Antonello Dettori | 45b3b82 | 2016-08-30 22:18:06 +0200 | [diff] [blame] | 117 | #else /* !__SIMPLE_DEVICE__ */ |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 118 | unsigned int pci_find_next_capability(device_t dev, unsigned int cap, |
| 119 | unsigned int last); |
| 120 | unsigned int pci_find_capability(device_t dev, unsigned int cap); |
Antonello Dettori | 45b3b82 | 2016-08-30 22:18:06 +0200 | [diff] [blame] | 121 | #endif /* __SIMPLE_DEVICE__ */ |
Edward O'Callaghan | c2956e7 | 2014-07-09 04:55:16 +1000 | [diff] [blame] | 122 | |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 123 | void pci_early_bridge_init(void); |
| 124 | int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base); |
Kyösti Mälkki | 2161c1d | 2014-02-11 19:56:57 +0200 | [diff] [blame] | 125 | |
Alexandru Gagniuc | 420caaf | 2016-01-05 17:00:27 -0800 | [diff] [blame] | 126 | #ifndef __ROMCC__ |
| 127 | static inline int pci_base_address_is_memory_space(unsigned int attr) |
| 128 | { |
| 129 | return (attr & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY; |
| 130 | } |
| 131 | #endif |
| 132 | |
Kyösti Mälkki | 318066f | 2014-02-12 14:18:50 +0200 | [diff] [blame] | 133 | #endif /* CONFIG_PCI */ |
| 134 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 135 | #endif /* PCI_H */ |