vcprop_subr.c revision 1.7 1 1.7 rin /* $NetBSD: vcprop_subr.c,v 1.7 2020/11/23 06:29: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.3 skrll
32 1.1 macallan #include <sys/param.h>
33 1.7 rin #include <sys/bus.h>
34 1.1 macallan #include <sys/device.h>
35 1.1 macallan
36 1.1 macallan #include <uvm/uvm_extern.h>
37 1.1 macallan
38 1.1 macallan #include <arm/broadcom/bcm2835reg.h>
39 1.1 macallan #include <arm/broadcom/bcm2835var.h>
40 1.1 macallan #include <arm/broadcom/bcm2835_mbox.h>
41 1.1 macallan
42 1.1 macallan #include <evbarm/rpi/vcio.h>
43 1.1 macallan #include <evbarm/rpi/vcpm.h>
44 1.1 macallan #include <evbarm/rpi/vcprop.h>
45 1.1 macallan
46 1.1 macallan #include <dev/wscons/wsconsio.h>
47 1.1 macallan
48 1.1 macallan int
49 1.1 macallan rpi_fb_set_video(int b)
50 1.1 macallan {
51 1.1 macallan int error;
52 1.1 macallan uint32_t res;
53 1.1 macallan
54 1.1 macallan /*
55 1.1 macallan * might as well put it here since we need to re-init it every time
56 1.1 macallan * and it's not like this is going to be called very often anyway
57 1.1 macallan */
58 1.1 macallan struct __aligned(16) {
59 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
60 1.1 macallan struct vcprop_tag_blankscreen vbt_blank;
61 1.1 macallan struct vcprop_tag end;
62 1.1 macallan } vb_setblank =
63 1.1 macallan {
64 1.1 macallan .vb_hdr = {
65 1.1 macallan .vpb_len = sizeof(vb_setblank),
66 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
67 1.1 macallan },
68 1.1 macallan .vbt_blank = {
69 1.1 macallan .tag = {
70 1.1 macallan .vpt_tag = VCPROPTAG_BLANK_SCREEN,
71 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_setblank.vbt_blank),
72 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
73 1.1 macallan },
74 1.1 macallan .state = (b != 0) ? VCPROP_BLANK_OFF : VCPROP_BLANK_ON,
75 1.1 macallan },
76 1.1 macallan .end = {
77 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
78 1.1 macallan },
79 1.1 macallan };
80 1.1 macallan
81 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_setblank,
82 1.1 macallan sizeof(vb_setblank), &res);
83 1.1 macallan #ifdef RPI_IOCTL_DEBUG
84 1.1 macallan printf("%s: %d %d %d %08x %08x\n", __func__, b,
85 1.1 macallan vb_setblank.vbt_blank.state, error, res,
86 1.1 macallan vb_setblank.vbt_blank.tag.vpt_rcode);
87 1.1 macallan #endif
88 1.2 skrll if (error)
89 1.2 skrll return error;
90 1.2 skrll
91 1.2 skrll if (!vcprop_buffer_success_p(&vb_setblank.vb_hdr) ||
92 1.2 skrll !vcprop_tag_success_p(&vb_setblank.vbt_blank.tag)) {
93 1.2 skrll return EIO;
94 1.2 skrll }
95 1.2 skrll
96 1.2 skrll return 0;
97 1.1 macallan }
98 1.1 macallan
99 1.1 macallan uint32_t
100 1.1 macallan rpi_alloc_mem(uint32_t size, uint32_t align, uint32_t flags)
101 1.1 macallan {
102 1.1 macallan int error;
103 1.1 macallan uint32_t res;
104 1.1 macallan
105 1.1 macallan struct __aligned(16) {
106 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
107 1.1 macallan struct vcprop_tag_allocmem vbt_am;
108 1.1 macallan struct vcprop_tag end;
109 1.1 macallan } vb_allocmem =
110 1.1 macallan {
111 1.1 macallan .vb_hdr = {
112 1.1 macallan .vpb_len = sizeof(vb_allocmem),
113 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
114 1.1 macallan },
115 1.1 macallan .vbt_am = {
116 1.1 macallan .tag = {
117 1.1 macallan .vpt_tag = VCPROPTAG_ALLOCMEM,
118 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_allocmem.vbt_am),
119 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
120 1.1 macallan },
121 1.1 macallan .size = size,
122 1.1 macallan .align = align,
123 1.1 macallan .flags = flags,
124 1.1 macallan },
125 1.1 macallan .end = {
126 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
127 1.1 macallan },
128 1.1 macallan };
129 1.1 macallan
130 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_allocmem,
131 1.1 macallan sizeof(vb_allocmem), &res);
132 1.1 macallan #ifdef RPI_IOCTL_DEBUG
133 1.1 macallan printf("%s: %d %d %08x %08x\n", __func__,
134 1.1 macallan vb_allocmem.vbt_am.size, error, res,
135 1.1 macallan vb_allocmem.vbt_am.tag.vpt_rcode);
136 1.1 macallan #endif
137 1.2 skrll if (error)
138 1.2 skrll return error;
139 1.2 skrll
140 1.2 skrll if (!vcprop_buffer_success_p(&vb_allocmem.vb_hdr) ||
141 1.2 skrll !vcprop_tag_success_p(&vb_allocmem.vbt_am.tag)) {
142 1.2 skrll return EIO;
143 1.2 skrll }
144 1.2 skrll
145 1.2 skrll /* Return the handle from the VC */
146 1.2 skrll return vb_allocmem.vbt_am.size;
147 1.1 macallan }
148 1.1 macallan
149 1.1 macallan bus_addr_t
150 1.1 macallan rpi_lock_mem(uint32_t handle)
151 1.1 macallan {
152 1.1 macallan int error;
153 1.1 macallan uint32_t res;
154 1.1 macallan
155 1.1 macallan struct __aligned(16) {
156 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
157 1.1 macallan struct vcprop_tag_lockmem vbt_lm;
158 1.1 macallan struct vcprop_tag end;
159 1.1 macallan } vb_lockmem =
160 1.1 macallan {
161 1.1 macallan .vb_hdr = {
162 1.1 macallan .vpb_len = sizeof(vb_lockmem),
163 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
164 1.1 macallan },
165 1.1 macallan .vbt_lm = {
166 1.1 macallan .tag = {
167 1.1 macallan .vpt_tag = VCPROPTAG_LOCKMEM,
168 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_lockmem.vbt_lm),
169 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
170 1.1 macallan },
171 1.1 macallan .handle = handle,
172 1.1 macallan },
173 1.1 macallan .end = {
174 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
175 1.1 macallan },
176 1.1 macallan };
177 1.1 macallan
178 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_lockmem,
179 1.1 macallan sizeof(vb_lockmem), &res);
180 1.1 macallan #ifdef RPI_IOCTL_DEBUG
181 1.1 macallan printf("%s: %d %d %08x %08x\n", __func__,
182 1.1 macallan vb_lockmem.vbt_lm.handle, error, res,
183 1.1 macallan vb_lockmem.vbt_lm.tag.vpt_rcode);
184 1.1 macallan #endif
185 1.2 skrll if (error)
186 1.2 skrll return 0;
187 1.2 skrll
188 1.2 skrll if (!vcprop_buffer_success_p(&vb_lockmem.vb_hdr) ||
189 1.2 skrll !vcprop_tag_success_p(&vb_lockmem.vbt_lm.tag)) {
190 1.2 skrll return 0;
191 1.2 skrll }
192 1.2 skrll
193 1.2 skrll return vb_lockmem.vbt_lm.handle;
194 1.1 macallan }
195 1.1 macallan
196 1.1 macallan int
197 1.1 macallan rpi_unlock_mem(uint32_t handle)
198 1.1 macallan {
199 1.1 macallan int error;
200 1.1 macallan uint32_t res;
201 1.1 macallan
202 1.1 macallan struct __aligned(16) {
203 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
204 1.1 macallan struct vcprop_tag_lockmem vbt_lm;
205 1.1 macallan struct vcprop_tag end;
206 1.1 macallan } vb_unlockmem =
207 1.1 macallan {
208 1.1 macallan .vb_hdr = {
209 1.1 macallan .vpb_len = sizeof(vb_unlockmem),
210 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
211 1.1 macallan },
212 1.1 macallan .vbt_lm = {
213 1.1 macallan .tag = {
214 1.1 macallan .vpt_tag = VCPROPTAG_UNLOCKMEM,
215 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_unlockmem.vbt_lm),
216 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
217 1.1 macallan },
218 1.1 macallan .handle = handle,
219 1.1 macallan },
220 1.1 macallan .end = {
221 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
222 1.1 macallan },
223 1.1 macallan };
224 1.1 macallan
225 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_unlockmem,
226 1.1 macallan sizeof(vb_unlockmem), &res);
227 1.1 macallan #ifdef RPI_IOCTL_DEBUG
228 1.1 macallan printf("%s: %d %d %08x %08x\n", __func__,
229 1.1 macallan vb_unlockmem.vbt_lm.handle, error, res,
230 1.1 macallan vb_unlockmem.vbt_lm.tag.vpt_rcode);
231 1.1 macallan #endif
232 1.2 skrll if (error)
233 1.2 skrll return error;
234 1.2 skrll
235 1.2 skrll if (!vcprop_buffer_success_p(&vb_unlockmem.vb_hdr) ||
236 1.2 skrll !vcprop_tag_success_p(&vb_unlockmem.vbt_lm.tag)) {
237 1.2 skrll return EIO;
238 1.2 skrll }
239 1.2 skrll
240 1.2 skrll return 0;
241 1.1 macallan }
242 1.1 macallan
243 1.1 macallan int
244 1.1 macallan rpi_release_mem(uint32_t handle)
245 1.1 macallan {
246 1.1 macallan int error;
247 1.1 macallan uint32_t res;
248 1.1 macallan
249 1.1 macallan struct __aligned(16) {
250 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
251 1.1 macallan struct vcprop_tag_lockmem vbt_lm;
252 1.1 macallan struct vcprop_tag end;
253 1.1 macallan } vb_releasemem =
254 1.1 macallan {
255 1.1 macallan .vb_hdr = {
256 1.1 macallan .vpb_len = sizeof(vb_releasemem),
257 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
258 1.1 macallan },
259 1.1 macallan .vbt_lm = {
260 1.1 macallan .tag = {
261 1.1 macallan .vpt_tag = VCPROPTAG_RELEASEMEM,
262 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_releasemem.vbt_lm),
263 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
264 1.1 macallan },
265 1.1 macallan .handle = handle,
266 1.1 macallan },
267 1.1 macallan .end = {
268 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
269 1.1 macallan },
270 1.1 macallan };
271 1.1 macallan
272 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_releasemem,
273 1.1 macallan sizeof(vb_releasemem), &res);
274 1.1 macallan #ifdef RPI_IOCTL_DEBUG
275 1.1 macallan printf("%s: %d %d %08x %08x\n", __func__,
276 1.1 macallan vb_releasemem.vbt_lm.handle, error, res,
277 1.1 macallan vb_releasemem.vbt_lm.tag.vpt_rcode);
278 1.1 macallan #endif
279 1.2 skrll if (error)
280 1.2 skrll return error;
281 1.2 skrll
282 1.2 skrll if (!vcprop_buffer_success_p(&vb_releasemem.vb_hdr) ||
283 1.2 skrll !vcprop_tag_success_p(&vb_releasemem.vbt_lm.tag)) {
284 1.2 skrll return EIO;
285 1.2 skrll }
286 1.2 skrll
287 1.2 skrll return 0;
288 1.1 macallan }
289 1.1 macallan
290 1.1 macallan int
291 1.1 macallan rpi_fb_movecursor(int x, int y, int on)
292 1.1 macallan {
293 1.1 macallan int error;
294 1.1 macallan uint32_t res;
295 1.1 macallan
296 1.1 macallan struct __aligned(16) {
297 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
298 1.1 macallan struct vcprop_tag_cursorstate vbt_cs;
299 1.1 macallan struct vcprop_tag end;
300 1.1 macallan } vb_cursorstate =
301 1.1 macallan {
302 1.1 macallan .vb_hdr = {
303 1.1 macallan .vpb_len = sizeof(vb_cursorstate),
304 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
305 1.1 macallan },
306 1.1 macallan .vbt_cs = {
307 1.1 macallan .tag = {
308 1.1 macallan .vpt_tag = VCPROPTAG_SET_CURSOR_STATE,
309 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_cursorstate.vbt_cs),
310 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
311 1.1 macallan },
312 1.1 macallan .enable = (on != 0) ? 1 : 0,
313 1.1 macallan .x = x,
314 1.1 macallan .y = y,
315 1.1 macallan .flags = 1,
316 1.1 macallan },
317 1.1 macallan .end = {
318 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
319 1.1 macallan },
320 1.1 macallan };
321 1.1 macallan
322 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_cursorstate,
323 1.1 macallan sizeof(vb_cursorstate), &res);
324 1.1 macallan #ifdef RPI_IOCTL_DEBUG
325 1.1 macallan printf("%s: %08x %d %08x %08x\n", __func__,
326 1.1 macallan vb_cursorstate.vbt_cs.enable, error, res,
327 1.1 macallan vb_cursorstate.vbt_cs.tag.vpt_rcode);
328 1.1 macallan #endif
329 1.2 skrll if (error)
330 1.2 skrll return error;
331 1.2 skrll
332 1.2 skrll if (!vcprop_buffer_success_p(&vb_cursorstate.vb_hdr) ||
333 1.2 skrll !vcprop_tag_success_p(&vb_cursorstate.vbt_cs.tag)) {
334 1.2 skrll return EIO;
335 1.2 skrll }
336 1.2 skrll
337 1.2 skrll return 0;
338 1.1 macallan }
339 1.1 macallan
340 1.1 macallan int
341 1.1 macallan rpi_fb_initcursor(bus_addr_t pixels, int hx, int hy)
342 1.1 macallan {
343 1.1 macallan int error;
344 1.1 macallan uint32_t res;
345 1.3 skrll
346 1.1 macallan
347 1.1 macallan struct __aligned(16) {
348 1.1 macallan struct vcprop_buffer_hdr vb_hdr;
349 1.1 macallan struct vcprop_tag_cursorinfo vbt_ci;
350 1.1 macallan struct vcprop_tag end;
351 1.1 macallan } vb_cursorinfo =
352 1.1 macallan {
353 1.1 macallan .vb_hdr = {
354 1.1 macallan .vpb_len = sizeof(vb_cursorinfo),
355 1.1 macallan .vpb_rcode = VCPROP_PROCESS_REQUEST,
356 1.1 macallan },
357 1.1 macallan .vbt_ci = {
358 1.1 macallan .tag = {
359 1.1 macallan .vpt_tag = VCPROPTAG_SET_CURSOR_INFO,
360 1.1 macallan .vpt_len = VCPROPTAG_LEN(vb_cursorinfo.vbt_ci),
361 1.1 macallan .vpt_rcode = VCPROPTAG_REQUEST,
362 1.1 macallan },
363 1.1 macallan .width = 64,
364 1.1 macallan .height = 64,
365 1.1 macallan .format = 0,
366 1.1 macallan .pixels = pixels,
367 1.1 macallan .hotspot_x = hx,
368 1.1 macallan .hotspot_y = hy,
369 1.1 macallan },
370 1.1 macallan .end = {
371 1.1 macallan .vpt_tag = VCPROPTAG_NULL,
372 1.1 macallan },
373 1.1 macallan };
374 1.1 macallan
375 1.1 macallan error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_cursorinfo,
376 1.1 macallan sizeof(vb_cursorinfo), &res);
377 1.1 macallan #ifdef RPI_IOCTL_DEBUG
378 1.1 macallan printf("%s: %d %d %08x %08x\n", __func__,
379 1.1 macallan vb_cursorinfo.vbt_ci.width, error, res,
380 1.1 macallan vb_cursorinfo.vbt_ci.tag.vpt_rcode);
381 1.1 macallan #endif
382 1.2 skrll if (error)
383 1.2 skrll return error;
384 1.2 skrll
385 1.2 skrll if (!vcprop_buffer_success_p(&vb_cursorinfo.vb_hdr) ||
386 1.2 skrll !vcprop_tag_success_p(&vb_cursorinfo.vbt_ci.tag)) {
387 1.2 skrll return EIO;
388 1.2 skrll }
389 1.2 skrll
390 1.2 skrll return 0;
391 1.1 macallan }
392