blob: 60339e3ade8108e18273c5773089f7f513922670 [file] [log] [blame]
Angel Ponsc74dae92020-04-02 23:48:16 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Uwe Hermannb80dbf02007-04-22 19:08:13 +00002
3/*
Martin Roth99f83bb2019-09-15 20:57:18 -07004 * Originally based on the Linux kernel (drivers/pci/pci.c).
Myles Watson29cc9ed2009-07-02 18:56:24 +00005 * PCI Bus Services, see include/linux/pci.h for further explanation.
Eric Biederman8ca8d762003-04-22 19:02:15 +00006 */
7
Furquan Shaikh76cedd22020-05-02 10:24:23 -07008#include <acpi/acpi.h>
Bill XIE513d3592022-08-02 22:55:51 +08009#include <assert.h>
Nico Huberae814972023-05-10 18:06:27 +020010#include <cbmem.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020011#include <device/pci_ops.h>
Edward O'Callaghan6c992502014-06-20 21:19:06 +100012#include <bootmode.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000013#include <console/console.h>
Furquan Shaikh871baf22020-03-12 17:51:24 -070014#include <cpu/cpu.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000015#include <stdlib.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000016#include <string.h>
Edward O'Callaghan6c992502014-06-20 21:19:06 +100017#include <delay.h>
Edward O'Callaghan6c992502014-06-20 21:19:06 +100018#include <device/cardbus.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000019#include <device/device.h>
20#include <device/pci.h>
21#include <device/pci_ids.h>
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000022#include <device/pcix.h>
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000023#include <device/pciexp.h>
Tim Wawrzynczak8c93fed2022-01-13 16:45:07 -070024#include <lib.h>
Stefan Reinauer4d933dd2009-07-21 21:36:41 +000025#include <pc80/i8259.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020026#include <security/vboot/vbnv.h>
Martin Roth5dd4a2a2018-03-06 16:10:45 -070027#include <timestamp.h>
Johanna Schanderdb7a3ae2019-07-24 10:14:26 +020028#include <types.h>
29
Myles Watson29cc9ed2009-07-02 18:56:24 +000030u8 pci_moving_config8(struct device *dev, unsigned int reg)
Eric Biederman03acab62004-10-14 21:25:53 +000031{
Myles Watson29cc9ed2009-07-02 18:56:24 +000032 u8 value, ones, zeroes;
Uwe Hermanne4870472010-11-04 23:23:47 +000033
Eric Biederman03acab62004-10-14 21:25:53 +000034 value = pci_read_config8(dev, reg);
Myles Watson032a9652009-05-11 22:24:53 +000035
Eric Biederman03acab62004-10-14 21:25:53 +000036 pci_write_config8(dev, reg, 0xff);
37 ones = pci_read_config8(dev, reg);
38
39 pci_write_config8(dev, reg, 0x00);
40 zeroes = pci_read_config8(dev, reg);
41
42 pci_write_config8(dev, reg, value);
43
44 return ones ^ zeroes;
45}
Li-Ta Lo9a5b4962004-12-23 21:48:01 +000046
Uwe Hermanne4870472010-11-04 23:23:47 +000047u16 pci_moving_config16(struct device *dev, unsigned int reg)
Eric Biederman03acab62004-10-14 21:25:53 +000048{
Myles Watson29cc9ed2009-07-02 18:56:24 +000049 u16 value, ones, zeroes;
Uwe Hermanne4870472010-11-04 23:23:47 +000050
Eric Biederman03acab62004-10-14 21:25:53 +000051 value = pci_read_config16(dev, reg);
Myles Watson032a9652009-05-11 22:24:53 +000052
Eric Biederman03acab62004-10-14 21:25:53 +000053 pci_write_config16(dev, reg, 0xffff);
54 ones = pci_read_config16(dev, reg);
55
56 pci_write_config16(dev, reg, 0x0000);
57 zeroes = pci_read_config16(dev, reg);
58
59 pci_write_config16(dev, reg, value);
60
61 return ones ^ zeroes;
62}
Li-Ta Loe8b1c9d2004-12-27 04:25:41 +000063
Uwe Hermanne4870472010-11-04 23:23:47 +000064u32 pci_moving_config32(struct device *dev, unsigned int reg)
Eric Biederman03acab62004-10-14 21:25:53 +000065{
Myles Watson29cc9ed2009-07-02 18:56:24 +000066 u32 value, ones, zeroes;
Uwe Hermanne4870472010-11-04 23:23:47 +000067
Eric Biederman03acab62004-10-14 21:25:53 +000068 value = pci_read_config32(dev, reg);
Myles Watson032a9652009-05-11 22:24:53 +000069
Eric Biederman03acab62004-10-14 21:25:53 +000070 pci_write_config32(dev, reg, 0xffffffff);
71 ones = pci_read_config32(dev, reg);
72
73 pci_write_config32(dev, reg, 0x00000000);
74 zeroes = pci_read_config32(dev, reg);
75
76 pci_write_config32(dev, reg, value);
77
78 return ones ^ zeroes;
79}
80
Myles Watson29cc9ed2009-07-02 18:56:24 +000081/**
Myles Watson29cc9ed2009-07-02 18:56:24 +000082 * Given a device and register, read the size of the BAR for that register.
83 *
84 * @param dev Pointer to the device structure.
85 * @param index Address of the PCI configuration register.
Uwe Hermannc1ee4292010-10-17 19:01:48 +000086 * @return TODO
Eric Biederman8ca8d762003-04-22 19:02:15 +000087 */
Eric Biederman03acab62004-10-14 21:25:53 +000088struct resource *pci_get_resource(struct device *dev, unsigned long index)
Eric Biederman8ca8d762003-04-22 19:02:15 +000089{
Eric Biederman5cd81732004-03-11 15:01:31 +000090 struct resource *resource;
Eric Biederman03acab62004-10-14 21:25:53 +000091 unsigned long value, attr;
Myles Watson29cc9ed2009-07-02 18:56:24 +000092 resource_t moving, limit;
Eric Biederman8ca8d762003-04-22 19:02:15 +000093
Myles Watson29cc9ed2009-07-02 18:56:24 +000094 /* Initialize the resources to nothing. */
Eric Biederman03acab62004-10-14 21:25:53 +000095 resource = new_resource(dev, index);
Eric Biederman8ca8d762003-04-22 19:02:15 +000096
Myles Watson29cc9ed2009-07-02 18:56:24 +000097 /* Get the initial value. */
Eric Biederman03acab62004-10-14 21:25:53 +000098 value = pci_read_config32(dev, index);
Eric Biederman8ca8d762003-04-22 19:02:15 +000099
Myles Watson29cc9ed2009-07-02 18:56:24 +0000100 /* See which bits move. */
Eric Biederman03acab62004-10-14 21:25:53 +0000101 moving = pci_moving_config32(dev, index);
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000102
Myles Watson29cc9ed2009-07-02 18:56:24 +0000103 /* Initialize attr to the bits that do not move. */
Eric Biederman03acab62004-10-14 21:25:53 +0000104 attr = value & ~moving;
105
Myles Watson29cc9ed2009-07-02 18:56:24 +0000106 /* If it is a 64bit resource look at the high half as well. */
Eric Biederman03acab62004-10-14 21:25:53 +0000107 if (((attr & PCI_BASE_ADDRESS_SPACE_IO) == 0) &&
Myles Watson29cc9ed2009-07-02 18:56:24 +0000108 ((attr & PCI_BASE_ADDRESS_MEM_LIMIT_MASK) ==
109 PCI_BASE_ADDRESS_MEM_LIMIT_64)) {
110 /* Find the high bits that move. */
111 moving |=
Elyes Haouasd369c662022-11-18 15:06:21 +0100112 ((resource_t)pci_moving_config32(dev, index + 4)) << 32;
Eric Biederman03acab62004-10-14 21:25:53 +0000113 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000114
Myles Watson032a9652009-05-11 22:24:53 +0000115 /* Find the resource constraints.
Eric Biederman03acab62004-10-14 21:25:53 +0000116 * Start by finding the bits that move. From there:
117 * - Size is the least significant bit of the bits that move.
118 * - Limit is all of the bits that move plus all of the lower bits.
Myles Watson29cc9ed2009-07-02 18:56:24 +0000119 * See PCI Spec 6.2.5.1.
Eric Biederman8ca8d762003-04-22 19:02:15 +0000120 */
Eric Biederman03acab62004-10-14 21:25:53 +0000121 limit = 0;
122 if (moving) {
123 resource->size = 1;
124 resource->align = resource->gran = 0;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000125 while (!(moving & resource->size)) {
Eric Biederman03acab62004-10-14 21:25:53 +0000126 resource->size <<= 1;
127 resource->align += 1;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000128 resource->gran += 1;
Eric Biederman03acab62004-10-14 21:25:53 +0000129 }
130 resource->limit = limit = moving | (resource->size - 1);
Nico Huber8193b062015-10-21 15:43:41 +0200131
132 if (pci_base_address_is_memory_space(attr)) {
133 /* Page-align to allow individual mapping of devices. */
134 if (resource->align < 12)
135 resource->align = 12;
136 }
Eric Biederman03acab62004-10-14 21:25:53 +0000137 }
Myles Watson29cc9ed2009-07-02 18:56:24 +0000138
Uwe Hermanne4870472010-11-04 23:23:47 +0000139 /*
140 * Some broken hardware has read-only registers that do not
Eric Biederman03acab62004-10-14 21:25:53 +0000141 * really size correctly.
Uwe Hermanne4870472010-11-04 23:23:47 +0000142 *
143 * Example: the Acer M7229 has BARs 1-4 normally read-only,
Eric Biederman8ca8d762003-04-22 19:02:15 +0000144 * so BAR1 at offset 0x10 reads 0x1f1. If you size that register
Uwe Hermanne4870472010-11-04 23:23:47 +0000145 * by writing 0xffffffff to it, it will read back as 0x1f1 -- which
146 * is a violation of the spec.
147 *
148 * We catch this case and ignore it by observing which bits move.
149 *
150 * This also catches the common case of unimplemented registers
Eric Biederman03acab62004-10-14 21:25:53 +0000151 * that always read back as 0.
Eric Biederman8ca8d762003-04-22 19:02:15 +0000152 */
Eric Biederman03acab62004-10-14 21:25:53 +0000153 if (moving == 0) {
154 if (value != 0) {
Angel Ponsd19cc112021-07-04 11:41:31 +0200155 printk(BIOS_DEBUG, "%s register %02lx(%08lx), read-only ignoring it\n",
Uwe Hermanne4870472010-11-04 23:23:47 +0000156 dev_path(dev), index, value);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000157 }
158 resource->flags = 0;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000159 } else if (attr & PCI_BASE_ADDRESS_SPACE_IO) {
160 /* An I/O mapped base address. */
Eric Biederman5cd81732004-03-11 15:01:31 +0000161 resource->flags |= IORESOURCE_IO;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000162 /* I don't want to deal with 32bit I/O resources. */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000163 resource->limit = 0xffff;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000164 } else {
165 /* A Memory mapped base address. */
Eric Biederman03acab62004-10-14 21:25:53 +0000166 attr &= PCI_BASE_ADDRESS_MEM_ATTR_MASK;
Eric Biederman5cd81732004-03-11 15:01:31 +0000167 resource->flags |= IORESOURCE_MEM;
Nico Huber577c6b92022-08-15 00:08:58 +0200168 if (attr & PCI_BASE_ADDRESS_MEM_PREFETCH) {
Eric Biederman8ca8d762003-04-22 19:02:15 +0000169 resource->flags |= IORESOURCE_PREFETCH;
Nico Huber577c6b92022-08-15 00:08:58 +0200170 if (CONFIG(PCIEXP_HOTPLUG_PREFETCH_MEM_ABOVE_4G)
171 && dev_path_hotplug(dev))
172 resource->flags |= IORESOURCE_ABOVE_4G;
173 }
Eric Biederman03acab62004-10-14 21:25:53 +0000174 attr &= PCI_BASE_ADDRESS_MEM_LIMIT_MASK;
175 if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_32) {
Myles Watson29cc9ed2009-07-02 18:56:24 +0000176 /* 32bit limit. */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000177 resource->limit = 0xffffffffUL;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000178 } else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_1M) {
179 /* 1MB limit. */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000180 resource->limit = 0x000fffffUL;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000181 } else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_64) {
182 /* 64bit limit. */
Eric Biederman03acab62004-10-14 21:25:53 +0000183 resource->limit = 0xffffffffffffffffULL;
Eric Biederman8ca8d762003-04-22 19:02:15 +0000184 resource->flags |= IORESOURCE_PCI64;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000185 } else {
186 /* Invalid value. */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000187 printk(BIOS_ERR, "Broken BAR with value %lx\n", attr);
188 printk(BIOS_ERR, " on dev %s at index %02lx\n",
Myles Watson29cc9ed2009-07-02 18:56:24 +0000189 dev_path(dev), index);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000190 resource->flags = 0;
191 }
192 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000193
Myles Watson29cc9ed2009-07-02 18:56:24 +0000194 /* Don't let the limit exceed which bits can move. */
Uwe Hermanne4870472010-11-04 23:23:47 +0000195 if (resource->limit > limit)
Eric Biederman03acab62004-10-14 21:25:53 +0000196 resource->limit = limit;
Eric Biederman03acab62004-10-14 21:25:53 +0000197
Eric Biederman5cd81732004-03-11 15:01:31 +0000198 return resource;
Eric Biederman8ca8d762003-04-22 19:02:15 +0000199}
200
Myles Watson29cc9ed2009-07-02 18:56:24 +0000201/**
202 * Given a device and an index, read the size of the BAR for that register.
203 *
204 * @param dev Pointer to the device structure.
205 * @param index Address of the PCI configuration register.
206 */
Li-Ta Loe8b1c9d2004-12-27 04:25:41 +0000207static void pci_get_rom_resource(struct device *dev, unsigned long index)
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000208{
209 struct resource *resource;
Li-Ta Loe8b1c9d2004-12-27 04:25:41 +0000210 unsigned long value;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000211 resource_t moving;
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000212
Myles Watson29cc9ed2009-07-02 18:56:24 +0000213 /* Initialize the resources to nothing. */
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000214 resource = new_resource(dev, index);
215
Myles Watson29cc9ed2009-07-02 18:56:24 +0000216 /* Get the initial value. */
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000217 value = pci_read_config32(dev, index);
218
Myles Watson29cc9ed2009-07-02 18:56:24 +0000219 /* See which bits move. */
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000220 moving = pci_moving_config32(dev, index);
Myles Watson29cc9ed2009-07-02 18:56:24 +0000221
222 /* Clear the Enable bit. */
Li-Ta Loe8b1c9d2004-12-27 04:25:41 +0000223 moving = moving & ~PCI_ROM_ADDRESS_ENABLE;
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000224
Myles Watson032a9652009-05-11 22:24:53 +0000225 /* Find the resource constraints.
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000226 * Start by finding the bits that move. From there:
227 * - Size is the least significant bit of the bits that move.
228 * - Limit is all of the bits that move plus all of the lower bits.
Myles Watson29cc9ed2009-07-02 18:56:24 +0000229 * See PCI Spec 6.2.5.1.
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000230 */
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000231 if (moving) {
232 resource->size = 1;
233 resource->align = resource->gran = 0;
Li-Ta Loe8b1c9d2004-12-27 04:25:41 +0000234 while (!(moving & resource->size)) {
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000235 resource->size <<= 1;
236 resource->align += 1;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000237 resource->gran += 1;
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000238 }
Patrick Georgi16cdbb22009-04-21 20:14:31 +0000239 resource->limit = moving | (resource->size - 1);
Myles Watson29cc9ed2009-07-02 18:56:24 +0000240 resource->flags |= IORESOURCE_MEM | IORESOURCE_READONLY;
241 } else {
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000242 if (value != 0) {
Angel Ponsd19cc112021-07-04 11:41:31 +0200243 printk(BIOS_DEBUG, "%s register %02lx(%08lx), read-only ignoring it\n",
Uwe Hermanne4870472010-11-04 23:23:47 +0000244 dev_path(dev), index, value);
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000245 }
246 resource->flags = 0;
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000247 }
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000248 compact_resources(dev);
Li-Ta Loe8b1c9d2004-12-27 04:25:41 +0000249}
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000250
Myles Watson29cc9ed2009-07-02 18:56:24 +0000251/**
Patrick Rudolph4e2f95b2018-05-16 14:56:22 +0200252 * Given a device, read the size of the MSI-X table.
253 *
254 * @param dev Pointer to the device structure.
255 * @return MSI-X table size or 0 if not MSI-X capable device
256 */
257size_t pci_msix_table_size(struct device *dev)
258{
259 const size_t pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
260 if (!pos)
261 return 0;
262
263 const u16 control = pci_read_config16(dev, pos + PCI_MSIX_FLAGS);
264 return (control & PCI_MSIX_FLAGS_QSIZE) + 1;
265}
266
267/**
268 * Given a device, return the table offset and bar the MSI-X tables resides in.
269 *
270 * @param dev Pointer to the device structure.
271 * @param offset Returned value gives the offset in bytes inside the PCI BAR.
272 * @param idx The returned value is the index of the PCI_BASE_ADDRESS register
273 * the MSI-X table is located in.
274 * @return Zero on success
275 */
276int pci_msix_table_bar(struct device *dev, u32 *offset, u8 *idx)
277{
278 const size_t pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
279 if (!pos || !offset || !idx)
280 return 1;
281
282 *offset = pci_read_config32(dev, pos + PCI_MSIX_TABLE);
283 *idx = (u8)(*offset & PCI_MSIX_PBA_BIR);
284 *offset &= PCI_MSIX_PBA_OFFSET;
285
286 return 0;
287}
288
289/**
290 * Given a device, return a msix_entry pointer or NULL if no table was found.
291 *
292 * @param dev Pointer to the device structure.
293 *
294 * @return NULL on error
295 */
296struct msix_entry *pci_msix_get_table(struct device *dev)
297{
298 struct resource *res;
299 u32 offset;
300 u8 idx;
301
302 if (pci_msix_table_bar(dev, &offset, &idx))
303 return NULL;
304
305 if (idx > 5)
306 return NULL;
307
308 res = probe_resource(dev, idx * 4 + PCI_BASE_ADDRESS_0);
309 if (!res || !res->base || offset >= res->size)
310 return NULL;
311
312 if ((res->flags & IORESOURCE_PCI64) &&
313 (uintptr_t)res->base != res->base)
314 return NULL;
315
316 return (struct msix_entry *)((uintptr_t)res->base + offset);
317}
318
Tim Wawrzynczak8c93fed2022-01-13 16:45:07 -0700319static unsigned int get_rebar_offset(const struct device *dev, unsigned long index)
320{
Nico Huber5ffc2c82022-08-05 12:58:18 +0200321 uint32_t offset = pciexp_find_extended_cap(dev, PCIE_EXT_CAP_RESIZABLE_BAR, 0);
Tim Wawrzynczak8c93fed2022-01-13 16:45:07 -0700322 if (!offset)
323 return 0;
324
325 /* Convert PCI_BASE_ADDRESS_0, ..._1, ..._2 into 0, 1, 2... */
326 const unsigned int find_bar_idx = (index - PCI_BASE_ADDRESS_0) /
327 sizeof(uint32_t);
328
329 /* Although all of the Resizable BAR Control Registers contain an
330 "NBARs" field, it is only valid in the Control Register for BAR 0 */
331 const uint32_t rebar_ctrl0 = pci_read_config32(dev, offset + PCI_REBAR_CTRL_OFFSET);
332 const unsigned int nbars = (rebar_ctrl0 & PCI_REBAR_CTRL_NBARS_MASK) >>
333 PCI_REBAR_CTRL_NBARS_SHIFT;
334
335 for (unsigned int i = 0; i < nbars; i++, offset += sizeof(uint64_t)) {
336 const uint32_t rebar_ctrl = pci_read_config32(
337 dev, offset + PCI_REBAR_CTRL_OFFSET);
338 const uint32_t bar_idx = rebar_ctrl & PCI_REBAR_CTRL_IDX_MASK;
339 if (bar_idx == find_bar_idx)
340 return offset;
341 }
342
343 return 0;
344}
345
346/* Bit 20 = 1 MiB, bit 21 = 2 MiB, bit 22 = 4 MiB, ... bit 63 = 8 EiB */
347static uint64_t get_rebar_sizes_mask(const struct device *dev,
348 unsigned long index)
349{
350 uint64_t size_mask = 0ULL;
351 const uint32_t offset = get_rebar_offset(dev, index);
352 if (!offset)
353 return 0;
354
355 /* Get 1 MB - 128 TB support from CAP register */
356 const uint32_t cap = pci_read_config32(dev, offset + PCI_REBAR_CAP_OFFSET);
357 /* Shift the bits from 4-31 to 0-27 (i.e., down by 4 bits) */
358 size_mask |= ((cap & PCI_REBAR_CAP_SIZE_MASK) >> 4);
359
360 /* Get 256 TB - 8 EB support from CTRL register and store it in bits 28-43 */
361 const uint64_t ctrl = pci_read_config32(dev, offset + PCI_REBAR_CTRL_OFFSET);
362 /* Shift ctrl mask from bit 16 to bit 28, so that the two
363 masks (fom cap and ctrl) form a contiguous bitmask when
364 concatenated (i.e., up by 12 bits). */
365 size_mask |= ((ctrl & PCI_REBAR_CTRL_SIZE_MASK) << 12);
366
367 /* Now that the mask occupies bits 0-43, shift it up to 20-63, so they
368 represent the actual powers of 2. */
369 return size_mask << 20;
370}
371
372static void pci_store_rebar_size(const struct device *dev,
373 const struct resource *resource)
374{
375 const unsigned int num_bits = __fls64(resource->size);
376 const uint32_t offset = get_rebar_offset(dev, resource->index);
377 if (!offset)
378 return;
379
380 pci_update_config32(dev, offset + PCI_REBAR_CTRL_OFFSET,
381 ~PCI_REBAR_CTRL_SIZE_MASK,
382 num_bits << PCI_REBAR_CTRL_SIZE_SHIFT);
383}
384
385static void configure_adjustable_base(const struct device *dev,
386 unsigned long index,
387 struct resource *res)
388{
389 /*
390 * Excerpt from an implementation note from the PCIe spec:
391 *
392 * System software uses this capability in place of the above mentioned
393 * method of determining the resource size[0], and prior to assigning
394 * the base address to the BAR. Potential usable resource sizes are
395 * reported by the Function via its Resizable BAR Capability and Control
396 * registers. It is intended that the software allocate the largest of
397 * the reported sizes that it can, since allocating less address space
398 * than the largest reported size can result in lower
399 * performance. Software then writes the size to the Resizable BAR
400 * Control register for the appropriate BAR for the Function. Following
401 * this, the base address is written to the BAR.
402 *
403 * [0] Referring to using the moving bits in the BAR to determine the
404 * requested size of the MMIO region
405 */
406 const uint64_t size_mask = get_rebar_sizes_mask(dev, index);
407 if (!size_mask)
408 return;
409
410 int max_requested_bits = __fls64(size_mask);
411 if (max_requested_bits > CONFIG_PCIEXP_DEFAULT_MAX_RESIZABLE_BAR_BITS) {
Elyes Haouasaba1c942022-11-09 15:05:23 +0100412 printk(BIOS_WARNING, "Device %s requests a BAR with"
Paul Menzeld579d802022-09-06 08:25:28 +0200413 " %u bits of address space, which coreboot is not"
414 " configured to hand out, truncating to %u bits\n",
Tim Wawrzynczak8c93fed2022-01-13 16:45:07 -0700415 dev_path(dev), max_requested_bits,
416 CONFIG_PCIEXP_DEFAULT_MAX_RESIZABLE_BAR_BITS);
417 max_requested_bits = CONFIG_PCIEXP_DEFAULT_MAX_RESIZABLE_BAR_BITS;
418 }
419
420 if (!(res->flags & IORESOURCE_PCI64) && max_requested_bits > 32) {
Elyes Haouasaba1c942022-11-09 15:05:23 +0100421 printk(BIOS_ERR, "Resizable BAR requested"
Paul Menzeld579d802022-09-06 08:25:28 +0200422 " above 32 bits, but PCI function reported a"
423 " 32-bit BAR.");
Tim Wawrzynczak8c93fed2022-01-13 16:45:07 -0700424 return;
425 }
426
427 /* Configure the resource parameters for the adjustable BAR */
428 res->size = 1ULL << max_requested_bits;
429 res->align = max_requested_bits;
430 res->gran = max_requested_bits;
431 res->limit = (res->flags & IORESOURCE_PCI64) ? UINT64_MAX : UINT32_MAX;
Tim Wawrzynczak2b83fa72022-05-27 12:27:50 -0600432 res->flags |= (res->flags & IORESOURCE_PCI64) ?
433 IORESOURCE_PCIE_RESIZABLE_BAR | IORESOURCE_ABOVE_4G :
434 IORESOURCE_PCIE_RESIZABLE_BAR;
Tim Wawrzynczak8c93fed2022-01-13 16:45:07 -0700435
436 printk(BIOS_INFO, "%s: Adjusting resource index %lu: base: %llx size: %llx "
437 "align: %d gran: %d limit: %llx\n",
438 dev_path(dev), res->index, res->base, res->size,
439 res->align, res->gran, res->limit);
440}
441
Patrick Rudolph4e2f95b2018-05-16 14:56:22 +0200442/**
Myles Watson29cc9ed2009-07-02 18:56:24 +0000443 * Read the base address registers for a given device.
444 *
445 * @param dev Pointer to the dev structure.
446 * @param howmany How many registers to read (6 for device, 2 for bridge).
Li-Ta Loe8b1c9d2004-12-27 04:25:41 +0000447 */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000448static void pci_read_bases(struct device *dev, unsigned int howmany)
Li-Ta Loe8b1c9d2004-12-27 04:25:41 +0000449{
450 unsigned long index;
451
Myles Watson29cc9ed2009-07-02 18:56:24 +0000452 for (index = PCI_BASE_ADDRESS_0;
453 (index < PCI_BASE_ADDRESS_0 + (howmany << 2));) {
Li-Ta Loe8b1c9d2004-12-27 04:25:41 +0000454 struct resource *resource;
455 resource = pci_get_resource(dev, index);
Tim Wawrzynczak8c93fed2022-01-13 16:45:07 -0700456
457 const bool is_pcie = pci_find_capability(dev, PCI_CAP_ID_PCIE) != 0;
458 if (CONFIG(PCIEXP_SUPPORT_RESIZABLE_BARS) && is_pcie)
459 configure_adjustable_base(dev, index, resource);
460
Myles Watson29cc9ed2009-07-02 18:56:24 +0000461 index += (resource->flags & IORESOURCE_PCI64) ? 8 : 4;
Li-Ta Loe8b1c9d2004-12-27 04:25:41 +0000462 }
Li-Ta Loe8b1c9d2004-12-27 04:25:41 +0000463
464 compact_resources(dev);
Li-Ta Lo9a5b4962004-12-23 21:48:01 +0000465}
466
Myles Watson29cc9ed2009-07-02 18:56:24 +0000467static void pci_record_bridge_resource(struct device *dev, resource_t moving,
Martin Roth38ddbfb2019-10-23 21:41:00 -0600468 unsigned int index, unsigned long type)
Eric Biederman03acab62004-10-14 21:25:53 +0000469{
Eric Biederman03acab62004-10-14 21:25:53 +0000470 struct resource *resource;
Uwe Hermanne4870472010-11-04 23:23:47 +0000471 unsigned long gran;
472 resource_t step;
473
Myles Watson29cc9ed2009-07-02 18:56:24 +0000474 resource = NULL;
Uwe Hermanne4870472010-11-04 23:23:47 +0000475
476 if (!moving)
477 return;
478
479 /* Initialize the constraints on the current bus. */
480 resource = new_resource(dev, index);
481 resource->size = 0;
482 gran = 0;
483 step = 1;
484 while ((moving & step) == 0) {
485 gran += 1;
486 step <<= 1;
Eric Biederman03acab62004-10-14 21:25:53 +0000487 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000488 resource->gran = gran;
489 resource->align = gran;
490 resource->limit = moving | (step - 1);
491 resource->flags = type | IORESOURCE_PCI_BRIDGE |
492 IORESOURCE_BRIDGE;
Eric Biederman03acab62004-10-14 21:25:53 +0000493}
494
Eric Biederman8ca8d762003-04-22 19:02:15 +0000495static void pci_bridge_read_bases(struct device *dev)
496{
Eric Biederman03acab62004-10-14 21:25:53 +0000497 resource_t moving_base, moving_limit, moving;
Eric Biederman8ca8d762003-04-22 19:02:15 +0000498
Myles Watson29cc9ed2009-07-02 18:56:24 +0000499 /* See if the bridge I/O resources are implemented. */
Elyes Haouasd369c662022-11-18 15:06:21 +0100500 moving_base = ((u32)pci_moving_config8(dev, PCI_IO_BASE)) << 8;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000501 moving_base |=
Elyes Haouasd369c662022-11-18 15:06:21 +0100502 ((u32)pci_moving_config16(dev, PCI_IO_BASE_UPPER16)) << 16;
Eric Biederman03acab62004-10-14 21:25:53 +0000503
Elyes Haouasd369c662022-11-18 15:06:21 +0100504 moving_limit = ((u32)pci_moving_config8(dev, PCI_IO_LIMIT)) << 8;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000505 moving_limit |=
Elyes Haouasd369c662022-11-18 15:06:21 +0100506 ((u32)pci_moving_config16(dev, PCI_IO_LIMIT_UPPER16)) << 16;
Eric Biederman03acab62004-10-14 21:25:53 +0000507
508 moving = moving_base & moving_limit;
Eric Biederman8ca8d762003-04-22 19:02:15 +0000509
Myles Watson29cc9ed2009-07-02 18:56:24 +0000510 /* Initialize the I/O space constraints on the current bus. */
511 pci_record_bridge_resource(dev, moving, PCI_IO_BASE, IORESOURCE_IO);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000512
Myles Watson29cc9ed2009-07-02 18:56:24 +0000513 /* See if the bridge prefmem resources are implemented. */
514 moving_base =
Elyes Haouasd369c662022-11-18 15:06:21 +0100515 ((resource_t)pci_moving_config16(dev, PCI_PREF_MEMORY_BASE)) << 16;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000516 moving_base |=
Elyes Haouasd369c662022-11-18 15:06:21 +0100517 ((resource_t)pci_moving_config32(dev, PCI_PREF_BASE_UPPER32)) << 32;
Eric Biederman03acab62004-10-14 21:25:53 +0000518
Myles Watson29cc9ed2009-07-02 18:56:24 +0000519 moving_limit =
Elyes Haouasd369c662022-11-18 15:06:21 +0100520 ((resource_t)pci_moving_config16(dev, PCI_PREF_MEMORY_LIMIT)) << 16;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000521 moving_limit |=
Elyes Haouasd369c662022-11-18 15:06:21 +0100522 ((resource_t)pci_moving_config32(dev, PCI_PREF_LIMIT_UPPER32)) << 32;
Myles Watson032a9652009-05-11 22:24:53 +0000523
Eric Biederman03acab62004-10-14 21:25:53 +0000524 moving = moving_base & moving_limit;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000525 /* Initialize the prefetchable memory constraints on the current bus. */
526 pci_record_bridge_resource(dev, moving, PCI_PREF_MEMORY_BASE,
527 IORESOURCE_MEM | IORESOURCE_PREFETCH);
Myles Watson032a9652009-05-11 22:24:53 +0000528
Myles Watson29cc9ed2009-07-02 18:56:24 +0000529 /* See if the bridge mem resources are implemented. */
Elyes Haouasd369c662022-11-18 15:06:21 +0100530 moving_base = ((u32)pci_moving_config16(dev, PCI_MEMORY_BASE)) << 16;
531 moving_limit = ((u32)pci_moving_config16(dev, PCI_MEMORY_LIMIT)) << 16;
Eric Biederman03acab62004-10-14 21:25:53 +0000532
533 moving = moving_base & moving_limit;
Eric Biederman8ca8d762003-04-22 19:02:15 +0000534
Myles Watson29cc9ed2009-07-02 18:56:24 +0000535 /* Initialize the memory resources on the current bus. */
536 pci_record_bridge_resource(dev, moving, PCI_MEMORY_BASE,
537 IORESOURCE_MEM);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000538
Eric Biederman5cd81732004-03-11 15:01:31 +0000539 compact_resources(dev);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000540}
541
Eric Biederman5899fd82003-04-24 06:25:08 +0000542void pci_dev_read_resources(struct device *dev)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000543{
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000544 pci_read_bases(dev, 6);
545 pci_get_rom_resource(dev, PCI_ROM_ADDRESS);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000546}
547
Eric Biederman5899fd82003-04-24 06:25:08 +0000548void pci_bus_read_resources(struct device *dev)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000549{
Eric Biederman8ca8d762003-04-22 19:02:15 +0000550 pci_bridge_read_bases(dev);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000551 pci_read_bases(dev, 2);
552 pci_get_rom_resource(dev, PCI_ROM_ADDRESS1);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000553}
554
Myles Watson29cc9ed2009-07-02 18:56:24 +0000555void pci_domain_read_resources(struct device *dev)
556{
557 struct resource *res;
558
559 /* Initialize the system-wide I/O space constraints. */
560 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
561 res->limit = 0xffffUL;
562 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
563 IORESOURCE_ASSIGNED;
564
Nico Huberae814972023-05-10 18:06:27 +0200565 /*
566 * Initialize 32-bit memory resource constraints.
567 *
568 * There are often undeclared chipset resources in lower memory
569 * and memory right below the 4G barrier. Hence, only allow
570 * one big range from cbmem_top to the configured limit.
571 */
Myles Watson29cc9ed2009-07-02 18:56:24 +0000572 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
Nico Huberae814972023-05-10 18:06:27 +0200573 res->base = (uintptr_t)cbmem_top();
574 res->limit = CONFIG_DOMAIN_RESOURCE_32BIT_LIMIT - 1;
575 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
576 IORESOURCE_ASSIGNED;
577
578 /* Initialize 64-bit memory resource constraints above 4G. */
579 res = new_resource(dev, IOINDEX_SUBTRACTIVE(2, 0));
580 res->base = 4ULL * GiB;
Furquan Shaikh871baf22020-03-12 17:51:24 -0700581 res->limit = (1ULL << cpu_phys_address_size()) - 1;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000582 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
583 IORESOURCE_ASSIGNED;
584}
585
Raul E Rangel5cb34e22020-05-04 16:41:22 -0600586void pci_domain_set_resources(struct device *dev)
587{
588 assign_resources(dev->link_list);
589}
590
Nico Huber730b2612020-05-20 00:32:50 +0200591static void pci_store_resource(const struct device *const dev,
592 const struct resource *const resource)
593{
594 unsigned long base_lo, base_hi;
595
596 base_lo = resource->base & 0xffffffff;
597 base_hi = (resource->base >> 32) & 0xffffffff;
598
599 /*
600 * Some chipsets allow us to set/clear the I/O bit
601 * (e.g. VIA 82C686A). So set it to be safe.
602 */
603 if (resource->flags & IORESOURCE_IO)
604 base_lo |= PCI_BASE_ADDRESS_SPACE_IO;
605
606 pci_write_config32(dev, resource->index, base_lo);
607 if (resource->flags & IORESOURCE_PCI64)
608 pci_write_config32(dev, resource->index + 4, base_hi);
609}
610
611static void pci_store_bridge_resource(const struct device *const dev,
612 struct resource *const resource)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000613{
Eric Biederman03acab62004-10-14 21:25:53 +0000614 resource_t base, end;
Eric Biedermane9a271e32003-09-02 03:36:25 +0000615
Nico Huber730b2612020-05-20 00:32:50 +0200616 /*
617 * PCI bridges have no enable bit. They are disabled if the base of
618 * the range is greater than the limit. If the size is zero, disable
619 * by setting the base = limit and end = limit - 2^gran.
620 */
621 if (resource->size == 0) {
622 base = resource->limit;
623 end = resource->limit - (1 << resource->gran);
624 resource->base = base;
625 } else {
626 base = resource->base;
627 end = resource_end(resource);
628 }
629
630 if (resource->index == PCI_IO_BASE) {
631 /* Set the I/O ranges. */
632 pci_write_config8(dev, PCI_IO_BASE, base >> 8);
633 pci_write_config16(dev, PCI_IO_BASE_UPPER16, base >> 16);
634 pci_write_config8(dev, PCI_IO_LIMIT, end >> 8);
635 pci_write_config16(dev, PCI_IO_LIMIT_UPPER16, end >> 16);
636 } else if (resource->index == PCI_MEMORY_BASE) {
637 /* Set the memory range. */
638 pci_write_config16(dev, PCI_MEMORY_BASE, base >> 16);
639 pci_write_config16(dev, PCI_MEMORY_LIMIT, end >> 16);
640 } else if (resource->index == PCI_PREF_MEMORY_BASE) {
641 /* Set the prefetchable memory range. */
642 pci_write_config16(dev, PCI_PREF_MEMORY_BASE, base >> 16);
643 pci_write_config32(dev, PCI_PREF_BASE_UPPER32, base >> 32);
644 pci_write_config16(dev, PCI_PREF_MEMORY_LIMIT, end >> 16);
645 pci_write_config32(dev, PCI_PREF_LIMIT_UPPER32, end >> 32);
646 } else {
647 /* Don't let me think I stored the resource. */
648 resource->flags &= ~IORESOURCE_STORED;
Julius Wernere9665952022-01-21 17:06:20 -0800649 printk(BIOS_ERR, "invalid resource->index %lx\n", resource->index);
Nico Huber730b2612020-05-20 00:32:50 +0200650 }
651}
652
653static void pci_set_resource(struct device *dev, struct resource *resource)
654{
Myles Watson29cc9ed2009-07-02 18:56:24 +0000655 /* Make certain the resource has actually been assigned a value. */
Eric Biederman5cd81732004-03-11 15:01:31 +0000656 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
Nico Huberf5312442020-05-20 01:02:18 +0200657 if (resource->flags & IORESOURCE_BRIDGE) {
658 /* If a bridge resource has no value assigned,
659 we can treat it like an empty resource. */
660 resource->size = 0;
661 } else {
Julius Wernere9665952022-01-21 17:06:20 -0800662 printk(BIOS_ERR, "%s %02lx %s size: 0x%010llx not assigned\n",
Angel Ponsd19cc112021-07-04 11:41:31 +0200663 dev_path(dev), resource->index,
Nico Huberf5312442020-05-20 01:02:18 +0200664 resource_type(resource), resource->size);
665 return;
666 }
Eric Biederman8ca8d762003-04-22 19:02:15 +0000667 }
668
Myles Watsoneb81a5b2009-11-05 20:06:19 +0000669 /* If this resource is fixed don't worry about it. */
Uwe Hermanne4870472010-11-04 23:23:47 +0000670 if (resource->flags & IORESOURCE_FIXED)
Myles Watsoneb81a5b2009-11-05 20:06:19 +0000671 return;
Myles Watsoneb81a5b2009-11-05 20:06:19 +0000672
Myles Watson29cc9ed2009-07-02 18:56:24 +0000673 /* If I have already stored this resource don't worry about it. */
Uwe Hermanne4870472010-11-04 23:23:47 +0000674 if (resource->flags & IORESOURCE_STORED)
Eric Biederman5cd81732004-03-11 15:01:31 +0000675 return;
Eric Biederman5cd81732004-03-11 15:01:31 +0000676
Myles Watson29cc9ed2009-07-02 18:56:24 +0000677 /* If the resource is subtractive don't worry about it. */
Uwe Hermanne4870472010-11-04 23:23:47 +0000678 if (resource->flags & IORESOURCE_SUBTRACTIVE)
Eric Biederman03acab62004-10-14 21:25:53 +0000679 return;
Eric Biederman03acab62004-10-14 21:25:53 +0000680
Myles Watson29cc9ed2009-07-02 18:56:24 +0000681 /* Only handle PCI memory and I/O resources for now. */
682 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
Eric Biederman8ca8d762003-04-22 19:02:15 +0000683 return;
Eric Biedermane9a271e32003-09-02 03:36:25 +0000684
Myles Watson29cc9ed2009-07-02 18:56:24 +0000685 /* Enable the resources in the command register. */
Eric Biederman03acab62004-10-14 21:25:53 +0000686 if (resource->size) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000687 if (resource->flags & IORESOURCE_MEM)
Eric Biederman03acab62004-10-14 21:25:53 +0000688 dev->command |= PCI_COMMAND_MEMORY;
Uwe Hermanne4870472010-11-04 23:23:47 +0000689 if (resource->flags & IORESOURCE_IO)
Eric Biederman03acab62004-10-14 21:25:53 +0000690 dev->command |= PCI_COMMAND_IO;
Felix Singer205b53e2020-09-07 15:21:21 +0200691 if (resource->flags & IORESOURCE_PCI_BRIDGE &&
692 CONFIG(PCI_SET_BUS_MASTER_PCI_BRIDGES))
Eric Biederman03acab62004-10-14 21:25:53 +0000693 dev->command |= PCI_COMMAND_MASTER;
Eric Biederman8ca8d762003-04-22 19:02:15 +0000694 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000695
Myles Watson29cc9ed2009-07-02 18:56:24 +0000696 /* Now store the resource. */
Eric Biederman5cd81732004-03-11 15:01:31 +0000697 resource->flags |= IORESOURCE_STORED;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000698
Tim Wawrzynczak8c93fed2022-01-13 16:45:07 -0700699 if (!(resource->flags & IORESOURCE_PCI_BRIDGE)) {
700 if (CONFIG(PCIEXP_SUPPORT_RESIZABLE_BARS) &&
701 (resource->flags & IORESOURCE_PCIE_RESIZABLE_BAR))
702 pci_store_rebar_size(dev, resource);
703
Nico Huber730b2612020-05-20 00:32:50 +0200704 pci_store_resource(dev, resource);
Uwe Hermanne4870472010-11-04 23:23:47 +0000705
Tim Wawrzynczak8c93fed2022-01-13 16:45:07 -0700706 } else {
707 pci_store_bridge_resource(dev, resource);
708 }
709
Eric Biederman03acab62004-10-14 21:25:53 +0000710 report_resource_stored(dev, resource, "");
Eric Biederman8ca8d762003-04-22 19:02:15 +0000711}
712
Eric Biederman5899fd82003-04-24 06:25:08 +0000713void pci_dev_set_resources(struct device *dev)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000714{
Myles Watsonc25cc112010-05-21 14:33:48 +0000715 struct resource *res;
Myles Watson894a3472010-06-09 22:41:35 +0000716 struct bus *bus;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000717 u8 line;
Eric Biederman8ca8d762003-04-22 19:02:15 +0000718
Uwe Hermanne4870472010-11-04 23:23:47 +0000719 for (res = dev->resource_list; res; res = res->next)
Myles Watsonc25cc112010-05-21 14:33:48 +0000720 pci_set_resource(dev, res);
Uwe Hermanne4870472010-11-04 23:23:47 +0000721
Myles Watson894a3472010-06-09 22:41:35 +0000722 for (bus = dev->link_list; bus; bus = bus->next) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000723 if (bus->children)
Eric Biedermane9a271e32003-09-02 03:36:25 +0000724 assign_resources(bus);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000725 }
726
Myles Watson29cc9ed2009-07-02 18:56:24 +0000727 /* Set a default latency timer. */
Eric Biederman7a5416a2003-06-12 19:23:51 +0000728 pci_write_config8(dev, PCI_LATENCY_TIMER, 0x40);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000729
Myles Watson29cc9ed2009-07-02 18:56:24 +0000730 /* Set a default secondary latency timer. */
Uwe Hermanne4870472010-11-04 23:23:47 +0000731 if ((dev->hdr_type & 0x7f) == PCI_HEADER_TYPE_BRIDGE)
Eric Biederman7a5416a2003-06-12 19:23:51 +0000732 pci_write_config8(dev, PCI_SEC_LATENCY_TIMER, 0x40);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000733
Myles Watson29cc9ed2009-07-02 18:56:24 +0000734 /* Zero the IRQ settings. */
Eric Biederman7a5416a2003-06-12 19:23:51 +0000735 line = pci_read_config8(dev, PCI_INTERRUPT_PIN);
Uwe Hermanne4870472010-11-04 23:23:47 +0000736 if (line)
Eric Biederman7a5416a2003-06-12 19:23:51 +0000737 pci_write_config8(dev, PCI_INTERRUPT_LINE, 0);
Uwe Hermanne4870472010-11-04 23:23:47 +0000738
Myles Watson29cc9ed2009-07-02 18:56:24 +0000739 /* Set the cache line size, so far 64 bytes is good for everyone. */
Eric Biederman7a5416a2003-06-12 19:23:51 +0000740 pci_write_config8(dev, PCI_CACHE_LINE_SIZE, 64 >> 2);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000741}
742
Eric Biedermane9a271e32003-09-02 03:36:25 +0000743void pci_dev_enable_resources(struct device *dev)
744{
Kyösti Mälkkicac02312019-06-30 08:40:04 +0300745 const struct pci_operations *ops = NULL;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000746 u16 command;
Eric Biederman03acab62004-10-14 21:25:53 +0000747
Uwe Hermanne4870472010-11-04 23:23:47 +0000748 /* Set the subsystem vendor and device ID for mainboard devices. */
Kyösti Mälkkicac02312019-06-30 08:40:04 +0300749 if (dev->ops)
750 ops = dev->ops->ops_pci;
Eric Biedermandbec2d42004-10-21 10:44:08 +0000751 if (dev->on_mainboard && ops && ops->set_subsystem) {
Duncan Laurie7e1c83e2013-08-09 07:55:10 -0700752 if (CONFIG_SUBSYSTEM_VENDOR_ID)
753 dev->subsystem_vendor = CONFIG_SUBSYSTEM_VENDOR_ID;
Rizwan Qureshifd891292017-04-26 21:00:37 +0530754 else if (!dev->subsystem_vendor)
755 dev->subsystem_vendor = pci_read_config16(dev,
756 PCI_VENDOR_ID);
Duncan Laurie7e1c83e2013-08-09 07:55:10 -0700757 if (CONFIG_SUBSYSTEM_DEVICE_ID)
758 dev->subsystem_device = CONFIG_SUBSYSTEM_DEVICE_ID;
Rizwan Qureshifd891292017-04-26 21:00:37 +0530759 else if (!dev->subsystem_device)
760 dev->subsystem_device = pci_read_config16(dev,
761 PCI_DEVICE_ID);
762
Sven Schnelle91321022011-03-01 19:58:47 +0000763 printk(BIOS_DEBUG, "%s subsystem <- %04x/%04x\n",
764 dev_path(dev), dev->subsystem_vendor,
765 dev->subsystem_device);
766 ops->set_subsystem(dev, dev->subsystem_vendor,
767 dev->subsystem_device);
Eric Biederman03acab62004-10-14 21:25:53 +0000768 }
Eric Biedermane9a271e32003-09-02 03:36:25 +0000769 command = pci_read_config16(dev, PCI_COMMAND);
770 command |= dev->command;
Uwe Hermanne4870472010-11-04 23:23:47 +0000771
Myles Watson29cc9ed2009-07-02 18:56:24 +0000772 /* v3 has
773 * command |= (PCI_COMMAND_PARITY + PCI_COMMAND_SERR); // Error check.
774 */
Uwe Hermanne4870472010-11-04 23:23:47 +0000775
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000776 printk(BIOS_DEBUG, "%s cmd <- %02x\n", dev_path(dev), command);
Eric Biedermane9a271e32003-09-02 03:36:25 +0000777 pci_write_config16(dev, PCI_COMMAND, command);
Eric Biedermane9a271e32003-09-02 03:36:25 +0000778}
779
780void pci_bus_enable_resources(struct device *dev)
781{
Myles Watson29cc9ed2009-07-02 18:56:24 +0000782 u16 ctrl;
783
Uwe Hermanne4870472010-11-04 23:23:47 +0000784 /*
785 * Enable I/O in command register if there is VGA card
Myles Watson29cc9ed2009-07-02 18:56:24 +0000786 * connected with (even it does not claim I/O resource).
787 */
Myles Watson894a3472010-06-09 22:41:35 +0000788 if (dev->link_list->bridge_ctrl & PCI_BRIDGE_CTL_VGA)
Li-Ta Lo515f6c72005-01-11 22:48:54 +0000789 dev->command |= PCI_COMMAND_IO;
Eric Biedermane9a271e32003-09-02 03:36:25 +0000790 ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL);
Myles Watson894a3472010-06-09 22:41:35 +0000791 ctrl |= dev->link_list->bridge_ctrl;
Kyösti Mälkki382e2162019-09-21 16:19:32 +0300792 ctrl |= (PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR); /* Error check. */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000793 printk(BIOS_DEBUG, "%s bridge ctrl <- %04x\n", dev_path(dev), ctrl);
Eric Biedermane9a271e32003-09-02 03:36:25 +0000794 pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl);
795
796 pci_dev_enable_resources(dev);
797}
798
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000799void pci_bus_reset(struct bus *bus)
800{
Uwe Hermanne4870472010-11-04 23:23:47 +0000801 u16 ctl;
802
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000803 ctl = pci_read_config16(bus->dev, PCI_BRIDGE_CONTROL);
804 ctl |= PCI_BRIDGE_CTL_BUS_RESET;
805 pci_write_config16(bus->dev, PCI_BRIDGE_CONTROL, ctl);
806 mdelay(10);
Uwe Hermanne4870472010-11-04 23:23:47 +0000807
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000808 ctl &= ~PCI_BRIDGE_CTL_BUS_RESET;
809 pci_write_config16(bus->dev, PCI_BRIDGE_CONTROL, ctl);
810 delay(1);
811}
812
Elyes HAOUAS88030b72018-09-20 17:26:10 +0200813void pci_dev_set_subsystem(struct device *dev, unsigned int vendor,
814 unsigned int device)
Eric Biederman03acab62004-10-14 21:25:53 +0000815{
Subrata Banik9514d472019-03-20 14:56:27 +0530816 uint8_t offset;
817
818 /* Header type */
819 switch (dev->hdr_type & 0x7f) {
820 case PCI_HEADER_TYPE_NORMAL:
821 offset = PCI_SUBSYSTEM_VENDOR_ID;
822 break;
823 case PCI_HEADER_TYPE_BRIDGE:
824 offset = pci_find_capability(dev, PCI_CAP_ID_SSVID);
825 if (!offset)
826 return;
827 offset += 4; /* Vendor ID at offset 4 */
828 break;
829 case PCI_HEADER_TYPE_CARDBUS:
830 offset = PCI_CB_SUBSYSTEM_VENDOR_ID;
831 break;
832 default:
833 return;
834 }
835
Subrata Banik4a0f0712019-03-20 14:29:47 +0530836 if (!vendor || !device) {
Subrata Banik9514d472019-03-20 14:56:27 +0530837 pci_write_config32(dev, offset,
Subrata Banik4a0f0712019-03-20 14:29:47 +0530838 pci_read_config32(dev, PCI_VENDOR_ID));
839 } else {
Subrata Banik9514d472019-03-20 14:56:27 +0530840 pci_write_config32(dev, offset,
Subrata Banik4a0f0712019-03-20 14:29:47 +0530841 ((device & 0xffff) << 16) | (vendor & 0xffff));
842 }
Eric Biederman03acab62004-10-14 21:25:53 +0000843}
844
Frans Hendriksb71181a2019-10-04 14:06:33 +0200845static int should_run_oprom(struct device *dev, struct rom_header *rom)
Kyösti Mälkki580e5642014-05-01 16:31:34 +0300846{
847 static int should_run = -1;
848
Frans Hendriksb71181a2019-10-04 14:06:33 +0200849 if (CONFIG(VENDORCODE_ELTAN_VBOOT))
850 if (rom != NULL)
851 if (!verified_boot_should_run_oprom(rom))
852 return 0;
853
Kyösti Mälkki580e5642014-05-01 16:31:34 +0300854 if (should_run >= 0)
855 return should_run;
856
Julius Wernercd49cce2019-03-05 16:53:33 -0800857 if (CONFIG(ALWAYS_RUN_OPROM)) {
Aaron Durbin10510252018-01-30 10:04:02 -0700858 should_run = 1;
859 return should_run;
860 }
861
Kyösti Mälkki9ab1c102013-12-22 00:22:49 +0200862 /* Don't run VGA option ROMs, unless we have to print
Kyösti Mälkki580e5642014-05-01 16:31:34 +0300863 * something on the screen before the kernel is loaded.
864 */
Furquan Shaikh0325dc62016-07-25 13:02:36 -0700865 should_run = display_init_required();
Kyösti Mälkki580e5642014-05-01 16:31:34 +0300866
Kyösti Mälkki9ab1c102013-12-22 00:22:49 +0200867 if (!should_run)
868 printk(BIOS_DEBUG, "Not running VGA Option ROM\n");
Kyösti Mälkki580e5642014-05-01 16:31:34 +0300869 return should_run;
870}
871
872static int should_load_oprom(struct device *dev)
873{
Kyösti Mälkki580e5642014-05-01 16:31:34 +0300874 /* If S3_VGA_ROM_RUN is disabled, skip running VGA option
875 * ROMs when coming out of an S3 resume.
876 */
Julius Wernercd49cce2019-03-05 16:53:33 -0800877 if (!CONFIG(S3_VGA_ROM_RUN) && acpi_is_wakeup_s3() &&
Kyösti Mälkki580e5642014-05-01 16:31:34 +0300878 ((dev->class >> 8) == PCI_CLASS_DISPLAY_VGA))
879 return 0;
Julius Wernercd49cce2019-03-05 16:53:33 -0800880 if (CONFIG(ALWAYS_LOAD_OPROM))
Kyösti Mälkki580e5642014-05-01 16:31:34 +0300881 return 1;
Frans Hendriksb71181a2019-10-04 14:06:33 +0200882 if (should_run_oprom(dev, NULL))
Kyösti Mälkki580e5642014-05-01 16:31:34 +0300883 return 1;
884
885 return 0;
886}
Kyösti Mälkki580e5642014-05-01 16:31:34 +0300887
Kyösti Mälkki0f300632020-12-19 23:43:56 +0200888static void oprom_pre_graphics_stall(void)
889{
Paul Menzelc4062c72021-02-11 10:43:14 +0100890 if (CONFIG_PRE_GRAPHICS_DELAY_MS)
891 mdelay(CONFIG_PRE_GRAPHICS_DELAY_MS);
Kyösti Mälkki0f300632020-12-19 23:43:56 +0200892}
893
Uwe Hermanne4870472010-11-04 23:23:47 +0000894/** Default handler: only runs the relevant PCI BIOS. */
Li-Ta Lo883b8792005-01-10 23:16:22 +0000895void pci_dev_init(struct device *dev)
896{
897 struct rom_header *rom, *ram;
898
Julius Wernercd49cce2019-03-05 16:53:33 -0800899 if (!CONFIG(VGA_ROM_RUN))
Aaron Durbinfbed9a52018-01-30 09:58:51 -0700900 return;
901
Vladimir Serbinenkob32816e2013-12-20 17:47:19 +0100902 /* Only execute VGA ROMs. */
903 if (((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA))
Myles Watson17aeeca2009-10-07 18:41:08 +0000904 return;
Roman Kononov778a42b2007-04-06 18:34:39 +0000905
Kyösti Mälkki580e5642014-05-01 16:31:34 +0300906 if (!should_load_oprom(dev))
Stefan Reinauer74a0efe2012-03-30 17:10:49 -0700907 return;
Martin Roth5dd4a2a2018-03-06 16:10:45 -0700908 timestamp_add_now(TS_OPROM_INITIALIZE);
Aaron Durbince872cb2013-03-28 15:59:19 -0500909
910 rom = pci_rom_probe(dev);
911 if (rom == NULL)
912 return;
913
914 ram = pci_rom_load(dev, rom);
915 if (ram == NULL)
916 return;
Martin Roth5dd4a2a2018-03-06 16:10:45 -0700917 timestamp_add_now(TS_OPROM_COPY_END);
Aaron Durbince872cb2013-03-28 15:59:19 -0500918
Frans Hendriksb71181a2019-10-04 14:06:33 +0200919 if (!should_run_oprom(dev, rom))
Kyösti Mälkki580e5642014-05-01 16:31:34 +0300920 return;
921
Kyösti Mälkki0f300632020-12-19 23:43:56 +0200922 /* Wait for any configured pre-graphics delay */
923 oprom_pre_graphics_stall();
924
Stefan Reinauerd98cf5b2008-08-01 11:25:41 +0000925 run_bios(dev, (unsigned long)ram);
Johanna Schanderdb7a3ae2019-07-24 10:14:26 +0200926
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +0200927 gfx_set_init_done(1);
928 printk(BIOS_DEBUG, "VGA Option ROM was run\n");
Martin Roth5dd4a2a2018-03-06 16:10:45 -0700929 timestamp_add_now(TS_OPROM_END);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000930}
Li-Ta Lo883b8792005-01-10 23:16:22 +0000931
Li-Ta Loe5266692004-03-23 21:28:05 +0000932/** Default device operation for PCI devices */
Subrata Banikffc790b2017-12-11 10:29:49 +0530933struct pci_operations pci_dev_ops_pci = {
Eric Biederman03acab62004-10-14 21:25:53 +0000934 .set_subsystem = pci_dev_set_subsystem,
935};
936
Eric Biederman8ca8d762003-04-22 19:02:15 +0000937struct device_operations default_pci_ops_dev = {
Uwe Hermanne4870472010-11-04 23:23:47 +0000938 .read_resources = pci_dev_read_resources,
939 .set_resources = pci_dev_set_resources,
Eric Biedermane9a271e32003-09-02 03:36:25 +0000940 .enable_resources = pci_dev_enable_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800941#if CONFIG(HAVE_ACPI_TABLES)
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200942 .write_acpi_tables = pci_rom_write_acpi_tables,
Nico Huber68680dd2020-03-31 17:34:52 +0200943 .acpi_fill_ssdt = pci_rom_ssdt,
Patrick Rudolpha5c2ac62016-03-31 20:04:23 +0200944#endif
Uwe Hermanne4870472010-11-04 23:23:47 +0000945 .init = pci_dev_init,
Uwe Hermanne4870472010-11-04 23:23:47 +0000946 .ops_pci = &pci_dev_ops_pci,
Eric Biederman8ca8d762003-04-22 19:02:15 +0000947};
Li-Ta Loe5266692004-03-23 21:28:05 +0000948
949/** Default device operations for PCI bridges */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000950struct device_operations default_pci_ops_bus = {
Uwe Hermanne4870472010-11-04 23:23:47 +0000951 .read_resources = pci_bus_read_resources,
952 .set_resources = pci_dev_set_resources,
Eric Biedermane9a271e32003-09-02 03:36:25 +0000953 .enable_resources = pci_bus_enable_resources,
Uwe Hermanne4870472010-11-04 23:23:47 +0000954 .scan_bus = pci_scan_bridge,
Uwe Hermanne4870472010-11-04 23:23:47 +0000955 .reset_bus = pci_bus_reset,
Eric Biederman8ca8d762003-04-22 19:02:15 +0000956};
Li-Ta Loe5266692004-03-23 21:28:05 +0000957
Tim Wawrzynczakdbcf7b12020-05-13 16:15:08 -0600958/** Default device operations for PCI devices marked 'hidden' */
959static struct device_operations default_hidden_pci_ops_dev = {
960 .read_resources = noop_read_resources,
961 .set_resources = noop_set_resources,
962 .scan_bus = scan_static_bus,
963};
964
Li-Ta Loe5266692004-03-23 21:28:05 +0000965/**
Nico Huber061b9052019-09-21 15:58:23 +0200966 * Check for compatibility to route legacy VGA cycles through a bridge.
967 *
968 * Originally, when decoding i/o ports for legacy VGA cycles, bridges
969 * should only consider the 10 least significant bits of the port address.
970 * This means all VGA registers were aliased every 1024 ports!
971 * e.g. 0x3b0 was also decoded as 0x7b0, 0xbb0 etc.
972 *
973 * To avoid this mess, a bridge control bit (VGA16) was introduced in
974 * 2003 to enable decoding of 16-bit port addresses. As we don't want
975 * to make this any more complex for now, we use this bit if possible
976 * and only warn if it's not supported (in set_vga_bridge_bits()).
977 */
978static void pci_bridge_vga_compat(struct bus *const bus)
979{
980 uint16_t bridge_ctrl;
981
982 bridge_ctrl = pci_read_config16(bus->dev, PCI_BRIDGE_CONTROL);
983
984 /* Ensure VGA decoding is disabled during probing (it should
985 be by default, but we run blobs nowadays) */
986 bridge_ctrl &= ~PCI_BRIDGE_CTL_VGA;
987 pci_write_config16(bus->dev, PCI_BRIDGE_CONTROL, bridge_ctrl);
988
989 /* If the upstream bridge doesn't support VGA16, we don't have to check */
990 bus->no_vga16 |= bus->dev->bus->no_vga16;
991 if (bus->no_vga16)
992 return;
993
994 /* Test if we can enable 16-bit decoding */
995 bridge_ctrl |= PCI_BRIDGE_CTL_VGA16;
996 pci_write_config16(bus->dev, PCI_BRIDGE_CONTROL, bridge_ctrl);
997 bridge_ctrl = pci_read_config16(bus->dev, PCI_BRIDGE_CONTROL);
998
999 bus->no_vga16 = !(bridge_ctrl & PCI_BRIDGE_CTL_VGA16);
1000}
1001
1002/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001003 * Detect the type of downstream bridge.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001004 *
Myles Watson29cc9ed2009-07-02 18:56:24 +00001005 * This function is a heuristic to detect which type of bus is downstream
1006 * of a PCI-to-PCI bridge. This functions by looking for various capability
1007 * blocks to figure out the type of downstream bridge. PCI-X, PCI-E, and
1008 * Hypertransport all seem to have appropriate capabilities.
Myles Watson032a9652009-05-11 22:24:53 +00001009 *
Uwe Hermanne4870472010-11-04 23:23:47 +00001010 * When only a PCI-Express capability is found the type is examined to see
1011 * which type of bridge we have.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001012 *
Myles Watson29cc9ed2009-07-02 18:56:24 +00001013 * @param dev Pointer to the device structure of the bridge.
1014 * @return Appropriate bridge operations.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001015 */
Aaron Durbinc30d9132017-08-07 16:55:43 -06001016static struct device_operations *get_pci_bridge_ops(struct device *dev)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001017{
Julius Wernercd49cce2019-03-05 16:53:33 -08001018#if CONFIG(PCIX_PLUGIN_SUPPORT)
Ronald G. Minnich78a16672012-11-29 16:28:21 -08001019 unsigned int pcixpos;
1020 pcixpos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
1021 if (pcixpos) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001022 printk(BIOS_DEBUG, "%s subordinate bus PCI-X\n", dev_path(dev));
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001023 return &default_pcix_ops_bus;
1024 }
1025#endif
Julius Wernercd49cce2019-03-05 16:53:33 -08001026#if CONFIG(PCIEXP_PLUGIN_SUPPORT)
Ronald G. Minnich78a16672012-11-29 16:28:21 -08001027 unsigned int pciexpos;
1028 pciexpos = pci_find_capability(dev, PCI_CAP_ID_PCIE);
1029 if (pciexpos) {
Uwe Hermanne4870472010-11-04 23:23:47 +00001030 u16 flags;
Ronald G. Minnich78a16672012-11-29 16:28:21 -08001031 flags = pci_read_config16(dev, pciexpos + PCI_EXP_FLAGS);
Myles Watson29cc9ed2009-07-02 18:56:24 +00001032 switch ((flags & PCI_EXP_FLAGS_TYPE) >> 4) {
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001033 case PCI_EXP_TYPE_ROOT_PORT:
1034 case PCI_EXP_TYPE_UPSTREAM:
1035 case PCI_EXP_TYPE_DOWNSTREAM:
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001036 printk(BIOS_DEBUG, "%s subordinate bus PCI Express\n",
Uwe Hermanne4870472010-11-04 23:23:47 +00001037 dev_path(dev));
Arthur Heymans24837e72021-03-11 20:34:05 +01001038 if (CONFIG(PCIEXP_HOTPLUG)) {
1039 u16 sltcap;
1040 sltcap = pci_read_config16(dev, pciexpos + PCI_EXP_SLTCAP);
1041 if (sltcap & PCI_EXP_SLTCAP_HPC) {
1042 printk(BIOS_DEBUG, "%s hot-plug capable\n",
1043 dev_path(dev));
1044 return &default_pciexp_hotplug_ops_bus;
1045 }
Jeremy Sollercf2ac542019-10-09 21:40:36 -06001046 }
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001047 return &default_pciexp_ops_bus;
1048 case PCI_EXP_TYPE_PCI_BRIDGE:
Uwe Hermanne4870472010-11-04 23:23:47 +00001049 printk(BIOS_DEBUG, "%s subordinate PCI\n",
1050 dev_path(dev));
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001051 return &default_pci_ops_bus;
1052 default:
1053 break;
1054 }
1055 }
1056#endif
1057 return &default_pci_ops_bus;
1058}
1059
1060/**
Vadim Bendebury8049fc92012-04-24 12:53:19 -07001061 * Check if a device id matches a PCI driver entry.
1062 *
1063 * The driver entry can either point at a zero terminated array of acceptable
1064 * device IDs, or include a single device ID.
1065 *
Martin Roth98b698c2015-01-06 21:02:52 -07001066 * @param driver pointer to the PCI driver entry being checked
1067 * @param device_id PCI device ID of the device being matched
Vadim Bendebury8049fc92012-04-24 12:53:19 -07001068 */
1069static int device_id_match(struct pci_driver *driver, unsigned short device_id)
1070{
1071 if (driver->devices) {
1072 unsigned short check_id;
1073 const unsigned short *device_list = driver->devices;
1074 while ((check_id = *device_list++) != 0)
1075 if (check_id == device_id)
1076 return 1;
1077 }
1078
1079 return (driver->device == device_id);
1080}
1081
1082/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001083 * Set up PCI device operation.
1084 *
1085 * Check if it already has a driver. If not, use find_device_operations(),
1086 * or set to a default based on type.
Li-Ta Loe5266692004-03-23 21:28:05 +00001087 *
Myles Watson29cc9ed2009-07-02 18:56:24 +00001088 * @param dev Pointer to the device whose pci_ops you want to set.
Li-Ta Loe5266692004-03-23 21:28:05 +00001089 * @see pci_drivers
1090 */
Eric Biederman8ca8d762003-04-22 19:02:15 +00001091static void set_pci_ops(struct device *dev)
1092{
1093 struct pci_driver *driver;
Li-Ta Loe5266692004-03-23 21:28:05 +00001094
Uwe Hermanne4870472010-11-04 23:23:47 +00001095 if (dev->ops)
1096 return;
1097
1098 /*
1099 * Look through the list of setup drivers and find one for
Myles Watson29cc9ed2009-07-02 18:56:24 +00001100 * this PCI device.
Eric Biedermanb78c1972004-10-14 20:54:17 +00001101 */
Aaron Durbin03758152015-09-03 17:23:08 -05001102 for (driver = &_pci_drivers[0]; driver != &_epci_drivers[0]; driver++) {
Eric Biederman8ca8d762003-04-22 19:02:15 +00001103 if ((driver->vendor == dev->vendor) &&
Vadim Bendebury8049fc92012-04-24 12:53:19 -07001104 device_id_match(driver, dev->device)) {
Uwe Hermann312673c2009-10-27 21:49:33 +00001105 dev->ops = (struct device_operations *)driver->ops;
Nico Huber7e3e1ea2020-10-12 16:25:40 +02001106 break;
Eric Biederman8ca8d762003-04-22 19:02:15 +00001107 }
1108 }
Li-Ta Loe5266692004-03-23 21:28:05 +00001109
Nico Huber7e3e1ea2020-10-12 16:25:40 +02001110 if (dev->ops) {
1111 printk(BIOS_SPEW, "%s [%04x/%04x] %sops\n", dev_path(dev),
1112 driver->vendor, driver->device, (driver->ops->scan_bus ? "bus " : ""));
1113 return;
1114 }
1115
Uwe Hermanne4870472010-11-04 23:23:47 +00001116 /* If I don't have a specific driver use the default operations. */
1117 switch (dev->hdr_type & 0x7f) { /* Header type */
1118 case PCI_HEADER_TYPE_NORMAL:
Eric Biederman8ca8d762003-04-22 19:02:15 +00001119 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)
1120 goto bad;
1121 dev->ops = &default_pci_ops_dev;
1122 break;
1123 case PCI_HEADER_TYPE_BRIDGE:
1124 if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
1125 goto bad;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001126 dev->ops = get_pci_bridge_ops(dev);
Eric Biederman8ca8d762003-04-22 19:02:15 +00001127 break;
Julius Wernercd49cce2019-03-05 16:53:33 -08001128#if CONFIG(CARDBUS_PLUGIN_SUPPORT)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001129 case PCI_HEADER_TYPE_CARDBUS:
1130 dev->ops = &default_cardbus_ops_bus;
1131 break;
1132#endif
Felix Singerc96ee7e2021-01-07 06:14:27 +00001133 default:
Uwe Hermanne4870472010-11-04 23:23:47 +00001134bad:
Li-Ta Lo69c5a902004-04-29 20:08:54 +00001135 if (dev->enabled) {
Angel Ponsd19cc112021-07-04 11:41:31 +02001136 printk(BIOS_ERR,
1137 "%s [%04x/%04x/%06x] has unknown header type %02x, ignoring.\n",
1138 dev_path(dev), dev->vendor, dev->device,
Uwe Hermanne4870472010-11-04 23:23:47 +00001139 dev->class >> 8, dev->hdr_type);
Eric Biederman83b991a2003-10-11 06:20:25 +00001140 }
Eric Biederman8ca8d762003-04-22 19:02:15 +00001141 }
Eric Biederman8ca8d762003-04-22 19:02:15 +00001142}
1143
1144/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001145 * See if we have already allocated a device structure for a given devfn.
Li-Ta Loe5266692004-03-23 21:28:05 +00001146 *
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001147 * Given a PCI bus structure and a devfn number, find the device structure
1148 * corresponding to the devfn, if present. Then move the device structure
1149 * as the last child on the bus.
Li-Ta Loe5266692004-03-23 21:28:05 +00001150 *
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001151 * @param bus Pointer to the bus structure.
Myles Watson29cc9ed2009-07-02 18:56:24 +00001152 * @param devfn A device/function number.
Myles Watson29cc9ed2009-07-02 18:56:24 +00001153 * @return Pointer to the device structure found or NULL if we have not
Li-Ta Lo3a812852004-12-03 22:39:34 +00001154 * allocated a device for this devfn yet.
Eric Biederman8ca8d762003-04-22 19:02:15 +00001155 */
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001156static struct device *pci_scan_get_dev(struct bus *bus, unsigned int devfn)
Eric Biederman8ca8d762003-04-22 19:02:15 +00001157{
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001158 struct device *dev, **prev;
Uwe Hermanne4870472010-11-04 23:23:47 +00001159
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001160 prev = &bus->children;
1161 for (dev = bus->children; dev; dev = dev->sibling) {
Duncan Lauriebf696222020-10-18 15:10:00 -07001162 if (dev->path.type == DEVICE_PATH_PCI && dev->path.pci.devfn == devfn) {
1163 /* Unlink from the list. */
1164 *prev = dev->sibling;
1165 dev->sibling = NULL;
1166 break;
Eric Biedermanad1b35a2003-10-14 02:36:51 +00001167 }
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001168 prev = &dev->sibling;
Eric Biederman8ca8d762003-04-22 19:02:15 +00001169 }
Myles Watson29cc9ed2009-07-02 18:56:24 +00001170
Uwe Hermanne4870472010-11-04 23:23:47 +00001171 /*
1172 * Just like alloc_dev() add the device to the list of devices on the
Myles Watson29cc9ed2009-07-02 18:56:24 +00001173 * bus. When the list of devices was formed we removed all of the
1174 * parents children, and now we are interleaving static and dynamic
1175 * devices in order on the bus.
Eric Biedermanb78c1972004-10-14 20:54:17 +00001176 */
Eric Biedermane9a271e32003-09-02 03:36:25 +00001177 if (dev) {
Myles Watson29cc9ed2009-07-02 18:56:24 +00001178 struct device *child;
Uwe Hermanne4870472010-11-04 23:23:47 +00001179
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001180 /* Find the last child on the bus. */
1181 for (child = bus->children; child && child->sibling;)
Eric Biedermane9a271e32003-09-02 03:36:25 +00001182 child = child->sibling;
Uwe Hermanne4870472010-11-04 23:23:47 +00001183
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001184 /* Place the device as last on the bus. */
Uwe Hermanne4870472010-11-04 23:23:47 +00001185 if (child)
Eric Biedermane9a271e32003-09-02 03:36:25 +00001186 child->sibling = dev;
Uwe Hermanne4870472010-11-04 23:23:47 +00001187 else
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001188 bus->children = dev;
Eric Biedermane9a271e32003-09-02 03:36:25 +00001189 }
1190
Eric Biederman8ca8d762003-04-22 19:02:15 +00001191 return dev;
1192}
1193
Myles Watson032a9652009-05-11 22:24:53 +00001194/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001195 * Scan a PCI bus.
Li-Ta Loe5266692004-03-23 21:28:05 +00001196 *
Myles Watson29cc9ed2009-07-02 18:56:24 +00001197 * Determine the existence of a given PCI device. Allocate a new struct device
1198 * if dev==NULL was passed in and the device exists in hardware.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001199 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001200 * @param dev Pointer to the dev structure.
1201 * @param bus Pointer to the bus structure.
1202 * @param devfn A device/function number to look at.
1203 * @return The device structure for the device (if found), NULL otherwise.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001204 */
Aaron Durbinc30d9132017-08-07 16:55:43 -06001205struct device *pci_probe_dev(struct device *dev, struct bus *bus,
1206 unsigned int devfn)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001207{
Myles Watson29cc9ed2009-07-02 18:56:24 +00001208 u32 id, class;
1209 u8 hdr_type;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001210
Myles Watson29cc9ed2009-07-02 18:56:24 +00001211 /* Detect if a device is present. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001212 if (!dev) {
1213 struct device dummy;
Uwe Hermanne4870472010-11-04 23:23:47 +00001214
Myles Watson29cc9ed2009-07-02 18:56:24 +00001215 dummy.bus = bus;
1216 dummy.path.type = DEVICE_PATH_PCI;
Stefan Reinauer2b34db82009-02-28 20:10:20 +00001217 dummy.path.pci.devfn = devfn;
Uwe Hermanne4870472010-11-04 23:23:47 +00001218
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001219 id = pci_read_config32(&dummy, PCI_VENDOR_ID);
Uwe Hermanne4870472010-11-04 23:23:47 +00001220 /*
1221 * Have we found something? Some broken boards return 0 if a
1222 * slot is empty, but the expected answer is 0xffffffff.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001223 */
Uwe Hermanne4870472010-11-04 23:23:47 +00001224 if (id == 0xffffffff)
Stefan Reinauer7355c752010-04-02 16:30:25 +00001225 return NULL;
Uwe Hermanne4870472010-11-04 23:23:47 +00001226
Stefan Reinauer7355c752010-04-02 16:30:25 +00001227 if ((id == 0x00000000) || (id == 0x0000ffff) ||
1228 (id == 0xffff0000)) {
Uwe Hermanne4870472010-11-04 23:23:47 +00001229 printk(BIOS_SPEW, "%s, bad id 0x%x\n",
1230 dev_path(&dummy), id);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001231 return NULL;
1232 }
1233 dev = alloc_dev(bus, &dummy.path);
Myles Watson29cc9ed2009-07-02 18:56:24 +00001234 } else {
Uwe Hermanne4870472010-11-04 23:23:47 +00001235 /*
1236 * Enable/disable the device. Once we have found the device-
Myles Watson29cc9ed2009-07-02 18:56:24 +00001237 * specific operations this operations we will disable the
1238 * device with those as well.
Myles Watson032a9652009-05-11 22:24:53 +00001239 *
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001240 * This is geared toward devices that have subfunctions
1241 * that do not show up by default.
Myles Watson032a9652009-05-11 22:24:53 +00001242 *
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001243 * If a device is a stuff option on the motherboard
Myles Watson29cc9ed2009-07-02 18:56:24 +00001244 * it may be absent and enable_dev() must cope.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001245 */
Myles Watson29cc9ed2009-07-02 18:56:24 +00001246 /* Run the magic enable sequence for the device. */
Uwe Hermanne4870472010-11-04 23:23:47 +00001247 if (dev->chip_ops && dev->chip_ops->enable_dev)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001248 dev->chip_ops->enable_dev(dev);
Uwe Hermanne4870472010-11-04 23:23:47 +00001249
Myles Watson29cc9ed2009-07-02 18:56:24 +00001250 /* Now read the vendor and device ID. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001251 id = pci_read_config32(dev, PCI_VENDOR_ID);
Myles Watson032a9652009-05-11 22:24:53 +00001252
Uwe Hermanne4870472010-11-04 23:23:47 +00001253 /*
1254 * If the device does not have a PCI ID disable it. Possibly
Myles Watson29cc9ed2009-07-02 18:56:24 +00001255 * this is because we have already disabled the device. But
1256 * this also handles optional devices that may not always
1257 * show up.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001258 */
1259 /* If the chain is fully enumerated quit */
Myles Watson29cc9ed2009-07-02 18:56:24 +00001260 if ((id == 0xffffffff) || (id == 0x00000000) ||
1261 (id == 0x0000ffff) || (id == 0xffff0000)) {
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001262 if (dev->enabled) {
Angel Ponsd19cc112021-07-04 11:41:31 +02001263 printk(BIOS_INFO,
1264 "PCI: Static device %s not found, disabling it.\n",
1265 dev_path(dev));
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001266 dev->enabled = 0;
1267 }
1268 return dev;
1269 }
1270 }
Uwe Hermanne4870472010-11-04 23:23:47 +00001271
Myles Watson29cc9ed2009-07-02 18:56:24 +00001272 /* Read the rest of the PCI configuration information. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001273 hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE);
1274 class = pci_read_config32(dev, PCI_CLASS_REVISION);
Myles Watson032a9652009-05-11 22:24:53 +00001275
Myles Watson29cc9ed2009-07-02 18:56:24 +00001276 /* Store the interesting information in the device structure. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001277 dev->vendor = id & 0xffff;
1278 dev->device = (id >> 16) & 0xffff;
1279 dev->hdr_type = hdr_type;
Myles Watson29cc9ed2009-07-02 18:56:24 +00001280
1281 /* Class code, the upper 3 bytes of PCI_CLASS_REVISION. */
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001282 dev->class = class >> 8;
Myles Watson032a9652009-05-11 22:24:53 +00001283
Myles Watson29cc9ed2009-07-02 18:56:24 +00001284 /* Architectural/System devices always need to be bus masters. */
Felix Singerd3d0fd72020-09-07 16:15:14 +02001285 if ((dev->class >> 16) == PCI_BASE_CLASS_SYSTEM &&
1286 CONFIG(PCI_ALLOW_BUS_MASTER_ANY_DEVICE))
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001287 dev->command |= PCI_COMMAND_MASTER;
Uwe Hermanne4870472010-11-04 23:23:47 +00001288
1289 /*
1290 * Look at the vendor and device ID, or at least the header type and
Myles Watson29cc9ed2009-07-02 18:56:24 +00001291 * class and figure out which set of configuration methods to use.
1292 * Unless we already have some PCI ops.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001293 */
1294 set_pci_ops(dev);
1295
Myles Watson29cc9ed2009-07-02 18:56:24 +00001296 /* Now run the magic enable/disable sequence for the device. */
Uwe Hermanne4870472010-11-04 23:23:47 +00001297 if (dev->ops && dev->ops->enable)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001298 dev->ops->enable(dev);
Myles Watson032a9652009-05-11 22:24:53 +00001299
Myles Watson29cc9ed2009-07-02 18:56:24 +00001300 /* Display the device. */
Uwe Hermanne4870472010-11-04 23:23:47 +00001301 printk(BIOS_DEBUG, "%s [%04x/%04x] %s%s\n", dev_path(dev),
1302 dev->vendor, dev->device, dev->enabled ? "enabled" : "disabled",
1303 dev->ops ? "" : " No operations");
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001304
1305 return dev;
1306}
1307
Myles Watson032a9652009-05-11 22:24:53 +00001308/**
Kyösti Mälkkic73acdb2013-06-15 17:16:56 +03001309 * Test for match between romstage and ramstage device instance.
1310 *
1311 * @param dev Pointer to the device structure.
1312 * @param sdev Simple device model identifier, created with PCI_DEV().
1313 * @return Non-zero if bus:dev.fn of device matches.
1314 */
Aaron Durbinc30d9132017-08-07 16:55:43 -06001315unsigned int pci_match_simple_dev(struct device *dev, pci_devfn_t sdev)
Kyösti Mälkkic73acdb2013-06-15 17:16:56 +03001316{
1317 return dev->bus->secondary == PCI_DEV2SEGBUS(sdev) &&
1318 dev->path.pci.devfn == PCI_DEV2DEVFN(sdev);
1319}
1320
1321/**
Bill XIE513d3592022-08-02 22:55:51 +08001322 * Test whether a capability is available along the whole path from the given
1323 * device to the host bridge.
1324 *
1325 * @param dev Pointer to the device structure.
1326 * @param cap PCI_CAP_LIST_ID of the PCI capability we're looking for.
1327 * @return The next matching capability of the given device, if it is available
1328 * along the whole path, or zero if not.
1329 */
1330uint16_t pci_find_cap_recursive(const struct device *dev, uint16_t cap)
1331{
1332 assert(dev->bus);
1333 uint16_t pos = pci_find_capability(dev, cap);
1334 const struct device *bridge = dev->bus->dev;
1335 while (bridge && (bridge->path.type == DEVICE_PATH_PCI)) {
1336 assert(bridge->bus);
1337 if (!pci_find_capability(bridge, cap))
1338 return 0;
1339 bridge = bridge->bus->dev;
1340 }
1341 return pos;
1342}
1343
1344/**
Tim Wawrzynczakdbcf7b12020-05-13 16:15:08 -06001345 * PCI devices that are marked as "hidden" do not get probed. However, the same
1346 * initialization logic is still performed as if it were. This is useful when
1347 * devices would like to be described in the devicetree.cb file, and/or present
1348 * static PCI resources to the allocator, but the platform firmware hides the
1349 * device (makes the device invisible to PCI enumeration) before PCI enumeration
1350 * takes place.
1351 *
1352 * The expected semantics of PCI devices marked as 'hidden':
1353 * 1) The device is actually present under the specified BDF
1354 * 2) The device config space can still be accessed somehow, but the Vendor ID
1355 * indicates there is no device there (it reads as 0xffffffff).
1356 * 3) The device may still consume PCI resources. Typically, these would have
1357 * been hardcoded elsewhere.
1358 *
1359 * @param dev Pointer to the device structure.
1360 */
1361static void pci_scan_hidden_device(struct device *dev)
1362{
1363 if (dev->chip_ops && dev->chip_ops->enable_dev)
1364 dev->chip_ops->enable_dev(dev);
1365
1366 /*
1367 * If chip_ops->enable_dev did not set dev->ops, then set to a default
1368 * .ops, because PCI enumeration is effectively being skipped, therefore
1369 * no PCI driver will bind to this device. However, children may want to
1370 * be enumerated, so this provides scan_static_bus for the .scan_bus
1371 * callback.
1372 */
1373 if (dev->ops == NULL)
1374 dev->ops = &default_hidden_pci_ops_dev;
1375
1376 if (dev->ops->enable)
1377 dev->ops->enable(dev);
1378
1379 /* Display the device almost as if it were probed normally */
1380 printk(BIOS_DEBUG, "%s [0000/%04x] hidden%s\n", dev_path(dev),
1381 dev->device, dev->ops ? "" : " No operations");
1382}
1383
1384/**
Jianjun Wang777ffff2021-07-24 14:50:36 +08001385 * A PCIe Downstream Port normally leads to a Link with only Device 0 on it
1386 * (PCIe spec r5.0, sec 7.3.1). As an optimization, scan only for Device 0 in
1387 * that situation.
1388 *
1389 * @param bus Pointer to the bus structure.
1390 */
1391static bool pci_bus_only_one_child(struct bus *bus)
1392{
1393 struct device *bridge = bus->dev;
1394 u16 pcie_pos, pcie_flags_reg;
1395 int pcie_type;
1396
Arthur Heymansdb199cc2022-01-06 20:56:01 +01001397 if (!bridge)
1398 return false;
1399
Nico Huberf514b8a2022-02-25 14:25:57 +01001400 if (bridge->path.type != DEVICE_PATH_PCI)
1401 return false;
1402
Jianjun Wang777ffff2021-07-24 14:50:36 +08001403 pcie_pos = pci_find_capability(bridge, PCI_CAP_ID_PCIE);
1404 if (!pcie_pos)
1405 return false;
1406
1407 pcie_flags_reg = pci_read_config16(bridge, pcie_pos + PCI_EXP_FLAGS);
1408
1409 pcie_type = (pcie_flags_reg & PCI_EXP_FLAGS_TYPE) >> 4;
1410
1411 return pciexp_is_downstream_port(pcie_type);
1412}
1413
1414/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001415 * Scan a PCI bus.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001416 *
Li-Ta Loe5266692004-03-23 21:28:05 +00001417 * Determine the existence of devices and bridges on a PCI bus. If there are
1418 * bridges on the bus, recursively scan the buses behind the bridges.
1419 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001420 * @param bus Pointer to the bus structure.
1421 * @param min_devfn Minimum devfn to look at in the scan, usually 0x00.
1422 * @param max_devfn Maximum devfn to look at in the scan, usually 0xff.
Eric Biederman8ca8d762003-04-22 19:02:15 +00001423 */
Martin Roth38ddbfb2019-10-23 21:41:00 -06001424void pci_scan_bus(struct bus *bus, unsigned int min_devfn,
1425 unsigned int max_devfn)
Eric Biederman8ca8d762003-04-22 19:02:15 +00001426{
1427 unsigned int devfn;
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001428 struct device *dev, **prev;
1429 int once = 0;
Eric Biederman8ca8d762003-04-22 19:02:15 +00001430
Elyes HAOUASf984aec2021-01-16 17:29:17 +01001431 printk(BIOS_DEBUG, "PCI: %s for bus %02x\n", __func__, bus->secondary);
Eric Biederman8ca8d762003-04-22 19:02:15 +00001432
Uwe Hermanne4870472010-11-04 23:23:47 +00001433 /* Maximum sane devfn is 0xFF. */
Juhana Helovuo50b78b62010-09-13 14:43:02 +00001434 if (max_devfn > 0xff) {
Elyes HAOUASf984aec2021-01-16 17:29:17 +01001435 printk(BIOS_ERR, "PCI: %s limits devfn %x - devfn %x\n",
1436 __func__, min_devfn, max_devfn);
1437 printk(BIOS_ERR, "PCI: %s upper limit too big. Using 0xff.\n", __func__);
Juhana Helovuo50b78b62010-09-13 14:43:02 +00001438 max_devfn=0xff;
1439 }
1440
lilacious40cb3fe2023-06-21 23:24:14 +02001441 post_code(POSTCODE_ENTER_PCI_SCAN_BUS);
Uwe Hermanne4870472010-11-04 23:23:47 +00001442
Jianjun Wang777ffff2021-07-24 14:50:36 +08001443 if (pci_bus_only_one_child(bus))
1444 max_devfn = MIN(max_devfn, 0x07);
1445
Uwe Hermanne4870472010-11-04 23:23:47 +00001446 /*
1447 * Probe all devices/functions on this bus with some optimization for
Myles Watson29cc9ed2009-07-02 18:56:24 +00001448 * non-existence and single function devices.
Eric Biedermanb78c1972004-10-14 20:54:17 +00001449 */
Eric Biedermane9a271e32003-09-02 03:36:25 +00001450 for (devfn = min_devfn; devfn <= max_devfn; devfn++) {
Ronald G. Minnich466ca2c2019-10-22 02:02:24 +00001451 if (CONFIG(MINIMAL_PCI_SCANNING)) {
1452 dev = pcidev_path_behind(bus, devfn);
1453 if (!dev || !dev->mandatory)
1454 continue;
1455 }
1456
Uwe Hermanne4870472010-11-04 23:23:47 +00001457 /* First thing setup the device structure. */
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001458 dev = pci_scan_get_dev(bus, devfn);
Li-Ta Lo9782f752004-05-05 21:15:42 +00001459
Tim Wawrzynczakdbcf7b12020-05-13 16:15:08 -06001460 /* Devices marked 'hidden' do not get probed */
1461 if (dev && dev->hidden) {
1462 pci_scan_hidden_device(dev);
1463
1464 /* Skip pci_probe_dev, go to next devfn */
1465 continue;
1466 }
1467
Myles Watson29cc9ed2009-07-02 18:56:24 +00001468 /* See if a device is present and setup the device structure. */
Myles Watson032a9652009-05-11 22:24:53 +00001469 dev = pci_probe_dev(dev, bus, devfn);
Eric Biederman03acab62004-10-14 21:25:53 +00001470
Uwe Hermanne4870472010-11-04 23:23:47 +00001471 /*
1472 * If this is not a multi function device, or the device is
Myles Watson29cc9ed2009-07-02 18:56:24 +00001473 * not present don't waste time probing another function.
Myles Watson032a9652009-05-11 22:24:53 +00001474 * Skip to next device.
Eric Biederman8ca8d762003-04-22 19:02:15 +00001475 */
Uwe Hermanne4870472010-11-04 23:23:47 +00001476 if ((PCI_FUNC(devfn) == 0x00) && (!dev
Myles Watson29cc9ed2009-07-02 18:56:24 +00001477 || (dev->enabled && ((dev->hdr_type & 0x80) != 0x80)))) {
Eric Biederman8ca8d762003-04-22 19:02:15 +00001478 devfn += 0x07;
1479 }
1480 }
Uwe Hermanne4870472010-11-04 23:23:47 +00001481
Uwe Hermanne4870472010-11-04 23:23:47 +00001482 /*
Elyes HAOUAS0ce74162021-01-16 14:43:49 +01001483 * Warn if any leftover static devices are found.
Uwe Hermanne4870472010-11-04 23:23:47 +00001484 * There's probably a problem in devicetree.cb.
Myles Watson29cc9ed2009-07-02 18:56:24 +00001485 */
Uwe Hermanne4870472010-11-04 23:23:47 +00001486
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001487 prev = &bus->children;
1488 for (dev = bus->children; dev; dev = dev->sibling) {
Duncan Lauriebf696222020-10-18 15:10:00 -07001489
1490 /*
1491 * If static device is not PCI then enable it here and don't
1492 * treat it as a leftover device.
1493 */
1494 if (dev->path.type != DEVICE_PATH_PCI) {
1495 enable_static_device(dev);
1496 continue;
1497 }
1498
Tim Wawrzynczakdbcf7b12020-05-13 16:15:08 -06001499 /*
1500 * The device is only considered leftover if it is not hidden
1501 * and it has a Vendor ID of 0 (the default for a device that
1502 * could not be probed).
1503 */
1504 if (dev->vendor != 0 || dev->hidden) {
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001505 prev = &dev->sibling;
1506 continue;
1507 }
1508
1509 /* Unlink it from list. */
1510 *prev = dev->sibling;
1511
1512 if (!once++)
1513 printk(BIOS_WARNING, "PCI: Leftover static devices:\n");
1514 printk(BIOS_WARNING, "%s\n", dev_path(dev));
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001515 }
1516
Kyösti Mälkki8712aa12019-01-09 11:31:25 +02001517 if (once)
1518 printk(BIOS_WARNING, "PCI: Check your devicetree.cb.\n");
1519
Uwe Hermanne4870472010-11-04 23:23:47 +00001520 /*
1521 * For all children that implement scan_bus() (i.e. bridges)
Eric Biedermanb78c1972004-10-14 20:54:17 +00001522 * scan the bus behind that child.
1523 */
Kyösti Mälkkide271a82015-03-18 13:09:47 +02001524
Kyösti Mälkki2d2367c2015-02-20 21:28:31 +02001525 scan_bridges(bus);
Kyösti Mälkkide271a82015-03-18 13:09:47 +02001526
Uwe Hermanne4870472010-11-04 23:23:47 +00001527 /*
1528 * We've scanned the bus and so we know all about what's on the other
Myles Watson29cc9ed2009-07-02 18:56:24 +00001529 * side of any bridges that may be on this bus plus any devices.
Eric Biederman8ca8d762003-04-22 19:02:15 +00001530 * Return how far we've got finding sub-buses.
1531 */
lilacious40cb3fe2023-06-21 23:24:14 +02001532 post_code(POSTCODE_EXIT_PCI_SCAN_BUS);
Eric Biederman8ca8d762003-04-22 19:02:15 +00001533}
1534
Kyösti Mälkki33452402015-02-23 06:58:26 +02001535typedef enum {
1536 PCI_ROUTE_CLOSE,
1537 PCI_ROUTE_SCAN,
1538 PCI_ROUTE_FINAL,
1539} scan_state;
1540
1541static void pci_bridge_route(struct bus *link, scan_state state)
1542{
1543 struct device *dev = link->dev;
1544 struct bus *parent = dev->bus;
Arthur Heymansf879d362021-11-10 22:09:58 +01001545 uint8_t primary, secondary, subordinate;
Kyösti Mälkki33452402015-02-23 06:58:26 +02001546
Kyösti Mälkki757c8b42015-02-23 06:58:26 +02001547 if (state == PCI_ROUTE_SCAN) {
1548 link->secondary = parent->subordinate + 1;
Jeremy Sollercf2ac542019-10-09 21:40:36 -06001549 link->subordinate = link->secondary + dev->hotplug_buses;
Arthur Heymans20d25772021-11-17 17:25:48 +01001550 link->max_subordinate = parent->max_subordinate
1551 ? parent->max_subordinate
1552 : (CONFIG_ECAM_MMCONF_BUS_NUMBER - 1);
1553 }
1554
1555 if (link->secondary > link->max_subordinate)
1556 die("%s: No more busses available!\n", __func__);
1557
1558 /* This ought to only happen with hotplug buses. */
1559 if (link->subordinate > link->max_subordinate) {
1560 printk(BIOS_WARNING, "%s: Limiting subordinate busses\n", __func__);
1561 link->subordinate = link->max_subordinate;
Kyösti Mälkki757c8b42015-02-23 06:58:26 +02001562 }
1563
Kyösti Mälkki33452402015-02-23 06:58:26 +02001564 if (state == PCI_ROUTE_CLOSE) {
Arthur Heymansf879d362021-11-10 22:09:58 +01001565 primary = 0;
1566 secondary = 0xff;
1567 subordinate = 0xfe;
Kyösti Mälkki33452402015-02-23 06:58:26 +02001568 } else if (state == PCI_ROUTE_SCAN) {
Arthur Heymansf879d362021-11-10 22:09:58 +01001569 primary = parent->secondary;
1570 secondary = link->secondary;
Arthur Heymans20d25772021-11-17 17:25:48 +01001571 subordinate = link->max_subordinate;
Kyösti Mälkki33452402015-02-23 06:58:26 +02001572 } else if (state == PCI_ROUTE_FINAL) {
Arthur Heymansf879d362021-11-10 22:09:58 +01001573 primary = parent->secondary;
1574 secondary = link->secondary;
1575 subordinate = link->subordinate;
Arthur Heymans4a3331d2022-03-23 17:58:46 +01001576 } else {
1577 return;
Kyösti Mälkki33452402015-02-23 06:58:26 +02001578 }
1579
1580 if (state == PCI_ROUTE_SCAN) {
1581 /* Clear all status bits and turn off memory, I/O and master enables. */
1582 link->bridge_cmd = pci_read_config16(dev, PCI_COMMAND);
1583 pci_write_config16(dev, PCI_COMMAND, 0x0000);
1584 pci_write_config16(dev, PCI_STATUS, 0xffff);
1585 }
1586
1587 /*
1588 * Configure the bus numbers for this bridge: the configuration
1589 * transactions will not be propagated by the bridge if it is not
1590 * correctly configured.
1591 */
Arthur Heymansf879d362021-11-10 22:09:58 +01001592 pci_write_config8(dev, PCI_PRIMARY_BUS, primary);
1593 pci_write_config8(dev, PCI_SECONDARY_BUS, secondary);
1594 pci_write_config8(dev, PCI_SUBORDINATE_BUS, subordinate);
Kyösti Mälkki33452402015-02-23 06:58:26 +02001595
1596 if (state == PCI_ROUTE_FINAL) {
1597 pci_write_config16(dev, PCI_COMMAND, link->bridge_cmd);
Kyösti Mälkki757c8b42015-02-23 06:58:26 +02001598 parent->subordinate = link->subordinate;
Kyösti Mälkki33452402015-02-23 06:58:26 +02001599 }
1600}
1601
Li-Ta Loe5266692004-03-23 21:28:05 +00001602/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001603 * Scan a PCI bridge and the buses behind the bridge.
Li-Ta Loe5266692004-03-23 21:28:05 +00001604 *
1605 * Determine the existence of buses behind the bridge. Set up the bridge
1606 * according to the result of the scan.
1607 *
1608 * This function is the default scan_bus() method for PCI bridge devices.
1609 *
Myles Watson29cc9ed2009-07-02 18:56:24 +00001610 * @param dev Pointer to the bridge device.
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001611 * @param do_scan_bus TODO
Eric Biederman8ca8d762003-04-22 19:02:15 +00001612 */
Kyösti Mälkki580e7222015-03-19 21:04:23 +02001613void do_pci_scan_bridge(struct device *dev,
Kyösti Mälkkide271a82015-03-18 13:09:47 +02001614 void (*do_scan_bus) (struct bus * bus,
Martin Roth38ddbfb2019-10-23 21:41:00 -06001615 unsigned int min_devfn,
1616 unsigned int max_devfn))
Eric Biederman8ca8d762003-04-22 19:02:15 +00001617{
Eric Biedermane9a271e32003-09-02 03:36:25 +00001618 struct bus *bus;
Eric Biederman83b991a2003-10-11 06:20:25 +00001619
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +00001620 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(dev));
Li-Ta Lo3a812852004-12-03 22:39:34 +00001621
Myles Watson894a3472010-06-09 22:41:35 +00001622 if (dev->link_list == NULL) {
1623 struct bus *link;
1624 link = malloc(sizeof(*link));
1625 if (link == NULL)
1626 die("Couldn't allocate a link!\n");
1627 memset(link, 0, sizeof(*link));
1628 link->dev = dev;
1629 dev->link_list = link;
1630 }
1631
1632 bus = dev->link_list;
Eric Biedermane9a271e32003-09-02 03:36:25 +00001633
Nico Huber061b9052019-09-21 15:58:23 +02001634 pci_bridge_vga_compat(bus);
1635
Kyösti Mälkki33452402015-02-23 06:58:26 +02001636 pci_bridge_route(bus, PCI_ROUTE_SCAN);
Li-Ta Lo3a812852004-12-03 22:39:34 +00001637
Kyösti Mälkkide271a82015-03-18 13:09:47 +02001638 do_scan_bus(bus, 0x00, 0xff);
Kyösti Mälkki33452402015-02-23 06:58:26 +02001639
1640 pci_bridge_route(bus, PCI_ROUTE_FINAL);
Eric Biederman8ca8d762003-04-22 19:02:15 +00001641}
Li-Ta Loe5266692004-03-23 21:28:05 +00001642
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001643/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001644 * Scan a PCI bridge and the buses behind the bridge.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001645 *
1646 * Determine the existence of buses behind the bridge. Set up the bridge
1647 * according to the result of the scan.
1648 *
1649 * This function is the default scan_bus() method for PCI bridge devices.
1650 *
Myles Watson29cc9ed2009-07-02 18:56:24 +00001651 * @param dev Pointer to the bridge device.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001652 */
Kyösti Mälkki580e7222015-03-19 21:04:23 +02001653void pci_scan_bridge(struct device *dev)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001654{
Kyösti Mälkki580e7222015-03-19 21:04:23 +02001655 do_pci_scan_bridge(dev, pci_scan_bus);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +00001656}
1657
Myles Watson29cc9ed2009-07-02 18:56:24 +00001658/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001659 * Scan a PCI domain.
Myles Watson29cc9ed2009-07-02 18:56:24 +00001660 *
1661 * This function is the default scan_bus() method for PCI domains.
1662 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001663 * @param dev Pointer to the domain.
Myles Watson29cc9ed2009-07-02 18:56:24 +00001664 */
Aaron Durbinc30d9132017-08-07 16:55:43 -06001665void pci_domain_scan_bus(struct device *dev)
Myles Watson29cc9ed2009-07-02 18:56:24 +00001666{
Kyösti Mälkki6f370172015-03-19 15:26:52 +02001667 struct bus *link = dev->link_list;
Kyösti Mälkkide271a82015-03-18 13:09:47 +02001668 pci_scan_bus(link, PCI_DEVFN(0, 0), 0xff);
Myles Watson29cc9ed2009-07-02 18:56:24 +00001669}
1670
Angel Ponsb6519812021-12-31 13:33:50 +01001671void pci_dev_disable_bus_master(const struct device *dev)
1672{
1673 pci_update_config16(dev, PCI_COMMAND, ~PCI_COMMAND_MASTER, 0x0);
1674}
1675
Mike Loptien0f5cf5e2014-05-12 21:46:31 -06001676/**
1677 * Take an INT_PIN number (0, 1 - 4) and convert
1678 * it to a string ("NO PIN", "PIN A" - "PIN D")
1679 *
1680 * @param pin PCI Interrupt Pin number (0, 1 - 4)
1681 * @return A string corresponding to the pin number or "Invalid"
1682 */
1683const char *pin_to_str(int pin)
1684{
1685 const char *str[5] = {
1686 "NO PIN",
1687 "PIN A",
1688 "PIN B",
1689 "PIN C",
1690 "PIN D",
1691 };
1692
1693 if (pin >= 0 && pin <= 4)
1694 return str[pin];
1695 else
1696 return "Invalid PIN, not 0 - 4";
1697}
1698
1699/**
1700 * Get the PCI INT_PIN swizzle for a device defined as:
1701 * pin_parent = (pin_child + devn_child) % 4 + 1
1702 * where PIN A = 1 ... PIN_D = 4
1703 *
1704 * Given a PCI device structure 'dev', find the interrupt pin
1705 * that will be triggered on its parent bridge device when
1706 * generating an interrupt. For example: Device 1:3.2 may
1707 * use INT_PIN A but will trigger PIN D on its parent bridge
1708 * device. In this case, this function will return 4 (PIN D).
1709 *
1710 * @param dev A PCI device structure to swizzle interrupt pins for
Martin Roth32bc6b62015-01-04 16:54:35 -07001711 * @param *parent_bridge The PCI device structure for the bridge
Mike Loptien0f5cf5e2014-05-12 21:46:31 -06001712 * device 'dev' is attached to
1713 * @return The interrupt pin number (1 - 4) that 'dev' will
1714 * trigger when generating an interrupt
1715 */
Aaron Durbinc30d9132017-08-07 16:55:43 -06001716static int swizzle_irq_pins(struct device *dev, struct device **parent_bridge)
Mike Loptien0f5cf5e2014-05-12 21:46:31 -06001717{
Aaron Durbinc30d9132017-08-07 16:55:43 -06001718 struct device *parent; /* Our current device's parent device */
1719 struct device *child; /* The child device of the parent */
Mike Loptien0f5cf5e2014-05-12 21:46:31 -06001720 uint8_t parent_bus = 0; /* Parent Bus number */
1721 uint16_t parent_devfn = 0; /* Parent Device and Function number */
1722 uint16_t child_devfn = 0; /* Child Device and Function number */
1723 uint8_t swizzled_pin = 0; /* Pin swizzled across a bridge */
1724
1725 /* Start with PIN A = 0 ... D = 3 */
1726 swizzled_pin = pci_read_config8(dev, PCI_INTERRUPT_PIN) - 1;
1727
1728 /* While our current device has parent devices */
1729 child = dev;
1730 for (parent = child->bus->dev; parent; parent = parent->bus->dev) {
1731 parent_bus = parent->bus->secondary;
1732 parent_devfn = parent->path.pci.devfn;
1733 child_devfn = child->path.pci.devfn;
1734
1735 /* Swizzle the INT_PIN for any bridges not on root bus */
1736 swizzled_pin = (PCI_SLOT(child_devfn) + swizzled_pin) % 4;
1737 printk(BIOS_SPEW, "\tWith INT_PIN swizzled to %s\n"
1738 "\tAttached to bridge device %01X:%02Xh.%02Xh\n",
1739 pin_to_str(swizzled_pin + 1), parent_bus,
1740 PCI_SLOT(parent_devfn), PCI_FUNC(parent_devfn));
1741
1742 /* Continue until we find the root bus */
1743 if (parent_bus > 0) {
1744 /*
1745 * We will go on to the next parent so this parent
1746 * becomes the child
1747 */
1748 child = parent;
1749 continue;
1750 } else {
1751 /*
1752 * Found the root bridge device,
1753 * fill in the structure and exit
1754 */
1755 *parent_bridge = parent;
1756 break;
1757 }
1758 }
1759
1760 /* End with PIN A = 1 ... D = 4 */
1761 return swizzled_pin + 1;
1762}
1763
1764/**
1765 * Given a device structure 'dev', find its interrupt pin
1766 * and its parent bridge 'parent_bdg' device structure.
1767 * If it is behind a bridge, it will return the interrupt
1768 * pin number (1 - 4) of the parent bridge that the device
1769 * interrupt pin has been swizzled to, otherwise it will
1770 * return the interrupt pin that is programmed into the
1771 * PCI config space of the target device. If 'dev' is
1772 * behind a bridge, it will fill in 'parent_bdg' with the
1773 * device structure of the bridge it is behind, otherwise
1774 * it will copy 'dev' into 'parent_bdg'.
1775 *
1776 * @param dev A PCI device structure to get interrupt pins for.
1777 * @param *parent_bdg The PCI device structure for the bridge
1778 * device 'dev' is attached to.
1779 * @return The interrupt pin number (1 - 4) that 'dev' will
1780 * trigger when generating an interrupt.
1781 * Errors: -1 is returned if the device is not enabled
1782 * -2 is returned if a parent bridge could not be found.
1783 */
Aaron Durbinc30d9132017-08-07 16:55:43 -06001784int get_pci_irq_pins(struct device *dev, struct device **parent_bdg)
Mike Loptien0f5cf5e2014-05-12 21:46:31 -06001785{
1786 uint8_t bus = 0; /* The bus this device is on */
1787 uint16_t devfn = 0; /* This device's device and function numbers */
1788 uint8_t int_pin = 0; /* Interrupt pin used by the device */
1789 uint8_t target_pin = 0; /* Interrupt pin we want to assign an IRQ to */
1790
1791 /* Make sure this device is enabled */
1792 if (!(dev->enabled && (dev->path.type == DEVICE_PATH_PCI)))
1793 return -1;
1794
1795 bus = dev->bus->secondary;
1796 devfn = dev->path.pci.devfn;
1797
1798 /* Get and validate the interrupt pin used. Only 1-4 are allowed */
1799 int_pin = pci_read_config8(dev, PCI_INTERRUPT_PIN);
1800 if (int_pin < 1 || int_pin > 4)
1801 return -1;
1802
1803 printk(BIOS_SPEW, "PCI IRQ: Found device %01X:%02X.%02X using %s\n",
1804 bus, PCI_SLOT(devfn), PCI_FUNC(devfn), pin_to_str(int_pin));
1805
1806 /* If this device is on a bridge, swizzle its INT_PIN */
1807 if (bus) {
1808 /* Swizzle its INT_PINs */
1809 target_pin = swizzle_irq_pins(dev, parent_bdg);
1810
1811 /* Make sure the swizzle returned valid structures */
1812 if (parent_bdg == NULL) {
Julius Wernere9665952022-01-21 17:06:20 -08001813 printk(BIOS_WARNING, "Could not find parent bridge for this device!\n");
Mike Loptien0f5cf5e2014-05-12 21:46:31 -06001814 return -2;
1815 }
1816 } else { /* Device is not behind a bridge */
1817 target_pin = int_pin; /* Return its own interrupt pin */
1818 *parent_bdg = dev; /* Return its own structure */
1819 }
1820
1821 /* Target pin is the interrupt pin we want to assign an IRQ to */
1822 return target_pin;
1823}
1824
Julius Wernercd49cce2019-03-05 16:53:33 -08001825#if CONFIG(PC80_SYSTEM)
Myles Watson29cc9ed2009-07-02 18:56:24 +00001826/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001827 * Assign IRQ numbers.
Myles Watson29cc9ed2009-07-02 18:56:24 +00001828 *
Stefan Reinauer4d933dd2009-07-21 21:36:41 +00001829 * This function assigns IRQs for all functions contained within the indicated
Uwe Hermanne4870472010-11-04 23:23:47 +00001830 * device address. If the device does not exist or does not require interrupts
Stefan Reinauer4d933dd2009-07-21 21:36:41 +00001831 * then this function has no effect.
Myles Watson29cc9ed2009-07-02 18:56:24 +00001832 *
1833 * This function should be called for each PCI slot in your system.
1834 *
Kyösti Mälkkic19d6a62019-07-04 21:39:28 +03001835 * @param dev Pointer to dev structure.
Uwe Hermannc1ee4292010-10-17 19:01:48 +00001836 * @param pIntAtoD An array of IRQ #s that are assigned to PINTA through PINTD
1837 * of this slot. The particular IRQ #s that are passed in depend on the
1838 * routing inside your southbridge and on your board.
Stefan Reinauer4d933dd2009-07-21 21:36:41 +00001839 */
Kyösti Mälkkic19d6a62019-07-04 21:39:28 +03001840void pci_assign_irqs(struct device *dev, const unsigned char pIntAtoD[4])
Ronald G. Minnich6dd6c6852003-10-02 00:08:42 +00001841{
Kyösti Mälkkic19d6a62019-07-04 21:39:28 +03001842 u8 slot, line, irq;
Ronald G. Minnich6dd6c6852003-10-02 00:08:42 +00001843
Kyösti Mälkkic19d6a62019-07-04 21:39:28 +03001844 /* Each device may contain up to eight functions. */
1845 slot = dev->path.pci.devfn >> 3;
Ronald G. Minnich6dd6c6852003-10-02 00:08:42 +00001846
Kyösti Mälkkic19d6a62019-07-04 21:39:28 +03001847 for (; dev ; dev = dev->sibling) {
Ronald G. Minnich6dd6c6852003-10-02 00:08:42 +00001848
Kyösti Mälkkic19d6a62019-07-04 21:39:28 +03001849 if (dev->path.pci.devfn >> 3 != slot)
1850 break;
1851
1852 line = pci_read_config8(dev, PCI_INTERRUPT_PIN);
Ronald G. Minnich6dd6c6852003-10-02 00:08:42 +00001853
Uwe Hermanne4870472010-11-04 23:23:47 +00001854 /* PCI spec says all values except 1..4 are reserved. */
Stefan Reinauer4d933dd2009-07-21 21:36:41 +00001855 if ((line < 1) || (line > 4))
1856 continue;
Ronald G. Minnich6dd6c6852003-10-02 00:08:42 +00001857
Stefan Reinauer4d933dd2009-07-21 21:36:41 +00001858 irq = pIntAtoD[line - 1];
Ronald G. Minnich6dd6c6852003-10-02 00:08:42 +00001859
Kyösti Mälkkic19d6a62019-07-04 21:39:28 +03001860 printk(BIOS_DEBUG, "Assigning IRQ %d to %s\n", irq, dev_path(dev));
Ronald G. Minnich6dd6c6852003-10-02 00:08:42 +00001861
Angel Ponsceca5de2021-06-28 11:59:33 +02001862 pci_write_config8(dev, PCI_INTERRUPT_LINE, irq);
Stefan Reinauer4d933dd2009-07-21 21:36:41 +00001863
Uwe Hermanne4870472010-11-04 23:23:47 +00001864 /* Change to level triggered. */
Angel Ponsceca5de2021-06-28 11:59:33 +02001865 i8259_configure_irq_trigger(irq, IRQ_LEVEL_TRIGGERED);
Ronald G. Minnich6dd6c6852003-10-02 00:08:42 +00001866 }
1867}
Stefan Reinauer4d933dd2009-07-21 21:36:41 +00001868#endif