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

From: Huacai Chen

Date: Wed Aug 05 2026 - 09:42:48 EST


Hi, Qunqin,

Replace "get" with "Get" in the subject line.


Huacai

On Wed, Aug 5, 2026 at 5:09 PM Qunqin Zhao <zhaoqunqin@xxxxxxxxxxx> 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.
>
> 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 abfc1e60e0..dd26153a9b 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;
> @@ -66,13 +68,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.3
>