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