From 41a9f72f78cf51d679be71b54bfafc9abe49695e Mon Sep 17 00:00:00 2001 From: Mikko Perttunen Date: Tue, 28 Feb 2023 11:12:18 +0200 Subject: [PATCH] gpu: host1x: Add API for reading actmon count Add API for reading the activity monitor average count for VIC, NVENC, and NVDEC. There is currently no support for initializing actmon, so this relies on someone else on a virtualized system having initialized it (and mapped the actmon region read-only). Bug 3973633 Signed-off-by: Mikko Perttunen Change-Id: Ia1bfec6a090d4effb288b17cbac4d42bf5d0b4e5 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2864719 Reviewed-by: svc_kernel_abi Reviewed-by: Jonathan Hunter GVS: Gerrit_Virtual_Submit --- drivers/gpu/host1x/Makefile | 1 + drivers/gpu/host1x/actmon.c | 36 +++++++++++++++++++ drivers/gpu/host1x/dev.c | 10 ++++-- drivers/gpu/host1x/dev.h | 1 + .../gpu/host1x/include/linux/host1x-next.h | 2 ++ 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/host1x/actmon.c diff --git a/drivers/gpu/host1x/Makefile b/drivers/gpu/host1x/Makefile index b5e7e933..affedf2c 100644 --- a/drivers/gpu/host1x/Makefile +++ b/drivers/gpu/host1x/Makefile @@ -15,6 +15,7 @@ host1x-next-y = \ debug.o \ mipi.o \ fence.o \ + actmon.o \ hw/host1x01.o \ hw/host1x02.o \ hw/host1x04.o \ diff --git a/drivers/gpu/host1x/actmon.c b/drivers/gpu/host1x/actmon.c new file mode 100644 index 00000000..33bac0db --- /dev/null +++ b/drivers/gpu/host1x/actmon.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Tegra host1x activity monitor interfaes + * + * Copyright (c) 2023, NVIDIA Corporation. + */ + +#include "dev.h" + +int host1x_actmon_read_avg_count(struct host1x_client *client) +{ + struct host1x *host = dev_get_drvdata(client->host->parent); + unsigned int offset; + + if (!host->actmon_regs) + return -ENODEV; + + /* FIXME: Only T234 supported */ + + switch (client->class) { + case HOST1X_CLASS_NVENC: + offset = 0x0; + break; + case HOST1X_CLASS_VIC: + offset = 0x10000; + break; + case HOST1X_CLASS_NVDEC: + offset = 0x20000; + break; + default: + return -EINVAL; + } + + return readl(host->actmon_regs + offset + 0xa4); +} +EXPORT_SYMBOL(host1x_actmon_read_avg_count); diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c index 2ea38483..9746969c 100644 --- a/drivers/gpu/host1x/dev.c +++ b/drivers/gpu/host1x/dev.c @@ -748,6 +748,7 @@ static int host1x_get_syncpt_pools(struct host1x *host) static int host1x_probe(struct platform_device *pdev) { + struct resource *res; struct host1x *host; int err; @@ -758,8 +759,6 @@ static int host1x_probe(struct platform_device *pdev) host->info = of_device_get_match_data(&pdev->dev); if (host->info->has_hypervisor) { - struct resource *res; - host->regs = devm_platform_ioremap_resource_byname(pdev, "vm"); if (IS_ERR(host->regs)) return PTR_ERR(host->regs); @@ -782,6 +781,13 @@ static int host1x_probe(struct platform_device *pdev) return PTR_ERR(host->regs); } + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "actmon"); + if (res) { + host->actmon_regs = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(host->actmon_regs)) + return PTR_ERR(host->actmon_regs); + } + host->syncpt_irq = platform_get_irq(pdev, 0); if (host->syncpt_irq < 0) return host->syncpt_irq; diff --git a/drivers/gpu/host1x/dev.h b/drivers/gpu/host1x/dev.h index 25e3f770..7a3ebf70 100644 --- a/drivers/gpu/host1x/dev.h +++ b/drivers/gpu/host1x/dev.h @@ -130,6 +130,7 @@ struct host1x { void __iomem *regs; void __iomem *hv_regs; /* hypervisor region */ void __iomem *common_regs; + void __iomem *actmon_regs; int syncpt_irq; struct host1x_syncpt *syncpt; struct host1x_syncpt_base *bases; diff --git a/drivers/gpu/host1x/include/linux/host1x-next.h b/drivers/gpu/host1x/include/linux/host1x-next.h index 3e67ed56..0c0134f0 100644 --- a/drivers/gpu/host1x/include/linux/host1x-next.h +++ b/drivers/gpu/host1x/include/linux/host1x-next.h @@ -506,4 +506,6 @@ static inline void host1x_memory_context_put(struct host1x_memory_context *cd) } #endif +int host1x_actmon_read_avg_count(struct host1x_client *client); + #endif