wsdisplay_vconsvar.h revision 1.19 1 /* $NetBSD: wsdisplay_vconsvar.h,v 1.19 2011/05/25 06:01:38 macallan 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 #include "opt_wsdisplay_compat.h"
33 #include "opt_vcons.h"
34
35 struct vcons_data;
36
37 struct vcons_screen {
38 struct rasops_info scr_ri;
39 LIST_ENTRY(vcons_screen) next;
40 void *scr_cookie;
41 struct vcons_data *scr_vd;
42 struct vcons_data *scr_origvd;
43 const struct wsscreen_descr *scr_type;
44 uint16_t *scr_chars;
45 long *scr_attrs;
46 long scr_defattr;
47 /* static flags set by the driver */
48 uint32_t scr_flags;
49 #define VCONS_NO_REDRAW 1 /* don't readraw in switch_screen */
50 #define VCONS_SCREEN_IS_STATIC 2 /* don't free() this vcons_screen */
51 #define VCONS_SWITCH_NEEDS_POLLING 4 /* rasops can overlap so we need to
52 * poll the busy flag when switching
53 * - for drivers that use software
54 * drawing */
55 #define VCONS_DONT_DRAW 8 /* don't draw on this screen at all */
56 /*
57 * the following flags are for drivers which either can't accelerate (all) copy
58 * operations or where drawing characters is faster than the blitter
59 * for example, Sun's Creator boards can't accelerate copycols()
60 */
61 #define VCONS_NO_COPYCOLS 0x10 /* use putchar() based copycols() */
62 #define VCONS_NO_COPYROWS 0x20 /* use putchar() basec copyrows() */
63 #define VCONS_DONT_READ 0x30 /* avoid framebuffer reads */
64 /* status flags used by vcons */
65 uint32_t scr_status;
66 #define VCONS_IS_VISIBLE 1 /* this screen is currently visible */
67 /* non zero when some rasops operation is in progress */
68 int scr_busy;
69 #ifdef WSDISPLAY_SCROLLSUPPORT
70 int scr_lines_in_buffer;
71 int scr_current_line;
72 int scr_line_wanted;
73 int scr_offset_to_zero;
74 int scr_current_offset;
75 #endif
76 #ifdef VCONS_DRAW_INTR
77 unsigned int scr_dirty;
78 #endif
79 };
80
81 #define SCREEN_IS_VISIBLE(scr) (((scr)->scr_status & VCONS_IS_VISIBLE) != 0)
82 #define SCREEN_IS_BUSY(scr) ((scr)->scr_busy != 0)
83 #define SCREEN_CAN_DRAW(scr) (((scr)->scr_flags & VCONS_DONT_DRAW) == 0)
84 #define SCREEN_BUSY(scr) ((scr)->scr_busy = 1)
85 #define SCREEN_IDLE(scr) ((scr)->scr_busy = 0)
86 #define SCREEN_VISIBLE(scr) ((scr)->scr_status |= VCONS_IS_VISIBLE)
87 #define SCREEN_INVISIBLE(scr) ((scr)->scr_status &= ~VCONS_IS_VISIBLE)
88 #define SCREEN_DISABLE_DRAWING(scr) ((scr)->scr_flags |= VCONS_DONT_DRAW)
89 #define SCREEN_ENABLE_DRAWING(scr) ((scr)->scr_flags &= ~VCONS_DONT_DRAW)
90
91 struct vcons_data {
92 /* usually the drivers softc */
93 void *cookie;
94
95 /*
96 * setup the rasops part of the passed vcons_screen, like
97 * geometry, framebuffer address, font, characters, acceleration.
98 * we pass the cookie as 1st parameter
99 */
100 void (*init_screen)(void *, struct vcons_screen *, int,
101 long *);
102
103 /* accessops */
104 int (*ioctl)(void *, void *, u_long, void *, int, struct lwp *);
105
106 /* rasops */
107 void (*copycols)(void *, int, int, int, int);
108 void (*erasecols)(void *, int, int, int, long);
109 void (*copyrows)(void *, int, int, int);
110 void (*eraserows)(void *, int, int, long);
111 void (*putchar)(void *, int, int, u_int, long);
112 void (*cursor)(void *, int, int, int);
113 /* called before vcons_redraw_screen */
114 void (*show_screen_cb)(struct vcons_screen *);
115 /* virtual screen management stuff */
116 void (*switch_cb)(void *, int, int);
117 void *switch_cb_arg;
118 struct callout switch_callout;
119 uint32_t switch_pending;
120 LIST_HEAD(, vcons_screen) screens;
121 struct vcons_screen *active, *wanted;
122 const struct wsscreen_descr *currenttype;
123 int switch_poll_count;
124 #ifdef VCONS_DRAW_ASYNC
125 lwp_t *drawing_thread;
126 kmutex_t drawing_mutex;
127 kcondvar_t go_draw; /* wakeup the drawing thread */
128 kcondvar_t go_buffer; /* wakeup anyone waiting for room in the
129 * buffer */
130 kmutex_t go_draw_il, go_buffer_il; /* interlocks for above */
131 int use_async; /* use async drawing when non-zero */
132 #define VCONS_RING_BUFFER_LENGTH 2048
133 uint32_t rb_read; /* to be written by the drawing thread only */
134 uint32_t rb_write; /* written by the async drawing methods with
135 * drawing_mutex held */
136 uint32_t rb_buffer[VCONS_RING_BUFFER_LENGTH];
137 #endif
138 #ifdef VCONS_DRAW_INTR
139 int cells;
140 long *attrs;
141 uint16_t *chars;
142 int cursor_offset;
143 callout_t intr;
144 int intr_valid;
145 void *intr_softint;
146 int use_intr; /* use intr drawing when non-zero */
147 #endif
148 };
149
150 /*
151 * the ring buffer contains commands in the form:
152 * uint32_t command
153 * uint32_t parameters[]
154 * uint32_t command
155 * ...
156 * parameters are exactly what the corresponding rasops method would take as a
157 * series of uint32_ts, except for the cookie which is always assumed to be
158 * the active screen
159 * There should probably be a command to do vcons_redraw_screen() as a single
160 * operation, not a huge series of VCMD_PUTCHAR, Also, when we find a buffer
161 * with lots of commands in it we should probably ignore all VCMD_CURSOR except
162 * the first that removes the cursor and the last that draws it again
163 */
164
165 #define VCMD_COPYCOLS 0x80000001
166 #define VCMD_COPYROWS 0x80000002
167 #define VCMD_ERASECOLS 0x80000003
168 #define VCMD_ERASEROWS 0x80000004
169 #define VCMD_PUTCHAR 0x80000005
170 #define VCMD_CURSOR 0x80000006
171
172 int vcons_init(struct vcons_data *, void *cookie, struct wsscreen_descr *,
173 struct wsdisplay_accessops *);
174
175 int vcons_init_screen(struct vcons_data *, struct vcons_screen *, int,
176 long *);
177
178 /* completely redraw the screen, clear it if RI_FULLCLEAR is set */
179 void vcons_redraw_screen(struct vcons_screen *);
180
181 #ifdef VCONS_DRAW_INTR
182 /* redraw all dirty character cells */
183 void vcons_update_screen(struct vcons_screen *);
184 void vcons_invalidate_cache(struct vcons_data *);
185 #else
186 #define vcons_update_screen vcons_redraw_screen
187 #endif
188
189 void vcons_replay_msgbuf(struct vcons_screen *);
190
191 void vcons_enable_polling(struct vcons_data *);
192 void vcons_disable_polling(struct vcons_data *);
193 void vcons_hard_switch(struct vcons_screen *);
194
195 #endif /* _WSDISPLAY_VCONS_H_ */
196