Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

platform/x86: asus-armoury: add apu-mem control support

Implement the APU memory size control under the asus-armoury module using
the fw_attributes class.

This allows the APU allocated memory size to be adjusted depending on
the users priority. A reboot is required after change.

Co-developed-by: Denis Benato <denis.benato@linux.dev>
Signed-off-by: Denis Benato <denis.benato@linux.dev>
Signed-off-by: Luke D. Jones <luke@ljones.dev>
Link: https://patch.msgid.link/20251102215319.3126879-5-denis.benato@linux.dev
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

authored by

Luke D. Jones and committed by
Ilpo Järvinen
9c7dacf5 628cb03b

+100
+98
drivers/platform/x86/asus-armoury.c
··· 174 174 * and should perform relevant checks. 175 175 * 176 176 * Returns: 177 + * * %-EINVAL - attempt to set a dangerous or unsupported value. 177 178 * * %-EIO - WMI function returned an error. 178 179 * * %0 - successful and retval is filled. 179 180 * * %other - error from WMI call. ··· 184 183 { 185 184 u32 result; 186 185 int err; 186 + 187 + /* 188 + * Prevent developers from bricking devices or issuing dangerous 189 + * commands that can be difficult or impossible to recover from. 190 + */ 191 + switch (dev_id) { 192 + case ASUS_WMI_DEVID_APU_MEM: 193 + /* 194 + * A hard reset might suffice to save the device, 195 + * but there is no value in sending these commands. 196 + */ 197 + if (value == 0x100 || value == 0x101) { 198 + pr_err("Refusing to set APU memory to unsafe value: 0x%x\n", value); 199 + return -EINVAL; 200 + } 201 + break; 202 + default: 203 + /* No problems are known for this dev_id */ 204 + break; 205 + } 187 206 188 207 err = asus_wmi_set_devstate(dev_id, value, retval ? retval : &result); 189 208 if (err) { ··· 620 599 } 621 600 ASUS_ATTR_GROUP_ENUM(egpu_enable, "egpu_enable", "Enable the eGPU (also disables dGPU)"); 622 601 602 + /* Device memory available to APU */ 603 + 604 + /* 605 + * Values map for APU reserved memory (index + 1 number of GB). 606 + * Some looks out of order, but are actually correct. 607 + */ 608 + static u32 apu_mem_map[] = { 609 + [0] = 0x000, /* called "AUTO" on the BIOS, is the minimum available */ 610 + [1] = 0x102, 611 + [2] = 0x103, 612 + [3] = 0x104, 613 + [4] = 0x105, 614 + [5] = 0x107, 615 + [6] = 0x108, 616 + [7] = 0x109, 617 + [8] = 0x106, 618 + }; 619 + 620 + static ssize_t apu_mem_current_value_show(struct kobject *kobj, struct kobj_attribute *attr, 621 + char *buf) 622 + { 623 + int err; 624 + u32 mem; 625 + 626 + err = armoury_get_devstate(attr, &mem, ASUS_WMI_DEVID_APU_MEM); 627 + if (err) 628 + return err; 629 + 630 + /* After 0x000 is set, a read will return 0x100 */ 631 + if (mem == 0x100) 632 + return sysfs_emit(buf, "0\n"); 633 + 634 + for (unsigned int i = 0; i < ARRAY_SIZE(apu_mem_map); i++) { 635 + if (apu_mem_map[i] == mem) 636 + return sysfs_emit(buf, "%u\n", i); 637 + } 638 + 639 + pr_warn("Unrecognised value for APU mem 0x%08x\n", mem); 640 + return -EIO; 641 + } 642 + 643 + static ssize_t apu_mem_current_value_store(struct kobject *kobj, struct kobj_attribute *attr, 644 + const char *buf, size_t count) 645 + { 646 + int result, err; 647 + u32 requested, mem; 648 + 649 + result = kstrtou32(buf, 10, &requested); 650 + if (result) 651 + return result; 652 + 653 + if (requested >= ARRAY_SIZE(apu_mem_map)) 654 + return -EINVAL; 655 + mem = apu_mem_map[requested]; 656 + 657 + err = armoury_set_devstate(attr, mem, NULL, ASUS_WMI_DEVID_APU_MEM); 658 + if (err) { 659 + pr_warn("Failed to set apu_mem 0x%x: %d\n", mem, err); 660 + return err; 661 + } 662 + 663 + pr_info("APU memory changed to %uGB, reboot required\n", requested + 1); 664 + sysfs_notify(kobj, NULL, attr->attr.name); 665 + 666 + asus_set_reboot_and_signal_event(); 667 + 668 + return count; 669 + } 670 + 671 + static ssize_t apu_mem_possible_values_show(struct kobject *kobj, struct kobj_attribute *attr, 672 + char *buf) 673 + { 674 + return armoury_attr_enum_list(buf, ARRAY_SIZE(apu_mem_map)); 675 + } 676 + ASUS_ATTR_GROUP_ENUM(apu_mem, "apu_mem", "Set available system RAM (in GB) for the APU to use"); 677 + 623 678 /* Simple attribute creation */ 624 679 ASUS_ATTR_GROUP_ENUM_INT_RO(charge_mode, "charge_mode", ASUS_WMI_DEVID_CHARGE_MODE, "0;1;2\n", 625 680 "Show the current mode of charging"); ··· 715 618 { &egpu_connected_attr_group, ASUS_WMI_DEVID_EGPU_CONNECTED }, 716 619 { &egpu_enable_attr_group, ASUS_WMI_DEVID_EGPU }, 717 620 { &dgpu_disable_attr_group, ASUS_WMI_DEVID_DGPU }, 621 + { &apu_mem_attr_group, ASUS_WMI_DEVID_APU_MEM }, 718 622 719 623 { &charge_mode_attr_group, ASUS_WMI_DEVID_CHARGE_MODE }, 720 624 { &boot_sound_attr_group, ASUS_WMI_DEVID_BOOT_SOUND },
+2
include/linux/platform_data/x86/asus-wmi.h
··· 136 136 /* dgpu on/off */ 137 137 #define ASUS_WMI_DEVID_DGPU 0x00090020 138 138 139 + #define ASUS_WMI_DEVID_APU_MEM 0x000600C1 140 + 139 141 /* gpu mux switch, 0 = dGPU, 1 = Optimus */ 140 142 #define ASUS_WMI_DEVID_GPU_MUX 0x00090016 141 143 #define ASUS_WMI_DEVID_GPU_MUX_VIVO 0x00090026