Re: [PATCH v8 3/4] EDAC/loongson: Get DIMM size from ACPI _DSM method
From: Borislav Petkov
Date: Fri Nov 27 2026 - 18:23:41 EST
On Wed, Nov 18, 2026 at 11:03:29AM +0800, Qunqin Zhao wrote:
> From: Wang Jinwei <wangjinwei@xxxxxxxxxxx>
>
> Add support to retrieve DIMM size from ACPI _DSM method instead
> of using hardcoded values.
>
> 1. Add loongson_get_dimm_size_acpi() to call ACPI _DSM method
> to Get DIMM size in MB.
>
> 2. Update dimm_config_init() to use the size from ACPI, with
> fallback to default 1 MB if ACPI method fails.
>
> 3. Add ACPI UUID and DSM function definitions for EDAC.
>
> The DIMM size is passed from UEFI through ACPI OperationRegion
> and _DSM method, enabling correct display of memory size in
> /sys/devices/system/edac/mc/mc*/size_mb.
Please, do not talk about *what* the patch is doing in the commit message
- that should be obvious from the diff itself. Rather, concentrate on the
*why* it needs to be done and why your patch exists.
It is perfectly fine to explain non-trivial aspects of the code the patch is
touching but do not regurgitate what it does.
See also https://docs.kernel.org/process/submitting-patches.html for
additional inspiration.
> Cc: Dongyan Qian <qiandongyan@xxxxxxxxxxx>
> Cc: Chao Li <lichao@xxxxxxxxxxx>
> Signed-off-by: Wang Jinwei <wangjinwei@xxxxxxxxxxx>
> Signed-off-by: Qunqin Zhao <zhaoqunqin@xxxxxxxxxxx>
> Reviewed-by: Huacai Chen <chenhuacai@xxxxxxxxxxx>
> ---
> drivers/edac/loongson_edac.c | 32 ++++++++++++++++++++++++++++++--
> 1 file changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c
> index 4ee9dcb3d5..413ca654b4 100644
> --- a/drivers/edac/loongson_edac.c
> +++ b/drivers/edac/loongson_edac.c
> @@ -13,6 +13,8 @@
> #include "edac_module.h"
>
> #define ECC_CS_COUNT_REG 0x18
> +#define LOONGSON_EDAC_DSM_UUID "65d0431b-7eb8-46df-b914-b7d568553140"
> +#define LOONGSON_EDAC_DSM_FUNC_GET_DIMM_SIZE 1
Are you serious? Can you make that define longer?!?
Didn't I already told you to zap all those "loongson" prefixes from static
objects?
>
> /* Memory controller index invalid due to inability to read it from ACPI, etc */
> #define MC_IDX_INVALID BIT(16)
> @@ -68,13 +70,39 @@ static void loongson_check(struct mem_ctl_info *mci)
> 0, 0, 0, 0, 0, -1, "error", other_detail);
> }
> static void dimm_config_init(struct mem_ctl_info *mci)
> {
> struct dimm_info *dimm;
> + struct device *dev = mci->pdev;
> u32 size, npages;
This tree's preferred ordering of variable declarations at the beginning of
a function is reverse fir tree order::
struct long_struct_name *descriptive_name;
unsigned long foo, bar;
unsigned int tmp;
int ret;
The above is faster to parse than the reverse ordering::
int ret;
unsigned int tmp;
unsigned long foo, bar;
struct long_struct_name *descriptive_name;
And even more so than random ordering::
unsigned long foo, bar;
int ret;
struct long_struct_name *descriptive_name;
unsigned int tmp;
I went and did it for you ontop again.
Please make sure you go over the changes I did and keep them in mind next time
you send patches.
---
From: Wang Jinwei <wangjinwei@xxxxxxxxxxx>
Date: Wed, 18 Nov 2026 11:03:29 +0800
Subject: [PATCH] EDAC/loongson: Get DIMM size from ACPI _DSM method
Retrieve DIMM size from the ACPI _DSM method instead of using hardcoded
values.
The DIMM size is passed from UEFI through ACPI OperationRegion and _DSM
method, enabling correct display of memory size in:
/sys/devices/system/edac/mc/mc*/size_mb
[ bp:
- Massage commit message, drop text explaining what the patch does
- Zap insanely long define
- Zap loongson prefix from more static objects
]
Signed-off-by: Wang Jinwei <wangjinwei@xxxxxxxxxxx>
Signed-off-by: Qunqin Zhao <zhaoqunqin@xxxxxxxxxxx>
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Reviewed-by: Huacai Chen <chenhuacai@xxxxxxxxxxx>
Link: https://patch.msgid.link/20261118030330.25779-4-zhaoqunqin@xxxxxxx
---
drivers/edac/loongson_edac.c | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c
index d9c86d7e721b..250eba136655 100644
--- a/drivers/edac/loongson_edac.c
+++ b/drivers/edac/loongson_edac.c
@@ -13,6 +13,7 @@
#include "edac_module.h"
#define ECC_CS_COUNT_REG 0x18
+#define DSM_UUID "65d0431b-7eb8-46df-b914-b7d568553140"
/* Memory controller index invalid due to inability to read it from ACPI, etc */
#define MC_IDX_INVALID BIT(16)
@@ -68,13 +69,40 @@ static void loongson_check(struct mem_ctl_info *mci)
0, 0, 0, 0, 0, -1, "error", other_detail);
}
+static u32 get_dimm_size_acpi(struct device *dev)
+{
+ acpi_handle handle = ACPI_HANDLE(dev);
+ union acpi_object *obj;
+ u32 size_mb = 1;
+ guid_t guid;
+
+ if (!handle)
+ return size_mb;
+
+ if (guid_parse(DSM_UUID, &guid))
+ return size_mb;
+
+ /* 1 = DSM get DIMM size */
+ obj = acpi_evaluate_dsm(handle, &guid, 0, 1, NULL);
+ if (!obj)
+ return size_mb;
+
+ if (obj->type == ACPI_TYPE_INTEGER)
+ size_mb = (u32)obj->integer.value;
+
+ ACPI_FREE(obj);
+
+ return size_mb;
+}
+
static void dimm_config_init(struct mem_ctl_info *mci)
{
+ struct device *dev = mci->pdev;
struct dimm_info *dimm;
u32 size, npages;
- /* size not used */
- size = -1;
+ size = get_dimm_size_acpi(dev);
+
npages = MiB_TO_PAGES(size);
dimm = edac_get_dimm(mci, 0, 0, 0);
--
2.53.0
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette