1/* $NetBSD: vcprop.h,v 1.20 2021/03/08 13:53:08 mlelstv 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#include <sys/endian.h> 42 43struct vcprop_tag { 44 uint32_t vpt_tag; 45#define VCPROPTAG_NULL 0x00000000 46#define VCPROPTAG_GET_FIRMWAREREV 0x00000001 47#define VCPROPTAG_GET_FIRMWAREVARIANT 0x00000002 48#define VCPROPTAG_GET_FIRMWAREHASH 0x00000003 49#define VCPROPTAG_GET_BOARDMODEL 0x00010001 50#define VCPROPTAG_GET_BOARDREVISION 0x00010002 51#define VCPROPTAG_GET_MACADDRESS 0x00010003 52#define VCPROPTAG_GET_BOARDSERIAL 0x00010004 53#define VCPROPTAG_GET_ARMMEMORY 0x00010005 54#define VCPROPTAG_GET_VCMEMORY 0x00010006 55#define VCPROPTAG_GET_CLOCKS 0x00010007 56 57#define VCPROPTAG_GET_POWERSTATE 0x00020001 58#define VCPROPTAG_GET_POWERTIMING 0x00020002 59#define VCPROPTAG_SET_POWERSTATE 0x00028001 60 61#define VCPROPTAG_GET_CLOCKSTATE 0x00030001 62#define VCPROPTAG_SET_CLOCKSTATE 0x00038001 63#define VCPROPTAG_GET_CLOCKRATE 0x00030002 64#define VCPROPTAG_SET_CLOCKRATE 0x00038002 65#define VCPROPTAG_GET_MIN_CLOCKRATE 0x00030007 66#define VCPROPTAG_GET_MAX_CLOCKRATE 0x00030004 67#define VCPROPTAG_GET_TURBO 0x00030009 68#define VCPROPTAG_SET_TURBO 0x00038009 69 70#define VCPROPTAG_GET_STC 0x0003000b 71#define VCPROPTAG_GET_THROTTLED 0x00030046 72#define VCPROPTAG_GET_CLOCK_MEASURED 0x00030047 73#define VCPROPTAG_NOTIFY_REBOOT 0x00030048 74 75#define VCPROPTAG_GET_VOLTAGE 0x00030003 76#define VCPROPTAG_SET_VOLTAGE 0x00038003 77#define VCPROPTAG_GET_MIN_VOLTAGE 0x00030008 78#define VCPROPTAG_GET_MAX_VOLTAGE 0x00030005 79 80#define VCPROPTAG_GET_TEMPERATURE 0x00030006 81#define VCPROPTAG_GET_MAX_TEMPERATURE 0x0003000a 82 83#define VCPROPTAG_GET_DOMAIN_STATE 0x00030030 84#define VCPROPTAG_SET_DOMAIN_STATE 0x00038030 85 86#define VCPROPTAG_GET_GPIO_STATE 0x00030041 87#define VCPROPTAG_SET_GPIO_STATE 0x00038041 88#define VCPROPTAG_GET_GPIO_CONFIG 0x00030041 89#define VCPROPTAG_SET_GPIO_CONFIG 0x00038041 90#define VCPROPTAG_GET_PERIPH_REG 0x00030045 91#define VCPROPTAG_SET_PERIPH_REG 0x00038045 92 93#define VCPROPTAG_GET_OTP 0x00030021 94#define VCPROPTAG_SET_OTP 0x00038021 95 96#define VCPROPTAG_SET_SDHOST_CLOCK 0x00038042 97 98#define VCPROPTAG_GET_POE_HAT_VAL 0x00030049 99#define VCPROPTAG_SET_POE_HAT_VAL 0x00030050 100 101#define VCPROPTAG_NOTIFY_XHCI_RESET 0x00030058 102 103#define VCPROPTAG_GET_CMDLINE 0x00050001 104#define VCPROPTAG_GET_DMACHAN 0x00060001 105 106#define VCPROPTAG_ALLOCATE_BUFFER 0x00040001 107#define VCPROPTAG_RELEASE_BUFFER 0x00048001 108#define VCPROPTAG_BLANK_SCREEN 0x00040002 109#define VCPROPTAG_GET_FB_RES 0x00040003 110#define VCPROPTAG_TST_FB_RES 0x00044003 111#define VCPROPTAG_SET_FB_RES 0x00048003 112#define VCPROPTAG_GET_FB_VRES 0x00040004 113#define VCPROPTAG_TST_FB_VRES 0x00044004 114#define VCPROPTAG_SET_FB_VRES 0x00048004 115#define VCPROPTAG_GET_FB_DEPTH 0x00040005 116#define VCPROPTAG_TST_FB_DEPTH 0x00044005 117#define VCPROPTAG_SET_FB_DEPTH 0x00048005 118#define VCPROPTAG_GET_FB_PIXEL_ORDER 0x00040006 119#define VCPROPTAG_TST_FB_PIXEL_ORDER 0x00044006 120#define VCPROPTAG_SET_FB_PIXEL_ORDER 0x00048006 121#define VCPROPTAG_GET_FB_ALPHA_MODE 0x00040007 122#define VCPROPTAG_TST_FB_ALPHA_MODE 0x00044007 123#define VCPROPTAG_SET_FB_ALPHA_MODE 0x00048007 124#define VCPROPTAG_GET_FB_PITCH 0x00040008 125#define VCPROPTAG_GET_VIRTUAL_OFFSET 0x00040009 126#define VCPROPTAG_TST_VIRTUAL_OFFSET 0x00044009 127#define VCPROPTAG_SET_VIRTUAL_OFFSET 0x00048009 128#define VCPROPTAG_GET_OVERSCAN 0x0004000a 129#define VCPROPTAG_TST_OVERSCAN 0x0004400a 130#define VCPROPTAG_SET_OVERSCAN 0x0004800a 131#define VCPROPTAG_GET_PALETTE 0x0004000b 132#define VCPROPTAG_TST_PALETTE 0x0004400b 133#define VCPROPTAG_SET_PALETTE 0x0004800b 134#define VCPROPTAG_GET_FB_LAYER 0x0004000c 135#define VCPROPTAG_TST_FB_LAYER 0x0004400c 136#define VCPROPTAG_SET_FB_LAYER 0x0004800c 137#define VCPROPTAG_GET_TRANSFORM 0x0004000d 138#define VCPROPTAG_TST_TRANSFORM 0x0004400d 139#define VCPROPTAG_SET_TRANSFORM 0x0004800d 140#define VCPROPTAG_GET_VSYNC 0x0004000e 141#define VCPROPTAG_TST_VSYNC 0x0004400e 142#define VCPROPTAG_SET_VSYNC 0x0004800e 143#define VCPROPTAG_GET_TOUCHBUF 0x0004000f 144#define VCPROPTAG_GET_SET_BACKLIGHT 0x0004800f 145#define VCPROPTAG_GET_GPIOVIRTBUF 0x00040010 146#define VCPROPTAG_SET_GPIOVIRTBUF 0x00048020 147#define VCPROPTAG_GET_NUM_DISPLAYS 0x00040013 148#define VCPROPTAG_SET_DISPLAYNUM 0x00048013 149#define VCPROPTAG_GET_DISPLAY_SETTINGS 0x00040014 150#define VCPROPTAG_GET_DISPLAYID 0x00040016 151 152#define VCPROPTAG_VCHIQ_INIT 0x00048010 153 154#define VCPROPTAG_SET_PLANE 0x00048015 155#define VCPROPTAG_GET_TIMING 0x00040017 156#define VCPROPTAG_SET_TIMING 0x00048017 157#define VCPROPTAG_GET_DISPLAY_CFG 0x00048018 158 159#define VCPROPTAG_GET_EDID_BLOCK 0x00030020 160#define VCPROPTAG_GET_EDID_BLOCK_DISP 0x00030021 161 162#define VCPROPTAG_ALLOCMEM 0x0003000c 163#define VCPROPTAG_LOCKMEM 0x0003000d 164#define VCPROPTAG_UNLOCKMEM 0x0003000e 165#define VCPROPTAG_RELEASEMEM 0x0003000f 166#define VCPROPTAG_EXECUTE_CODE 0x00030010 167#define VCPROPTAG_EXECUTE_QPU 0x00030011 168#define VCPROPTAG_SET_ENABLE_QPU 0x00030012 169#define VCPROPTAG_GET_DISPMANX_HANDLE 0x00030014 170 171#define VCPROPTAG_SET_CURSOR_INFO 0x00008010 172#define VCPROPTAG_SET_CURSOR_STATE 0x00008011 173 174 uint32_t vpt_len; 175 uint32_t vpt_rcode; 176#define VCPROPTAG_REQUEST (0U << 31) 177#define VCPROPTAG_RESPONSE (1U << 31) 178 179}; 180 181#define VCPROPTAG_LEN(x) (sizeof((x)) - sizeof(struct vcprop_tag)) 182 183#define VCPROP_INIT_REQUEST(req) \ 184 do { \ 185 memset(&(req), 0, sizeof((req))); \ 186 (req).vb_hdr.vpb_len = htole32(sizeof((req))); \ 187 (req).vb_hdr.vpb_rcode = htole32(VCPROP_PROCESS_REQUEST);\ 188 (req).end.vpt_tag = htole32(VCPROPTAG_NULL); \ 189 } while (0) 190#define VCPROP_INIT_TAG(s, t) \ 191 do { \ 192 (s).tag.vpt_tag = htole32(t); \ 193 (s).tag.vpt_rcode = htole32(VCPROPTAG_REQUEST); \ 194 (s).tag.vpt_len = htole32(VCPROPTAG_LEN(s)); \ 195 } while (0) 196 197struct vcprop_memory { 198 uint32_t base; 199 uint32_t size; 200}; 201 202#define VCPROP_MAXMEMBLOCKS 4 203struct vcprop_tag_memory { 204 struct vcprop_tag tag; 205 struct vcprop_memory mem[VCPROP_MAXMEMBLOCKS]; 206}; 207 208struct vcprop_tag_fwrev { 209 struct vcprop_tag tag; 210 uint32_t rev; 211}; 212 213struct vcprop_tag_boardmodel { 214 struct vcprop_tag tag; 215 uint32_t model; 216}; 217 218struct vcprop_tag_boardrev { 219 struct vcprop_tag tag; 220 uint32_t rev; 221}; 222 223#define VCPROP_REV_PCBREV __BITS(3,0) 224#define VCPROP_REV_MODEL __BITS(11,4) 225#define RPI_MODEL_A 0 226#define RPI_MODEL_B 1 227#define RPI_MODEL_A_PLUS 2 228#define RPI_MODEL_B_PLUS 3 229#define RPI_MODEL_B_PI2 4 230#define RPI_MODEL_ALPHA 5 231#define RPI_MODEL_COMPUTE 6 232#define RPI_MODEL_B_PI3 8 233#define RPI_MODEL_ZERO 9 234#define RPI_MODEL_COMPUTE_PI3 10 235#define RPI_MODEL_ZERO_W 12 236#define RPI_MODEL_B_PLUS_PI3 13 237#define RPI_MODEL_A_PLUS_PI3 14 238#define RPI_MODEL_CM_PLUS_PI3 16 239#define RPI_MODEL_B_PI4 17 240#define VCPROP_REV_PROCESSOR __BITS(15,12) 241#define RPI_PROCESSOR_BCM2835 0 242#define RPI_PROCESSOR_BCM2836 1 243#define RPI_PROCESSOR_BCM2837 2 244#define RPI_PROCESSOR_BCM2711 3 245#define VCPROP_REV_MANUF __BITS(19,16) 246#define RPI_MANUF_SONY 0 247#define RPI_MANUF_EGOMAN 1 248#define RPI_MANUF_QISDA 16 249#define RPI_MANUF_EMBEST 2 250#define RPI_MANUF_SONYJAPAN 3 251#define VCPROP_REV_MEMSIZE __BITS(22,20) 252#define RPI_MEMSIZE_256 0 253#define RPI_MEMSIZE_512 1 254#define RPI_MEMSIZE_1024 2 255#define RPI_MEMSIZE_2048 3 256#define RPI_MEMSIZE_4096 4 257#define VCPROP_REV_ENCFLAG __BIT(23) 258#define VCPROP_REV_WARRANTY __BITS(25,24) 259 260struct vcprop_tag_macaddr { 261 struct vcprop_tag tag; 262 uint64_t addr; 263} __packed; 264 265struct vcprop_tag_boardserial { 266 struct vcprop_tag tag; 267 uint64_t sn; 268} __packed; 269 270#define VCPROP_CLK_EMMC 1 271#define VCPROP_CLK_UART 2 272#define VCPROP_CLK_ARM 3 273#define VCPROP_CLK_CORE 4 274#define VCPROP_CLK_V3D 5 275#define VCPROP_CLK_H264 6 276#define VCPROP_CLK_ISP 7 277#define VCPROP_CLK_SDRAM 8 278#define VCPROP_CLK_PIXEL 9 279#define VCPROP_CLK_PWM 10 280#define VCPROP_CLK_EMMC2 12 281 282struct vcprop_clock { 283 uint32_t pclk; 284 uint32_t cclk; 285}; 286 287#define VCPROP_MAXCLOCKS 16 288struct vcprop_tag_clock { 289 struct vcprop_tag tag; 290 struct vcprop_clock clk[VCPROP_MAXCLOCKS]; 291}; 292 293#ifndef VCPROP_MAXCMDLINE 294#define VCPROP_MAXCMDLINE 1024 295#endif 296struct vcprop_tag_cmdline { 297 struct vcprop_tag tag; 298 uint8_t cmdline[VCPROP_MAXCMDLINE]; 299}; 300 301struct vcprop_tag_dmachan { 302 struct vcprop_tag tag; 303 uint32_t mask; 304}; 305 306struct vcprop_tag_clockstate { 307 struct vcprop_tag tag; 308 uint32_t id; 309 uint32_t state; 310}; 311 312struct vcprop_tag_clockrate { 313 struct vcprop_tag tag; 314 uint32_t id; 315 uint32_t rate; 316 uint32_t noturbo; 317}; 318 319struct vcprop_tag_sdhostclock { 320 struct vcprop_tag tag; 321 uint32_t clock; 322 uint32_t clock1; 323 uint32_t clock2; 324}; 325 326#define VCPROP_VOLTAGE_CORE 1 327#define VCPROP_VOLTAGE_SDRAM_C 2 328#define VCPROP_VOLTAGE_SDRAM_P 3 329#define VCPROP_VOLTAGE_SDRAM_I 4 330 331struct vcprop_tag_voltage { 332 struct vcprop_tag tag; 333 uint32_t id; 334 uint32_t value; 335}; 336 337#define VCPROP_TEMP_SOC 0 338 339struct vcprop_tag_temperature { 340 struct vcprop_tag tag; 341 uint32_t id; 342 uint32_t value; 343}; 344 345#define VCPROP_POWER_SDCARD 0 346#define VCPROP_POWER_UART0 1 347#define VCPROP_POWER_UART1 2 348#define VCPROP_POWER_USB 3 349#define VCPROP_POWER_I2C0 4 350#define VCPROP_POWER_I2C1 5 351#define VCPROP_POWER_I2C2 6 352#define VCPROP_POWER_SPI 7 353#define VCPROP_POWER_CCP2TX 8 354 355#define VCPROP_DOMAIN_I2C0 1 356#define VCPROP_DOMAIN_I2C1 2 357#define VCPROP_DOMAIN_I2C2 3 358#define VCPROP_DOMAIN_VIDEO_SCALER 4 359#define VCPROP_DOMAIN_VPU1 5 360#define VCPROP_DOMAIN_HDMI 6 361#define VCPROP_DOMAIN_USB 7 362#define VCPROP_DOMAIN_VEC 8 363#define VCPROP_DOMAIN_JPEG 9 364#define VCPROP_DOMAIN_H264 10 365#define VCPROP_DOMAIN_V3D 11 366#define VCPROP_DOMAIN_ISP 12 367#define VCPROP_DOMAIN_UNICAM0 13 368#define VCPROP_DOMAIN_UNICAM1 14 369#define VCPROP_DOMAIN_CCP2RX 15 370#define VCPROP_DOMAIN_CSI2 16 371#define VCPROP_DOMAIN_CPI 17 372#define VCPROP_DOMAIN_DSI0 18 373#define VCPROP_DOMAIN_DSI1 19 374#define VCPROP_DOMAIN_TRANSPOSER 20 375#define VCPROP_DOMAIN_CCP2TX 21 376#define VCPROP_DOMAIN_CDP 22 377#define VCPROP_DOMAIN_ARM 23 378 379struct vcprop_tag_powertiming { 380 struct vcprop_tag tag; 381 uint32_t id; 382 uint32_t waitusec; 383}; 384 385struct vcprop_tag_powerstate { 386 struct vcprop_tag tag; 387 uint32_t id; 388 uint32_t state; 389}; 390 391struct vcprop_tag_allocbuf { 392 struct vcprop_tag tag; 393 uint32_t address; /* alignment for request */ 394 uint32_t size; 395}; 396 397#define VCPROP_BLANK_OFF 0 398#define VCPROP_BLANK_ON 1 399 400struct vcprop_tag_blankscreen { 401 struct vcprop_tag tag; 402 uint32_t state; 403}; 404 405struct vcprop_tag_fbres { 406 struct vcprop_tag tag; 407 uint32_t width; 408 uint32_t height; 409}; 410 411struct vcprop_tag_fbdepth { 412 struct vcprop_tag tag; 413 uint32_t bpp; 414}; 415 416#define VCPROP_PIXEL_BGR 0 417#define VCPROP_PIXEL_RGB 1 418 419struct vcprop_tag_fbpixelorder { 420 struct vcprop_tag tag; 421 uint32_t order; 422}; 423 424struct vcprop_tag_fbpitch { 425 struct vcprop_tag tag; 426 uint32_t linebytes; 427}; 428 429#define VCPROP_ALPHA_ENABLED 0 430#define VCPROP_ALPHA_REVERSED 1 431#define VCPROP_ALPHA_IGNORED 2 432 433struct vcprop_tag_fbalpha { 434 struct vcprop_tag tag; 435 uint32_t state; 436}; 437 438struct vcprop_tag_edidblock { 439 struct vcprop_tag tag; 440 uint32_t blockno; 441 uint32_t status; 442 uint8_t data[128]; 443}; 444 445struct vcprop_tag_numdpy { 446 struct vcprop_tag tag; 447 uint32_t count; 448}; 449 450struct vcprop_tag_setdpy { 451 struct vcprop_tag tag; 452 uint32_t display_num; 453}; 454 455struct vcprop_tag_cursorinfo { 456 struct vcprop_tag tag; 457 uint32_t width; 458 uint32_t height; 459 uint32_t format; 460 uint32_t pixels; /* bus address in VC memory */ 461 uint32_t hotspot_x; 462 uint32_t hotspot_y; 463}; 464 465struct vcprop_tag_cursorstate { 466 struct vcprop_tag tag; 467 uint32_t enable; /* 1 - visible */ 468 uint32_t x; 469 uint32_t y; 470 uint32_t flags; /* 0 - display coord. 1 - fb coord. */ 471}; 472 473struct vcprop_tag_allocmem { 474 struct vcprop_tag tag; 475 uint32_t size; /* handle returned here */ 476 uint32_t align; 477 uint32_t flags; 478/* 479 * flag definitions from 480 * https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface 481 */ 482#define MEM_FLAG_DISCARDABLE (1 << 0) /* can be resized to 0 at any time. Use for cached data */ 483#define MEM_FLAG_NORMAL (0 << 2) /* normal allocating alias. Don't use from ARM */ 484#define MEM_FLAG_DIRECT (1 << 2) /* 0xC alias uncached */ 485#define MEM_FLAG_COHERENT (2 << 2) /* 0x8 alias. Non-allocating in L2 but coherent */ 486#define MEM_FLAG_L1_NONALLOCATING (MEM_FLAG_DIRECT | MEM_FLAG_COHERENT) /* Allocating in L2 */ 487#define MEM_FLAG_ZERO (1 << 4) /* initialise buffer to all zeros */ 488#define MEM_FLAG_NO_INIT (1 << 5) /* don't initialise (default is initialise to all ones */ 489#define MEM_FLAG_HINT_PERMALOCK (1 << 6) /* Likely to be locked for long periods of time. */ 490}; 491 492/* also for unlock and release */ 493struct vcprop_tag_lockmem { 494 struct vcprop_tag tag; 495 uint32_t handle; /* bus address returned here */ 496}; 497 498struct vcprop_tag_vchiqinit { 499 struct vcprop_tag tag; 500 uint32_t base; 501}; 502 503struct vcprop_tag_notifyxhcireset { 504 struct vcprop_tag tag; 505 uint32_t deviceaddress; 506}; 507 508struct vcprop_buffer_hdr { 509 uint32_t vpb_len; 510 uint32_t vpb_rcode; 511#define VCPROP_PROCESS_REQUEST 0 512#define VCPROP_REQ_SUCCESS (1U << 31) 513#define VCPROP_REQ_EPARSE (1U << 0) 514}; 515 516static inline bool 517vcprop_buffer_success_p(struct vcprop_buffer_hdr *vpbh) 518{ 519 520 return le32toh(vpbh->vpb_rcode) & VCPROP_REQ_SUCCESS; 521} 522 523static inline bool 524vcprop_tag_success_p(struct vcprop_tag *vpbt) 525{ 526 527 return le32toh(vpbt->vpt_rcode) & VCPROPTAG_RESPONSE; 528} 529 530static inline size_t 531vcprop_tag_resplen(struct vcprop_tag *vpbt) 532{ 533 534 return le32toh(vpbt->vpt_rcode) & ~VCPROPTAG_RESPONSE; 535} 536 537uint32_t rpi_alloc_mem(uint32_t, uint32_t, uint32_t); 538bus_addr_t rpi_lock_mem(uint32_t); 539int rpi_unlock_mem(uint32_t); 540int rpi_release_mem(uint32_t); 541 542int rpi_fb_set_video(int); 543 544int rpi_fb_movecursor(int, int, int); 545int rpi_fb_initcursor(bus_addr_t, int, int); 546 547int rpi_fb_set_pixelorder(uint32_t); 548int rpi_fb_get_pixelorder(uint32_t *); 549 550int rpi_set_domain(uint32_t, uint32_t); 551int rpi_get_domain(uint32_t, uint32_t *); 552 553int rpi_vchiq_init(uint32_t *); 554 555int rpi_notify_xhci_reset(uint32_t); 556 557#endif /* _EVBARM_RPI_VCPROP_H_ */ 558 559