From 8dda6e08a0e2999562d613e6dbe3b0c90b4a11a0 Mon Sep 17 00:00:00 2001 From: Aparna Das Date: Fri, 4 Aug 2017 17:36:25 -0700 Subject: video: tegra: host: read reg resources by name Implement capability to get host1x reg resources from device tree by name instead of index since index for a resource can vary between native and virtualized configurations. Jira EVLR-1571 Change-Id: I0e287e5f41af307f3503220243e6cfcd60d29d5e Signed-off-by: Aparna Das Reviewed-on: https://git-master.nvidia.com/r/1533437 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/video/tegra/host/host1x/host1x.c | 39 +++++++++++++++++++++++++++++++- drivers/video/tegra/host/host1x/host1x.h | 4 ++++ include/linux/nvhost.h | 3 +-- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/drivers/video/tegra/host/host1x/host1x.c b/drivers/video/tegra/host/host1x/host1x.c index 4a3320aa0..6373c59db 100644 --- a/drivers/video/tegra/host/host1x/host1x.c +++ b/drivers/video/tegra/host/host1x/host1x.c @@ -954,6 +954,40 @@ struct nvhost_syncpt *nvhost_get_syncpt_owner_struct(u32 id, return &host->syncpt; } +static int nvhost_device_get_host1x_resources_byname(struct nvhost_master *host) +{ + int i; + void __iomem *regs = NULL; + struct platform_device *dev = host->dev; + struct nvhost_device_data *pdata = platform_get_drvdata(dev); + int ret; + + for (i = 0; i < host->info.nb_resources; ++i) { + struct resource *r = NULL; + + r = platform_get_resource_byname(dev, IORESOURCE_MEM, + host->info.resources[i]); + /* Get next resource without failing if current resource is not + * present. Resources vary with configurations. + */ + if (!r) + continue; + + regs = devm_ioremap_resource(&dev->dev, r); + if (IS_ERR(regs)) { + ret = PTR_ERR(regs); + goto fail; + } + + pdata->aperture[i] = regs; + } + + return 0; +fail: + dev_err(&dev->dev, "failed to get register memory\n"); + return -ENXIO; +} + static int nvhost_probe(struct platform_device *dev) { struct nvhost_master *host; @@ -1047,7 +1081,10 @@ static int nvhost_probe(struct platform_device *dev) } if (!pdata->virtual_dev) { - err = nvhost_device_get_resources(dev); + if (host->info.nb_resources) + err = nvhost_device_get_host1x_resources_byname(host); + else + err = nvhost_device_get_resources(dev); if (err) { dev_err(&dev->dev, "failed to get resources\n"); goto fail; diff --git a/drivers/video/tegra/host/host1x/host1x.h b/drivers/video/tegra/host/host1x/host1x.h index 1989c416b..a0e8eacda 100644 --- a/drivers/video/tegra/host/host1x/host1x.h +++ b/drivers/video/tegra/host/host1x/host1x.h @@ -82,6 +82,10 @@ struct host1x_device_info { bool vmserver_owns_engines; /* true if hw supports remote syncpoint interrupts */ bool use_cross_vm_interrupts; + /* host1x: reg resources */ + char *resources[NVHOST_MODULE_MAX_IORESOURCE_MEM]; + /* host1x: number of resources */ + int nb_resources; }; struct nvhost_vm_firmware_area { diff --git a/include/linux/nvhost.h b/include/linux/nvhost.h index a8185c7d8..20793c850 100644 --- a/include/linux/nvhost.h +++ b/include/linux/nvhost.h @@ -56,8 +56,7 @@ struct sync_pt; #define NVHOST_MODULE_MAX_SYNCPTS 16 #define NVHOST_MODULE_MAX_WAITBASES 3 #define NVHOST_MODULE_MAX_MODMUTEXES 5 -#define NVHOST_MODULE_MAX_IORESOURCE_MEM 3 -#define NVHOST_MODULE_MAX_IORESOURCE_MEM 3 +#define NVHOST_MODULE_MAX_IORESOURCE_MEM 4 #define NVHOST_NAME_SIZE 24 #define NVSYNCPT_INVALID (-1) #define NVHOST_MODULE_MAX_FREQS 8 -- cgit v1.2.2