1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software developed by the Computer Systems
8 * Engineering group at Lawrence Berkeley Laboratory under DARPA
9 * contract BG 91-66 and contributed to Berkeley.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #ifndef _SYS_FBIO_H_
37 #define _SYS_FBIO_H_
38
39 #ifndef _KERNEL
40 #include <sys/types.h>
41 #else
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/eventhandler.h>
45 #endif
46 #include <sys/ioccom.h>
47
48 /*
49 * Frame buffer ioctls (from Sprite, trimmed to essentials for X11).
50 */
51
52 /*
53 * Frame buffer type codes.
54 */
55 #define FBTYPE_SUN1BW 0 /* multibus mono */
56 #define FBTYPE_SUN1COLOR 1 /* multibus color */
57 #define FBTYPE_SUN2BW 2 /* memory mono */
58 #define FBTYPE_SUN2COLOR 3 /* color w/rasterop chips */
59 #define FBTYPE_SUN2GP 4 /* GP1/GP2 */
60 #define FBTYPE_SUN5COLOR 5 /* RoadRunner accelerator */
61 #define FBTYPE_SUN3COLOR 6 /* memory color */
62 #define FBTYPE_MEMCOLOR 7 /* memory 24-bit */
63 #define FBTYPE_SUN4COLOR 8 /* memory color w/overlay */
64
65 #define FBTYPE_NOTSUN1 9 /* reserved for customer */
66 #define FBTYPE_NOTSUN2 10 /* reserved for customer */
67 #define FBTYPE_PCIMISC 11 /* (generic) PCI misc. disp. */
68
69 #define FBTYPE_SUNFAST_COLOR 12 /* accelerated 8bit */
70 #define FBTYPE_SUNROP_COLOR 13 /* MEMCOLOR with rop h/w */
71 #define FBTYPE_SUNFB_VIDEO 14 /* Simple video mixing */
72 #define FBTYPE_RESERVED5 15 /* reserved, do not use */
73 #define FBTYPE_RESERVED4 16 /* reserved, do not use */
74 #define FBTYPE_SUNGP3 17
75 #define FBTYPE_SUNGT 18
76 #define FBTYPE_SUNLEO 19 /* zx Leo */
77
78 #define FBTYPE_MDA 20
79 #define FBTYPE_HERCULES 21
80 #define FBTYPE_CGA 22
81 #define FBTYPE_EGA 23
82 #define FBTYPE_VGA 24
83 #define FBTYPE_TGA 26
84 #define FBTYPE_TGA2 27
85
86 #define FBTYPE_MDICOLOR 28 /* cg14 */
87 #define FBTYPE_TCXCOLOR 29 /* SUNW,tcx */
88 #define FBTYPE_CREATOR 30
89
90 #define FBTYPE_EFIFB 31 /* EFI Graphical Output Protocol (GOP) */
91
92 #define FBTYPE_LASTPLUSONE 32 /* max number of fbs (change as add) */
93
94 /*
95 * Frame buffer descriptor as returned by FBIOGTYPE.
96 */
97 struct fbtype {
98 int fb_type; /* as defined above */
99 int fb_height; /* in pixels */
100 int fb_width; /* in pixels */
101 int fb_depth; /* bits per pixel */
102 int fb_cmsize; /* size of color map (entries) */
103 int fb_size; /* total size in bytes */
104 };
105 #define FBIOGTYPE _IOR('F', 0, struct fbtype)
106
107 #define FBTYPE_GET_STRIDE(_fb) ((_fb)->fb_size / (_fb)->fb_height)
108 #define FBTYPE_GET_BPP(_fb) ((_fb)->fb_bpp)
109 #define FBTYPE_GET_BYTESPP(_fb) ((_fb)->fb_bpp / 8)
110
111 /*
112 * RGB offsets as returned by FBIO_GETRGBOFFS.
113 */
114 struct fb_rgboffs {
115 int red;
116 int green;
117 int blue;
118 };
119
120 #ifdef _KERNEL
121
122 struct fb_info;
123
124 typedef int fb_enter_t(void *priv);
125 typedef int fb_leave_t(void *priv);
126 typedef int fb_setblankmode_t(void *priv, int mode);
127
128 struct fb_info {
129 /* Raw copy of fbtype. Do not change. */
130 int fb_type; /* as defined above */
131 int fb_height; /* in pixels */
132 int fb_width; /* in pixels */
133 int fb_depth; /* bits to define color */
134 int fb_cmsize; /* size of color map (entries) */
135 int fb_size; /* total size in bytes */
136
137 struct cdev *fb_cdev;
138
139 device_t fb_fbd_dev; /* "fbd" device. */
140 device_t fb_video_dev; /* Video adapter. */
141
142 fb_enter_t *enter;
143 fb_leave_t *leave;
144 fb_setblankmode_t *setblankmode;
145
146 vm_paddr_t fb_pbase; /* For FB mmap. */
147 vm_offset_t fb_vbase; /* if NULL, use fb_write/fb_read. */
148 void *fb_priv; /* First argument for read/write. */
149 const char *fb_name;
150 uint32_t fb_flags;
151 #define FB_FLAG_NOMMAP 1 /* mmap unsupported. */
152 #define FB_FLAG_NOWRITE 2 /* disable writes for the time being */
153 #define FB_FLAG_MEMATTR 4 /* override memattr for mmap */
154 vm_memattr_t fb_memattr;
155 int fb_stride;
156 int fb_bpp; /* bits per pixel */
157 uint32_t fb_cmap[16];
158
159 struct fb_rgboffs fb_rgboffs; /* RGB offsets */
160 };
161
162 int fbd_list(void);
163 int fbd_register(struct fb_info *);
164 int fbd_unregister(struct fb_info *);
165
166 static inline int
register_framebuffer(struct fb_info * info)167 register_framebuffer(struct fb_info *info)
168 {
169
170 EVENTHANDLER_INVOKE(register_framebuffer, info);
171 return (0);
172 }
173
174 static inline int
unregister_framebuffer(struct fb_info * info)175 unregister_framebuffer(struct fb_info *info)
176 {
177
178 EVENTHANDLER_INVOKE(unregister_framebuffer, info);
179 return (0);
180 }
181 #endif
182
183 /*
184 * Color map I/O.
185 */
186 struct fbcmap {
187 int index; /* first element (0 origin) */
188 int count; /* number of elements */
189 u_char *red; /* red color map elements */
190 u_char *green; /* green color map elements */
191 u_char *blue; /* blue color map elements */
192 };
193 #define FBIOPUTCMAP _IOW('F', 3, struct fbcmap)
194 #define FBIOGETCMAP _IOW('F', 4, struct fbcmap)
195
196 /* The new style frame buffer ioctls. */
197
198 /* video mode information block */
199 struct video_info {
200 int vi_mode; /* mode number, see below */
201 int vi_flags;
202 #define V_INFO_COLOR (1 << 0)
203 #define V_INFO_GRAPHICS (1 << 1)
204 #define V_INFO_LINEAR (1 << 2)
205 #define V_INFO_VESA (1 << 3)
206 #define V_INFO_NONVGA (1 << 4)
207 #define V_INFO_CWIDTH9 (1 << 5)
208 int vi_width;
209 int vi_height;
210 int vi_cwidth;
211 int vi_cheight;
212 int vi_depth;
213 int vi_planes;
214 vm_offset_t vi_window; /* physical address */
215 size_t vi_window_size;
216 size_t vi_window_gran;
217 vm_offset_t vi_buffer; /* physical address */
218 size_t vi_buffer_size;
219 int vi_mem_model;
220 #define V_INFO_MM_OTHER (-1)
221 #define V_INFO_MM_TEXT 0
222 #define V_INFO_MM_PLANAR 1
223 #define V_INFO_MM_PACKED 2
224 #define V_INFO_MM_DIRECT 3
225 #define V_INFO_MM_CGA 100
226 #define V_INFO_MM_HGC 101
227 #define V_INFO_MM_VGAX 102
228 /* for MM_PACKED and MM_DIRECT only */
229 int vi_pixel_size; /* in bytes */
230 /* for MM_DIRECT only */
231 int vi_pixel_fields[4]; /* RGB and reserved fields */
232 int vi_pixel_fsizes[4];
233 /* reserved */
234 u_char vi_reserved[64];
235 vm_offset_t vi_registers; /* physical address */
236 vm_offset_t vi_registers_size;
237 };
238 typedef struct video_info video_info_t;
239
240 /* adapter infromation block */
241 struct video_adapter {
242 int va_index;
243 int va_type;
244 #define KD_OTHER 0 /* unknown */
245 #define KD_MONO 1 /* monochrome adapter */
246 #define KD_HERCULES 2 /* hercules adapter */
247 #define KD_CGA 3 /* color graphics adapter */
248 #define KD_EGA 4 /* enhanced graphics adapter */
249 #define KD_VGA 5 /* video graphics adapter */
250 #define KD_TGA 7 /* TGA */
251 #define KD_TGA2 8 /* TGA2 */
252 char *va_name;
253 int va_unit;
254 int va_minor;
255 int va_flags;
256 #define V_ADP_COLOR (1 << 0)
257 #define V_ADP_MODECHANGE (1 << 1)
258 #define V_ADP_STATESAVE (1 << 2)
259 #define V_ADP_STATELOAD (1 << 3)
260 #define V_ADP_FONT (1 << 4)
261 #define V_ADP_PALETTE (1 << 5)
262 #define V_ADP_BORDER (1 << 6)
263 #define V_ADP_VESA (1 << 7)
264 #define V_ADP_BOOTDISPLAY (1 << 8)
265 #define V_ADP_PROBED (1 << 16)
266 #define V_ADP_INITIALIZED (1 << 17)
267 #define V_ADP_REGISTERED (1 << 18)
268 #define V_ADP_ATTACHED (1 << 19)
269 #define V_ADP_DAC8 (1 << 20)
270 #define V_ADP_CWIDTH9 (1 << 21)
271 vm_offset_t va_io_base;
272 int va_io_size;
273 vm_offset_t va_crtc_addr;
274 vm_offset_t va_mem_base;
275 int va_mem_size;
276 vm_offset_t va_window; /* virtual address */
277 size_t va_window_size;
278 size_t va_window_gran;
279 u_int va_window_orig;
280 vm_offset_t va_buffer; /* virtual address */
281 size_t va_buffer_size;
282 int va_initial_mode;
283 int va_initial_bios_mode;
284 int va_mode;
285 struct video_info va_info;
286 int va_line_width;
287 struct {
288 int x;
289 int y;
290 } va_disp_start;
291 void *va_token;
292 int va_model;
293 int va_little_bitian;
294 int va_little_endian;
295 int va_buffer_alias;
296 vm_offset_t va_registers; /* virtual address */
297 vm_offset_t va_registers_size;
298 };
299 typedef struct video_adapter video_adapter_t;
300
301 struct video_adapter_info {
302 int va_index;
303 int va_type;
304 char va_name[16];
305 int va_unit;
306 int va_flags;
307 vm_offset_t va_io_base;
308 int va_io_size;
309 vm_offset_t va_crtc_addr;
310 vm_offset_t va_mem_base;
311 int va_mem_size;
312 vm_offset_t va_window; /* virtual address */
313 size_t va_window_size;
314 size_t va_window_gran;
315 vm_offset_t va_unused0;
316 size_t va_buffer_size;
317 int va_initial_mode;
318 int va_initial_bios_mode;
319 int va_mode;
320 int va_line_width;
321 struct {
322 int x;
323 int y;
324 } va_disp_start;
325 u_int va_window_orig;
326 /* reserved */
327 u_char va_reserved[64];
328 };
329 typedef struct video_adapter_info video_adapter_info_t;
330
331 /* some useful video adapter index */
332 #define V_ADP_PRIMARY 0
333 #define V_ADP_SECONDARY 1
334
335 /* video mode numbers */
336
337 #define M_B40x25 0 /* black & white 40 columns */
338 #define M_C40x25 1 /* color 40 columns */
339 #define M_B80x25 2 /* black & white 80 columns */
340 #define M_C80x25 3 /* color 80 columns */
341 #define M_BG320 4 /* black & white graphics 320x200 */
342 #define M_CG320 5 /* color graphics 320x200 */
343 #define M_BG640 6 /* black & white graphics 640x200 hi-res */
344 #define M_EGAMONO80x25 7 /* ega-mono 80x25 */
345 #define M_CG320_D 13 /* ega mode D */
346 #define M_CG640_E 14 /* ega mode E */
347 #define M_EGAMONOAPA 15 /* ega mode F */
348 #define M_CG640x350 16 /* ega mode 10 */
349 #define M_ENHMONOAPA2 17 /* ega mode F with extended memory */
350 #define M_ENH_CG640 18 /* ega mode 10* */
351 #define M_ENH_B40x25 19 /* ega enhanced black & white 40 columns */
352 #define M_ENH_C40x25 20 /* ega enhanced color 40 columns */
353 #define M_ENH_B80x25 21 /* ega enhanced black & white 80 columns */
354 #define M_ENH_C80x25 22 /* ega enhanced color 80 columns */
355 #define M_VGA_C40x25 23 /* vga 8x16 font on color */
356 #define M_VGA_C80x25 24 /* vga 8x16 font on color */
357 #define M_VGA_M80x25 25 /* vga 8x16 font on mono */
358
359 #define M_VGA11 26 /* vga 640x480 2 colors */
360 #define M_BG640x480 26
361 #define M_VGA12 27 /* vga 640x480 16 colors */
362 #define M_CG640x480 27
363 #define M_VGA13 28 /* vga 320x200 256 colors */
364 #define M_VGA_CG320 28
365
366 #define M_VGA_C80x50 30 /* vga 8x8 font on color */
367 #define M_VGA_M80x50 31 /* vga 8x8 font on color */
368 #define M_VGA_C80x30 32 /* vga 8x16 font on color */
369 #define M_VGA_M80x30 33 /* vga 8x16 font on color */
370 #define M_VGA_C80x60 34 /* vga 8x8 font on color */
371 #define M_VGA_M80x60 35 /* vga 8x8 font on color */
372 #define M_VGA_CG640 36 /* vga 640x400 256 color */
373 #define M_VGA_MODEX 37 /* vga 320x240 256 color */
374
375 #define M_VGA_C90x25 40 /* vga 8x16 font on color */
376 #define M_VGA_M90x25 41 /* vga 8x16 font on mono */
377 #define M_VGA_C90x30 42 /* vga 8x16 font on color */
378 #define M_VGA_M90x30 43 /* vga 8x16 font on mono */
379 #define M_VGA_C90x43 44 /* vga 8x8 font on color */
380 #define M_VGA_M90x43 45 /* vga 8x8 font on mono */
381 #define M_VGA_C90x50 46 /* vga 8x8 font on color */
382 #define M_VGA_M90x50 47 /* vga 8x8 font on mono */
383 #define M_VGA_C90x60 48 /* vga 8x8 font on color */
384 #define M_VGA_M90x60 49 /* vga 8x8 font on mono */
385
386 #define M_ENH_B80x43 0x70 /* ega black & white 80x43 */
387 #define M_ENH_C80x43 0x71 /* ega color 80x43 */
388
389 #define M_HGC_P0 0xe0 /* hercules graphics - page 0 @ B0000 */
390 #define M_HGC_P1 0xe1 /* hercules graphics - page 1 @ B8000 */
391 #define M_MCA_MODE 0xff /* monochrome adapter mode */
392
393 #define M_TEXT_80x25 200 /* generic text modes */
394 #define M_TEXT_80x30 201
395 #define M_TEXT_80x43 202
396 #define M_TEXT_80x50 203
397 #define M_TEXT_80x60 204
398 #define M_TEXT_132x25 205
399 #define M_TEXT_132x30 206
400 #define M_TEXT_132x43 207
401 #define M_TEXT_132x50 208
402 #define M_TEXT_132x60 209
403
404 #define M_VESA_BASE 0x100 /* VESA mode number base */
405 #define M_VESA_CG640x400 0x100 /* 640x400, 256 color */
406 #define M_VESA_CG640x480 0x101 /* 640x480, 256 color */
407 #define M_VESA_800x600 0x102 /* 800x600, 16 color */
408 #define M_VESA_CG800x600 0x103 /* 800x600, 256 color */
409 #define M_VESA_1024x768 0x104 /* 1024x768, 16 color */
410 #define M_VESA_CG1024x768 0x105 /* 1024x768, 256 color */
411 #define M_VESA_1280x1024 0x106 /* 1280x1024, 16 color */
412 #define M_VESA_CG1280x1024 0x107 /* 1280x1024, 256 color */
413 #define M_VESA_C80x60 0x108 /* 8x8 font */
414 #define M_VESA_C132x25 0x109 /* 8x16 font */
415 #define M_VESA_C132x43 0x10a /* 8x14 font */
416 #define M_VESA_C132x50 0x10b /* 8x8 font */
417 #define M_VESA_C132x60 0x10c /* 8x8 font */
418 #define M_VESA_32K_320 0x10d /* 320x200, 5:5:5 */
419 #define M_VESA_64K_320 0x10e /* 320x200, 5:6:5 */
420 #define M_VESA_FULL_320 0x10f /* 320x200, 8:8:8 */
421 #define M_VESA_32K_640 0x110 /* 640x480, 5:5:5 */
422 #define M_VESA_64K_640 0x111 /* 640x480, 5:6:5 */
423 #define M_VESA_FULL_640 0x112 /* 640x480, 8:8:8 */
424 #define M_VESA_32K_800 0x113 /* 800x600, 5:5:5 */
425 #define M_VESA_64K_800 0x114 /* 800x600, 5:6:5 */
426 #define M_VESA_FULL_800 0x115 /* 800x600, 8:8:8 */
427 #define M_VESA_32K_1024 0x116 /* 1024x768, 5:5:5 */
428 #define M_VESA_64K_1024 0x117 /* 1024x768, 5:6:5 */
429 #define M_VESA_FULL_1024 0x118 /* 1024x768, 8:8:8 */
430 #define M_VESA_32K_1280 0x119 /* 1280x1024, 5:5:5 */
431 #define M_VESA_64K_1280 0x11a /* 1280x1024, 5:6:5 */
432 #define M_VESA_FULL_1280 0x11b /* 1280x1024, 8:8:8 */
433 #define M_VESA_MODE_MAX 0x1ff
434
435 struct video_display_start {
436 int x;
437 int y;
438 };
439 typedef struct video_display_start video_display_start_t;
440
441 struct video_color_palette {
442 int index; /* first element (zero-based) */
443 int count; /* number of elements */
444 u_char *red; /* red */
445 u_char *green; /* green */
446 u_char *blue; /* blue */
447 u_char *transparent; /* may be NULL */
448 };
449 typedef struct video_color_palette video_color_palette_t;
450
451 /* adapter info. */
452 #define FBIO_ADAPTER _IOR('F', 100, int)
453 #define FBIO_ADPTYPE _IOR('F', 101, int)
454 #define FBIO_ADPINFO _IOR('F', 102, struct video_adapter_info)
455
456 /* video mode control */
457 #define FBIO_MODEINFO _IOWR('F', 103, struct video_info)
458 #define FBIO_FINDMODE _IOWR('F', 104, struct video_info)
459 #define FBIO_GETMODE _IOR('F', 105, int)
460 #define FBIO_SETMODE _IOW('F', 106, int)
461
462 /* get/set frame buffer window origin */
463 #define FBIO_GETWINORG _IOR('F', 107, u_int)
464 #define FBIO_SETWINORG _IOW('F', 108, u_int)
465
466 /* get/set display start address */
467 #define FBIO_GETDISPSTART _IOR('F', 109, video_display_start_t)
468 #define FBIO_SETDISPSTART _IOW('F', 110, video_display_start_t)
469
470 /* get/set scan line width */
471 #define FBIO_GETLINEWIDTH _IOR('F', 111, u_int)
472 #define FBIO_SETLINEWIDTH _IOW('F', 112, u_int)
473
474 /* color palette control */
475 #define FBIO_GETPALETTE _IOW('F', 113, video_color_palette_t)
476 #define FBIO_SETPALETTE _IOW('F', 114, video_color_palette_t)
477
478 /* blank display */
479 #define V_DISPLAY_ON 0
480 #define V_DISPLAY_BLANK 1
481 #define V_DISPLAY_STAND_BY 2
482 #define V_DISPLAY_SUSPEND 3
483
484 #define FBIO_BLANK _IOW('F', 115, int)
485
486 /* get RGB offsets */
487 #define FBIO_GETRGBOFFS _IOR('F', 116, struct fb_rgboffs)
488
489 #endif /* !_SYS_FBIO_H_ */
490