]>
Commit | Line | Data |
---|---|---|
6579324a | 1 | /* |
6579324a TB |
2 | * Copyright (c) 2009-2013, NVIDIA Corporation. All rights reserved. |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | */ | |
18 | ||
19 | #ifndef __LINUX_HOST1X_H | |
20 | #define __LINUX_HOST1X_H | |
21 | ||
35d747a8 TR |
22 | #include <linux/kref.h> |
23 | #include <linux/types.h> | |
24 | ||
6579324a | 25 | enum host1x_class { |
e1e90644 TR |
26 | HOST1X_CLASS_HOST1X = 0x1, |
27 | HOST1X_CLASS_GR2D = 0x51, | |
28 | HOST1X_CLASS_GR2D_SB = 0x52, | |
6579324a TB |
29 | }; |
30 | ||
53fa7f72 TR |
31 | struct host1x_client; |
32 | ||
33 | struct host1x_client_ops { | |
34 | int (*init)(struct host1x_client *client); | |
35 | int (*exit)(struct host1x_client *client); | |
36 | }; | |
37 | ||
38 | struct host1x_client { | |
39 | struct list_head list; | |
40 | struct device *dev; | |
41 | ||
42 | const struct host1x_client_ops *ops; | |
43 | ||
44 | enum host1x_class class; | |
45 | struct host1x_channel *channel; | |
46 | ||
47 | struct host1x_syncpt **syncpts; | |
48 | unsigned int num_syncpts; | |
49 | }; | |
50 | ||
35d747a8 TR |
51 | /* |
52 | * host1x buffer objects | |
53 | */ | |
54 | ||
55 | struct host1x_bo; | |
56 | struct sg_table; | |
57 | ||
58 | struct host1x_bo_ops { | |
59 | struct host1x_bo *(*get)(struct host1x_bo *bo); | |
60 | void (*put)(struct host1x_bo *bo); | |
61 | dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt); | |
62 | void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt); | |
63 | void *(*mmap)(struct host1x_bo *bo); | |
64 | void (*munmap)(struct host1x_bo *bo, void *addr); | |
65 | void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum); | |
66 | void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr); | |
67 | }; | |
68 | ||
69 | struct host1x_bo { | |
70 | const struct host1x_bo_ops *ops; | |
71 | }; | |
72 | ||
73 | static inline void host1x_bo_init(struct host1x_bo *bo, | |
74 | const struct host1x_bo_ops *ops) | |
75 | { | |
76 | bo->ops = ops; | |
77 | } | |
78 | ||
79 | static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo) | |
80 | { | |
81 | return bo->ops->get(bo); | |
82 | } | |
83 | ||
84 | static inline void host1x_bo_put(struct host1x_bo *bo) | |
85 | { | |
86 | bo->ops->put(bo); | |
87 | } | |
88 | ||
89 | static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo, | |
90 | struct sg_table **sgt) | |
91 | { | |
92 | return bo->ops->pin(bo, sgt); | |
93 | } | |
94 | ||
95 | static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt) | |
96 | { | |
97 | bo->ops->unpin(bo, sgt); | |
98 | } | |
99 | ||
100 | static inline void *host1x_bo_mmap(struct host1x_bo *bo) | |
101 | { | |
102 | return bo->ops->mmap(bo); | |
103 | } | |
104 | ||
105 | static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr) | |
106 | { | |
107 | bo->ops->munmap(bo, addr); | |
108 | } | |
109 | ||
110 | static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum) | |
111 | { | |
112 | return bo->ops->kmap(bo, pagenum); | |
113 | } | |
114 | ||
115 | static inline void host1x_bo_kunmap(struct host1x_bo *bo, | |
116 | unsigned int pagenum, void *addr) | |
117 | { | |
118 | bo->ops->kunmap(bo, pagenum, addr); | |
119 | } | |
120 | ||
121 | /* | |
122 | * host1x syncpoints | |
123 | */ | |
124 | ||
125 | struct host1x_syncpt; | |
126 | struct host1x; | |
127 | ||
128 | struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id); | |
129 | u32 host1x_syncpt_id(struct host1x_syncpt *sp); | |
130 | u32 host1x_syncpt_read_min(struct host1x_syncpt *sp); | |
131 | u32 host1x_syncpt_read_max(struct host1x_syncpt *sp); | |
132 | int host1x_syncpt_incr(struct host1x_syncpt *sp); | |
133 | int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout, | |
134 | u32 *value); | |
135 | struct host1x_syncpt *host1x_syncpt_request(struct device *dev, | |
136 | bool client_managed); | |
137 | void host1x_syncpt_free(struct host1x_syncpt *sp); | |
138 | ||
139 | /* | |
140 | * host1x channel | |
141 | */ | |
142 | ||
143 | struct host1x_channel; | |
144 | struct host1x_job; | |
145 | ||
146 | struct host1x_channel *host1x_channel_request(struct device *dev); | |
147 | void host1x_channel_free(struct host1x_channel *channel); | |
148 | struct host1x_channel *host1x_channel_get(struct host1x_channel *channel); | |
149 | void host1x_channel_put(struct host1x_channel *channel); | |
150 | int host1x_job_submit(struct host1x_job *job); | |
151 | ||
152 | /* | |
153 | * host1x job | |
154 | */ | |
155 | ||
156 | struct host1x_reloc { | |
157 | struct host1x_bo *cmdbuf; | |
158 | u32 cmdbuf_offset; | |
159 | struct host1x_bo *target; | |
160 | u32 target_offset; | |
161 | u32 shift; | |
162 | u32 pad; | |
163 | }; | |
164 | ||
165 | struct host1x_job { | |
166 | /* When refcount goes to zero, job can be freed */ | |
167 | struct kref ref; | |
168 | ||
169 | /* List entry */ | |
170 | struct list_head list; | |
171 | ||
172 | /* Channel where job is submitted to */ | |
173 | struct host1x_channel *channel; | |
174 | ||
175 | u32 client; | |
176 | ||
177 | /* Gathers and their memory */ | |
178 | struct host1x_job_gather *gathers; | |
179 | unsigned int num_gathers; | |
180 | ||
181 | /* Wait checks to be processed at submit time */ | |
182 | struct host1x_waitchk *waitchk; | |
183 | unsigned int num_waitchk; | |
184 | u32 waitchk_mask; | |
185 | ||
186 | /* Array of handles to be pinned & unpinned */ | |
187 | struct host1x_reloc *relocarray; | |
188 | unsigned int num_relocs; | |
189 | struct host1x_job_unpin_data *unpins; | |
190 | unsigned int num_unpins; | |
191 | ||
192 | dma_addr_t *addr_phys; | |
193 | dma_addr_t *gather_addr_phys; | |
194 | dma_addr_t *reloc_addr_phys; | |
195 | ||
196 | /* Sync point id, number of increments and end related to the submit */ | |
197 | u32 syncpt_id; | |
198 | u32 syncpt_incrs; | |
199 | u32 syncpt_end; | |
200 | ||
201 | /* Maximum time to wait for this job */ | |
202 | unsigned int timeout; | |
203 | ||
204 | /* Index and number of slots used in the push buffer */ | |
205 | unsigned int first_get; | |
206 | unsigned int num_slots; | |
207 | ||
208 | /* Copy of gathers */ | |
209 | size_t gather_copy_size; | |
210 | dma_addr_t gather_copy; | |
211 | u8 *gather_copy_mapped; | |
212 | ||
213 | /* Check if register is marked as an address reg */ | |
214 | int (*is_addr_reg)(struct device *dev, u32 reg, u32 class); | |
215 | ||
216 | /* Request a SETCLASS to this class */ | |
217 | u32 class; | |
218 | ||
219 | /* Add a channel wait for previous ops to complete */ | |
220 | bool serialize; | |
221 | }; | |
222 | ||
223 | struct host1x_job *host1x_job_alloc(struct host1x_channel *ch, | |
224 | u32 num_cmdbufs, u32 num_relocs, | |
225 | u32 num_waitchks); | |
226 | void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id, | |
227 | u32 words, u32 offset); | |
228 | struct host1x_job *host1x_job_get(struct host1x_job *job); | |
229 | void host1x_job_put(struct host1x_job *job); | |
230 | int host1x_job_pin(struct host1x_job *job, struct device *dev); | |
231 | void host1x_job_unpin(struct host1x_job *job); | |
232 | ||
6579324a | 233 | #endif |