xref: /openbmc/linux/drivers/gpu/host1x/syncpt.h (revision 9952f691)
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>
1475471687STerje Bergstrom #include <linux/sched.h>
1575471687STerje Bergstrom 
167ede0b0bSTerje Bergstrom #include "intr.h"
177ede0b0bSTerje Bergstrom 
1875471687STerje Bergstrom struct host1x;
1975471687STerje Bergstrom 
206579324aSTerje Bergstrom /* Reserved for replacing an expired wait with a NOP */
216579324aSTerje Bergstrom #define HOST1X_SYNCPT_RESERVED			0
226579324aSTerje Bergstrom 
23f5a954feSArto Merilainen struct host1x_syncpt_base {
24f5a954feSArto Merilainen 	unsigned int id;
25f5a954feSArto Merilainen 	bool requested;
26f5a954feSArto Merilainen };
27f5a954feSArto Merilainen 
2875471687STerje Bergstrom struct host1x_syncpt {
295c0d8d38SThierry Reding 	unsigned int id;
3075471687STerje Bergstrom 	atomic_t min_val;
3175471687STerje Bergstrom 	atomic_t max_val;
3275471687STerje Bergstrom 	u32 base_val;
3375471687STerje Bergstrom 	const char *name;
34ece66891SArto Merilainen 	bool client_managed;
3575471687STerje Bergstrom 	struct host1x *host;
36617dd7ccSThierry Reding 	struct host1x_client *client;
37f5a954feSArto Merilainen 	struct host1x_syncpt_base *base;
387ede0b0bSTerje Bergstrom 
397ede0b0bSTerje Bergstrom 	/* interrupt data */
407ede0b0bSTerje Bergstrom 	struct host1x_syncpt_intr intr;
4175471687STerje Bergstrom };
4275471687STerje Bergstrom 
4375471687STerje Bergstrom /* Initialize sync point array  */
4475471687STerje Bergstrom int host1x_syncpt_init(struct host1x *host);
4575471687STerje Bergstrom 
4675471687STerje Bergstrom /*  Free sync point array */
4775471687STerje Bergstrom void host1x_syncpt_deinit(struct host1x *host);
4875471687STerje Bergstrom 
4975471687STerje Bergstrom /* Return number of sync point supported. */
5014c95fc8SThierry Reding unsigned int host1x_syncpt_nb_pts(struct host1x *host);
5175471687STerje Bergstrom 
5275471687STerje Bergstrom /* Return number of wait bases supported. */
5314c95fc8SThierry Reding unsigned int host1x_syncpt_nb_bases(struct host1x *host);
5475471687STerje Bergstrom 
5575471687STerje Bergstrom /* Return number of mlocks supported. */
5614c95fc8SThierry Reding unsigned int host1x_syncpt_nb_mlocks(struct host1x *host);
5775471687STerje Bergstrom 
5875471687STerje Bergstrom /*
5975471687STerje Bergstrom  * Check sync point sanity. If max is larger than min, there have too many
6075471687STerje Bergstrom  * sync point increments.
6175471687STerje Bergstrom  *
6275471687STerje Bergstrom  * Client managed sync point are not tracked.
6375471687STerje Bergstrom  * */
6475471687STerje Bergstrom static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real)
6575471687STerje Bergstrom {
6675471687STerje Bergstrom 	u32 max;
6775471687STerje Bergstrom 	if (sp->client_managed)
6875471687STerje Bergstrom 		return true;
6975471687STerje Bergstrom 	max = host1x_syncpt_read_max(sp);
7075471687STerje Bergstrom 	return (s32)(max - real) >= 0;
7175471687STerje Bergstrom }
7275471687STerje Bergstrom 
7375471687STerje Bergstrom /* Return true if sync point is client managed. */
74ece66891SArto Merilainen static inline bool host1x_syncpt_client_managed(struct host1x_syncpt *sp)
7575471687STerje Bergstrom {
7675471687STerje Bergstrom 	return sp->client_managed;
7775471687STerje Bergstrom }
7875471687STerje Bergstrom 
7975471687STerje Bergstrom /*
8075471687STerje Bergstrom  * Returns true if syncpoint min == max, which means that there are no
8175471687STerje Bergstrom  * outstanding operations.
8275471687STerje Bergstrom  */
8375471687STerje Bergstrom static inline bool host1x_syncpt_idle(struct host1x_syncpt *sp)
8475471687STerje Bergstrom {
8575471687STerje Bergstrom 	int min, max;
8675471687STerje Bergstrom 	smp_rmb();
8775471687STerje Bergstrom 	min = atomic_read(&sp->min_val);
8875471687STerje Bergstrom 	max = atomic_read(&sp->max_val);
8975471687STerje Bergstrom 	return (min == max);
9075471687STerje Bergstrom }
9175471687STerje Bergstrom 
9275471687STerje Bergstrom /* Load current value from hardware to the shadow register. */
9375471687STerje Bergstrom u32 host1x_syncpt_load(struct host1x_syncpt *sp);
9475471687STerje Bergstrom 
957ede0b0bSTerje Bergstrom /* Check if the given syncpoint value has already passed */
967ede0b0bSTerje Bergstrom bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
977ede0b0bSTerje Bergstrom 
9875471687STerje Bergstrom /* Save host1x sync point state into shadow registers. */
9975471687STerje Bergstrom void host1x_syncpt_save(struct host1x *host);
10075471687STerje Bergstrom 
10175471687STerje Bergstrom /* Reset host1x sync point state from shadow registers. */
10275471687STerje Bergstrom void host1x_syncpt_restore(struct host1x *host);
10375471687STerje Bergstrom 
10475471687STerje Bergstrom /* Read current wait base value into shadow register and return it. */
10575471687STerje Bergstrom u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp);
10675471687STerje Bergstrom 
10775471687STerje Bergstrom /* Indicate future operations by incrementing the sync point max. */
10875471687STerje Bergstrom u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
10975471687STerje Bergstrom 
11075471687STerje Bergstrom /* Check if sync point id is valid. */
11175471687STerje Bergstrom static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
11275471687STerje Bergstrom {
11375471687STerje Bergstrom 	return sp->id < host1x_syncpt_nb_pts(sp->host);
11475471687STerje Bergstrom }
11575471687STerje Bergstrom 
11675471687STerje Bergstrom #endif
117