xref: /freebsd/sys/arm/broadcom/bcm2835/bcm2835_mbox_prop.h (revision 61898cde69374d5a9994e2074605bc4101aff72d)
1 /*-
2  * Copyright (C) 2013-2014 Daisuke Aoyama <aoyama@peach.ne.jp>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _BCM2835_MBOX_PROP_H_
30 #define _BCM2835_MBOX_PROP_H_
31 
32 #include <sys/cdefs.h>
33 #include <sys/types.h>
34 
35 /*
36  * Mailbox property interface:
37  * https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
38  */
39 #define BCM2835_MBOX_CODE_REQ			0
40 #define BCM2835_MBOX_CODE_RESP_SUCCESS		0x80000000
41 #define BCM2835_MBOX_CODE_RESP_ERROR		0x80000001
42 #define BCM2835_MBOX_TAG_VAL_LEN_RESPONSE	0x80000000
43 
44 struct bcm2835_mbox_hdr {
45 	uint32_t	buf_size;
46 	uint32_t	code;
47 };
48 
49 struct bcm2835_mbox_tag_hdr {
50 	uint32_t	tag;
51 	uint32_t	val_buf_size;
52 	uint32_t	val_len;
53 };
54 
55 #define	BCM2835_MBOX_INIT_TAG(tag_, tagid_) do {		\
56 	(tag_)->tag_hdr.tag = BCM2835_MBOX_TAG_##tagid_;	\
57 	(tag_)->tag_hdr.val_buf_size = sizeof((tag_)->body);	\
58 	(tag_)->tag_hdr.val_len = sizeof((tag_)->body.req);	\
59 } while (0)
60 
61 #define BCM2835_MBOX_TAG_FIRMWARE_REVISION	0x00000001
62 
63 
64 
65 #define BCM2835_MBOX_POWER_ID_EMMC		0x00000000
66 #define BCM2835_MBOX_POWER_ID_UART0		0x00000001
67 #define BCM2835_MBOX_POWER_ID_UART1		0x00000002
68 #define BCM2835_MBOX_POWER_ID_USB_HCD		0x00000003
69 #define BCM2835_MBOX_POWER_ID_I2C0		0x00000004
70 #define BCM2835_MBOX_POWER_ID_I2C1		0x00000005
71 #define BCM2835_MBOX_POWER_ID_I2C2		0x00000006
72 #define BCM2835_MBOX_POWER_ID_SPI		0x00000007
73 #define BCM2835_MBOX_POWER_ID_CCP2TX		0x00000008
74 
75 #define BCM2835_MBOX_POWER_ON			(1 << 0)
76 #define BCM2835_MBOX_POWER_WAIT			(1 << 1)
77 
78 #define BCM2835_MBOX_TAG_GET_POWER_STATE	0x00020001
79 #define BCM2835_MBOX_TAG_SET_POWER_STATE	0x00028001
80 
81 struct msg_get_power_state {
82 	struct bcm2835_mbox_hdr hdr;
83 	struct bcm2835_mbox_tag_hdr tag_hdr;
84 	union {
85 		struct {
86 			uint32_t device_id;
87 		} req;
88 		struct {
89 			uint32_t device_id;
90 			uint32_t state;
91 		} resp;
92 	} body;
93 	uint32_t end_tag;
94 };
95 
96 struct msg_set_power_state {
97 	struct bcm2835_mbox_hdr hdr;
98 	struct bcm2835_mbox_tag_hdr tag_hdr;
99 	union {
100 		struct {
101 			uint32_t device_id;
102 			uint32_t state;
103 		} req;
104 		struct {
105 			uint32_t device_id;
106 			uint32_t state;
107 		} resp;
108 	} body;
109 	uint32_t end_tag;
110 };
111 
112 /* Sets the power state for a given device */
113 int bcm2835_mbox_set_power_state(uint32_t, boolean_t);
114 
115 #define BCM2835_MBOX_TAG_NOTIFY_XHCI_RESET	0x00030058
116 
117 struct msg_notify_xhci_reset {
118 	struct bcm2835_mbox_hdr hdr;
119 	struct bcm2835_mbox_tag_hdr tag_hdr;
120 	union {
121 		struct {
122 			uint32_t pci_device_addr;
123 		} req;
124 		struct {
125 		} resp;
126 	} body;
127 	uint32_t end_tag;
128 };
129 
130 /* Prompts the VideoCore processor to reload the xhci firmware. */
131 int bcm2835_mbox_notify_xhci_reset(uint32_t);
132 
133 #define BCM2835_MBOX_CLOCK_ID_EMMC		0x00000001
134 #define BCM2838_MBOX_CLOCK_ID_EMMC2		0x0000000c
135 
136 #define BCM2835_MBOX_TAG_GET_CLOCK_RATE		0x00030002
137 
138 struct msg_get_clock_rate {
139 	struct bcm2835_mbox_hdr hdr;
140 	struct bcm2835_mbox_tag_hdr tag_hdr;
141 	union {
142 		struct {
143 			uint32_t clock_id;
144 		} req;
145 		struct {
146 			uint32_t clock_id;
147 			uint32_t rate_hz;
148 		} resp;
149 	} body;
150 	uint32_t end_tag;
151 };
152 
153 int bcm2835_mbox_get_clock_rate(uint32_t, uint32_t *);
154 
155 #define BCM2835_MBOX_TURBO_ON			1
156 #define BCM2835_MBOX_TURBO_OFF			0
157 
158 #define BCM2835_MBOX_TAG_GET_TURBO		0x00030009
159 #define BCM2835_MBOX_TAG_SET_TURBO		0x00038009
160 
161 struct msg_get_turbo {
162 	struct bcm2835_mbox_hdr hdr;
163 	struct bcm2835_mbox_tag_hdr tag_hdr;
164 	union {
165 		struct {
166 			uint32_t id;
167 		} req;
168 		struct {
169 			uint32_t id;
170 			uint32_t level;
171 		} resp;
172 	} body;
173 	uint32_t end_tag;
174 };
175 
176 struct msg_set_turbo {
177 	struct bcm2835_mbox_hdr hdr;
178 	struct bcm2835_mbox_tag_hdr tag_hdr;
179 	union {
180 		struct {
181 			uint32_t id;
182 			uint32_t level;
183 		} req;
184 		struct {
185 			uint32_t id;
186 			uint32_t level;
187 		} resp;
188 	} body;
189 	uint32_t end_tag;
190 };
191 
192 #define BCM2835_MBOX_VOLTAGE_ID_CORE		0x00000001
193 #define BCM2835_MBOX_VOLTAGE_ID_SDRAM_C		0x00000002
194 #define BCM2835_MBOX_VOLTAGE_ID_SDRAM_P		0x00000003
195 #define BCM2835_MBOX_VOLTAGE_ID_SDRAM_I		0x00000004
196 
197 #define BCM2835_MBOX_TAG_GET_VOLTAGE		0x00030003
198 #define BCM2835_MBOX_TAG_SET_VOLTAGE		0x00038003
199 #define BCM2835_MBOX_TAG_GET_MAX_VOLTAGE	0x00030005
200 #define BCM2835_MBOX_TAG_GET_MIN_VOLTAGE	0x00030008
201 
202 struct msg_get_voltage {
203 	struct bcm2835_mbox_hdr hdr;
204 	struct bcm2835_mbox_tag_hdr tag_hdr;
205 	union {
206 		struct {
207 			uint32_t voltage_id;
208 		} req;
209 		struct {
210 			uint32_t voltage_id;
211 			uint32_t value;
212 		} resp;
213 	} body;
214 	uint32_t end_tag;
215 };
216 
217 struct msg_set_voltage {
218 	struct bcm2835_mbox_hdr hdr;
219 	struct bcm2835_mbox_tag_hdr tag_hdr;
220 	union {
221 		struct {
222 			uint32_t voltage_id;
223 			uint32_t value;
224 		} req;
225 		struct {
226 			uint32_t voltage_id;
227 			uint32_t value;
228 		} resp;
229 	} body;
230 	uint32_t end_tag;
231 };
232 
233 struct msg_get_max_voltage {
234 	struct bcm2835_mbox_hdr hdr;
235 	struct bcm2835_mbox_tag_hdr tag_hdr;
236 	union {
237 		struct {
238 			uint32_t voltage_id;
239 		} req;
240 		struct {
241 			uint32_t voltage_id;
242 			uint32_t value;
243 		} resp;
244 	} body;
245 	uint32_t end_tag;
246 };
247 
248 struct msg_get_min_voltage {
249 	struct bcm2835_mbox_hdr hdr;
250 	struct bcm2835_mbox_tag_hdr tag_hdr;
251 	union {
252 		struct {
253 			uint32_t voltage_id;
254 		} req;
255 		struct {
256 			uint32_t voltage_id;
257 			uint32_t value;
258 		} resp;
259 	} body;
260 	uint32_t end_tag;
261 };
262 
263 #define BCM2835_MBOX_TAG_GET_TEMPERATURE	0x00030006
264 #define BCM2835_MBOX_TAG_GET_MAX_TEMPERATURE	0x0003000a
265 
266 struct msg_get_temperature {
267 	struct bcm2835_mbox_hdr hdr;
268 	struct bcm2835_mbox_tag_hdr tag_hdr;
269 	union {
270 		struct {
271 			uint32_t temperature_id;
272 		} req;
273 		struct {
274 			uint32_t temperature_id;
275 			uint32_t value;
276 		} resp;
277 	} body;
278 	uint32_t end_tag;
279 };
280 
281 struct msg_get_max_temperature {
282 	struct bcm2835_mbox_hdr hdr;
283 	struct bcm2835_mbox_tag_hdr tag_hdr;
284 	union {
285 		struct {
286 			uint32_t temperature_id;
287 		} req;
288 		struct {
289 			uint32_t temperature_id;
290 			uint32_t value;
291 		} resp;
292 	} body;
293 	uint32_t end_tag;
294 };
295 
296 #define	BCM2835_MBOX_TAG_GET_PHYSICAL_W_H	0x00040003
297 #define	BCM2835_MBOX_TAG_SET_PHYSICAL_W_H	0x00048003
298 #define	BCM2835_MBOX_TAG_GET_VIRTUAL_W_H	0x00040004
299 #define	BCM2835_MBOX_TAG_SET_VIRTUAL_W_H	0x00048004
300 
301 struct bcm2835_mbox_tag_fb_w_h {
302 	struct bcm2835_mbox_tag_hdr tag_hdr;
303 	union {
304 		struct {
305 			uint32_t width;
306 			uint32_t height;
307 		} req;
308 		struct {
309 			uint32_t width;
310 			uint32_t height;
311 		} resp;
312 	} body;
313 };
314 
315 #define	BCM2835_MBOX_TAG_GET_DEPTH		0x00040005
316 #define	BCM2835_MBOX_TAG_SET_DEPTH		0x00048005
317 
318 struct bcm2835_mbox_tag_depth {
319 	struct bcm2835_mbox_tag_hdr tag_hdr;
320 	union {
321 		struct {
322 			uint32_t bpp;
323 		} req;
324 		struct {
325 			uint32_t bpp;
326 		} resp;
327 	} body;
328 };
329 
330 #define	BCM2835_MBOX_TAG_GET_ALPHA_MODE		0x00040007
331 #define	BCM2835_MBOX_TAG_SET_ALPHA_MODE		0x00048007
332 
333 #define	BCM2835_MBOX_ALPHA_MODE_0_OPAQUE	0
334 #define	BCM2835_MBOX_ALPHA_MODE_0_TRANSPARENT	1
335 #define	BCM2835_MBOX_ALPHA_MODE_IGNORED		2
336 
337 struct bcm2835_mbox_tag_alpha_mode {
338 	struct bcm2835_mbox_tag_hdr tag_hdr;
339 	union {
340 		struct {
341 			uint32_t alpha;
342 		} req;
343 		struct {
344 			uint32_t alpha;
345 		} resp;
346 	} body;
347 };
348 
349 #define	BCM2835_MBOX_TAG_GET_VIRTUAL_OFFSET	0x00040009
350 #define	BCM2835_MBOX_TAG_SET_VIRTUAL_OFFSET	0x00048009
351 
352 struct bcm2835_mbox_tag_virtual_offset {
353 	struct bcm2835_mbox_tag_hdr tag_hdr;
354 	union {
355 		struct {
356 			uint32_t x;
357 			uint32_t y;
358 		} req;
359 		struct {
360 			uint32_t x;
361 			uint32_t y;
362 		} resp;
363 	} body;
364 };
365 
366 #define	BCM2835_MBOX_TAG_GET_PITCH		0x00040008
367 
368 struct bcm2835_mbox_tag_pitch {
369 	struct bcm2835_mbox_tag_hdr tag_hdr;
370 	union {
371 		struct {
372 		} req;
373 		struct {
374 			uint32_t pitch;
375 		} resp;
376 	} body;
377 };
378 
379 #define	BCM2835_MBOX_TAG_ALLOCATE_BUFFER	0x00040001
380 
381 struct bcm2835_mbox_tag_allocate_buffer {
382 	struct bcm2835_mbox_tag_hdr tag_hdr;
383 	union {
384 		struct {
385 			uint32_t alignment;
386 		} req;
387 		struct {
388 			uint32_t fb_address;
389 			uint32_t fb_size;
390 		} resp;
391 	} body;
392 };
393 
394 #define	BCM2835_MBOX_TAG_RELEASE_BUFFER		0x00048001
395 
396 struct bcm2835_mbox_tag_release_buffer {
397 	struct bcm2835_mbox_tag_hdr tag_hdr;
398 	union {
399 		struct {
400 		} req;
401 		struct {
402 		} resp;
403 	} body;
404 };
405 
406 #define	BCM2835_MBOX_TAG_GET_TOUCHBUF		0x0004000f
407 
408 struct bcm2835_mbox_tag_touchbuf {
409 	struct bcm2835_mbox_hdr hdr;
410 	struct bcm2835_mbox_tag_hdr tag_hdr;
411 	union {
412 		struct {
413 		} req;
414 		struct {
415 			uint32_t address;
416 		} resp;
417 	} body;
418 	uint32_t end_tag;
419 };
420 
421 struct bcm2835_fb_config {
422 	uint32_t xres;
423 	uint32_t yres;
424 	uint32_t vxres;
425 	uint32_t vyres;
426 	uint32_t xoffset;
427 	uint32_t yoffset;
428 	uint32_t bpp;
429 	uint32_t pitch;
430 	uint32_t base;
431 	uint32_t size;
432 };
433 
434 struct msg_fb_get_w_h {
435 	struct bcm2835_mbox_hdr hdr;
436 	struct bcm2835_mbox_tag_fb_w_h physical_w_h;
437 	uint32_t end_tag;
438 };
439 
440 int bcm2835_mbox_fb_get_w_h(struct bcm2835_fb_config *);
441 
442 struct msg_fb_get_bpp {
443 	struct bcm2835_mbox_hdr hdr;
444 	struct bcm2835_mbox_tag_depth bpp;
445 	uint32_t end_tag;
446 };
447 
448 int bcm2835_mbox_fb_get_bpp(struct bcm2835_fb_config *);
449 
450 struct msg_fb_setup {
451 	struct bcm2835_mbox_hdr hdr;
452 	struct bcm2835_mbox_tag_fb_w_h physical_w_h;
453 	struct bcm2835_mbox_tag_fb_w_h virtual_w_h;
454 	struct bcm2835_mbox_tag_virtual_offset offset;
455 	struct bcm2835_mbox_tag_depth depth;
456 	struct bcm2835_mbox_tag_alpha_mode alpha;
457 	struct bcm2835_mbox_tag_allocate_buffer buffer;
458 	struct bcm2835_mbox_tag_pitch pitch;
459 	uint32_t end_tag;
460 };
461 
462 int bcm2835_mbox_fb_init(struct bcm2835_fb_config *);
463 
464 int bcm2835_mbox_property(void *, size_t);
465 
466 #endif /* _BCM2835_MBOX_PROP_H_ */
467