Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Martin Roth | ebace9f | 2018-05-26 18:56:17 -0600 | [diff] [blame] | 2 | |
Kyösti Mälkki | 5c2594e | 2021-06-08 10:47:24 +0300 | [diff] [blame] | 3 | #include <arch/ioapic.h> |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 4 | #include <device/device.h> |
| 5 | #include <device/pci.h> |
| 6 | #include <device/pci_ids.h> |
| 7 | #include <device/pci_ops.h> |
Steven J. Magnani | 09e4ef6 | 2005-09-14 13:56:25 +0000 | [diff] [blame] | 8 | #include <assert.h> |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 9 | #include "82870.h" |
| 10 | |
Steven J. Magnani | 09e4ef6 | 2005-09-14 13:56:25 +0000 | [diff] [blame] | 11 | static int num_p64h2_ioapics = 0; |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 12 | |
Elyes HAOUAS | 17c59f5 | 2018-05-13 13:38:38 +0200 | [diff] [blame] | 13 | static void p64h2_ioapic_enable(struct device *dev) |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 14 | { |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 15 | /* We have to enable MEM and Bus Master for IOAPIC */ |
| 16 | uint16_t command = PCI_COMMAND_SERR | PCI_COMMAND_PARITY | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 17 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 18 | pci_write_config16(dev, PCI_COMMAND, command); |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Uwe Hermann | b69cb5a | 2010-10-26 22:46:43 +0000 | [diff] [blame] | 21 | /** |
| 22 | * Configure one of the IOAPICs in a P64H2. |
| 23 | * |
| 24 | * Note that a PCI bus scan will detect both IOAPICs, so this function |
| 25 | * will be called twice for each P64H2 in the system. |
| 26 | * |
| 27 | * @param dev PCI bus/device/function of P64H2 IOAPIC. |
| 28 | * NOTE: There are two IOAPICs per P64H2, at D28:F0 and D30:F0. |
| 29 | */ |
Elyes HAOUAS | 17c59f5 | 2018-05-13 13:38:38 +0200 | [diff] [blame] | 30 | static void p64h2_ioapic_init(struct device *dev) |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 31 | { |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 32 | uint32_t memoryBase; |
| 33 | int apic_index, apic_id; |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 34 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 35 | apic_index = num_p64h2_ioapics; |
| 36 | num_p64h2_ioapics++; |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 37 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 38 | // A note on IOAPIC addresses: |
| 39 | // 0 and 1 are used for the local APICs of the dual virtual |
| 40 | // (hyper-threaded) CPUs of physical CPU 0 (devicetree.cb). |
| 41 | // 6 and 7 are used for the local APICs of the dual virtual |
| 42 | // (hyper-threaded) CPUs of physical CPU 1 (devicetree.cb). |
| 43 | // 2 is used for the IOAPIC in the 82801 southbridge (hard-coded in i82801xx_lpc.c) |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 44 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 45 | // Map APIC index into APIC ID |
| 46 | // IDs 3, 4, 5, and 8+ are available (see above note) |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 47 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 48 | if (apic_index < 3) |
| 49 | apic_id = apic_index + 3; |
| 50 | else |
| 51 | apic_id = apic_index + 5; |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 52 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 53 | ASSERT(apic_id < 16); // ID is only 4 bits |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 54 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 55 | // Read the MBAR address for setting up the IOAPIC in memory space |
| 56 | // NOTE: this address was assigned during enumeration of the bus |
Steven J. Magnani | 09e4ef6 | 2005-09-14 13:56:25 +0000 | [diff] [blame] | 57 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 58 | memoryBase = pci_read_config32(dev, PCI_BASE_ADDRESS_0); |
Steven J. Magnani | 09e4ef6 | 2005-09-14 13:56:25 +0000 | [diff] [blame] | 59 | |
Kyösti Mälkki | 5c2594e | 2021-06-08 10:47:24 +0300 | [diff] [blame] | 60 | set_ioapic_id((void *)memoryBase, apic_id); |
Steven J. Magnani | 09e4ef6 | 2005-09-14 13:56:25 +0000 | [diff] [blame] | 61 | |
Kyösti Mälkki | 5c2594e | 2021-06-08 10:47:24 +0300 | [diff] [blame] | 62 | // Use Processor System Bus to deliver interrupts |
| 63 | ioapic_set_boot_config((void *)memoryBase, true); |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static struct device_operations ioapic_ops = { |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 67 | .read_resources = pci_dev_read_resources, |
| 68 | .set_resources = pci_dev_set_resources, |
| 69 | .enable_resources = pci_dev_enable_resources, |
| 70 | .init = p64h2_ioapic_init, |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 71 | .enable = p64h2_ioapic_enable, |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 74 | static const struct pci_driver ioapic_driver __pci_driver = { |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 75 | .ops = &ioapic_ops, |
| 76 | .vendor = PCI_VENDOR_ID_INTEL, |
| 77 | .device = PCI_DEVICE_ID_INTEL_82870_1E0, |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 78 | |
| 79 | }; |