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