xref: /illumos-gate/usr/src/boot/sys/boot/common/gfx_fb.h (revision 2d84dc94)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2017 Toomas Soome <tsoome@me.com>
14  * Copyright 2020 RackTop Systems, Inc.
15  */
16 
17 #ifndef _GFX_FB_H
18 #define	_GFX_FB_H
19 
20 #include <stdbool.h>
21 #include <sys/visual_io.h>
22 #include <sys/multiboot2.h>
23 #include <sys/queue.h>
24 #include <pnglite.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #define	EDID_MAGIC	{ 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }
31 
32 struct edid_header {
33 	uint8_t header[8];	/* fixed header pattern */
34 	uint16_t manufacturer_id;
35 	uint16_t product_code;
36 	uint32_t serial_number;
37 	uint8_t week_of_manufacture;
38 	uint8_t year_of_manufacture;
39 	uint8_t version;
40 	uint8_t revision;
41 };
42 
43 struct edid_basic_display_parameters {
44 	uint8_t video_input_parameters;
45 	uint8_t max_horizontal_image_size;
46 	uint8_t max_vertical_image_size;
47 	uint8_t display_gamma;
48 	uint8_t supported_features;
49 };
50 
51 struct edid_chromaticity_coordinates {
52 	uint8_t red_green_lo;
53 	uint8_t blue_white_lo;
54 	uint8_t red_x_hi;
55 	uint8_t red_y_hi;
56 	uint8_t green_x_hi;
57 	uint8_t green_y_hi;
58 	uint8_t blue_x_hi;
59 	uint8_t blue_y_hi;
60 	uint8_t white_x_hi;
61 	uint8_t white_y_hi;
62 };
63 
64 struct edid_detailed_timings {
65 	uint16_t pixel_clock;
66 	uint8_t horizontal_active_lo;
67 	uint8_t horizontal_blanking_lo;
68 	uint8_t horizontal_hi;
69 	uint8_t vertical_active_lo;
70 	uint8_t vertical_blanking_lo;
71 	uint8_t vertical_hi;
72 	uint8_t horizontal_sync_offset_lo;
73 	uint8_t horizontal_sync_pulse_width_lo;
74 	uint8_t vertical_sync_lo;
75 	uint8_t sync_hi;
76 	uint8_t horizontal_image_size_lo;
77 	uint8_t vertical_image_size_lo;
78 	uint8_t image_size_hi;
79 	uint8_t horizontal_border;
80 	uint8_t vertical_border;
81 	uint8_t features;
82 };
83 
84 struct vesa_edid_info {
85 	struct edid_header header;
86 	struct edid_basic_display_parameters display;
87 #define	EDID_FEATURE_PREFERRED_TIMING_MODE	(1 << 1)
88 	struct edid_chromaticity_coordinates chromaticity;
89 	uint8_t established_timings_1;
90 	uint8_t established_timings_2;
91 	uint8_t manufacturer_reserved_timings;
92 	uint16_t standard_timings[8];
93 	struct edid_detailed_timings detailed_timings[4];
94 	uint8_t number_of_extensions;
95 	uint8_t checksum;
96 } __packed;
97 
98 #define	STD_TIMINGS	8
99 #define	DET_TIMINGS	4
100 
101 #define	HSIZE(x)	(((x & 0xff) + 31) * 8)
102 #define	RATIO(x)	((x & 0xC000) >> 14)
103 #define	RATIO1_1	0
104 /* EDID Ver. 1.3 redefined this */
105 #define	RATIO16_10	RATIO1_1
106 #define	RATIO4_3	1
107 #define	RATIO5_4	2
108 #define	RATIO16_9	3
109 
110 /*
111  * Number of pixels and lines is 12-bit int, valid values 0-4095.
112  */
113 #define	EDID_MAX_PIXELS	4095
114 #define	EDID_MAX_LINES	4095
115 
116 #define	GET_EDID_INFO_WIDTH(edid_info, timings_num) \
117 	((edid_info)->detailed_timings[(timings_num)].horizontal_active_lo | \
118 	(((uint_t)(edid_info)->detailed_timings[(timings_num)].horizontal_hi & \
119 	0xf0) << 4))
120 
121 #define	GET_EDID_INFO_HEIGHT(edid_info, timings_num) \
122 	((edid_info)->detailed_timings[(timings_num)].vertical_active_lo | \
123 	(((uint_t)(edid_info)->detailed_timings[(timings_num)].vertical_hi & \
124 	0xf0) << 4))
125 
126 struct resolution {
127 	uint32_t width;
128 	uint32_t height;
129 	TAILQ_ENTRY(resolution) next;
130 };
131 
132 typedef TAILQ_HEAD(edid_resolution, resolution) edid_res_list_t;
133 
134 extern multiboot_tag_framebuffer_t gfx_fb;
135 
136 typedef enum {
137 	GfxFbBltVideoFill,
138 	GfxFbBltVideoToBltBuffer,
139 	GfxFbBltBufferToVideo,
140 	GfxFbBltVideoToVideo,
141 	GfxFbBltOperationMax,
142 } GFXFB_BLT_OPERATION;
143 
144 int gfxfb_blt(void *, GFXFB_BLT_OPERATION, uint32_t, uint32_t,
145     uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
146 
147 void bios_text_font(bool);
148 bool gfx_get_edid_resolution(struct vesa_edid_info *, edid_res_list_t *);
149 void gfx_framework_init(void);
150 uint32_t gfx_fb_color_map(uint8_t);
151 int gfx_fb_cons_clear(struct vis_consclear *);
152 void gfx_fb_cons_copy(struct vis_conscopy *);
153 void gfx_fb_cons_display(struct vis_consdisplay *);
154 void gfx_fb_display_cursor(struct vis_conscursor *);
155 void gfx_fb_setpixel(uint32_t, uint32_t);
156 void gfx_fb_drawrect(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
157 void gfx_term_drawrect(uint32_t, uint32_t, uint32_t, uint32_t);
158 void gfx_fb_line(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
159 void gfx_fb_bezier(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t,
160 	uint32_t);
161 void plat_cons_update_mode(int);
162 
163 #define	FL_PUTIMAGE_BORDER	0x1
164 #define	FL_PUTIMAGE_NOSCROLL	0x2
165 #define	FL_PUTIMAGE_DEBUG	0x80
166 
167 int gfx_fb_putimage(png_t *, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
168 
169 bool gfx_parse_mode_str(char *, int *, int *, int *);
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif /* _GFX_FB_H */
175