From patchwork Thu Feb 16 18:20:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 58198 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp457477wrn; Thu, 16 Feb 2023 10:24:23 -0800 (PST) X-Google-Smtp-Source: AK7set/0EYORgR7toiT0vr4HRy5BoosbnPV2ztejNaIaZ4PyY9ZQynPnQA/NtjWgbyVGjRKiyFTF X-Received: by 2002:a17:903:88d:b0:19a:95ab:6b38 with SMTP id kt13-20020a170903088d00b0019a95ab6b38mr6428639plb.1.1676571863386; Thu, 16 Feb 2023 10:24:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676571863; cv=none; d=google.com; s=arc-20160816; b=n0I0IUH1mD4lDSA0NgwD2zFG5lpRtenkF1QoIrHxrZ1LUlwofMYrUHA21GxqTB0uEk +XD0GTO6KF5pCca+zWdTS6dXTDeKRy/xMU+k3FFxxrBK1hrVFRSA7gB1rQYzhohM5vUA wiXzuRfRKg4cWTUwJQQNJgoc/BTDKUpDcdJGDY48AXQLAWh21GSgZxz6iZ2WYXIEVEHD H2yHxCWm2QONjgXxN9SS01Q69HtGrsh8g9WQZdxcCIxVCw3NlKRVsLsYi7v5qioZMBXk 0pY1ZBEfAWapEARLDRWr/AI9z4Mc/56fFnC/2uxAYfP8VqMRFfsDHq7EGs0DaWT3l+UV /q/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GipxeDCOyjMj8YF40M4Hg7LI5rDefQ4n1sWRXQ5Wf4A=; b=m5gNdaH+1aKnee5711+8r0xNRYazc5lJ9ahLCPa3hmfRiU2jaNJR/5zxdq9XeRQ9Za 69hrSdJ2W+2sTfFjF8VbFoFaWVglzHiJhpQCRNumICZ27rAdDwOKZhX9O0Ht9L2xMsfT jQUby4B9PsjF8K05HmGb4RK+72uVajKke3Tznkp/gOEy8b0IemGTYkT8O+QVQWWLEYu+ S6W+zkv3PrrH7noo7nFlEf7sdi+rqN5fSRWzUvtF+PeFb3ghbKSAzGylMj7SGuyZOT5u wLBzTVEJHbQyVLPyZ8Oo2vBluvkFFR6MVwKw2dTT4APE6lOlyEgp6+4o3cmMTRKkEjk8 LEmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="eEFXo/Gf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a170902f54200b001968a5d4107si2431831plf.398.2023.02.16.10.24.09; Thu, 16 Feb 2023 10:24:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="eEFXo/Gf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230350AbjBPSWh (ORCPT + 99 others); Thu, 16 Feb 2023 13:22:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230256AbjBPSWO (ORCPT ); Thu, 16 Feb 2023 13:22:14 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3B4F50ADD for ; Thu, 16 Feb 2023 10:21:46 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id bx22so2712451pjb.3 for ; Thu, 16 Feb 2023 10:21:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GipxeDCOyjMj8YF40M4Hg7LI5rDefQ4n1sWRXQ5Wf4A=; b=eEFXo/GfQ56r4rtPgsxzNpFtJ23EjjcqYMMKhNbgLjE2Uuuy6P1bpuyH7mca/UbFYP aBNx3N2EIanq/lyuvYX2QMPg6Z1XipqO6QH1D/VjXzNzHfwBixUTZ/HkyjgfC9haFo78 Y12zsDunSkOjC4xURoqcxMZVCuD9ZLuBo70InXbPD6zU79CNTJXTYKIqcnJ1InzY+flJ //f7yL3N67uDxSS8o5mkf0Pe86BtKQRee5sbU4av6NbYmLZowEkxCR9khQ3johCdCu8S KY1xIiFS6em7YokS3n0jAZZwM4ZAuhjIaWBjjPllKiungJ3uK7QAE9DuaATKsqxVIfyc phdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GipxeDCOyjMj8YF40M4Hg7LI5rDefQ4n1sWRXQ5Wf4A=; b=46mEJe8olB0Gb6FWWcDsGiFrqouJCYesTnxfoXgE12KTCcHm6XQqSWWwQm8H95Q17/ ZOGgQsdAi4alWXLXb099SbZxV4N8mHgUlZXHh2UxAHlKi5mRo8zpm59JyoS9DuMygRTn wRIpdTnTI967X7EsyHRYvs5B6BgivMCBAhOVLAINQFrlT5BFC+VOQRwZyg/rpsx/yoZb 1JK0wNxyJp3HsIABirl7Tm33rwxJpR1NgLwrgEB9auLP4egMhNBbL89wHb4soCrXZ4y+ 72pb44qu+qx20nOF7BSHRssxhrOpyUUl1Q1mduMXcP8eTZxBMQ2I5w7NKCog3ME4bHFW QBlA== X-Gm-Message-State: AO0yUKVUXywJj0lz6iYy8vaA/GIvwnF9im8g5Ty9hUVvolaBVxAyrX7w WfoUsFAuO2t34LDxpEAyxiasxg== X-Received: by 2002:a05:6a20:6a0c:b0:9f:3197:bfa1 with SMTP id p12-20020a056a206a0c00b0009f3197bfa1mr7989098pzk.7.1676571705447; Thu, 16 Feb 2023 10:21:45 -0800 (PST) Received: from kerodi.Dlink ([49.206.14.226]) by smtp.gmail.com with ESMTPSA id n21-20020a637215000000b004dff15fc121sm1517574pgc.36.2023.02.16.10.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 10:21:45 -0800 (PST) From: Sunil V L To: Palmer Dabbelt , Albert Ou , Paul Walmsley , "Rafael J . Wysocki" , Len Brown , Thomas Gleixner , Marc Zyngier , Jonathan Corbet Cc: linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Conor Dooley , Andrew Jones , Anup Patel , Atish Patra , Sunil V L , "Rafael J . Wysocki" Subject: [PATCH V2 11/21] RISC-V: ACPI: Add a function to retrieve the hartid Date: Thu, 16 Feb 2023 23:50:33 +0530 Message-Id: <20230216182043.1946553-12-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216182043.1946553-1-sunilvl@ventanamicro.com> References: <20230216182043.1946553-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758013018245099862?= X-GMAIL-MSGID: =?utf-8?q?1758013018245099862?= The hartid is in the RINTC structure of the MADT table. Instead of parsing the ACPI table every time, cache it and provide a function to read it. Signed-off-by: Sunil V L Acked-by: Rafael J. Wysocki --- arch/riscv/include/asm/acpi.h | 8 +++++ arch/riscv/kernel/acpi.c | 55 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h index 3c3a8ac3b37a..b9d7b713fb43 100644 --- a/arch/riscv/include/asm/acpi.h +++ b/arch/riscv/include/asm/acpi.h @@ -67,6 +67,9 @@ int acpi_numa_get_nid(unsigned int cpu); static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; } #endif /* CONFIG_ACPI_NUMA */ +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu); + +u32 get_acpi_id_for_cpu(int cpu); #else static inline int acpi_get_riscv_isa(struct acpi_table_header *table, unsigned int cpu, const char **isa) @@ -74,6 +77,11 @@ static inline int acpi_get_riscv_isa(struct acpi_table_header *table, return -EINVAL; } +static inline u32 get_acpi_id_for_cpu(int cpu) +{ + return -1; +} + #endif /* CONFIG_ACPI */ #endif /*_ASM_ACPI_H*/ diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c index 81d448c41714..13b26c87c136 100644 --- a/arch/riscv/kernel/acpi.c +++ b/arch/riscv/kernel/acpi.c @@ -24,6 +24,61 @@ EXPORT_SYMBOL(acpi_disabled); int acpi_pci_disabled = 1; /* skip ACPI PCI scan and IRQ initialization */ EXPORT_SYMBOL(acpi_pci_disabled); +static unsigned int intc_count; +static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS]; + +static int acpi_parse_madt_rintc(union acpi_subtable_headers *header, const unsigned long end) +{ + struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header; + + if (!(rintc->flags & ACPI_MADT_ENABLED)) + return 0; + + cpu_madt_rintc[intc_count++] = *rintc; + + return 0; +} + +static int acpi_init_rintc_array(void) +{ + if (acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_madt_rintc, 0) > 0) + return 0; + + pr_info("No valid RINTC entries exist\n"); + return -ENODEV; +} + +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu) +{ + static bool rintc_init_done; + unsigned int i; + + if (!rintc_init_done) { + if (acpi_init_rintc_array()) { + pr_err("Failed to initialize RINTC array\n"); + return NULL; + } + rintc_init_done = true; + } + + for (i = 0; i < intc_count; i++) { + if (cpu_madt_rintc[i].hart_id == cpuid_to_hartid_map(cpu)) + return &cpu_madt_rintc[i]; + } + + return NULL; +} + +u32 get_acpi_id_for_cpu(int cpu) +{ + struct acpi_madt_rintc *rintc = acpi_cpu_get_madt_rintc(cpu); + + if (!rintc) + return -1; + + return rintc->uid; +} + /* * __acpi_map_table() will be called before paging_init(), so early_ioremap() * or early_memremap() should be called here to for ACPI table mapping.