From patchwork Mon May 15 05:49:17 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: 93873 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6696075vqo; Sun, 14 May 2023 23:08:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5iRXaygbqjjLxGQlk2WWHPqgupewDTt4nhRHLHnGiOOnL3OMKV8p98Zzac+rGeCQgcNFQb X-Received: by 2002:a05:6a20:4281:b0:100:ba96:e5e7 with SMTP id o1-20020a056a20428100b00100ba96e5e7mr31339102pzj.18.1684130930688; Sun, 14 May 2023 23:08:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684130930; cv=none; d=google.com; s=arc-20160816; b=o34ODQY3ikJoS5oJSN4pd5o8Ab6MDqXiIXKRSAyuM3rGnGgLYsHxZH2ha17iVK0FxR 3Iaxqm8Z9qRBLbQm+LEfeuzFlSw401jKke1dejVYTglsobqCFaPDC57dplUDgeE8KLMj huemvIFwyaqb7qpys4hoQgCMpxAA5fF2Vu0GLcBKWJ3sj4GuXPZQNl7b6d9cPx5YFxd0 cSDgw/0DVldXJMVSXUZ9Nm2a4hRmYy0i/gfsb+TfRdoDyRi5AFeDeD5jlYtIVn4aVu5+ 2Qe10KroQgfxdVlxbwnCI2bg5sUY07FREVbnMZxODk45ICuudz6oLaY8Hm1OngyFVNqi n/MQ== 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=0nwVNZh7ok4nFqCGOtk3GB5ee+yA98GCkbh3FEbeZck=; b=rtYdJmE9yyOFWcs36ejf/pMvXsE6+gvZ0GD9eanNDovriSQS2fef8++u0PSwIFTVHY fP4yC0oyjRYwnEQjUOYSaHPFe7o0HwjWFDjoBCzX8n70Sa0XZsjCzwFOf6sKa3l31hoq LrEeRQB+V/fgU1whD7vFUCM1ofbex8bjX76VXgSyi3j1c9LhGes/g3/vPjyueHuX5LRl 80DlGa3ywf0i3UoUE5q+3arRUwT0SiPmOqHq7RTetIp09BBiHanEWbDXOQ27JUPSckyn Ly5yk8nhC0y2lH2kVTNuLgqf809g/v7B3VU5C85D1WdYv0BIkxZk4zmD5S1zETn28cx8 8VRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="E/akYS7O"; 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 a13-20020aa78e8d000000b0063b7b7712a6si16359794pfr.255.2023.05.14.23.08.36; Sun, 14 May 2023 23:08:50 -0700 (PDT) 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="E/akYS7O"; 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 S238452AbjEOFx1 (ORCPT + 99 others); Mon, 15 May 2023 01:53:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232353AbjEOFwU (ORCPT ); Mon, 15 May 2023 01:52:20 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EAAF3C27 for ; Sun, 14 May 2023 22:50:45 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-64ab2a37812so17225111b3a.1 for ; Sun, 14 May 2023 22:50:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1684129844; x=1686721844; 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=0nwVNZh7ok4nFqCGOtk3GB5ee+yA98GCkbh3FEbeZck=; b=E/akYS7O6yGgTDZ3Bf1T/P6nEJT968oaRhtj9rnRPRkcrOZSH3VS3K+x12YdT6/pch bCrXJMtYnM0QbaQqUhysZVUOx1hvleobJhLyQ2v9Uo/Coo4TSFaQII32wL0puYRy4kel YD3LtEyjx+e9J4c+uIR1fhu7TP8WOromrEOwE4Q50AGU7/Ma6U6Nz6v492FYkJw1JCP0 axsv8nlEsljhLjcZ2TuPLj0zj0QrqKnIwxeqCEc+epcl/4QKIO1ZGbHD8RDbbfnZHB/C IRzXw3yI7cTvq0aEjEObSoZoTF/I6pTsk0EvE6JFtdCmgGRYkc29VbLRfF6gJfukbRPH pDHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684129844; x=1686721844; 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=0nwVNZh7ok4nFqCGOtk3GB5ee+yA98GCkbh3FEbeZck=; b=f29fD48u8KH89yHiLOWOFLcjTLE8AMHygwpPylBXK9Hb+WFl45qMx4ZvVUi+tQf8rN Ze2w1FUmA0e7nelSNcuOw29nbYwd8S7Sbj9rdLJljC6i6Jmaj+yCqYuTdd/Ww7t5YfNh AwyI2irmvgYM9naLgzi09x7l6chEdcp+DLuEc1Jb6c3NgR3ev8x5cSYOrV/bJfrIh4TQ qRxQ7YjFhvUGKx6CxIc/BayMXjSMfvtAuH0NgfBIljNf4UH5IOwfN4L6FzSbpnPh1W1W jZkwsc9mQ2CkfXqVa64lsYKmM5r9/EGlj+SBYpiKDu8keO7+DYsvLTEeeNzh2U1wIbKI Rc/w== X-Gm-Message-State: AC+VfDwCs6aOxsLk9/P0BfUvt1PR671XVh4I7v0rCNDsx8OFDNIO00Rx kARUlUe5LaymgalUGXSUv9wNsQ== X-Received: by 2002:a17:902:ea05:b0:1ad:d542:6e14 with SMTP id s5-20020a170902ea0500b001add5426e14mr14552690plg.12.1684129844559; Sun, 14 May 2023 22:50:44 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 22:50:44 -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 , Palmer Dabbelt Subject: [PATCH V6 10/21] drivers/acpi: RISC-V: Add RHCT related code Date: Mon, 15 May 2023 11:19:17 +0530 Message-Id: <20230515054928.2079268-11-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 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=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?1765939274636769426?= X-GMAIL-MSGID: =?utf-8?q?1765939274636769426?= 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 Reviewed-by: Palmer Dabbelt --- arch/riscv/include/asm/acpi.h | 8 ++++ drivers/acpi/Makefile | 2 + drivers/acpi/riscv/Makefile | 2 + drivers/acpi/riscv/rhct.c | 83 +++++++++++++++++++++++++++++++++++ 4 files changed, 95 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 6519529c8bdf..39471759bec1 100644 --- a/arch/riscv/include/asm/acpi.h +++ b/arch/riscv/include/asm/acpi.h @@ -62,6 +62,8 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { } void acpi_init_rintc_map(void); 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 void acpi_init_rintc_map(void) { } static inline struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu) @@ -69,6 +71,12 @@ static inline struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu) return NULL; } +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..b280b3e9c7d9 --- /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; +}