From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0B0CC433F5 for ; Fri, 30 Sep 2022 17:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qUnwOXDNKv7bDxWw9natlvkeFumHSF/itDTs68Ont8g=; b=APy1XB46ErWVvb 6c3hovH1y3Dxchg8ZJXEP8uvC9z6J8z7yO0pLOdWaoa81tKhXrT36g/kDaDrte+biQs9/KdLjIeaq zaZBKutL9NRSiT4T/ztUyHidZehZHIHJv38VwdVMYiQmhXwxwr8fEAw4MlD+4zHm9uhGXmi9KOmkt 9DqY6vfcVMXFo/Zmn8rXpwRHiXtNj+Xt+UhDeV0l2JZhTYZzHyX1hrK4/UW6SM21uxx1BfyUQmQc3 jkwCgjw+9QeXWlj4djX3hjLR5lON7+KCNIscq5a3g/uMYdnz0N8Wk6Hwr4XoWEBOibg3bHCG8Cpsp Z3PIzquH8vEkA8zO8kdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oeK5g-00ArDI-Uh; Fri, 30 Sep 2022 17:46:25 +0000 Received: from mail-qt1-f175.google.com ([209.85.160.175]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oeK5d-00ArCZ-Kg for linux-arm-kernel@lists.infradead.org; Fri, 30 Sep 2022 17:46:23 +0000 Received: by mail-qt1-f175.google.com with SMTP id gb14so3110957qtb.3 for ; Fri, 30 Sep 2022 10:46:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=UWpIBj+/9sQw5QyigeVTqr3A6AC0TPRLfI1uqBcxDFQ=; b=D6IiaZSTcOoweyYToNQd0b0LNStxBfvXAMxHxObzWNw8w7WGNQXcNYDc31+0dWM3al EMg1QCzTWgzR4eGOr+FVwt61Az7Rc4B/ugk7uSdDY+vtNHZ7Hk0SsXTic6hurZCJoSno 4uR85BDMTfFZ/Cc71KWYhAdcmyg1BRWuluCMiwjfCZJwCK0K7VWiUMIquRyNRj5wDHYX pvKqE/+0pJOx1lKfqubo/iYR2wbn9Nh4N4jStKhxNDMsqDQOWmF0OyaMyNBS3omB39uC vUtBYfiyp0S4OChRkVhXiQYn0t1opINdSHF7jhMYyLSfplISxjzNLd3XJ/CH+h/rYsNc MB8g== X-Gm-Message-State: ACrzQf0yxTBsLdX2jM0C5vOLKPw5wyEUWQM+0wmmp2j+xpKs01i9+n9z MsLgEYFkhGHyU/PcCC8B+klmSWIPq5SF1nOonIg= X-Google-Smtp-Source: AMsMyM4m7jwXON/4b4YZv4l+r4LmRE0QFUsGIqap9s7oQh8aq/1X51OA+Ojtt77lDUokyhsUUE54UNjZsPEN39MaHno= X-Received: by 2002:a05:622a:1a08:b0:35c:d9b5:144b with SMTP id f8-20020a05622a1a0800b0035cd9b5144bmr7795240qtb.27.1664559979468; Fri, 30 Sep 2022 10:46:19 -0700 (PDT) MIME-Version: 1.0 References: <20220929002834.32664-1-bwicaksono@nvidia.com> In-Reply-To: <20220929002834.32664-1-bwicaksono@nvidia.com> From: "Rafael J. Wysocki" Date: Fri, 30 Sep 2022 19:46:08 +0200 Message-ID: Subject: Re: [PATCH v2] ACPI: ARM Performance Monitoring Unit Table (APMT) initial support To: Besar Wicaksono , sudeep.holla@arm.com, lorenzo.pieralisi@arm.com Cc: lenb@kernel.org, catalin.marinas@arm.com, will@kernel.org, guohanjun@huawei.com, linux-tegra@vger.kernel.org, treding@nvidia.com, jonathanh@nvidia.com, vsethi@nvidia.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220930_104621_728456_4C4AEFB0 X-CRM114-Status: GOOD ( 41.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 29, 2022 at 2:29 AM Besar Wicaksono wrote: > > ARM Performance Monitoring Unit Table describes the properties of PMU > support in ARM-based system. The APMT table contains a list of nodes, > each represents a PMU in the system that conforms to ARM CoreSight PMU > architecture. The properties of each node include information required > to access the PMU (e.g. MMIO base address, interrupt number) and also > identification. For more detailed information, please refer to the > specification below: > * APMT: https://developer.arm.com/documentation/den0117/latest > * ARM Coresight PMU: > https://developer.arm.com/documentation/ihi0091/latest > > The initial support adds the detection of APMT table and generic > infrastructure to create platform devices for ARM CoreSight PMUs. > Similar to IORT the root pointer of APMT is preserved during runtime > and each PMU platform device is given a pointer to the corresponding > APMT node. > > Signed-off-by: Besar Wicaksono Acked-by: Rafael J. Wysocki for the change in bus.c, but as a side note, it would be good to move all of the ARM-specific initialization into one place, so it is not necessary to touch bus.c every time a new piece of it is added. > --- > > The patch applies on top of > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git > master next-20220524 > > Changes from v1: > * Include acpi_apmt.h header file > * Update the device name. Related driver patch: > https://lore.kernel.org/linux-arm-kernel/20220928201830.45637-1-bwicaksono@nvidia.com/ > v1: https://lkml.org/lkml/2022/4/19/1395 > > arch/arm64/Kconfig | 1 + > drivers/acpi/arm64/Kconfig | 3 + > drivers/acpi/arm64/Makefile | 1 + > drivers/acpi/arm64/apmt.c | 177 ++++++++++++++++++++++++++++++++++++ > drivers/acpi/bus.c | 2 + > include/linux/acpi_apmt.h | 19 ++++ > 6 files changed, 203 insertions(+) > create mode 100644 drivers/acpi/arm64/apmt.c > create mode 100644 include/linux/acpi_apmt.h > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index aaeb70358979..dbcb09ee29dd 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -1,6 +1,7 @@ > # SPDX-License-Identifier: GPL-2.0-only > config ARM64 > def_bool y > + select ACPI_APMT if ACPI > select ACPI_CCA_REQUIRED if ACPI > select ACPI_GENERIC_GSI if ACPI > select ACPI_GTDT if ACPI > diff --git a/drivers/acpi/arm64/Kconfig b/drivers/acpi/arm64/Kconfig > index d4a72835f328..b3ed6212244c 100644 > --- a/drivers/acpi/arm64/Kconfig > +++ b/drivers/acpi/arm64/Kconfig > @@ -18,3 +18,6 @@ config ACPI_AGDI > reset command. > > If set, the kernel parses AGDI table and listens for the command. > + > +config ACPI_APMT > + bool > diff --git a/drivers/acpi/arm64/Makefile b/drivers/acpi/arm64/Makefile > index 7b9e4045659d..e21a9e84e394 100644 > --- a/drivers/acpi/arm64/Makefile > +++ b/drivers/acpi/arm64/Makefile > @@ -2,4 +2,5 @@ > obj-$(CONFIG_ACPI_AGDI) += agdi.o > obj-$(CONFIG_ACPI_IORT) += iort.o > obj-$(CONFIG_ACPI_GTDT) += gtdt.o > +obj-$(CONFIG_ACPI_APMT) += apmt.o > obj-y += dma.o > diff --git a/drivers/acpi/arm64/apmt.c b/drivers/acpi/arm64/apmt.c > new file mode 100644 > index 000000000000..f55167ca51e7 > --- /dev/null > +++ b/drivers/acpi/arm64/apmt.c > @@ -0,0 +1,177 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * ARM APMT table support. > + * Design document number: ARM DEN0117. > + * > + * Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. > + * > + */ > + > +#define pr_fmt(fmt) "ACPI: APMT: " fmt > + > +#include > +#include > +#include > +#include > +#include > + > +#define DEV_NAME "arm-cs-arch-pmu" > + > +/* There can be up to 3 resources: page 0 and 1 address, and interrupt. */ > +#define DEV_MAX_RESOURCE_COUNT 3 > + > +/* Root pointer to the mapped APMT table */ > +static struct acpi_table_header *apmt_table; > + > +static int __init apmt_init_resources(struct resource *res, > + struct acpi_apmt_node *node) > +{ > + int irq, trigger; > + int num_res = 0; > + > + res[num_res].start = node->base_address0; > + res[num_res].end = node->base_address0 + SZ_4K - 1; > + res[num_res].flags = IORESOURCE_MEM; > + > + num_res++; > + > + res[num_res].start = node->base_address1; > + res[num_res].end = node->base_address1 + SZ_4K - 1; > + res[num_res].flags = IORESOURCE_MEM; > + > + num_res++; > + > + if (node->ovflw_irq != 0) { > + trigger = (node->ovflw_irq_flags & ACPI_APMT_OVFLW_IRQ_FLAGS_MODE); > + trigger = (trigger == ACPI_APMT_OVFLW_IRQ_FLAGS_MODE_LEVEL) ? > + ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE; > + irq = acpi_register_gsi(NULL, node->ovflw_irq, trigger, > + ACPI_ACTIVE_HIGH); > + > + if (irq <= 0) { > + pr_warn("APMT could not register gsi hwirq %d\n", irq); > + return num_res; > + } > + > + res[num_res].start = irq; > + res[num_res].end = irq; > + res[num_res].flags = IORESOURCE_IRQ; > + > + num_res++; > + } > + > + return num_res; > +} > + > +/** > + * apmt_add_platform_device() - Allocate a platform device for APMT node > + * @node: Pointer to device ACPI APMT node > + * > + * Returns: 0 on success, <0 failure > + */ > +static int __init apmt_add_platform_device(struct acpi_apmt_node *node, > + struct fwnode_handle *fwnode) > +{ > + struct platform_device *pdev; > + int ret, count; > + struct resource res[DEV_MAX_RESOURCE_COUNT]; > + > + pdev = platform_device_alloc(DEV_NAME, PLATFORM_DEVID_AUTO); > + if (!pdev) > + return -ENOMEM; > + > + memset(res, 0, sizeof(res)); > + > + count = apmt_init_resources(res, node); > + > + ret = platform_device_add_resources(pdev, res, count); > + if (ret) > + goto dev_put; > + > + /* > + * Add a copy of APMT node pointer to platform_data to be used to > + * retrieve APMT data information. > + */ > + ret = platform_device_add_data(pdev, &node, sizeof(node)); > + if (ret) > + goto dev_put; > + > + pdev->dev.fwnode = fwnode; > + > + ret = platform_device_add(pdev); > + > + if (ret) > + goto dev_put; > + > + return 0; > + > +dev_put: > + platform_device_put(pdev); > + > + return ret; > +} > + > +static int __init apmt_init_platform_devices(void) > +{ > + struct acpi_apmt_node *apmt_node; > + struct acpi_table_apmt *apmt; > + struct fwnode_handle *fwnode; > + u64 offset, end; > + int ret; > + > + /* > + * apmt_table and apmt both point to the start of APMT table, but > + * have different struct types > + */ > + apmt = (struct acpi_table_apmt *)apmt_table; > + offset = sizeof(*apmt); > + end = apmt->header.length; > + > + while (offset < end) { > + apmt_node = ACPI_ADD_PTR(struct acpi_apmt_node, apmt, > + offset); > + > + fwnode = acpi_alloc_fwnode_static(); > + if (!fwnode) > + return -ENOMEM; > + > + ret = apmt_add_platform_device(apmt_node, fwnode); > + if (ret) { > + acpi_free_fwnode_static(fwnode); > + return ret; > + } > + > + offset += apmt_node->length; > + } > + > + return 0; > +} > + > +void __init acpi_apmt_init(void) > +{ > + acpi_status status; > + int ret; > + > + /** > + * APMT table nodes will be used at runtime after the apmt init, > + * so we don't need to call acpi_put_table() to release > + * the APMT table mapping. > + */ > + status = acpi_get_table(ACPI_SIG_APMT, 0, &apmt_table); > + > + if (ACPI_FAILURE(status)) { > + if (status != AE_NOT_FOUND) { > + const char *msg = acpi_format_exception(status); > + > + pr_err("Failed to get APMT table, %s\n", msg); > + } > + > + return; > + } > + > + ret = apmt_init_platform_devices(); > + if (ret) { > + pr_err("Failed to initialize APMT platform devices, ret: %d\n", ret); > + acpi_put_table(apmt_table); > + } > +} > diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c > index 86fa61a21826..f9dc5b3d5c55 100644 > --- a/drivers/acpi/bus.c > +++ b/drivers/acpi/bus.c > @@ -27,6 +27,7 @@ > #include > #endif > #include > +#include > #include > #include > #include > @@ -1411,6 +1412,7 @@ static int __init acpi_init(void) > acpi_setup_sb_notify_handler(); > acpi_viot_init(); > acpi_agdi_init(); > + acpi_apmt_init(); > return 0; > } > > diff --git a/include/linux/acpi_apmt.h b/include/linux/acpi_apmt.h > new file mode 100644 > index 000000000000..40bd634d082f > --- /dev/null > +++ b/include/linux/acpi_apmt.h > @@ -0,0 +1,19 @@ > +/* SPDX-License-Identifier: GPL-2.0 > + * > + * ARM CoreSight PMU driver. > + * Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. > + * > + */ > + > +#ifndef __ACPI_APMT_H__ > +#define __ACPI_APMT_H__ > + > +#include > + > +#ifdef CONFIG_ACPI_APMT > +void acpi_apmt_init(void); > +#else > +static inline void acpi_apmt_init(void) { } > +#endif /* CONFIG_ACPI_APMT */ > + > +#endif /* __ACPI_APMT_H__ */ > > base-commit: 09ce5091ff971cdbfd67ad84dc561ea27f10d67a > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel