xref: /openbsd/sys/dev/rasops/rasops.h (revision c123c265)
1 /*	$OpenBSD: rasops.h,v 1.26 2023/02/03 18:32:31 miod Exp $ */
2 /* 	$NetBSD: rasops.h,v 1.13 2000/06/13 13:36:54 ad Exp $ */
3 
4 /*-
5  * Copyright (c) 1999 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Andrew Doran.
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  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef _RASOPS_H_
34 #define _RASOPS_H_ 1
35 
36 #include <sys/task.h>
37 
38 #ifdef	SMALL_KERNEL
39 #define	RASOPS_SMALL
40 #endif
41 
42 #include "rasops_glue.h"
43 
44 struct wsdisplay_font;
45 
46 /* For rasops_info::ri_flg */
47 #define RI_FULLCLEAR	0x0001	/* eraserows() hack to clear full screen */
48 #define RI_FORCEMONO	0x0002	/* monochrome output even if we can do color */
49 #define RI_BSWAP	0x0004	/* framebuffer endianness doesn't match CPU */
50 #define RI_CURSOR	0x0008	/* cursor is switched on */
51 #define RI_CLEAR	0x0010	/* clear display on startup */
52 #define	RI_CLEARMARGINS	0x0020	/* clear display margins on startup */
53 #define RI_CENTER	0x0040	/* center onscreen output */
54 #define RI_CURSORCLIP	0x0080	/* cursor is currently clipped */
55 #define RI_ROTATE_CW	0x0100	/* display is rotated, 90 deg clockwise */
56 #define RI_ROTATE_CCW	0x0200	/* display is rotated, 90 deg anti-clockwise */
57 #define RI_CFGDONE	0x0400	/* rasops_reconfig() completed successfully */
58 #define RI_VCONS	0x0800	/* virtual consoles */
59 #define RI_WRONLY	0x1000	/* avoid framebuffer reads */
60 
61 struct rasops_screen;
62 
63 struct rasops_info {
64 	/* These must be filled in by the caller */
65 	int	ri_depth;	/* depth in bits */
66 	u_char	*ri_bits;	/* ptr to bits */
67 	int	ri_width;	/* width (pels) */
68 	int	ri_height;	/* height (pels) */
69 	int	ri_stride;	/* stride in bytes */
70 
71 	/*
72 	 * These can optionally be left zeroed out. If you fill ri_font,
73 	 * but aren't using wsfont, set ri_wsfcookie to -1.
74 	 */
75 	struct	wsdisplay_font *ri_font;
76 	int	ri_wsfcookie;	/* wsfont cookie */
77 	void	*ri_hw;		/* driver private data; ignored by rasops */
78 	struct wsdisplay_charcell *ri_bs; /* character backing store */
79 	int	ri_crow;	/* cursor row */
80 	int	ri_ccol;	/* cursor column */
81 	int	ri_flg;		/* various operational flags */
82 
83 	/*
84 	 * These are optional and will default if zero. Meaningless
85 	 * on depths other than 15, 16, 24 and 32 bits per pel. On
86 	 * 24 bit displays, ri_{r,g,b}num must be 8.
87 	 */
88 	u_char	ri_rnum;	/* number of bits for red */
89 	u_char	ri_gnum;	/* number of bits for green */
90 	u_char	ri_bnum;	/* number of bits for blue */
91 	u_char	ri_rpos;	/* which bit red starts at */
92 	u_char	ri_gpos;	/* which bit green starts at */
93 	u_char	ri_bpos;	/* which bit blue starts at */
94 
95 	/* These are filled in by rasops_init() */
96 	int	ri_emuwidth;	/* width we actually care about */
97 	int	ri_emuheight;	/* height we actually care about */
98 	int	ri_emustride;	/* bytes per row we actually care about */
99 	int	ri_rows;	/* number of rows (characters, not pels) */
100 	int	ri_cols;	/* number of columns (characters, not pels) */
101 	int	ri_delta;	/* row delta in bytes */
102 	int	ri_pelbytes;	/* bytes per pel (may be zero) */
103 	int	ri_fontscale;	/* fontheight * fontstride */
104 	int	ri_xscale;	/* fontwidth * pelbytes */
105 	int	ri_yscale;	/* fontheight * stride */
106 	u_char  *ri_origbits;	/* where screen bits actually start */
107 	int	ri_xorigin;	/* where ri_bits begins (x) */
108 	int	ri_yorigin;	/* where ri_bits begins (y) */
109 	int32_t	ri_devcmap[16]; /* color -> framebuffer data */
110 
111 	/* The emulops you need to use, and the screen caps for wscons */
112 	struct	wsdisplay_emulops ri_ops;
113 	int	ri_caps;
114 
115 	/* Callbacks so we can share some code */
116 	int	(*ri_do_cursor)(struct rasops_info *);
117 	void	(*ri_updatecursor)(struct rasops_info *);
118 
119 #if NRASOPS_ROTATION > 0
120 	/* Used to intercept putchar to permit display rotation */
121 	struct	wsdisplay_emulops ri_real_ops;
122 #endif
123 
124 	int	ri_nscreens;
125 	LIST_HEAD(, rasops_screen) ri_screens;
126 	struct rasops_screen *ri_active;
127 
128 	void	(*ri_switchcb)(void *, int, int);
129 	void	*ri_switchcbarg;
130 	void	*ri_switchcookie;
131 	struct task ri_switchtask;
132 
133 	int	(*ri_putchar)(void *, int, int, u_int, uint32_t);
134 	int	(*ri_copycols)(void *, int, int, int, int);
135 	int	(*ri_erasecols)(void *, int, int, int, uint32_t);
136 	int	(*ri_copyrows)(void *, int, int, int);
137 	int	(*ri_eraserows)(void *, int, int, uint32_t);
138 	int	(*ri_pack_attr)(void *, int, int, int, uint32_t *);
139 };
140 
141 #define DELTA(p, d, cast) ((p) = (cast)((caddr_t)(p) + (d)))
142 
143 /*
144  * rasops_init().
145  *
146  * Integer parameters are the number of rows and columns we'd *like*.
147  *
148  * In terms of optimization, fonts that are a multiple of 8 pixels wide
149  * work the best.
150  *
151  * rasops_init() takes care of rasops_reconfig(). The parameters to both
152  * are the same. If calling rasops_reconfig() to change the font and
153  * ri_wsfcookie >= 0, you must call wsfont_unlock() on it, and reset it
154  * to -1 (or a new, valid cookie).
155  */
156 
157 /*
158  * Per-depth initialization functions. These should not be called outside
159  * the rasops code.
160  */
161 void	rasops1_init(struct rasops_info *);
162 void	rasops4_init(struct rasops_info *);
163 void	rasops8_init(struct rasops_info *);
164 void	rasops15_init(struct rasops_info *);
165 void	rasops24_init(struct rasops_info *);
166 void	rasops32_init(struct rasops_info *);
167 
168 /* rasops.c */
169 int	rasops_init(struct rasops_info *, int, int);
170 int	rasops_reconfig(struct rasops_info *, int, int);
171 int	rasops_eraserows(void *, int, int, uint32_t);
172 int	rasops_erasecols(void *, int, int, int, uint32_t);
173 
174 int	rasops_alloc_screen(void *, void **, int *, int *, uint32_t *);
175 void	rasops_free_screen(void *, void *);
176 int	rasops_show_screen(void *, void *, int,
177 	    void (*)(void *, int, int), void *);
178 int	rasops_load_font(void *, void *, struct wsdisplay_font *);
179 int	rasops_list_font(void *, struct wsdisplay_font *);
180 int	rasops_getchar(void *, int, int, struct wsdisplay_charcell *);
181 void	rasops_scrollback(void *, void *, int);
182 void	rasops_claim_framebuffer(paddr_t, psize_t, struct device *);
183 int	rasops_check_framebuffer(paddr_t);
184 
185 extern const u_char	rasops_cmap[256*3];
186 
187 #endif /* _RASOPS_H_ */
188