diff --git a/0002-x86-setup-Consolidate-early-memory-reservations.patch b/0002-x86-setup-Consolidate-early-memory-reservations.patch deleted file mode 100644 index ee256a5..0000000 --- a/0002-x86-setup-Consolidate-early-memory-reservations.patch +++ /dev/null @@ -1,188 +0,0 @@ -From 8bd9e7d22ae0676f6dd2af4ea385111c052e745e Mon Sep 17 00:00:00 2001 -From: Mike Rapoport -Date: Tue, 2 Mar 2021 12:04:05 +0200 -Subject: [PATCH 2/7] x86/setup: Consolidate early memory reservations - -The early reservations of memory areas used by the firmware, bootloader, -kernel text and data are spread over setup_arch(). Moreover, some of them -happen *after* memblock allocations, e.g trim_platform_memory_ranges() and -trim_low_memory_range() are called after reserve_real_mode() that allocates -memory. - -There was no corruption of these memory regions because memblock always -allocates memory either from the end of memory (in top-down mode) or above -the kernel image (in bottom-up mode). However, the bottom up mode is going -to be updated to span the entire memory [1] to avoid limitations caused by -KASLR. - -Consolidate early memory reservations in a dedicated function to improve -robustness against future changes. Having the early reservations in one -place also makes it clearer what memory must be reserved before memblock -allocations are allowed. - -Signed-off-by: Mike Rapoport -Signed-off-by: Borislav Petkov -Reviewed-by: Baoquan He -Acked-by: Borislav Petkov -Acked-by: David Hildenbrand -Link: [1] https://lore.kernel.org/lkml/20201217201214.3414100-2-guro@fb.com -Link: https://lkml.kernel.org/r/20210302100406.22059-2-rppt@kernel.org ---- - arch/x86/kernel/setup.c | 92 ++++++++++++++++++++--------------------- - 1 file changed, 44 insertions(+), 48 deletions(-) - -diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c -index e79f21d13a0d..420d881da2bd 100644 ---- a/arch/x86/kernel/setup.c -+++ b/arch/x86/kernel/setup.c -@@ -646,18 +646,6 @@ static void __init trim_snb_memory(void) - } - } - --/* -- * Here we put platform-specific memory range workarounds, i.e. -- * memory known to be corrupt or otherwise in need to be reserved on -- * specific platforms. -- * -- * If this gets used more widely it could use a real dispatch mechanism. -- */ --static void __init trim_platform_memory_ranges(void) --{ -- trim_snb_memory(); --} -- - static void __init trim_bios_range(void) - { - /* -@@ -730,7 +718,38 @@ static void __init trim_low_memory_range(void) - { - memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE)); - } -- -+ -+static void __init early_reserve_memory(void) -+{ -+ /* -+ * Reserve the memory occupied by the kernel between _text and -+ * __end_of_kernel_reserve symbols. Any kernel sections after the -+ * __end_of_kernel_reserve symbol must be explicitly reserved with a -+ * separate memblock_reserve() or they will be discarded. -+ */ -+ memblock_reserve(__pa_symbol(_text), -+ (unsigned long)__end_of_kernel_reserve - (unsigned long)_text); -+ -+ /* -+ * Make sure page 0 is always reserved because on systems with -+ * L1TF its contents can be leaked to user processes. -+ */ -+ memblock_reserve(0, PAGE_SIZE); -+ -+ early_reserve_initrd(); -+ -+ if (efi_enabled(EFI_BOOT)) -+ efi_memblock_x86_reserve_range(); -+ -+ memblock_x86_reserve_range_setup_data(); -+ -+ reserve_ibft_region(); -+ reserve_bios_regions(); -+ -+ trim_snb_memory(); -+ trim_low_memory_range(); -+} -+ - /* - * Dump out kernel offset information on panic. - */ -@@ -765,29 +784,6 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) - - void __init setup_arch(char **cmdline_p) - { -- /* -- * Reserve the memory occupied by the kernel between _text and -- * __end_of_kernel_reserve symbols. Any kernel sections after the -- * __end_of_kernel_reserve symbol must be explicitly reserved with a -- * separate memblock_reserve() or they will be discarded. -- */ -- memblock_reserve(__pa_symbol(_text), -- (unsigned long)__end_of_kernel_reserve - (unsigned long)_text); -- -- /* -- * Make sure page 0 is always reserved because on systems with -- * L1TF its contents can be leaked to user processes. -- */ -- memblock_reserve(0, PAGE_SIZE); -- -- early_reserve_initrd(); -- -- /* -- * At this point everything still needed from the boot loader -- * or BIOS or kernel text should be early reserved or marked not -- * RAM in e820. All other memory is free game. -- */ -- - #ifdef CONFIG_X86_32 - memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data)); - -@@ -911,8 +907,18 @@ void __init setup_arch(char **cmdline_p) - - parse_early_param(); - -- if (efi_enabled(EFI_BOOT)) -- efi_memblock_x86_reserve_range(); -+ /* -+ * Do some memory reservations *before* memory is added to -+ * memblock, so memblock allocations won't overwrite it. -+ * Do it after early param, so we could get (unlikely) panic from -+ * serial. -+ * -+ * After this point everything still needed from the boot loader or -+ * firmware or kernel text should be early reserved or marked not -+ * RAM in e820. All other memory is free game. -+ */ -+ early_reserve_memory(); -+ - #ifdef CONFIG_MEMORY_HOTPLUG - /* - * Memory used by the kernel cannot be hot-removed because Linux -@@ -939,9 +945,6 @@ void __init setup_arch(char **cmdline_p) - - x86_report_nx(); - -- /* after early param, so could get panic from serial */ -- memblock_x86_reserve_range_setup_data(); -- - if (acpi_mps_check()) { - #ifdef CONFIG_X86_LOCAL_APIC - disable_apic = 1; -@@ -1033,8 +1036,6 @@ void __init setup_arch(char **cmdline_p) - */ - find_smp_config(); - -- reserve_ibft_region(); -- - early_alloc_pgt_buf(); - - /* -@@ -1055,8 +1056,6 @@ void __init setup_arch(char **cmdline_p) - */ - sev_setup_arch(); - -- reserve_bios_regions(); -- - efi_fake_memmap(); - efi_find_mirror(); - efi_esrt_init(); -@@ -1082,9 +1081,6 @@ void __init setup_arch(char **cmdline_p) - - reserve_real_mode(); - -- trim_platform_memory_ranges(); -- trim_low_memory_range(); -- - init_mem_mapping(); - - idt_setup_early_pf(); --- -2.32.0 - diff --git a/0003-x86-setup-Merge-several-reservations-of-start-of-mem.patch b/0003-x86-setup-Merge-several-reservations-of-start-of-mem.patch deleted file mode 100644 index 14b6051..0000000 --- a/0003-x86-setup-Merge-several-reservations-of-start-of-mem.patch +++ /dev/null @@ -1,67 +0,0 @@ -From c1f1e2a2781a0c0ead90df1e873ba7f6aaad35ed Mon Sep 17 00:00:00 2001 -From: Mike Rapoport -Date: Tue, 2 Mar 2021 12:04:06 +0200 -Subject: [PATCH 3/7] x86/setup: Merge several reservations of start of memory - -Currently, the first several pages are reserved both to avoid leaking -their contents on systems with L1TF and to avoid corrupting BIOS memory. - -Merge the two memory reservations. - -Signed-off-by: Mike Rapoport -Signed-off-by: Borislav Petkov -Reviewed-by: David Hildenbrand -Acked-by: Borislav Petkov -Link: https://lkml.kernel.org/r/20210302100406.22059-3-rppt@kernel.org ---- - arch/x86/kernel/setup.c | 19 ++++++++++--------- - 1 file changed, 10 insertions(+), 9 deletions(-) - -diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c -index 420d881da2bd..282d572e49af 100644 ---- a/arch/x86/kernel/setup.c -+++ b/arch/x86/kernel/setup.c -@@ -714,11 +714,6 @@ static int __init parse_reservelow(char *p) - - early_param("reservelow", parse_reservelow); - --static void __init trim_low_memory_range(void) --{ -- memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE)); --} -- - static void __init early_reserve_memory(void) - { - /* -@@ -731,10 +726,17 @@ static void __init early_reserve_memory(void) - (unsigned long)__end_of_kernel_reserve - (unsigned long)_text); - - /* -- * Make sure page 0 is always reserved because on systems with -- * L1TF its contents can be leaked to user processes. -+ * The first 4Kb of memory is a BIOS owned area, but generally it is -+ * not listed as such in the E820 table. -+ * -+ * Reserve the first memory page and typically some additional -+ * memory (64KiB by default) since some BIOSes are known to corrupt -+ * low memory. See the Kconfig help text for X86_RESERVE_LOW. -+ * -+ * In addition, make sure page 0 is always reserved because on -+ * systems with L1TF its contents can be leaked to user processes. - */ -- memblock_reserve(0, PAGE_SIZE); -+ memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE)); - - early_reserve_initrd(); - -@@ -747,7 +749,6 @@ static void __init early_reserve_memory(void) - reserve_bios_regions(); - - trim_snb_memory(); -- trim_low_memory_range(); - } - - /* --- -2.32.0 - diff --git a/0004-x86-setup-Move-trim_snb_memory-later-in-setup_arch-t.patch b/0004-x86-setup-Move-trim_snb_memory-later-in-setup_arch-t.patch deleted file mode 100644 index 2f695f9..0000000 --- a/0004-x86-setup-Move-trim_snb_memory-later-in-setup_arch-t.patch +++ /dev/null @@ -1,87 +0,0 @@ -From 743e1a2b9b6e79fb237ac84e20dc4411217deb24 Mon Sep 17 00:00:00 2001 -From: Mike Rapoport -Date: Tue, 13 Apr 2021 21:08:39 +0300 -Subject: [PATCH 4/7] x86/setup: Move trim_snb_memory() later in setup_arch() - to fix boot hangs - -Commit - - a799c2bd29d1 ("x86/setup: Consolidate early memory reservations") - -moved reservation of the memory inaccessible by Sandy Bride integrated -graphics very early, and, as a result, on systems with such devices -the first 1M was reserved by trim_snb_memory() which prevented the -allocation of the real mode trampoline and made the boot hang very -early. - -Since the purpose of trim_snb_memory() is to prevent problematic pages -ever reaching the graphics device, it is safe to reserve these pages -after memblock allocations are possible. - -Move trim_snb_memory() later in boot so that it will be called after -reserve_real_mode() and make comments describing trim_snb_memory() -operation more elaborate. - - [ bp: Massage a bit. ] - -Fixes: a799c2bd29d1 ("x86/setup: Consolidate early memory reservations") -Reported-by: Randy Dunlap -Signed-off-by: Mike Rapoport -Signed-off-by: Borislav Petkov -Tested-by: Randy Dunlap -Tested-by: Hugh Dickins -Link: https://lkml.kernel.org/r/f67d3e03-af90-f790-baf4-8d412fe055af@infradead.org ---- - arch/x86/kernel/setup.c | 20 +++++++++++++++----- - 1 file changed, 15 insertions(+), 5 deletions(-) - -diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c -index 282d572e49af..7d466f51be1f 100644 ---- a/arch/x86/kernel/setup.c -+++ b/arch/x86/kernel/setup.c -@@ -634,11 +634,16 @@ static void __init trim_snb_memory(void) - printk(KERN_DEBUG "reserving inaccessible SNB gfx pages\n"); - - /* -- * Reserve all memory below the 1 MB mark that has not -- * already been reserved. -+ * SandyBridge integrated graphics devices have a bug that prevents -+ * them from accessing certain memory ranges, namely anything below -+ * 1M and in the pages listed in bad_pages[] above. -+ * -+ * To avoid these pages being ever accessed by SNB gfx devices -+ * reserve all memory below the 1 MB mark and bad_pages that have -+ * not already been reserved at boot time. - */ - memblock_reserve(0, 1<<20); -- -+ - for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { - if (memblock_reserve(bad_pages[i], PAGE_SIZE)) - printk(KERN_WARNING "failed to reserve 0x%08lx\n", -@@ -747,8 +752,6 @@ static void __init early_reserve_memory(void) - - reserve_ibft_region(); - reserve_bios_regions(); -- -- trim_snb_memory(); - } - - /* -@@ -1082,6 +1085,13 @@ void __init setup_arch(char **cmdline_p) - - reserve_real_mode(); - -+ /* -+ * Reserving memory causing GPU hangs on Sandy Bridge integrated -+ * graphics devices should be done after we allocated memory under -+ * 1M for the real mode trampoline. -+ */ -+ trim_snb_memory(); -+ - init_mem_mapping(); - - idt_setup_early_pf(); --- -2.32.0 - diff --git a/0005-x86-setup-always-reserve-the-first-1M-of-RAM.patch b/0005-x86-setup-always-reserve-the-first-1M-of-RAM.patch deleted file mode 100644 index 5769218..0000000 --- a/0005-x86-setup-always-reserve-the-first-1M-of-RAM.patch +++ /dev/null @@ -1,170 +0,0 @@ -From f2c34dfc0b3903b5ebed62a7a8ec7c27c7c203d0 Mon Sep 17 00:00:00 2001 -From: Mike Rapoport -Date: Tue, 1 Jun 2021 10:53:52 +0300 -Subject: [PATCH 5/7] x86/setup: always reserve the first 1M of RAM - -There are BIOSes that are known to corrupt the memory under 1M, or more -precisely under 640K because the memory above 640K is anyway reserved for -the EGA/VGA frame buffer and BIOS. - -To prevent usage of the memory that will be potentially clobbered by the -kernel, the beginning of the memory is always reserved. The exact size of -the reserved area is determined by CONFIG_X86_RESERVE_LOW build time and -reservelow command line option. The reserved range may be from 4K to 640K -with the default of 64K. There are also configurations that reserve the -entire 1M range, like machines with SandyBridge graphic devices or systems -that enable crash kernel. - -In addition to the potentially clobbered memory, EBDA of unknown size may -be as low as 128K and the memory above that EBDA start is also reserved -early. - -It would have been possible to reserve the entire range under 1M unless for -the real mode trampoline that must reside in that area. - -To accommodate placement of the real mode trampoline and keep the memory -safe from being clobbered by BIOS reserve the first 64K of RAM before -memory allocations are possible and then, after the real mode trampoline is -allocated, reserve the entire range from 0 to 1M. - -Update trim_snb_memory() and reserve_real_mode() to avoid redundant -reservations of the same memory range. - -Also make sure the memory under 1M is not getting freed by -efi_free_boot_services(). - -Fixes: a799c2bd29d1 ("x86/setup: Consolidate early memory reservations") -Signed-off-by: Mike Rapoport ---- - arch/x86/kernel/setup.c | 35 ++++++++++++++++++++-------------- - arch/x86/platform/efi/quirks.c | 12 ++++++++++++ - arch/x86/realmode/init.c | 14 ++++++++------ - 3 files changed, 41 insertions(+), 20 deletions(-) - -diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c -index 7d466f51be1f..d7cfb927864f 100644 ---- a/arch/x86/kernel/setup.c -+++ b/arch/x86/kernel/setup.c -@@ -638,11 +638,11 @@ static void __init trim_snb_memory(void) - * them from accessing certain memory ranges, namely anything below - * 1M and in the pages listed in bad_pages[] above. - * -- * To avoid these pages being ever accessed by SNB gfx devices -- * reserve all memory below the 1 MB mark and bad_pages that have -- * not already been reserved at boot time. -+ * To avoid these pages being ever accessed by SNB gfx devices reserve -+ * bad_pages that have not already been reserved at boot time. -+ * All memory below the 1 MB mark is anyway reserved later during -+ * setup_arch(), so there is no need to reserve it here. - */ -- memblock_reserve(0, 1<<20); - - for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { - if (memblock_reserve(bad_pages[i], PAGE_SIZE)) -@@ -734,14 +734,14 @@ static void __init early_reserve_memory(void) - * The first 4Kb of memory is a BIOS owned area, but generally it is - * not listed as such in the E820 table. - * -- * Reserve the first memory page and typically some additional -- * memory (64KiB by default) since some BIOSes are known to corrupt -- * low memory. See the Kconfig help text for X86_RESERVE_LOW. -+ * Reserve the first 64K of memory since some BIOSes are known to -+ * corrupt low memory. After the real mode trampoline is allocated the -+ * rest of the memory below 640k is reserved. - * - * In addition, make sure page 0 is always reserved because on - * systems with L1TF its contents can be leaked to user processes. - */ -- memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE)); -+ memblock_reserve(0, SZ_64K); - - early_reserve_initrd(); - -@@ -752,6 +752,7 @@ static void __init early_reserve_memory(void) - - reserve_ibft_region(); - reserve_bios_regions(); -+ trim_snb_memory(); - } - - /* -@@ -1083,14 +1084,20 @@ void __init setup_arch(char **cmdline_p) - (max_pfn_mapped< -@@ -119,7 +120,7 @@ struct applesmc_entry { +@@ -119,7 +120,7 @@ }; /* Register lookup and registers common to all SMCs */ @@ -34,7 +34,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 struct mutex mutex; /* register read/write mutex */ unsigned int key_count; /* number of SMC registers */ unsigned int fan_count; /* number of fans */ -@@ -133,26 +134,32 @@ static struct applesmc_registers { +@@ -133,26 +134,32 @@ bool init_complete; /* true when fully initialized */ struct applesmc_entry *cache; /* cached key entries */ const char **index; /* temperature key index */ @@ -82,7 +82,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 /* * Wait for specific status bits with a mask on the SMC. -@@ -338,36 +345,37 @@ static int read_register_count(unsigned int *count) +@@ -338,36 +345,37 @@ * All functions below are concurrency safe - callers should NOT hold lock. */ @@ -130,7 +130,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 u8 key[4], info[6]; __be32 be; int ret = 0; -@@ -375,7 +383,7 @@ static const struct applesmc_entry *applesmc_get_entry_by_index(int index) +@@ -375,7 +383,7 @@ if (cache->valid) return cache; @@ -139,7 +139,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (cache->valid) goto out; -@@ -394,20 +402,21 @@ static const struct applesmc_entry *applesmc_get_entry_by_index(int index) +@@ -394,20 +402,21 @@ cache->valid = 1; out: @@ -165,7 +165,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (IS_ERR(entry)) { *lo = 0; return PTR_ERR(entry); -@@ -422,16 +431,17 @@ static int applesmc_get_lower_bound(unsigned int *lo, const char *key) +@@ -422,16 +431,17 @@ return 0; } @@ -187,7 +187,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 return PTR_ERR(entry); } if (strcmp(key, entry->key) < 0) -@@ -444,50 +454,54 @@ static int applesmc_get_upper_bound(unsigned int *hi, const char *key) +@@ -444,50 +454,54 @@ return 0; } @@ -254,7 +254,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (IS_ERR(entry) && PTR_ERR(entry) != -EINVAL) return PTR_ERR(entry); -@@ -498,12 +512,13 @@ static int applesmc_has_key(const char *key, bool *value) +@@ -498,12 +512,13 @@ /* * applesmc_read_s16 - Read 16-bit signed big endian register */ @@ -270,7 +270,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) return ret; -@@ -514,28 +529,29 @@ static int applesmc_read_s16(const char *key, s16 *value) +@@ -514,28 +529,29 @@ /* * applesmc_device_init - initialize the accelerometer. Can sleep. */ @@ -305,7 +305,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 { const struct applesmc_entry *entry; unsigned int i; -@@ -548,7 +564,7 @@ static int applesmc_init_index(struct applesmc_registers *s) +@@ -548,7 +564,7 @@ return -ENOMEM; for (i = s->temp_begin; i < s->temp_end; i++) { @@ -314,7 +314,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (IS_ERR(entry)) continue; if (strcmp(entry->type, TEMP_SENSOR_TYPE)) -@@ -562,9 +578,9 @@ static int applesmc_init_index(struct applesmc_registers *s) +@@ -562,9 +578,9 @@ /* * applesmc_init_smcreg_try - Try to initialize register cache. Idempotent. */ @@ -326,7 +326,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 bool left_light_sensor = false, right_light_sensor = false; unsigned int count; u8 tmp[1]; -@@ -590,35 +606,35 @@ static int applesmc_init_smcreg_try(void) +@@ -590,35 +606,35 @@ if (!s->cache) return -ENOMEM; @@ -370,7 +370,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) return ret; -@@ -634,13 +650,13 @@ static int applesmc_init_smcreg_try(void) +@@ -634,13 +650,13 @@ return 0; } @@ -390,7 +390,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 } /* -@@ -649,12 +665,12 @@ static void applesmc_destroy_smcreg(void) +@@ -649,12 +665,12 @@ * Retries until initialization is successful, or the operation times out. * */ @@ -405,7 +405,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (!ret) { if (ms) pr_info("init_smcreg() took %d ms\n", ms); -@@ -663,21 +679,58 @@ static int applesmc_init_smcreg(void) +@@ -663,21 +679,58 @@ msleep(INIT_WAIT_MSECS); } @@ -451,8 +451,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 + platform_set_drvdata(dev, NULL); + mutex_destroy(&smc->reg.mutex); + kfree(smc); - -- applesmc_device_init(); ++ + return ret; +} + @@ -462,13 +461,14 @@ index 28b137eedf2e..cf00f7b62a78 100644 + + applesmc_destroy_modules(smc); + applesmc_destroy_smcreg(smc); -+ + +- applesmc_device_init(); + mutex_destroy(&smc->reg.mutex); + kfree(smc); return 0; } -@@ -685,15 +738,21 @@ static int applesmc_probe(struct platform_device *dev) +@@ -685,15 +738,21 @@ /* Synchronize device with memorized backlight state */ static int applesmc_pm_resume(struct device *dev) { @@ -493,7 +493,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 return applesmc_pm_resume(dev); } -@@ -704,6 +763,7 @@ static const struct dev_pm_ops applesmc_pm_ops = { +@@ -704,6 +763,7 @@ static struct platform_driver applesmc_driver = { .probe = applesmc_probe, @@ -501,7 +501,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 .driver = { .name = "applesmc", .pm = &applesmc_pm_ops, -@@ -714,25 +774,26 @@ static struct platform_driver applesmc_driver = { +@@ -714,25 +774,26 @@ * applesmc_calibrate - Set our "resting" values. Callers must * hold applesmc_lock. */ @@ -536,7 +536,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 input_sync(idev); } -@@ -747,16 +808,17 @@ static ssize_t applesmc_name_show(struct device *dev, +@@ -747,16 +808,17 @@ static ssize_t applesmc_position_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -557,7 +557,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) goto out; -@@ -770,6 +832,7 @@ static ssize_t applesmc_position_show(struct device *dev, +@@ -770,6 +832,7 @@ static ssize_t applesmc_light_show(struct device *dev, struct device_attribute *attr, char *sysfsbuf) { @@ -565,7 +565,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 const struct applesmc_entry *entry; static int data_length; int ret; -@@ -777,7 +840,7 @@ static ssize_t applesmc_light_show(struct device *dev, +@@ -777,7 +840,7 @@ u8 buffer[10]; if (!data_length) { @@ -574,7 +574,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (IS_ERR(entry)) return PTR_ERR(entry); if (entry->len > 10) -@@ -786,7 +849,7 @@ static ssize_t applesmc_light_show(struct device *dev, +@@ -786,7 +849,7 @@ pr_info("light sensor data length set to %d\n", data_length); } @@ -583,7 +583,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) goto out; /* newer macbooks report a single 10-bit bigendian value */ -@@ -796,7 +859,7 @@ static ssize_t applesmc_light_show(struct device *dev, +@@ -796,7 +859,7 @@ } left = buffer[2]; @@ -592,7 +592,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) goto out; right = buffer[2]; -@@ -812,7 +875,8 @@ static ssize_t applesmc_light_show(struct device *dev, +@@ -812,7 +875,8 @@ static ssize_t applesmc_show_sensor_label(struct device *dev, struct device_attribute *devattr, char *sysfsbuf) { @@ -600,9 +600,9 @@ index 28b137eedf2e..cf00f7b62a78 100644 + struct applesmc_device *smc = dev_get_drvdata(dev); + const char *key = smc->reg.index[to_index(devattr)]; - return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", key); + return sysfs_emit(sysfsbuf, "%s\n", key); } -@@ -821,12 +885,13 @@ static ssize_t applesmc_show_sensor_label(struct device *dev, +@@ -821,12 +885,13 @@ static ssize_t applesmc_show_temperature(struct device *dev, struct device_attribute *devattr, char *sysfsbuf) { @@ -618,7 +618,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) return ret; -@@ -838,6 +903,7 @@ static ssize_t applesmc_show_temperature(struct device *dev, +@@ -838,6 +903,7 @@ static ssize_t applesmc_show_fan_speed(struct device *dev, struct device_attribute *attr, char *sysfsbuf) { @@ -626,7 +626,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 int ret; unsigned int speed = 0; char newkey[5]; -@@ -846,7 +912,7 @@ static ssize_t applesmc_show_fan_speed(struct device *dev, +@@ -846,7 +912,7 @@ scnprintf(newkey, sizeof(newkey), fan_speed_fmt[to_option(attr)], to_index(attr)); @@ -635,7 +635,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) return ret; -@@ -858,6 +924,7 @@ static ssize_t applesmc_store_fan_speed(struct device *dev, +@@ -858,6 +924,7 @@ struct device_attribute *attr, const char *sysfsbuf, size_t count) { @@ -643,7 +643,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 int ret; unsigned long speed; char newkey[5]; -@@ -871,7 +938,7 @@ static ssize_t applesmc_store_fan_speed(struct device *dev, +@@ -871,7 +938,7 @@ buffer[0] = (speed >> 6) & 0xff; buffer[1] = (speed << 2) & 0xff; @@ -652,7 +652,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) return ret; -@@ -882,11 +949,12 @@ static ssize_t applesmc_store_fan_speed(struct device *dev, +@@ -882,11 +949,12 @@ static ssize_t applesmc_show_fan_manual(struct device *dev, struct device_attribute *attr, char *sysfsbuf) { @@ -666,7 +666,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) return ret; -@@ -898,6 +966,7 @@ static ssize_t applesmc_store_fan_manual(struct device *dev, +@@ -898,6 +966,7 @@ struct device_attribute *attr, const char *sysfsbuf, size_t count) { @@ -674,7 +674,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 int ret; u8 buffer[2]; unsigned long input; -@@ -906,7 +975,7 @@ static ssize_t applesmc_store_fan_manual(struct device *dev, +@@ -906,7 +975,7 @@ if (kstrtoul(sysfsbuf, 10, &input) < 0) return -EINVAL; @@ -683,7 +683,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) goto out; -@@ -920,7 +989,7 @@ static ssize_t applesmc_store_fan_manual(struct device *dev, +@@ -920,7 +989,7 @@ buffer[0] = (val >> 8) & 0xFF; buffer[1] = val & 0xFF; @@ -692,7 +692,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 out: if (ret) -@@ -932,13 +1001,14 @@ static ssize_t applesmc_store_fan_manual(struct device *dev, +@@ -932,13 +1001,14 @@ static ssize_t applesmc_show_fan_position(struct device *dev, struct device_attribute *attr, char *sysfsbuf) { @@ -708,14 +708,13 @@ index 28b137eedf2e..cf00f7b62a78 100644 buffer[16] = 0; if (ret) -@@ -950,30 +1020,36 @@ static ssize_t applesmc_show_fan_position(struct device *dev, +@@ -950,30 +1020,33 @@ static ssize_t applesmc_calibrate_show(struct device *dev, struct device_attribute *attr, char *sysfsbuf) { -- return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", rest_x, rest_y); +- return sysfs_emit(sysfsbuf, "(%d,%d)\n", rest_x, rest_y); + struct applesmc_device *smc = dev_get_drvdata(dev); -+ -+ return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", smc->rest_x, smc->rest_y); ++ return sysfs_emit(sysfsbuf, "(%d,%d)\n", smc->rest_x, smc->rest_y); } static ssize_t applesmc_calibrate_store(struct device *dev, @@ -723,7 +722,6 @@ index 28b137eedf2e..cf00f7b62a78 100644 { - applesmc_calibrate(); + struct applesmc_device *smc = dev_get_drvdata(dev); -+ + applesmc_calibrate(smc); return count; @@ -733,7 +731,6 @@ index 28b137eedf2e..cf00f7b62a78 100644 { - applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2); + struct applesmc_device *smc = container_of(work, struct applesmc_device, backlight_work); -+ + applesmc_write_key(smc, BACKLIGHT_KEY, smc->backlight_state, 2); } -static DECLARE_WORK(backlight_work, &applesmc_backlight_set); @@ -751,7 +748,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (debug && (!ret)) dev_dbg(led_cdev->dev, "work was already on the queue.\n"); -@@ -982,11 +1058,12 @@ static void applesmc_brightness_set(struct led_classdev *led_cdev, +@@ -982,11 +1055,12 @@ static ssize_t applesmc_key_count_show(struct device *dev, struct device_attribute *attr, char *sysfsbuf) { @@ -765,7 +762,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) return ret; -@@ -998,13 +1075,14 @@ static ssize_t applesmc_key_count_show(struct device *dev, +@@ -998,13 +1072,14 @@ static ssize_t applesmc_key_at_index_read_show(struct device *dev, struct device_attribute *attr, char *sysfsbuf) { @@ -782,7 +779,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) return ret; -@@ -1014,9 +1092,10 @@ static ssize_t applesmc_key_at_index_read_show(struct device *dev, +@@ -1014,9 +1089,10 @@ static ssize_t applesmc_key_at_index_data_length_show(struct device *dev, struct device_attribute *attr, char *sysfsbuf) { @@ -794,7 +791,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (IS_ERR(entry)) return PTR_ERR(entry); -@@ -1026,9 +1105,10 @@ static ssize_t applesmc_key_at_index_data_length_show(struct device *dev, +@@ -1026,9 +1102,10 @@ static ssize_t applesmc_key_at_index_type_show(struct device *dev, struct device_attribute *attr, char *sysfsbuf) { @@ -806,7 +803,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (IS_ERR(entry)) return PTR_ERR(entry); -@@ -1038,9 +1118,10 @@ static ssize_t applesmc_key_at_index_type_show(struct device *dev, +@@ -1038,9 +1115,10 @@ static ssize_t applesmc_key_at_index_name_show(struct device *dev, struct device_attribute *attr, char *sysfsbuf) { @@ -818,22 +815,21 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (IS_ERR(entry)) return PTR_ERR(entry); -@@ -1050,28 +1131,25 @@ static ssize_t applesmc_key_at_index_name_show(struct device *dev, +@@ -1050,27 +1128,23 @@ static ssize_t applesmc_key_at_index_show(struct device *dev, struct device_attribute *attr, char *sysfsbuf) { -- return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", key_at_index); +- return sysfs_emit(sysfsbuf, "%d\n", key_at_index); + struct applesmc_device *smc = dev_get_drvdata(dev); -+ -+ return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", smc->key_at_index); ++ return sysfs_emit(sysfsbuf, "%d\n", smc->key_at_index); } static ssize_t applesmc_key_at_index_store(struct device *dev, struct device_attribute *attr, const char *sysfsbuf, size_t count) { -+ struct applesmc_device *smc = dev_get_drvdata(dev); unsigned long newkey; - +- ++ struct applesmc_device *smc = dev_get_drvdata(dev); if (kstrtoul(sysfsbuf, 10, &newkey) < 0 - || newkey >= smcreg.key_count) + || newkey >= smc->reg.key_count) @@ -849,11 +845,10 @@ index 28b137eedf2e..cf00f7b62a78 100644 - .default_trigger = "nand-disk", - .brightness_set = applesmc_brightness_set, -}; -- + static struct applesmc_node_group info_group[] = { { "name", applesmc_name_show }, - { "key_count", applesmc_key_count_show }, -@@ -1116,14 +1194,15 @@ static struct applesmc_node_group temp_group[] = { +@@ -1116,14 +1190,15 @@ /* * applesmc_destroy_nodes - remove files and free associated memory */ @@ -871,7 +866,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 &node->sda.dev_attr.attr); kfree(grp->nodes); grp->nodes = NULL; -@@ -1133,7 +1212,8 @@ static void applesmc_destroy_nodes(struct applesmc_node_group *groups) +@@ -1133,7 +1208,8 @@ /* * applesmc_create_nodes - create a two-dimensional group of sysfs files */ @@ -881,7 +876,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 { struct applesmc_node_group *grp; struct applesmc_dev_attr *node; -@@ -1157,7 +1237,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num) +@@ -1157,7 +1233,7 @@ sysfs_attr_init(attr); attr->name = node->name; attr->mode = 0444 | (grp->store ? 0200 : 0); @@ -890,7 +885,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 if (ret) { attr->name = NULL; goto out; -@@ -1167,57 +1247,57 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num) +@@ -1167,57 +1243,57 @@ return 0; out: @@ -965,7 +960,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 out: pr_warn("driver init failed (ret=%d)!\n", ret); -@@ -1225,44 +1305,55 @@ static int applesmc_create_accelerometer(void) +@@ -1225,44 +1301,55 @@ } /* Release all resources used by the accelerometer */ @@ -1040,7 +1035,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 } static int applesmc_dmi_match(const struct dmi_system_id *id) -@@ -1306,86 +1397,100 @@ static const struct dmi_system_id applesmc_whitelist[] __initconst = { +@@ -1306,86 +1393,100 @@ { .ident = NULL } }; @@ -1062,7 +1057,8 @@ index 28b137eedf2e..cf00f7b62a78 100644 - } - - ret = platform_driver_register(&applesmc_driver); -- if (ret) ++ ret = applesmc_create_nodes(smc, info_group, 1); + if (ret) - goto out_region; - - pdev = platform_device_register_simple("applesmc", APPLESMC_DATA_PORT, @@ -1078,8 +1074,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 - goto out_device; - - ret = applesmc_create_nodes(info_group, 1); -+ ret = applesmc_create_nodes(smc, info_group, 1); - if (ret) +- if (ret) - goto out_smcreg; + goto out; @@ -1190,7 +1185,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 out_driver: platform_driver_unregister(&applesmc_driver); out_region: -@@ -1397,14 +1502,6 @@ static int __init applesmc_init(void) +@@ -1397,14 +1498,6 @@ static void __exit applesmc_exit(void) { @@ -1205,7 +1200,7 @@ index 28b137eedf2e..cf00f7b62a78 100644 platform_device_unregister(pdev); platform_driver_unregister(&applesmc_driver); release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS); -@@ -1414,6 +1511,7 @@ module_init(applesmc_init); +@@ -1414,6 +1507,7 @@ module_exit(applesmc_exit); MODULE_AUTHOR("Nicolas Boichat"); @@ -1213,6 +1208,3 @@ index 28b137eedf2e..cf00f7b62a78 100644 MODULE_DESCRIPTION("Apple SMC"); MODULE_LICENSE("GPL v2"); MODULE_DEVICE_TABLE(dmi, applesmc_whitelist); --- -2.31.1 - diff --git a/3006-applesmc-fan-support-on-T2-Macs.patch b/3006-applesmc-fan-support-on-T2-Macs.patch index f172afa..ec16d7d 100644 --- a/3006-applesmc-fan-support-on-T2-Macs.patch +++ b/3006-applesmc-fan-support-on-T2-Macs.patch @@ -110,7 +110,7 @@ index ae0aa5dbc842..867cf857448c 100644 return ret; - speed = ((buffer[0] << 8 | buffer[1]) >> 2); - return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", speed); + return sysfs_emit(sysfsbuf, "%u\n", speed); } @@ -1263,6 +1312,7 @@ static ssize_t applesmc_store_fan_speed(struct device *dev, @@ -169,7 +169,7 @@ index ae0aa5dbc842..867cf857448c 100644 return ret; - manual = ((buffer[0] << 8 | buffer[1]) >> to_index(attr)) & 0x01; - return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", manual); + return sysfs_emit(sysfsbuf, "%d\n", manual); } @@ -1307,27 +1380,39 @@ static ssize_t applesmc_store_fan_manual(struct device *dev,