]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/commitdiff
video: tegra: host: add API for base syncpt id
authorDeepak Nibade <dnibade@nvidia.com>
Thu, 26 Feb 2015 06:55:27 +0000 (12:25 +0530)
committerArto Merilainen <amerilainen@nvidia.com>
Mon, 2 Mar 2015 10:44:38 +0000 (02:44 -0800)
Currently we assume that all the syncpoints are available
to us starting from index 0.
Make this more flexible by using nvhost_syncpt_pts_base()
API to get the base syncpt id
So we have nb_pts syncpoints available with range
[pts_base, pts_limit - 1]

Add below APIs to get base of syncpts :
nvhost_syncpt_base_pt()

Also add API nvhost_syncpt_is_valid_pt() to check if
syncpoint id provided is within the range or not.

Use above APIs at all places where we just assume the
syncpoint range from 0 to MAX

Bug 1611482

Change-Id: I7dede8d96927db130e92963b5fc7d4746f561ff0
Signed-off-by: Deepak Nibade <dnibade@nvidia.com>
Reviewed-on: http://git-master/r/711210
Reviewed-by: Arto Merilainen <amerilainen@nvidia.com>
Tested-by: Arto Merilainen <amerilainen@nvidia.com>
drivers/video/tegra/host/bus_client.c
drivers/video/tegra/host/debug.c
drivers/video/tegra/host/host1x/host1x.c
drivers/video/tegra/host/host1x/host1x_channel.c
drivers/video/tegra/host/nvhost_job.c
drivers/video/tegra/host/nvhost_sync.c
drivers/video/tegra/host/nvhost_syncpt.c
drivers/video/tegra/host/nvhost_syncpt.h
include/linux/nvhost.h

index aac3725ef4d9656e404667db608e90babfd92d97..6e863bbe7f76968a15360426474b6bbfb2d14df6 100644 (file)
@@ -438,7 +438,6 @@ static int nvhost_ioctl_channel_submit(struct nvhost_channel_userctx *ctx,
        u32 __user *class_ids = (u32 __user *)(uintptr_t)args->class_ids;
        struct nvhost_device_data *pdata = platform_get_drvdata(ctx->pdev);
 
-       struct nvhost_master *host = nvhost_get_host(ctx->pdev);
        const u32 *syncpt_array =
                (nvhost_get_syncpt_policy() == SYNCPT_PER_CHANNEL_INSTANCE) ?
                ctx->syncpts :
@@ -446,9 +445,6 @@ static int nvhost_ioctl_channel_submit(struct nvhost_channel_userctx *ctx,
        u32 *local_class_ids = NULL;
        int err, i;
 
-       if (num_syncpt_incrs > host->info.nb_pts)
-               return -EINVAL;
-
        job = nvhost_job_alloc(ctx->ch,
                        num_cmdbufs,
                        num_relocs,
index 7d0e86818d175f5c00b83ba0c64b1f20f4f43d9d..16a9c4a40b821cc64ae0a2d244ec2f5619ef5cd9 100644 (file)
@@ -112,9 +112,11 @@ static int show_channels_no_fifo(struct platform_device *pdev, void *data,
 static void show_syncpts(struct nvhost_master *m, struct output *o)
 {
        int i;
+
        nvhost_debug_output(o, "---- syncpts ----\n");
        mutex_lock(&m->syncpt.syncpt_mutex);
-       for (i = 0; i < nvhost_syncpt_nb_pts(&m->syncpt); i++) {
+       for (i = nvhost_syncpt_pts_base(&m->syncpt);
+                       i < nvhost_syncpt_pts_limit(&m->syncpt); i++) {
                u32 max = nvhost_syncpt_read_max(&m->syncpt, i);
                u32 min = nvhost_syncpt_update_min(&m->syncpt, i);
                if (!min && !max)
index 74bf9067991a0e5f1b1b96e6f211c20afe54f3c0..176fd6d56933ba6998190890b91efb43842888f5 100644 (file)
@@ -128,7 +128,7 @@ static int nvhost_ctrlopen(struct inode *inode, struct file *filp)
 static int nvhost_ioctl_ctrl_syncpt_read(struct nvhost_ctrl_userctx *ctx,
        struct nvhost_ctrl_syncpt_read_args *args)
 {
-       if (args->id >= nvhost_syncpt_nb_pts(&ctx->dev->syncpt))
+       if (!nvhost_syncpt_is_valid_pt(&ctx->dev->syncpt, args->id))
                return -EINVAL;
        args->value = nvhost_syncpt_read(&ctx->dev->syncpt, args->id);
        trace_nvhost_ioctl_ctrl_syncpt_read(args->id, args->value);
@@ -138,7 +138,7 @@ static int nvhost_ioctl_ctrl_syncpt_read(struct nvhost_ctrl_userctx *ctx,
 static int nvhost_ioctl_ctrl_syncpt_incr(struct nvhost_ctrl_userctx *ctx,
        struct nvhost_ctrl_syncpt_incr_args *args)
 {
-       if (args->id >= nvhost_syncpt_nb_pts(&ctx->dev->syncpt))
+       if (!nvhost_syncpt_is_valid_pt(&ctx->dev->syncpt, args->id))
                return -EINVAL;
        trace_nvhost_ioctl_ctrl_syncpt_incr(args->id);
        nvhost_syncpt_incr(&ctx->dev->syncpt, args->id);
@@ -150,7 +150,7 @@ static int nvhost_ioctl_ctrl_syncpt_waitex(struct nvhost_ctrl_userctx *ctx,
 {
        u32 timeout;
        int err;
-       if (args->id >= nvhost_syncpt_nb_pts(&ctx->dev->syncpt))
+       if (!nvhost_syncpt_is_valid_pt(&ctx->dev->syncpt, args->id))
                return -EINVAL;
        if (args->timeout == NVHOST_NO_TIMEOUT)
                /* FIXME: MAX_SCHEDULE_TIMEOUT is ulong which can be bigger
@@ -175,7 +175,7 @@ static int nvhost_ioctl_ctrl_syncpt_waitmex(struct nvhost_ctrl_userctx *ctx,
        ulong timeout;
        int err;
        struct timespec ts;
-       if (args->id >= nvhost_syncpt_nb_pts(&ctx->dev->syncpt))
+       if (!nvhost_syncpt_is_valid_pt(&ctx->dev->syncpt, args->id))
                return -EINVAL;
        if (args->timeout == NVHOST_NO_TIMEOUT)
                timeout = MAX_SCHEDULE_TIMEOUT;
@@ -225,8 +225,7 @@ static int nvhost_ioctl_ctrl_sync_fence_create(struct nvhost_ctrl_userctx *ctx,
        }
 
        for (i = 0; i < args->num_pts; i++) {
-               if (pts[i].id >= nvhost_syncpt_nb_pts(&ctx->dev->syncpt) &&
-                   pts[i].id != NVSYNCPT_INVALID) {
+               if (!nvhost_syncpt_is_valid_pt(&ctx->dev->syncpt, pts[i].id)) {
                        err = -EINVAL;
                        goto out;
                }
@@ -385,7 +384,7 @@ static int nvhost_ioctl_ctrl_get_version(struct nvhost_ctrl_userctx *ctx,
 static int nvhost_ioctl_ctrl_syncpt_read_max(struct nvhost_ctrl_userctx *ctx,
        struct nvhost_ctrl_syncpt_read_args *args)
 {
-       if (args->id >= nvhost_syncpt_nb_pts(&ctx->dev->syncpt))
+       if (!nvhost_syncpt_is_valid_pt(&ctx->dev->syncpt, args->id))
                return -EINVAL;
        args->value = nvhost_syncpt_read_max(&ctx->dev->syncpt, args->id);
        return 0;
index cb0afe9e5da9bedd3c7c60e8b591a27626905ef9..5bcb8092d9b7519b61fc545a2de19b5fa5650286 100644 (file)
@@ -128,7 +128,7 @@ static void add_sync_waits(struct nvhost_channel *ch, int fd)
                u32 id;
                pt = container_of(pos, struct sync_pt, pt_list);
                id = nvhost_sync_pt_id(pt);
-               if (!id || id >= nvhost_syncpt_nb_pts(sp)) {
+               if (!id || !nvhost_syncpt_is_valid_pt(sp, id)) {
                        sync_fence_put(fence);
                        return;
                }
index 4ab6774ba77f5035535cdda73dd1b3d2f63ac12b..ead8610b73370550dfdc1bd275d12ec722635292 100644 (file)
@@ -219,7 +219,7 @@ static int do_waitchks(struct nvhost_job *job, struct nvhost_syncpt *sp,
                struct nvhost_waitchk *wait = &job->waitchk[i];
 
                /* validate syncpt id */
-               if (wait->syncpt_id > nvhost_syncpt_nb_pts(sp))
+               if (!nvhost_syncpt_is_valid_pt(sp, wait->syncpt_id))
                        continue;
 
                /* skip all other gathers */
@@ -398,7 +398,7 @@ int nvhost_job_pin(struct nvhost_job *job, struct nvhost_syncpt *sp)
        bitmap_zero(waitchk_mask, nvhost_syncpt_nb_pts(sp));
        for (i = 0; i < job->num_waitchk; i++) {
                u32 syncpt_id = job->waitchk[i].syncpt_id;
-               if (syncpt_id < nvhost_syncpt_nb_pts(sp))
+               if (nvhost_syncpt_is_valid_pt(sp, syncpt_id))
                        set_bit(syncpt_id, waitchk_mask);
        }
 
index 7d0e0c37b7b2b811a1b360acaaa2db7f45e79e27..3265c6190931076daa9847cad267f6b4b858f59e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Tegra Graphics Host Syncpoint Integration to linux/sync Framework
  *
- * Copyright (c) 2013-2014, NVIDIA Corporation. All rights reserved.
+ * Copyright (c) 2013-2015, NVIDIA Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -421,6 +421,13 @@ struct sync_fence *nvhost_sync_create_fence(struct platform_device *pdev,
        u32 i;
        struct sync_fence *fence = NULL;
 
+       for (i = 0; i < num_pts; i++) {
+               if (!nvhost_syncpt_is_valid_pt(sp, pts[i].id)) {
+                       WARN_ON(1);
+                       return ERR_PTR(-EINVAL);
+               }
+       }
+
        for (i = 0; i < num_pts; i++) {
                struct nvhost_sync_timeline *obj;
                struct sync_pt *pt;
@@ -428,8 +435,6 @@ struct sync_fence *nvhost_sync_create_fence(struct platform_device *pdev,
                u32 id = pts[i].id;
                u32 thresh = pts[i].thresh;
 
-               BUG_ON(id >= nvhost_syncpt_nb_pts(sp) &&
-                               (id != NVSYNCPT_INVALID));
                obj = nvhost_syncpt_timeline(sp, id);
                pt = nvhost_sync_pt_create_inst(obj, thresh);
                if (pt == NULL) {
index 0071e67a1817091cb738b514f645108cbb8f03d6..2cc1e16782a3a4cf396136329496da505ff0b37c 100644 (file)
@@ -52,10 +52,10 @@ static const char *max_name = "max";
  */
 void nvhost_syncpt_reset(struct nvhost_syncpt *sp)
 {
-       struct nvhost_master *host = syncpt_to_dev(sp);
        u32 i;
 
-       for (i = host->info.pts_base; i < host->info.pts_limit; i++)
+       for (i = nvhost_syncpt_pts_base(sp);
+                       i < nvhost_syncpt_pts_limit(sp); i++)
                syncpt_op().reset(sp, i);
        wmb();
 }
@@ -77,7 +77,8 @@ void nvhost_syncpt_save(struct nvhost_syncpt *sp)
        u32 i;
        struct nvhost_master *master = syncpt_to_dev(sp);
 
-       for (i = 0; i < nvhost_syncpt_nb_pts(sp); i++) {
+       for (i = nvhost_syncpt_pts_base(sp);
+                       i < nvhost_syncpt_pts_limit(sp); i++) {
                if (nvhost_syncpt_client_managed(sp, i))
                        syncpt_op().update_min(sp, i);
                else
@@ -207,7 +208,7 @@ int nvhost_syncpt_wait_timeout(struct nvhost_syncpt *sp, u32 id,
                        u32 id,
                        u32 thresh);
 
-       if (!id || id >= nvhost_syncpt_nb_pts(sp))
+       if (!id || !nvhost_syncpt_is_valid_pt(sp, id))
                return -EINVAL;
 
        if (value)
@@ -963,27 +964,22 @@ int nvhost_syncpt_init(struct platform_device *dev,
        int i;
        struct nvhost_master *host = syncpt_to_dev(sp);
        struct nvhost_device_data *data = platform_get_drvdata(dev);
+       int nb_pts = nvhost_syncpt_nb_pts(sp);
        int err = 0;
 
        /* Allocate structs for min, max and base values */
-       sp->assigned = kzalloc(sizeof(bool) * nvhost_syncpt_nb_pts(sp),
-                       GFP_KERNEL);
-       sp->client_managed = kzalloc(sizeof(bool) * nvhost_syncpt_nb_pts(sp),
-                       GFP_KERNEL);
-       sp->syncpt_names = kzalloc(sizeof(char *) * nvhost_syncpt_nb_pts(sp),
-                       GFP_KERNEL);
-       sp->last_used_by = kzalloc(sizeof(char *) * nvhost_syncpt_nb_pts(sp),
-                       GFP_KERNEL);
-       sp->min_val = kzalloc(sizeof(atomic_t) * nvhost_syncpt_nb_pts(sp),
-                       GFP_KERNEL);
-       sp->max_val = kzalloc(sizeof(atomic_t) * nvhost_syncpt_nb_pts(sp),
-                       GFP_KERNEL);
+       sp->assigned = kzalloc(sizeof(bool) * nb_pts, GFP_KERNEL);
+       sp->client_managed = kzalloc(sizeof(bool) * nb_pts, GFP_KERNEL);
+       sp->syncpt_names = kzalloc(sizeof(char *) * nb_pts, GFP_KERNEL);
+       sp->last_used_by = kzalloc(sizeof(char *) * nb_pts, GFP_KERNEL);
+       sp->min_val = kzalloc(sizeof(atomic_t) * nb_pts, GFP_KERNEL);
+       sp->max_val = kzalloc(sizeof(atomic_t) * nb_pts, GFP_KERNEL);
        sp->lock_counts =
                kzalloc(sizeof(atomic_t) * nvhost_syncpt_nb_mlocks(sp),
                        GFP_KERNEL);
 #ifdef CONFIG_TEGRA_GRHOST_SYNC
        sp->timeline = kzalloc(sizeof(struct nvhost_sync_timeline *) *
-                       nvhost_syncpt_nb_pts(sp), GFP_KERNEL);
+                       nb_pts, GFP_KERNEL);
        if (!sp->timeline) {
                err = -ENOMEM;
                goto fail;
@@ -1018,7 +1014,7 @@ int nvhost_syncpt_init(struct platform_device *dev,
 
        /* Allocate two attributes for each sync point: min and max */
        sp->syncpt_attrs = kzalloc(sizeof(*sp->syncpt_attrs)
-                       * nvhost_syncpt_nb_pts(sp) * NUM_SYSFS_ENTRY,
+                       * nb_pts * NUM_SYSFS_ENTRY,
                        GFP_KERNEL);
        if (!sp->syncpt_attrs) {
                err = -ENOMEM;
@@ -1031,7 +1027,8 @@ int nvhost_syncpt_init(struct platform_device *dev,
        }
 
        /* Fill in the attributes */
-       for (i = 0; i < nvhost_syncpt_nb_pts(sp); i++) {
+       for (i = nvhost_syncpt_pts_base(sp);
+                       i < nvhost_syncpt_pts_limit(sp); i++) {
                struct nvhost_syncpt_attr *min =
                        &sp->syncpt_attrs[i*NUM_SYSFS_ENTRY];
                struct nvhost_syncpt_attr *max =
@@ -1098,7 +1095,8 @@ static void nvhost_syncpt_deinit_timeline(struct nvhost_syncpt *sp)
 {
 #ifdef CONFIG_TEGRA_GRHOST_SYNC
        int i;
-       for (i = 0; i < nvhost_syncpt_nb_pts(sp); i++) {
+       for (i = nvhost_syncpt_pts_base(sp);
+                       i < nvhost_syncpt_pts_limit(sp); i++) {
                if (sp->timeline && sp->timeline[i]) {
                        sync_timeline_destroy(
                                (struct sync_timeline *)sp->timeline[i]);
@@ -1153,6 +1151,27 @@ int nvhost_syncpt_nb_pts(struct nvhost_syncpt *sp)
        return syncpt_to_dev(sp)->info.nb_pts;
 }
 
+int nvhost_syncpt_graphics_host_sp(struct nvhost_syncpt *sp)
+{
+       return syncpt_to_dev(sp)->info.pts_base;
+}
+
+int nvhost_syncpt_pts_limit(struct nvhost_syncpt *sp)
+{
+       return syncpt_to_dev(sp)->info.pts_limit;
+}
+
+int nvhost_syncpt_pts_base(struct nvhost_syncpt *sp)
+{
+       return syncpt_to_dev(sp)->info.pts_base;
+}
+
+bool nvhost_syncpt_is_valid_pt(struct nvhost_syncpt *sp, u32 id)
+{
+       return (id >= nvhost_syncpt_pts_base(sp) &&
+               id < nvhost_syncpt_pts_limit(sp) && id != NVSYNCPT_INVALID);
+}
+
 int nvhost_nb_syncpts_store(struct nvhost_syncpt *sp, const char *buf)
 {
        struct nvhost_master *master = syncpt_to_dev(sp);
@@ -1164,6 +1183,8 @@ int nvhost_nb_syncpts_store(struct nvhost_syncpt *sp, const char *buf)
                nvhost_warn(d, "number of syncpts modified from %d to %d\n",
                        master->info.nb_pts, nb_syncpts);
                master->info.nb_pts = nb_syncpts;
+               master->info.pts_limit = master->info.pts_base +
+                                               master->info.nb_pts;
        } else
                ret = -EIO;
 
@@ -1180,16 +1201,6 @@ void nvhost_syncpt_set_manager(struct nvhost_syncpt *sp, int id, bool client)
        sp->client_managed[id] = client;
 }
 
-int nvhost_syncpt_graphics_host_sp(struct nvhost_syncpt *sp)
-{
-       return syncpt_to_dev(sp)->info.pts_base;
-}
-
-int nvhost_syncpt_pts_limit(struct nvhost_syncpt *sp)
-{
-       return syncpt_to_dev(sp)->info.pts_limit;
-}
-
 /* public sync point API */
 u32 nvhost_syncpt_incr_max_ext(struct platform_device *dev, u32 id, u32 incrs)
 {
@@ -1261,12 +1272,21 @@ void nvhost_syncpt_set_min_eq_max_ext(struct platform_device *dev, u32 id)
 }
 EXPORT_SYMBOL(nvhost_syncpt_set_min_eq_max_ext);
 
+bool nvhost_syncpt_is_valid_pt_ext(struct platform_device *dev, u32 id)
+{
+       struct nvhost_master *master = nvhost_get_host(dev);
+       struct nvhost_syncpt *sp = &master->syncpt;
+
+       return nvhost_syncpt_is_valid_pt(sp, id);
+}
+EXPORT_SYMBOL(nvhost_syncpt_is_valid_pt_ext);
+
 int nvhost_syncpt_nb_pts_ext(struct platform_device *dev)
 {
        struct nvhost_master *master = nvhost_get_host(dev);
        struct nvhost_syncpt *sp = &master->syncpt;
 
-       return syncpt_to_dev(sp)->info.nb_pts;
+       return nvhost_syncpt_nb_pts(sp);
 }
 EXPORT_SYMBOL(nvhost_syncpt_nb_pts_ext);
 
index a3b8b44064a1334d17cb3da54f1a8b5ec2ab009e..8bc63a2e4d3b4e1d8f21245f1a49e7ec3febcbbf 100644 (file)
@@ -28,7 +28,7 @@
 
 /* when searching for free syncpt id, start from this base */
 #define NVHOST_FREE_SYNCPT_BASE(sp)    \
-       (nvhost_syncpt_graphics_host_sp(sp) + 1)
+       (nvhost_syncpt_pts_base(sp) + 1)
 
 /* timeout to wait for a syncpt to become free */
 #define NVHOST_SYNCPT_FREE_WAIT_TIMEOUT (1 * HZ)
@@ -107,6 +107,8 @@ void nvhost_syncpt_patch_check(struct nvhost_syncpt *sp);
 void nvhost_syncpt_set_min_eq_max(struct nvhost_syncpt *sp, u32 id);
 int nvhost_syncpt_client_managed(struct nvhost_syncpt *sp, u32 id);
 int nvhost_syncpt_nb_pts(struct nvhost_syncpt *sp);
+int nvhost_syncpt_pts_base(struct nvhost_syncpt *sp);
+bool nvhost_syncpt_is_valid_pt(struct nvhost_syncpt *sp, u32 id);
 int nvhost_nb_syncpts_store(struct nvhost_syncpt *sp, const char *buf);
 int nvhost_syncpt_nb_mlocks(struct nvhost_syncpt *sp);
 void nvhost_syncpt_set_manager(struct nvhost_syncpt *sp, int id, bool client);
@@ -160,11 +162,6 @@ static inline int nvhost_syncpt_wait(struct nvhost_syncpt *sp, u32 id, u32 thres
 
 int nvhost_syncpt_patch_wait(struct nvhost_syncpt *sp, void *patch_addr);
 
-static inline int nvhost_syncpt_is_valid(struct nvhost_syncpt *sp, u32 id)
-{
-       return id != NVSYNCPT_INVALID && id < nvhost_syncpt_nb_pts(sp);
-}
-
 int nvhost_mutex_try_lock(struct nvhost_syncpt *sp, int idx);
 
 void nvhost_mutex_unlock(struct nvhost_syncpt *sp, int idx);
index 31b8d1705d4ce1742fc1849dfecea36a8ae3d0c6..26d95e733e4a67c74b654a9237d0c416461ca16e 100644 (file)
@@ -379,6 +379,7 @@ int nvhost_syncpt_is_expired_ext(struct platform_device *dev,
        u32 id, u32 thresh);
 void nvhost_syncpt_set_min_eq_max_ext(struct platform_device *dev, u32 id);
 int nvhost_syncpt_nb_pts_ext(struct platform_device *dev);
+bool nvhost_syncpt_is_valid_pt_ext(struct platform_device *dev, u32 id);
 
 /* public host1x interrupt management APIs */
 int nvhost_intr_register_notifier(struct platform_device *pdev,