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