Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp431478lqm; Wed, 1 May 2024 05:24:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUj2NzeM+tQ/xrIAY69MlLr5WAWm/pobs2je0yNQB0mIbKixpJdI9JgWD2r5qoO9rDODUt6G9wawzO6OAhWEjjmnmW6S0fo5McofZNodw== X-Google-Smtp-Source: AGHT+IH3TgRK1BPM9LJ6N2NT2gZlUU7r+B7suQhO3tHjyLRPGgGbFVqTPAs8pXChOPO+HaYme32p X-Received: by 2002:a05:6359:4c0c:b0:186:1128:bca7 with SMTP id kj12-20020a0563594c0c00b001861128bca7mr2566900rwc.6.1714566272392; Wed, 01 May 2024 05:24:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714566272; cv=pass; d=google.com; s=arc-20160816; b=oLLkAHrOSuhcOXBGT9hnlLDI4awUy+mChaMZxZfUoFCnfLAfnE4yumU/cZug0okVoB sTtScyUxsPnnuVnv+nMBLruXaLZrr8gq5Wj5HQZZTbkKP9Wzby6QskoO9jeubsp4/v51 Pzw/9hUIHavU34BlQxiSdFtHjyXXGdkY8WG0ddjrqerKxDZb+C9t7pz42n8gAzb1A4QI a5bUx8HU230i90+f9VHjdxCQ5XiKmHH/OpNWjUizrhjwoEKd5d1KAHS2sGxI8r6HMwzV rtBF2b8twIk3ED2foWr9y9sLVg/5fIpuNxYYKnbBVWWBzQU/KMn4mUQRfr8JpvGRSWVq jVRw== 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=BG93T+gcNC0mbkbP77au2VNz1Cnxnueu2TjA3uMrqLg=; fh=NSWD0uSG/ERj4xIObslFBoOUhVll+7j16cMSLdB9pZg=; b=bzD0fO59FpAyA06lo4ABdB7TaeDPNxuDlacNz71s6PzUN6bR7OyUAwbE8mzorE8JYr gn2a6Mr8PZ2HexEhH2R9lqr++i7WVooGAyhk1uw0AB9UkbsXE6sGe3QCpsIVmNZB3OzS TKtZ6I4p3X8zf6rnq3UsWAG4VKJ14L01LykakHSdKOsQd5qfdn9CxMeEOlkrj7lQUitH sr/Uvcx+T3XmxIztsRyXOrprobg4384bJeI9CvwIEAysjXY4p9r2A+66xKOpTbtz+rbs dDtSDW1hO+fM5n0UyFceyDCvT8L9acCP3TY27wEODGTRMZ28jwMk6BFhJmhLrxZfqXna fN8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="F7p/5lvl"; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-165227-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165227-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 d23-20020a63fd17000000b005dc4eb5d421si23968196pgh.347.2024.05.01.05.24.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 05:24:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165227-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="F7p/5lvl"; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-165227-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165227-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 C95BDB23530 for ; Wed, 1 May 2024 12:22:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 656DD12F383; Wed, 1 May 2024 12:19:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="F7p/5lvl" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 DD13412F385 for ; Wed, 1 May 2024 12:19:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714565980; cv=none; b=MUjIGFS9S6r6esCvaKkaHW0Th9yWLW9ho31MgNO3K7I64VqYMfZSbxvnS3Dimh+53FdXaUywcohTRWbxo+OvlMozE7zNhfqXt7RxjUVVfOd7zrFimdDszUIwYypIsljUpL3KR4142DZyK1T9RNBkgR4CippnFQh64cNQVikBARk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714565980; c=relaxed/simple; bh=qhqCGi8o9IAINNxfLRxMEmmSPodYgvrNH462+zJ18l4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FNVQ5q62HgkYS7010ctgtoL21Uqti76EmE3OgfM8t1Z2xWf4oyB/J/Z+7ld9eL/Ydqte0NLgW11RhEIuEe0jN/Qcs9TNj4T1mJnk4gWYcHRiGuDGmPUjtCqF9YMjTHxDmRL7qbs9DOD4dZDiTOabWgyFpfDzFpSNJDXgZiM2LQM= 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=F7p/5lvl; arc=none smtp.client-ip=209.85.214.177 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-pl1-f177.google.com with SMTP id d9443c01a7336-1eab699fcddso52724455ad.0 for ; Wed, 01 May 2024 05:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1714565977; x=1715170777; 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=BG93T+gcNC0mbkbP77au2VNz1Cnxnueu2TjA3uMrqLg=; b=F7p/5lvlKSw310BCiP2ZGUgCUqUi9/kUTkodwgNLpjUPAvLryvL0nn56uSeWJwqWOQ P/sMniwmSk5jxqcMMUm4UreyyKrbigKUDp8zt2opbXDU+0G/Em3Qd3RTUpZkVj++VPbs cQhStm8SnaRGYL6pBr3BjzuMMWB9clmlSujQ+duQl0M+rVDbNEUaQyid+15L44BULXTs jN8hgF5+nAWISyWIhyRLykzKgsOWBTLjcv40vZa072N6PCf0ajJp/jFqf/gMdpdPAJBl 5Br7BWdg8X02Ml1BXig43/0j4D4ld6YiFZ2GaHfdRFlY91gul0AN6nh8dodK4nVld3Mp zoYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714565977; x=1715170777; 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=BG93T+gcNC0mbkbP77au2VNz1Cnxnueu2TjA3uMrqLg=; b=iQZPBm0OLIxHsVupPHmzni7wkC3i+9VXqsxjF2LKmaK+LnnX2pM91VkC7b7YYrmPG9 g/FoslgeD3ULyN2tM1+fBFmj/YBi2DKQZPrlMXbwP/F70cRJkYxFdF+JVvuCku9IsWEy uGRPOSMdkzU9/C7BfVyzwzoVEQ+EV8kR0DJhibDPRmBsZVn/KDqSHegS3Ia/jycea9oA Dvo0sRDFjA4zgy6uPKBpixBjka2m8VaSlUG3xPy+lPAyl9dwSud3zk6spnQNEy1qrgRo eMaa1MuhtqjvQqJEMAhG515WtavS39b1kByAZhcWzeb/Y5Ztjh0HCMdqGOr87rLAVVMe wFJQ== X-Forwarded-Encrypted: i=1; AJvYcCWOsb8N4fN9wqlNxRGvQwERZeFS2AJ9VSPQqJGiv3NtVuQDaa5x1YwQeb+DjhFjNSzwwu+cxFMunUiU++J0FuJ4YOSe7ZgiCgLqOwjN X-Gm-Message-State: AOJu0Yyt9F10+2faQbuABWN+4TXaDHuxdnS+Dz5OujN8No8nIE+SSQfv rYOUKzQowAZYMoWbp+Mh5X5X68HObTEAMexA0sKi0Tj4ic9tjK9L/8oBGtGY7dE= X-Received: by 2002:a17:902:eecc:b0:1eb:2988:549d with SMTP id h12-20020a170902eecc00b001eb2988549dmr2035967plb.40.1714565977219; Wed, 01 May 2024 05:19:37 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.188.106]) by smtp.gmail.com with ESMTPSA id im15-20020a170902bb0f00b001ec8888b22esm1336900plb.65.2024.05.01.05.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 05:19:36 -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, linux-serial@vger.kernel.org, acpica-devel@lists.linux.dev Cc: Catalin Marinas , Will Deacon , Paul Walmsley , Albert Ou , "Rafael J . Wysocki" , Len Brown , Bjorn Helgaas , Anup Patel , Thomas Gleixner , Samuel Holland , Greg Kroah-Hartman , Jiri Slaby , Robert Moore , Conor Dooley , Andrew Jones , Andy Shevchenko , Marc Zyngier , Atish Kumar Patra , Andrei Warkentin , Haibo1 Xu , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Sunil V L Subject: [PATCH v5 12/17] ACPI: RISC-V: Implement function to add implicit dependencies Date: Wed, 1 May 2024 17:47:37 +0530 Message-Id: <20240501121742.1215792-13-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240501121742.1215792-1-sunilvl@ventanamicro.com> References: <20240501121742.1215792-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 interrupt controllers for wired interrupts are platform devices and hence their driver will be probed late. Also, APLIC which is one such interrupt controller can not be probed early since it needs MSI services. This needs a probing order between the interrupt controller driver and the device drivers. _DEP is typically used to indicate such dependencies. However, the dependency may be already available like GSI mapping. Hence, instead of an explicit _DEP, architecture can find the implicit dependencies and add to the dependency list. For RISC-V, add the dependencies for below use cases. 1) For devices which has IRQ resource, find out the interrupt controller using GSI number map and add the dependency. 2) For PCI host bridges: a) If _PRT indicate PCI link devices, add dependency on the link device. b) If _PRT indicates GSI, find out the interrupt controller using GSI number map and add the dependency. Signed-off-by: Sunil V L --- drivers/acpi/riscv/irq.c | 155 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/drivers/acpi/riscv/irq.c b/drivers/acpi/riscv/irq.c index 0473428e8d1e..2878ae48131f 100644 --- a/drivers/acpi/riscv/irq.c +++ b/drivers/acpi/riscv/irq.c @@ -21,6 +21,12 @@ struct riscv_ext_intc_list { struct list_head list; }; +struct acpi_irq_dep_ctx { + int rc; + unsigned int index; + acpi_handle handle; +}; + LIST_HEAD(ext_intc_list); static int irqchip_cmp_func(const void *in0, const void *in1) @@ -62,6 +68,21 @@ static void riscv_acpi_update_gsi_handle(u32 gsi_base, acpi_handle handle) acpi_handle_err(handle, "failed to find the GSI mapping entry\n"); } +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) { @@ -172,3 +193,137 @@ void __init riscv_acpi_init_gsi_mapping(void) if (acpi_table_parse_madt(ACPI_MADT_TYPE_APLIC, riscv_acpi_aplic_parse_madt, 0) > 0) acpi_get_devices("RSCV0002", riscv_acpi_create_gsi_map, NULL, NULL); } + +static acpi_status riscv_acpi_irq_get_parent(struct acpi_resource *ares, void *context) +{ + struct acpi_irq_dep_ctx *ctx = context; + struct acpi_resource_irq *irq; + struct acpi_resource_extended_irq *eirq; + + switch (ares->type) { + case ACPI_RESOURCE_TYPE_IRQ: + irq = &ares->data.irq; + if (ctx->index >= irq->interrupt_count) { + ctx->index -= irq->interrupt_count; + return AE_OK; + } + ctx->handle = riscv_acpi_get_gsi_handle(irq->interrupts[ctx->index]); + return AE_CTRL_TERMINATE; + case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: + eirq = &ares->data.extended_irq; + if (eirq->producer_consumer == ACPI_PRODUCER) + return AE_OK; + + if (ctx->index >= eirq->interrupt_count) { + ctx->index -= eirq->interrupt_count; + return AE_OK; + } + + /* Support GSIs only */ + if (eirq->resource_source.string_length) + return AE_OK; + + ctx->handle = riscv_acpi_get_gsi_handle(eirq->interrupts[ctx->index]); + return AE_CTRL_TERMINATE; + } + + return AE_OK; +} + +static int riscv_acpi_irq_get_dep(acpi_handle handle, unsigned int index, acpi_handle *gsi_handle) +{ + struct acpi_irq_dep_ctx ctx = {-EINVAL, index, NULL}; + + if (!gsi_handle) + return 0; + + acpi_walk_resources(handle, METHOD_NAME__CRS, riscv_acpi_irq_get_parent, &ctx); + *gsi_handle = ctx.handle; + if (*gsi_handle) + return 1; + + return 0; +} + +static u32 riscv_acpi_add_prt_dep(acpi_handle handle) +{ + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_pci_routing_table *entry; + struct acpi_handle_list dep_devices; + acpi_handle gsi_handle; + acpi_handle link_handle; + acpi_status status; + u32 count = 0; + + status = acpi_get_irq_routing_table(handle, &buffer); + if (ACPI_FAILURE(status)) { + acpi_handle_err(handle, "failed to get IRQ routing table\n"); + kfree(buffer.pointer); + return 0; + } + + entry = buffer.pointer; + while (entry && (entry->length > 0)) { + if (entry->source[0]) { + acpi_get_handle(handle, entry->source, &link_handle); + dep_devices.count = 1; + dep_devices.handles = kcalloc(1, sizeof(*dep_devices.handles), GFP_KERNEL); + if (!dep_devices.handles) { + acpi_handle_err(handle, "failed to allocate memory\n"); + continue; + } + + dep_devices.handles[0] = link_handle; + count += acpi_scan_add_dep(handle, &dep_devices); + } else { + gsi_handle = riscv_acpi_get_gsi_handle(entry->source_index); + dep_devices.count = 1; + dep_devices.handles = kcalloc(1, sizeof(*dep_devices.handles), GFP_KERNEL); + if (!dep_devices.handles) { + acpi_handle_err(handle, "failed to allocate memory\n"); + continue; + } + + dep_devices.handles[0] = gsi_handle; + count += acpi_scan_add_dep(handle, &dep_devices); + } + + entry = (struct acpi_pci_routing_table *) + ((unsigned long)entry + entry->length); + } + + kfree(buffer.pointer); + return count; +} + +static u32 riscv_acpi_add_irq_dep(acpi_handle handle) +{ + struct acpi_handle_list dep_devices; + acpi_handle gsi_handle; + u32 count = 0; + int i; + + for (i = 0; + riscv_acpi_irq_get_dep(handle, i, &gsi_handle); + i++) { + dep_devices.count = 1; + dep_devices.handles = kcalloc(1, sizeof(*dep_devices.handles), GFP_KERNEL); + if (!dep_devices.handles) { + acpi_handle_err(handle, "failed to allocate memory\n"); + continue; + } + + dep_devices.handles[0] = gsi_handle; + count += acpi_scan_add_dep(handle, &dep_devices); + } + + return count; +} + +u32 arch_acpi_add_auto_dep(acpi_handle handle) +{ + if (acpi_has_method(handle, "_PRT")) + return riscv_acpi_add_prt_dep(handle); + + return riscv_acpi_add_irq_dep(handle); +} -- 2.40.1