From 03df341ccb7fdc227fc6011676435a8091fe368b Mon Sep 17 00:00:00 2001 From: Terje Bergstrom Date: Thu, 26 Apr 2012 12:49:28 +0300 Subject: video: tegra: host: Iterate devices without nb_channels Do not use nb_channels to find out the number of client devices. Instead, allocate devno regions when they are needed and find a device by module id by iterating over nvhost bus. Bug 871237 Change-Id: I53fd0d8e5874422ef9877430c0a170db2660118a Signed-off-by: Terje Bergstrom Reviewed-on: http://git-master/r/99067 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Juha Tukkinen --- drivers/video/tegra/host/bus_client.c | 9 +++++++-- drivers/video/tegra/host/dev.c | 33 ++++++++++++--------------------- drivers/video/tegra/host/dev.h | 3 --- drivers/video/tegra/host/t20/t20.c | 2 +- drivers/video/tegra/host/t30/t30.c | 2 +- 5 files changed, 21 insertions(+), 28 deletions(-) (limited to 'drivers/video/tegra/host') diff --git a/drivers/video/tegra/host/bus_client.c b/drivers/video/tegra/host/bus_client.c index a3dc3781f81c..272e0c9f2efb 100644 --- a/drivers/video/tegra/host/bus_client.c +++ b/drivers/video/tegra/host/bus_client.c @@ -540,18 +540,23 @@ int nvhost_client_user_init(struct nvhost_device *dev) int err, devno; struct nvhost_channel *ch = dev->channel; + err = alloc_chrdev_region(&devno, 0, 1, IFACE_NAME); + if (err < 0) { + dev_err(&dev->dev, "failed to allocate devno\n"); + goto fail; + } cdev_init(&ch->cdev, &nvhost_channelops); ch->cdev.owner = THIS_MODULE; - devno = MKDEV(nvhost_major, nvhost_minor + dev->index); err = cdev_add(&ch->cdev, devno, 1); if (err < 0) { dev_err(&dev->dev, "failed to add chan %i cdev\n", dev->index); goto fail; } - ch->node = device_create(nvhost_get_host(dev)->nvhost_class, NULL, devno, NULL, + ch->node = device_create(nvhost_get_host(dev)->nvhost_class, + NULL, devno, NULL, IFACE_NAME "-%s", dev->name); if (IS_ERR(ch->node)) { err = PTR_ERR(ch->node); diff --git a/drivers/video/tegra/host/dev.c b/drivers/video/tegra/host/dev.c index d21719bcda56..7917e4e20b44 100644 --- a/drivers/video/tegra/host/dev.c +++ b/drivers/video/tegra/host/dev.c @@ -51,9 +51,6 @@ #define DRIVER_NAME "host1x" -int nvhost_major; -int nvhost_minor; - static unsigned int register_sets; struct nvhost_ctrl_userctx { @@ -170,24 +167,21 @@ static int nvhost_ioctl_ctrl_module_mutex(struct nvhost_ctrl_userctx *ctx, return err; } -static struct nvhost_device *get_ndev_by_moduleid(struct nvhost_master *host, - u32 id) +static int match_by_moduleid(struct device *dev, void *data) { - int i; + struct nvhost_device *ndev = to_nvhost_device(dev); + u32 id = (u32)data; - for (i = 0; i < host->nb_channels; i++) { - struct nvhost_device *ndev = host->channels[i].dev; + return id == ndev->moduleid; +} - /* display and dsi do not use channel for register programming. - * so their channels do not have device instance. - * hence skip such channels from here. */ - if (ndev == NULL) - continue; +static struct nvhost_device *get_ndev_by_moduleid(struct nvhost_master *host, + u32 id) +{ + struct device *dev = bus_find_device(&nvhost_bus_type, NULL, (void *)id, + match_by_moduleid); - if (id == ndev->moduleid) - return ndev; - } - return NULL; + return dev ? to_nvhost_device(dev) : NULL; } static int nvhost_ioctl_ctrl_module_regrdwr(struct nvhost_ctrl_userctx *ctx, @@ -332,9 +326,7 @@ static int __devinit nvhost_user_init(struct nvhost_master *host) goto fail; } - err = alloc_chrdev_region(&devno, nvhost_minor, - host->nb_channels + 1, IFACE_NAME); - nvhost_major = MAJOR(devno); + err = alloc_chrdev_region(&devno, 0, 1, IFACE_NAME); if (err < 0) { dev_err(&host->dev->dev, "failed to reserve chrdev region\n"); goto fail; @@ -342,7 +334,6 @@ static int __devinit nvhost_user_init(struct nvhost_master *host) cdev_init(&host->cdev, &nvhost_ctrlops); host->cdev.owner = THIS_MODULE; - devno = MKDEV(nvhost_major, nvhost_minor + host->nb_channels); err = cdev_add(&host->cdev, devno, 1); if (err < 0) goto fail; diff --git a/drivers/video/tegra/host/dev.h b/drivers/video/tegra/host/dev.h index 70199d8a5914..b357ef9f29c9 100644 --- a/drivers/video/tegra/host/dev.h +++ b/drivers/video/tegra/host/dev.h @@ -29,9 +29,6 @@ #define TRACE_MAX_LENGTH 128U #define IFACE_NAME "nvhost" -extern int nvhost_major; -extern int nvhost_minor; - struct nvhost_hwctx; struct nvhost_channel; diff --git a/drivers/video/tegra/host/t20/t20.c b/drivers/video/tegra/host/t20/t20.c index 19967cb8c7a4..3f90e6a837c9 100644 --- a/drivers/video/tegra/host/t20/t20.c +++ b/drivers/video/tegra/host/t20/t20.c @@ -202,7 +202,7 @@ struct nvhost_device *t20_get_nvhost_device(struct nvhost_master *host, { int i; - for (i = 0; i < host->nb_channels; i++) { + for (i = 0; i < ARRAY_SIZE(t20_devices); i++) { if (strcmp(t20_devices[i].name, name) == 0) return &t20_devices[i]; } diff --git a/drivers/video/tegra/host/t30/t30.c b/drivers/video/tegra/host/t30/t30.c index fce8081df332..01009a708d19 100644 --- a/drivers/video/tegra/host/t30/t30.c +++ b/drivers/video/tegra/host/t30/t30.c @@ -221,7 +221,7 @@ struct nvhost_device *t30_get_nvhost_device(struct nvhost_master *host, { int i; - for (i = 0; i < host->nb_channels; i++) { + for (i = 0; i < ARRAY_SIZE(t30_devices); i++) { if (strcmp(t30_devices[i].name, name) == 0) return &t30_devices[i]; } -- cgit v1.2.3