vcprop_subr.c revision 1.8 1 1.8 rin /* $NetBSD: vcprop_subr.c,v 1.8 2020/11/23 06:39:54 rin Exp $ */
2 1.1 macallan
3 1.1 macallan /*
4 1.1 macallan * Copyright (c) 2014 Michael Lorenz
5 1.1 macallan * All rights reserved.
6 1.1 macallan *
7 1.1 macallan * Redistribution and use in source and binary forms, with or without
8 1.1 macallan * modification, are permitted provided that the following conditions
9 1.1 macallan * are met:
10 1.1 macallan * 1. Redistributions of source code must retain the above copyright
11 1.1 macallan * notice, this list of conditions and the following disclaimer.
12 1.1 macallan * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 macallan * notice, this list of conditions and the following disclaimer in the
14 1.1 macallan * documentation and/or other materials provided with the distribution.
15 1.1 macallan *
16 1.1 macallan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 macallan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 macallan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 macallan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 macallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1 macallan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1 macallan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1 macallan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1 macallan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1 macallan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1 macallan */
27 1.1 macallan
28 1.1 macallan /*
29 1.1 macallan * Mailbox property interface wrapper functions
30 1.1 macallan */
31 1.8 rin #include <sys/cdefs.h>
32 1.8 rin __KERNEL_RCSID(0, "$NetBSD: vcprop_subr.c,v 1.8 2020/11/23 06:39:54 rin Exp $");
33 1.3 skrll
34 1.1 macallan #include <sys/param.h>
35 1.7 rin #include <sys/bus.h>
36 1.1 macallan #include <sys/device.h>
37 1.1 macallan
38 1.1 macallan #include <uvm/uvm_extern.h>
39 1.1 macallan
40 1.1 macallan #include <arm/broadcom/bcm2835reg.h>
41 1.1 macallan #include <arm/broadcom/bcm2835var.h>
42 1.1 macallan #include <arm/broadcom/bcm2835_mbox.h>
43 1.1 macallan
44 1.1 macallan #include <evbarm/rpi/vcio.h>
45 1.1 macallan #include <evbarm/rpi/vcpm.h>
46 1.1 macallan #include <evbarm/rpi/vcprop.h>
47 1.1 macallan
48 1.1 macallan #include <dev/wscons/wsconsio.h>
49 1.1 macallan
50 1.1 macallan int
51 1.1 macallan rpi_fb_set_video(int b)
52 1.1 macallan {
53 1.1 macallan int error;
54 1.1 macallan uint32_t res;
55 1.1 macallan
56 1.1 macallan /*
57 1.1 macallan * might as well put it here since we need to re-init it every time
58 1.1 macallan * and it's not like this is going to be called very often anyway
59 1.1 macallan */
60 1.1 macallan struct __aligned(16) {
61 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
62 1.1 macallan struct vcprop_tag_blankscreen vbt_blank;
63 1.1 macallan struct vcprop_tag end;
64 1.1 macallan } vb_setblank =
65 1.1 macallan {
66 1.1 macallan .vb_hdr = {
67 1.1 macallan .vpb_len = sizeof(vb_setblank),
68 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
69 1.1 macallan },
70 1.1 macallan .vbt_blank = {
71 1.1 macallan .tag = {
72 1.1 macallan .vpt_tag = VCPROPTAG_BLANK_SCREEN,
73 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_setblank.vbt_blank),
74 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
75 1.1 macallan },
76 1.1 macallan .state = (b != 0) ? VCPROP_BLANK_OFF : VCPROP_BLANK_ON,
77 1.1 macallan },
78 1.1 macallan .end = {
79 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
80 1.1 macallan },
81 1.1 macallan };
82 1.1 macallan
83 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_setblank,
84 1.1 macallan sizeof(vb_setblank), &res);
85 1.1 macallan #ifdef RPI_IOCTL_DEBUG
86 1.1 macallan printf("%s: %d %d %d %08x %08x\n", __func__, b,
87 1.1 macallan vb_setblank.vbt_blank.state, error, res,
88 1.1 macallan vb_setblank.vbt_blank.tag.vpt_rcode);
89 1.1 macallan #endif
90 1.2 skrll if (error)
91 1.2 skrll return error;
92 1.2 skrll
93 1.2 skrll if (!vcprop_buffer_success_p(&vb_setblank.vb_hdr) ||
94 1.2 skrll !vcprop_tag_success_p(&vb_setblank.vbt_blank.tag)) {
95 1.2 skrll return EIO;
96 1.2 skrll }
97 1.2 skrll
98 1.2 skrll return 0;
99 1.1 macallan }
100 1.1 macallan
101 1.1 macallan uint32_t
102 1.1 macallan rpi_alloc_mem(uint32_t size, uint32_t align, uint32_t flags)
103 1.1 macallan {
104 1.1 macallan int error;
105 1.1 macallan uint32_t res;
106 1.1 macallan
107 1.1 macallan struct __aligned(16) {
108 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
109 1.1 macallan struct vcprop_tag_allocmem vbt_am;
110 1.1 macallan struct vcprop_tag end;
111 1.1 macallan } vb_allocmem =
112 1.1 macallan {
113 1.1 macallan .vb_hdr = {
114 1.1 macallan .vpb_len = sizeof(vb_allocmem),
115 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
116 1.1 macallan },
117 1.1 macallan .vbt_am = {
118 1.1 macallan .tag = {
119 1.1 macallan .vpt_tag = VCPROPTAG_ALLOCMEM,
120 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_allocmem.vbt_am),
121 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
122 1.1 macallan },
123 1.1 macallan .size = size,
124 1.1 macallan .align = align,
125 1.1 macallan .flags = flags,
126 1.1 macallan },
127 1.1 macallan .end = {
128 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
129 1.1 macallan },
130 1.1 macallan };
131 1.1 macallan
132 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_allocmem,
133 1.1 macallan sizeof(vb_allocmem), &res);
134 1.1 macallan #ifdef RPI_IOCTL_DEBUG
135 1.1 macallan printf("%s: %d %d %08x %08x\n", __func__,
136 1.1 macallan vb_allocmem.vbt_am.size, error, res,
137 1.1 macallan vb_allocmem.vbt_am.tag.vpt_rcode);
138 1.1 macallan #endif
139 1.2 skrll if (error)
140 1.2 skrll return error;
141 1.2 skrll
142 1.2 skrll if (!vcprop_buffer_success_p(&vb_allocmem.vb_hdr) ||
143 1.2 skrll !vcprop_tag_success_p(&vb_allocmem.vbt_am.tag)) {
144 1.2 skrll return EIO;
145 1.2 skrll }
146 1.2 skrll
147 1.2 skrll /* Return the handle from the VC */
148 1.2 skrll return vb_allocmem.vbt_am.size;
149 1.1 macallan }
150 1.1 macallan
151 1.1 macallan bus_addr_t
152 1.1 macallan rpi_lock_mem(uint32_t handle)
153 1.1 macallan {
154 1.1 macallan int error;
155 1.1 macallan uint32_t res;
156 1.1 macallan
157 1.1 macallan struct __aligned(16) {
158 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
159 1.1 macallan struct vcprop_tag_lockmem vbt_lm;
160 1.1 macallan struct vcprop_tag end;
161 1.1 macallan } vb_lockmem =
162 1.1 macallan {
163 1.1 macallan .vb_hdr = {
164 1.1 macallan .vpb_len = sizeof(vb_lockmem),
165 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
166 1.1 macallan },
167 1.1 macallan .vbt_lm = {
168 1.1 macallan .tag = {
169 1.1 macallan .vpt_tag = VCPROPTAG_LOCKMEM,
170 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_lockmem.vbt_lm),
171 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
172 1.1 macallan },
173 1.1 macallan .handle = handle,
174 1.1 macallan },
175 1.1 macallan .end = {
176 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
177 1.1 macallan },
178 1.1 macallan };
179 1.1 macallan
180 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_lockmem,
181 1.1 macallan sizeof(vb_lockmem), &res);
182 1.1 macallan #ifdef RPI_IOCTL_DEBUG
183 1.1 macallan printf("%s: %d %d %08x %08x\n", __func__,
184 1.1 macallan vb_lockmem.vbt_lm.handle, error, res,
185 1.1 macallan vb_lockmem.vbt_lm.tag.vpt_rcode);
186 1.1 macallan #endif
187 1.2 skrll if (error)
188 1.2 skrll return 0;
189 1.2 skrll
190 1.2 skrll if (!vcprop_buffer_success_p(&vb_lockmem.vb_hdr) ||
191 1.2 skrll !vcprop_tag_success_p(&vb_lockmem.vbt_lm.tag)) {
192 1.2 skrll return 0;
193 1.2 skrll }
194 1.2 skrll
195 1.2 skrll return vb_lockmem.vbt_lm.handle;
196 1.1 macallan }
197 1.1 macallan
198 1.1 macallan int
199 1.1 macallan rpi_unlock_mem(uint32_t handle)
200 1.1 macallan {
201 1.1 macallan int error;
202 1.1 macallan uint32_t res;
203 1.1 macallan
204 1.1 macallan struct __aligned(16) {
205 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
206 1.1 macallan struct vcprop_tag_lockmem vbt_lm;
207 1.1 macallan struct vcprop_tag end;
208 1.1 macallan } vb_unlockmem =
209 1.1 macallan {
210 1.1 macallan .vb_hdr = {
211 1.1 macallan .vpb_len = sizeof(vb_unlockmem),
212 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
213 1.1 macallan },
214 1.1 macallan .vbt_lm = {
215 1.1 macallan .tag = {
216 1.1 macallan .vpt_tag = VCPROPTAG_UNLOCKMEM,
217 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_unlockmem.vbt_lm),
218 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
219 1.1 macallan },
220 1.1 macallan .handle = handle,
221 1.1 macallan },
222 1.1 macallan .end = {
223 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
224 1.1 macallan },
225 1.1 macallan };
226 1.1 macallan
227 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_unlockmem,
228 1.1 macallan sizeof(vb_unlockmem), &res);
229 1.1 macallan #ifdef RPI_IOCTL_DEBUG
230 1.1 macallan printf("%s: %d %d %08x %08x\n", __func__,
231 1.1 macallan vb_unlockmem.vbt_lm.handle, error, res,
232 1.1 macallan vb_unlockmem.vbt_lm.tag.vpt_rcode);
233 1.1 macallan #endif
234 1.2 skrll if (error)
235 1.2 skrll return error;
236 1.2 skrll
237 1.2 skrll if (!vcprop_buffer_success_p(&vb_unlockmem.vb_hdr) ||
238 1.2 skrll !vcprop_tag_success_p(&vb_unlockmem.vbt_lm.tag)) {
239 1.2 skrll return EIO;
240 1.2 skrll }
241 1.2 skrll
242 1.2 skrll return 0;
243 1.1 macallan }
244 1.1 macallan
245 1.1 macallan int
246 1.1 macallan rpi_release_mem(uint32_t handle)
247 1.1 macallan {
248 1.1 macallan int error;
249 1.1 macallan uint32_t res;
250 1.1 macallan
251 1.1 macallan struct __aligned(16) {
252 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
253 1.1 macallan struct vcprop_tag_lockmem vbt_lm;
254 1.1 macallan struct vcprop_tag end;
255 1.1 macallan } vb_releasemem =
256 1.1 macallan {
257 1.1 macallan .vb_hdr = {
258 1.1 macallan .vpb_len = sizeof(vb_releasemem),
259 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
260 1.1 macallan },
261 1.1 macallan .vbt_lm = {
262 1.1 macallan .tag = {
263 1.1 macallan .vpt_tag = VCPROPTAG_RELEASEMEM,
264 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_releasemem.vbt_lm),
265 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
266 1.1 macallan },
267 1.1 macallan .handle = handle,
268 1.1 macallan },
269 1.1 macallan .end = {
270 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
271 1.1 macallan },
272 1.1 macallan };
273 1.1 macallan
274 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_releasemem,
275 1.1 macallan sizeof(vb_releasemem), &res);
276 1.1 macallan #ifdef RPI_IOCTL_DEBUG
277 1.1 macallan printf("%s: %d %d %08x %08x\n", __func__,
278 1.1 macallan vb_releasemem.vbt_lm.handle, error, res,
279 1.1 macallan vb_releasemem.vbt_lm.tag.vpt_rcode);
280 1.1 macallan #endif
281 1.2 skrll if (error)
282 1.2 skrll return error;
283 1.2 skrll
284 1.2 skrll if (!vcprop_buffer_success_p(&vb_releasemem.vb_hdr) ||
285 1.2 skrll !vcprop_tag_success_p(&vb_releasemem.vbt_lm.tag)) {
286 1.2 skrll return EIO;
287 1.2 skrll }
288 1.2 skrll
289 1.2 skrll return 0;
290 1.1 macallan }
291 1.1 macallan
292 1.1 macallan int
293 1.1 macallan rpi_fb_movecursor(int x, int y, int on)
294 1.1 macallan {
295 1.1 macallan int error;
296 1.1 macallan uint32_t res;
297 1.1 macallan
298 1.1 macallan struct __aligned(16) {
299 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
300 1.1 macallan struct vcprop_tag_cursorstate vbt_cs;
301 1.1 macallan struct vcprop_tag end;
302 1.1 macallan } vb_cursorstate =
303 1.1 macallan {
304 1.1 macallan .vb_hdr = {
305 1.1 macallan .vpb_len = sizeof(vb_cursorstate),
306 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
307 1.1 macallan },
308 1.1 macallan .vbt_cs = {
309 1.1 macallan .tag = {
310 1.1 macallan .vpt_tag = VCPROPTAG_SET_CURSOR_STATE,
311 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_cursorstate.vbt_cs),
312 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
313 1.1 macallan },
314 1.1 macallan .enable = (on != 0) ? 1 : 0,
315 1.1 macallan .x = x,
316 1.1 macallan .y = y,
317 1.1 macallan .flags = 1,
318 1.1 macallan },
319 1.1 macallan .end = {
320 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
321 1.1 macallan },
322 1.1 macallan };
323 1.1 macallan
324 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_cursorstate,
325 1.1 macallan sizeof(vb_cursorstate), &res);
326 1.1 macallan #ifdef RPI_IOCTL_DEBUG
327 1.1 macallan printf("%s: %08x %d %08x %08x\n", __func__,
328 1.1 macallan vb_cursorstate.vbt_cs.enable, error, res,
329 1.1 macallan vb_cursorstate.vbt_cs.tag.vpt_rcode);
330 1.1 macallan #endif
331 1.2 skrll if (error)
332 1.2 skrll return error;
333 1.2 skrll
334 1.2 skrll if (!vcprop_buffer_success_p(&vb_cursorstate.vb_hdr) ||
335 1.2 skrll !vcprop_tag_success_p(&vb_cursorstate.vbt_cs.tag)) {
336 1.2 skrll return EIO;
337 1.2 skrll }
338 1.2 skrll
339 1.2 skrll return 0;
340 1.1 macallan }
341 1.1 macallan
342 1.1 macallan int
343 1.1 macallan rpi_fb_initcursor(bus_addr_t pixels, int hx, int hy)
344 1.1 macallan {
345 1.1 macallan int error;
346 1.1 macallan uint32_t res;
347 1.3 skrll
348 1.1 macallan
349 1.1 macallan struct __aligned(16) {
350 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
351 1.1 macallan struct vcprop_tag_cursorinfo vbt_ci;
352 1.1 macallan struct vcprop_tag end;
353 1.1 macallan } vb_cursorinfo =
354 1.1 macallan {
355 1.1 macallan .vb_hdr = {
356 1.1 macallan .vpb_len = sizeof(vb_cursorinfo),
357 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
358 1.1 macallan },
359 1.1 macallan .vbt_ci = {
360 1.1 macallan .tag = {
361 1.1 macallan .vpt_tag = VCPROPTAG_SET_CURSOR_INFO,
362 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_cursorinfo.vbt_ci),
363 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
364 1.1 macallan },
365 1.1 macallan .width = 64,
366 1.1 macallan .height = 64,
367 1.1 macallan .format = 0,
368 1.1 macallan .pixels = pixels,
369 1.1 macallan .hotspot_x = hx,
370 1.1 macallan .hotspot_y = hy,
371 1.1 macallan },
372 1.1 macallan .end = {
373 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
374 1.1 macallan },
375 1.1 macallan };
376 1.1 macallan
377 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_cursorinfo,
378 1.1 macallan sizeof(vb_cursorinfo), &res);
379 1.1 macallan #ifdef RPI_IOCTL_DEBUG
380 1.1 macallan printf("%s: %d %d %08x %08x\n", __func__,
381 1.1 macallan vb_cursorinfo.vbt_ci.width, error, res,
382 1.1 macallan vb_cursorinfo.vbt_ci.tag.vpt_rcode);
383 1.1 macallan #endif
384 1.2 skrll if (error)
385 1.2 skrll return error;
386 1.2 skrll
387 1.2 skrll if (!vcprop_buffer_success_p(&vb_cursorinfo.vb_hdr) ||
388 1.2 skrll !vcprop_tag_success_p(&vb_cursorinfo.vbt_ci.tag)) {
389 1.2 skrll return EIO;
390 1.2 skrll }
391 1.2 skrll
392 1.2 skrll return 0;
393 1.1 macallan }
394