Message ID | 20230303133647.845095-11-sunilvl@ventanamicro.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp412412wrd; Fri, 3 Mar 2023 05:39:20 -0800 (PST) X-Google-Smtp-Source: AK7set8flG5rgHFNGW9C/WeONKNQHfNmZbBMJ4PXEZ7KskqqdHL/2fGdGmh/WTnWJa/YQthlcuTa X-Received: by 2002:a17:90a:1a0b:b0:234:190d:e636 with SMTP id 11-20020a17090a1a0b00b00234190de636mr1836458pjk.8.1677850759957; Fri, 03 Mar 2023 05:39:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677850759; cv=none; d=google.com; s=arc-20160816; b=r3RR1HZqRiBS4D7io1JtiJBG+qSMCalzeTjdRYLF/9qj+PJb5ZJ5IxFad80A7NJHXY bEKXno9R1EVAZWRHy03oJ5w0vMck+6j9Cb6zmJf8wu2gQChUZYtCHhX+/8vNECa5xTRY 7TGFHmLX8YNZSVp5mhyizNAV7VvX9iva6m9FAD6O+JxQEJURaaFOIhMxEUWZ1amER8ZJ MQPIwrwfUadKKcCtXmcOuQbGo6quZNYK4N3o3S1t3auE6g5IA/Px/d2xEBFuNs2RuY4m Lk6cXtt1PkCDQhGlEoNspkj2BBQTXmUu1aEN5yND/QZI/gCYYIC1cZ6Fbnub4hhtpB8T yPWA== 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=V8QTnerj7bYskLlpj17RAvWj070+do7b32kQaiggteA=; b=PXDtEh2vnoaUzuMcwzp9B4TfJdJ+pRnK1Vc9Z2gqwHHF6cgIKEWycPyAm3KaXNCCca St1wPr1IRBDpKtKu/io8RysMkTiWhxTtm1Re6j6/TcJBCYpy9TgcyE7eQJLdGoFaN4K3 hGAy3EIhi+jTANMnmVnaLTP3SpKz0CnRfFF8TPkTKTeLqhhTai1OBSP16dN+JXXbaFD5 aC1dIOY+q/w5a9pVB+ABfGWEIbUXyoi9SiWd7DNbpVZhq/HhtoRy0qodWdMWpWr2lLWZ uCWnseBEIdBHFq/IgWuud3z7JQNJsrKSoJanak7b1t2Ug9uQuuLcoEk+gY19GlntxKwt Ojpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=RgJqREjh; 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-20020a17090a3d0200b00233d3b31b61si4767915pjc.140.2023.03.03.05.39.06; Fri, 03 Mar 2023 05:39:19 -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=RgJqREjh; 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 S231337AbjCCNiu (ORCPT <rfc822;davidbtadokoro@gmail.com> + 99 others); Fri, 3 Mar 2023 08:38:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231244AbjCCNiW (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 3 Mar 2023 08:38:22 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ED007042B for <linux-kernel@vger.kernel.org>; Fri, 3 Mar 2023 05:37:46 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id u5so2662455plq.7 for <linux-kernel@vger.kernel.org>; Fri, 03 Mar 2023 05:37:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1677850663; 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=V8QTnerj7bYskLlpj17RAvWj070+do7b32kQaiggteA=; b=RgJqREjhLWiT9HAwULg1TCKy3elPJioYn7o58gezsP6MvD88qFFcqTs8G4yvOZl1+x uACE7bocF1Nt5qSzzsw3Id8jszuDh4dCI34HMitP5OGUEy0rypJR0r1L+EWVBdLdPJOK L3W3Af6kXSq9+OjQxCsfQMpWrgqlvh/c3/grFMzOVy/bM+ARSvmoksPof6W9e0RUXsvj srUJfWInlYLWE1JJR6JImY+rNgxvrmC3zyQYnnq9efC8Y2f1zyc1D+I+Cj7T9ltu79mh t8GR2B13Tgo6izfj2S+7J1Chr1wjxfZs9uxJju+wjkhw0lZhR7quW1egY3yUltQV2PkU Rfgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677850663; 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=V8QTnerj7bYskLlpj17RAvWj070+do7b32kQaiggteA=; b=UO1x0EqpEPjgwq2eG93hN9O1txm9CUZSj4WRUt0LuZMgHCOtDwGp+MdJ7yTEXzOKio G/ANuZMav7ixEHtWUdWk5JNpZVng+9fFnqjxmsHENmr877K5+TZyrUVG8uXD2FhZqMe6 F14DdXiZwK0MrivgtKzNVTGUX41c0osJQ5R3Nd1RGHIHvsHwjuw5+UNq41AuVeF1pFvb qp1JT/xGUSJq9b1SNZ3espey3BmefRHwhsYyw4krfieyxSk+mG3/z/HuIUyTvmlotN2t KH3TE9imXqVMmYBdp+AnVRVPHZYJ9qicc5QNdkN9dIrzJj/mGu0LfVlXMK5KMu/enaZi fBAA== X-Gm-Message-State: AO0yUKWtfLgD5rudLSqVuDVdfOWK2aPZ9WBtwx+fszjga+0Nqvf9ZaCn 62CoE/NfknNj7rg6HoD4ZAdAow== X-Received: by 2002:a17:902:d4c8:b0:19e:7bce:cc65 with SMTP id o8-20020a170902d4c800b0019e7bcecc65mr1963990plg.66.1677850663667; Fri, 03 Mar 2023 05:37:43 -0800 (PST) Received: from localhost.localdomain ([49.206.14.226]) by smtp.gmail.com with ESMTPSA id m9-20020a170902768900b0019ac5d3ee9dsm1533125pll.157.2023.03.03.05.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 05:37:43 -0800 (PST) From: Sunil V L <sunilvl@ventanamicro.com> To: linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, "Rafael J . Wysocki" <rafael@kernel.org>, Len Brown <lenb@kernel.org>, Thomas Gleixner <tglx@linutronix.de>, Marc Zyngier <maz@kernel.org>, Daniel Lezcano <daniel.lezcano@linaro.org>, Jonathan Corbet <corbet@lwn.net>, Anup Patel <apatel@ventanamicro.com>, Andrew Jones <ajones@ventanamicro.com>, Atish Patra <atishp@rivosinc.com>, 'Conor Dooley ' <conor.dooley@microchip.com>, Sunil V L <sunilvl@ventanamicro.com>, "Rafael J . Wysocki" <rafael.j.wysocki@intel.com> Subject: [PATCH V3 10/20] RISC-V: smpboot: Add ACPI support in smp_setup() Date: Fri, 3 Mar 2023 19:06:37 +0530 Message-Id: <20230303133647.845095-11-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230303133647.845095-1-sunilvl@ventanamicro.com> References: <20230303133647.845095-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759354038351795533?= X-GMAIL-MSGID: =?utf-8?q?1759354038351795533?= |
Series |
Add basic ACPI support for RISC-V
|
|
Commit Message
Sunil V L
March 3, 2023, 1:36 p.m. UTC
Enable SMP boot on ACPI based platforms by using the RINTC structures in the MADT table. Signed-off-by: Sunil V L <sunilvl@ventanamicro.com> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> --- arch/riscv/kernel/smpboot.c | 72 ++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-)
Comments
On Fri, Mar 03, 2023 at 07:06:37PM +0530, Sunil V L wrote: > Enable SMP boot on ACPI based platforms by using the RINTC > structures in the MADT table. > > Signed-off-by: Sunil V L <sunilvl@ventanamicro.com> > Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > Reviewed-by: Conor Dooley <conor.dooley@microchip.com> > --- > arch/riscv/kernel/smpboot.c | 72 ++++++++++++++++++++++++++++++++++++- > 1 file changed, 71 insertions(+), 1 deletion(-) > > diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c > index 26214ddefaa4..27047322d3bb 100644 > --- a/arch/riscv/kernel/smpboot.c > +++ b/arch/riscv/kernel/smpboot.c > @@ -8,6 +8,7 @@ > * Copyright (C) 2017 SiFive > */ > > +#include <linux/acpi.h> > #include <linux/arch_topology.h> > #include <linux/module.h> > #include <linux/init.h> > @@ -70,6 +71,72 @@ void __init smp_prepare_cpus(unsigned int max_cpus) > } > } > > +#ifdef CONFIG_ACPI > +static unsigned int cpu_count = 1; > + > +static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const unsigned long end) > +{ > + unsigned long hart; > + static bool found_boot_cpu; > + struct acpi_madt_rintc *processor = (struct acpi_madt_rintc *)header; > + > + /* > + * Each RINTC structure in MADT will have a flag. If ACPI_MADT_ENABLED > + * bit in the flag is not enabled, it means OS should not try to enable > + * the cpu to which RINTC belongs. > + */ > + if (!(processor->flags & ACPI_MADT_ENABLED)) > + return 0; > + > + if (BAD_MADT_ENTRY(processor, end)) > + return -EINVAL; > + > + acpi_table_print_madt_entry(&header->common); > + > + hart = processor->hart_id; > + if (hart == INVALID_HARTID) { > + pr_warn("Invalid hartid\n"); > + return 0; > + } > + > + if (hart == cpuid_to_hartid_map(0)) { > + BUG_ON(found_boot_cpu); > + found_boot_cpu = true; > + early_map_cpu_to_node(0, NUMA_NO_NODE); We should have kept static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; } and only dropped the #ifdef CONFIG_ACPI_NUMA int acpi_numa_get_nid(unsigned int cpu); #else ... #endif > + return 0; > + } > + > + if (cpu_count >= NR_CPUS) { > + pr_warn("NR_CPUS is too small for the number of ACPI tables.\n"); > + return 0; > + } > + > + cpuid_to_hartid_map(cpu_count) = hart; > + early_map_cpu_to_node(cpu_count, NUMA_NO_NODE); > + cpu_count++; > + > + return 0; > +} > + > +static void __init acpi_parse_and_init_cpus(void) > +{ > + int cpuid; > + > + cpu_set_ops(0); > + > + acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_rintc, 0); > + > + for (cpuid = 1; cpuid < nr_cpu_ids; cpuid++) { > + if (cpuid_to_hartid_map(cpuid) != INVALID_HARTID) { > + cpu_set_ops(cpuid); > + set_cpu_possible(cpuid, true); > + } > + } > +} > +#else > +#define acpi_parse_and_init_cpus(...) do { } while (0) > +#endif > + > static void __init of_parse_and_init_cpus(void) > { > struct device_node *dn; > @@ -118,7 +185,10 @@ static void __init of_parse_and_init_cpus(void) > > void __init setup_smp(void) > { > - of_parse_and_init_cpus(); > + if (acpi_disabled) > + of_parse_and_init_cpus(); > + else > + acpi_parse_and_init_cpus(); > } > > static int start_secondary_cpu(int cpu, struct task_struct *tidle) > -- > 2.34.1 > Thanks, drew
On Fri, Mar 03, 2023 at 04:49:20PM +0100, Andrew Jones wrote: > On Fri, Mar 03, 2023 at 07:06:37PM +0530, Sunil V L wrote: > > Enable SMP boot on ACPI based platforms by using the RINTC > > structures in the MADT table. > > > > Signed-off-by: Sunil V L <sunilvl@ventanamicro.com> > > Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > Reviewed-by: Conor Dooley <conor.dooley@microchip.com> > > --- > > arch/riscv/kernel/smpboot.c | 72 ++++++++++++++++++++++++++++++++++++- > > 1 file changed, 71 insertions(+), 1 deletion(-) > > > > diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c > > index 26214ddefaa4..27047322d3bb 100644 > > --- a/arch/riscv/kernel/smpboot.c > > +++ b/arch/riscv/kernel/smpboot.c > > @@ -8,6 +8,7 @@ > > * Copyright (C) 2017 SiFive > > */ > > > > +#include <linux/acpi.h> > > #include <linux/arch_topology.h> > > #include <linux/module.h> > > #include <linux/init.h> > > @@ -70,6 +71,72 @@ void __init smp_prepare_cpus(unsigned int max_cpus) > > } > > } > > > > +#ifdef CONFIG_ACPI > > +static unsigned int cpu_count = 1; > > + > > +static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const unsigned long end) > > +{ > > + unsigned long hart; > > + static bool found_boot_cpu; > > + struct acpi_madt_rintc *processor = (struct acpi_madt_rintc *)header; > > + > > + /* > > + * Each RINTC structure in MADT will have a flag. If ACPI_MADT_ENABLED > > + * bit in the flag is not enabled, it means OS should not try to enable > > + * the cpu to which RINTC belongs. > > + */ > > + if (!(processor->flags & ACPI_MADT_ENABLED)) > > + return 0; > > + > > + if (BAD_MADT_ENTRY(processor, end)) > > + return -EINVAL; > > + > > + acpi_table_print_madt_entry(&header->common); > > + > > + hart = processor->hart_id; > > + if (hart == INVALID_HARTID) { > > + pr_warn("Invalid hartid\n"); > > + return 0; > > + } > > + > > + if (hart == cpuid_to_hartid_map(0)) { > > + BUG_ON(found_boot_cpu); > > + found_boot_cpu = true; > > + early_map_cpu_to_node(0, NUMA_NO_NODE); > > We should have kept > > static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; } > > and only dropped the > > #ifdef CONFIG_ACPI_NUMA > int acpi_numa_get_nid(unsigned int cpu); > #else > ... > #endif > Okay, I thought we better add it when we enable NUMA with ACPI. > > + return 0; > > + } > > + > > + if (cpu_count >= NR_CPUS) { > > + pr_warn("NR_CPUS is too small for the number of ACPI tables.\n"); > > + return 0; > > + } > > + > > + cpuid_to_hartid_map(cpu_count) = hart; > > + early_map_cpu_to_node(cpu_count, NUMA_NO_NODE); > > + cpu_count++; > > + > > + return 0; > > +} > > + > > +static void __init acpi_parse_and_init_cpus(void) > > +{ > > + int cpuid; > > + > > + cpu_set_ops(0); > > + > > + acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_rintc, 0); > > + > > + for (cpuid = 1; cpuid < nr_cpu_ids; cpuid++) { > > + if (cpuid_to_hartid_map(cpuid) != INVALID_HARTID) { > > + cpu_set_ops(cpuid); > > + set_cpu_possible(cpuid, true); > > + } > > + } > > +} > > +#else > > +#define acpi_parse_and_init_cpus(...) do { } while (0) > > +#endif > > + > > static void __init of_parse_and_init_cpus(void) > > { > > struct device_node *dn; > > @@ -118,7 +185,10 @@ static void __init of_parse_and_init_cpus(void) > > > > void __init setup_smp(void) > > { > > - of_parse_and_init_cpus(); > > + if (acpi_disabled) > > + of_parse_and_init_cpus(); > > + else > > + acpi_parse_and_init_cpus(); > > } > > > > static int start_secondary_cpu(int cpu, struct task_struct *tidle) > > -- > > 2.34.1 > > > > Thanks, > drew
diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index 26214ddefaa4..27047322d3bb 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -8,6 +8,7 @@ * Copyright (C) 2017 SiFive */ +#include <linux/acpi.h> #include <linux/arch_topology.h> #include <linux/module.h> #include <linux/init.h> @@ -70,6 +71,72 @@ void __init smp_prepare_cpus(unsigned int max_cpus) } } +#ifdef CONFIG_ACPI +static unsigned int cpu_count = 1; + +static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const unsigned long end) +{ + unsigned long hart; + static bool found_boot_cpu; + struct acpi_madt_rintc *processor = (struct acpi_madt_rintc *)header; + + /* + * Each RINTC structure in MADT will have a flag. If ACPI_MADT_ENABLED + * bit in the flag is not enabled, it means OS should not try to enable + * the cpu to which RINTC belongs. + */ + if (!(processor->flags & ACPI_MADT_ENABLED)) + return 0; + + if (BAD_MADT_ENTRY(processor, end)) + return -EINVAL; + + acpi_table_print_madt_entry(&header->common); + + hart = processor->hart_id; + if (hart == INVALID_HARTID) { + pr_warn("Invalid hartid\n"); + return 0; + } + + if (hart == cpuid_to_hartid_map(0)) { + BUG_ON(found_boot_cpu); + found_boot_cpu = true; + early_map_cpu_to_node(0, NUMA_NO_NODE); + return 0; + } + + if (cpu_count >= NR_CPUS) { + pr_warn("NR_CPUS is too small for the number of ACPI tables.\n"); + return 0; + } + + cpuid_to_hartid_map(cpu_count) = hart; + early_map_cpu_to_node(cpu_count, NUMA_NO_NODE); + cpu_count++; + + return 0; +} + +static void __init acpi_parse_and_init_cpus(void) +{ + int cpuid; + + cpu_set_ops(0); + + acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_rintc, 0); + + for (cpuid = 1; cpuid < nr_cpu_ids; cpuid++) { + if (cpuid_to_hartid_map(cpuid) != INVALID_HARTID) { + cpu_set_ops(cpuid); + set_cpu_possible(cpuid, true); + } + } +} +#else +#define acpi_parse_and_init_cpus(...) do { } while (0) +#endif + static void __init of_parse_and_init_cpus(void) { struct device_node *dn; @@ -118,7 +185,10 @@ static void __init of_parse_and_init_cpus(void) void __init setup_smp(void) { - of_parse_and_init_cpus(); + if (acpi_disabled) + of_parse_and_init_cpus(); + else + acpi_parse_and_init_cpus(); } static int start_secondary_cpu(int cpu, struct task_struct *tidle)