wsdisplay_vconsvar.h revision 1.34.6.1 1 /* $NetBSD: wsdisplay_vconsvar.h,v 1.34.6.1 2025/08/02 05:57:08 perseant 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 #include <dev/rasops/rasops.h>
40 #include <dev/wscons/wsdisplayvar.h>
41
42 struct vcons_data;
43
44 struct vcons_screen {
45 struct rasops_info scr_ri;
46 LIST_ENTRY(vcons_screen) next;
47 void *scr_cookie;
48 struct vcons_data *scr_vd;
49 struct vcons_data *scr_origvd;
50 struct wsscreen_descr *scr_type;
51 uint32_t *scr_chars;
52 long *scr_attrs;
53 void (*putchar)(void *, int, int, u_int, long);
54 long scr_defattr;
55 /* static flags set by the driver */
56 uint32_t scr_flags;
57 #define VCONS_NO_REDRAW 1 /* don't readraw in switch_screen */
58 #define VCONS_SCREEN_IS_STATIC 2 /* don't free() this vcons_screen */
59 #define VCONS_SWITCH_NEEDS_POLLING 4 /* rasops can overlap so we need to
60 * poll the busy flag when switching
61 * - for drivers that use software
62 * drawing */
63 #define VCONS_DONT_DRAW 8 /* don't draw on this screen at all */
64 /*
65 * the following flags are for drivers which either can't accelerate (all) copy
66 * operations or where drawing characters is faster than the blitter
67 * for example, Sun's Creator boards can't accelerate copycols()
68 */
69 #define VCONS_NO_COPYCOLS 0x10 /* use putchar() based copycols() */
70 #define VCONS_NO_COPYROWS 0x20 /* use putchar() based copyrows() */
71 #define VCONS_DONT_READ (VCONS_NO_COPYCOLS|VCONS_NO_COPYROWS|VCONS_NO_CURSOR)
72 /* avoid framebuffer reads */
73 #define VCONS_LOADFONT 0x40 /* driver can load_font() */
74 #define VCONS_NO_CURSOR 0x80 /* use putchar() based cursor(), to
75 * avoid fb reads */
76 #define VCONS_FONT_BITS_R2L 0x100 /* request right-to-left bitorder in
77 * wsfont_find() */
78 #define VCONS_FONT_BYTES_R2L 0x200 /* request right-to-left byteorder in
79 * wsfont_find() */
80
81 /* status flags used by vcons */
82 uint32_t scr_status;
83 #define VCONS_IS_VISIBLE 1 /* this screen is currently visible */
84 /* non zero when some rasops operation is in progress */
85 int scr_busy;
86 #ifdef WSDISPLAY_SCROLLSUPPORT
87 int scr_lines_in_buffer;
88 int scr_current_line;
89 int scr_line_wanted;
90 int scr_offset_to_zero;
91 int scr_current_offset;
92 #endif
93 #ifdef VCONS_DRAW_INTR
94 unsigned int scr_dirty;
95 #endif
96 };
97
98 #define SCREEN_IS_VISIBLE(scr) (((scr)->scr_status & VCONS_IS_VISIBLE) != 0)
99 #define SCREEN_IS_BUSY(scr) (membar_consumer(), (scr)->scr_busy != 0)
100 #define SCREEN_CAN_DRAW(scr) (((scr)->scr_flags & VCONS_DONT_DRAW) == 0)
101 #define SCREEN_BUSY(scr) ((scr)->scr_busy = 1, membar_producer())
102 #define SCREEN_IDLE(scr) ((scr)->scr_busy = 0, membar_producer())
103 #define SCREEN_VISIBLE(scr) ((scr)->scr_status |= VCONS_IS_VISIBLE)
104 #define SCREEN_INVISIBLE(scr) ((scr)->scr_status &= ~VCONS_IS_VISIBLE)
105 #define SCREEN_DISABLE_DRAWING(scr) ((scr)->scr_flags |= VCONS_DONT_DRAW)
106 #define SCREEN_ENABLE_DRAWING(scr) ((scr)->scr_flags &= ~VCONS_DONT_DRAW)
107
108 #define DEFATTR ((WS_DEFAULT_FG << 24) || (WS_DEFAULT_BG << 16))
109
110 struct vcons_data {
111 /* usually the drivers softc */
112 void *cookie;
113
114 /*
115 * setup the rasops part of the passed vcons_screen, like
116 * geometry, framebuffer address, font, characters, acceleration.
117 * we pass the cookie as 1st parameter
118 */
119 void (*init_screen)(void *, struct vcons_screen *, int,
120 long *);
121
122 /* called before vcons_redraw_screen */
123 void *show_screen_cookie;
124 void (*show_screen_cb)(struct vcons_screen *, void *);
125
126 struct vcons_screen *active;
127 struct vcons_data_private *private;
128 };
129
130 int vcons_init(struct vcons_data *, void *, struct wsscreen_descr *,
131 struct wsdisplay_accessops *);
132 int vcons_earlyinit(struct vcons_data *, void *, struct wsscreen_descr *,
133 struct wsdisplay_accessops *);
134
135 int vcons_init_screen(struct vcons_data *, struct vcons_screen *, int,
136 long *);
137
138 /* completely redraw the screen, clear it if RI_FULLCLEAR is set */
139 void vcons_redraw_screen(struct vcons_screen *);
140
141 void vcons_update_screen(struct vcons_screen *);
142
143 void vcons_replay_msgbuf(struct vcons_screen *);
144
145 void vcons_enable_polling(struct vcons_data *);
146 void vcons_disable_polling(struct vcons_data *);
147 void vcons_hard_switch(struct vcons_screen *);
148
149 int vcons_offset_to_zero(const struct vcons_screen *);
150
151 #endif /* _WSDISPLAY_VCONS_H_ */
152