Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1574000lqp; Mon, 15 Apr 2024 10:09:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUdaYDQzK1Uj7vXC2k+I1Y+RmxcgDcknyoX7cFCLkyb7P91MsHAgTkUeUfVsrgZs/N0Xzz9zKGqVKgqsWSdI6jY5WYJQQGEKHn57E2gzQ== X-Google-Smtp-Source: AGHT+IEieERi+4QuCDM9oc+y2ZiVZpE6nINR/WNp1pwvYR3nLpwVdIhK+JMkToIWXNc1+0Gr5spD X-Received: by 2002:a05:6a21:398e:b0:1a7:ab24:79e2 with SMTP id ad14-20020a056a21398e00b001a7ab2479e2mr277563pzc.30.1713200995397; Mon, 15 Apr 2024 10:09:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713200995; cv=pass; d=google.com; s=arc-20160816; b=SOCSTruLaSar/xhUAKnCaf5tHBMJYBcJEU+dtDzEOGkqb5a40bFM//FZ36xZaJl3A5 YPrp1HvBuGscYFMKXdLtmJhsq7ozphTR2kKS//Vcj0JLGuOOjrqsRJOYhn/mn4VNvbfv bR9BW+XZteZrtRoxcehac2q1NVsHxAlP660OEp5qKu6F0aNfHrNHLJlkvBm00WkGmGo8 xbUHJBcG0GRergdgg3fHa+ZY4gSBGqP35AUV61WLtUT2aypA9zWpB41Z60OZ2eq0rC/j jYS9R9LVC8LVJIDYBB2y8kBQ7SQgjp0sp9YPoTrc8nYYyb2RvO36+9tAukexRLesMsaP aoFQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qa8aPZaBb5SHnjDhwNe5AO6s82EyT//Q/0nqKZneQ7s=; fh=tWEycFpSFrqIbfeVuXuhzc/0NukfNdVd5k6ruRxC5Mo=; b=cOyd4lxZlFmNHu+jaaxo+dLT9uXnbTCNpWnM9sg84pjfVU6X3w/pOQCBm/31RE6iQg Db6sMMpyYsYv1epZS4XhXMNpiM0jgBesvFa1N2dsY2LzTtadb/IGJuFO7YlibjVIjy9i GvvyeJ18rEWJHow7aPqix+EnfuETRgxBZD2uhiy+gA59AFKmWZWtS87hAcC17Swtgonl y/DnKdqxsdQPVu8B244Pvfeszq5TfbdS3100pI5hSWzPb+CLB0AwbuwXIg0vQn8f4MCL uvJZN5aHamrG6MwF9EVEKTy/OkgltbmVShIBImN7KihFPMHtvG0oXOMiX5+C6K2sVQ3L ognw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=OI5mMiFt; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-145610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145610-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m30-20020a637d5e000000b005e47d608cbesi8019145pgn.134.2024.04.15.10.09.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 10:09:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=OI5mMiFt; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-145610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145610-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9D542B246B3 for ; Mon, 15 Apr 2024 17:04:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3BDDE84DE4; Mon, 15 Apr 2024 17:02:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="OI5mMiFt" Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F34C84D0F for ; Mon, 15 Apr 2024 17:02:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713200557; cv=none; b=nyDxSO5NtZH7bXJNw1IiusLt8PqaKV2j9q15EYxAT7NOJhDHm0RrXHtNm0hWl3CN2/MQP3m7PyZe553+wF66WjXgutrHydsfF062KDwyYcAu0jXR5cP2yqSzDPhPZRfM1WJrkAUi8dRRCTOlj0bleGOCQrl48wK4lAP1sv6zeLM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713200557; c=relaxed/simple; bh=8faRomOS+YY08OK+jIa6TJx7uMvk/iowqcEmkn3Wzl4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZcL5Cv5UbLETWkIAxXzOZp/tZw2yFeFWTE48cI1XG2l8aSwIYCSqYjpEDdpjrjZFSTd+uUhdIhspHb/s7YHn4KON17iSOmD/c2rcgd6KSl0bcTrC1z58lcvetJWx9UStmVqcywuPyOpEuNFPTN8ge7krhK5I+BdVfTsq3xcN8fk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=OI5mMiFt; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6ecf8ebff50so2272992b3a.1 for ; Mon, 15 Apr 2024 10:02:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1713200550; x=1713805350; darn=vger.kernel.org; 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=qa8aPZaBb5SHnjDhwNe5AO6s82EyT//Q/0nqKZneQ7s=; b=OI5mMiFtEufjmJ51zyFJltn0N67rSGQnrPi5CCzUTE590jGmhh/wu8+N+RkKfP2rnJ fdjuiokRtCL6tJEv/25pte1/8uLZOrUEXcqz4DCG/YogCP7Qz8iRCY3cxssH9Qki5bkg qTLVcCNBz1Qqb9arkp1zUya072ls2GBoxRDCaWHBEYawIsAG2Nu9oR+/KT9ofrUK6JFm dRcEufcmU1FYs4c/1u0ilB2Q2ERA8vfAp8w8hTn6XWKkWXS2tNZVZkQNI1AgB6jFPJMU BWn8pL8x2E0Y0BcE5hDo07oK8IDylK7M3xogRxeTxkYb0+mbGY3RQMQuphxigkCOj56C p0cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713200550; x=1713805350; 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=qa8aPZaBb5SHnjDhwNe5AO6s82EyT//Q/0nqKZneQ7s=; b=aFLcdpxZq7g+KPKo8/RZwLnyZelsvMzIVPxqRnbgY+QUxvlmPHbyDQwiqeb7DjU2y4 cxQnuP7NgbThyMCrfN6GKlUyql5E5p/Cil4s4jYK0xhj3igmzLir15eudkEO7s4mbY2X kO0CJZrJFKJldGYSs3aduAlH7lcXVJKLKp9x9TeQYbRZ+8vfbmjuoH679p9L+bee0NgI 82frXymJsuzwM9jhtkE1+0UL67IRrRTDV0O6dkhw50zp+aYdX7pJrCdvx0ZHy8LGOMnB s7AfwfAliEendvv9LD+4sUpza3b5xFm/rWbXzHOVaajiVNj80nz80nk+WqzDiTiEDzfz rBJg== X-Forwarded-Encrypted: i=1; AJvYcCW0cHGxCRKXtoHrv/3/6+3jRHTM+rsH2alG+Di2/D8dEgSdFNT8BuNJM6xad+AJOVbJzTpUO98bcHBfVoO1RGGDutVkEfcGjEH1v6RH X-Gm-Message-State: AOJu0Yz+8SvJ5fyOHDARAJKT3ahQosD04tUMzssXg2KwN1rWJUHrFLtw LJdLNTPpSjLw6jxK6It94HvxeXxmMzm0ytjKuPAPl6/8EuLkIQWigz6cZ8CnDPc= X-Received: by 2002:a05:6a00:c88:b0:6ec:e21b:24f with SMTP id a8-20020a056a000c8800b006ece21b024fmr288145pfv.10.1713200550215; Mon, 15 Apr 2024 10:02:30 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.187.230]) by smtp.gmail.com with ESMTPSA id 1-20020a056a00072100b006ed045e3a70sm7433158pfm.25.2024.04.15.10.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 10:02:29 -0700 (PDT) From: Sunil V L To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, acpica-devel@lists.linux.dev Cc: Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Rafael J . Wysocki" , Len Brown , Bjorn Helgaas , Anup Patel , Thomas Gleixner , Samuel Holland , Robert Moore , Haibo1 Xu , Conor Dooley , Andrew Jones , Atish Kumar Patra , Andrei Warkentin , Marc Zyngier , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Sunil V L Subject: [RFC PATCH v4 10/20] RISC-V: ACPI: Initialize GSI mapping structures Date: Mon, 15 Apr 2024 22:31:03 +0530 Message-Id: <20240415170113.662318-11-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240415170113.662318-1-sunilvl@ventanamicro.com> References: <20240415170113.662318-1-sunilvl@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit RISC-V has PLIC and APLIC in MADT as well as namespace devices. Initialize the list of those structures using MADT and namespace devices to create mapping between the ACPI handle and the GSI ranges. This is will be used later to add dependencies. Signed-off-by: Sunil V L --- arch/riscv/include/asm/irq.h | 22 +++++ drivers/acpi/riscv/init.c | 2 + drivers/acpi/riscv/init.h | 4 + drivers/acpi/riscv/irq.c | 159 +++++++++++++++++++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 drivers/acpi/riscv/init.h diff --git a/arch/riscv/include/asm/irq.h b/arch/riscv/include/asm/irq.h index 8e10a94430a2..44a0b128c602 100644 --- a/arch/riscv/include/asm/irq.h +++ b/arch/riscv/include/asm/irq.h @@ -16,4 +16,26 @@ void riscv_set_intc_hwnode_fn(struct fwnode_handle *(*fn)(void)); struct fwnode_handle *riscv_get_intc_hwnode(void); +#ifdef CONFIG_ACPI + +enum riscv_irqchip_type { + ACPI_RISCV_IRQCHIP_INTC = 0x00, + ACPI_RISCV_IRQCHIP_IMSIC = 0x01, + ACPI_RISCV_IRQCHIP_PLIC = 0x02, + ACPI_RISCV_IRQCHIP_APLIC = 0x03, +}; + +int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base, + u32 *id, u32 *nr_irqs, u32 *nr_idcs); +struct fwnode_handle *riscv_acpi_get_gsi_domain_id(u32 gsi); + +#else +static inline int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base, + u32 *id, u32 *nr_irqs, u32 *nr_idcs) +{ + return 0; +} + +#endif /* CONFIG_ACPI */ + #endif /* _ASM_RISCV_IRQ_H */ diff --git a/drivers/acpi/riscv/init.c b/drivers/acpi/riscv/init.c index b5807bbdb171..56780af6ceb3 100644 --- a/drivers/acpi/riscv/init.c +++ b/drivers/acpi/riscv/init.c @@ -6,7 +6,9 @@ */ #include +#include "init.h" void __init acpi_riscv_init(void) { + riscv_acpi_init_gsi_mapping(); } diff --git a/drivers/acpi/riscv/init.h b/drivers/acpi/riscv/init.h new file mode 100644 index 000000000000..2a488ec684b9 --- /dev/null +++ b/drivers/acpi/riscv/init.h @@ -0,0 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include + +int __init riscv_acpi_init_gsi_mapping(void); diff --git a/drivers/acpi/riscv/irq.c b/drivers/acpi/riscv/irq.c index 36e0525b3235..de0f1ba92068 100644 --- a/drivers/acpi/riscv/irq.c +++ b/drivers/acpi/riscv/irq.c @@ -7,6 +7,21 @@ #include #include +#include + +#include "init.h" + +struct riscv_ext_intc_list { + acpi_handle handle; + u32 gsi_base; + u32 nr_irqs; + u32 nr_idcs; + u32 id; + u32 type; + struct list_head list; +}; + +LIST_HEAD(ext_intc_list); static int irqchip_cmp_func(const void *in0, const void *in1) { @@ -30,3 +45,147 @@ void arch_sort_irqchip_probe(struct acpi_probe_entry *ap_head, int nr) return; sort(ape, nr, sizeof(*ape), irqchip_cmp_func, NULL); } + +static int riscv_acpi_update_gsi_handle(u32 gsi_base, acpi_handle handle) +{ + struct riscv_ext_intc_list *ext_intc_element; + struct list_head *i, *tmp; + + list_for_each_safe(i, tmp, &ext_intc_list) { + ext_intc_element = list_entry(i, struct riscv_ext_intc_list, list); + if (gsi_base == ext_intc_element->gsi_base) { + ext_intc_element->handle = handle; + return 0; + } + } + + return -1; +} + +static acpi_handle riscv_acpi_get_gsi_handle(u32 gsi) +{ + struct riscv_ext_intc_list *ext_intc_element; + struct list_head *i, *tmp; + + list_for_each_safe(i, tmp, &ext_intc_list) { + ext_intc_element = list_entry(i, struct riscv_ext_intc_list, list); + if (gsi >= ext_intc_element->gsi_base && + gsi < (ext_intc_element->gsi_base + ext_intc_element->nr_irqs)) + return ext_intc_element->handle; + } + + return NULL; +} + +int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base, + u32 *id, u32 *nr_irqs, u32 *nr_idcs) +{ + struct riscv_ext_intc_list *ext_intc_element; + struct list_head *i, *tmp; + + list_for_each_safe(i, tmp, &ext_intc_list) { + ext_intc_element = list_entry(i, struct riscv_ext_intc_list, list); + if (ext_intc_element->handle == ACPI_HANDLE_FWNODE(fwnode)) { + *gsi_base = ext_intc_element->gsi_base; + *id = ext_intc_element->id; + *nr_irqs = ext_intc_element->nr_irqs; + if (nr_idcs) + *nr_idcs = ext_intc_element->nr_idcs; + return 0; + } + } + + return -ENODEV; +} + +struct fwnode_handle *riscv_acpi_get_gsi_domain_id(u32 gsi) +{ + struct riscv_ext_intc_list *ext_intc_element; + struct acpi_device *adev; + struct list_head *i, *tmp; + + list_for_each_safe(i, tmp, &ext_intc_list) { + ext_intc_element = list_entry(i, struct riscv_ext_intc_list, list); + if (gsi >= ext_intc_element->gsi_base && + gsi < (ext_intc_element->gsi_base + ext_intc_element->nr_irqs)) { + adev = acpi_fetch_acpi_dev(ext_intc_element->handle); + if (!adev) + return NULL; + + return acpi_fwnode_handle(adev); + } + } + + return NULL; +} + +static int __init riscv_acpi_register_ext_intc(u32 gsi_base, u32 nr_irqs, u32 nr_idcs, + u32 id, u32 type) +{ + struct riscv_ext_intc_list *ext_intc_element; + + ext_intc_element = kzalloc(sizeof(*ext_intc_element), GFP_KERNEL); + if (!ext_intc_element) + return -1; + + ext_intc_element->gsi_base = gsi_base; + ext_intc_element->nr_irqs = nr_irqs; + ext_intc_element->nr_idcs = nr_idcs; + ext_intc_element->id = id; + list_add_tail(&ext_intc_element->list, &ext_intc_list); + return 0; +} + +static acpi_status __init riscv_acpi_create_gsi_map(acpi_handle handle, u32 level, + void *context, void **return_value) +{ + acpi_status status; + u64 gbase; + + if (!acpi_has_method(handle, "_GSB")) + return AE_OK; + + status = acpi_evaluate_integer(handle, "_GSB", NULL, &gbase); + if (ACPI_FAILURE(status)) { + acpi_handle_err(handle, "failed to evaluate _GSB method\n"); + return AE_OK; + } + + riscv_acpi_update_gsi_handle((u32)gbase, handle); + return AE_OK; +} + +static int __init riscv_acpi_aplic_parse_madt(union acpi_subtable_headers *header, + const unsigned long end) +{ + struct acpi_madt_aplic *aplic = (struct acpi_madt_aplic *)header; + + riscv_acpi_register_ext_intc(aplic->gsi_base, aplic->num_sources, + aplic->num_idcs, aplic->id, ACPI_RISCV_IRQCHIP_APLIC); + return 0; +} + +static int __init riscv_acpi_plic_parse_madt(union acpi_subtable_headers *header, + const unsigned long end) +{ + struct acpi_madt_plic *plic = (struct acpi_madt_plic *)header; + + riscv_acpi_register_ext_intc(plic->gsi_base, plic->num_irqs, 0, + plic->id, ACPI_RISCV_IRQCHIP_PLIC); + return 0; +} + +int __init riscv_acpi_init_gsi_mapping(void) +{ + int count = 0; + + count = acpi_table_parse_madt(ACPI_MADT_TYPE_PLIC, riscv_acpi_plic_parse_madt, 0); + if (count <= 0) { + acpi_table_parse_madt(ACPI_MADT_TYPE_APLIC, riscv_acpi_aplic_parse_madt, 0); + acpi_get_devices("RSCV0002", riscv_acpi_create_gsi_map, NULL, NULL); + return 0; + } + + acpi_get_devices("RSCV0001", riscv_acpi_create_gsi_map, NULL, NULL); + return 0; +} -- 2.40.1