video: tegra: host: Turn host1x on when reading counters
Terje Bergstrom [Wed, 19 Dec 2012 07:31:14 +0000 (09:31 +0200)]
Turn host1x on when initializing and accessing the tick counter
registers.

Change-Id: I1ee41746ce7e1c603772b8fc643e58d19908f889
Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-on: http://git-master/r/172724
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Arto Merilainen <amerilainen@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Juha Tukkinen <jtukkinen@nvidia.com>

drivers/video/tegra/host/chip_support.h
drivers/video/tegra/host/debug.c
drivers/video/tegra/host/host1x/host1x.c
drivers/video/tegra/host/host1x/host1x_tickctrl.c

index e913c2e..c583e4f 100644 (file)
@@ -179,8 +179,6 @@ struct nvhost_actmon_ops {
 };
 
 struct nvhost_tickctrl_ops {
-       int (*init_host)(struct nvhost_master *host);
-       void (*deinit_host)(struct nvhost_master *host);
        int (*init_channel)(struct platform_device *dev);
        void (*deinit_channel)(struct platform_device *dev);
        int (*tickcount)(struct platform_device *dev, u64 *val);
index efe3f94..d535058 100644 (file)
@@ -488,6 +488,7 @@ void nvhost_device_debug_init(struct platform_device *dev)
        de = debugfs_create_dir(dev->name, de);
        debugfs_create_file("stallcount", S_IRUGO, de, dev, &stallcount_fops);
        debugfs_create_file("xfercount", S_IRUGO, de, dev, &xfercount_fops);
+       debugfs_create_file("tickcount", S_IRUGO, de, dev, &tickcount_fops);
 
        pdata->debugfs = de;
 }
@@ -539,8 +540,6 @@ void nvhost_debug_init(struct nvhost_master *master)
                        master, &actmon_above_wmark_fops);
        debugfs_create_file("3d_actmon_below_wmark", S_IRUGO, de,
                        master, &actmon_below_wmark_fops);
-       debugfs_create_file("tickcount", S_IRUGO, de,
-                       master->dev, &tickcount_fops);
 }
 #else
 void nvhost_debug_init(struct nvhost_master *master)
index 91886ea..6db03e7 100644 (file)
@@ -297,16 +297,12 @@ static void power_on_host(struct platform_device *dev)
        struct nvhost_master *host = nvhost_get_private_data(dev);
 
        nvhost_syncpt_reset(&host->syncpt);
-       if (tickctrl_op().init_host)
-               tickctrl_op().init_host(host);
 }
 
 static int power_off_host(struct platform_device *dev)
 {
        struct nvhost_master *host = nvhost_get_private_data(dev);
 
-       if (tickctrl_op().deinit_host)
-               tickctrl_op().deinit_host(host);
        nvhost_syncpt_save(&host->syncpt);
        return 0;
 }
@@ -498,9 +494,6 @@ static int __devinit nvhost_probe(struct platform_device *dev)
 
        nvhost_debug_init(host);
 
-       if (tickctrl_op().init_host)
-               tickctrl_op().init_host(host);
-
        dev_info(&dev->dev, "initialized\n");
        return 0;
 
index 9a08bc3..963ae32 100644 (file)
 #include "dev.h"
 #include "chip_support.h"
 
-static int host1x_tickctrl_init_host(struct nvhost_master *host)
-{
-       void __iomem *regs = host->aperture;
-
-       /* Initialize counter */
-       writel(0, regs + host1x_channel_tickcount_hi_r());
-       writel(0, regs + host1x_channel_tickcount_lo_r());
-
-       writel(host1x_channel_channelctrl_enabletickcnt_f(1),
-                       regs + host1x_channel_channelctrl_r());
-
-       return 0;
-}
-
-static void host1x_tickctrl_deinit_host(struct nvhost_master *host)
-{
-       void __iomem *regs = host->aperture;
-
-       writel(host1x_channel_channelctrl_enabletickcnt_f(0),
-                       regs + host1x_channel_channelctrl_r());
-}
-
 static int host1x_tickctrl_init_channel(struct platform_device *dev)
 {
        struct nvhost_device_data *pdata = platform_get_drvdata(dev);
        void __iomem *regs = pdata->channel->aperture;
 
+       nvhost_module_busy(nvhost_get_parent(dev));
+
        /* Initialize counter */
+       writel(0, regs + host1x_channel_tickcount_hi_r());
+       writel(0, regs + host1x_channel_tickcount_lo_r());
        writel(0, regs + host1x_channel_stallcount_hi_r());
        writel(0, regs + host1x_channel_stallcount_lo_r());
        writel(0, regs + host1x_channel_xfercount_hi_r());
        writel(0, regs + host1x_channel_xfercount_lo_r());
 
+       writel(host1x_channel_channelctrl_enabletickcnt_f(1),
+                       regs + host1x_channel_channelctrl_r());
        writel(host1x_channel_stallctrl_enable_channel_stall_f(1),
                        regs + host1x_channel_stallctrl_r());
        writel(host1x_channel_xferctrl_enable_channel_xfer_f(1),
                        regs + host1x_channel_xferctrl_r());
 
+       nvhost_module_idle(nvhost_get_parent(dev));
+
        return 0;
 }
 
@@ -69,10 +55,14 @@ static void host1x_tickctrl_deinit_channel(struct platform_device *dev)
        struct nvhost_device_data *pdata = platform_get_drvdata(dev);
        void __iomem *regs = pdata->channel->aperture;
 
+       nvhost_module_busy(nvhost_get_parent(dev));
        writel(host1x_channel_stallctrl_enable_channel_stall_f(0),
                        regs + host1x_channel_stallctrl_r());
        writel(host1x_channel_xferctrl_enable_channel_xfer_f(0),
                        regs + host1x_channel_xferctrl_r());
+       writel(host1x_channel_channelctrl_enabletickcnt_f(0),
+                       regs + host1x_channel_channelctrl_r());
+       nvhost_module_idle(nvhost_get_parent(dev));
 }
 
 static u64 readl64(void __iomem *reg_hi, void __iomem *reg_lo)
@@ -81,6 +71,7 @@ static u64 readl64(void __iomem *reg_hi, void __iomem *reg_lo)
        do {
                hi = readl(reg_hi);
                lo = readl(reg_lo);
+               rmb();
                hi2 = readl(reg_hi);
        } while (hi2 != hi);
        return ((u64)hi << 32) | (u64)lo;
@@ -88,11 +79,16 @@ static u64 readl64(void __iomem *reg_hi, void __iomem *reg_lo)
 
 static int host1x_tickctrl_tickcount(struct platform_device *dev, u64 *val)
 {
-       void __iomem *regs = nvhost_get_host(dev)->aperture;
+       struct nvhost_device_data *pdata = platform_get_drvdata(dev);
+       void __iomem *regs = pdata->channel->aperture;
+
+       nvhost_module_busy(nvhost_get_parent(dev));
 
        *val = readl64(regs + host1x_channel_tickcount_hi_r(),
                regs + host1x_channel_tickcount_lo_r());
+
        rmb();
+       nvhost_module_idle(nvhost_get_parent(dev));
 
        return 0;
 }
@@ -102,9 +98,11 @@ static int host1x_tickctrl_stallcount(struct platform_device *dev, u64 *val)
        struct nvhost_device_data *pdata = platform_get_drvdata(dev);
        void __iomem *regs = pdata->channel->aperture;
 
+       nvhost_module_busy(nvhost_get_parent(dev));
        *val = readl64(regs + host1x_channel_stallcount_hi_r(),
                regs + host1x_channel_stallcount_lo_r());
        rmb();
+       nvhost_module_idle(nvhost_get_parent(dev));
 
        return 0;
 }
@@ -114,16 +112,16 @@ static int host1x_tickctrl_xfercount(struct platform_device *dev, u64 *val)
        struct nvhost_device_data *pdata = platform_get_drvdata(dev);
        void __iomem *regs = pdata->channel->aperture;
 
+       nvhost_module_busy(nvhost_get_parent(dev));
        *val = readl64(regs + host1x_channel_xfercount_hi_r(),
                regs + host1x_channel_xfercount_lo_r());
        rmb();
+       nvhost_module_idle(nvhost_get_parent(dev));
 
        return 0;
 }
 
 static const struct nvhost_tickctrl_ops host1x_tickctrl_ops = {
-       .init_host = host1x_tickctrl_init_host,
-       .deinit_host = host1x_tickctrl_deinit_host,
        .init_channel = host1x_tickctrl_init_channel,
        .deinit_channel = host1x_tickctrl_deinit_channel,
        .tickcount = host1x_tickctrl_tickcount,