Home | History | Annotate | Line # | Download | only in pci
      1 /*	$NetBSD: veritefbio.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  * veritefb RISC debug ioctl interface.
     33  *
     34  * Only available in kernels built with the VERITEFB_DEBUG.
     35  */
     36 
     37 #ifndef VERITEFBIO_H
     38 #define VERITEFBIO_H
     39 
     40 #include <sys/ioccom.h>
     41 
     42 #define VERITEFB_DIAG_RING	16
     43 
     44 /* who owns the RISC (vd_owner; kernel uses the same values) */
     45 #define VERITEFB_OWNER_CONSOLE	0	/* 2D console microcode */
     46 #define VERITEFB_OWNER_PARKED	1	/* parked in the csucode monitor */
     47 #define VERITEFB_OWNER_FOREIGN	2	/* foreign (3D/GL) microcode */
     48 
     49 struct veritefb_dbg_diag {
     50 	uint32_t	vd_accel;	/* 0 off, 1 sw-degraded, 2 on */
     51 	uint32_t	vd_owner;	/* VERITEFB_OWNER_* */
     52 	uint32_t	vd_pc;		/* sampled RISC program counter */
     53 	uint32_t	vd_fifoinfree;
     54 	uint32_t	vd_fifooutvalid;
     55 	uint32_t	vd_debugreg;
     56 	uint32_t	vd_heartbeat;	/* 0 ok, 1 skipped, 2 failed */
     57 	uint32_t	vd_ringcount;	/* total FIFO words ever written */
     58 	uint32_t	vd_ring[VERITEFB_DIAG_RING]; /* newest last */
     59 };
     60 
     61 struct veritefb_dbg_rw {
     62 	uint32_t	vr_addr;	/* register index or address */
     63 	uint32_t	vr_val;
     64 };
     65 
     66 #define VERITEFB_DBG_DIAG	_IOR('V', 100, struct veritefb_dbg_diag)
     67 #define VERITEFB_DBG_HOLD	_IO('V', 101)
     68 #define VERITEFB_DBG_CONT	_IO('V', 102)
     69 #define VERITEFB_DBG_RDREG	_IOWR('V', 103, struct veritefb_dbg_rw)
     70 #define VERITEFB_DBG_RDMEM	_IOWR('V', 104, struct veritefb_dbg_rw)
     71 #define VERITEFB_DBG_FAULT	_IO('V', 105)	/* wedge on purpose */
     72 #define VERITEFB_DBG_RESET	_IOR('V', 106, int) /* reload + restart */
     73 
     74 /*
     75  * Accumulated per-op statistics.
     76  */
     77 struct veritefb_dbg_stats {
     78 	uint64_t	vs_count[16];
     79 	uint64_t	vs_us[16];
     80 };
     81 #define VFB_STAT_FILL		0	/* eraserows/erasecols */
     82 #define VFB_STAT_BLT		1	/* copyrows/copycols */
     83 #define VFB_STAT_CHAR_SPACE	2	/* putchar: space rectfill */
     84 #define VFB_STAT_CHAR_HIT	3	/* putchar: glyphcache hit */
     85 #define VFB_STAT_CHAR_ADD	4	/* putchar: SW render + cache add */
     86 #define VFB_STAT_CHAR_SW	5	/* putchar: SW fallback */
     87 #define VFB_STAT_SYNC		6	/* engine sync round-trips */
     88 /*
     89  * 3D path
     90  */
     91 #define VFB_STAT_V3D_SUBMIT	7	/* dma_submit body */
     92 #define VFB_STAT_V3D_SPIN	8	/* drain DMABusy wait only */
     93 #define VFB_STAT_V3D_SYNC	9	/* V3D_SYNC FIFO round-trip */
     94 #define VFB_STAT_V3D_FLIP	10	/* V3D_FLIP vsync wait only */
     95 #define VFB_STAT_V3D_BYTES	11	/* count += submitted bytes */
     96 #define VFB_STAT_V3D_DRAIN_BUSY	12	/* drain found master busy */
     97 #define VFB_STAT_V3D_DRAIN_IDLE	13	/* drain found master done */
     98 
     99 #define VERITEFB_DBG_STATS	_IOR('V', 108, struct veritefb_dbg_stats)
    100 #define VERITEFB_DBG_STATCLR	_IO('V', 109)
    101 
    102 /* raw byte access to the chip register window (offset < 0x100) */
    103 #define VERITEFB_DBG_IO_IOSPACE	0x1000	/* vr_addr flag: force the I/O BAR */
    104 #define VERITEFB_DBG_RDIO	_IOWR('V', 110, struct veritefb_dbg_rw)
    105 #define VERITEFB_DBG_WRIO	_IOW('V', 111, struct veritefb_dbg_rw)
    106 
    107 #define VERITEFB_DBG_SUSPEND2D	_IO('V', 112)
    108 #define VERITEFB_DBG_RESUME2D	_IO('V', 113)
    109 
    110 struct veritefb_dbg_ucload {
    111 	uint32_t	vu_size;	/* image size in bytes */
    112 	const void	*vu_data;	/* userland image pointer */
    113 	uint32_t	vu_entry;	/* out: entry point */
    114 };
    115 #define VERITEFB_DBG_UCLOAD	_IOWR('V', 114, struct veritefb_dbg_ucload)
    116 
    117 #define VFB_DBG_FIFO_MAX	16
    118 /* vf_setowner values: keep, or switch the recorded RISC owner */
    119 #define VERITEFB_SETOWNER_KEEP	0xffffffffU
    120 struct veritefb_dbg_fifowr {
    121 	uint32_t	vf_count;	/* 1..VFB_DBG_FIFO_MAX */
    122 	uint32_t	vf_setowner;	/* VERITEFB_OWNER_* or KEEP */
    123 	uint32_t	vf_words[VFB_DBG_FIFO_MAX];
    124 };
    125 #define VERITEFB_DBG_FIFOWR	_IOW('V', 115, struct veritefb_dbg_fifowr)
    126 
    127 struct veritefb_dbg_fiford {
    128 	uint32_t	vf_timo_us;	/* bounded wait; clamped by kernel */
    129 	uint32_t	vf_word;	/* out */
    130 };
    131 #define VERITEFB_DBG_FIFORD	_IOWR('V', 116, struct veritefb_dbg_fiford)
    132 
    133 /* 32-bit VRAM peek in [0, VFB_MC_SIZE), MEMENDIAN-stable */
    134 #define VERITEFB_DBG_RDVRAM	_IOWR('V', 117, struct veritefb_dbg_rw)
    135 
    136 /*
    137  * Scanout depth switch for 3D experiments: 8 (console) or 16 (565).
    138  * Only while the console microcode is parked; resume2d restores 8.
    139  */
    140 #define VERITEFB_DBG_SETDEPTH	_IOW('V', 118, uint32_t)
    141 
    142 /*
    143  * Bus-master into the input FIFO.
    144  */
    145 struct veritefb_dbg_dma {
    146 	uint64_t	vd_buf;		/* user buffer address */
    147 	uint32_t	vd_len;		/* bytes */
    148 	uint32_t	vd_swap;	/* 0..3 */
    149 };
    150 #define VERITEFB_DBG_DMASUBMIT	_IOW('V', 119, struct veritefb_dbg_dma)
    151 
    152 /*
    153  * RISC program-counter sampling profiler.
    154  */
    155 #define VFB_PCHIST_BUCKETS	512
    156 struct veritefb_dbg_pcsample {
    157 	uint32_t	vp_hz;		/* 0 stop; else clamped to [1, kern hz] */
    158 	uint32_t	vp_base;	/* PC of bucket 0 */
    159 	uint32_t	vp_shift;	/* PC units per bucket = 1 << vp_shift */
    160 };
    161 #define VERITEFB_DBG_PCSAMPLE	_IOW('V', 120, struct veritefb_dbg_pcsample)
    162 
    163 struct veritefb_dbg_pchist {
    164 	uint64_t	vp_samples;	/* total PC samples taken */
    165 	uint64_t	vp_missed;	/* samples outside the window */
    166 	uint32_t	vp_base;	/* echoed window base */
    167 	uint32_t	vp_shift;	/* echoed window shift */
    168 	uint32_t	vp_min;		/* lowest raw PC seen (~0u if none) */
    169 	uint32_t	vp_max;		/* highest raw PC seen */
    170 	uint32_t	vp_hist[VFB_PCHIST_BUCKETS];
    171 };
    172 #define VERITEFB_DBG_PCHIST	_IOR('V', 121, struct veritefb_dbg_pchist)
    173 
    174 #endif /* VERITEFBIO_H */
    175