From nobody Sun Feb 8 15:32:57 2026 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E4AA24DCFD for ; Sun, 2 Nov 2025 21:53:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762120423; cv=none; b=BZxkw+JxB3W3p/UPX09rKQpy503LBfQCwS8ZS5wJMwvD66yT6KwG5HLPlPlUy5ljYRodM6RfaR35mzYiWFJe6NDiXNHM6aylLE8sLohM/7UgDBjqT/9Ig2yMliuMNLSA0nQaY1s+6EC0w+VNmoL7yUYYUC8HBnfV9kv1FOrkhOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762120423; c=relaxed/simple; bh=drLkssrnjGMmjf4Qy02PSWQz7yGQiTpK/LifN+/YdIY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sks03zK9ywW/2QFL4jNm0rXbsHrZIara28cVvvNY8Vo3CnJdhUQC8tRffCPCmBzvz4GTyKuze88E0xVK/7wggs1hoVIOSsqJUH/IC/zmMIUh56ff1BuNLrM/vUtOh6jRHzDORBH7IPo/G9UOGWMfJIyjhAkPV6dlxfW6W7ic0KM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=m6aRVMnm; arc=none smtp.client-ip=95.215.58.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="m6aRVMnm" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762120418; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VjWUPCcZBXThnsjowjq/FKoSatTuXX22H85fDHwlDSk=; b=m6aRVMnmcMDdJSC2HUMkRO5MdOQQSrWpQjRFFQfOSJs5TsyZVeJHs0o4jdhXuqPWyG18Lz qlmlPnxiBiPHJ6KvJOmLTz+6eIeskAM+nhjkUC0Fg2+CfkkcD+tTfEyltbL7DFWvsO8tGL rm2WbCKRGKatrn/7cyE5haFQCfF0UPI= From: Denis Benato To: linux-kernel@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org, "Hans de Goede" , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , "Limonciello, Mario" , "Luke D . Jones" , "Alok Tiwari" , "Derek John Clark" , "Mateusz Schyboll" , porfet828@gmail.com, "Denis Benato" , Denis Benato Subject: [PATCH v17 4/9] platform/x86: asus-armoury: add apu-mem control support Date: Sun, 2 Nov 2025 22:53:14 +0100 Message-ID: <20251102215319.3126879-5-denis.benato@linux.dev> In-Reply-To: <20251102215319.3126879-1-denis.benato@linux.dev> References: <20251102215319.3126879-1-denis.benato@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: "Luke D. Jones" 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 Signed-off-by: Denis Benato Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-armoury.c | 98 ++++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 2 + 2 files changed, 100 insertions(+) diff --git a/drivers/platform/x86/asus-armoury.c b/drivers/platform/x86/asu= s-armoury.c index a6b86968fa37..75fead6091cb 100644 --- a/drivers/platform/x86/asus-armoury.c +++ b/drivers/platform/x86/asus-armoury.c @@ -174,6 +174,7 @@ static int armoury_get_devstate(struct kobj_attribute *= attr, u32 *retval, u32 de * and should perform relevant checks. * * Returns: + * * %-EINVAL - attempt to set a dangerous or unsupported value. * * %-EIO - WMI function returned an error. * * %0 - successful and retval is filled. * * %other - error from WMI call. @@ -184,6 +185,26 @@ static int armoury_set_devstate(struct kobj_attribute = *attr, u32 result; int err; =20 + /* + * Prevent developers from bricking devices or issuing dangerous + * commands that can be difficult or impossible to recover from. + */ + switch (dev_id) { + case ASUS_WMI_DEVID_APU_MEM: + /* + * A hard reset might suffice to save the device, + * but there is no value in sending these commands. + */ + if (value =3D=3D 0x100 || value =3D=3D 0x101) { + pr_err("Refusing to set APU memory to unsafe value: 0x%x\n", value); + return -EINVAL; + } + break; + default: + /* No known problems are known for this dev_id */ + break; + } + err =3D asus_wmi_set_devstate(dev_id, value, retval ? retval : &result); if (err) { if (attr) @@ -599,6 +620,82 @@ static ssize_t egpu_enable_possible_values_show(struct= kobject *kobj, struct kob } ASUS_ATTR_GROUP_ENUM(egpu_enable, "egpu_enable", "Enable the eGPU (also di= sables dGPU)"); =20 +/* Device memory available to APU */ + +/* + * Values map for APU reserved memory (index + 1 number of GB). + * Some looks out of order, but are actually correct. + */ +static u32 apu_mem_map[] =3D { + [0] =3D 0x000, /* called "AUTO" on the BIOS, is the minimum available */ + [1] =3D 0x102, + [2] =3D 0x103, + [3] =3D 0x104, + [4] =3D 0x105, + [5] =3D 0x107, + [6] =3D 0x108, + [7] =3D 0x109, + [8] =3D 0x106, +}; + +static ssize_t apu_mem_current_value_show(struct kobject *kobj, struct kob= j_attribute *attr, + char *buf) +{ + int err; + u32 mem; + + err =3D armoury_get_devstate(attr, &mem, ASUS_WMI_DEVID_APU_MEM); + if (err) + return err; + + /* After 0x000 is set, a read will return 0x100 */ + if (mem =3D=3D 0x100) + return sysfs_emit(buf, "0\n"); + + for (unsigned int i =3D 0; i < ARRAY_SIZE(apu_mem_map); i++) { + if (apu_mem_map[i] =3D=3D mem) + return sysfs_emit(buf, "%u\n", i); + } + + pr_warn("Unrecognised value for APU mem 0x%08x\n", mem); + return -EIO; +} + +static ssize_t apu_mem_current_value_store(struct kobject *kobj, struct ko= bj_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 requested, mem; + + result =3D kstrtou32(buf, 10, &requested); + if (result) + return result; + + if (requested >=3D ARRAY_SIZE(apu_mem_map)) + return -EINVAL; + mem =3D apu_mem_map[requested]; + + err =3D armoury_set_devstate(attr, mem, NULL, ASUS_WMI_DEVID_APU_MEM); + if (err) { + pr_warn("Failed to set apu_mem 0x%x: %d\n", mem, err); + return err; + } + + pr_info("APU memory changed to %uGB, reboot required\n", requested + 1); + sysfs_notify(kobj, NULL, attr->attr.name); + + asus_set_reboot_and_signal_event(); + + return count; +} + +static ssize_t apu_mem_possible_values_show(struct kobject *kobj, struct k= obj_attribute *attr, + char *buf) +{ + return armoury_attr_enum_list(buf, ARRAY_SIZE(apu_mem_map)); +} +ASUS_ATTR_GROUP_ENUM(apu_mem, "apu_mem", "Set available system RAM (in GB)= for the APU to use"); + /* Simple attribute creation */ ASUS_ATTR_GROUP_ENUM_INT_RO(charge_mode, "charge_mode", ASUS_WMI_DEVID_CHA= RGE_MODE, "0;1;2\n", "Show the current mode of charging"); @@ -618,6 +715,7 @@ static const struct asus_attr_group armoury_attr_groups= [] =3D { { &egpu_connected_attr_group, ASUS_WMI_DEVID_EGPU_CONNECTED }, { &egpu_enable_attr_group, ASUS_WMI_DEVID_EGPU }, { &dgpu_disable_attr_group, ASUS_WMI_DEVID_DGPU }, + { &apu_mem_attr_group, ASUS_WMI_DEVID_APU_MEM }, =20 { &charge_mode_attr_group, ASUS_WMI_DEVID_CHARGE_MODE }, { &boot_sound_attr_group, ASUS_WMI_DEVID_BOOT_SOUND }, diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/pla= tform_data/x86/asus-wmi.h index 3cc235b20be4..9a6433d08973 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -136,6 +136,8 @@ /* dgpu on/off */ #define ASUS_WMI_DEVID_DGPU 0x00090020 =20 +#define ASUS_WMI_DEVID_APU_MEM 0x000600C1 + /* gpu mux switch, 0 =3D dGPU, 1 =3D Optimus */ #define ASUS_WMI_DEVID_GPU_MUX 0x00090016 #define ASUS_WMI_DEVID_GPU_MUX_VIVO 0x00090026 --=20 2.51.2