video: tegra: host: Use chip_ops for save context
Terje Bergstrom [Fri, 15 Jun 2012 04:43:07 +0000 (07:43 +0300)]
Call drain fifo and save context functions via nvhost_chip_support.
Earlier client drivers called into host1x code directly, which
makes each client driver SoC specific.

Change-Id: I4f805abad21012e59e11bf6a98fa46441c71c51a
Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-on: http://git-master/r/109101
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Mayuresh Kulkarni <mkulkarni@nvidia.com>
Reviewed-by: Juha Tukkinen <jtukkinen@nvidia.com>
Reviewed-by: Ken Adams <kadams@nvidia.com>

drivers/video/tegra/host/chip_support.h
drivers/video/tegra/host/gr3d/gr3d.c
drivers/video/tegra/host/gr3d/gr3d_t20.c
drivers/video/tegra/host/host1x/host1x_channel.c
drivers/video/tegra/host/host1x/host1x_channel.h
drivers/video/tegra/host/mpe/mpe.c
drivers/video/tegra/host/nvhost_channel.c
drivers/video/tegra/host/nvhost_channel.h
drivers/video/tegra/host/t20/t20.c

index c6860e6..5bc0c9f 100644 (file)
@@ -52,6 +52,10 @@ struct nvhost_chip_support {
                                struct nvhost_hwctx *hwctx,
                                u32 offset,
                                u32 *value);
+               int (*save_context)(struct nvhost_channel *channel);
+               int (*drain_read_fifo)(struct nvhost_channel *ch,
+                               u32 *ptr, unsigned int count,
+                               unsigned int *pending);
        } channel;
 
        struct {
index 5338ce9..3cc041d 100644 (file)
@@ -147,13 +147,7 @@ void nvhost_3dctx_put(struct nvhost_hwctx *ctx)
 
 int nvhost_gr3d_prepare_power_off(struct nvhost_device *dev)
 {
-       struct nvhost_hwctx *cur_ctx = dev->channel->cur_ctx;
-       int err = 0;
-       if (cur_ctx)
-               err = host1x_save_context(dev,
-                       to_host1x_hwctx_handler(cur_ctx->h)->syncpt);
-
-       return err;
+       return nvhost_channel_save_context(dev->channel);
 }
 
 enum gr3d_ip_ver {
index 88bb2be..23cd155 100644 (file)
@@ -200,7 +200,7 @@ static void __init save_end_v0(struct host1x_hwctx_handler *h, u32 *ptr)
 }
 
 static u32 *save_regs_v0(u32 *ptr, unsigned int *pending,
-                       void __iomem *chan_regs,
+                       struct nvhost_channel *ch,
                        const struct hwctx_reginfo *regs,
                        unsigned int nr_regs)
 {
@@ -218,7 +218,7 @@ static u32 *save_regs_v0(u32 *ptr, unsigned int *pending,
                        ptr += RESTORE_INDIRECT_SIZE;
                        break;
                }
-               drain_result = host1x_drain_read_fifo(chan_regs,
+               drain_result = nvhost_channel_drain_read_fifo(ch,
                        ptr, count, pending);
                BUG_ON(drain_result < 0);
                ptr += count;
@@ -344,7 +344,7 @@ static void ctx3d_save_service(struct nvhost_hwctx *nctx)
        u32 *ptr = (u32 *)ctx->restore_virt + RESTORE_BEGIN_SIZE;
        unsigned int pending = 0;
 
-       ptr = save_regs_v0(ptr, &pending, nctx->channel->aperture,
+       ptr = save_regs_v0(ptr, &pending, nctx->channel,
                        ctxsave_regs_3d_global,
                        ARRAY_SIZE(ctxsave_regs_3d_global));
 
index 03ba72c..09f022b 100644 (file)
@@ -461,8 +461,7 @@ int host1x_channel_read_3d_reg(
        nvhost_intr_put_ref(&nvhost_get_host(channel->dev)->intr, ref);
 
        /* Read the register value from FIFO */
-       err = host1x_drain_read_fifo(channel->aperture,
-               value, 1, &pending);
+       err = host1x_drain_read_fifo(channel, value, 1, &pending);
 
        /* Indicate we've read the value */
        nvhost_syncpt_cpu_incr(&nvhost_get_host(channel->dev)->syncpt,
@@ -486,11 +485,12 @@ done:
 }
 
 
-int host1x_drain_read_fifo(void __iomem *chan_regs,
+int host1x_drain_read_fifo(struct nvhost_channel *ch,
        u32 *ptr, unsigned int count, unsigned int *pending)
 {
        unsigned int entries = *pending;
        unsigned long timeout = jiffies + NV_FIFO_READ_TIMEOUT;
+       void __iomem *chan_regs = ch->aperture;
        while (count) {
                unsigned int num;
 
@@ -528,9 +528,9 @@ int host1x_drain_read_fifo(void __iomem *chan_regs,
        return 0;
 }
 
-int host1x_save_context(struct nvhost_device *dev, u32 syncpt_id)
+int host1x_save_context(struct nvhost_channel *ch)
 {
-       struct nvhost_channel *ch = dev->channel;
+       struct nvhost_device *dev = ch->dev;
        struct nvhost_hwctx *hwctx_to_save;
        DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
        u32 syncpt_incrs, syncpt_val;
@@ -539,6 +539,7 @@ int host1x_save_context(struct nvhost_device *dev, u32 syncpt_id)
        void *ctx_waiter = NULL, *wakeup_waiter = NULL;
        struct nvhost_job *job;
        struct nvhost_driver *drv = to_nvhost_driver(dev->dev.driver);
+       u32 syncpt_id;
 
        ctx_waiter = nvhost_intr_alloc_waiter();
        wakeup_waiter = nvhost_intr_alloc_waiter();
@@ -569,6 +570,7 @@ int host1x_save_context(struct nvhost_device *dev, u32 syncpt_id)
        hwctx_to_save->valid = true;
        ch->ctxhandler->get(hwctx_to_save);
        ch->cur_ctx = NULL;
+       syncpt_id = to_host1x_hwctx_handler(hwctx_to_save->h)->syncpt;
 
        syncpt_incrs = to_host1x_hwctx(hwctx_to_save)->save_incrs;
        syncpt_val = nvhost_syncpt_incr_max(&nvhost_get_host(ch->dev)->syncpt,
index 4113dbc..98a67c7 100644 (file)
@@ -37,9 +37,9 @@ int host1x_channel_read_3d_reg(
        u32 *value);
 
 /* Reads words from FIFO */
-int host1x_drain_read_fifo(void __iomem *chan_regs,
+int host1x_drain_read_fifo(struct nvhost_channel *ch,
                u32 *ptr, unsigned int count, unsigned int *pending);
 
-int host1x_save_context(struct nvhost_device *dev, u32 syncpt_id);
+int host1x_save_context(struct nvhost_channel *ch);
 
 #endif
index 9f90553..7b76393 100644 (file)
@@ -396,7 +396,7 @@ static u32 *save_regs(u32 *ptr, unsigned int *pending,
                u32 count = regs->count;
                ++ptr; /* restore incr */
                if (regs->type == HWCTX_REGINFO_NORMAL) {
-                       host1x_drain_read_fifo(channel->aperture,
+                       nvhost_channel_drain_read_fifo(channel,
                                                ptr, count, pending);
                        ptr += count;
                } else {
@@ -405,8 +405,8 @@ static u32 *save_regs(u32 *ptr, unsigned int *pending,
                                BUG_ON(msi->out_pos >= NR_WRITEBACKS);
                                word = msi->out[msi->out_pos++];
                        } else {
-                               host1x_drain_read_fifo(channel->aperture,
-                                                       &word, 1, pending);
+                               nvhost_channel_drain_read_fifo(channel,
+                                               &word, 1, pending);
                                if (regs->type == HWCTX_REGINFO_STASH) {
                                        BUG_ON(msi->in_pos >= NR_STASHES);
                                        msi->in[msi->in_pos++] = word;
@@ -426,7 +426,7 @@ static u32 *save_ram(u32 *ptr, unsigned int *pending,
 {
        int err = 0;
        ptr += RESTORE_RAM_SIZE;
-       err = host1x_drain_read_fifo(channel->aperture, ptr, words, pending);
+       err = nvhost_channel_drain_read_fifo(channel, ptr, words, pending);
        WARN_ON(err);
        return ptr + words;
 }
@@ -583,13 +583,7 @@ struct nvhost_hwctx_handler *nvhost_mpe_ctxhandler_init(u32 syncpt,
 
 int nvhost_mpe_prepare_power_off(struct nvhost_device *dev)
 {
-       struct nvhost_hwctx *cur_ctx = dev->channel->cur_ctx;
-       int err = 0;
-       if (cur_ctx)
-               err = host1x_save_context(dev,
-                       to_host1x_hwctx_handler(cur_ctx->h)->syncpt);
-
-       return err;
+       return nvhost_channel_save_context(dev->channel);
 }
 
 enum mpe_ip_ver {
index ad303cf..fd309ee 100644 (file)
@@ -169,3 +169,20 @@ void nvhost_free_channel_internal(struct nvhost_channel *ch,
        kfree(ch);
        (*current_channel_count)--;
 }
+
+int nvhost_channel_save_context(struct nvhost_channel *ch)
+{
+       struct nvhost_hwctx *cur_ctx = ch->cur_ctx;
+       int err = 0;
+       if (cur_ctx)
+               err = channel_op().save_context(ch);
+
+       return err;
+
+}
+
+int nvhost_channel_drain_read_fifo(struct nvhost_channel *ch,
+                       u32 *ptr, unsigned int count, unsigned int *pending)
+{
+       return channel_op().drain_read_fifo(ch, ptr, count, pending);
+}
index b3a904d..d7f096d 100644 (file)
@@ -59,7 +59,7 @@ struct nvhost_channel *nvhost_getchannel(struct nvhost_channel *ch);
 void nvhost_putchannel(struct nvhost_channel *ch, struct nvhost_hwctx *ctx);
 int nvhost_channel_suspend(struct nvhost_channel *ch);
 
-int nvhost_channel_drain_read_fifo(void __iomem *chan_regs,
+int nvhost_channel_drain_read_fifo(struct nvhost_channel *ch,
                        u32 *ptr, unsigned int count, unsigned int *pending);
 
 int nvhost_channel_read_3d_reg(struct nvhost_channel *channel,
@@ -72,4 +72,6 @@ struct nvhost_channel *nvhost_alloc_channel_internal(int chindex,
 void nvhost_free_channel_internal(struct nvhost_channel *ch,
        int *current_channel_count);
 
+int nvhost_channel_save_context(struct nvhost_channel *ch);
+
 #endif
index 93e73e5..1f8f143 100644 (file)
@@ -294,6 +294,8 @@ int nvhost_init_t20_channel_support(struct nvhost_master *host,
        op->channel.init = t20_channel_init;
        op->channel.submit = host1x_channel_submit;
        op->channel.read3dreg = host1x_channel_read_3d_reg;
+       op->channel.save_context = host1x_save_context;
+       op->channel.drain_read_fifo = host1x_drain_read_fifo;
 
        return 0;
 }