xref: /openbmc/linux/drivers/gpu/host1x/syncpt.h (revision 625d4ffb)
19952f691SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
275471687STerje Bergstrom /*
375471687STerje Bergstrom  * Tegra host1x Syncpoints
475471687STerje Bergstrom  *
575471687STerje Bergstrom  * Copyright (c) 2010-2013, NVIDIA Corporation.
675471687STerje Bergstrom  */
775471687STerje Bergstrom 
875471687STerje Bergstrom #ifndef __HOST1X_SYNCPT_H
975471687STerje Bergstrom #define __HOST1X_SYNCPT_H
1075471687STerje Bergstrom 
1175471687STerje Bergstrom #include <linux/atomic.h>
1235d747a8SThierry Reding #include <linux/host1x.h>
1375471687STerje Bergstrom #include <linux/kernel.h>
142aed4f5aSMikko Perttunen #include <linux/kref.h>
1575471687STerje Bergstrom #include <linux/sched.h>
1675471687STerje Bergstrom 
17*625d4ffbSMikko Perttunen #include "fence.h"
187ede0b0bSTerje Bergstrom #include "intr.h"
197ede0b0bSTerje Bergstrom 
2075471687STerje Bergstrom struct host1x;
2175471687STerje Bergstrom 
226579324aSTerje Bergstrom /* Reserved for replacing an expired wait with a NOP */
236579324aSTerje Bergstrom #define HOST1X_SYNCPT_RESERVED			0
246579324aSTerje Bergstrom 
25f5a954feSArto Merilainen struct host1x_syncpt_base {
26f5a954feSArto Merilainen 	unsigned int id;
27f5a954feSArto Merilainen 	bool requested;
28f5a954feSArto Merilainen };
29f5a954feSArto Merilainen 
3075471687STerje Bergstrom struct host1x_syncpt {
312aed4f5aSMikko Perttunen 	struct kref ref;
322aed4f5aSMikko Perttunen 
335c0d8d38SThierry Reding 	unsigned int id;
3475471687STerje Bergstrom 	atomic_t min_val;
3575471687STerje Bergstrom 	atomic_t max_val;
3675471687STerje Bergstrom 	u32 base_val;
3775471687STerje Bergstrom 	const char *name;
38ece66891SArto Merilainen 	bool client_managed;
3975471687STerje Bergstrom 	struct host1x *host;
40f5a954feSArto Merilainen 	struct host1x_syncpt_base *base;
417ede0b0bSTerje Bergstrom 
427ede0b0bSTerje Bergstrom 	/* interrupt data */
43*625d4ffbSMikko Perttunen 	struct host1x_fence_list fences;
44c78f837aSMikko Perttunen 
45c78f837aSMikko Perttunen 	/*
46c78f837aSMikko Perttunen 	 * If a submission incrementing this syncpoint fails, lock it so that
47c78f837aSMikko Perttunen 	 * further submission cannot be made until application has handled the
48c78f837aSMikko Perttunen 	 * failure.
49c78f837aSMikko Perttunen 	 */
50c78f837aSMikko Perttunen 	bool locked;
5175471687STerje Bergstrom };
5275471687STerje Bergstrom 
5375471687STerje Bergstrom /* Initialize sync point array  */
5475471687STerje Bergstrom int host1x_syncpt_init(struct host1x *host);
5575471687STerje Bergstrom 
5675471687STerje Bergstrom /*  Free sync point array */
5775471687STerje Bergstrom void host1x_syncpt_deinit(struct host1x *host);
5875471687STerje Bergstrom 
5975471687STerje Bergstrom /* Return number of sync point supported. */
6014c95fc8SThierry Reding unsigned int host1x_syncpt_nb_pts(struct host1x *host);
6175471687STerje Bergstrom 
6275471687STerje Bergstrom /* Return number of wait bases supported. */
6314c95fc8SThierry Reding unsigned int host1x_syncpt_nb_bases(struct host1x *host);
6475471687STerje Bergstrom 
6575471687STerje Bergstrom /* Return number of mlocks supported. */
6614c95fc8SThierry Reding unsigned int host1x_syncpt_nb_mlocks(struct host1x *host);
6775471687STerje Bergstrom 
6875471687STerje Bergstrom /*
6975471687STerje Bergstrom  * Check sync point sanity. If max is larger than min, there have too many
7075471687STerje Bergstrom  * sync point increments.
7175471687STerje Bergstrom  *
7275471687STerje Bergstrom  * Client managed sync point are not tracked.
7375471687STerje Bergstrom  * */
host1x_syncpt_check_max(struct host1x_syncpt * sp,u32 real)7475471687STerje Bergstrom static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real)
7575471687STerje Bergstrom {
7675471687STerje Bergstrom 	u32 max;
7775471687STerje Bergstrom 	if (sp->client_managed)
7875471687STerje Bergstrom 		return true;
7975471687STerje Bergstrom 	max = host1x_syncpt_read_max(sp);
8075471687STerje Bergstrom 	return (s32)(max - real) >= 0;
8175471687STerje Bergstrom }
8275471687STerje Bergstrom 
8375471687STerje Bergstrom /* Return true if sync point is client managed. */
host1x_syncpt_client_managed(struct host1x_syncpt * sp)84ece66891SArto Merilainen static inline bool host1x_syncpt_client_managed(struct host1x_syncpt *sp)
8575471687STerje Bergstrom {
8675471687STerje Bergstrom 	return sp->client_managed;
8775471687STerje Bergstrom }
8875471687STerje Bergstrom 
8975471687STerje Bergstrom /*
9075471687STerje Bergstrom  * Returns true if syncpoint min == max, which means that there are no
9175471687STerje Bergstrom  * outstanding operations.
9275471687STerje Bergstrom  */
host1x_syncpt_idle(struct host1x_syncpt * sp)9375471687STerje Bergstrom static inline bool host1x_syncpt_idle(struct host1x_syncpt *sp)
9475471687STerje Bergstrom {
9575471687STerje Bergstrom 	int min, max;
9675471687STerje Bergstrom 	smp_rmb();
9775471687STerje Bergstrom 	min = atomic_read(&sp->min_val);
9875471687STerje Bergstrom 	max = atomic_read(&sp->max_val);
9975471687STerje Bergstrom 	return (min == max);
10075471687STerje Bergstrom }
10175471687STerje Bergstrom 
10275471687STerje Bergstrom /* Load current value from hardware to the shadow register. */
10375471687STerje Bergstrom u32 host1x_syncpt_load(struct host1x_syncpt *sp);
10475471687STerje Bergstrom 
1057ede0b0bSTerje Bergstrom /* Check if the given syncpoint value has already passed */
1067ede0b0bSTerje Bergstrom bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
1077ede0b0bSTerje Bergstrom 
10875471687STerje Bergstrom /* Save host1x sync point state into shadow registers. */
10975471687STerje Bergstrom void host1x_syncpt_save(struct host1x *host);
11075471687STerje Bergstrom 
11175471687STerje Bergstrom /* Reset host1x sync point state from shadow registers. */
11275471687STerje Bergstrom void host1x_syncpt_restore(struct host1x *host);
11375471687STerje Bergstrom 
11475471687STerje Bergstrom /* Read current wait base value into shadow register and return it. */
11575471687STerje Bergstrom u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp);
11675471687STerje Bergstrom 
11775471687STerje Bergstrom /* Indicate future operations by incrementing the sync point max. */
11875471687STerje Bergstrom u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
11975471687STerje Bergstrom 
12075471687STerje Bergstrom /* Check if sync point id is valid. */
host1x_syncpt_is_valid(struct host1x_syncpt * sp)12175471687STerje Bergstrom static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
12275471687STerje Bergstrom {
12375471687STerje Bergstrom 	return sp->id < host1x_syncpt_nb_pts(sp->host);
12475471687STerje Bergstrom }
12575471687STerje Bergstrom 
host1x_syncpt_set_locked(struct host1x_syncpt * sp)126c78f837aSMikko Perttunen static inline void host1x_syncpt_set_locked(struct host1x_syncpt *sp)
127c78f837aSMikko Perttunen {
128c78f837aSMikko Perttunen 	sp->locked = true;
129c78f837aSMikko Perttunen }
130c78f837aSMikko Perttunen 
13175471687STerje Bergstrom #endif
132