^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Tegra host1x Syncpoints
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2010-2015, NVIDIA Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <trace/events/host1x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "syncpt.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "intr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define SYNCPT_CHECK_PERIOD (2 * HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define MAX_STUCK_CHECK_COUNT 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static struct host1x_syncpt_base *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) host1x_syncpt_base_request(struct host1x *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct host1x_syncpt_base *bases = host->bases;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) for (i = 0; i < host->info->nb_bases; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (!bases[i].requested)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if (i >= host->info->nb_bases)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) bases[i].requested = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return &bases[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static void host1x_syncpt_base_free(struct host1x_syncpt_base *base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) base->requested = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct host1x_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct host1x_syncpt *sp = host->syncpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) mutex_lock(&host->syncpt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) for (i = 0; i < host->info->nb_pts && sp->name; i++, sp++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (i >= host->info->nb_pts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (flags & HOST1X_SYNCPT_HAS_BASE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) sp->base = host1x_syncpt_base_request(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (!sp->base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) name = kasprintf(GFP_KERNEL, "%02u-%s", sp->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) client ? dev_name(client->dev) : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) goto free_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) sp->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) sp->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (flags & HOST1X_SYNCPT_CLIENT_MANAGED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) sp->client_managed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) sp->client_managed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) mutex_unlock(&host->syncpt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) free_base:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) host1x_syncpt_base_free(sp->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) sp->base = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) mutex_unlock(&host->syncpt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * host1x_syncpt_id() - retrieve syncpoint ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * @sp: host1x syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * Given a pointer to a struct host1x_syncpt, retrieves its ID. This ID is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * often used as a value to program into registers that control how hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * blocks interact with syncpoints.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u32 host1x_syncpt_id(struct host1x_syncpt *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return sp->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) EXPORT_SYMBOL(host1x_syncpt_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * host1x_syncpt_incr_max() - update the value sent to hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @sp: host1x syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * @incrs: number of increments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return (u32)atomic_add_return(incrs, &sp->max_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) EXPORT_SYMBOL(host1x_syncpt_incr_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * Write cached syncpoint and waitbase values to hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) void host1x_syncpt_restore(struct host1x *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct host1x_syncpt *sp_base = host->syncpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) for (i = 0; i < host1x_syncpt_nb_pts(host); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) host1x_hw_syncpt_restore(host, sp_base + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) for (i = 0; i < host1x_syncpt_nb_bases(host); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) host1x_hw_syncpt_restore_wait_base(host, sp_base + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * Update the cached syncpoint and waitbase values by reading them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * from the registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) void host1x_syncpt_save(struct host1x *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct host1x_syncpt *sp_base = host->syncpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) for (i = 0; i < host1x_syncpt_nb_pts(host); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (host1x_syncpt_client_managed(sp_base + i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) host1x_hw_syncpt_load(host, sp_base + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) WARN_ON(!host1x_syncpt_idle(sp_base + i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) for (i = 0; i < host1x_syncpt_nb_bases(host); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) host1x_hw_syncpt_load_wait_base(host, sp_base + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * Updates the cached syncpoint value by reading a new value from the hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) u32 host1x_syncpt_load(struct host1x_syncpt *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) val = host1x_hw_syncpt_load(sp->host, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) trace_host1x_syncpt_load_min(sp->id, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * Get the current syncpoint base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) host1x_hw_syncpt_load_wait_base(sp->host, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return sp->base_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * host1x_syncpt_incr() - increment syncpoint value from CPU, updating cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * @sp: host1x syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int host1x_syncpt_incr(struct host1x_syncpt *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return host1x_hw_syncpt_cpu_incr(sp->host, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) EXPORT_SYMBOL(host1x_syncpt_incr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * Updated sync point form hardware, and returns true if syncpoint is expired,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * false if we may need to wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static bool syncpt_load_min_is_expired(struct host1x_syncpt *sp, u32 thresh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) host1x_hw_syncpt_load(sp->host, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return host1x_syncpt_is_expired(sp, thresh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * host1x_syncpt_wait() - wait for a syncpoint to reach a given value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * @sp: host1x syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * @thresh: threshold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * @timeout: maximum time to wait for the syncpoint to reach the given value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * @value: return location for the syncpoint value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) u32 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) void *ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct host1x_waitlist *waiter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int err = 0, check_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) *value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* first check cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (host1x_syncpt_is_expired(sp, thresh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) *value = host1x_syncpt_load(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /* try to read from register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) val = host1x_hw_syncpt_load(sp->host, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (host1x_syncpt_is_expired(sp, thresh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) *value = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (!timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) err = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* allocate a waiter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) waiter = kzalloc(sizeof(*waiter), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (!waiter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /* schedule a wakeup when the syncpoint value is reached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) err = host1x_intr_add_action(sp->host, sp, thresh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) HOST1X_INTR_ACTION_WAKEUP_INTERRUPTIBLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) &wq, waiter, &ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) err = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* Caller-specified timeout may be impractically low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (timeout < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) timeout = LONG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /* wait for the syncpoint, or timeout, or signal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) while (timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) long check = min_t(long, SYNCPT_CHECK_PERIOD, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int remain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) remain = wait_event_interruptible_timeout(wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) syncpt_load_min_is_expired(sp, thresh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (remain > 0 || host1x_syncpt_is_expired(sp, thresh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) *value = host1x_syncpt_load(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (remain < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) err = remain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) timeout -= check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (timeout && check_count <= MAX_STUCK_CHECK_COUNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) dev_warn(sp->host->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) "%s: syncpoint id %u (%s) stuck waiting %d, timeout=%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) current->comm, sp->id, sp->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) thresh, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) host1x_debug_dump_syncpts(sp->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (check_count == MAX_STUCK_CHECK_COUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) host1x_debug_dump(sp->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) check_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) host1x_intr_put_ref(sp->host, sp->id, ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) EXPORT_SYMBOL(host1x_syncpt_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * Returns true if syncpoint is expired, false if we may need to wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) u32 current_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) u32 future_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) smp_rmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) current_val = (u32)atomic_read(&sp->min_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) future_val = (u32)atomic_read(&sp->max_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /* Note the use of unsigned arithmetic here (mod 1<<32).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * c = current_val = min_val = the current value of the syncpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * t = thresh = the value we are checking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * f = future_val = max_val = the value c will reach when all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * outstanding increments have completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * Note that c always chases f until it reaches f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * Dtf = (f - t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * Dtc = (c - t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * Consider all cases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * A) .....c..t..f..... Dtf < Dtc need to wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * B) .....c.....f..t.. Dtf > Dtc expired
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * C) ..t..c.....f..... Dtf > Dtc expired (Dct very large)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * Any case where f==c: always expired (for any t). Dtf == Dcf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * Any case where t==c: always expired (for any f). Dtf >= Dtc (because Dtc==0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * Any case where t==f!=c: always wait. Dtf < Dtc (because Dtf==0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * Dtc!=0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * Other cases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * A) .....t..f..c..... Dtf < Dtc need to wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * A) .....f..c..t..... Dtf < Dtc need to wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * A) .....f..t..c..... Dtf > Dtc expired
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * So:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * Dtf >= Dtc implies EXPIRED (return true)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * Dtf < Dtc implies WAIT (return false)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * Note: If t is expired then we *cannot* wait on it. We would wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * forever (hang the system).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * Note: do NOT get clever and remove the -thresh from both sides. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * is NOT the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * If future valueis zero, we have a client managed sync point. In that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * case we do a direct comparison.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (!host1x_syncpt_client_managed(sp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return future_val - thresh >= current_val - thresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return (s32)(current_val - thresh) >= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) int host1x_syncpt_init(struct host1x *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct host1x_syncpt_base *bases;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct host1x_syncpt *syncpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) syncpt = devm_kcalloc(host->dev, host->info->nb_pts, sizeof(*syncpt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (!syncpt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) bases = devm_kcalloc(host->dev, host->info->nb_bases, sizeof(*bases),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (!bases)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) for (i = 0; i < host->info->nb_pts; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) syncpt[i].id = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) syncpt[i].host = host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * Unassign syncpt from channels for purposes of Tegra186
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * syncpoint protection. This prevents any channel from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * accessing it until it is reassigned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) host1x_hw_syncpt_assign_to_channel(host, &syncpt[i], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) for (i = 0; i < host->info->nb_bases; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) bases[i].id = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) mutex_init(&host->syncpt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) host->syncpt = syncpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) host->bases = bases;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) host1x_syncpt_restore(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) host1x_hw_syncpt_enable_protection(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) /* Allocate sync point to use for clearing waits for expired fences */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) host->nop_sp = host1x_syncpt_alloc(host, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (!host->nop_sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * host1x_syncpt_request() - request a syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * @client: client requesting the syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * @flags: flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) * host1x client drivers can use this function to allocate a syncpoint for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) * subsequent use. A syncpoint returned by this function will be reserved for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) * use by the client exclusively. When no longer using a syncpoint, a host1x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * client driver needs to release it using host1x_syncpt_free().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct host1x *host = dev_get_drvdata(client->host->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return host1x_syncpt_alloc(host, client, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) EXPORT_SYMBOL(host1x_syncpt_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) * host1x_syncpt_free() - free a requested syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) * @sp: host1x syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * Release a syncpoint previously allocated using host1x_syncpt_request(). A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * host1x client driver should call this when the syncpoint is no longer in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * use. Note that client drivers must ensure that the syncpoint doesn't remain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * under the control of hardware after calling this function, otherwise two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * clients may end up trying to access the same syncpoint concurrently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) void host1x_syncpt_free(struct host1x_syncpt *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (!sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) mutex_lock(&sp->host->syncpt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) host1x_syncpt_base_free(sp->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) kfree(sp->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) sp->base = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) sp->client = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) sp->name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) sp->client_managed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) mutex_unlock(&sp->host->syncpt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) EXPORT_SYMBOL(host1x_syncpt_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) void host1x_syncpt_deinit(struct host1x *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) struct host1x_syncpt *sp = host->syncpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) for (i = 0; i < host->info->nb_pts; i++, sp++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) kfree(sp->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * host1x_syncpt_read_max() - read maximum syncpoint value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * @sp: host1x syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * The maximum syncpoint value indicates how many operations there are in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * queue, either in channel or in a software thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) u32 host1x_syncpt_read_max(struct host1x_syncpt *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) smp_rmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return (u32)atomic_read(&sp->max_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) EXPORT_SYMBOL(host1x_syncpt_read_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) * host1x_syncpt_read_min() - read minimum syncpoint value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * @sp: host1x syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) * The minimum syncpoint value is a shadow of the current sync point value in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) * hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) u32 host1x_syncpt_read_min(struct host1x_syncpt *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) smp_rmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return (u32)atomic_read(&sp->min_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) EXPORT_SYMBOL(host1x_syncpt_read_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * host1x_syncpt_read() - read the current syncpoint value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * @sp: host1x syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) u32 host1x_syncpt_read(struct host1x_syncpt *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) return host1x_syncpt_load(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) EXPORT_SYMBOL(host1x_syncpt_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) unsigned int host1x_syncpt_nb_pts(struct host1x *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) return host->info->nb_pts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) unsigned int host1x_syncpt_nb_bases(struct host1x *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) return host->info->nb_bases;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) unsigned int host1x_syncpt_nb_mlocks(struct host1x *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) return host->info->nb_mlocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) * host1x_syncpt_get() - obtain a syncpoint by ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) * @host: host1x controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) * @id: syncpoint ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, unsigned int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (id >= host->info->nb_pts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) return host->syncpt + id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) EXPORT_SYMBOL(host1x_syncpt_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) * host1x_syncpt_get_base() - obtain the wait base associated with a syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) * @sp: host1x syncpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return sp ? sp->base : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) EXPORT_SYMBOL(host1x_syncpt_get_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * host1x_syncpt_base_id() - retrieve the ID of a syncpoint wait base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * @base: host1x syncpoint wait base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) return base->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) EXPORT_SYMBOL(host1x_syncpt_base_id);