xref: /illumos-gate/usr/src/boot/common/gfx_fb.h (revision 22028508)
19890ff83SToomas Soome /*
29890ff83SToomas Soome  * This file and its contents are supplied under the terms of the
39890ff83SToomas Soome  * Common Development and Distribution License ("CDDL"), version 1.0.
49890ff83SToomas Soome  * You may only use this file in accordance with the terms of version
59890ff83SToomas Soome  * 1.0 of the CDDL.
69890ff83SToomas Soome  *
79890ff83SToomas Soome  * A full copy of the text of the CDDL should have accompanied this
89890ff83SToomas Soome  * source.  A copy of the CDDL is also available via the Internet at
99890ff83SToomas Soome  * http://www.illumos.org/license/CDDL.
109890ff83SToomas Soome  */
119890ff83SToomas Soome 
129890ff83SToomas Soome /*
139890ff83SToomas Soome  * Copyright 2017 Toomas Soome <tsoome@me.com>
14d45f07cbSAndrew Stormont  * Copyright 2020 RackTop Systems, Inc.
159890ff83SToomas Soome  */
169890ff83SToomas Soome 
179890ff83SToomas Soome #ifndef _GFX_FB_H
189890ff83SToomas Soome #define	_GFX_FB_H
199890ff83SToomas Soome 
209890ff83SToomas Soome #include <stdbool.h>
219890ff83SToomas Soome #include <sys/visual_io.h>
229890ff83SToomas Soome #include <sys/multiboot2.h>
23d06ea0b9SToomas Soome #include <sys/queue.h>
249890ff83SToomas Soome #include <pnglite.h>
259890ff83SToomas Soome 
269890ff83SToomas Soome #ifdef __cplusplus
279890ff83SToomas Soome extern "C" {
289890ff83SToomas Soome #endif
299890ff83SToomas Soome 
309890ff83SToomas Soome #define	EDID_MAGIC	{ 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }
319890ff83SToomas Soome 
329890ff83SToomas Soome struct edid_header {
339890ff83SToomas Soome 	uint8_t header[8];	/* fixed header pattern */
349890ff83SToomas Soome 	uint16_t manufacturer_id;
359890ff83SToomas Soome 	uint16_t product_code;
369890ff83SToomas Soome 	uint32_t serial_number;
379890ff83SToomas Soome 	uint8_t week_of_manufacture;
389890ff83SToomas Soome 	uint8_t year_of_manufacture;
399890ff83SToomas Soome 	uint8_t version;
409890ff83SToomas Soome 	uint8_t revision;
419890ff83SToomas Soome };
429890ff83SToomas Soome 
439890ff83SToomas Soome struct edid_basic_display_parameters {
449890ff83SToomas Soome 	uint8_t video_input_parameters;
459890ff83SToomas Soome 	uint8_t max_horizontal_image_size;
469890ff83SToomas Soome 	uint8_t max_vertical_image_size;
479890ff83SToomas Soome 	uint8_t display_gamma;
489890ff83SToomas Soome 	uint8_t supported_features;
499890ff83SToomas Soome };
509890ff83SToomas Soome 
519890ff83SToomas Soome struct edid_chromaticity_coordinates {
529890ff83SToomas Soome 	uint8_t red_green_lo;
539890ff83SToomas Soome 	uint8_t blue_white_lo;
549890ff83SToomas Soome 	uint8_t red_x_hi;
559890ff83SToomas Soome 	uint8_t red_y_hi;
569890ff83SToomas Soome 	uint8_t green_x_hi;
579890ff83SToomas Soome 	uint8_t green_y_hi;
589890ff83SToomas Soome 	uint8_t blue_x_hi;
599890ff83SToomas Soome 	uint8_t blue_y_hi;
609890ff83SToomas Soome 	uint8_t white_x_hi;
619890ff83SToomas Soome 	uint8_t white_y_hi;
629890ff83SToomas Soome };
639890ff83SToomas Soome 
649890ff83SToomas Soome struct edid_detailed_timings {
659890ff83SToomas Soome 	uint16_t pixel_clock;
669890ff83SToomas Soome 	uint8_t horizontal_active_lo;
679890ff83SToomas Soome 	uint8_t horizontal_blanking_lo;
689890ff83SToomas Soome 	uint8_t horizontal_hi;
699890ff83SToomas Soome 	uint8_t vertical_active_lo;
709890ff83SToomas Soome 	uint8_t vertical_blanking_lo;
719890ff83SToomas Soome 	uint8_t vertical_hi;
729890ff83SToomas Soome 	uint8_t horizontal_sync_offset_lo;
739890ff83SToomas Soome 	uint8_t horizontal_sync_pulse_width_lo;
749890ff83SToomas Soome 	uint8_t vertical_sync_lo;
759890ff83SToomas Soome 	uint8_t sync_hi;
769890ff83SToomas Soome 	uint8_t horizontal_image_size_lo;
779890ff83SToomas Soome 	uint8_t vertical_image_size_lo;
789890ff83SToomas Soome 	uint8_t image_size_hi;
799890ff83SToomas Soome 	uint8_t horizontal_border;
809890ff83SToomas Soome 	uint8_t vertical_border;
819890ff83SToomas Soome 	uint8_t features;
829890ff83SToomas Soome };
839890ff83SToomas Soome 
849890ff83SToomas Soome struct vesa_edid_info {
859890ff83SToomas Soome 	struct edid_header header;
869890ff83SToomas Soome 	struct edid_basic_display_parameters display;
879890ff83SToomas Soome #define	EDID_FEATURE_PREFERRED_TIMING_MODE	(1 << 1)
889890ff83SToomas Soome 	struct edid_chromaticity_coordinates chromaticity;
899890ff83SToomas Soome 	uint8_t established_timings_1;
909890ff83SToomas Soome 	uint8_t established_timings_2;
919890ff83SToomas Soome 	uint8_t manufacturer_reserved_timings;
929890ff83SToomas Soome 	uint16_t standard_timings[8];
939890ff83SToomas Soome 	struct edid_detailed_timings detailed_timings[4];
949890ff83SToomas Soome 	uint8_t number_of_extensions;
959890ff83SToomas Soome 	uint8_t checksum;
969890ff83SToomas Soome } __packed;
979890ff83SToomas Soome 
981b1c4b08SToomas Soome extern struct vesa_edid_info *edid_info;
991b1c4b08SToomas Soome 
100d06ea0b9SToomas Soome #define	STD_TIMINGS	8
101d06ea0b9SToomas Soome #define	DET_TIMINGS	4
102d06ea0b9SToomas Soome 
103d06ea0b9SToomas Soome #define	HSIZE(x)	(((x & 0xff) + 31) * 8)
104d06ea0b9SToomas Soome #define	RATIO(x)	((x & 0xC000) >> 14)
105d06ea0b9SToomas Soome #define	RATIO1_1	0
106d06ea0b9SToomas Soome /* EDID Ver. 1.3 redefined this */
107d06ea0b9SToomas Soome #define	RATIO16_10	RATIO1_1
108d06ea0b9SToomas Soome #define	RATIO4_3	1
109d06ea0b9SToomas Soome #define	RATIO5_4	2
110d06ea0b9SToomas Soome #define	RATIO16_9	3
111d06ea0b9SToomas Soome 
1124d503977SToomas Soome /*
1134d503977SToomas Soome  * Number of pixels and lines is 12-bit int, valid values 0-4095.
1144d503977SToomas Soome  */
1154d503977SToomas Soome #define	EDID_MAX_PIXELS	4095
1164d503977SToomas Soome #define	EDID_MAX_LINES	4095
1174d503977SToomas Soome 
118b18a8f64SToomas Soome #define	GET_EDID_INFO_WIDTH(edid_info, timings_num) \
1194d503977SToomas Soome 	((edid_info)->detailed_timings[(timings_num)].horizontal_active_lo | \
1204d503977SToomas Soome 	(((uint_t)(edid_info)->detailed_timings[(timings_num)].horizontal_hi & \
1214d503977SToomas Soome 	0xf0) << 4))
122b18a8f64SToomas Soome 
123b18a8f64SToomas Soome #define	GET_EDID_INFO_HEIGHT(edid_info, timings_num) \
1244d503977SToomas Soome 	((edid_info)->detailed_timings[(timings_num)].vertical_active_lo | \
1254d503977SToomas Soome 	(((uint_t)(edid_info)->detailed_timings[(timings_num)].vertical_hi & \
1264d503977SToomas Soome 	0xf0) << 4))
127b18a8f64SToomas Soome 
128d06ea0b9SToomas Soome struct resolution {
129d06ea0b9SToomas Soome 	uint32_t width;
130d06ea0b9SToomas Soome 	uint32_t height;
131d06ea0b9SToomas Soome 	TAILQ_ENTRY(resolution) next;
132d06ea0b9SToomas Soome };
133d06ea0b9SToomas Soome 
134d06ea0b9SToomas Soome typedef TAILQ_HEAD(edid_resolution, resolution) edid_res_list_t;
135d06ea0b9SToomas Soome 
1369890ff83SToomas Soome extern multiboot_tag_framebuffer_t gfx_fb;
1379890ff83SToomas Soome 
1382d84dc94SToomas Soome typedef enum {
1392d84dc94SToomas Soome 	GfxFbBltVideoFill,
1402d84dc94SToomas Soome 	GfxFbBltVideoToBltBuffer,
1412d84dc94SToomas Soome 	GfxFbBltBufferToVideo,
1422d84dc94SToomas Soome 	GfxFbBltVideoToVideo,
1432d84dc94SToomas Soome 	GfxFbBltOperationMax,
1442d84dc94SToomas Soome } GFXFB_BLT_OPERATION;
1452d84dc94SToomas Soome 
1462d84dc94SToomas Soome int gfxfb_blt(void *, GFXFB_BLT_OPERATION, uint32_t, uint32_t,
1472d84dc94SToomas Soome     uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
1482d84dc94SToomas Soome 
149e0721d5aSToomas Soome void bios_text_font(bool);
150d06ea0b9SToomas Soome bool gfx_get_edid_resolution(struct vesa_edid_info *, edid_res_list_t *);
1512d84dc94SToomas Soome void gfx_framework_init(void);
1529890ff83SToomas Soome uint32_t gfx_fb_color_map(uint8_t);
1532d84dc94SToomas Soome int gfx_fb_cons_clear(struct vis_consclear *);
1542d84dc94SToomas Soome void gfx_fb_cons_copy(struct vis_conscopy *);
1552d84dc94SToomas Soome void gfx_fb_cons_display(struct vis_consdisplay *);
1569890ff83SToomas Soome void gfx_fb_display_cursor(struct vis_conscursor *);
1579890ff83SToomas Soome void gfx_fb_setpixel(uint32_t, uint32_t);
1589890ff83SToomas Soome void gfx_fb_drawrect(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
1599890ff83SToomas Soome void gfx_term_drawrect(uint32_t, uint32_t, uint32_t, uint32_t);
1609890ff83SToomas Soome void gfx_fb_line(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
1619890ff83SToomas Soome void gfx_fb_bezier(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t,
1629890ff83SToomas Soome 	uint32_t);
1639890ff83SToomas Soome void plat_cons_update_mode(int);
164d45f07cbSAndrew Stormont 
165d45f07cbSAndrew Stormont #define	FL_PUTIMAGE_BORDER	0x1
166d45f07cbSAndrew Stormont #define	FL_PUTIMAGE_NOSCROLL	0x2
167d45f07cbSAndrew Stormont #define	FL_PUTIMAGE_DEBUG	0x80
168d45f07cbSAndrew Stormont 
16909b64481SAndy Fiddaman int gfx_fb_putimage(png_t *, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
1709890ff83SToomas Soome 
1719890ff83SToomas Soome bool gfx_parse_mode_str(char *, int *, int *, int *);
17209b64481SAndy Fiddaman #ifdef __cplusplus
1739890ff83SToomas Soome }
1749890ff83SToomas Soome #endif
1759890ff83SToomas Soome 
17609b64481SAndy Fiddaman #endif /* _GFX_FB_H */
177