Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4326946rwb; Mon, 31 Jul 2023 05:24:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlEoZ383Fz8Db01llLDRllnwp0EJmRdPKFLv2ZF3kTIS0URxnBVWXR+pLdPB0NRdoj4sepjK X-Received: by 2002:a17:906:249:b0:99b:d178:f059 with SMTP id 9-20020a170906024900b0099bd178f059mr6692867ejl.35.1690806254375; Mon, 31 Jul 2023 05:24:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690806254; cv=none; d=google.com; s=arc-20160816; b=CXRBHbNZCXg9wqPJFvV4zq4TUJR/izei7BXRDVvOw453IyOLrwI/lzn44dXobagses rKXLtLN/w+BbyDvv8tgtFbwUTABRjsJPVIakop0Z0C+T8s6WNWE4x3uuuOpJzEfSDAU/ qCBTRcoG3tKeASU1yQSIlAG89GqpBSEuZJRh+y58AkrqTFc48RY57pvH8smJSEOScsag qdE2U2HzPY7qrxymd+onMWOl2gUAhMIfjv+O9I+zQF3vsZiRERPGbC0G0u7Oxsdf3Fa8 Cs2HSD1F4WliUD4f4LxaPXOIZq/cWASsIm9tWfuYXCE3CGc/v52akzPoUmeYTdQfuk12 4Sbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id; bh=118pjJzaJ300Pwag5HchJ0J6wdjG2+9xtlksMMWVZJ8=; fh=jV5xtEIfej03nibAmcg4MoGauEboeMW2AigK786I/1s=; b=UkkngoiSA4APAjKwrZkJU+Jwcq9ZeaTGEt1aZWTCzoJ6D/iAmRv8xz/sF5KsADEjdb pf3UbKhowOy80CK3YE1A/N06tOkRC/912tbIy09wMMz5F7zFwJPd0cOIFDn4X3fH970y E5+5IMCOC70tbfi0ikaTSPsXUJt0YQUhEir554gUpuyPCVGOiTwhA4WMJmJ+D20HLwsu +KJ6TpGAV+f5wPSb4Xk5dP4nkQhJj9lwP9lWkqUnvarkTrTFJw5jl+3ndnB+lnqH/+CY mw2G4ke/dnF4xOt51piJb6UVzLp8rZFOknBMJ3moxRs1Dorbviht3EpXEjwCVq9+nyvQ PatA== 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 o21-20020a17090637d500b00992e23ef221si3484879ejc.564.2023.07.31.05.23.48; Mon, 31 Jul 2023 05:24:14 -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 S229753AbjGaMIs (ORCPT + 99 others); Mon, 31 Jul 2023 08:08:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbjGaMIq (ORCPT ); Mon, 31 Jul 2023 08:08:46 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EC6A410F0 for ; Mon, 31 Jul 2023 05:08:44 -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 A407DD75; Mon, 31 Jul 2023 05:09:27 -0700 (PDT) Received: from [10.163.53.56] (unknown [10.163.53.56]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 362FA3F5A1; Mon, 31 Jul 2023 05:08:41 -0700 (PDT) Message-ID: <3ee165d7-3727-53cc-295d-a2108734952d@arm.com> Date: Mon, 31 Jul 2023 17:38:38 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 From: Anshuman Khandual Subject: Re: [PATCH 1/3] arm_pmu: acpi: Add a representative platform device for TRBE To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, suzuki.poulose@arm.com, Catalin Marinas , Mark Rutland , linux-kernel@vger.kernel.org References: <20230728112733.359620-1-anshuman.khandual@arm.com> <20230728112733.359620-2-anshuman.khandual@arm.com> <20230728144056.GE21718@willie-the-truck> Content-Language: en-US In-Reply-To: <20230728144056.GE21718@willie-the-truck> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 On 7/28/23 20:10, Will Deacon wrote: > On Fri, Jul 28, 2023 at 04:57:31PM +0530, Anshuman Khandual wrote: >> ACPI TRBE does not have a HID for identification which could create and add >> a platform device into the platform bus. Also without a platform device, it >> cannot be probed and bound to a platform driver. >> >> This creates a dummy platform device for TRBE after ascertaining that ACPI >> provides required interrupts uniformly across all cpus on the system. This >> device gets created inside drivers/perf/arm_pmu_acpi.c to accommodate TRBE >> being built as a module. >> >> Cc: Catalin Marinas >> Cc: Will Deacon >> Cc: Mark Rutland >> Cc: linux-arm-kernel@lists.infradead.org >> Cc: linux-kernel@vger.kernel.org >> Signed-off-by: Anshuman Khandual > > --->8 > >> diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c >> index 90815ad762eb..dd3df6729808 100644 >> --- a/drivers/perf/arm_pmu_acpi.c >> +++ b/drivers/perf/arm_pmu_acpi.c >> @@ -139,6 +139,68 @@ static inline void arm_spe_acpi_register_device(void) >> } >> #endif /* CONFIG_ARM_SPE_PMU */ >> >> +#ifdef CONFIG_CORESIGHT_TRBE >> +static struct resource trbe_acpi_resources[] = { >> + { >> + /* irq */ >> + .flags = IORESOURCE_IRQ, >> + } >> +}; >> + >> +static struct platform_device trbe_acpi_dev = { >> + .name = ARMV8_TRBE_PDEV_NAME, >> + .id = -1, >> + .resource = trbe_acpi_resources, >> + .num_resources = ARRAY_SIZE(trbe_acpi_resources) >> +}; >> + >> +static void arm_trbe_acpi_register_device(void) >> +{ >> + int cpu, hetid, irq, ret; >> + bool first = true; >> + u16 gsi = 0; >> + >> + 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_TRBE) >> + return; >> + >> + if (first) { >> + gsi = gicc->trbe_interrupt; >> + if (!gsi) >> + return; >> + >> + hetid = find_acpi_cpu_topology_hetero_id(cpu); >> + first = false; >> + } else if ((gsi != gicc->trbe_interrupt) || >> + (hetid != find_acpi_cpu_topology_hetero_id(cpu))) { >> + pr_warn("ACPI: TRBE must be homogeneous\n"); >> + return; >> + } >> + } >> + >> + irq = acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_HIGH); >> + if (irq < 0) { >> + pr_warn("ACPI: TRBE Unable to register interrupt: %d\n", gsi); >> + return; >> + } >> + trbe_acpi_resources[0].start = irq; >> + >> + ret = platform_device_register(&trbe_acpi_dev); >> + if (ret < 0) { >> + pr_warn("ACPI: TRBE: Unable to register device\n"); >> + acpi_unregister_gsi(gsi); >> + } >> +} >> +#else >> +static inline void arm_trbe_acpi_register_device(void) >> +{ >> + >> +} >> +#endif /* CONFIG_CORESIGHT_TRBE */ > > This looks like you ran s/spe/trbe/ over the SPE device registration > code :) Yeah, almost :) > > Please can you refactor things so we don't have all the duplication? I > suspect this won't be the last device which needs the same treatement. Should the refactoring just accommodate SPE, and TRBE or make it more generic to accommodate future devices as well. Something like the following enumeration. enum arm_platform_device { ARM_PLATFORM_DEVICE_SPE, ARM_PLATFORM_DEVICE_TRBE, ARM_PLATFORM_DEVICE_MAX, }; But that would require adding some helper functions to select these following elements based on the above enumeration via a common function - gicc->XXX_interrupt - ACPI_MADT_GICC_SPE/TRBE for header length comparison - static struct platform_device/resources (static objects in the file) Seems like will add much more code for a refactor. Did you have something else in mind for the refactor.