Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6362182rwl; Tue, 4 Apr 2023 11:24:52 -0700 (PDT) X-Google-Smtp-Source: AKy350bfzREgU/ana3qEfuRY+WKVRIf5V1SsFqURDG+oxw+MD91NMJ4t3Dpaud91XxeoizvjFiZ5 X-Received: by 2002:a17:90a:65c4:b0:240:d00f:310f with SMTP id i4-20020a17090a65c400b00240d00f310fmr2889263pjs.1.1680632692553; Tue, 04 Apr 2023 11:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680632692; cv=none; d=google.com; s=arc-20160816; b=W/8aBplSUy+D/YEeIaaIP1ammZRLVQpZOrfacei0PYTp7bbHCcjrOpzLhM02Q8r1EM KOmi4/LCDp5IskHTyNgi7WcUDgBlEow1tcl7f/DOjVqm8DjHz08zBSoh3SfUEYMOOa3y t+53sKlcuiw6+8ANWWSYf8VSn/BWyhYoNSAciezfErQ/OUVcUshctQMxE8tnsj19BmiV Hlcc3DcPYgN0y6lnCY8XfvslUwC+GknzohvnX/HvKa00LZiEcIB+s6AV00qpsqKXJKre w/S6gpVs6EdiA/xSXOF07hH+Z8/rVY4HDl8XxaQW9Xw3orH6Scv4lkyS/7vBMVEInzKQ Fpug== 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=XGonri/T19XQF2naGXJvqqLnbSM1YN1GWyJxGmsm0G8=; b=jqK6q41vnIE+lnvJenwYVw0EWdbLqYGv6FGcboZavVfYyhgg1/ZdOYTrx2CJZfxO3+ ubwaWenPAagLYjdj5fvC0+kFNZmwAuJxV7IQt0NqzH8Mg0/FQzp4VqnC6Dly5535KOjl +9hO6FwrNRHOjdQ923bjSRvBb4kT0ap6TFirQOGl/Zxnod6eAO0XWDYuwmdOwsCVDTbN k2o6lHVhwe+5dQcY6qHIUcgU7+UKoUnZWIg+wF9jZXB9I3I5Jo5k5EP8CiHdgAwzUUCs XeA6KFlHcA0szWyHZXhZXkUlFmAE66N0r5HO1ig4CYoIK9Wj750mJpl9g7t+i0TT2/RR 4zqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=jlU6cVDR; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x4-20020a17090a9dc400b00232f57260c1si2084297pjv.1.2023.04.04.11.24.39; Tue, 04 Apr 2023 11:24:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=jlU6cVDR; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236347AbjDDSXF (ORCPT + 99 others); Tue, 4 Apr 2023 14:23:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236425AbjDDSWq (ORCPT ); Tue, 4 Apr 2023 14:22:46 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 634DE5FE5 for ; Tue, 4 Apr 2023 11:22:05 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id le6so32121933plb.12 for ; Tue, 04 Apr 2023 11:22:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680632524; 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=XGonri/T19XQF2naGXJvqqLnbSM1YN1GWyJxGmsm0G8=; b=jlU6cVDRpS7N+hbCajzQ5MBLlupJaHtqzIdkqiPTdgeHP85eBAGnt3IyBNq6jANDpp cwqU4j6QhylWaoAD+i+RvRnFnexq1wQ7hFZtqJGwVlBRMJgGNeR4vpKazmlZG0XQ2Zrn InczBkrjePyvmC01JogcOj/miAoB9IP8R8uwJH07fk96+hULRShilpkKLxZorAWOWvPs 4lTqHyEsR8TapU0eESkEuqvZH3dKe12+qtas+XnrbS95Qwlo+rOrfF8OWmXZ214KwCeV 0u+YSRiu7NhnExNyDKcz1HrlVGKzxl7vbNHloZt2ohNHTePS3ZURQLDXTYnysnOHTTCx aDcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680632524; 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=XGonri/T19XQF2naGXJvqqLnbSM1YN1GWyJxGmsm0G8=; b=NU5Ff6RYcOQ0TNGKNJ2tiI5v0Djs17KbzmbR3H6WMRqpqB0DAKJzVaSGIEqeiJVama Vf4Mm+GzCvI84aUfBlCCXqwql7e8jyl1dSAEz54KmDY94/QD3UVZkornlt7QGh/BFiqL beBI9cpnxy0b0M4nO0orUQuDTtRi2jmsI6zrbsjkrArXT/1/9L+yMfCsCeRaXUvJwT+v U+EDEYqU7RehqJMqDgoqCQKpInVWNaPIXrzDL0jIAnEE3OzNelJ0n9wRu70KeS6Z5+5h IxLMrXXxOS96W8kLLYfTGDgyQymb5F66RE704kuzGqJJ2fshvk53TbbjmT1hUdbTCt8a LnYA== X-Gm-Message-State: AAQBX9eXq5EUf3V8b2xtJNLrAnNXYe0+yJt0T1FMhCe7808iYJ+VVPAP KcfLmodRpg5dOk586GSbwefZzg== X-Received: by 2002:a05:6a20:930f:b0:d9:7af9:6a82 with SMTP id r15-20020a056a20930f00b000d97af96a82mr90355pzh.9.1680632524615; Tue, 04 Apr 2023 11:22:04 -0700 (PDT) Received: from localhost.localdomain ([106.51.184.50]) by smtp.gmail.com with ESMTPSA id o12-20020a056a001bcc00b0062dcf5c01f9sm9018524pfw.36.2023.04.04.11.21.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:22:04 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, linux-crypto@vger.kernel.org, platform-driver-x86@vger.kernel.org, llvm@lists.linux.dev Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Len Brown , Daniel Lezcano , Thomas Gleixner , Weili Qian , Zhou Wang , Herbert Xu , Marc Zyngier , Maximilian Luz , Hans de Goede , Mark Gross , Nathan Chancellor , Nick Desaulniers , Tom Rix , "Rafael J . Wysocki" , "David S . Miller" , Sunil V L , "Rafael J . Wysocki" , Conor Dooley Subject: [PATCH V4 11/23] RISC-V: smpboot: Add ACPI support in smp_setup() Date: Tue, 4 Apr 2023 23:50:25 +0530 Message-Id: <20230404182037.863533-12-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230404182037.863533-1-sunilvl@ventanamicro.com> References: <20230404182037.863533-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=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-crypto@vger.kernel.org Enable SMP boot on ACPI based platforms by using the RINTC structures in the MADT table. Signed-off-by: Sunil V L Acked-by: Rafael J. Wysocki Reviewed-by: Conor Dooley --- arch/riscv/include/asm/acpi.h | 2 + arch/riscv/kernel/smpboot.c | 72 ++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h index 2b3e78d5a13b..b26ba911f0a9 100644 --- a/arch/riscv/include/asm/acpi.h +++ b/arch/riscv/include/asm/acpi.h @@ -63,6 +63,8 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu); u32 get_acpi_id_for_cpu(int cpu); int acpi_get_riscv_isa(struct acpi_table_header *table, unsigned int cpu, const char **isa); + +static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; } #else static inline int acpi_get_riscv_isa(struct acpi_table_header *table, unsigned int cpu, const char **isa) diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index 26214ddefaa4..6a854b200b72 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -8,6 +8,7 @@ * Copyright (C) 2017 SiFive */ +#include #include #include #include @@ -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, acpi_numa_get_nid(cpu_count)); + 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, acpi_numa_get_nid(cpu_count)); + 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