Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp430416lqm; Wed, 1 May 2024 05:22:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUXT9sfDcY13D0CSEqtlcSwKbo3U13Ktdul7VCIl4kYnIRxbm0J3qpcjJ8BC7l4bQtVzS4fjxCSnx3MSUkLqGhuwtnrJRBiVtA8PAMMew== X-Google-Smtp-Source: AGHT+IGPPX1HHRQMB/nd4SPWhJpF50h/fzqEwTm9apUZcqsCFAD3kt7/p5bDN4zXuCR2n6hV3UaH X-Received: by 2002:a05:6122:3c53:b0:4d3:4ac2:29f4 with SMTP id fv19-20020a0561223c5300b004d34ac229f4mr2772173vkb.2.1714566147519; Wed, 01 May 2024 05:22:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714566147; cv=pass; d=google.com; s=arc-20160816; b=dlygHdcdxS4ebmqd/XjXxbUlyXeVye3L1rat/8HvvNHFri3NnZ1RToymf2kb8bR9Kd f2Boqw7khvnM41xNmba8o6WRky2H1Dk6lflAnDn26dXnD8lXQYYBjWoxI9+Nw0RneJH/ KnH2zMCAohexrdftVp/mA6C9hEFBmYhFBSmQWHuUSrZHU1mbBtPpBe0qpL8IrOpezClk s+mb6LP5DZhq3XPb2+XKwO6Yr6STz51NGzep9I+iw1Lgw7gMw3tORBdI25widGLC16gD 8v4c43ZUp2pH5SCUQK+CLYIpW71+pyaZDuZRwkbE9ZKUbcaljGVtlsOZHvMuJOKTNjTy fuRw== 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=zCPPOR1ckSAJZ1Ubedg9t4QsI9vLkLXGoLfn+9ixWV8=; fh=Ktgw3Xae5LayI6sNyFDSBmv5DU4Eep31oVKKo6JwKiw=; b=cFMFN6aNqgkV1jCQiAUxHS172SmmYjjLIogRLyubatDuHP8jJFvattgJ3XncvUU0yp FHCwd9vgtIGcbBArn+iQvFEdaZCuS37gJklQw0Ik0JnT85b86noFl2g98YexqgLYsx36 IxtkIOJJ+RdZEe2jpU77CmY9FjZAkcnjW5SiBYrdVdz2Nle2gML9ngH7ZurAhyXes8rO QJuckp2vHb0UXP+Nh1HQoCHl3Du/gJwN3U60YFKbZO7+5Grup8yGqPppiDzEk0CexRiS P12dd90+iy+fy4dtdVLhDUVUmM2IClmdTvZthGGxVd7enz5K6sGyTiZx4jpEt5+kuI74 gUEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=IaFa2q+Z; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-165228-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165228-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j12-20020ac5cccc000000b004d409235ec5si4873470vkn.40.2024.05.01.05.22.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 05:22:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165228-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=IaFa2q+Z; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-165228-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165228-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E25A01C210DC for ; Wed, 1 May 2024 12:22:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EAA9F12F385; Wed, 1 May 2024 12:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="IaFa2q+Z" Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 777E712BEAB for ; Wed, 1 May 2024 12:19:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714565986; cv=none; b=YVOsF08N/ERRKFwHV4iIN4tsPN+qVONjGPzogoJX+Y+74r7BQEFaSMgLJus4/RmqslhG9tDvo4C23bHxeSK2woaN1vXQvrygL3/Ff/6fP9T417rmqLWyTlvLi+gN2dadeATVFFCXvK83bjaIgl4iLV3PnOHW6xM3VkbJj3CIEvU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714565986; c=relaxed/simple; bh=ahgw0IfHPDtwuOAghidN1DUqYNQgZUOZv3r84r5UQZg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hlq81f6nMYayYS6u4n2lzRe/gGjAGTtr2fDcIfhQdhrWNLCwVhNOk7u9TR7t9q1ElmuFaMimSjonuKwcze1tPXlNmrAJjyXJva+OLVFipxv/bd+N4yuWzl9yHs/SOXDKKRN0DH7s/PgIL32HAlX69kj3+U4e6kwqqzYCvIBUVWY= 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=IaFa2q+Z; arc=none smtp.client-ip=209.85.214.182 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-f182.google.com with SMTP id d9443c01a7336-1eb0e08bfd2so33076445ad.1 for ; Wed, 01 May 2024 05:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1714565985; x=1715170785; 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=zCPPOR1ckSAJZ1Ubedg9t4QsI9vLkLXGoLfn+9ixWV8=; b=IaFa2q+ZhE7Q1d5K01vyR1jz9On9WXxrLwe1Bgu/VPyfM+IbnUyEwtET6hM0VB6JIp Mo1xe22WoyUCcsNELfXuVhnrvvaOJixMQvRNgaOyFW9jJTCpx9TqriZRHhwYkzZZL/HD iLnBbReDPeNZtyAYmw6YDel/zclSt4qMEcNLm5gDt7BWissE+2qIOppXIpHCg79t/q0P fHgO7G5vO/V/IEVzSAYNOnVNX6BA+qd4aReEER3xh1PQzXqVO14/lOkgwh41OhhZtH2K TPaMrrczEbtcO7NymPAt0TsqdG25/niKIyhf6qZttyEKQ8tmszWESpRqchDFs9vjetUH JL6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714565985; x=1715170785; 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=zCPPOR1ckSAJZ1Ubedg9t4QsI9vLkLXGoLfn+9ixWV8=; b=FV9lVo8YbKEXKxM8vohws+D1HQuHKJKlcFvCA7V8QPRLvWj07YxSuoyYjnCmvMAgdN RhOPkP3DonYthnWY7nAqcMhcXrFTHRXZAOxNFwZt6w5BugfSmkb1X7a0ppkTJZ+yajRW 4uuoWhyXh/pfJn/l/0ZoMoOVnbARbthVD7itYZHydUDhuWfY2YqgKWyc+98JyYYdwJTD jAVA/3RFJVqQiQHOCOV1qduGci/YZa8BSFfwwwRHFaL2AOREpr+dLvkBKrTfgqXNouLx 149abE3abc3hXmprGeS9rVYlSrUAiAu88OtPEjE1LYaFHiykCdhmwMmGLQ04kzVCaUfE I16A== X-Forwarded-Encrypted: i=1; AJvYcCU/rdSlre6B1rpDFINrwOB23txlf4W/nF6J2VfpwAGFmYGbqzns6eA/6EeeW7ohRUjiHu9/WKZjt+Cj77TrBWfTgdqYZM99kaIvvbLx X-Gm-Message-State: AOJu0Yw/vmwpIy/GLkwNdhGiyvYeiEtIwRqvaZhnGLwwDE3kKvrhZdHh eeBQ6Oh9AGfCNsd31Die5EjuA3NNgMrvgRqAAjjLhQKlO5rKot4Di2xlqncR3jo= X-Received: by 2002:a17:902:e841:b0:1eb:66b6:930b with SMTP id t1-20020a170902e84100b001eb66b6930bmr2252492plg.55.1714565984846; Wed, 01 May 2024 05:19:44 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 05:19:44 -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 13/17] irqchip/riscv-intc: Add ACPI support for AIA Date: Wed, 1 May 2024 17:47:38 +0530 Message-Id: <20240501121742.1215792-14-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 The RINTC subtype structure in MADT also has information about other interrupt controllers. Save this information and provide interfaces to retrieve them when required by corresponding drivers. Signed-off-by: Sunil V L --- arch/riscv/include/asm/irq.h | 35 +++++++++++ drivers/irqchip/irq-riscv-intc.c | 102 ++++++++++++++++++++++++++++++- 2 files changed, 135 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/irq.h b/arch/riscv/include/asm/irq.h index 44a0b128c602..6bd578b1ffc9 100644 --- a/arch/riscv/include/asm/irq.h +++ b/arch/riscv/include/asm/irq.h @@ -25,9 +25,22 @@ enum riscv_irqchip_type { ACPI_RISCV_IRQCHIP_APLIC = 0x03, }; +/* + * The ext_intc_id format is as follows: + * Bits [31:24] APLIC/PLIC ID + * Bits [15:0] APLIC IDC ID / PLIC S-Mode Context ID for this hart + */ +#define APLIC_PLIC_ID(x) ((x) >> 24) +#define IDC_CONTEXT_ID(x) ((x) & 0x0000ffff) + 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); +int __init acpi_get_intc_index_hartid(u32 index, unsigned long *hartid); +int acpi_get_ext_intc_parent_hartid(u8 id, u32 idx, unsigned long *hartid); +void acpi_get_plic_nr_contexts(u8 id, int *nr_contexts); +int acpi_get_plic_context(u8 id, u32 idx, int *context_id); +int __init acpi_get_imsic_mmio_info(u32 index, struct resource *res); #else static inline int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base, @@ -36,6 +49,28 @@ static inline int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi return 0; } +static inline int __init acpi_get_intc_index_hartid(u32 index, unsigned long *hartid) +{ + return -EINVAL; +} + +static inline int acpi_get_ext_intc_parent_hartid(u8 id, u32 idx, unsigned long *hartid) +{ + return -EINVAL; +} + +static inline void acpi_get_plic_nr_contexts(u8 id, int *nr_contexts) { } + +static inline int acpi_get_plic_context(u8 id, u32 idx, int *context_id) +{ + return -EINVAL; +} + +static inline int __init acpi_get_imsic_mmio_info(u32 index, struct resource *res) +{ + return 0; +} + #endif /* CONFIG_ACPI */ #endif /* _ASM_RISCV_IRQ_H */ diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c index 9e71c4428814..af7a2f78f0ee 100644 --- a/drivers/irqchip/irq-riscv-intc.c +++ b/drivers/irqchip/irq-riscv-intc.c @@ -249,14 +249,105 @@ IRQCHIP_DECLARE(riscv, "riscv,cpu-intc", riscv_intc_init); IRQCHIP_DECLARE(andes, "andestech,cpu-intc", riscv_intc_init); #ifdef CONFIG_ACPI +struct rintc_data { + u32 ext_intc_id; + unsigned long hart_id; + u64 imsic_addr; + u32 imsic_size; +}; + +static u32 nr_rintc; +static struct rintc_data *rintc_acpi_data[NR_CPUS]; + +int acpi_get_intc_index_hartid(u32 index, unsigned long *hartid) +{ + if (index >= nr_rintc) + return -1; + + *hartid = rintc_acpi_data[index]->hart_id; + return 0; +} + +int acpi_get_ext_intc_parent_hartid(u8 id, u32 idx, unsigned long *hartid) +{ + int i, j = 0; + + for (i = 0; i < nr_rintc; i++) { + if (APLIC_PLIC_ID(rintc_acpi_data[i]->ext_intc_id) == id) { + if (idx == j) { + *hartid = rintc_acpi_data[i]->hart_id; + return 0; + } + j++; + } + } + + return -1; +} + +void acpi_get_plic_nr_contexts(u8 id, int *nr_contexts) +{ + int i, j = 0; + + for (i = 0; i < nr_rintc; i++) { + if (APLIC_PLIC_ID(rintc_acpi_data[i]->ext_intc_id) == id) + j++; + } + + *nr_contexts = j; +} + +int acpi_get_plic_context(u8 id, u32 idx, int *context_id) +{ + int i, j = 0; + + for (i = 0; i < nr_rintc; i++) { + if (APLIC_PLIC_ID(rintc_acpi_data[i]->ext_intc_id) == id) { + if (idx == j) { + *context_id = IDC_CONTEXT_ID(rintc_acpi_data[i]->ext_intc_id); + return 0; + } + + j++; + } + } + + return -1; +} + +int acpi_get_imsic_mmio_info(u32 index, struct resource *res) +{ + if (index >= nr_rintc) + return -1; + + res->start = rintc_acpi_data[index]->imsic_addr; + res->end = res->start + rintc_acpi_data[index]->imsic_size - 1; + res->flags = IORESOURCE_MEM; + return 0; +} + +static struct fwnode_handle *ext_entc_get_gsi_domain_id(u32 gsi) +{ + return riscv_acpi_get_gsi_domain_id(gsi); +} static int __init riscv_intc_acpi_init(union acpi_subtable_headers *header, const unsigned long end) { - struct fwnode_handle *fn; struct acpi_madt_rintc *rintc; + struct fwnode_handle *fn; + int rc; rintc = (struct acpi_madt_rintc *)header; + rintc_acpi_data[nr_rintc] = kzalloc(sizeof(*rintc_acpi_data[0]), GFP_KERNEL); + if (!rintc_acpi_data[nr_rintc]) + return -ENOMEM; + + rintc_acpi_data[nr_rintc]->ext_intc_id = rintc->ext_intc_id; + rintc_acpi_data[nr_rintc]->hart_id = rintc->hart_id; + rintc_acpi_data[nr_rintc]->imsic_addr = rintc->imsic_addr; + rintc_acpi_data[nr_rintc]->imsic_size = rintc->imsic_size; + nr_rintc++; /* * The ACPI MADT will have one INTC for each CPU (or HART) @@ -273,7 +364,14 @@ static int __init riscv_intc_acpi_init(union acpi_subtable_headers *header, return -ENOMEM; } - return riscv_intc_init_common(fn, &riscv_intc_chip); + rc = riscv_intc_init_common(fn, &riscv_intc_chip); + if (rc) { + irq_domain_free_fwnode(fn); + return rc; + } + + acpi_set_irq_model(ACPI_IRQ_MODEL_RINTC, ext_entc_get_gsi_domain_id); + return 0; } IRQCHIP_ACPI_DECLARE(riscv_intc, ACPI_MADT_TYPE_RINTC, NULL, -- 2.40.1