Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 630b3aff authored by Lukas Wunner's avatar Lukas Wunner Committed by Rafael J. Wysocki
Browse files

treewide: Consolidate Apple DMI checks



We're about to amend ACPI bus scan with DMI checks whether we're running
on a Mac to support Apple device properties in AML.  The DMI checks are
performed for every single device, adding overhead for everything x86
that isn't Apple, which is the majority.  Rafael and Andy therefore
request to perform the DMI match only once and cache the result.

Outside of ACPI various other Apple DMI checks exist and it seems
reasonable to use the cached value there as well.  Rafael, Andy and
Darren suggest performing the DMI check in arch code and making it
available with a header in include/linux/platform_data/x86/.

To this end, add early_platform_quirks() to arch/x86/kernel/quirks.c
to perform the DMI check and invoke it from setup_arch().  Switch over
all existing Apple DMI checks, thereby fixing two deficiencies:

* They are now #defined to false on non-x86 arches and can thus be
  optimized away if they're located in cross-arch code.

* Some of them only match "Apple Inc." but not "Apple Computer, Inc.",
  which is used by BIOSes released between January 2006 (when the first
  x86 Macs started shipping) and January 2007 (when the company name
  changed upon introduction of the iPhone).

Suggested-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Suggested-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Suggested-by: default avatarDarren Hart <dvhart@infradead.org>
Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
Acked-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 16f73eb0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ static inline void vsmp_init(void) { }
#endif

void setup_bios_corruption_check(void);
void early_platform_quirks(void);

extern unsigned long saved_video_mode;

+2 −2
Original line number Diff line number Diff line
@@ -12,10 +12,10 @@
#include <linux/pci.h>
#include <linux/acpi.h>
#include <linux/delay.h>
#include <linux/dmi.h>
#include <linux/pci_ids.h>
#include <linux/bcma/bcma.h>
#include <linux/bcma/bcma_regs.h>
#include <linux/platform_data/x86/apple.h>
#include <drm/i915_drm.h>
#include <asm/pci-direct.h>
#include <asm/dma.h>
@@ -593,7 +593,7 @@ static void __init apple_airport_reset(int bus, int slot, int func)
	u64 addr;
	int i;

	if (!dmi_match(DMI_SYS_VENDOR, "Apple Inc."))
	if (!x86_apple_machine)
		return;

	/* Card may have been put into PCI_D3hot by grub quirk */
+10 −0
Original line number Diff line number Diff line
/*
 * This file contains work-arounds for x86 and x86_64 platform bugs.
 */
#include <linux/dmi.h>
#include <linux/pci.h>
#include <linux/irq.h>

@@ -656,3 +657,12 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6fc0, quirk_intel_brickland_xeon_
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_ras_cap);
#endif
#endif

bool x86_apple_machine;
EXPORT_SYMBOL(x86_apple_machine);

void __init early_platform_quirks(void)
{
	x86_apple_machine = dmi_match(DMI_SYS_VENDOR, "Apple Inc.") ||
			    dmi_match(DMI_SYS_VENDOR, "Apple Computer, Inc.");
}
+2 −0
Original line number Diff line number Diff line
@@ -1206,6 +1206,8 @@ void __init setup_arch(char **cmdline_p)

	io_delay_init();

	early_platform_quirks();

	/*
	 * Parse the ACPI tables for possible boot-time SMP configuration.
	 */
+8 −29
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <linux/kernel.h>
#include <linux/acpi.h>
#include <linux/dmi.h>
#include <linux/platform_data/x86/apple.h>

#include "internal.h"

@@ -257,12 +258,11 @@ bool acpi_osi_is_win8(void)
}
EXPORT_SYMBOL(acpi_osi_is_win8);

static void __init acpi_osi_dmi_darwin(bool enable,
				       const struct dmi_system_id *d)
static void __init acpi_osi_dmi_darwin(void)
{
	pr_notice("DMI detected to setup _OSI(\"Darwin\"): %s\n", d->ident);
	pr_notice("DMI detected to setup _OSI(\"Darwin\"): Apple hardware\n");
	osi_config.darwin_dmi = 1;
	__acpi_osi_setup_darwin(enable);
	__acpi_osi_setup_darwin(true);
}

static void __init acpi_osi_dmi_linux(bool enable,
@@ -273,13 +273,6 @@ static void __init acpi_osi_dmi_linux(bool enable,
	__acpi_osi_setup_linux(enable);
}

static int __init dmi_enable_osi_darwin(const struct dmi_system_id *d)
{
	acpi_osi_dmi_darwin(true, d);

	return 0;
}

static int __init dmi_enable_osi_linux(const struct dmi_system_id *d)
{
	acpi_osi_dmi_linux(true, d);
@@ -481,30 +474,16 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
		     DMI_MATCH(DMI_PRODUCT_NAME, "1015PX"),
		},
	},

	/*
	 * Enable _OSI("Darwin") for all apple platforms.
	 */
	{
	.callback = dmi_enable_osi_darwin,
	.ident = "Apple hardware",
	.matches = {
		     DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
		},
	},
	{
	.callback = dmi_enable_osi_darwin,
	.ident = "Apple hardware",
	.matches = {
		     DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."),
		},
	},
	{}
};

static __init void acpi_osi_dmi_blacklisted(void)
{
	dmi_check_system(acpi_osi_dmi_table);

	/* Enable _OSI("Darwin") for Apple platforms. */
	if (x86_apple_machine)
		acpi_osi_dmi_darwin();
}

int __init early_acpi_osi_init(void)
Loading