Timothy Pearson | 4551b68 | 2015-11-24 14:12:08 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Advanced Micro Devices, Inc. |
| 5 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
Timothy Pearson | 4551b68 | 2015-11-24 14:12:08 -0600 | [diff] [blame] | 17 | #include <string.h> |
| 18 | #include <arch/acpi.h> |
| 19 | #include <arch/ioapic.h> |
| 20 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 21 | #include <device/pci_ops.h> |
Timothy Pearson | 4551b68 | 2015-11-24 14:12:08 -0600 | [diff] [blame] | 22 | #include <cpu/amd/amdfam10_sysconf.h> |
| 23 | |
Timothy Pearson | 4551b68 | 2015-11-24 14:12:08 -0600 | [diff] [blame] | 24 | unsigned long acpi_fill_madt(unsigned long current) |
| 25 | { |
Elyes HAOUAS | 02b05d1 | 2018-05-04 20:00:08 +0200 | [diff] [blame] | 26 | struct device *dev; |
Timothy Pearson | 4551b68 | 2015-11-24 14:12:08 -0600 | [diff] [blame] | 27 | u32 dword; |
Elyes HAOUAS | 6350a2e | 2016-09-16 20:49:38 +0200 | [diff] [blame] | 28 | u32 gsi_base = 0; |
Timothy Pearson | 4551b68 | 2015-11-24 14:12:08 -0600 | [diff] [blame] | 29 | uint32_t apicid_sp5100; |
| 30 | uint32_t apicid_sr5650; |
| 31 | /* create all subtables for processors */ |
| 32 | current = acpi_create_madt_lapics(current); |
| 33 | |
| 34 | if (IS_ENABLED(CONFIG_ENABLE_APIC_EXT_ID) && (CONFIG_APIC_ID_OFFSET > 0)) |
| 35 | apicid_sp5100 = 0x0; |
| 36 | else |
| 37 | apicid_sp5100 = 0x20; |
| 38 | apicid_sr5650 = apicid_sp5100 + 1; |
| 39 | |
| 40 | /* Write SB700 IOAPIC, only one */ |
| 41 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, apicid_sp5100, |
| 42 | IO_APIC_ADDR, gsi_base); |
| 43 | /* IOAPIC on rs5690 */ |
| 44 | gsi_base += 24; /* SB700 has 24 IOAPIC entries. */ |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 45 | dev = pcidev_on_root(0, 0); |
Timothy Pearson | 4551b68 | 2015-11-24 14:12:08 -0600 | [diff] [blame] | 46 | if (dev) { |
| 47 | pci_write_config32(dev, 0xF8, 0x1); |
| 48 | dword = pci_read_config32(dev, 0xFC) & 0xfffffff0; |
| 49 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, apicid_sr5650, |
| 50 | dword, gsi_base); |
| 51 | } |
| 52 | |
| 53 | /* bus, source, gsirq, flags */ |
| 54 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 55 | current, 0, 0, 2, 0); |
| 56 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 57 | current, 0, 9, 9, 0xf); |
| 58 | |
| 59 | /* create all subtables for processors */ |
| 60 | current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0xff, 0, 1); |
| 61 | /* 1: LINT1 connect to NMI */ |
| 62 | |
| 63 | return current; |
| 64 | } |
| 65 | |
Elyes HAOUAS | 95bca33 | 2018-07-08 12:38:11 +0200 | [diff] [blame] | 66 | unsigned long acpi_fill_ivrs_ioapic(acpi_ivrs_t *ivrs, unsigned long current) |
Timothy Pearson | 4551b68 | 2015-11-24 14:12:08 -0600 | [diff] [blame] | 67 | { |
| 68 | uint8_t *p; |
| 69 | |
| 70 | uint32_t apicid_sp5100; |
| 71 | uint32_t apicid_sr5650; |
| 72 | |
| 73 | if (IS_ENABLED(CONFIG_ENABLE_APIC_EXT_ID) && (CONFIG_APIC_ID_OFFSET > 0)) |
| 74 | apicid_sp5100 = 0x0; |
| 75 | else |
| 76 | apicid_sp5100 = 0x20; |
| 77 | apicid_sr5650 = apicid_sp5100 + 1; |
| 78 | |
| 79 | /* Describe NB IOAPIC */ |
| 80 | p = (uint8_t *)current; |
| 81 | p[0] = 0x48; /* Entry type */ |
| 82 | p[1] = 0; /* Device */ |
| 83 | p[2] = 0; /* Bus */ |
| 84 | p[3] = 0x0; /* Data */ |
| 85 | p[4] = apicid_sr5650; /* IOAPIC ID */ |
| 86 | p[5] = 0x1; /* Device 0 Function 1 */ |
| 87 | p[6] = 0x0; /* Northbridge bus */ |
| 88 | p[7] = 0x1; /* Variety */ |
| 89 | current += 8; |
| 90 | |
| 91 | /* Describe SB IOAPIC */ |
| 92 | p = (uint8_t *)current; |
| 93 | p[0] = 0x48; /* Entry type */ |
| 94 | p[1] = 0; /* Device */ |
| 95 | p[2] = 0; /* Bus */ |
| 96 | p[3] = 0xd7; /* Data */ |
| 97 | p[4] = apicid_sp5100; /* IOAPIC ID */ |
| 98 | p[5] = 0x14 << 3; /* Device 0x14 Function 0 */ |
| 99 | p[6] = 0x0; /* Southbridge bus */ |
| 100 | p[7] = 0x1; /* Variety */ |
| 101 | current += 8; |
| 102 | |
| 103 | return current; |
Martin Roth | bb9722b | 2016-07-28 16:32:56 -0600 | [diff] [blame] | 104 | } |