sb,soc/amd,intel: Add and use ACPI_COMMON_MADT_LAPIC

Boards with SOC_INTEL_COMMON_BLOCK_ACPI_CPU_HYBRID have
special handling for the time being.

Change of aopen/dxplplusu is coupled with sb/intel/i82801dx.
Change of emulation/qemu-i440fx is coupled with intel/i82371eb.

For asus/p2b, this adds MADT LAPIC entries, even though platform
has ACPI_NO_MADT selected. Even previously ACPI_NO_MADT creates
the MADT, including an entry for LAPIC address.

Change-Id: I1f8d7ee9891553742d73a92b55a87c04fa95a132
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/74316
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
diff --git a/src/acpi/Kconfig b/src/acpi/Kconfig
index ec7fcc4..5af8b22 100644
--- a/src/acpi/Kconfig
+++ b/src/acpi/Kconfig
@@ -31,6 +31,9 @@
 	  Set to indicate <soc/nvs.h> exists for the platform with a definition
 	  for global_nvs.
 
+config ACPI_COMMON_MADT_LAPIC
+	bool
+
 config ACPI_NO_MADT
 	bool
 	help
diff --git a/src/acpi/acpi.c b/src/acpi/acpi.c
index de5abe0..492d043 100644
--- a/src/acpi/acpi.c
+++ b/src/acpi/acpi.c
@@ -312,6 +312,9 @@
 	if (CONFIG(ACPI_HAVE_PCAT_8259))
 		madt->flags |= 1;
 
+	if (CONFIG(ACPI_COMMON_MADT_LAPIC))
+		current = acpi_create_madt_lapics_with_nmis(current);
+
 	if (!CONFIG(ACPI_NO_MADT))
 		current = acpi_fill_madt(current);
 
diff --git a/src/mainboard/aopen/dxplplusu/acpi_tables.c b/src/mainboard/aopen/dxplplusu/acpi_tables.c
index 13ddb3e..ba9d3c8 100644
--- a/src/mainboard/aopen/dxplplusu/acpi_tables.c
+++ b/src/mainboard/aopen/dxplplusu/acpi_tables.c
@@ -8,8 +8,6 @@
 	struct device *bdev, *dev = NULL;
 	struct resource *res = NULL;
 
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	/* Southbridge IOAPIC */
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, 0xfec00000);
 
diff --git a/src/mainboard/emulation/qemu-i440fx/acpi_tables.c b/src/mainboard/emulation/qemu-i440fx/acpi_tables.c
index e6262d1..593cbc7 100644
--- a/src/mainboard/emulation/qemu-i440fx/acpi_tables.c
+++ b/src/mainboard/emulation/qemu-i440fx/acpi_tables.c
@@ -10,9 +10,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* Local APICs */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	/* IOAPIC */
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
diff --git a/src/northbridge/amd/pi/00730F01/acpi_tables.c b/src/northbridge/amd/pi/00730F01/acpi_tables.c
index ef240c1..e139639 100644
--- a/src/northbridge/amd/pi/00730F01/acpi_tables.c
+++ b/src/northbridge/amd/pi/00730F01/acpi_tables.c
@@ -6,9 +6,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* create all subtables for processors */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	/* Write SB800 IOAPIC, only one */
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
diff --git a/src/soc/amd/cezanne/acpi.c b/src/soc/amd/cezanne/acpi.c
index b8ac827..08effca 100644
--- a/src/soc/amd/cezanne/acpi.c
+++ b/src/soc/amd/cezanne/acpi.c
@@ -21,9 +21,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* create all subtables for processors */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current,
diff --git a/src/soc/amd/common/block/acpi/Kconfig b/src/soc/amd/common/block/acpi/Kconfig
index fd62ad6..289efbc 100644
--- a/src/soc/amd/common/block/acpi/Kconfig
+++ b/src/soc/amd/common/block/acpi/Kconfig
@@ -2,6 +2,7 @@
 	bool
 	depends on SOC_AMD_COMMON_BLOCK_ACPIMMIO
 	select ACPI_AMD_HARDWARE_SLEEP_VALUES
+	select ACPI_COMMON_MADT_LAPIC
 	help
 	  Select this option to use the AcpiMmio ACPI registers.
 
diff --git a/src/soc/amd/glinda/acpi.c b/src/soc/amd/glinda/acpi.c
index 49fb658..cb8039d 100644
--- a/src/soc/amd/glinda/acpi.c
+++ b/src/soc/amd/glinda/acpi.c
@@ -24,9 +24,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* create all subtables for processors */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current,
diff --git a/src/soc/amd/mendocino/acpi.c b/src/soc/amd/mendocino/acpi.c
index 83b24ec..17d8955 100644
--- a/src/soc/amd/mendocino/acpi.c
+++ b/src/soc/amd/mendocino/acpi.c
@@ -23,9 +23,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* create all subtables for processors */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current,
diff --git a/src/soc/amd/phoenix/acpi.c b/src/soc/amd/phoenix/acpi.c
index 8e90d44..5e37a27 100644
--- a/src/soc/amd/phoenix/acpi.c
+++ b/src/soc/amd/phoenix/acpi.c
@@ -24,9 +24,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* create all subtables for processors */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current,
diff --git a/src/soc/amd/picasso/acpi.c b/src/soc/amd/picasso/acpi.c
index a6f1ebd..227a5d8 100644
--- a/src/soc/amd/picasso/acpi.c
+++ b/src/soc/amd/picasso/acpi.c
@@ -28,9 +28,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* create all subtables for processors */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current,
diff --git a/src/soc/amd/stoneyridge/acpi.c b/src/soc/amd/stoneyridge/acpi.c
index caa6496..947c806 100644
--- a/src/soc/amd/stoneyridge/acpi.c
+++ b/src/soc/amd/stoneyridge/acpi.c
@@ -26,9 +26,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* create all subtables for processors */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	/* Write Kern IOAPIC, only one */
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
diff --git a/src/soc/intel/baytrail/Kconfig b/src/soc/intel/baytrail/Kconfig
index 5ecfe3e..0f908b6 100644
--- a/src/soc/intel/baytrail/Kconfig
+++ b/src/soc/intel/baytrail/Kconfig
@@ -7,6 +7,7 @@
 
 config CPU_SPECIFIC_OPTIONS
 	def_bool y
+	select ACPI_COMMON_MADT_LAPIC
 	select ACPI_INTEL_HARDWARE_SLEEP_VALUES
 	select ARCH_X86
 	select BOOT_DEVICE_SPI_FLASH_NO_EARLY_WRITES
diff --git a/src/soc/intel/baytrail/acpi.c b/src/soc/intel/baytrail/acpi.c
index 42e4b26..77bdcc9 100644
--- a/src/soc/intel/baytrail/acpi.c
+++ b/src/soc/intel/baytrail/acpi.c
@@ -87,9 +87,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* Local APICs */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	/* IOAPIC */
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
diff --git a/src/soc/intel/braswell/Kconfig b/src/soc/intel/braswell/Kconfig
index 4d3d4df..8d540f3 100644
--- a/src/soc/intel/braswell/Kconfig
+++ b/src/soc/intel/braswell/Kconfig
@@ -7,6 +7,7 @@
 
 config CPU_SPECIFIC_OPTIONS
 	def_bool y
+	select ACPI_COMMON_MADT_LAPIC
 	select ACPI_INTEL_HARDWARE_SLEEP_VALUES
 	select ARCH_X86
 	select BOOT_DEVICE_SUPPORTS_WRITES
diff --git a/src/soc/intel/braswell/acpi.c b/src/soc/intel/braswell/acpi.c
index 9ef7a75..308da12 100644
--- a/src/soc/intel/braswell/acpi.c
+++ b/src/soc/intel/braswell/acpi.c
@@ -328,9 +328,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* Local APICs */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	/* IOAPIC */
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
diff --git a/src/soc/intel/broadwell/pch/Kconfig b/src/soc/intel/broadwell/pch/Kconfig
index 5a80d32..63f0439 100644
--- a/src/soc/intel/broadwell/pch/Kconfig
+++ b/src/soc/intel/broadwell/pch/Kconfig
@@ -4,6 +4,7 @@
 
 config PCH_SPECIFIC_OPTIONS
 	def_bool y
+	select ACPI_COMMON_MADT_LAPIC
 	select ACPI_INTEL_HARDWARE_SLEEP_VALUES
 	select ACPI_SOC_NVS
 	select AZALIA_PLUGIN_SUPPORT
diff --git a/src/soc/intel/common/block/acpi/Kconfig b/src/soc/intel/common/block/acpi/Kconfig
index bf5fa56..8f4e308 100644
--- a/src/soc/intel/common/block/acpi/Kconfig
+++ b/src/soc/intel/common/block/acpi/Kconfig
@@ -1,6 +1,7 @@
 config SOC_INTEL_COMMON_BLOCK_ACPI
 	depends on SOC_INTEL_COMMON_BLOCK_CPU
 	depends on SOC_INTEL_COMMON_BLOCK_PMC
+	select ACPI_COMMON_MADT_LAPIC if !SOC_INTEL_COMMON_BLOCK_ACPI_CPU_HYBRID
 	bool
 	help
 	  Intel Processor common code for ACPI
diff --git a/src/soc/intel/common/block/acpi/acpi.c b/src/soc/intel/common/block/acpi/acpi.c
index 4139054..51649d0 100644
--- a/src/soc/intel/common/block/acpi/acpi.c
+++ b/src/soc/intel/common/block/acpi/acpi.c
@@ -87,11 +87,8 @@
 	size_t ioapic_entries;
 
 	/* Local APICs */
-
-	if (CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_CPU_HYBRID))
+	if (!CONFIG(ACPI_COMMON_MADT_LAPIC))
 		current = acpi_create_madt_lapics_with_nmis_hybrid(current);
-	else
-		current = acpi_create_madt_lapics_with_nmis(current);
 
 	/* IOAPIC */
 	ioapic_entries = soc_get_ioapic_info(&ioapic_table);
diff --git a/src/southbridge/amd/pi/hudson/Kconfig b/src/southbridge/amd/pi/hudson/Kconfig
index 53f7b3e..4b19431 100644
--- a/src/southbridge/amd/pi/hudson/Kconfig
+++ b/src/southbridge/amd/pi/hudson/Kconfig
@@ -10,6 +10,7 @@
 
 config SOUTHBRIDGE_SPECIFIC_OPTIONS
 	def_bool y
+	select ACPI_COMMON_MADT_LAPIC
 	select HAVE_USBDEBUG_OPTIONS
 	select HAVE_CF9_RESET
 	select HAVE_CF9_RESET_PREPARE
diff --git a/src/southbridge/intel/bd82x6x/Kconfig b/src/southbridge/intel/bd82x6x/Kconfig
index 7fee1f1..a0d8605 100644
--- a/src/southbridge/intel/bd82x6x/Kconfig
+++ b/src/southbridge/intel/bd82x6x/Kconfig
@@ -10,6 +10,7 @@
 
 config SOUTH_BRIDGE_OPTIONS
 	def_bool y
+	select ACPI_COMMON_MADT_LAPIC
 	select ACPI_INTEL_HARDWARE_SLEEP_VALUES
 	select ACPI_SOC_NVS
 	select AZALIA_PLUGIN_SUPPORT
diff --git a/src/southbridge/intel/common/madt.c b/src/southbridge/intel/common/madt.c
index b85e110..2482391 100644
--- a/src/southbridge/intel/common/madt.c
+++ b/src/southbridge/intel/common/madt.c
@@ -6,9 +6,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* Local APICs */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	/* IOAPIC */
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
diff --git a/src/southbridge/intel/i82371eb/Kconfig b/src/southbridge/intel/i82371eb/Kconfig
index 03e70a6..08ffb00 100644
--- a/src/southbridge/intel/i82371eb/Kconfig
+++ b/src/southbridge/intel/i82371eb/Kconfig
@@ -1,4 +1,5 @@
 config SOUTHBRIDGE_INTEL_I82371EB
+	select ACPI_COMMON_MADT_LAPIC
 	select ACPI_INTEL_HARDWARE_SLEEP_VALUES
 	select SOUTHBRIDGE_INTEL_COMMON_SMBUS
 	select SOUTHBRIDGE_INTEL_COMMON_RTC
diff --git a/src/southbridge/intel/i82801dx/Kconfig b/src/southbridge/intel/i82801dx/Kconfig
index 3916b41..2be911d 100644
--- a/src/southbridge/intel/i82801dx/Kconfig
+++ b/src/southbridge/intel/i82801dx/Kconfig
@@ -2,6 +2,7 @@
 
 config SOUTHBRIDGE_INTEL_I82801DX
 	bool
+	select ACPI_COMMON_MADT_LAPIC
 	select ACPI_INTEL_HARDWARE_SLEEP_VALUES
 	select HAVE_SMI_HANDLER
 	select SOUTHBRIDGE_INTEL_COMMON_SMBUS
diff --git a/src/southbridge/intel/i82801gx/Kconfig b/src/southbridge/intel/i82801gx/Kconfig
index b1b885b..330915f 100644
--- a/src/southbridge/intel/i82801gx/Kconfig
+++ b/src/southbridge/intel/i82801gx/Kconfig
@@ -2,6 +2,7 @@
 
 config SOUTHBRIDGE_INTEL_I82801GX
 	bool
+	select ACPI_COMMON_MADT_LAPIC
 	select ACPI_INTEL_HARDWARE_SLEEP_VALUES
 	select ACPI_SOC_NVS
 	select AZALIA_PLUGIN_SUPPORT
diff --git a/src/southbridge/intel/i82801gx/lpc.c b/src/southbridge/intel/i82801gx/lpc.c
index 69c1469..2871453 100644
--- a/src/southbridge/intel/i82801gx/lpc.c
+++ b/src/southbridge/intel/i82801gx/lpc.c
@@ -351,9 +351,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* Local APICs */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	/* IOAPIC */
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
diff --git a/src/southbridge/intel/i82801ix/Kconfig b/src/southbridge/intel/i82801ix/Kconfig
index 4d6b097..d93afa6 100644
--- a/src/southbridge/intel/i82801ix/Kconfig
+++ b/src/southbridge/intel/i82801ix/Kconfig
@@ -2,6 +2,7 @@
 
 config SOUTHBRIDGE_INTEL_I82801IX
 	bool
+	select ACPI_COMMON_MADT_LAPIC
 	select ACPI_INTEL_HARDWARE_SLEEP_VALUES
 	select ACPI_SOC_NVS
 	select AZALIA_PLUGIN_SUPPORT
diff --git a/src/southbridge/intel/i82801ix/madt.c b/src/southbridge/intel/i82801ix/madt.c
index 009c9ea..1ac8149 100644
--- a/src/southbridge/intel/i82801ix/madt.c
+++ b/src/southbridge/intel/i82801ix/madt.c
@@ -6,9 +6,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* Local APICs */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	/* IOAPIC */
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
diff --git a/src/southbridge/intel/i82801jx/Kconfig b/src/southbridge/intel/i82801jx/Kconfig
index b189852..62684ec 100644
--- a/src/southbridge/intel/i82801jx/Kconfig
+++ b/src/southbridge/intel/i82801jx/Kconfig
@@ -2,6 +2,7 @@
 
 config SOUTHBRIDGE_INTEL_I82801JX
 	bool
+	select ACPI_COMMON_MADT_LAPIC
 	select ACPI_INTEL_HARDWARE_SLEEP_VALUES
 	select AZALIA_PLUGIN_SUPPORT
 	select HAVE_POWER_STATE_AFTER_FAILURE
diff --git a/src/southbridge/intel/i82801jx/lpc.c b/src/southbridge/intel/i82801jx/lpc.c
index ead2b8a..8ff7926 100644
--- a/src/southbridge/intel/i82801jx/lpc.c
+++ b/src/southbridge/intel/i82801jx/lpc.c
@@ -381,9 +381,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* Local APICs */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	/* IOAPIC */
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
diff --git a/src/southbridge/intel/ibexpeak/Kconfig b/src/southbridge/intel/ibexpeak/Kconfig
index fd5e322..ffeef5d 100644
--- a/src/southbridge/intel/ibexpeak/Kconfig
+++ b/src/southbridge/intel/ibexpeak/Kconfig
@@ -7,6 +7,7 @@
 
 config SOUTH_BRIDGE_OPTIONS
 	def_bool y
+	select ACPI_COMMON_MADT_LAPIC
 	select ACPI_INTEL_HARDWARE_SLEEP_VALUES
 	select AZALIA_PLUGIN_SUPPORT
 	select HAVE_SMI_HANDLER
diff --git a/src/southbridge/intel/ibexpeak/madt.c b/src/southbridge/intel/ibexpeak/madt.c
index 26b1630..c5b1f0b 100644
--- a/src/southbridge/intel/ibexpeak/madt.c
+++ b/src/southbridge/intel/ibexpeak/madt.c
@@ -8,9 +8,6 @@
 
 unsigned long acpi_fill_madt(unsigned long current)
 {
-	/* Local APICs */
-	current = acpi_create_madt_lapics_with_nmis(current);
-
 	/* IOAPIC */
 	current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
 
diff --git a/src/southbridge/intel/lynxpoint/Kconfig b/src/southbridge/intel/lynxpoint/Kconfig
index 6305812..9cea74b 100644
--- a/src/southbridge/intel/lynxpoint/Kconfig
+++ b/src/southbridge/intel/lynxpoint/Kconfig
@@ -7,6 +7,7 @@
 
 config SOUTH_BRIDGE_OPTIONS
 	def_bool y
+	select ACPI_COMMON_MADT_LAPIC
 	select ACPI_INTEL_HARDWARE_SLEEP_VALUES
 	select ACPI_SOC_NVS
 	select AZALIA_PLUGIN_SUPPORT