projects/linux·blob master · refs

132 lines · 3.2 KiB

1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Tegra host1x Syncpoints
4 *
5 * Copyright (c) 2010-2013, NVIDIA Corporation.
6 */
7
8#ifndef __HOST1X_SYNCPT_H
9#define __HOST1X_SYNCPT_H
10
11#include <linux/atomic.h>
12#include <linux/host1x.h>
13#include <linux/kernel.h>
14#include <linux/kref.h>
15#include <linux/overflow.h>
16#include <linux/sched.h>
17
18#include "fence.h"
19#include "intr.h"
20
21struct host1x;
22
23/* Reserved for replacing an expired wait with a NOP */
24#define HOST1X_SYNCPT_RESERVED 0
25
26struct host1x_syncpt_base {
27 unsigned int id;
28 bool requested;
29};
30
31struct host1x_syncpt {
32 struct kref ref;
33
34 unsigned int id;
35 atomic_t min_val;
36 atomic_t max_val;
37 u32 base_val;
38 const char *name;
39 bool client_managed;
40 struct host1x *host;
41 struct host1x_syncpt_base *base;
42
43 /* interrupt data */
44 struct host1x_fence_list fences;
45
46 /*
47 * If a submission incrementing this syncpoint fails, lock it so that
48 * further submission cannot be made until application has handled the
49 * failure.
50 */
51 bool locked;
52};
53
54/* Initialize sync point array */
55int host1x_syncpt_init(struct host1x *host);
56
57/* Free sync point array */
58void host1x_syncpt_deinit(struct host1x *host);
59
60/* Return number of sync point supported. */
61unsigned int host1x_syncpt_nb_pts(struct host1x *host);
62
63/* Return number of wait bases supported. */
64unsigned int host1x_syncpt_nb_bases(struct host1x *host);
65
66/* Return number of mlocks supported. */
67unsigned int host1x_syncpt_nb_mlocks(struct host1x *host);
68
69/*
70 * Check sync point sanity. If max is larger than min, there have too many
71 * sync point increments.
72 *
73 * Client managed sync point are not tracked.
74 * */
75static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real)
76{
77 u32 max;
78 if (sp->client_managed)
79 return true;
80 max = host1x_syncpt_read_max(sp);
81 return (s32)wrapping_sub(u32, max, real) >= 0;
82}
83
84/* Return true if sync point is client managed. */
85static inline bool host1x_syncpt_client_managed(struct host1x_syncpt *sp)
86{
87 return sp->client_managed;
88}
89
90/*
91 * Returns true if syncpoint min == max, which means that there are no
92 * outstanding operations.
93 */
94static inline bool host1x_syncpt_idle(struct host1x_syncpt *sp)
95{
96 int min, max;
97 smp_rmb();
98 min = atomic_read(&sp->min_val);
99 max = atomic_read(&sp->max_val);
100 return (min == max);
101}
102
103/* Load current value from hardware to the shadow register. */
104u32 host1x_syncpt_load(struct host1x_syncpt *sp);
105
106/* Check if the given syncpoint value has already passed */
107bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
108
109/* Save host1x sync point state into shadow registers. */
110void host1x_syncpt_save(struct host1x *host);
111
112/* Reset host1x sync point state from shadow registers. */
113void host1x_syncpt_restore(struct host1x *host);
114
115/* Read current wait base value into shadow register and return it. */
116u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp);
117
118/* Indicate future operations by incrementing the sync point max. */
119u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
120
121/* Check if sync point id is valid. */
122static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
123{
124 return sp->id < host1x_syncpt_nb_pts(sp->host);
125}
126
127static inline void host1x_syncpt_set_locked(struct host1x_syncpt *sp)
128{
129 sp->locked = true;
130}
131
132#endif