video: tegra: host: Iterate devices without nb_channels
Terje Bergstrom [Thu, 26 Apr 2012 09:49:28 +0000 (12:49 +0300)]
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 <tbergstrom@nvidia.com>
Reviewed-on: http://git-master/r/99067
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Juha Tukkinen <jtukkinen@nvidia.com>

drivers/video/tegra/host/bus_client.c
drivers/video/tegra/host/dev.c
drivers/video/tegra/host/dev.h
drivers/video/tegra/host/t20/t20.c
drivers/video/tegra/host/t30/t30.c

index 3b362b0..e70506d 100644 (file)
@@ -541,18 +541,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);
index 56eafa7..d1cbafe 100644 (file)
@@ -52,9 +52,6 @@
 
 #define DRIVER_NAME            "host1x"
 
-int nvhost_major;
-int nvhost_minor;
-
 static unsigned int register_sets;
 
 struct nvhost_ctrl_userctx {
@@ -171,24 +168,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,
@@ -333,9 +327,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;
@@ -343,7 +335,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;
index 70199d8..b357ef9 100644 (file)
@@ -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;
 
index 19967cb..3f90e6a 100644 (file)
@@ -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];
        }
index 68c9789..2a98cdc 100644 (file)
@@ -222,7 +222,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];
        }