Skip to content

Commit 630b3af

Browse files
l1krafaeljw
authored andcommitted
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: Andy Shevchenko <[email protected]> Suggested-by: Rafael J. Wysocki <[email protected]> Suggested-by: Darren Hart <[email protected]> Signed-off-by: Lukas Wunner <[email protected]> Acked-by: Mika Westerberg <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 16f73eb commit 630b3af

File tree

12 files changed

+51
-72
lines changed

12 files changed

+51
-72
lines changed

arch/x86/include/asm/setup.h

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static inline void vsmp_init(void) { }
3939
#endif
4040

4141
void setup_bios_corruption_check(void);
42+
void early_platform_quirks(void);
4243

4344
extern unsigned long saved_video_mode;
4445

arch/x86/kernel/early-quirks.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
#include <linux/pci.h>
1313
#include <linux/acpi.h>
1414
#include <linux/delay.h>
15-
#include <linux/dmi.h>
1615
#include <linux/pci_ids.h>
1716
#include <linux/bcma/bcma.h>
1817
#include <linux/bcma/bcma_regs.h>
18+
#include <linux/platform_data/x86/apple.h>
1919
#include <drm/i915_drm.h>
2020
#include <asm/pci-direct.h>
2121
#include <asm/dma.h>
@@ -593,7 +593,7 @@ static void __init apple_airport_reset(int bus, int slot, int func)
593593
u64 addr;
594594
int i;
595595

596-
if (!dmi_match(DMI_SYS_VENDOR, "Apple Inc."))
596+
if (!x86_apple_machine)
597597
return;
598598

599599
/* Card may have been put into PCI_D3hot by grub quirk */

arch/x86/kernel/quirks.c

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* This file contains work-arounds for x86 and x86_64 platform bugs.
33
*/
4+
#include <linux/dmi.h>
45
#include <linux/pci.h>
56
#include <linux/irq.h>
67

@@ -656,3 +657,12 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6fc0, quirk_intel_brickland_xeon_
656657
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_ras_cap);
657658
#endif
658659
#endif
660+
661+
bool x86_apple_machine;
662+
EXPORT_SYMBOL(x86_apple_machine);
663+
664+
void __init early_platform_quirks(void)
665+
{
666+
x86_apple_machine = dmi_match(DMI_SYS_VENDOR, "Apple Inc.") ||
667+
dmi_match(DMI_SYS_VENDOR, "Apple Computer, Inc.");
668+
}

arch/x86/kernel/setup.c

+2
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,8 @@ void __init setup_arch(char **cmdline_p)
12061206

12071207
io_delay_init();
12081208

1209+
early_platform_quirks();
1210+
12091211
/*
12101212
* Parse the ACPI tables for possible boot-time SMP configuration.
12111213
*/

drivers/acpi/osi.c

+8-29
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/kernel.h>
2828
#include <linux/acpi.h>
2929
#include <linux/dmi.h>
30+
#include <linux/platform_data/x86/apple.h>
3031

3132
#include "internal.h"
3233

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

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

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

276-
static int __init dmi_enable_osi_darwin(const struct dmi_system_id *d)
277-
{
278-
acpi_osi_dmi_darwin(true, d);
279-
280-
return 0;
281-
}
282-
283276
static int __init dmi_enable_osi_linux(const struct dmi_system_id *d)
284277
{
285278
acpi_osi_dmi_linux(true, d);
@@ -481,30 +474,16 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
481474
DMI_MATCH(DMI_PRODUCT_NAME, "1015PX"),
482475
},
483476
},
484-
485-
/*
486-
* Enable _OSI("Darwin") for all apple platforms.
487-
*/
488-
{
489-
.callback = dmi_enable_osi_darwin,
490-
.ident = "Apple hardware",
491-
.matches = {
492-
DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
493-
},
494-
},
495-
{
496-
.callback = dmi_enable_osi_darwin,
497-
.ident = "Apple hardware",
498-
.matches = {
499-
DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."),
500-
},
501-
},
502477
{}
503478
};
504479

505480
static __init void acpi_osi_dmi_blacklisted(void)
506481
{
507482
dmi_check_system(acpi_osi_dmi_table);
483+
484+
/* Enable _OSI("Darwin") for Apple platforms. */
485+
if (x86_apple_machine)
486+
acpi_osi_dmi_darwin();
508487
}
509488

510489
int __init early_acpi_osi_init(void)

drivers/acpi/pci_root.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/acpi.h>
3434
#include <linux/slab.h>
3535
#include <linux/dmi.h>
36+
#include <linux/platform_data/x86/apple.h>
3637
#include <acpi/apei.h> /* for acpi_hest_init() */
3738

3839
#include "internal.h"
@@ -431,8 +432,7 @@ static void negotiate_os_control(struct acpi_pci_root *root, int *no_aspm)
431432
* been called successfully. We know the feature set supported by the
432433
* platform, so avoid calling _OSC at all
433434
*/
434-
435-
if (dmi_match(DMI_SYS_VENDOR, "Apple Inc.")) {
435+
if (x86_apple_machine) {
436436
root->osc_control_set = ~OSC_PCI_EXPRESS_PME_CONTROL;
437437
decode_osc_control(root, "OS assumes control of",
438438
root->osc_control_set);

drivers/acpi/sbs.c

+2-23
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <linux/jiffies.h>
3232
#include <linux/delay.h>
3333
#include <linux/power_supply.h>
34-
#include <linux/dmi.h>
34+
#include <linux/platform_data/x86/apple.h>
3535

3636
#include "sbshc.h"
3737
#include "battery.h"
@@ -58,8 +58,6 @@ static unsigned int cache_time = 1000;
5858
module_param(cache_time, uint, 0644);
5959
MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
6060

61-
static bool sbs_manager_broken;
62-
6361
#define MAX_SBS_BAT 4
6462
#define ACPI_SBS_BLOCK_MAX 32
6563

@@ -632,31 +630,12 @@ static void acpi_sbs_callback(void *context)
632630
}
633631
}
634632

635-
static int disable_sbs_manager(const struct dmi_system_id *d)
636-
{
637-
sbs_manager_broken = true;
638-
return 0;
639-
}
640-
641-
static struct dmi_system_id acpi_sbs_dmi_table[] = {
642-
{
643-
.callback = disable_sbs_manager,
644-
.ident = "Apple",
645-
.matches = {
646-
DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc.")
647-
},
648-
},
649-
{ },
650-
};
651-
652633
static int acpi_sbs_add(struct acpi_device *device)
653634
{
654635
struct acpi_sbs *sbs;
655636
int result = 0;
656637
int id;
657638

658-
dmi_check_system(acpi_sbs_dmi_table);
659-
660639
sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL);
661640
if (!sbs) {
662641
result = -ENOMEM;
@@ -677,7 +656,7 @@ static int acpi_sbs_add(struct acpi_device *device)
677656

678657
result = 0;
679658

680-
if (!sbs_manager_broken) {
659+
if (!x86_apple_machine) {
681660
result = acpi_manager_get_info(sbs);
682661
if (!result) {
683662
sbs->manager_present = 1;

drivers/firmware/efi/apple-properties.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#define pr_fmt(fmt) "apple-properties: " fmt
1919

2020
#include <linux/bootmem.h>
21-
#include <linux/dmi.h>
2221
#include <linux/efi.h>
22+
#include <linux/platform_data/x86/apple.h>
2323
#include <linux/property.h>
2424
#include <linux/slab.h>
2525
#include <linux/ucs2_string.h>
@@ -191,8 +191,7 @@ static int __init map_properties(void)
191191
u64 pa_data;
192192
int ret;
193193

194-
if (!dmi_match(DMI_SYS_VENDOR, "Apple Inc.") &&
195-
!dmi_match(DMI_SYS_VENDOR, "Apple Computer, Inc."))
194+
if (!x86_apple_machine)
196195
return 0;
197196

198197
pa_data = boot_params.hdr.setup_data;

drivers/pci/quirks.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/sched.h>
2626
#include <linux/ktime.h>
2727
#include <linux/mm.h>
28+
#include <linux/platform_data/x86/apple.h>
2829
#include <asm/dma.h> /* isa_dma_bridge_buggy */
2930
#include "pci.h"
3031

@@ -3447,7 +3448,7 @@ static void quirk_apple_poweroff_thunderbolt(struct pci_dev *dev)
34473448
{
34483449
acpi_handle bridge, SXIO, SXFP, SXLV;
34493450

3450-
if (!dmi_match(DMI_BOARD_VENDOR, "Apple Inc."))
3451+
if (!x86_apple_machine)
34513452
return;
34523453
if (pci_pcie_type(dev) != PCI_EXP_TYPE_UPSTREAM)
34533454
return;
@@ -3492,7 +3493,7 @@ static void quirk_apple_wait_for_thunderbolt(struct pci_dev *dev)
34923493
struct pci_dev *sibling = NULL;
34933494
struct pci_dev *nhi = NULL;
34943495

3495-
if (!dmi_match(DMI_BOARD_VENDOR, "Apple Inc."))
3496+
if (!x86_apple_machine)
34963497
return;
34973498
if (pci_pcie_type(dev) != PCI_EXP_TYPE_DOWNSTREAM)
34983499
return;

drivers/thunderbolt/icm.c

+4-9
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
*/
1414

1515
#include <linux/delay.h>
16-
#include <linux/dmi.h>
1716
#include <linux/mutex.h>
1817
#include <linux/pci.h>
18+
#include <linux/platform_data/x86/apple.h>
1919
#include <linux/sizes.h>
2020
#include <linux/slab.h>
2121
#include <linux/workqueue.h>
@@ -102,11 +102,6 @@ static inline u64 get_route(u32 route_hi, u32 route_lo)
102102
return (u64)route_hi << 32 | route_lo;
103103
}
104104

105-
static inline bool is_apple(void)
106-
{
107-
return dmi_match(DMI_BOARD_VENDOR, "Apple Inc.");
108-
}
109-
110105
static bool icm_match(const struct tb_cfg_request *req,
111106
const struct ctl_pkg *pkg)
112107
{
@@ -176,7 +171,7 @@ static int icm_request(struct tb *tb, const void *request, size_t request_size,
176171

177172
static bool icm_fr_is_supported(struct tb *tb)
178173
{
179-
return !is_apple();
174+
return !x86_apple_machine;
180175
}
181176

182177
static inline int icm_fr_get_switch_index(u32 port)
@@ -517,7 +512,7 @@ static bool icm_ar_is_supported(struct tb *tb)
517512
* Starting from Alpine Ridge we can use ICM on Apple machines
518513
* as well. We just need to reset and re-enable it first.
519514
*/
520-
if (!is_apple())
515+
if (!x86_apple_machine)
521516
return true;
522517

523518
/*
@@ -1004,7 +999,7 @@ static int icm_start(struct tb *tb)
1004999
* don't provide images publicly either. To be on the safe side
10051000
* prevent root switch NVM upgrade on Macs for now.
10061001
*/
1007-
tb->root_switch->no_nvm_upgrade = is_apple();
1002+
tb->root_switch->no_nvm_upgrade = x86_apple_machine;
10081003

10091004
ret = tb_switch_add(tb->root_switch);
10101005
if (ret)

drivers/thunderbolt/tb.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <linux/slab.h>
88
#include <linux/errno.h>
99
#include <linux/delay.h>
10-
#include <linux/dmi.h>
10+
#include <linux/platform_data/x86/apple.h>
1111

1212
#include "tb.h"
1313
#include "tb_regs.h"
@@ -453,7 +453,7 @@ struct tb *tb_probe(struct tb_nhi *nhi)
453453
struct tb_cm *tcm;
454454
struct tb *tb;
455455

456-
if (!dmi_match(DMI_BOARD_VENDOR, "Apple Inc."))
456+
if (!x86_apple_machine)
457457
return NULL;
458458

459459
tb = tb_domain_alloc(nhi, sizeof(*tcm));
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef PLATFORM_DATA_X86_APPLE_H
2+
#define PLATFORM_DATA_X86_APPLE_H
3+
4+
#ifdef CONFIG_X86
5+
/**
6+
* x86_apple_machine - whether the machine is an x86 Apple Macintosh
7+
*/
8+
extern bool x86_apple_machine;
9+
#else
10+
#define x86_apple_machine false
11+
#endif
12+
13+
#endif

0 commit comments

Comments
 (0)