Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1227204rwr; Wed, 26 Apr 2023 11:46:01 -0700 (PDT) X-Google-Smtp-Source: AKy350YMQul3GKjFcna5QN5bVCFedqWzfELL6I/XAqATvGs8Phoy5XcMwFG3hd2PoISmX/kP9f8d X-Received: by 2002:a05:6a00:2790:b0:63a:2829:7e33 with SMTP id bd16-20020a056a00279000b0063a28297e33mr24879236pfb.0.1682534761288; Wed, 26 Apr 2023 11:46:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682534761; cv=none; d=google.com; s=arc-20160816; b=ACm0Gbp0ocjvrmuRqeu3VWP+ySPQnIyTNnHy3qHRKOu5tsAGTupKmHLo66bfCIjz61 Z7Zjb2k8SG9690gtTMfdSOaqn240w2qwNCfeBJ9CsJeCZq91NiHndpyK7kMsRP13soRt ViCtnNeyHgz0h/tUddgULWFD5eMK5+hVWts8wl28oyas57Fr9tewTRjlBDC2CW9r8XQK QJJbTaH6fxiCmUA7odpiUL2evu5slT0K4OCetWTS2HGth+E9hqgt/hOD4CEOpZ18jDs2 mWdtaywtTnabprSdFQpNczplw32j6HPzr1kFfuhs9P1Rwn5IMkYylBIW+8aKH/DGzpfq gShA== 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 :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=W8X9QIdG4Ip5y9y13sVSAOZfIX4bMSFLSP6fvMFKbKI=; b=b0oAwtkMm/ZpiocatQ/WkeDXJ0aAoz9rSFooh40d4nekIksmGvLZkjC+4wS7+zdI6m 6y+ifO73kNssRh4wHE6GdEZysWPXcuLeZKLkQvPmTCSdPs6JX2wRYt64mfJB5dFNlP77 xPX0jQI2tsPHmnBJI+ROBAy9TEoYeeZXXCIt5DCn2xA0YG1bwo/y82mfYxrQK5pVEG93 5mh1OomwIcuZVKopttdg43stGfy3EqJyetLRxf0v0kh2r5qXGYTDdFoJhU6fdidEU7Vg aHW2uCvr5KFXG2AjMPa+yoq0Xyp4Je08tfnkPLruUO8NHGJN4Mj4tyUo2CDbcEKUGKM0 K51g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20221208.gappssmtp.com header.s=20221208 header.b=pudR6w2s; 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 y2-20020aa793c2000000b0063b2655def0si16756253pff.47.2023.04.26.11.45.49; Wed, 26 Apr 2023 11:46:01 -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=@dabbelt-com.20221208.gappssmtp.com header.s=20221208 header.b=pudR6w2s; 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 S236285AbjDZSp2 (ORCPT + 99 others); Wed, 26 Apr 2023 14:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236280AbjDZSpX (ORCPT ); Wed, 26 Apr 2023 14:45:23 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D0A58692 for ; Wed, 26 Apr 2023 11:45:04 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-51f1b6e8179so5374050a12.3 for ; Wed, 26 Apr 2023 11:45:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20221208.gappssmtp.com; s=20221208; t=1682534703; x=1685126703; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:from:to:cc:subject:date:message-id :reply-to; bh=W8X9QIdG4Ip5y9y13sVSAOZfIX4bMSFLSP6fvMFKbKI=; b=pudR6w2sMYaPRbOA7YCNd1nXsK3n1NGjv1R7Q9HFR2gTFGztwnNIB5tTbbTV5SdJ3q Lrm9H0UtTXrx20/sfZM9daDQutjpUALtt2UBHlXi09a7x5xweFuc6YjmpDwnAcy79qhT oS9vAYCHEzf7XWsXJXMMuaVDO0NaE/Wxjs56ryvH5Oxt8Xla7Lg3U/ngtGmQj38Uvp1k 8ctb/S35RfnY+L9kHpDrkI9C8UV2KQVcary3H1xQfWY5wSrJMZ+02s5cRAv52Ef9BKXF q/gz+oIP5uOPRMD5iNhwygrma7IyAM4k0uNnzj72xYnpgvAxxJ/7e3eB4F3gW+Xlie3D Rlgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682534703; x=1685126703; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=W8X9QIdG4Ip5y9y13sVSAOZfIX4bMSFLSP6fvMFKbKI=; b=bnE67AACsNIWO7fxQmW+TAamPqTebB4ijp7xOD/LEtbiCp2NnqlPLRA++G7wCFgrI+ mnURzzABOiX+8KgxrzXWOAFnxcZ/dlf59DNqFvl4bWjQLtMtIf2cksR4Hko63Y7yKXvX /Sp+804DIR7wYgzvJEGhboiwbHwNOrWzA19k0mg4dJWJt2nqwLIrZOO/H5p5VVIogekM wBgiQAlwFa88HPTcBYwiB9AIw/9rfXWKRAxpjkSGbcDsuagQrmGJyI3A6Gcw/u/ZzmO/ BAvAwFdqszLFpScGdnwSEFIZpoi2rvt2C1Kwd88xKdjZ8Pj4rWIy5gtRH5ALbGAibMWK nXAA== X-Gm-Message-State: AAQBX9frrgyy99LgkM0xzRWhplMv2hhbtGRQ4IYB/JTWtAghe1uv11VS tK3ava/8eFcvLJY7Oom1OLwnYw== X-Received: by 2002:a05:6a20:2443:b0:f0:3e57:f42a with SMTP id t3-20020a056a20244300b000f03e57f42amr29047614pzc.44.1682534703116; Wed, 26 Apr 2023 11:45:03 -0700 (PDT) Received: from localhost ([50.221.140.188]) by smtp.gmail.com with ESMTPSA id b6-20020a63d806000000b005143d3fa0e0sm10115035pgh.2.2023.04.26.11.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 11:45:02 -0700 (PDT) Date: Wed, 26 Apr 2023 11:45:02 -0700 (PDT) X-Google-Original-Date: Wed, 26 Apr 2023 11:44:12 PDT (-0700) Subject: Re: [PATCH V4 09/23] drivers/acpi: RISC-V: Add RHCT related code In-Reply-To: <20230404182037.863533-10-sunilvl@ventanamicro.com> CC: 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, corbet@lwn.net, Paul Walmsley , aou@eecs.berkeley.edu, lenb@kernel.org, daniel.lezcano@linaro.org, tglx@linutronix.de, qianweili@huawei.com, wangzhou1@hisilicon.com, herbert@gondor.apana.org.au, Marc Zyngier , luzmaximilian@gmail.com, hdegoede@redhat.com, markgross@kernel.org, nathan@kernel.org, ndesaulniers@google.com, trix@redhat.com, rafael@kernel.org, davem@davemloft.net, sunilvl@ventanamicro.com, rafael.j.wysocki@intel.com, ajones@ventanamicro.com From: Palmer Dabbelt To: sunilvl@ventanamicro.com Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 On Tue, 04 Apr 2023 11:20:23 PDT (-0700), sunilvl@ventanamicro.com wrote: > RHCT is a new table defined for RISC-V to communicate the > features of the CPU to the OS. Create a new architecture folder > in drivers/acpi and add RHCT parsing code. > > Signed-off-by: Sunil V L > Acked-by: Rafael J. Wysocki > Reviewed-by: Andrew Jones > --- > arch/riscv/include/asm/acpi.h | 9 ++++ > drivers/acpi/Makefile | 2 + > drivers/acpi/riscv/Makefile | 2 + > drivers/acpi/riscv/rhct.c | 83 +++++++++++++++++++++++++++++++++++ > 4 files changed, 96 insertions(+) > create mode 100644 drivers/acpi/riscv/Makefile > create mode 100644 drivers/acpi/riscv/rhct.c > > diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h > index 1606dce8992e..2b3e78d5a13b 100644 > --- a/arch/riscv/include/asm/acpi.h > +++ b/arch/riscv/include/asm/acpi.h > @@ -61,6 +61,15 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { } > > 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); > +#else > +static inline int acpi_get_riscv_isa(struct acpi_table_header *table, > + unsigned int cpu, const char **isa) > +{ > + return -EINVAL; > +} > + > #endif /* CONFIG_ACPI */ > > #endif /*_ASM_ACPI_H*/ > diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile > index feb36c0b9446..3fc5a0d54f6e 100644 > --- a/drivers/acpi/Makefile > +++ b/drivers/acpi/Makefile > @@ -131,3 +131,5 @@ obj-y += dptf/ > obj-$(CONFIG_ARM64) += arm64/ > > obj-$(CONFIG_ACPI_VIOT) += viot.o > + > +obj-$(CONFIG_RISCV) += riscv/ > diff --git a/drivers/acpi/riscv/Makefile b/drivers/acpi/riscv/Makefile > new file mode 100644 > index 000000000000..8b3b126e0b94 > --- /dev/null > +++ b/drivers/acpi/riscv/Makefile > @@ -0,0 +1,2 @@ > +# SPDX-License-Identifier: GPL-2.0-only > +obj-y += rhct.o > diff --git a/drivers/acpi/riscv/rhct.c b/drivers/acpi/riscv/rhct.c > new file mode 100644 > index 000000000000..ea78d906a0fe > --- /dev/null > +++ b/drivers/acpi/riscv/rhct.c > @@ -0,0 +1,83 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (C) 2022-2023, Ventana Micro Systems Inc > + * Author: Sunil V L > + * > + */ > + > +#define pr_fmt(fmt) "ACPI: RHCT: " fmt > + > +#include > + > +static struct acpi_table_header *acpi_get_rhct(void) > +{ > + static struct acpi_table_header *rhct; > + acpi_status status; > + > + /* > + * RHCT will be used at runtime on every CPU, so we > + * don't need to call acpi_put_table() to release the table mapping. > + */ > + if (!rhct) { > + status = acpi_get_table(ACPI_SIG_RHCT, 0, &rhct); > + if (ACPI_FAILURE(status)) { > + pr_warn_once("No RHCT table found\n"); > + return NULL; > + } > + } > + > + return rhct; > +} > + > +/* > + * During early boot, the caller should call acpi_get_table() and pass its pointer to > + * these functions(and free up later). At run time, since this table can be used > + * multiple times, NULL may be passed in order to use the cached table. > + */ > +int acpi_get_riscv_isa(struct acpi_table_header *table, unsigned int cpu, const char **isa) > +{ > + struct acpi_rhct_node_header *node, *ref_node, *end; > + u32 size_hdr = sizeof(struct acpi_rhct_node_header); > + u32 size_hartinfo = sizeof(struct acpi_rhct_hart_info); > + struct acpi_rhct_hart_info *hart_info; > + 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); > + > + BUG_ON(acpi_disabled); > + > + if (!table) { > + rhct = (struct acpi_table_rhct *)acpi_get_rhct(); > + if (!rhct) > + return -ENOENT; > + } else { > + rhct = (struct acpi_table_rhct *)table; > + } > + > + end = ACPI_ADD_PTR(struct acpi_rhct_node_header, rhct, rhct->header.length); > + > + for (node = ACPI_ADD_PTR(struct acpi_rhct_node_header, rhct, rhct->node_offset); > + node < end; > + node = ACPI_ADD_PTR(struct acpi_rhct_node_header, node, node->length)) { > + if (node->type == ACPI_RHCT_NODE_TYPE_HART_INFO) { > + hart_info = ACPI_ADD_PTR(struct acpi_rhct_hart_info, node, size_hdr); > + hart_info_node_offset = ACPI_ADD_PTR(u32, hart_info, size_hartinfo); > + if (acpi_cpu_id != hart_info->uid) > + continue; > + > + for (int i = 0; i < hart_info->num_offsets; i++) { > + ref_node = ACPI_ADD_PTR(struct acpi_rhct_node_header, > + rhct, hart_info_node_offset[i]); > + if (ref_node->type == ACPI_RHCT_NODE_TYPE_ISA_STRING) { > + isa_node = ACPI_ADD_PTR(struct acpi_rhct_isa_string, > + ref_node, size_hdr); > + *isa = isa_node->isa; > + return 0; > + } > + } > + } > + } > + > + return -1; > +} Reviewed-by: Palmer Dabbelt