Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1839724rwo; Wed, 2 Aug 2023 23:57:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlHyxaks1pHgnQVxqxRsVF+ExYV6udHjeNz3NtEWOUSEobOTyyBkJAzG3pmt1cGu/3WDSG3W X-Received: by 2002:a2e:880b:0:b0:2b6:e196:68c4 with SMTP id x11-20020a2e880b000000b002b6e19668c4mr6424096ljh.39.1691045830110; Wed, 02 Aug 2023 23:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691045830; cv=none; d=google.com; s=arc-20160816; b=t/kMHOv+Sy9h2i8lX+4caNnaDtgyULygEJZ76CJCm8Pb34YyE3UjmzkAV1L8LL1tqJ x/NZxFzdWf6wU/45LQCqx5vAn2ix2otf6m15348asycjy5ZhnLInnXQ5+NqPPDQV7IMi vKnaxQUQ7xR42e/fu8axEkH4MFjNcE6h/4r6MA2MrMAGfzkWMa91Vj97VP1zeN2QQkuT CIwmQrR52XzomjNywe7+KFg78lXBjv5SOQTiOxzLD6hRZCCf/tFDy7+VpXV+szDv6YpC IYK9BjrLCp6pI6464i66ojjJ/Y5MdvGQ0AhsDuUGl5kjDjgAPcdb8nDJl3U67eU8txpj C2oA== 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; bh=8wH5u1P0xsjAUe1QhWj+PsW33W1kvkq4Ik5lxtFfaq4=; fh=PK7qZE2l3RufuWL/yvUO8bu8mrcIpscTWlY+prmDsuM=; b=f8m0cNsBfkvxUFo4o7SP3GfZ8ifgI4M94tEdn8FBz5Mw02Ia+7QIK3VSv4JsjZ6qT1 kDRDqMtCeaf6zhZyrJLGKmxdooWEDLkl4loeAb62g2bbGu8kMyJO1tafPItOsPPH4ZN2 5gLvR4K85a43mqcqSorp3NOYLw855aZisZZGCggTrD+PQ3JYw3Q77ppd7Esuu7MSngDO QLLzmmFUYpeWqyZJQUqVBZgE2b+MSuo37uE3Qrkt91LRH5bVb8ExGPL4b5Q0wnorENY7 UB6oHH1N/SWaMP/P7SGQaY4aVFT9mcU+VwU1MyNwAxh7UJUcl9RyJjT+6kGq4+RXCZ6P PF2w== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m15-20020a17090607cf00b00992feaebee8si155821ejc.943.2023.08.02.23.56.45; Wed, 02 Aug 2023 23:57:10 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232593AbjHCF5R (ORCPT + 99 others); Thu, 3 Aug 2023 01:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229944AbjHCF5N (ORCPT ); Thu, 3 Aug 2023 01:57:13 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0A9122D43 for ; Wed, 2 Aug 2023 22:57:12 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7870C12FC; Wed, 2 Aug 2023 22:57:54 -0700 (PDT) Received: from a077893.blr.arm.com (unknown [10.162.42.10]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 22F2D3F6C4; Wed, 2 Aug 2023 22:57:06 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org, suzuki.poulose@arm.com Cc: Anshuman Khandual , Sami Mujawar , Catalin Marinas , Will Deacon , Mark Rutland , Mike Leach , Leo Yan , Alexander Shishkin , James Clark , coresight@lists.linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 1/4] arm_pmu: acpi: Refactor arm_spe_acpi_register_device() Date: Thu, 3 Aug 2023 11:26:49 +0530 Message-Id: <20230803055652.1322801-2-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230803055652.1322801-1-anshuman.khandual@arm.com> References: <20230803055652.1322801-1-anshuman.khandual@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Sanity checking all the GICC tables for same interrupt number, and ensuring a homogeneous ACPI based machine, could be used for other platform devices as well. Hence this refactors arm_spe_acpi_register_device() into a common helper arm_acpi_register_pmu_device(). Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Co-developed-by: Will Deacon Signed-off-by: Will Deacon Signed-off-by: Anshuman Khandual --- drivers/perf/arm_pmu_acpi.c | 107 ++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 40 deletions(-) diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c index 90815ad762eb..235c14766a36 100644 --- a/drivers/perf/arm_pmu_acpi.c +++ b/drivers/perf/arm_pmu_acpi.c @@ -70,6 +70,65 @@ static void arm_pmu_acpi_unregister_irq(int cpu) } #if IS_ENABLED(CONFIG_ARM_SPE_PMU) +static int +arm_acpi_register_pmu_device(struct platform_device *pdev, u8 len, + u16 (*parse_gsi)(struct acpi_madt_generic_interrupt *)) +{ + int cpu, this_hetid, hetid, irq, ret; + u16 this_gsi, gsi = 0; + + /* + * Ensure that platform device must have IORESOURCE_IRQ + * resource to hold gsi interrupt. + */ + if (pdev->num_resources != 1) + return -ENXIO; + + if (pdev->resource[0].flags != IORESOURCE_IRQ) + return -ENXIO; + + /* + * Sanity check all the GICC tables for the same interrupt + * number. For now, only support homogeneous ACPI machines. + */ + for_each_possible_cpu(cpu) { + struct acpi_madt_generic_interrupt *gicc; + + gicc = acpi_cpu_get_madt_gicc(cpu); + if (gicc->header.length < len) + return gsi ? -ENXIO : 0; + + this_gsi = parse_gsi(gicc); + if (!this_gsi) + return gsi ? -ENXIO : 0; + + this_hetid = find_acpi_cpu_topology_hetero_id(cpu); + if (!gsi) { + hetid = this_hetid; + gsi = this_gsi; + } else if (hetid != this_hetid || gsi != this_gsi) { + pr_warn("ACPI: %s: must be homogeneous\n", pdev->name); + return -ENXIO; + } + } + + irq = acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_HIGH); + if (irq < 0) { + pr_warn("ACPI: %s Unable to register interrupt: %d\n", pdev->name, gsi); + return -ENXIO; + } + + pdev->resource[0].start = irq; + ret = platform_device_register(pdev); + if (ret < 0) { + pr_warn("ACPI: %s: Unable to register device\n", pdev->name); + acpi_unregister_gsi(gsi); + } + return ret; +} +#endif + +#ifdef CONFIG_ARM_SPE_PMU static struct resource spe_resources[] = { { /* irq */ @@ -84,6 +143,11 @@ static struct platform_device spe_dev = { .num_resources = ARRAY_SIZE(spe_resources) }; +static u16 arm_spe_parse_gsi(struct acpi_madt_generic_interrupt *gicc) +{ + return gicc->spe_interrupt; +} + /* * For lack of a better place, hook the normal PMU MADT walk * and create a SPE device if we detect a recent MADT with @@ -91,47 +155,10 @@ static struct platform_device spe_dev = { */ static void arm_spe_acpi_register_device(void) { - int cpu, hetid, irq, ret; - bool first = true; - u16 gsi = 0; - - /* - * Sanity check all the GICC tables for the same interrupt number. - * For now, we only support homogeneous ACPI/SPE machines. - */ - for_each_possible_cpu(cpu) { - struct acpi_madt_generic_interrupt *gicc; - - gicc = acpi_cpu_get_madt_gicc(cpu); - if (gicc->header.length < ACPI_MADT_GICC_SPE) - return; - - if (first) { - gsi = gicc->spe_interrupt; - if (!gsi) - return; - hetid = find_acpi_cpu_topology_hetero_id(cpu); - first = false; - } else if ((gsi != gicc->spe_interrupt) || - (hetid != find_acpi_cpu_topology_hetero_id(cpu))) { - pr_warn("ACPI: SPE must be homogeneous\n"); - return; - } - } - - irq = acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, - ACPI_ACTIVE_HIGH); - if (irq < 0) { - pr_warn("ACPI: SPE Unable to register interrupt: %d\n", gsi); - return; - } - - spe_resources[0].start = irq; - ret = platform_device_register(&spe_dev); - if (ret < 0) { + int ret = arm_acpi_register_pmu_device(&spe_dev, ACPI_MADT_GICC_SPE, + arm_spe_parse_gsi); + if (ret) pr_warn("ACPI: SPE: Unable to register device\n"); - acpi_unregister_gsi(gsi); - } } #else static inline void arm_spe_acpi_register_device(void) -- 2.25.1