wsdisplay_vconsvar.h revision 1.32 1 /* $NetBSD: wsdisplay_vconsvar.h,v 1.32 2022/07/17 10:28:09 riastradh Exp $ */
2
3 /*-
4 * Copyright (c) 2005, 2006 Michael Lorenz
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef _WSDISPLAY_VCONS_H_
30 #define _WSDISPLAY_VCONS_H_
31
32 #ifdef _KERNEL_OPT
33 #include "opt_wsdisplay_compat.h"
34 #include "opt_vcons.h"
35 #endif
36
37 #include <sys/atomic.h>
38
39 struct vcons_data;
40
41 struct vcons_screen {
42 struct rasops_info scr_ri;
43 LIST_ENTRY(vcons_screen) next;
44 void *scr_cookie;
45 struct vcons_data *scr_vd;
46 struct vcons_data *scr_origvd;
47 struct wsscreen_descr *scr_type;
48 uint32_t *scr_chars;
49 long *scr_attrs;
50 void (*putchar)(void *, int, int, u_int, long);
51 long scr_defattr;
52 /* static flags set by the driver */
53 uint32_t scr_flags;
54 #define VCONS_NO_REDRAW 1 /* don't readraw in switch_screen */
55 #define VCONS_SCREEN_IS_STATIC 2 /* don't free() this vcons_screen */
56 #define VCONS_SWITCH_NEEDS_POLLING 4 /* rasops can overlap so we need to
57 * poll the busy flag when switching
58 * - for drivers that use software
59 * drawing */
60 #define VCONS_DONT_DRAW 8 /* don't draw on this screen at all */
61 /*
62 * the following flags are for drivers which either can't accelerate (all) copy
63 * operations or where drawing characters is faster than the blitter
64 * for example, Sun's Creator boards can't accelerate copycols()
65 */
66 #define VCONS_NO_COPYCOLS 0x10 /* use putchar() based copycols() */
67 #define VCONS_NO_COPYROWS 0x20 /* use putchar() based copyrows() */
68 #define VCONS_DONT_READ (VCONS_NO_COPYCOLS|VCONS_NO_COPYROWS|VCONS_NO_CURSOR)
69 /* avoid framebuffer reads */
70 #define VCONS_LOADFONT 0x40 /* driver can load_font() */
71 #define VCONS_NO_CURSOR 0x80 /* use putchar() based cursor(), to
72 * avoid fb reads */
73 /* status flags used by vcons */
74 uint32_t scr_status;
75 #define VCONS_IS_VISIBLE 1 /* this screen is currently visible */
76 /* non zero when some rasops operation is in progress */
77 int scr_busy;
78 #ifdef WSDISPLAY_SCROLLSUPPORT
79 int scr_lines_in_buffer;
80 int scr_current_line;
81 int scr_line_wanted;
82 int scr_offset_to_zero;
83 int scr_current_offset;
84 #endif
85 #ifdef VCONS_DRAW_INTR
86 unsigned int scr_dirty;
87 #endif
88 };
89
90 #define SCREEN_IS_VISIBLE(scr) (((scr)->scr_status & VCONS_IS_VISIBLE) != 0)
91 #define SCREEN_IS_BUSY(scr) (membar_consumer(), (scr)->scr_busy != 0)
92 #define SCREEN_CAN_DRAW(scr) (((scr)->scr_flags & VCONS_DONT_DRAW) == 0)
93 #define SCREEN_BUSY(scr) ((scr)->scr_busy = 1, membar_producer())
94 #define SCREEN_IDLE(scr) ((scr)->scr_busy = 0, membar_producer())
95 #define SCREEN_VISIBLE(scr) ((scr)->scr_status |= VCONS_IS_VISIBLE)
96 #define SCREEN_INVISIBLE(scr) ((scr)->scr_status &= ~VCONS_IS_VISIBLE)
97 #define SCREEN_DISABLE_DRAWING(scr) ((scr)->scr_flags |= VCONS_DONT_DRAW)
98 #define SCREEN_ENABLE_DRAWING(scr) ((scr)->scr_flags &= ~VCONS_DONT_DRAW)
99
100 #define DEFATTR ((WS_DEFAULT_FG << 24) || (WS_DEFAULT_BG << 16))
101
102 struct vcons_data {
103 /* usually the drivers softc */
104 void *cookie;
105
106 /*
107 * setup the rasops part of the passed vcons_screen, like
108 * geometry, framebuffer address, font, characters, acceleration.
109 * we pass the cookie as 1st parameter
110 */
111 void (*init_screen)(void *, struct vcons_screen *, int,
112 long *);
113
114 /* accessops */
115 int (*ioctl)(void *, void *, u_long, void *, int, struct lwp *);
116
117 /* rasops */
118 void (*copycols)(void *, int, int, int, int);
119 void (*erasecols)(void *, int, int, int, long);
120 void (*copyrows)(void *, int, int, int);
121 void (*eraserows)(void *, int, int, long);
122 void (*cursor)(void *, int, int, int);
123 /* called before vcons_redraw_screen */
124 void *show_screen_cookie;
125 void (*show_screen_cb)(struct vcons_screen *, void *);
126 /* virtual screen management stuff */
127 void (*switch_cb)(void *, int, int);
128 void *switch_cb_arg;
129 struct callout switch_callout;
130 uint32_t switch_pending;
131 LIST_HEAD(, vcons_screen) screens;
132 struct vcons_screen *active, *wanted;
133 const struct wsscreen_descr *currenttype;
134 struct wsscreen_descr *defaulttype;
135 int switch_poll_count;
136 #ifdef VCONS_DRAW_INTR
137 int cells;
138 long *attrs;
139 uint32_t *chars;
140 int cursor_offset;
141 callout_t intr;
142 int intr_valid;
143 void *intr_softint;
144 int use_intr; /* use intr drawing when non-zero */
145 #endif
146 };
147
148 int vcons_init(struct vcons_data *, void *, struct wsscreen_descr *,
149 struct wsdisplay_accessops *);
150 int vcons_earlyinit(struct vcons_data *, void *, struct wsscreen_descr *,
151 struct wsdisplay_accessops *);
152
153 int vcons_init_screen(struct vcons_data *, struct vcons_screen *, int,
154 long *);
155
156 /* completely redraw the screen, clear it if RI_FULLCLEAR is set */
157 void vcons_redraw_screen(struct vcons_screen *);
158
159 #ifdef VCONS_DRAW_INTR
160 /* redraw all dirty character cells */
161 void vcons_update_screen(struct vcons_screen *);
162 void vcons_invalidate_cache(struct vcons_data *);
163 #else
164 #define vcons_update_screen vcons_redraw_screen
165 #endif
166
167 void vcons_replay_msgbuf(struct vcons_screen *);
168
169 void vcons_enable_polling(struct vcons_data *);
170 void vcons_disable_polling(struct vcons_data *);
171 void vcons_hard_switch(struct vcons_screen *);
172
173 static inline int
174 vcons_offset_to_zero(const struct vcons_screen *scr)
175 {
176 #ifdef WSDISPLAY_SCROLLSUPPORT
177 return scr->scr_offset_to_zero;
178 #else
179 return 0;
180 #endif
181 }
182
183 #endif /* _WSDISPLAY_VCONS_H_ */
184