xref: /illumos-gate/usr/src/boot/common/gfx_fb.h (revision 22028508fd28d36ff74dc02c5774a8ba1f0db045)
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 extern struct vesa_edid_info *edid_info;
99 
100 #define	STD_TIMINGS	8
101 #define	DET_TIMINGS	4
102 
103 #define	HSIZE(x)	(((x & 0xff) + 31) * 8)
104 #define	RATIO(x)	((x & 0xC000) >> 14)
105 #define	RATIO1_1	0
106 /* EDID Ver. 1.3 redefined this */
107 #define	RATIO16_10	RATIO1_1
108 #define	RATIO4_3	1
109 #define	RATIO5_4	2
110 #define	RATIO16_9	3
111 
112 /*
113  * Number of pixels and lines is 12-bit int, valid values 0-4095.
114  */
115 #define	EDID_MAX_PIXELS	4095
116 #define	EDID_MAX_LINES	4095
117 
118 #define	GET_EDID_INFO_WIDTH(edid_info, timings_num) \
119 	((edid_info)->detailed_timings[(timings_num)].horizontal_active_lo | \
120 	(((uint_t)(edid_info)->detailed_timings[(timings_num)].horizontal_hi & \
121 	0xf0) << 4))
122 
123 #define	GET_EDID_INFO_HEIGHT(edid_info, timings_num) \
124 	((edid_info)->detailed_timings[(timings_num)].vertical_active_lo | \
125 	(((uint_t)(edid_info)->detailed_timings[(timings_num)].vertical_hi & \
126 	0xf0) << 4))
127 
128 struct resolution {
129 	uint32_t width;
130 	uint32_t height;
131 	TAILQ_ENTRY(resolution) next;
132 };
133 
134 typedef TAILQ_HEAD(edid_resolution, resolution) edid_res_list_t;
135 
136 extern multiboot_tag_framebuffer_t gfx_fb;
137 
138 typedef enum {
139 	GfxFbBltVideoFill,
140 	GfxFbBltVideoToBltBuffer,
141 	GfxFbBltBufferToVideo,
142 	GfxFbBltVideoToVideo,
143 	GfxFbBltOperationMax,
144 } GFXFB_BLT_OPERATION;
145 
146 int gfxfb_blt(void *, GFXFB_BLT_OPERATION, uint32_t, uint32_t,
147     uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
148 
149 void bios_text_font(bool);
150 bool gfx_get_edid_resolution(struct vesa_edid_info *, edid_res_list_t *);
151 void gfx_framework_init(void);
152 uint32_t gfx_fb_color_map(uint8_t);
153 int gfx_fb_cons_clear(struct vis_consclear *);
154 void gfx_fb_cons_copy(struct vis_conscopy *);
155 void gfx_fb_cons_display(struct vis_consdisplay *);
156 void gfx_fb_display_cursor(struct vis_conscursor *);
157 void gfx_fb_setpixel(uint32_t, uint32_t);
158 void gfx_fb_drawrect(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
159 void gfx_term_drawrect(uint32_t, uint32_t, uint32_t, uint32_t);
160 void gfx_fb_line(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
161 void gfx_fb_bezier(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t,
162 	uint32_t);
163 void plat_cons_update_mode(int);
164 
165 #define	FL_PUTIMAGE_BORDER	0x1
166 #define	FL_PUTIMAGE_NOSCROLL	0x2
167 #define	FL_PUTIMAGE_DEBUG	0x80
168 
169 int gfx_fb_putimage(png_t *, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
170 
171 bool gfx_parse_mode_str(char *, int *, int *, int *);
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif /* _GFX_FB_H */
177