vcprop.h revision 1.13 1 /* $NetBSD: vcprop.h,v 1.13 2014/09/28 14:38:29 macallan Exp $ */
2
3 /*-
4 * Copyright (c) 2012 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nick Hudson
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Mailbox property interface
34 */
35
36 #ifndef _EVBARM_RPI_VCPROP_H_
37 #define _EVBARM_RPI_VCPROP_H_
38
39 #include "opt_vcprop.h"
40
41 struct vcprop_tag {
42 uint32_t vpt_tag;
43 #define VCPROPTAG_NULL 0x00000000
44 #define VCPROPTAG_GET_FIRMWAREREV 0x00000001
45 #define VCPROPTAG_GET_BOARDMODEL 0x00010001
46 #define VCPROPTAG_GET_BOARDREVISION 0x00010002
47 #define VCPROPTAG_GET_MACADDRESS 0x00010003
48 #define VCPROPTAG_GET_BOARDSERIAL 0x00010004
49 #define VCPROPTAG_GET_ARMMEMORY 0x00010005
50 #define VCPROPTAG_GET_VCMEMORY 0x00010006
51 #define VCPROPTAG_GET_CLOCKS 0x00010007
52
53 #define VCPROPTAG_GET_POWERSTATE 0x00020001
54 #define VCPROPTAG_GET_POWERTIMING 0x00020002
55 #define VCPROPTAG_SET_POWERSTATE 0x00028001
56
57 #define VCPROPTAG_GET_CLOCKSTATE 0x00030001
58 #define VCPROPTAG_SET_CLOCKSTATE 0x00038001
59 #define VCPROPTAG_GET_CLOCKRATE 0x00030002
60 #define VCPROPTAG_SET_CLOCKRATE 0x00038002
61 #define VCPROPTAG_GET_MIN_CLOCKRATE 0x00030007
62 #define VCPROPTAG_GET_MAX_CLOCKRATE 0x00030004
63
64 #define VCPROPTAG_GET_VOLTAGE 0x00030003
65 #define VCPROPTAG_SET_VOLTAGE 0x00038003
66 #define VCPROPTAG_GET_MIN_VOLTAGE 0x00030008
67 #define VCPROPTAG_GET_MAX_VOLTAGE 0x00030005
68
69 #define VCPROPTAG_GET_TEMPERATURE 0x00030006
70 #define VCPROPTAG_GET_MAX_TEMPERATURE 0x0003000a
71
72 #define VCPROPTAG_GET_CMDLINE 0x00050001
73 #define VCPROPTAG_GET_DMACHAN 0x00060001
74
75 #define VCPROPTAG_ALLOCATE_BUFFER 0x00040001
76 #define VCPROPTAG_BLANK_SCREEN 0x00040002
77 #define VCPROPTAG_GET_FB_RES 0x00040003
78 #define VCPROPTAG_SET_FB_RES 0x00048003
79 #define VCPROPTAG_GET_FB_VRES 0x00040004
80 #define VCPROPTAG_SET_FB_VRES 0x00048004
81 #define VCPROPTAG_GET_FB_DEPTH 0x00040005
82 #define VCPROPTAG_SET_FB_DEPTH 0x00048005
83 #define VCPROPTAG_GET_FB_PIXEL_ORDER 0x00040006
84 #define VCPROPTAG_SET_FB_PIXEL_ORDER 0x00048006
85 #define VCPROPTAG_GET_FB_ALPHA_MODE 0x00040007
86 #define VCPROPTAG_SET_FB_ALPHA_MODE 0x00048007
87 #define VCPROPTAG_GET_FB_PITCH 0x00040008
88
89 #define VCPROPTAG_GET_EDID_BLOCK 0x00030020
90
91 #define VCPROPTAG_ALLOCMEM 0x0003000c
92 #define VCPROPTAG_LOCKMEM 0x0003000d
93 #define VCPROPTAG_UNLOCKMEM 0x0003000e
94 #define VCPROPTAG_RELEASEMEM 0x0003000f
95
96 #define VCPROPTAG_SET_CURSOR_INFO 0x00008010
97 #define VCPROPTAG_SET_CURSOR_STATE 0x00008011
98
99 uint32_t vpt_len;
100 uint32_t vpt_rcode;
101 #define VCPROPTAG_REQUEST (0U << 31)
102 #define VCPROPTAG_RESPONSE (1U << 31)
103
104 };
105
106 #define VCPROPTAG_LEN(x) (sizeof((x)) - sizeof(struct vcprop_tag))
107
108 struct vcprop_memory {
109 uint32_t base;
110 uint32_t size;
111 };
112
113 #define VCPROP_MAXMEMBLOCKS 4
114 struct vcprop_tag_memory {
115 struct vcprop_tag tag;
116 struct vcprop_memory mem[VCPROP_MAXMEMBLOCKS];
117 };
118
119 struct vcprop_tag_fwrev {
120 struct vcprop_tag tag;
121 uint32_t rev;
122 };
123
124 struct vcprop_tag_boardmodel {
125 struct vcprop_tag tag;
126 uint32_t model;
127 } ;
128
129 struct vcprop_tag_boardrev {
130 struct vcprop_tag tag;
131 uint32_t rev;
132 } ;
133
134 struct vcprop_tag_macaddr {
135 struct vcprop_tag tag;
136 uint64_t addr;
137 } __packed;
138
139 struct vcprop_tag_boardserial {
140 struct vcprop_tag tag;
141 uint64_t sn;
142 } __packed;
143
144 #define VCPROP_CLK_EMMC 1
145 #define VCPROP_CLK_UART 2
146 #define VCPROP_CLK_ARM 3
147 #define VCPROP_CLK_CORE 4
148 #define VCPROP_CLK_V3D 5
149 #define VCPROP_CLK_H264 6
150 #define VCPROP_CLK_ISP 7
151 #define VCPROP_CLK_SDRAM 8
152 #define VCPROP_CLK_PIXEL 9
153 #define VCPROP_CLK_PWM 10
154
155 struct vcprop_clock {
156 uint32_t pclk;
157 uint32_t cclk;
158 };
159
160 #define VCPROP_MAXCLOCKS 16
161 struct vcprop_tag_clock {
162 struct vcprop_tag tag;
163 struct vcprop_clock clk[VCPROP_MAXCLOCKS];
164 };
165
166 #ifndef VCPROP_MAXCMDLINE
167 #define VCPROP_MAXCMDLINE 1024
168 #endif
169 struct vcprop_tag_cmdline {
170 struct vcprop_tag tag;
171 uint8_t cmdline[VCPROP_MAXCMDLINE];
172 };
173
174 struct vcprop_tag_dmachan {
175 struct vcprop_tag tag;
176 uint32_t mask;
177 };
178
179 struct vcprop_tag_clockstate {
180 struct vcprop_tag tag;
181 uint32_t id;
182 uint32_t state;
183 };
184
185 struct vcprop_tag_clockrate {
186 struct vcprop_tag tag;
187 uint32_t id;
188 uint32_t rate;
189 };
190
191 #define VCPROP_VOLTAGE_CORE 1
192 #define VCPROP_VOLTAGE_SDRAM_C 2
193 #define VCPROP_VOLTAGE_SDRAM_P 3
194 #define VCPROP_VOLTAGE_SDRAM_I 4
195
196 struct vcprop_tag_voltage {
197 struct vcprop_tag tag;
198 uint32_t id;
199 uint32_t value;
200 };
201
202 #define VCPROP_TEMP_SOC 0
203
204 struct vcprop_tag_temperature {
205 struct vcprop_tag tag;
206 uint32_t id;
207 uint32_t value;
208 };
209
210 #define VCPROP_POWER_SDCARD 0
211 #define VCPROP_POWER_UART0 1
212 #define VCPROP_POWER_UART1 2
213 #define VCPROP_POWER_USB 3
214 #define VCPROP_POWER_I2C0 4
215 #define VCPROP_POWER_I2C1 5
216 #define VCPROP_POWER_I2C2 6
217 #define VCPROP_POWER_SPI 7
218 #define VCPROP_POWER_CCP2TX 8
219
220 struct vcprop_tag_powertiming {
221 struct vcprop_tag tag;
222 uint32_t id;
223 uint32_t waitusec;
224 };
225
226 struct vcprop_tag_powerstate {
227 struct vcprop_tag tag;
228 uint32_t id;
229 uint32_t state;
230 };
231
232 struct vcprop_tag_allocbuf {
233 struct vcprop_tag tag;
234 uint32_t address; /* alignment for request */
235 uint32_t size;
236 };
237
238 #define VCPROP_BLANK_OFF 0
239 #define VCPROP_BLANK_ON 1
240
241 struct vcprop_tag_blankscreen {
242 struct vcprop_tag tag;
243 uint32_t state;
244 };
245
246 struct vcprop_tag_fbres {
247 struct vcprop_tag tag;
248 uint32_t width;
249 uint32_t height;
250 };
251
252 struct vcprop_tag_fbdepth {
253 struct vcprop_tag tag;
254 uint32_t bpp;
255 };
256
257 #define VCPROP_PIXEL_BGR 0
258 #define VCPROP_PIXEL_RGB 1
259
260 struct vcprop_tag_fbpixelorder {
261 struct vcprop_tag tag;
262 uint32_t state;
263 };
264
265 struct vcprop_tag_fbpitch {
266 struct vcprop_tag tag;
267 uint32_t linebytes;
268 };
269
270 #define VCPROP_ALPHA_ENABLED 0
271 #define VCPROP_ALPHA_REVERSED 1
272 #define VCPROP_ALPHA_IGNORED 2
273
274 struct vcprop_tag_fbalpha {
275 struct vcprop_tag tag;
276 uint32_t state;
277 };
278
279 struct vcprop_tag_edidblock {
280 struct vcprop_tag tag;
281 uint32_t blockno;
282 uint32_t status;
283 uint8_t data[128];
284 };
285
286 struct vcprop_tag_cursorinfo {
287 struct vcprop_tag tag;
288 uint32_t width;
289 uint32_t height;
290 uint32_t format;
291 uint32_t pixels; /* bus address in VC memory */
292 uint32_t hotspot_x;
293 uint32_t hotspot_y;
294 };
295
296 struct vcprop_tag_cursorstate {
297 struct vcprop_tag tag;
298 uint32_t enable; /* 1 - visible */
299 uint32_t x;
300 uint32_t y;
301 uint32_t flags; /* 0 - display coord. 1 - fb coord. */
302 };
303
304 struct vcprop_tag_allocmem {
305 struct vcprop_tag tag;
306 uint32_t size; /* handle returned here */
307 uint32_t align;
308 uint32_t flags;
309 /*
310 * flag definitions from
311 * https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
312 */
313 #define MEM_FLAG_DISCARDABLE (1 << 0) /* can be resized to 0 at any time. Use for cached data */
314 #define MEM_FLAG_NORMAL (0 << 2) /* normal allocating alias. Don't use from ARM */
315 #define MEM_FLAG_DIRECT (1 << 2) /* 0xC alias uncached */
316 #define MEM_FLAG_COHERENT (2 << 2) /* 0x8 alias. Non-allocating in L2 but coherent */
317 #define MEM_FLAG_L1_NONALLOCATING (MEM_FLAG_DIRECT | MEM_FLAG_COHERENT) /* Allocating in L2 */
318 #define MEM_FLAG_ZERO (1 << 4) /* initialise buffer to all zeros */
319 #define MEM_FLAG_NO_INIT (1 << 5) /* don't initialise (default is initialise to all ones */
320 #define MEM_FLAG_HINT_PERMALOCK (1 << 6) /* Likely to be locked for long periods of time. */
321 };
322
323 /* also for unlock and release */
324 struct vcprop_tag_lockmem {
325 struct vcprop_tag tag;
326 uint32_t handle; /* bus address returned here */
327 };
328
329 struct vcprop_buffer_hdr {
330 uint32_t vpb_len;
331 uint32_t vpb_rcode;
332 #define VCPROP_PROCESS_REQUEST 0
333 #define VCPROP_REQ_SUCCESS (1U << 31)
334 #define VCPROP_REQ_EPARSE (1U << 0)
335 };
336
337 static inline bool
338 vcprop_buffer_success_p(struct vcprop_buffer_hdr *vpbh)
339 {
340
341 return (vpbh->vpb_rcode & VCPROP_REQ_SUCCESS);
342 }
343
344 static inline bool
345 vcprop_tag_success_p(struct vcprop_tag *vpbt)
346 {
347
348 return (vpbt->vpt_rcode & VCPROPTAG_RESPONSE);
349 }
350
351 static inline size_t
352 vcprop_tag_resplen(struct vcprop_tag *vpbt)
353 {
354
355 return (vpbt->vpt_rcode & ~VCPROPTAG_RESPONSE);
356 }
357
358 #endif /* _EVBARM_RPI_VCPROP_H_ */
359
360 uint32_t rpi_alloc_mem(uint32_t, uint32_t, uint32_t);
361 bus_addr_t rpi_lock_mem(uint32_t);
362 int rpi_unlock_mem(uint32_t);
363 int rpi_release_mem(uint32_t);
364
365 int rpi_fb_set_video(int);
366
367 int rpi_fb_movecursor(int, int, int);
368 int rpi_fb_initcursor(bus_addr_t, int, int);
369