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 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 18 | #if 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> |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 22 | #include <device/pci_def.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 23 | #include <device/resource.h> |
| 24 | #include <device/device.h> |
Kyösti Mälkki | 4663f45 | 2019-03-07 14:18:28 +0200 | [diff] [blame] | 25 | #include <device/pci_ops.h> |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 26 | #include <device/pci_rom.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 27 | #include <device/pci_type.h> |
Kyösti Mälkki | ef84401 | 2013-06-25 23:17:43 +0300 | [diff] [blame] | 28 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 29 | /* Common pci operations without a standard interface */ |
| 30 | struct pci_operations { |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 31 | /* set the Subsystem IDs for the PCI device */ |
Aaron Durbin | c30d913 | 2017-08-07 16:55:43 -0600 | [diff] [blame] | 32 | void (*set_subsystem)(struct device *dev, unsigned int vendor, |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 33 | unsigned int device); |
Nico Huber | 968ef75 | 2021-03-07 01:39:18 +0100 | [diff] [blame] | 34 | void (*get_ltr_max_latencies)(u16 *max_snoop, u16 *max_nosnoop); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 37 | struct pci_driver { |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 38 | const struct device_operations *ops; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 39 | unsigned short vendor; |
| 40 | unsigned short device; |
Vadim Bendebury | 8049fc9 | 2012-04-24 12:53:19 -0700 | [diff] [blame] | 41 | const unsigned short *devices; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
Patrick Rudolph | 4e2f95b | 2018-05-16 14:56:22 +0200 | [diff] [blame] | 44 | struct msix_entry { |
| 45 | union { |
| 46 | struct { |
| 47 | u32 lower_addr; |
| 48 | u32 upper_addr; |
| 49 | }; |
| 50 | struct { |
| 51 | u64 addr; |
| 52 | }; |
| 53 | }; |
| 54 | u32 data; |
| 55 | u32 vec_control; |
| 56 | }; |
| 57 | |
Kyösti Mälkki | 44da9e2 | 2019-09-27 15:02:32 +0300 | [diff] [blame] | 58 | #if ENV_RAMSTAGE |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 59 | #define __pci_driver __attribute__((used, __section__(".rodata.pci_driver"))) |
Kyösti Mälkki | 44da9e2 | 2019-09-27 15:02:32 +0300 | [diff] [blame] | 60 | #else |
| 61 | #define __pci_driver __attribute__((unused)) |
Aaron Durbin | c30d913 | 2017-08-07 16:55:43 -0600 | [diff] [blame] | 62 | #endif |
Kyösti Mälkki | 44da9e2 | 2019-09-27 15:02:32 +0300 | [diff] [blame] | 63 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 64 | /** start of compile time generated pci driver array */ |
Aaron Durbin | 0375815 | 2015-09-03 17:23:08 -0500 | [diff] [blame] | 65 | extern struct pci_driver _pci_drivers[]; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 66 | /** end of compile time generated pci driver array */ |
Aaron Durbin | 0375815 | 2015-09-03 17:23:08 -0500 | [diff] [blame] | 67 | extern struct pci_driver _epci_drivers[]; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 68 | |
Subrata Banik | ffc790b | 2017-12-11 10:29:49 +0530 | [diff] [blame] | 69 | /* Set Subsystem ID operation for PCI devices */ |
| 70 | extern struct pci_operations pci_dev_ops_pci; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 71 | extern struct device_operations default_pci_ops_dev; |
| 72 | extern struct device_operations default_pci_ops_bus; |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 73 | |
Aaron Durbin | c30d913 | 2017-08-07 16:55:43 -0600 | [diff] [blame] | 74 | void pci_dev_read_resources(struct device *dev); |
| 75 | void pci_bus_read_resources(struct device *dev); |
| 76 | void pci_dev_set_resources(struct device *dev); |
| 77 | void pci_dev_enable_resources(struct device *dev); |
| 78 | void pci_bus_enable_resources(struct device *dev); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 79 | void pci_bus_reset(struct bus *bus); |
Aaron Durbin | c30d913 | 2017-08-07 16:55:43 -0600 | [diff] [blame] | 80 | struct device *pci_probe_dev(struct device *dev, struct bus *bus, |
| 81 | unsigned int devfn); |
Patrick Rudolph | aa6971e | 2018-05-03 12:54:47 +0200 | [diff] [blame] | 82 | void do_pci_scan_bridge(struct device *dev, |
Kyösti Mälkki | de271a8 | 2015-03-18 13:09:47 +0200 | [diff] [blame] | 83 | void (*do_scan_bus)(struct bus *bus, |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 84 | unsigned int min_devfn, unsigned int max_devfn)); |
Kyösti Mälkki | de271a8 | 2015-03-18 13:09:47 +0200 | [diff] [blame] | 85 | |
Aaron Durbin | c30d913 | 2017-08-07 16:55:43 -0600 | [diff] [blame] | 86 | void pci_scan_bridge(struct device *bus); |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 87 | void pci_scan_bus(struct bus *bus, unsigned int min_devfn, |
| 88 | unsigned int max_devfn); |
Kyösti Mälkki | de271a8 | 2015-03-18 13:09:47 +0200 | [diff] [blame] | 89 | |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 90 | uint8_t pci_moving_config8(struct device *dev, unsigned int reg); |
| 91 | uint16_t pci_moving_config16(struct device *dev, unsigned int reg); |
| 92 | uint32_t pci_moving_config32(struct device *dev, unsigned int reg); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 93 | struct resource *pci_get_resource(struct device *dev, unsigned long index); |
Aaron Durbin | c30d913 | 2017-08-07 16:55:43 -0600 | [diff] [blame] | 94 | void pci_dev_set_subsystem(struct device *dev, unsigned int vendor, |
Lee Leahy | 0ca2a06 | 2017-03-06 18:01:04 -0800 | [diff] [blame] | 95 | unsigned int device); |
Myles Watson | 43bb9cd | 2008-12-18 18:24:11 +0000 | [diff] [blame] | 96 | void pci_dev_init(struct device *dev); |
Aaron Durbin | c30d913 | 2017-08-07 16:55:43 -0600 | [diff] [blame] | 97 | 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] | 98 | |
Lee Leahy | 6d71a43 | 2017-03-07 15:24:16 -0800 | [diff] [blame] | 99 | const char *pin_to_str(int pin); |
Aaron Durbin | c30d913 | 2017-08-07 16:55:43 -0600 | [diff] [blame] | 100 | int get_pci_irq_pins(struct device *dev, struct device **parent_bdg); |
Kyösti Mälkki | c19d6a6 | 2019-07-04 21:39:28 +0300 | [diff] [blame] | 101 | void pci_assign_irqs(struct device *dev, const unsigned char pIntAtoD[4]); |
Aaron Durbin | c30d913 | 2017-08-07 16:55:43 -0600 | [diff] [blame] | 102 | const char *get_pci_class_name(struct device *dev); |
| 103 | const char *get_pci_subclass_name(struct device *dev); |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 104 | |
Patrick Rudolph | 4e2f95b | 2018-05-16 14:56:22 +0200 | [diff] [blame] | 105 | size_t pci_msix_table_size(struct device *dev); |
| 106 | int pci_msix_table_bar(struct device *dev, u32 *offset, u8 *idx); |
| 107 | struct msix_entry *pci_msix_get_table(struct device *dev); |
| 108 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 109 | #define PCI_IO_BRIDGE_ALIGN 4096 |
| 110 | #define PCI_MEM_BRIDGE_ALIGN (1024*1024) |
| 111 | |
Kyösti Mälkki | 8a41f4b | 2019-02-08 18:14:34 +0200 | [diff] [blame] | 112 | #define PCI_ID(VENDOR_ID, DEVICE_ID) \ |
| 113 | ((((DEVICE_ID) & 0xFFFF) << 16) | ((VENDOR_ID) & 0xFFFF)) |
| 114 | |
| 115 | pci_devfn_t pci_locate_device(unsigned int pci_id, pci_devfn_t dev); |
| 116 | pci_devfn_t pci_locate_device_on_bus(unsigned int pci_id, unsigned int bus); |
| 117 | |
Kyösti Mälkki | a0b366d | 2019-09-26 22:33:51 +0300 | [diff] [blame] | 118 | void pci_s_assert_secondary_reset(pci_devfn_t p2p_bridge); |
| 119 | void pci_s_deassert_secondary_reset(pci_devfn_t p2p_bridge); |
| 120 | void pci_s_bridge_set_secondary(pci_devfn_t p2p_bridge, u8 secondary); |
| 121 | |
Kyösti Mälkki | 4c686f2 | 2014-02-14 12:45:09 +0200 | [diff] [blame] | 122 | 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] | 123 | |
Alexandru Gagniuc | 420caaf | 2016-01-05 17:00:27 -0800 | [diff] [blame] | 124 | static inline int pci_base_address_is_memory_space(unsigned int attr) |
| 125 | { |
| 126 | return (attr & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY; |
| 127 | } |
Alexandru Gagniuc | 420caaf | 2016-01-05 17:00:27 -0800 | [diff] [blame] | 128 | |
John Zhao | 95b4ece0 | 2020-05-04 15:58:48 -0700 | [diff] [blame] | 129 | void pci_dev_disable_bus_master(const struct device *dev); |
Felix Singer | e4a7d9f | 2020-06-15 15:00:56 +0200 | [diff] [blame] | 130 | |
| 131 | static __always_inline |
| 132 | #if ENV_PCI_SIMPLE_DEVICE |
| 133 | void pci_dev_request_bus_master(pci_devfn_t dev) |
| 134 | #else |
Subrata Banik | 86e5326 | 2020-09-05 14:03:31 +0530 | [diff] [blame] | 135 | void pci_dev_request_bus_master(struct device *dev) |
Felix Singer | e4a7d9f | 2020-06-15 15:00:56 +0200 | [diff] [blame] | 136 | #endif /* ENV_PCI_SIMPLE_DEVICE */ |
| 137 | { |
Felix Singer | 3d9fa08 | 2020-09-07 13:57:49 +0200 | [diff] [blame] | 138 | if (CONFIG(PCI_ALLOW_BUS_MASTER_ANY_DEVICE)) |
Felix Singer | e4a7d9f | 2020-06-15 15:00:56 +0200 | [diff] [blame] | 139 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
| 140 | } |
| 141 | |
Kyösti Mälkki | 318066f | 2014-02-12 14:18:50 +0200 | [diff] [blame] | 142 | #endif /* CONFIG_PCI */ |
| 143 | |
Kyösti Mälkki | 5b14116 | 2019-01-23 16:02:28 +0200 | [diff] [blame] | 144 | void pci_early_bridge_init(void); |
| 145 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 146 | #endif /* PCI_H */ |