[PATCH 2/3] EDAC/loongson: get DIMM size from ACPI _DSM method

From: Qunqin Zhao

Date: Thu Jul 30 2026 - 02:55:40 EST


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.

Cc: Dongyan Qian <qiandongyan@xxxxxxxxxxx>
Cc: Chao Li <lichao@xxxxxxxxxxx>
Signed-off-by: Wang Jinwei <wangjinwei@xxxxxxxxxxx>
Signed-off-by: Qunqin Zhao <zhaoqunqin@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 f2452e98f5..b458f81dfe 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

struct loongson_edac_pvt {
void __iomem *ecc_base;
@@ -69,13 +71,39 @@ static void edac_check(struct mem_ctl_info *mci)
0, 0, 0, 0, 0, -1, "error", other_detail);
}

+static u32 loongson_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(LOONGSON_EDAC_DSM_UUID, &guid))
+ return size_mb;
+
+ obj = acpi_evaluate_dsm(handle, &guid, 0,
+ LOONGSON_EDAC_DSM_FUNC_GET_DIMM_SIZE, 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 dimm_info *dimm;
+ struct device *dev = mci->pdev;
u32 size, npages;

- /* size not used */
- size = -1;
+ size = loongson_get_dimm_size_acpi(dev);
+
npages = MiB_TO_PAGES(size);

dimm = edac_get_dimm(mci, 0, 0, 0);
--
2.47.2