From patchwork Wed Oct 25 20:23:43 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: 158291 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp219000vqb; Wed, 25 Oct 2023 13:27:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7Psmp0vlL38z/pB+0i15zztJo3Uo2d5RRdnxeThe9c1fgOYHcbSAJkfb6BBFK6gFmrmUN X-Received: by 2002:aca:2110:0:b0:3a7:1e86:e83f with SMTP id 16-20020aca2110000000b003a71e86e83fmr16534732oiz.51.1698265670165; Wed, 25 Oct 2023 13:27:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698265670; cv=none; d=google.com; s=arc-20160816; b=Kx/E53Y8NG4jG2IQ53iBgkNC3QxCxyP3xaR4817cDu2t9QTkccGJnM7K8THjYVpU9Y hL9PtrNDu8ygaTsQDkZiE6UPx7ArH2Fh4ynKZZVIt5o69nsI5nnAxgTmYvOtjjCTSI/s Gq2yER238LC5zCINVdub7OvA9YBgmEMCOK5ccDH5EYb/YQ+KhpnhDx+3a+hl+VR4zzbD rPeWuMMTlu/u0Hm85apA+LvUBn/IZHcNG02CQGpaLYNIfjVAfeR5ZnSqvDjeRvJqf5+E 5aaehuHaCzmPRX3f++CNZUy9cvoVD5QcUTSyD/q2zuCkpoxmYdmOu0A7tqE2iEE0Ao93 J7/g== 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=YyAbjmaR4eN/4ltFJMCVbHeHJN24CQKSdc3guUQ+sXY=; fh=/fEAwM0ftwV2z3MN/iSYq1lv8IFPZ2fY8Kg8RoFcxjU=; b=VN2PtO92q04H/TgakUgkp03K9kW8A+/BPtvomkik5zKE8MhHEuxO9FkVQ4vjBek7qj BVS5eM+QRtEpWzNqfim2gkUnYvXkDptmyTQtQDqyKxVeMl2AxcTwXBOx6g1Kc2UxvJ0v xT0MCwfJpHnXV+WwXur4an8zXWWpCKzsJhawQOkUokpPlVgA0f+DQ9aHYLkHC/VlXANA 0hSuo0Mg12aFk8kmfgZ+K1U1Q+ckzEOsLug4uOSkt90baDVkysIOzQXUahZkFrmvf+vx NRiTgrWCFbQL6qkFuXrmXGAVvBGpYplhMlmuTXKM6xZDyKCTf+98vdsKnfi0fpZjVn5H H9DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=lYxzdUsu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id e3-20020a251e03000000b00d9a61b3818asi11097851ybe.258.2023.10.25.13.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 13:27:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=lYxzdUsu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 20AE180295F5; Wed, 25 Oct 2023 13:27:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235131AbjJYU1k (ORCPT + 25 others); Wed, 25 Oct 2023 16:27:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343976AbjJYU1G (ORCPT ); Wed, 25 Oct 2023 16:27:06 -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 896661FCF for ; Wed, 25 Oct 2023 13:26:05 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-5a9d8f4388bso150872a12.3 for ; Wed, 25 Oct 2023 13:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1698265565; x=1698870365; 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=YyAbjmaR4eN/4ltFJMCVbHeHJN24CQKSdc3guUQ+sXY=; b=lYxzdUsuOneYhoIV+rYgVVKZNSp0/KjI1w4hVj4ZjBNi+d684vIjZpU3C5bvKho2ua T2HrWtolaPG2TtCyFcRW3Xxn5fhO+hrUq0ptTInqJZpUTl6SEfVKEY0lCWGHetvIItds a1q4/Rd9BDYEV60OZ/wnKfgr2DV0HhRXr7hQWLRB7a4JI6UCSb1IEnbVRoCK6N5+zJQ0 E0xjWFarsTv4yN7dEsRjvdFs32Fj+9KZwuRWlZfe+pfoND04lmh6m1gf2zVvL+qSKrgH Al57+cknEsACPvo1q0XjaTcQjPfchYsjS+zI9JL+wL2NK2BykB3W+pb5SlOr+1hLhTKX nSSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698265565; x=1698870365; 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=YyAbjmaR4eN/4ltFJMCVbHeHJN24CQKSdc3guUQ+sXY=; b=M80zHqiyQtw18LYYweoU9J41uRxTAjv9DOUW0UzfJjmXk7vzw5xhWptFa3MhvFrxyL PHs4u8JQLKp0QAIEkwkxR3j0N5iTUXsxKWhY1/Mx89WqQDUrHXcdTwf4YQByNkjSZO8G hKICZuRpIZHHrNeDr3D9yBIWfB29X9SUJuASTFblPPrde0XgE3Vt1DLkoBUGT/7c/vMg FPkNUP2UIAMvRn2EcQcVsJefrFQJlYwMo1MwEMVlKE+NKp+Xka3uqyHmpRvW1858231e 21Eb7vVzFsYhC//KDzmxSd6vD2u5ah2AyblrfucXErIqgcOx55JPMmODoCSE81Be59MP rCMw== X-Gm-Message-State: AOJu0YxCqeAWk+wVeAL7t5ItYEBwzuNoRh8bVCXj3+LEIJ1wJXHS582L qu6I6sN2SS/QQdOycpDqbIRjtA== X-Received: by 2002:a05:6a20:3d13:b0:16b:8132:b547 with SMTP id y19-20020a056a203d1300b0016b8132b547mr8489178pzi.4.1698265564985; Wed, 25 Oct 2023 13:26:04 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.188.78]) by smtp.gmail.com with ESMTPSA id y3-20020aa79423000000b006b84ed9371esm10079590pfo.177.2023.10.25.13.25.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 13:26:04 -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 Cc: Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Rafael J . Wysocki" , Len Brown , Bjorn Helgaas , Anup Patel , Thomas Gleixner , Greg Kroah-Hartman , Jiri Slaby , Conor Dooley , Andrew Jones , Atish Kumar Patra , Haibo Xu , Sunil V L Subject: [RFC PATCH v2 20/21] ACPI: RISC-V: Create APLIC platform device Date: Thu, 26 Oct 2023 01:53:43 +0530 Message-Id: <20231025202344.581132-21-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231025202344.581132-1-sunilvl@ventanamicro.com> References: <20231025202344.581132-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 25 Oct 2023 13:27:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780760623091452564 X-GMAIL-MSGID: 1780760623091452564 Since APLIC needs to be a platform device, probe the MADT and create platform devices for each APLIC in the system. Signed-off-by: Sunil V L --- drivers/acpi/riscv/init.c | 2 ++ drivers/acpi/riscv/init.h | 5 +++ drivers/acpi/riscv/irq.c | 74 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 drivers/acpi/riscv/init.h diff --git a/drivers/acpi/riscv/init.c b/drivers/acpi/riscv/init.c index b5807bbdb171..e7eff7ab1474 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_aplic_platform_init(); } diff --git a/drivers/acpi/riscv/init.h b/drivers/acpi/riscv/init.h new file mode 100644 index 000000000000..17bcf0baaadb --- /dev/null +++ b/drivers/acpi/riscv/init.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include + +void __init riscv_acpi_imsic_platform_init(void); +void __init riscv_acpi_aplic_platform_init(void); diff --git a/drivers/acpi/riscv/irq.c b/drivers/acpi/riscv/irq.c index 36e0525b3235..fbccecdcbf8b 100644 --- a/drivers/acpi/riscv/irq.c +++ b/drivers/acpi/riscv/irq.c @@ -6,6 +6,8 @@ */ #include +#include +#include #include static int irqchip_cmp_func(const void *in0, const void *in1) @@ -30,3 +32,75 @@ 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 __init irqchip_add_platform_device(char *irqchip_name, u32 irqchip_id, + resource_size_t iomem_res_start, + resource_size_t iomem_res_size, + union acpi_subtable_headers *header) +{ + struct platform_device *pdev; + struct fwnode_handle *fn; + struct resource *res; + int ret; + + fn = irq_domain_alloc_named_id_fwnode(irqchip_name, irqchip_id); + if (!fn) + return -ENOMEM; + + pdev = platform_device_alloc(irqchip_name, irqchip_id); + if (!pdev) { + irq_domain_free_fwnode(fn); + return -ENOMEM; + } + + res = kcalloc(1, sizeof(*res), GFP_KERNEL); + if (!res) { + irq_domain_free_fwnode(fn); + platform_device_put(pdev); + return -ENOMEM; + } + + res->start = iomem_res_start; + res->end = res->start + iomem_res_size - 1; + res->flags = IORESOURCE_MEM; + ret = platform_device_add_resources(pdev, res, 1); + /* + * Resources are duplicated in platform_device_add_resources, + * free their allocated memory + */ + kfree(res); + + /* + * Add copy of aplic pointer so that platform driver get aplic details. + */ + ret = platform_device_add_data(pdev, &header, sizeof(header)); + if (ret) { + irq_domain_free_fwnode(fn); + platform_device_put(pdev); + return ret; + } + + pdev->dev.fwnode = fn; + ret = platform_device_add(pdev); + if (ret) { + irq_domain_free_fwnode(fn); + platform_device_put(pdev); + return ret; + } + + return 0; +} + +static int __init aplic_parse_madt(union acpi_subtable_headers *header, + const unsigned long end) +{ + struct acpi_madt_aplic *aplic = (struct acpi_madt_aplic *)header; + + return irqchip_add_platform_device("riscv-aplic", aplic->id, aplic->base_addr, + aplic->size, header); +} + +void __init riscv_acpi_aplic_platform_init(void) +{ + acpi_table_parse_madt(ACPI_MADT_TYPE_APLIC, aplic_parse_madt, 0); +}