Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1559771rwd; Sun, 14 May 2023 22:53:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VMiRhBqQ29wcMl27YYhHc9PIzyF3fHqI9tZ6Qp5p1PUKlBFY8OLFbsqV51PesoXGm94aq X-Received: by 2002:a17:90b:3b8b:b0:252:7114:b37a with SMTP id pc11-20020a17090b3b8b00b002527114b37amr16055070pjb.47.1684129989632; Sun, 14 May 2023 22:53:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684129989; cv=none; d=google.com; s=arc-20160816; b=bDhcChfmwEt9i+G3eidzAGffgtHN4gY+hnLkzqYJagXQYZ2uHp9m8Kfg46SHPo3Glu mBVvBoi0ANvH0kc4BurlW/4phKV0/g3xhm2yMnoQb+C48JYzl5Fi5a14w+rwI+3kJl5E pHU1gpEL4PYWX+8CidaIpvRSEPX0guz8Z6PhALcO5cfpPUA7I+9Qe6+UCwjPNGlTbXHG tdx+OGpvEnClLFclMrMvOkJcSogJBvwTWJQT5v8ajMwmMoOY8gWOqgrqOBIF033AxrZn DKA+jRbRlDfSbP0zPP4xC9raf2n/zLJ16SWlTfbRkEB3xCnM/SoLPtGsHyjPz6/PccTD w9iA== 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=IOZQhaBTCz12V545SHDXdLyrBMlTmswFdV1zXLm6S/A=; b=GxsOjDcm+D+nYUbxHIzA6iZ8kYx+3n6IIolvtrhMiYtPT2nqQNJT1uGBcekQ3iEaYz atu/m84TRYj+MgEyI+7d/VLOvBmWz1rZBW6fcHVsD1mtF61No7SDk+xnp/8lV0TyaO+i 9NwJ6iVEhYXZnvNLCpGA3SqvKGtPPVzNPH1MFMlvdE/buuOTLxMkJka16ODSJRBDIDp6 +m8rEyf5Xr5pOY6Gjl4L6RvtX1AKiC3QOT3orOv67VzAQTF769c1OwMO7DAwveEFu4rY UCJOkAuptTeE5MzwtYDQ3g4ZVncouYajZXTw4eSUH8WSfL+l+M/k1bx7gbIF9o+BqueL iL9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=ZubYLK6A; 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 l186-20020a633ec3000000b0050f83aa181esi16211137pga.698.2023.05.14.22.52.56; Sun, 14 May 2023 22:53:09 -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=ZubYLK6A; 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 S238384AbjEOFwp (ORCPT + 99 others); Mon, 15 May 2023 01:52:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238553AbjEOFvr (ORCPT ); Mon, 15 May 2023 01:51:47 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EAEF3A8E for ; Sun, 14 May 2023 22:50:32 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1aaf7067647so83466185ad.0 for ; Sun, 14 May 2023 22:50:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1684129831; x=1686721831; 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=IOZQhaBTCz12V545SHDXdLyrBMlTmswFdV1zXLm6S/A=; b=ZubYLK6AhfJJ3ewIaZiB/Vc9A4y0gXVxLHOh+ufOe8gp3a7NBjZoz6GiImqdqBN0Qf 0UVkkE/ktkw91RhL5MRflcITMnW+pDUiR6puLaLszIdLxJ+c6oxTmEJgJiSjB83VQ8WH x2xfg5fWT2JwVcN563C7hvJ2fvKSpWvTG9lbb5TMzGZ5mecRJpdcu2voOKuOFgUHLkVz XHhIXvp6Y80F8BvMh6b2DevrHukcjLaf2+UayUkWamX/3VKNySOz+BWgaGjqaDa5IKwo dZGNLQV2qCIXqVUUZksNwga8sCbtQx9oW0hFNVaQs3nTGf87Q8gsky296vjZXa0bqWyN Fz3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684129831; x=1686721831; 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=IOZQhaBTCz12V545SHDXdLyrBMlTmswFdV1zXLm6S/A=; b=Te3Ifr4ByfuVxbau+LPC40OE4zBOBaw+V3kNp9rNWL5mu2wLiaRLFHPDwsYZukQoI9 sgyNcPQNsjMrn14JAVSCO3UMz7uJzNWfi1PS7tI0Vc6jzVNPNR5wtIS4HcaRYVWa4KRa mcRK8Nx4FBmV5+iavA8RY/yrTAZVbJe7jU6UAhx2BnrqgOl2y79jYHAKMMjV5W8F2WrF DVj/qO8ux+DBabC4PnbqFrEI1uBPonq9DA+zq/vIJTHGP7WkZ+JT3tQod1YN40SeQaei AErH+uDY+D+tOhdKz4e+Ily69Au+fu2OcHqoBnaaAaoEr+q75VYLnUkQsw66iNZI3Ksz Whsw== X-Gm-Message-State: AC+VfDzKTIvp0e7/jS1yE4enXhTnfvm0baOQEABLd8GOezkfPw0vt5kA YmqO02ttEYIDNOz2RSDzuGJ35A== X-Received: by 2002:a17:902:6545:b0:1a9:2c70:e1eb with SMTP id d5-20020a170902654500b001a92c70e1ebmr31919353pln.36.1684129831244; Sun, 14 May 2023 22:50:31 -0700 (PDT) Received: from localhost.localdomain ([106.51.191.118]) by smtp.gmail.com with ESMTPSA id f10-20020a17090274ca00b001ab28f620d0sm12423277plt.290.2023.05.14.22.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 22:50:30 -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 , "Rafael J . Wysocki" , Len Brown , Sunil V L , Daniel Lezcano , Thomas Gleixner , Weili Qian , Zhou Wang , Herbert Xu , "David S . Miller" , Marc Zyngier , Maximilian Luz , Hans de Goede , Mark Gross , Nathan Chancellor , Nick Desaulniers , Tom Rix , "Rafael J . Wysocki" , Andrew Jones , Conor Dooley Subject: [PATCH V6 08/21] RISC-V: Add ACPI initialization in setup_arch() Date: Mon, 15 May 2023 11:19:15 +0530 Message-Id: <20230515054928.2079268-9-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230515054928.2079268-1-sunilvl@ventanamicro.com> References: <20230515054928.2079268-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,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Initialize the ACPI core for RISC-V during boot. ACPI tables and interpreter are initialized based on the information passed from the firmware and the value of the kernel parameter 'acpi'. With ACPI support added for RISC-V, the kernel parameter 'acpi' is also supported on RISC-V. Hence, update the documentation. Signed-off-by: Sunil V L Acked-by: Rafael J. Wysocki Reviewed-by: Andrew Jones Acked-by: Conor Dooley --- .../admin-guide/kernel-parameters.txt | 8 +- arch/riscv/kernel/acpi.c | 126 ++++++++++++++++++ arch/riscv/kernel/setup.c | 5 + 3 files changed, 135 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 9e5bab29685f..d910fba25f2c 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1,17 +1,17 @@ - acpi= [HW,ACPI,X86,ARM64] + acpi= [HW,ACPI,X86,ARM64,RISCV64] Advanced Configuration and Power Interface Format: { force | on | off | strict | noirq | rsdt | copy_dsdt } force -- enable ACPI if default was off - on -- enable ACPI but allow fallback to DT [arm64] + on -- enable ACPI but allow fallback to DT [arm64,riscv64] off -- disable ACPI if default was on noirq -- do not use ACPI for IRQ routing strict -- Be less tolerant of platforms that are not strictly ACPI specification compliant. rsdt -- prefer RSDT over (default) XSDT copy_dsdt -- copy DSDT to memory - For ARM64, ONLY "acpi=off", "acpi=on" or "acpi=force" - are available + For ARM64 and RISCV64, ONLY "acpi=off", "acpi=on" or + "acpi=force" are available See also Documentation/power/runtime_pm.rst, pci=noacpi diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c index 81d448c41714..7c080c8cbccf 100644 --- a/arch/riscv/kernel/acpi.c +++ b/arch/riscv/kernel/acpi.c @@ -16,6 +16,7 @@ #include #include #include +#include int acpi_noirq = 1; /* skip ACPI IRQ initialization */ int acpi_disabled = 1; @@ -24,6 +25,131 @@ EXPORT_SYMBOL(acpi_disabled); int acpi_pci_disabled = 1; /* skip ACPI PCI scan and IRQ initialization */ EXPORT_SYMBOL(acpi_pci_disabled); +static bool param_acpi_off __initdata; +static bool param_acpi_on __initdata; +static bool param_acpi_force __initdata; + +static int __init parse_acpi(char *arg) +{ + if (!arg) + return -EINVAL; + + /* "acpi=off" disables both ACPI table parsing and interpreter */ + if (strcmp(arg, "off") == 0) + param_acpi_off = true; + else if (strcmp(arg, "on") == 0) /* prefer ACPI over DT */ + param_acpi_on = true; + else if (strcmp(arg, "force") == 0) /* force ACPI to be enabled */ + param_acpi_force = true; + else + return -EINVAL; /* Core will print when we return error */ + + return 0; +} +early_param("acpi", parse_acpi); + +/* + * acpi_fadt_sanity_check() - Check FADT presence and carry out sanity + * checks on it + * + * Return 0 on success, <0 on failure + */ +static int __init acpi_fadt_sanity_check(void) +{ + struct acpi_table_header *table; + struct acpi_table_fadt *fadt; + acpi_status status; + int ret = 0; + + /* + * FADT is required on riscv; retrieve it to check its presence + * and carry out revision and ACPI HW reduced compliancy tests + */ + status = acpi_get_table(ACPI_SIG_FADT, 0, &table); + if (ACPI_FAILURE(status)) { + const char *msg = acpi_format_exception(status); + + pr_err("Failed to get FADT table, %s\n", msg); + return -ENODEV; + } + + fadt = (struct acpi_table_fadt *)table; + + /* + * The revision in the table header is the FADT's Major revision. The + * FADT also has a minor revision, which is stored in the FADT itself. + * + * TODO: Currently, we check for 6.5 as the minimum version to check + * for HW_REDUCED flag. However, once RISC-V updates are released in + * the ACPI spec, we need to update this check for exact minor revision + */ + if (table->revision < 6 || (table->revision == 6 && fadt->minor_revision < 5)) + pr_err(FW_BUG "Unsupported FADT revision %d.%d, should be 6.5+\n", + table->revision, fadt->minor_revision); + + if (!(fadt->flags & ACPI_FADT_HW_REDUCED)) { + pr_err("FADT not ACPI hardware reduced compliant\n"); + ret = -EINVAL; + } + + /* + * acpi_get_table() creates FADT table mapping that + * should be released after parsing and before resuming boot + */ + acpi_put_table(table); + return ret; +} + +/* + * acpi_boot_table_init() called from setup_arch(), always. + * 1. find RSDP and get its address, and then find XSDT + * 2. extract all tables and checksums them all + * 3. check ACPI FADT HW reduced flag + * + * We can parse ACPI boot-time tables such as MADT after + * this function is called. + * + * On return ACPI is enabled if either: + * + * - ACPI tables are initialized and sanity checks passed + * - acpi=force was passed in the command line and ACPI was not disabled + * explicitly through acpi=off command line parameter + * + * ACPI is disabled on function return otherwise + */ +void __init acpi_boot_table_init(void) +{ + /* + * Enable ACPI instead of device tree unless + * - ACPI has been disabled explicitly (acpi=off), or + * - firmware has not populated ACPI ptr in EFI system table + * and ACPI has not been [force] enabled (acpi=on|force) + */ + if (param_acpi_off || + (!param_acpi_on && !param_acpi_force && + efi.acpi20 == EFI_INVALID_TABLE_ADDR)) + return; + + /* + * ACPI is disabled at this point. Enable it in order to parse + * the ACPI tables and carry out sanity checks + */ + enable_acpi(); + + /* + * If ACPI tables are initialized and FADT sanity checks passed, + * leave ACPI enabled and carry on booting; otherwise disable ACPI + * on initialization error. + * If acpi=force was passed on the command line it forces ACPI + * to be enabled even if its initialization failed. + */ + if (acpi_table_init() || acpi_fadt_sanity_check()) { + pr_err("Failed to init ACPI tables\n"); + if (!param_acpi_force) + disable_acpi(); + } +} + /* * __acpi_map_table() will be called before paging_init(), so early_ioremap() * or early_memremap() should be called here to for ACPI table mapping. diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 9fb839074e16..45df7cc88b19 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -8,6 +8,7 @@ * Nick Kossifidis */ +#include #include #include #include @@ -276,6 +277,10 @@ void __init setup_arch(char **cmdline_p) efi_init(); paging_init(); + + /* Parse the ACPI tables for possible boot-time configuration */ + acpi_boot_table_init(); + #if IS_ENABLED(CONFIG_BUILTIN_DTB) unflatten_and_copy_device_tree(); #else -- 2.34.1