xref: /illumos-gate/usr/src/uts/common/sys/font.h (revision fa9eb222)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5fea9cb91Slq150181  * Common Development and Distribution License (the "License").
6fea9cb91Slq150181  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21fea9cb91Slq150181 
227c478bd9Sstevel@tonic-gate /*
23fea9cb91Slq150181  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
259c7c0c4bSToomas Soome  * Copyright 2019 Toomas Soome <tsoome@me.com>
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifndef _SYS_FONT_H
297c478bd9Sstevel@tonic-gate #define	_SYS_FONT_H
307c478bd9Sstevel@tonic-gate 
31cbc8e155SToomas Soome #include <sys/queue.h>
32cbc8e155SToomas Soome 
337c478bd9Sstevel@tonic-gate #ifdef __cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
37cbc8e155SToomas Soome enum vfnt_map {
38cbc8e155SToomas Soome 	VFNT_MAP_NORMAL = 0,	/* Normal font. */
39cbc8e155SToomas Soome 	VFNT_MAP_NORMAL_RH,	/* Normal font right hand. */
40cbc8e155SToomas Soome 	VFNT_MAP_BOLD,		/* Bold font. */
41cbc8e155SToomas Soome 	VFNT_MAP_BOLD_RH,	/* Bold font right hand. */
42cbc8e155SToomas Soome 	VFNT_MAPS		/* Number of maps. */
43cbc8e155SToomas Soome };
44898c3fecSToomas Soome 
45cbc8e155SToomas Soome /*
46cbc8e155SToomas Soome  * If the custom console font was loaded, pass it for kernel as a module.
47cbc8e155SToomas Soome  * We do not just load the font file, as the font file needs to be processed,
48cbc8e155SToomas Soome  * and the early boot has very little resources. So we just set up the
49cbc8e155SToomas Soome  * needed structures and make a copy of the byte arrays.
50cbc8e155SToomas Soome  *
51cbc8e155SToomas Soome  * Note we cannot copy the structures one to one due to the pointer size,
52cbc8e155SToomas Soome  * so we record the data by using fixed size structure.
53cbc8e155SToomas Soome  */
54cbc8e155SToomas Soome struct font_info {
55cbc8e155SToomas Soome 	int32_t fi_checksum;
56cbc8e155SToomas Soome 	uint32_t fi_width;
57cbc8e155SToomas Soome 	uint32_t fi_height;
58cbc8e155SToomas Soome 	uint32_t fi_bitmap_size;
59cbc8e155SToomas Soome 	uint32_t fi_map_count[VFNT_MAPS];
60cbc8e155SToomas Soome };
61cbc8e155SToomas Soome 
62cbc8e155SToomas Soome struct font_map {
63cbc8e155SToomas Soome 	uint32_t font_src;	/* Source glyph. */
64cbc8e155SToomas Soome 	uint16_t font_dst;	/* Target glyph. */
65cbc8e155SToomas Soome 	uint16_t font_len;	/* The number of glyphs in sequence. */
66cbc8e155SToomas Soome };
67cbc8e155SToomas Soome 
68cbc8e155SToomas Soome /* Any unknown glyph is mapped as first (offset 0) glyph in bitmap. */
697c478bd9Sstevel@tonic-gate struct font {
70cbc8e155SToomas Soome 	struct font_map	*vf_map[VFNT_MAPS];	/* Mapping tables. */
71cbc8e155SToomas Soome 	uint8_t		*vf_bytes;		/* Font bitmap data. */
72cbc8e155SToomas Soome 	uint32_t	vf_width;		/* Glyph width. */
73cbc8e155SToomas Soome 	uint32_t	vf_height;		/* Glyph height. */
74cbc8e155SToomas Soome 	uint32_t	vf_map_count[VFNT_MAPS];	/* Entries in map */
757c478bd9Sstevel@tonic-gate };
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate typedef	struct  bitmap_data {
78cbc8e155SToomas Soome 	uint32_t	width;
79cbc8e155SToomas Soome 	uint32_t	height;
80cbc8e155SToomas Soome 	uint32_t	compressed_size;
81cbc8e155SToomas Soome 	uint32_t	uncompressed_size;
82cbc8e155SToomas Soome 	uint8_t		*compressed_data;
83cbc8e155SToomas Soome 	struct font	*font;
847c478bd9Sstevel@tonic-gate } bitmap_data_t;
857c478bd9Sstevel@tonic-gate 
86cbc8e155SToomas Soome typedef enum {
87e0721d5aSToomas Soome 	FONT_AUTO,	/* This font is loaded by software */
88e0721d5aSToomas Soome 	FONT_MANUAL,	/* This font is loaded manually by user */
89e0721d5aSToomas Soome 	FONT_BOOT,	/* This font was passed to kernel by bootloader */
90e0721d5aSToomas Soome 	FONT_BUILTIN,	/* This font was built in at compile time */
91e0721d5aSToomas Soome 	FONT_RELOAD	/* This font is marked to be re-read from file */
92cbc8e155SToomas Soome } FONT_FLAGS;
93cbc8e155SToomas Soome 
947c478bd9Sstevel@tonic-gate struct fontlist {
95cbc8e155SToomas Soome 	char		*font_name;
96cbc8e155SToomas Soome 	FONT_FLAGS	font_flags;
97cbc8e155SToomas Soome 	bitmap_data_t	*font_data;
98cbc8e155SToomas Soome 	bitmap_data_t   *(*font_load)(char *);
99cbc8e155SToomas Soome 	STAILQ_ENTRY(fontlist) font_next;
1007c478bd9Sstevel@tonic-gate };
1017c478bd9Sstevel@tonic-gate 
102cbc8e155SToomas Soome #define	FONT_HEADER_MAGIC	"VFNT0002"
103cbc8e155SToomas Soome struct font_header {
104cbc8e155SToomas Soome 	uint8_t		fh_magic[8];
105cbc8e155SToomas Soome 	uint8_t		fh_width;
106cbc8e155SToomas Soome 	uint8_t		fh_height;
107cbc8e155SToomas Soome 	uint16_t	fh_pad;
108cbc8e155SToomas Soome 	uint32_t	fh_glyph_count;
109cbc8e155SToomas Soome 	uint32_t	fh_map_count[4];
110cbc8e155SToomas Soome } __attribute__((__packed__));
111898c3fecSToomas Soome 
112cbc8e155SToomas Soome typedef STAILQ_HEAD(font_list, fontlist) font_list_t;
113cbc8e155SToomas Soome extern font_list_t fonts;
114cbc8e155SToomas Soome 
115898c3fecSToomas Soome /*
116cbc8e155SToomas Soome  * Built in fonts. We are using Gallant as default on sparc to keep
117cbc8e155SToomas Soome  * smooth transition from prom and 8x16 on x86, for vga text mode.
118898c3fecSToomas Soome  */
119cbc8e155SToomas Soome #ifdef sparc
120cbc8e155SToomas Soome #define	DEFAULT_FONT_DATA	font_data_12x22
121898c3fecSToomas Soome extern bitmap_data_t font_data_12x22;
122cbc8e155SToomas Soome #else
123cbc8e155SToomas Soome #define	DEFAULT_FONT_DATA	font_data_8x16
124898c3fecSToomas Soome extern bitmap_data_t font_data_8x16;
125cbc8e155SToomas Soome #endif
126cbc8e155SToomas Soome #define	BORDER_PIXELS		10	/* space from screen border */
127898c3fecSToomas Soome 
128337411fcSToomas Soome void reset_font_flags(void);
129cbc8e155SToomas Soome bitmap_data_t *set_font(short *, short *, short, short);
130cbc8e155SToomas Soome const uint8_t *font_lookup(const struct font *, uint32_t);
131*fa9eb222SToomas Soome void font_bit_to_pix4(struct font *, uint8_t *, uint32_t, uint32_t, uint32_t);
132*fa9eb222SToomas Soome void font_bit_to_pix8(struct font *, uint8_t *, uint32_t, uint32_t, uint32_t);
133*fa9eb222SToomas Soome void font_bit_to_pix16(struct font *, uint16_t *, uint32_t, uint32_t, uint32_t);
1349c7c0c4bSToomas Soome void font_bit_to_pix24(struct font *, uint8_t *, uint32_t, uint32_t, uint32_t);
1359c7c0c4bSToomas Soome void font_bit_to_pix32(struct font *, uint32_t *, uint32_t, uint32_t, uint32_t);
136898c3fecSToomas Soome 
1377c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate #endif
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate #endif /* !_SYS_FONT_H */
142