1 /* $NetBSD: veritefb_ucode.h,v 1.2 2026/07/15 20:53:22 rkujawa Exp $ */ 2 3 /* 4 * Copyright (c) 2026 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Radoslaw Kujawa. 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 AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 /* 32 * Rendition Verite RISC and 2D microcode interface definitions. 33 * 34 * Command numbers are taken from the dispatch table extracted from the 35 * V2x00 2D microcode blob itself (v20002d.uc, dispatch table at 0x5140). 36 */ 37 38 #ifndef VERITEFB_UCODE_H 39 #define VERITEFB_UCODE_H 40 41 /* 42 * VRAM layout: the first VFB_MC_SIZE bytes are reserved for microcode, 43 * the framebuffer starts right after... 44 * 45 * The context-switch monitor (csucode) lives at VFB_CSUCODE_BASE. 46 */ 47 #define VFB_MC_SIZE 0x20000 48 #define VFB_CSUCODE_BASE 0x800 49 #define VFB_CSUCODE_SEM0 0x7f8 50 #define VFB_CSUCODE_SEM1 0x7fc 51 52 /* Per-slot load bounds for the two resident microcode images. */ 53 #define VFB_UC2D_LO 0x1000 /* 2D blob: link base 0x1000 */ 54 #define VFB_UC2D_HI VFB_UCF_BASE 55 #define VFB_UCF_BASE 0x8000 /* foreign 3D/GL slot */ 56 #define VFB_UCF_END 0x14000 /* v20003d data stash ends 0x13208 */ 57 #define VFB_CTX_BASE 0x14000 /* foreign context store area */ 58 #define VFB_CTX_SIZE 0x400 /* context store area */ 59 60 /* csucode monitor commands (first FIFO word after starting the monitor) */ 61 #define VFB_CSUCODE_INIT 0 /* a1=ctx store area, a2, entry */ 62 #define VFB_CSUCODE_RESUME 1 /* same args; ucode sees cmd in %128 */ 63 #define VFB_CSUCODE_PING 2 /* echoes 0x2 on the output FIFO */ 64 65 /* 66 * Host->RISC commands: 32-bit words into the input FIFO, 67 * command index in bits 15:0, first parameter in bits 31:16. 68 */ 69 #define VFB_CMDW(param, cmd) (((uint32_t)(uint16_t)(param) << 16) | \ 70 (uint16_t)(cmd)) 71 #define VFB_P2(x, y) VFB_CMDW(x, y) 72 73 #define VCMD_SUSPEND 0 /* park in the csucode monitor */ 74 #define VCMD_FILLRECTSOLID 1 /* prefer the ROP variant */ 75 #define VCMD_PIXENGSYNC 8 /* -> 0xffffffff in output FIFO */ 76 #define VCMD_GETPIXEL 9 /* P2(x,y) -> pixel in output FIFO */ 77 #define VCMD_SETSCREENINFO 10 78 #define VCMD_SCREENBLT 12 79 #define VCMD_MONOSOURCEBLT 22 80 #define VCMD_SETUP 32 /* 6 words total */ 81 #define VCMD_SETPALETTE 33 82 #define VCMD_SETPIXEL 34 83 #define VCMD_DRAWGLYPHS 35 84 #define VCMD_SETCLIPPING 36 85 #define VCMD_FILLRECTSOLIDROP 41 86 87 #define VFB_SYNC_TOKEN 0xffffffffU 88 89 /* 2D blob layout facts, for RISC program counter classification. */ 90 #define VFB_UC_BASE 0x1000 /* link base; dispatch loop here */ 91 #define VFB_UC_DISPATCH_END 0x101c /* end of the dispatch idle loop */ 92 #define VFB_UC_TRAP 0x1050 /* invalid-command self-branch */ 93 #define VFB_UC_TRAP_END 0x1058 /* including the delay slot */ 94 #define VFB_UC_END 0x5000 /* end of the command handlers */ 95 #define VFB_RISC_ROM_BASE 0xfffe0000 /* boot ROM, RISC view */ 96 97 /* DstMode for 2D: ALUMode in bits 3:0, other bits zero. */ 98 #define VFB_ROP_COPY 0xc 99 100 /* 101 * RISC register file indices and instruction encodings, for driving the 102 * processor through the STATEINDEX/STATEDATA debug port. 103 */ 104 #define VRISC_FLAG 37 /* flags register */ 105 #define VRISC_SP 252 /* stack pointer / scratch */ 106 #define VRISC_RA 254 /* link / scratch */ 107 #define VRISC_FP 255 /* frame pointer / scratch */ 108 109 #define VRISC_NOP 0x00000000 /* addi zero, zero, 0 */ 110 111 #define VRISC_ADDI_OP 0x00 112 #define VRISC_ADD_OP 0x10 113 #define VRISC_ANDN_OP 0x12 114 #define VRISC_OR_OP 0x15 115 #define VRISC_ADDIFI_OP 0x40 116 #define VRISC_ADDSL8_OP 0x4b 117 #define VRISC_SPRI_OP 0x4f 118 #define VRISC_JMP_OP 0x6c 119 #define VRISC_LB_OP 0x70 120 #define VRISC_LH_OP 0x71 121 #define VRISC_LW_OP 0x72 122 #define VRISC_LI_OP 0x76 123 #define VRISC_LUI_OP 0x77 124 #define VRISC_SB_OP 0x78 125 #define VRISC_SH_OP 0x79 126 #define VRISC_SW_OP 0x7a 127 128 #define VRISC_INT(op, d, s2, s1) \ 129 (((uint32_t)(op) << 24) | ((uint32_t)(d) << 16) | \ 130 ((uint32_t)(s2) << 8) | ((uint32_t)(s1) & 0xff)) 131 #define VRISC_LD(op, d, off8, s1) \ 132 (((uint32_t)(op) << 24) | ((uint32_t)(d) << 16) | \ 133 (((uint32_t)(off8) & 0xff) << 8) | ((uint32_t)(s1))) 134 #define VRISC_ST(op, off8, s2, s1) \ 135 (((uint32_t)(op) << 24) | (((uint32_t)(off8) & 0xff) << 16) | \ 136 ((uint32_t)(s2) << 8) | ((uint32_t)(s1))) 137 #define VRISC_LI(op, d, imm16) \ 138 (((uint32_t)(op) << 24) | ((uint32_t)(d) << 16) | \ 139 ((uint32_t)(imm16) & 0xffff)) 140 #define VRISC_JMP(addr24) \ 141 (((uint32_t)VRISC_JMP_OP << 24) | ((uint32_t)(addr24))) 142 143 /* Instruction cache */ 144 #define VRISC_ICACHESIZE 2048 145 #define VRISC_ICACHELINESIZE 32 146 #define VRISC_ICACHE_ONOFF_MASK (((uint32_t)1 << 17) | (1 << 3)) 147 148 /* 149 * Context-switch monitor microcode ("csucode") 150 */ 151 static const uint32_t veritefb_csucode[] = { 152 0x10802100, 0x5d808000, 0x4c808002, 0x6b820000, 153 0x00818002, 0x45818103, 0x10828281, 0x6f000082, 154 0x00000000, 0x62000500, 0x00000000, 0x62000300, 155 0x00000000, 0x62000800, 0x00000000, 0x10812100, 156 0x10822100, 0x10c02100, 0x6ffe00c0, 0x00000000, 157 0x62ffeb00, 0x00000000, 0x04812502, 0x61fffe81, 158 0x00000000, 0x10218000, 0x00000000, 0x00000000, 159 0x62ffe300, 0x00000000, 160 }; 161 162 #endif /* VERITEFB_UCODE_H */ 163