From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 58F48D35157 for ; Wed, 1 Apr 2026 08:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=d0vH6zCv/2GLgDh03b9erJbXr5hT1Px7m8rmk60nqik=; b=JzRx8kgSvWAyC0 qKpvJ4mqcHSzL++eVzGbLm1ATgXyau98qhxARjQTfGsMAVfhkRLET1BME/7PWL5VRFSYooLgeCt0C ZHs8N3nR+wbBvXFqj4rtW07g2fH7jtUWKfTmRHu2rz2SuzniwZ3CJmJ0SKdootG7XMRhc/RccHvHw 2zSSpefWSlaQJzSrte0dlJxwC0edAUgSNZV2PkQXAM6jBihjoqa+QB+nrh55opfYK6W4FUK2W0GlW 4E73l5/b1+at8ZxsDqFk15nA+nRZLepjf7EnPvT2v27Ak6sWYPqhTgIoQzzBGoNCU6/Jw5jLkwPLV V/wBXBZzHle5AJ3KgM3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w7qlR-0000000EHj3-1a3B; Wed, 01 Apr 2026 08:17:25 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w7qlN-0000000EHdJ-3pqX; Wed, 01 Apr 2026 08:17:23 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=BMMryEb1CdnOx2gMiVv+9iHKONhR3XK5c+5CZUibkPo=; b=l/7oJpMqJuYSGHZyOqLiw5LD07h+45LWAipYVAvEt9pYxSp4UxJSqwXgX66M8/EZ74aeSBY3M qLpVsSs+rpKpxDOoVmFTloYQFQ4DUIG80JTpBOmlHJ7rSI3KUDZxGFyGCXDxs8sVu0UH3BlI+It fJwAj4fQtMaqP5gUwirfIBk= Received: from canpmsgout11.his.huawei.com (unknown [172.19.92.148]) by szxga01-in.huawei.com (SkyGuard) with ESMTPS id 4flyWd4trCz1BG5q; Wed, 1 Apr 2026 16:17:01 +0800 (CST) dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=BMMryEb1CdnOx2gMiVv+9iHKONhR3XK5c+5CZUibkPo=; b=l/7oJpMqJuYSGHZyOqLiw5LD07h+45LWAipYVAvEt9pYxSp4UxJSqwXgX66M8/EZ74aeSBY3M qLpVsSs+rpKpxDOoVmFTloYQFQ4DUIG80JTpBOmlHJ7rSI3KUDZxGFyGCXDxs8sVu0UH3BlI+It fJwAj4fQtMaqP5gUwirfIBk= Received: from mail.maildlp.com (unknown [172.19.163.163]) by canpmsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4flyNJ5zjPzKm91; Wed, 1 Apr 2026 16:10:40 +0800 (CST) Received: from kwepemk500009.china.huawei.com (unknown [7.202.194.94]) by mail.maildlp.com (Postfix) with ESMTPS id 743394048B; Wed, 1 Apr 2026 16:16:52 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by kwepemk500009.china.huawei.com (7.202.194.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 1 Apr 2026 16:16:50 +0800 From: Chengwen Feng To: Bjorn Helgaas , Catalin Marinas , Will Deacon , "Rafael J . Wysocki" Subject: [PATCH RESEND v10 3/8] RISC-V: ACPI: Add acpi_get_cpu_uid() for unified ACPI CPU UID retrieval Date: Wed, 1 Apr 2026 16:16:35 +0800 Message-ID: <20260401081640.26875-4-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260401081640.26875-1-fengchengwen@huawei.com> References: <20260401081640.26875-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk500009.china.huawei.com (7.202.194.94) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260401_011722_274706_CBAFB442 X-CRM114-Status: GOOD ( 17.04 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , x86@kernel.org, liuyonglong@huawei.com, anshuman.khandual@arm.com, linux-doc@vger.kernel.org, Kees Cook , linux-pci@vger.kernel.org, Dave Hansen , Eric.VanTassell@amd.com, fengchengwen@huawei.com, Somnath Kotur , Kai Huang , Kevin Loughlin , punit.agrawal@oss.qualcomm.com, "H . Peter Anvin" , Ilkka Koskinen , WANG Xuerui , Thorsten Blum , linux-acpi@vger.kernel.org, Jonathan Corbet , masahiroy@kernel.org, Yanteng Si , linux-riscv@lists.infradead.org, Peter Zijlstra , Pawan Gupta , linux-arm-kernel@lists.infradead.org, xen-devel@lists.xenproject.org, Zheyun Shen , Len Brown , Tom Lendacky , Thomas Huth , ryan.roberts@arm.com, "Ahmed S . Darwish" , Ma Ke , suzuki.poulose@arm.com, James Clark , Wei Huang , Besar Wicaksono , loongarch@lists.linux.dev, Jonathan Cameron , Sohil Mehta , Boris Ostrovsky , Xin Li , Andy Gospodarek , wanghuiqiang@huawei.com, Juergen Gross , wangyuquan1236@phytium.com.cn, Sean Christopherson , guohanjun@huawei.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-perf-users@vger.kernel.org, wangzhou1@hisilicon.com, Thomas Gleixner , heinrich.schuchardt@canonical.com, chenl311@chinatelecom.cn, Robin Murphy Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org As a step towards unifying the interface for retrieving ACPI CPU UID across architectures, introduce a new function acpi_get_cpu_uid() for riscv. While at it, add input validation to make the code more robust. And also update acpi_numa.c and rhct.c to use the new interface instead of the legacy get_acpi_id_for_cpu(). Cc: stable@vger.kernel.org Signed-off-by: Chengwen Feng Reviewed-by: Jonathan Cameron --- arch/riscv/include/asm/acpi.h | 1 + arch/riscv/kernel/acpi.c | 16 ++++++++++++++++ arch/riscv/kernel/acpi_numa.c | 9 ++++++--- drivers/acpi/riscv/rhct.c | 7 ++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h index 6e13695120bc..f3520cc85af3 100644 --- a/arch/riscv/include/asm/acpi.h +++ b/arch/riscv/include/asm/acpi.h @@ -65,6 +65,7 @@ static inline u32 get_acpi_id_for_cpu(int cpu) { return acpi_cpu_get_madt_rintc(cpu)->uid; } +int acpi_get_cpu_uid(unsigned int cpu, u32 *uid); int acpi_get_riscv_isa(struct acpi_table_header *table, unsigned int cpu, const char **isa); diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c index 71698ee11621..322ea92aa39f 100644 --- a/arch/riscv/kernel/acpi.c +++ b/arch/riscv/kernel/acpi.c @@ -337,3 +337,19 @@ int raw_pci_write(unsigned int domain, unsigned int bus, } #endif /* CONFIG_PCI */ + +int acpi_get_cpu_uid(unsigned int cpu, u32 *uid) +{ + struct acpi_madt_rintc *rintc; + + if (cpu >= nr_cpu_ids) + return -EINVAL; + + rintc = acpi_cpu_get_madt_rintc(cpu); + if (!rintc) + return -ENODEV; + + *uid = rintc->uid; + return 0; +} +EXPORT_SYMBOL_GPL(acpi_get_cpu_uid); diff --git a/arch/riscv/kernel/acpi_numa.c b/arch/riscv/kernel/acpi_numa.c index 130769e3a99c..6a2d4289f806 100644 --- a/arch/riscv/kernel/acpi_numa.c +++ b/arch/riscv/kernel/acpi_numa.c @@ -37,11 +37,14 @@ static int __init acpi_numa_get_nid(unsigned int cpu) static inline int get_cpu_for_acpi_id(u32 uid) { - int cpu; + u32 cpu_uid; + int ret; - for (cpu = 0; cpu < nr_cpu_ids; cpu++) - if (uid == get_acpi_id_for_cpu(cpu)) + for (int cpu = 0; cpu < nr_cpu_ids; cpu++) { + ret = acpi_get_cpu_uid(cpu, &cpu_uid); + if (ret == 0 && uid == cpu_uid) return cpu; + } return -EINVAL; } diff --git a/drivers/acpi/riscv/rhct.c b/drivers/acpi/riscv/rhct.c index caa2c16e1697..8f3f38c64a88 100644 --- a/drivers/acpi/riscv/rhct.c +++ b/drivers/acpi/riscv/rhct.c @@ -44,10 +44,15 @@ int acpi_get_riscv_isa(struct acpi_table_header *table, unsigned int cpu, const struct acpi_rhct_isa_string *isa_node; struct acpi_table_rhct *rhct; u32 *hart_info_node_offset; - u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu); + u32 acpi_cpu_id; + int ret; BUG_ON(acpi_disabled); + ret = acpi_get_cpu_uid(cpu, &acpi_cpu_id); + if (ret != 0) + return ret; + if (!table) { rhct = acpi_get_rhct(); if (!rhct) -- 2.17.1 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv