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