hpcfb.c revision 1.59 1 1.59 christos /* $NetBSD: hpcfb.c,v 1.59 2015/04/04 15:39:40 christos Exp $ */
2 1.1 uch
3 1.1 uch /*-
4 1.1 uch * Copyright (c) 1999
5 1.1 uch * Shin Takemura and PocketBSD Project. All rights reserved.
6 1.1 uch * Copyright (c) 2000,2001
7 1.1 uch * SATO Kazumi. All rights reserved.
8 1.1 uch *
9 1.1 uch * Redistribution and use in source and binary forms, with or without
10 1.1 uch * modification, are permitted provided that the following conditions
11 1.1 uch * are met:
12 1.1 uch * 1. Redistributions of source code must retain the above copyright
13 1.1 uch * notice, this list of conditions and the following disclaimer.
14 1.1 uch * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 uch * notice, this list of conditions and the following disclaimer in the
16 1.1 uch * documentation and/or other materials provided with the distribution.
17 1.1 uch * 3. All advertising materials mentioning features or use of this software
18 1.1 uch * must display the following acknowledgement:
19 1.1 uch * This product includes software developed by the PocketBSD project
20 1.1 uch * and its contributors.
21 1.1 uch * 4. Neither the name of the project nor the names of its contributors
22 1.1 uch * may be used to endorse or promote products derived from this software
23 1.1 uch * without specific prior written permission.
24 1.1 uch *
25 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.1 uch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.1 uch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.1 uch * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.1 uch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.1 uch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.1 uch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1 uch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1 uch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1 uch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1 uch * SUCH DAMAGE.
36 1.1 uch *
37 1.1 uch */
38 1.1 uch
39 1.1 uch /*
40 1.31 perry * jump scroll, scroll thread, multiscreen, virtual text vram
41 1.1 uch * and hpcfb_emulops functions
42 1.1 uch * written by SATO Kazumi.
43 1.1 uch */
44 1.1 uch
45 1.15 lukem #include <sys/cdefs.h>
46 1.59 christos __KERNEL_RCSID(0, "$NetBSD: hpcfb.c,v 1.59 2015/04/04 15:39:40 christos Exp $");
47 1.15 lukem
48 1.38 peter #ifdef _KERNEL_OPT
49 1.38 peter #include "opt_hpcfb.h"
50 1.38 peter #endif
51 1.1 uch
52 1.1 uch #include <sys/param.h>
53 1.1 uch #include <sys/systm.h>
54 1.1 uch #include <sys/kernel.h>
55 1.1 uch #include <sys/signalvar.h>
56 1.1 uch #include <sys/proc.h>
57 1.1 uch #include <sys/kthread.h>
58 1.1 uch #include <sys/device.h>
59 1.1 uch #include <sys/conf.h>
60 1.1 uch #include <sys/malloc.h>
61 1.1 uch #include <sys/buf.h>
62 1.1 uch #include <sys/ioctl.h>
63 1.1 uch
64 1.43 ad #include <sys/bus.h>
65 1.1 uch
66 1.1 uch #include <dev/wscons/wsconsio.h>
67 1.1 uch #include <dev/wscons/wsdisplayvar.h>
68 1.1 uch #include <dev/wscons/wscons_callbacks.h>
69 1.1 uch
70 1.1 uch #include <dev/wsfont/wsfont.h>
71 1.1 uch #include <dev/rasops/rasops.h>
72 1.1 uch
73 1.1 uch #include <dev/hpc/hpcfbvar.h>
74 1.1 uch #include <dev/hpc/hpcfbio.h>
75 1.1 uch
76 1.1 uch #include "bivideo.h"
77 1.1 uch #if NBIVIDEO > 0
78 1.1 uch #include <dev/hpc/bivideovar.h>
79 1.1 uch #endif
80 1.1 uch
81 1.1 uch #ifdef FBDEBUG
82 1.1 uch int hpcfb_debug = 0;
83 1.39 uwe #define DPRINTF(arg) if (hpcfb_debug) printf arg
84 1.1 uch #else
85 1.39 uwe #define DPRINTF(arg) do {} while (/* CONSTCOND */ 0)
86 1.1 uch #endif
87 1.1 uch
88 1.1 uch #ifndef HPCFB_MAX_COLUMN
89 1.1 uch #define HPCFB_MAX_COLUMN 130
90 1.1 uch #endif /* HPCFB_MAX_COLUMN */
91 1.1 uch #ifndef HPCFB_MAX_ROW
92 1.1 uch #define HPCFB_MAX_ROW 80
93 1.1 uch #endif /* HPCFB_MAX_ROW */
94 1.1 uch
95 1.1 uch /*
96 1.1 uch * currently experimental
97 1.1 uch #define HPCFB_JUMP
98 1.1 uch */
99 1.1 uch
100 1.1 uch struct hpcfb_vchar {
101 1.1 uch u_int c;
102 1.1 uch long attr;
103 1.1 uch };
104 1.1 uch
105 1.1 uch struct hpcfb_tvrow {
106 1.1 uch int maxcol;
107 1.1 uch int spacecol;
108 1.1 uch struct hpcfb_vchar col[HPCFB_MAX_COLUMN];
109 1.1 uch };
110 1.1 uch
111 1.1 uch struct hpcfb_devconfig {
112 1.9 toshii struct rasops_info dc_rinfo; /* rasops information */
113 1.1 uch
114 1.1 uch int dc_blanked; /* currently had video disabled */
115 1.1 uch struct hpcfb_softc *dc_sc;
116 1.1 uch int dc_rows;
117 1.1 uch int dc_cols;
118 1.1 uch struct hpcfb_tvrow *dc_tvram;
119 1.1 uch int dc_curx;
120 1.1 uch int dc_cury;
121 1.1 uch #ifdef HPCFB_JUMP
122 1.1 uch int dc_min_row;
123 1.1 uch int dc_max_row;
124 1.1 uch int dc_scroll;
125 1.1 uch struct callout dc_scroll_ch;
126 1.1 uch int dc_scroll_src;
127 1.1 uch int dc_scroll_dst;
128 1.1 uch int dc_scroll_num;
129 1.1 uch #endif /* HPCFB_JUMP */
130 1.1 uch volatile int dc_state;
131 1.1 uch #define HPCFB_DC_CURRENT 0x80000000
132 1.1 uch #define HPCFB_DC_DRAWING 0x01 /* drawing raster ops */
133 1.1 uch #define HPCFB_DC_TDRAWING 0x02 /* drawing tvram */
134 1.1 uch #define HPCFB_DC_SCROLLPENDING 0x04 /* scroll is pending */
135 1.1 uch #define HPCFB_DC_UPDATE 0x08 /* tvram update */
136 1.1 uch #define HPCFB_DC_SCRDELAY 0x10 /* scroll time but delay it */
137 1.1 uch #define HPCFB_DC_SCRTHREAD 0x20 /* in scroll thread or callout */
138 1.1 uch #define HPCFB_DC_UPDATEALL 0x40 /* need to redraw all */
139 1.1 uch #define HPCFB_DC_ABORT 0x80 /* abort redrawing */
140 1.12 sato #define HPCFB_DC_SWITCHREQ 0x100 /* switch request exist */
141 1.1 uch int dc_memsize;
142 1.1 uch u_char *dc_fbaddr;
143 1.1 uch };
144 1.1 uch
145 1.12 sato #define IS_DRAWABLE(dc) \
146 1.12 sato (((dc)->dc_state&HPCFB_DC_CURRENT)&& \
147 1.12 sato (((dc)->dc_state&(HPCFB_DC_DRAWING|HPCFB_DC_SWITCHREQ)) == 0))
148 1.12 sato
149 1.1 uch #define HPCFB_MAX_SCREEN 5
150 1.1 uch #define HPCFB_MAX_JUMP 5
151 1.1 uch
152 1.1 uch struct hpcfb_softc {
153 1.49 uwe device_t sc_dev;
154 1.1 uch struct hpcfb_devconfig *sc_dc; /* device configuration */
155 1.1 uch const struct hpcfb_accessops *sc_accessops;
156 1.1 uch void *sc_accessctx;
157 1.49 uwe device_t sc_wsdisplay;
158 1.1 uch int sc_screen_resumed;
159 1.1 uch int sc_polling;
160 1.1 uch int sc_mapping;
161 1.1 uch struct proc *sc_thread;
162 1.1 uch void *sc_wantedscreen;
163 1.4 uch void (*sc_switchcb)(void *, int, int);
164 1.1 uch void *sc_switchcbarg;
165 1.1 uch struct callout sc_switch_callout;
166 1.10 takemura int sc_nfbconf;
167 1.10 takemura struct hpcfb_fbconf *sc_fbconflist;
168 1.1 uch };
169 1.1 uch
170 1.1 uch /*
171 1.1 uch * function prototypes
172 1.1 uch */
173 1.49 uwe int hpcfbmatch(device_t, cfdata_t, void *);
174 1.49 uwe void hpcfbattach(device_t, device_t, void *);
175 1.4 uch int hpcfbprint(void *, const char *);
176 1.4 uch
177 1.41 christos int hpcfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
178 1.36 jmmv paddr_t hpcfb_mmap(void *, void *, off_t, int);
179 1.4 uch
180 1.4 uch void hpcfb_refresh_screen(struct hpcfb_softc *);
181 1.4 uch void hpcfb_doswitch(struct hpcfb_softc *);
182 1.4 uch
183 1.4 uch #ifdef HPCFB_JUMP
184 1.4 uch static void hpcfb_thread(void *);
185 1.4 uch #endif /* HPCFB_JUMP */
186 1.4 uch
187 1.4 uch static int hpcfb_init(struct hpcfb_fbconf *, struct hpcfb_devconfig *);
188 1.4 uch static int hpcfb_alloc_screen(void *, const struct wsscreen_descr *,
189 1.4 uch void **, int *, int *, long *);
190 1.4 uch static void hpcfb_free_screen(void *, void *);
191 1.4 uch static int hpcfb_show_screen(void *, void *, int,
192 1.4 uch void (*) (void *, int, int), void *);
193 1.4 uch static void hpcfb_pollc(void *, int);
194 1.4 uch static void hpcfb_cmap_reorder(struct hpcfb_fbconf *,
195 1.4 uch struct hpcfb_devconfig *);
196 1.4 uch
197 1.50 uwe static void hpcfb_power(int, void *);
198 1.53 dyoung static bool hpcfb_suspend(device_t, const pmf_qual_t *);
199 1.53 dyoung static bool hpcfb_resume(device_t, const pmf_qual_t *);
200 1.50 uwe
201 1.50 uwe
202 1.4 uch void hpcfb_cursor(void *, int, int, int);
203 1.4 uch int hpcfb_mapchar(void *, int, unsigned int *);
204 1.4 uch void hpcfb_putchar(void *, int, int, u_int, long);
205 1.4 uch void hpcfb_copycols(void *, int, int, int, int);
206 1.4 uch void hpcfb_erasecols(void *, int, int, int, long);
207 1.4 uch void hpcfb_redraw(void *, int, int, int);
208 1.4 uch void hpcfb_copyrows(void *, int, int, int);
209 1.4 uch void hpcfb_eraserows(void *, int, int, long);
210 1.21 junyoung int hpcfb_allocattr(void *, int, int, int, long *);
211 1.4 uch void hpcfb_cursor_raw(void *, int, int, int);
212 1.4 uch
213 1.4 uch #ifdef HPCFB_JUMP
214 1.4 uch void hpcfb_update(void *);
215 1.4 uch void hpcfb_do_scroll(void *);
216 1.4 uch void hpcfb_check_update(void *);
217 1.1 uch #endif /* HPCFB_JUMP */
218 1.1 uch
219 1.1 uch struct wsdisplay_emulops hpcfb_emulops = {
220 1.39 uwe .cursor = hpcfb_cursor,
221 1.39 uwe .mapchar = hpcfb_mapchar,
222 1.39 uwe .putchar = hpcfb_putchar,
223 1.39 uwe .copycols = hpcfb_copycols,
224 1.39 uwe .erasecols = hpcfb_erasecols,
225 1.39 uwe .copyrows = hpcfb_copyrows,
226 1.39 uwe .eraserows = hpcfb_eraserows,
227 1.39 uwe .allocattr = hpcfb_allocattr,
228 1.39 uwe .replaceattr = NULL,
229 1.1 uch };
230 1.1 uch
231 1.1 uch /*
232 1.1 uch * static variables
233 1.1 uch */
234 1.49 uwe CFATTACH_DECL_NEW(hpcfb, sizeof(struct hpcfb_softc),
235 1.27 thorpej hpcfbmatch, hpcfbattach, NULL, NULL);
236 1.1 uch
237 1.1 uch struct wsscreen_descr hpcfb_stdscreen = {
238 1.39 uwe .name = "std",
239 1.39 uwe .textops = &hpcfb_emulops, /* XXX */
240 1.39 uwe .capabilities = WSSCREEN_REVERSE,
241 1.39 uwe /* XXX: ncols/nrows will be filled in -- shouldn't, they are global */
242 1.1 uch };
243 1.1 uch
244 1.1 uch const struct wsscreen_descr *_hpcfb_scrlist[] = {
245 1.1 uch &hpcfb_stdscreen,
246 1.1 uch /* XXX other formats, graphics screen? */
247 1.1 uch };
248 1.1 uch
249 1.1 uch struct wsscreen_list hpcfb_screenlist = {
250 1.39 uwe .nscreens = __arraycount(_hpcfb_scrlist),
251 1.39 uwe .screens = _hpcfb_scrlist,
252 1.1 uch };
253 1.1 uch
254 1.1 uch struct wsdisplay_accessops hpcfb_accessops = {
255 1.39 uwe .ioctl = hpcfb_ioctl,
256 1.39 uwe .mmap = hpcfb_mmap,
257 1.39 uwe .alloc_screen = hpcfb_alloc_screen,
258 1.39 uwe .free_screen = hpcfb_free_screen,
259 1.39 uwe .show_screen = hpcfb_show_screen,
260 1.39 uwe .load_font = NULL,
261 1.39 uwe .pollc = hpcfb_pollc,
262 1.39 uwe .scroll = NULL,
263 1.1 uch };
264 1.1 uch
265 1.4 uch void hpcfb_tv_putchar(struct hpcfb_devconfig *, int, int, u_int, long);
266 1.4 uch void hpcfb_tv_copycols(struct hpcfb_devconfig *, int, int, int, int);
267 1.4 uch void hpcfb_tv_erasecols(struct hpcfb_devconfig *, int, int, int, long);
268 1.4 uch void hpcfb_tv_copyrows(struct hpcfb_devconfig *, int, int, int);
269 1.4 uch void hpcfb_tv_eraserows(struct hpcfb_devconfig *, int, int, long);
270 1.1 uch
271 1.1 uch struct wsdisplay_emulops rasops_emul;
272 1.1 uch
273 1.1 uch static int hpcfbconsole;
274 1.1 uch struct hpcfb_devconfig hpcfb_console_dc;
275 1.1 uch struct wsscreen_descr hpcfb_console_wsscreen;
276 1.1 uch struct hpcfb_tvrow hpcfb_console_tvram[HPCFB_MAX_ROW];
277 1.1 uch
278 1.1 uch /*
279 1.1 uch * function bodies
280 1.1 uch */
281 1.1 uch
282 1.1 uch int
283 1.49 uwe hpcfbmatch(device_t parent, cfdata_t match, void *aux)
284 1.1 uch {
285 1.1 uch return (1);
286 1.1 uch }
287 1.1 uch
288 1.1 uch void
289 1.49 uwe hpcfbattach(device_t parent, device_t self, void *aux)
290 1.1 uch {
291 1.49 uwe struct hpcfb_softc *sc;
292 1.1 uch struct hpcfb_attach_args *ha = aux;
293 1.1 uch struct wsemuldisplaydev_attach_args wa;
294 1.1 uch
295 1.49 uwe sc = device_private(self);
296 1.49 uwe sc->sc_dev = self;
297 1.49 uwe
298 1.1 uch sc->sc_accessops = ha->ha_accessops;
299 1.1 uch sc->sc_accessctx = ha->ha_accessctx;
300 1.10 takemura sc->sc_nfbconf = ha->ha_nfbconf;
301 1.10 takemura sc->sc_fbconflist = ha->ha_fbconflist;
302 1.1 uch
303 1.1 uch if (hpcfbconsole) {
304 1.10 takemura sc->sc_dc = &hpcfb_console_dc;
305 1.55 tsutsui sc->sc_dc->dc_rinfo.ri_flg &= ~RI_NO_AUTO;
306 1.1 uch hpcfb_console_dc.dc_sc = sc;
307 1.10 takemura printf(": %dx%d pixels, %d colors, %dx%d chars",
308 1.10 takemura sc->sc_dc->dc_rinfo.ri_width,sc->sc_dc->dc_rinfo.ri_height,
309 1.26 reinoud (1 << sc->sc_dc->dc_rinfo.ri_depth),
310 1.10 takemura sc->sc_dc->dc_rinfo.ri_cols,sc->sc_dc->dc_rinfo.ri_rows);
311 1.10 takemura /* Set video chip dependent CLUT if any. */
312 1.10 takemura if (sc->sc_accessops->setclut)
313 1.31 perry sc->sc_accessops->setclut(sc->sc_accessctx,
314 1.10 takemura &hpcfb_console_dc.dc_rinfo);
315 1.1 uch }
316 1.10 takemura printf("\n");
317 1.10 takemura
318 1.1 uch sc->sc_polling = 0; /* XXX */
319 1.1 uch sc->sc_mapping = 0; /* XXX */
320 1.42 ad callout_init(&sc->sc_switch_callout, 0);
321 1.1 uch
322 1.1 uch wa.console = hpcfbconsole;
323 1.1 uch wa.scrdata = &hpcfb_screenlist;
324 1.1 uch wa.accessops = &hpcfb_accessops;
325 1.1 uch wa.accesscookie = sc;
326 1.1 uch
327 1.1 uch sc->sc_wsdisplay = config_found(self, &wa, wsemuldisplaydevprint);
328 1.1 uch
329 1.1 uch #ifdef HPCFB_JUMP
330 1.1 uch /*
331 1.1 uch * Create a kernel thread to scroll,
332 1.1 uch */
333 1.42 ad if (kthread_create(PRI_NONE, 0, NULL, hpcfb_thread, sc,
334 1.49 uwe &sc->sc_thread, "%s", device_xname(sc->sc_dev)) != 0) {
335 1.42 ad /*
336 1.42 ad * We were unable to create the HPCFB thread; bail out.
337 1.42 ad */
338 1.42 ad sc->sc_thread = 0;
339 1.49 uwe aprint_error_dev(sc->sc_dev, "unable to create thread, kernel "
340 1.47 cegger "hpcfb scroll support disabled\n");
341 1.42 ad }
342 1.1 uch #endif /* HPCFB_JUMP */
343 1.50 uwe
344 1.50 uwe if (!pmf_device_register(self, hpcfb_suspend, hpcfb_resume))
345 1.50 uwe aprint_error_dev(self, "unable to establish power handler\n");
346 1.1 uch }
347 1.1 uch
348 1.1 uch #ifdef HPCFB_JUMP
349 1.1 uch void
350 1.4 uch hpcfb_thread(void *arg)
351 1.1 uch {
352 1.1 uch struct hpcfb_softc *sc = arg;
353 1.1 uch
354 1.1 uch /*
355 1.1 uch * Loop forever, doing a periodic check for update events.
356 1.1 uch */
357 1.1 uch for (;;) {
358 1.1 uch /* HPCFB_LOCK(sc); */
359 1.31 perry sc->sc_dc->dc_state |= HPCFB_DC_SCRTHREAD;
360 1.1 uch if (!sc->sc_mapping) /* draw only EMUL mode */
361 1.1 uch hpcfb_update(sc->sc_dc);
362 1.31 perry sc->sc_dc->dc_state &= ~HPCFB_DC_SCRTHREAD;
363 1.1 uch /* APM_UNLOCK(sc); */
364 1.1 uch (void) tsleep(sc, PWAIT, "hpcfb", (8 * hz) / 7 / 10);
365 1.1 uch }
366 1.1 uch }
367 1.1 uch #endif /* HPCFB_JUMP */
368 1.1 uch
369 1.1 uch /* Print function (for parent devices). */
370 1.1 uch int
371 1.40 christos hpcfbprint(void *aux, const char *pnp)
372 1.1 uch {
373 1.1 uch if (pnp)
374 1.28 thorpej aprint_normal("hpcfb at %s", pnp);
375 1.1 uch
376 1.1 uch return (UNCONF);
377 1.1 uch }
378 1.1 uch
379 1.1 uch int
380 1.4 uch hpcfb_cnattach(struct hpcfb_fbconf *fbconf)
381 1.1 uch {
382 1.39 uwe #if NBIVIDEO > 0
383 1.39 uwe struct hpcfb_fbconf __fbconf;
384 1.39 uwe #endif
385 1.1 uch long defattr;
386 1.1 uch
387 1.10 takemura DPRINTF(("%s(%d): hpcfb_cnattach()\n", __FILE__, __LINE__));
388 1.1 uch #if NBIVIDEO > 0
389 1.39 uwe if (fbconf == NULL) {
390 1.1 uch memset(&__fbconf, 0, sizeof(struct hpcfb_fbconf));
391 1.1 uch if (bivideo_getcnfb(&__fbconf) != 0)
392 1.1 uch return (ENXIO);
393 1.1 uch fbconf = &__fbconf;
394 1.1 uch }
395 1.1 uch #endif /* NBIVIDEO > 0 */
396 1.7 toshii memset(&hpcfb_console_dc, 0, sizeof(struct hpcfb_devconfig));
397 1.1 uch if (hpcfb_init(fbconf, &hpcfb_console_dc) != 0)
398 1.1 uch return (ENXIO);
399 1.10 takemura hpcfb_console_dc.dc_state |= HPCFB_DC_CURRENT;
400 1.1 uch
401 1.1 uch hpcfb_console_dc.dc_tvram = hpcfb_console_tvram;
402 1.10 takemura /* clear screen */
403 1.7 toshii memset(hpcfb_console_tvram, 0, sizeof(hpcfb_console_tvram));
404 1.10 takemura hpcfb_redraw(&hpcfb_console_dc, 0, hpcfb_console_dc.dc_rows, 1);
405 1.1 uch
406 1.1 uch hpcfb_console_wsscreen = hpcfb_stdscreen;
407 1.1 uch hpcfb_console_wsscreen.nrows = hpcfb_console_dc.dc_rows;
408 1.1 uch hpcfb_console_wsscreen.ncols = hpcfb_console_dc.dc_cols;
409 1.1 uch hpcfb_console_wsscreen.capabilities = hpcfb_console_dc.dc_rinfo.ri_caps;
410 1.21 junyoung hpcfb_allocattr(&hpcfb_console_dc,
411 1.21 junyoung WSCOL_WHITE, WSCOL_BLACK, 0, &defattr);
412 1.1 uch wsdisplay_cnattach(&hpcfb_console_wsscreen, &hpcfb_console_dc,
413 1.4 uch 0, 0, defattr);
414 1.1 uch hpcfbconsole = 1;
415 1.1 uch
416 1.1 uch return (0);
417 1.1 uch }
418 1.1 uch
419 1.1 uch int
420 1.4 uch hpcfb_init(struct hpcfb_fbconf *fbconf, struct hpcfb_devconfig *dc)
421 1.1 uch {
422 1.1 uch struct rasops_info *ri;
423 1.1 uch vaddr_t fbaddr;
424 1.1 uch
425 1.1 uch fbaddr = (vaddr_t)fbconf->hf_baseaddr;
426 1.1 uch dc->dc_fbaddr = (u_char *)fbaddr;
427 1.1 uch
428 1.1 uch /* init rasops */
429 1.1 uch ri = &dc->dc_rinfo;
430 1.7 toshii memset(ri, 0, sizeof(struct rasops_info));
431 1.1 uch ri->ri_depth = fbconf->hf_pixel_width;
432 1.41 christos ri->ri_bits = (void *)fbaddr;
433 1.1 uch ri->ri_width = fbconf->hf_width;
434 1.1 uch ri->ri_height = fbconf->hf_height;
435 1.1 uch ri->ri_stride = fbconf->hf_bytes_per_line;
436 1.1 uch #if 0
437 1.1 uch ri->ri_flg = RI_FORCEMONO | RI_CURSOR;
438 1.1 uch #else
439 1.1 uch ri->ri_flg = RI_CURSOR;
440 1.1 uch #endif
441 1.54 tsutsui if (dc == &hpcfb_console_dc)
442 1.54 tsutsui ri->ri_flg |= RI_NO_AUTO;
443 1.54 tsutsui
444 1.19 takemura switch (ri->ri_depth) {
445 1.19 takemura case 8:
446 1.19 takemura if (32 <= fbconf->hf_pack_width &&
447 1.19 takemura (fbconf->hf_order_flags & HPCFB_REVORDER_BYTE) &&
448 1.19 takemura (fbconf->hf_order_flags & HPCFB_REVORDER_WORD)) {
449 1.19 takemura ri->ri_flg |= RI_BSWAP;
450 1.19 takemura }
451 1.19 takemura break;
452 1.19 takemura default:
453 1.19 takemura if (fbconf->hf_order_flags & HPCFB_REVORDER_BYTE) {
454 1.11 takemura #if BYTE_ORDER == BIG_ENDIAN
455 1.19 takemura ri->ri_flg |= RI_BSWAP;
456 1.11 takemura #endif
457 1.19 takemura } else {
458 1.11 takemura #if BYTE_ORDER == LITTLE_ENDIAN
459 1.19 takemura ri->ri_flg |= RI_BSWAP;
460 1.11 takemura #endif
461 1.19 takemura }
462 1.19 takemura break;
463 1.5 uch }
464 1.5 uch
465 1.33 uwe if (fbconf->hf_class == HPCFB_CLASS_RGBCOLOR) {
466 1.33 uwe ri->ri_rnum = fbconf->hf_u.hf_rgb.hf_red_width;
467 1.33 uwe ri->ri_rpos = fbconf->hf_u.hf_rgb.hf_red_shift;
468 1.33 uwe ri->ri_gnum = fbconf->hf_u.hf_rgb.hf_green_width;
469 1.33 uwe ri->ri_gpos = fbconf->hf_u.hf_rgb.hf_green_shift;
470 1.33 uwe ri->ri_bnum = fbconf->hf_u.hf_rgb.hf_blue_width;
471 1.33 uwe ri->ri_bpos = fbconf->hf_u.hf_rgb.hf_blue_shift;
472 1.33 uwe }
473 1.33 uwe
474 1.1 uch if (rasops_init(ri, HPCFB_MAX_ROW, HPCFB_MAX_COLUMN)) {
475 1.59 christos aprint_error_dev(dc->dc_sc->sc_dev, "rasops_init() failed!")
476 1.59 christos return -1;
477 1.1 uch }
478 1.1 uch
479 1.1 uch /* over write color map of rasops */
480 1.1 uch hpcfb_cmap_reorder (fbconf, dc);
481 1.1 uch
482 1.1 uch dc->dc_curx = -1;
483 1.1 uch dc->dc_cury = -1;
484 1.1 uch dc->dc_rows = dc->dc_rinfo.ri_rows;
485 1.1 uch dc->dc_cols = dc->dc_rinfo.ri_cols;
486 1.1 uch #ifdef HPCFB_JUMP
487 1.1 uch dc->dc_max_row = 0;
488 1.1 uch dc->dc_min_row = dc->dc_rows;
489 1.1 uch dc->dc_scroll = 0;
490 1.42 ad callout_init(&dc->dc_scroll_ch, 0);
491 1.1 uch #endif /* HPCFB_JUMP */
492 1.1 uch dc->dc_memsize = ri->ri_stride * ri->ri_height;
493 1.1 uch /* hook rasops in hpcfb_ops */
494 1.1 uch rasops_emul = ri->ri_ops; /* struct copy */
495 1.1 uch ri->ri_ops = hpcfb_emulops; /* struct copy */
496 1.1 uch
497 1.1 uch return (0);
498 1.1 uch }
499 1.1 uch
500 1.1 uch static void
501 1.4 uch hpcfb_cmap_reorder(struct hpcfb_fbconf *fbconf, struct hpcfb_devconfig *dc)
502 1.1 uch {
503 1.1 uch struct rasops_info *ri = &dc->dc_rinfo;
504 1.1 uch int reverse = fbconf->hf_access_flags & HPCFB_ACCESS_REVERSE;
505 1.1 uch int *cmap = ri->ri_devcmap;
506 1.1 uch int i, j, bg, fg, tmp;
507 1.1 uch
508 1.1 uch /*
509 1.31 perry * Set forground and background so that the screen
510 1.1 uch * looks black on white.
511 1.1 uch * Normally, black = 00 and white = ff.
512 1.1 uch * HPCFB_ACCESS_REVERSE means black = ff and white = 00.
513 1.1 uch */
514 1.1 uch switch (fbconf->hf_pixel_width) {
515 1.1 uch case 1:
516 1.1 uch /* FALLTHROUGH */
517 1.1 uch case 2:
518 1.1 uch /* FALLTHROUGH */
519 1.1 uch case 4:
520 1.1 uch if (reverse) {
521 1.1 uch bg = 0;
522 1.1 uch fg = ~0;
523 1.1 uch } else {
524 1.1 uch bg = ~0;
525 1.1 uch fg = 0;
526 1.1 uch }
527 1.1 uch /* for gray-scale LCD, hi-contrast color map */
528 1.1 uch cmap[0] = bg;
529 1.1 uch for (i = 1; i < 16; i++)
530 1.1 uch cmap[i] = fg;
531 1.1 uch break;
532 1.1 uch case 8:
533 1.1 uch /* FALLTHROUGH */
534 1.1 uch case 16:
535 1.1 uch if (reverse) {
536 1.1 uch for (i = 0, j = 15; i < 8; i++, j--) {
537 1.1 uch tmp = cmap[i];
538 1.1 uch cmap[i] = cmap[j];
539 1.1 uch cmap[j] = tmp;
540 1.1 uch }
541 1.1 uch }
542 1.1 uch break;
543 1.1 uch }
544 1.1 uch }
545 1.1 uch
546 1.1 uch int
547 1.41 christos hpcfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
548 1.36 jmmv struct lwp *l)
549 1.1 uch {
550 1.1 uch struct hpcfb_softc *sc = v;
551 1.1 uch struct hpcfb_devconfig *dc = sc->sc_dc;
552 1.1 uch struct wsdisplay_fbinfo *wdf;
553 1.1 uch
554 1.10 takemura DPRINTF(("hpcfb_ioctl(cmd=0x%lx)\n", cmd));
555 1.1 uch switch (cmd) {
556 1.1 uch case WSKBDIO_BELL:
557 1.1 uch return (0);
558 1.1 uch break;
559 1.1 uch
560 1.1 uch case WSDISPLAYIO_GTYPE:
561 1.1 uch *(u_int *)data = WSDISPLAY_TYPE_HPCFB;
562 1.4 uch return (0);
563 1.1 uch
564 1.1 uch case WSDISPLAYIO_GINFO:
565 1.1 uch wdf = (void *)data;
566 1.1 uch wdf->height = dc->dc_rinfo.ri_height;
567 1.1 uch wdf->width = dc->dc_rinfo.ri_width;
568 1.1 uch wdf->depth = dc->dc_rinfo.ri_depth;
569 1.1 uch wdf->cmsize = 256; /* XXXX */
570 1.4 uch return (0);
571 1.31 perry
572 1.56 tsutsui case WSDISPLAYIO_LINEBYTES:
573 1.56 tsutsui *(u_int *)data = dc->dc_rinfo.ri_stride;
574 1.56 tsutsui return 0;
575 1.56 tsutsui
576 1.1 uch case WSDISPLAYIO_SMODE:
577 1.31 perry if (*(int *)data == WSDISPLAYIO_MODE_EMUL){
578 1.1 uch if (sc->sc_mapping){
579 1.1 uch sc->sc_mapping = 0;
580 1.1 uch if (dc->dc_state&HPCFB_DC_DRAWING)
581 1.1 uch dc->dc_state &= ~HPCFB_DC_ABORT;
582 1.1 uch #ifdef HPCFB_FORCE_REDRAW
583 1.1 uch hpcfb_refresh_screen(sc);
584 1.1 uch #else
585 1.1 uch dc->dc_state |= HPCFB_DC_UPDATEALL;
586 1.1 uch #endif
587 1.1 uch }
588 1.1 uch } else {
589 1.1 uch if (!sc->sc_mapping) {
590 1.1 uch sc->sc_mapping = 1;
591 1.1 uch dc->dc_state |= HPCFB_DC_ABORT;
592 1.1 uch }
593 1.1 uch sc->sc_mapping = 1;
594 1.1 uch }
595 1.1 uch if (sc && sc->sc_accessops->iodone)
596 1.1 uch (*sc->sc_accessops->iodone)(sc->sc_accessctx);
597 1.31 perry return (0);
598 1.1 uch
599 1.1 uch case WSDISPLAYIO_GETCMAP:
600 1.1 uch case WSDISPLAYIO_PUTCMAP:
601 1.22 takemura case WSDISPLAYIO_SVIDEO:
602 1.22 takemura case WSDISPLAYIO_GVIDEO:
603 1.1 uch case WSDISPLAYIO_GETPARAM:
604 1.1 uch case WSDISPLAYIO_SETPARAM:
605 1.1 uch case HPCFBIO_GCONF:
606 1.1 uch case HPCFBIO_SCONF:
607 1.1 uch case HPCFBIO_GDSPCONF:
608 1.1 uch case HPCFBIO_SDSPCONF:
609 1.1 uch case HPCFBIO_GOP:
610 1.1 uch case HPCFBIO_SOP:
611 1.4 uch return ((*sc->sc_accessops->ioctl)(sc->sc_accessctx,
612 1.34 christos cmd, data, flag, l));
613 1.1 uch
614 1.1 uch default:
615 1.1 uch if (IOCGROUP(cmd) != 't')
616 1.1 uch DPRINTF(("%s(%d): hpcfb_ioctl(%lx, %lx) grp=%c num=%ld\n",
617 1.4 uch __FILE__, __LINE__,
618 1.4 uch cmd, (u_long)data, (char)IOCGROUP(cmd), cmd&0xff));
619 1.1 uch break;
620 1.1 uch }
621 1.1 uch
622 1.18 atatat return (EPASSTHROUGH); /* Inappropriate ioctl for device */
623 1.1 uch }
624 1.1 uch
625 1.1 uch paddr_t
626 1.40 christos hpcfb_mmap(void *v, void *vs, off_t offset, int prot)
627 1.1 uch {
628 1.1 uch struct hpcfb_softc *sc = v;
629 1.1 uch
630 1.4 uch return ((*sc->sc_accessops->mmap)(sc->sc_accessctx, offset, prot));
631 1.1 uch }
632 1.1 uch
633 1.31 perry static void
634 1.4 uch hpcfb_power(int why, void *arg)
635 1.1 uch {
636 1.1 uch struct hpcfb_softc *sc = arg;
637 1.17 takemura
638 1.17 takemura if (sc->sc_dc == NULL)
639 1.17 takemura return; /* You have no screen yet. */
640 1.1 uch
641 1.1 uch switch (why) {
642 1.1 uch case PWR_STANDBY:
643 1.1 uch break;
644 1.44 peter case PWR_SOFTSUSPEND: {
645 1.44 peter struct wsdisplay_softc *wsc = device_private(sc->sc_wsdisplay);
646 1.44 peter
647 1.44 peter sc->sc_screen_resumed = wsdisplay_getactivescreen(wsc);
648 1.44 peter
649 1.1 uch if (wsdisplay_switch(sc->sc_wsdisplay,
650 1.44 peter WSDISPLAY_NULLSCREEN, 1 /* waitok */) == 0) {
651 1.44 peter wsscreen_switchwait(wsc, WSDISPLAY_NULLSCREEN);
652 1.1 uch } else {
653 1.1 uch sc->sc_screen_resumed = WSDISPLAY_NULLSCREEN;
654 1.1 uch }
655 1.8 sato
656 1.8 sato sc->sc_dc->dc_state &= ~HPCFB_DC_CURRENT;
657 1.1 uch break;
658 1.44 peter }
659 1.1 uch case PWR_SOFTRESUME:
660 1.8 sato sc->sc_dc->dc_state |= HPCFB_DC_CURRENT;
661 1.1 uch if (sc->sc_screen_resumed != WSDISPLAY_NULLSCREEN)
662 1.1 uch wsdisplay_switch(sc->sc_wsdisplay,
663 1.44 peter sc->sc_screen_resumed, 1 /* waitok */);
664 1.1 uch break;
665 1.1 uch }
666 1.1 uch }
667 1.1 uch
668 1.50 uwe static bool
669 1.53 dyoung hpcfb_suspend(device_t self, const pmf_qual_t *qual)
670 1.50 uwe {
671 1.50 uwe struct hpcfb_softc *sc = device_private(self);
672 1.50 uwe
673 1.50 uwe hpcfb_power(PWR_SOFTSUSPEND, sc);
674 1.50 uwe return true;
675 1.50 uwe }
676 1.50 uwe
677 1.50 uwe static bool
678 1.53 dyoung hpcfb_resume(device_t self, const pmf_qual_t *qual)
679 1.50 uwe {
680 1.50 uwe struct hpcfb_softc *sc = device_private(self);
681 1.50 uwe
682 1.50 uwe hpcfb_power(PWR_SOFTRESUME, sc);
683 1.50 uwe return true;
684 1.50 uwe }
685 1.50 uwe
686 1.1 uch void
687 1.4 uch hpcfb_refresh_screen(struct hpcfb_softc *sc)
688 1.1 uch {
689 1.1 uch struct hpcfb_devconfig *dc = sc->sc_dc;
690 1.1 uch int x, y;
691 1.1 uch
692 1.10 takemura DPRINTF(("hpcfb_refres_screen()\n"));
693 1.1 uch if (dc == NULL)
694 1.1 uch return;
695 1.1 uch
696 1.1 uch #ifdef HPCFB_JUMP
697 1.1 uch if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
698 1.1 uch dc->dc_state &= ~HPCFB_DC_SCROLLPENDING;
699 1.1 uch dc->dc_state &= ~HPCFB_DC_UPDATE;
700 1.1 uch callout_stop(&dc->dc_scroll_ch);
701 1.1 uch }
702 1.1 uch #endif /* HPCFB_JUMP */
703 1.1 uch /*
704 1.1 uch * refresh screen
705 1.1 uch */
706 1.1 uch dc->dc_state &= ~HPCFB_DC_UPDATEALL;
707 1.1 uch x = dc->dc_curx;
708 1.1 uch y = dc->dc_cury;
709 1.1 uch if (0 <= x && 0 <= y)
710 1.1 uch hpcfb_cursor_raw(dc, 0, y, x); /* disable cursor */
711 1.1 uch /* redraw all text */
712 1.1 uch hpcfb_redraw(dc, 0, dc->dc_rows, 1);
713 1.1 uch if (0 <= x && 0 <= y)
714 1.1 uch hpcfb_cursor_raw(dc, 1, y, x); /* enable cursor */
715 1.1 uch }
716 1.1 uch
717 1.1 uch static int
718 1.40 christos hpcfb_alloc_screen(void *v, const struct wsscreen_descr *type,
719 1.39 uwe void **cookiep, int *curxp, int *curyp, long *attrp)
720 1.1 uch {
721 1.1 uch struct hpcfb_softc *sc = v;
722 1.1 uch struct hpcfb_devconfig *dc;
723 1.1 uch
724 1.1 uch DPRINTF(("%s(%d): hpcfb_alloc_screen()\n", __FILE__, __LINE__));
725 1.1 uch
726 1.59 christos dc = malloc(sizeof(*dc), M_DEVBUF, M_WAITOK|M_ZERO);
727 1.10 takemura if (dc == NULL)
728 1.59 christos return ENOMEM;
729 1.1 uch
730 1.1 uch dc->dc_sc = sc;
731 1.59 christos if (hpcfb_init(&sc->sc_fbconflist[0], dc) != 0) {
732 1.59 christos free(dc, M_DEVBUF);
733 1.59 christos return EINVAL;
734 1.59 christos }
735 1.1 uch if (sc->sc_accessops->font) {
736 1.31 perry sc->sc_accessops->font(sc->sc_accessctx,
737 1.10 takemura dc->dc_rinfo.ri_font);
738 1.10 takemura }
739 1.10 takemura /* Set video chip dependent CLUT if any. */
740 1.10 takemura if (sc->sc_accessops->setclut)
741 1.10 takemura sc->sc_accessops->setclut(sc->sc_accessctx, &dc->dc_rinfo);
742 1.10 takemura printf("hpcfb: %dx%d pixels, %d colors, %dx%d chars\n",
743 1.10 takemura dc->dc_rinfo.ri_width, dc->dc_rinfo.ri_height,
744 1.26 reinoud (1 << dc->dc_rinfo.ri_depth),
745 1.10 takemura dc->dc_rinfo.ri_cols, dc->dc_rinfo.ri_rows);
746 1.10 takemura
747 1.10 takemura /*
748 1.10 takemura * XXX, wsdisplay won't reffer the information in wsscreen_descr
749 1.10 takemura * structure until alloc_screen will be called, at least, under
750 1.10 takemura * current implementation...
751 1.10 takemura */
752 1.10 takemura hpcfb_stdscreen.nrows = dc->dc_rows;
753 1.10 takemura hpcfb_stdscreen.ncols = dc->dc_cols;
754 1.10 takemura hpcfb_stdscreen.capabilities = dc->dc_rinfo.ri_caps;
755 1.1 uch
756 1.1 uch dc->dc_fbaddr = dc->dc_rinfo.ri_bits;
757 1.1 uch dc->dc_rows = dc->dc_rinfo.ri_rows;
758 1.1 uch dc->dc_cols = dc->dc_rinfo.ri_cols;
759 1.1 uch dc->dc_memsize = dc->dc_rinfo.ri_stride * dc->dc_rinfo.ri_height;
760 1.1 uch
761 1.1 uch dc->dc_curx = -1;
762 1.1 uch dc->dc_cury = -1;
763 1.10 takemura dc->dc_tvram = malloc(sizeof(struct hpcfb_tvrow)*dc->dc_rows,
764 1.16 tsutsui M_DEVBUF, M_WAITOK|M_ZERO);
765 1.1 uch if (dc->dc_tvram == NULL){
766 1.10 takemura free(dc, M_DEVBUF);
767 1.10 takemura return (ENOMEM);
768 1.1 uch }
769 1.31 perry
770 1.1 uch *curxp = 0;
771 1.1 uch *curyp = 0;
772 1.31 perry *cookiep = dc;
773 1.21 junyoung hpcfb_allocattr(*cookiep, WSCOL_WHITE, WSCOL_BLACK, 0, attrp);
774 1.32 christos DPRINTF(("%s(%d): hpcfb_alloc_screen(): %p\n",
775 1.10 takemura __FILE__, __LINE__, dc));
776 1.10 takemura
777 1.1 uch return (0);
778 1.1 uch }
779 1.1 uch
780 1.1 uch static void
781 1.40 christos hpcfb_free_screen(void *v, void *cookie)
782 1.1 uch {
783 1.10 takemura struct hpcfb_devconfig *dc = cookie;
784 1.1 uch
785 1.32 christos DPRINTF(("%s(%d): hpcfb_free_screen(%p)\n",
786 1.10 takemura __FILE__, __LINE__, cookie));
787 1.10 takemura #ifdef DIAGNOSTIC
788 1.10 takemura if (dc == &hpcfb_console_dc)
789 1.1 uch panic("hpcfb_free_screen: console");
790 1.10 takemura #endif
791 1.10 takemura free(dc->dc_tvram, M_DEVBUF);
792 1.10 takemura free(dc, M_DEVBUF);
793 1.1 uch }
794 1.1 uch
795 1.1 uch static int
796 1.40 christos hpcfb_show_screen(void *v, void *cookie, int waitok,
797 1.4 uch void (*cb)(void *, int, int), void *cbarg)
798 1.1 uch {
799 1.1 uch struct hpcfb_softc *sc = v;
800 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
801 1.1 uch struct hpcfb_devconfig *odc;
802 1.1 uch
803 1.32 christos DPRINTF(("%s(%d): hpcfb_show_screen(%p)\n",
804 1.10 takemura __FILE__, __LINE__, dc));
805 1.1 uch
806 1.1 uch odc = sc->sc_dc;
807 1.1 uch
808 1.1 uch if (dc == NULL || odc == dc) {
809 1.1 uch hpcfb_refresh_screen(sc);
810 1.4 uch return (0);
811 1.1 uch }
812 1.12 sato
813 1.13 toshii if (odc != NULL) {
814 1.13 toshii odc->dc_state |= HPCFB_DC_SWITCHREQ;
815 1.13 toshii
816 1.13 toshii if ((odc->dc_state&HPCFB_DC_DRAWING) != 0) {
817 1.13 toshii odc->dc_state |= HPCFB_DC_ABORT;
818 1.13 toshii }
819 1.12 sato }
820 1.1 uch
821 1.1 uch sc->sc_wantedscreen = cookie;
822 1.1 uch sc->sc_switchcb = cb;
823 1.1 uch sc->sc_switchcbarg = cbarg;
824 1.1 uch if (cb) {
825 1.1 uch callout_reset(&sc->sc_switch_callout, 0,
826 1.4 uch (void(*)(void *))hpcfb_doswitch, sc);
827 1.4 uch return (EAGAIN);
828 1.1 uch }
829 1.1 uch
830 1.1 uch hpcfb_doswitch(sc);
831 1.4 uch return (0);
832 1.1 uch }
833 1.1 uch
834 1.1 uch void
835 1.4 uch hpcfb_doswitch(struct hpcfb_softc *sc)
836 1.1 uch {
837 1.1 uch struct hpcfb_devconfig *dc;
838 1.1 uch struct hpcfb_devconfig *odc;
839 1.1 uch
840 1.10 takemura DPRINTF(("hpcfb_doswitch()\n"));
841 1.1 uch odc = sc->sc_dc;
842 1.1 uch dc = sc->sc_wantedscreen;
843 1.1 uch
844 1.1 uch if (!dc) {
845 1.1 uch (*sc->sc_switchcb)(sc->sc_switchcbarg, EIO, 0);
846 1.12 sato odc->dc_state &= ~HPCFB_DC_SWITCHREQ;
847 1.1 uch return;
848 1.1 uch }
849 1.1 uch
850 1.12 sato if (odc == dc) {
851 1.12 sato odc->dc_state &= ~HPCFB_DC_SWITCHREQ;
852 1.1 uch return;
853 1.12 sato }
854 1.1 uch
855 1.1 uch if (odc) {
856 1.1 uch #ifdef HPCFB_JUMP
857 1.1 uch odc->dc_state |= HPCFB_DC_ABORT;
858 1.1 uch #endif /* HPCFB_JUMP */
859 1.1 uch
860 1.1 uch if (odc->dc_curx >= 0 && odc->dc_cury >= 0)
861 1.1 uch hpcfb_cursor_raw(odc, 0, odc->dc_cury, odc->dc_curx);
862 1.4 uch /* disable cursor */
863 1.1 uch /* disable old screen */
864 1.1 uch odc->dc_state &= ~HPCFB_DC_CURRENT;
865 1.10 takemura /* XXX, This is too dangerous.
866 1.1 uch odc->dc_rinfo.ri_bits = NULL;
867 1.10 takemura */
868 1.1 uch }
869 1.1 uch /* switch screen to new one */
870 1.1 uch dc->dc_state |= HPCFB_DC_CURRENT;
871 1.12 sato dc->dc_state &= ~HPCFB_DC_ABORT;
872 1.1 uch dc->dc_rinfo.ri_bits = dc->dc_fbaddr;
873 1.1 uch sc->sc_dc = dc;
874 1.1 uch
875 1.1 uch /* redraw screen image */
876 1.1 uch hpcfb_refresh_screen(sc);
877 1.1 uch
878 1.1 uch sc->sc_wantedscreen = NULL;
879 1.1 uch if (sc->sc_switchcb)
880 1.1 uch (*sc->sc_switchcb)(sc->sc_switchcbarg, 0, 0);
881 1.1 uch
882 1.13 toshii if (odc != NULL)
883 1.13 toshii odc->dc_state &= ~HPCFB_DC_SWITCHREQ;
884 1.12 sato dc->dc_state &= ~HPCFB_DC_SWITCHREQ;
885 1.1 uch return;
886 1.1 uch }
887 1.1 uch
888 1.1 uch static void
889 1.4 uch hpcfb_pollc(void *v, int on)
890 1.1 uch {
891 1.1 uch struct hpcfb_softc *sc = v;
892 1.1 uch
893 1.1 uch if (sc == NULL)
894 1.1 uch return;
895 1.1 uch sc->sc_polling = on;
896 1.1 uch if (sc->sc_accessops->iodone)
897 1.1 uch (*sc->sc_accessops->iodone)(sc->sc_accessctx);
898 1.1 uch if (on) {
899 1.1 uch hpcfb_refresh_screen(sc);
900 1.1 uch if (sc->sc_accessops->iodone)
901 1.1 uch (*sc->sc_accessops->iodone)(sc->sc_accessctx);
902 1.1 uch }
903 1.1 uch
904 1.1 uch return;
905 1.1 uch }
906 1.1 uch
907 1.1 uch /*
908 1.1 uch * cursor
909 1.1 uch */
910 1.1 uch void
911 1.4 uch hpcfb_cursor(void *cookie, int on, int row, int col)
912 1.1 uch {
913 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
914 1.1 uch
915 1.1 uch if (on) {
916 1.1 uch dc->dc_curx = col;
917 1.1 uch dc->dc_cury = row;
918 1.1 uch } else {
919 1.1 uch dc->dc_curx = -1;
920 1.1 uch dc->dc_cury = -1;
921 1.1 uch }
922 1.1 uch
923 1.1 uch hpcfb_cursor_raw(cookie, on, row, col);
924 1.1 uch }
925 1.1 uch
926 1.1 uch void
927 1.48 dsl hpcfb_cursor_raw(void *cookie, int on, int row, int col)
928 1.1 uch {
929 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
930 1.1 uch struct hpcfb_softc *sc = dc->dc_sc;
931 1.1 uch struct rasops_info *ri = &dc->dc_rinfo;
932 1.1 uch int curwidth, curheight;
933 1.1 uch int xoff, yoff;
934 1.1 uch
935 1.1 uch #ifdef HPCFB_JUMP
936 1.1 uch if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
937 1.1 uch dc->dc_state |= HPCFB_DC_UPDATE;
938 1.1 uch return;
939 1.1 uch }
940 1.1 uch #endif /* HPCFB_JUMP */
941 1.12 sato if (!IS_DRAWABLE(dc)) {
942 1.1 uch return;
943 1.12 sato }
944 1.1 uch
945 1.1 uch if (ri->ri_bits == NULL)
946 1.1 uch return;
947 1.1 uch
948 1.1 uch dc->dc_state |= HPCFB_DC_DRAWING;
949 1.1 uch if (sc && sc->sc_accessops->cursor) {
950 1.1 uch xoff = col * ri->ri_font->fontwidth;
951 1.1 uch yoff = row * ri->ri_font->fontheight;
952 1.1 uch curheight = ri->ri_font->fontheight;
953 1.1 uch curwidth = ri->ri_font->fontwidth;
954 1.1 uch (*sc->sc_accessops->cursor)(sc->sc_accessctx,
955 1.4 uch on, xoff, yoff, curwidth, curheight);
956 1.31 perry } else
957 1.1 uch rasops_emul.cursor(ri, on, row, col);
958 1.1 uch dc->dc_state &= ~HPCFB_DC_DRAWING;
959 1.1 uch }
960 1.1 uch
961 1.1 uch /*
962 1.1 uch * mapchar
963 1.1 uch */
964 1.1 uch int
965 1.4 uch hpcfb_mapchar(void *cookie, int c, unsigned int *cp)
966 1.1 uch {
967 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
968 1.1 uch struct rasops_info *ri = &dc->dc_rinfo;
969 1.1 uch
970 1.4 uch return (rasops_emul.mapchar(ri, c, cp));
971 1.1 uch }
972 1.1 uch
973 1.1 uch /*
974 1.1 uch * putchar
975 1.1 uch */
976 1.1 uch void
977 1.4 uch hpcfb_tv_putchar(struct hpcfb_devconfig *dc, int row, int col, u_int uc,
978 1.4 uch long attr)
979 1.1 uch {
980 1.1 uch struct hpcfb_tvrow *vscn = dc->dc_tvram;
981 1.1 uch struct hpcfb_vchar *vc = &vscn[row].col[col];
982 1.1 uch struct hpcfb_vchar *vcb;
983 1.1 uch
984 1.1 uch if (vscn == 0)
985 1.1 uch return;
986 1.1 uch
987 1.1 uch dc->dc_state |= HPCFB_DC_TDRAWING;
988 1.1 uch #ifdef HPCFB_JUMP
989 1.1 uch if (row < dc->dc_min_row)
990 1.1 uch dc->dc_min_row = row;
991 1.1 uch if (row > dc->dc_max_row)
992 1.1 uch dc->dc_max_row = row;
993 1.1 uch
994 1.1 uch #endif /* HPCFB_JUMP */
995 1.1 uch if (vscn[row].maxcol +1 == col)
996 1.1 uch vscn[row].maxcol = col;
997 1.1 uch else if (vscn[row].maxcol < col) {
998 1.1 uch vcb = &vscn[row].col[vscn[row].maxcol+1];
999 1.7 toshii memset(vcb, 0,
1000 1.7 toshii sizeof(struct hpcfb_vchar)*(col-vscn[row].maxcol-1));
1001 1.1 uch vscn[row].maxcol = col;
1002 1.1 uch }
1003 1.1 uch vc->c = uc;
1004 1.1 uch vc->attr = attr;
1005 1.1 uch dc->dc_state &= ~HPCFB_DC_TDRAWING;
1006 1.1 uch #ifdef HPCFB_JUMP
1007 1.1 uch hpcfb_check_update(dc);
1008 1.1 uch #endif /* HPCFB_JUMP */
1009 1.1 uch }
1010 1.1 uch
1011 1.1 uch void
1012 1.4 uch hpcfb_putchar(void *cookie, int row, int col, u_int uc, long attr)
1013 1.1 uch {
1014 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1015 1.1 uch struct hpcfb_softc *sc = dc->dc_sc;
1016 1.1 uch struct rasops_info *ri = &dc->dc_rinfo;
1017 1.1 uch int xoff;
1018 1.1 uch int yoff;
1019 1.1 uch int fclr, uclr;
1020 1.1 uch struct wsdisplay_font *font;
1021 1.1 uch
1022 1.1 uch hpcfb_tv_putchar(dc, row, col, uc, attr);
1023 1.1 uch #ifdef HPCFB_JUMP
1024 1.1 uch if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
1025 1.1 uch dc->dc_state |= HPCFB_DC_UPDATE;
1026 1.1 uch return;
1027 1.1 uch }
1028 1.1 uch #endif /* HPCFB_JUMP */
1029 1.1 uch
1030 1.12 sato if (!IS_DRAWABLE(dc)) {
1031 1.1 uch return;
1032 1.12 sato }
1033 1.12 sato
1034 1.1 uch if (ri->ri_bits == NULL)
1035 1.1 uch return;
1036 1.1 uch
1037 1.1 uch dc->dc_state |= HPCFB_DC_DRAWING;
1038 1.31 perry if (sc && sc->sc_accessops->putchar
1039 1.4 uch && (dc->dc_state&HPCFB_DC_CURRENT)) {
1040 1.1 uch font = ri->ri_font;
1041 1.1 uch yoff = row * ri->ri_font->fontheight;
1042 1.1 uch xoff = col * ri->ri_font->fontwidth;
1043 1.1 uch fclr = ri->ri_devcmap[((u_int)attr >> 24) & 15];
1044 1.1 uch uclr = ri->ri_devcmap[((u_int)attr >> 16) & 15];
1045 1.1 uch
1046 1.1 uch (*sc->sc_accessops->putchar)(sc->sc_accessctx,
1047 1.4 uch xoff, yoff, font, fclr, uclr, uc, attr);
1048 1.1 uch } else
1049 1.1 uch rasops_emul.putchar(ri, row, col, uc, attr);
1050 1.1 uch dc->dc_state &= ~HPCFB_DC_DRAWING;
1051 1.1 uch #ifdef HPCFB_JUMP
1052 1.1 uch hpcfb_check_update(dc);
1053 1.1 uch #endif /* HPCFB_JUMP */
1054 1.1 uch }
1055 1.1 uch
1056 1.1 uch /*
1057 1.1 uch * copycols
1058 1.1 uch */
1059 1.1 uch void
1060 1.4 uch hpcfb_tv_copycols(struct hpcfb_devconfig *dc, int row, int srccol, int dstcol,
1061 1.4 uch int ncols)
1062 1.1 uch {
1063 1.1 uch struct hpcfb_tvrow *vscn = dc->dc_tvram;
1064 1.1 uch struct hpcfb_vchar *svc = &vscn[row].col[srccol];
1065 1.1 uch struct hpcfb_vchar *dvc = &vscn[row].col[dstcol];
1066 1.1 uch
1067 1.1 uch if (vscn == 0)
1068 1.1 uch return;
1069 1.1 uch
1070 1.1 uch dc->dc_state |= HPCFB_DC_TDRAWING;
1071 1.1 uch #ifdef HPCFB_JUMP
1072 1.1 uch if (row < dc->dc_min_row)
1073 1.1 uch dc->dc_min_row = row;
1074 1.1 uch if (row > dc->dc_max_row)
1075 1.1 uch dc->dc_max_row = row;
1076 1.1 uch #endif /* HPCFB_JUMP */
1077 1.1 uch
1078 1.7 toshii memcpy(dvc, svc, ncols*sizeof(struct hpcfb_vchar));
1079 1.1 uch if (vscn[row].maxcol < srccol+ncols-1)
1080 1.1 uch vscn[row].maxcol = srccol+ncols-1;
1081 1.1 uch if (vscn[row].maxcol < dstcol+ncols-1)
1082 1.1 uch vscn[row].maxcol = dstcol+ncols-1;
1083 1.1 uch dc->dc_state &= ~HPCFB_DC_TDRAWING;
1084 1.1 uch #ifdef HPCFB_JUMP
1085 1.1 uch hpcfb_check_update(dc);
1086 1.1 uch #endif /* HPCFB_JUMP */
1087 1.1 uch }
1088 1.1 uch
1089 1.1 uch void
1090 1.4 uch hpcfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
1091 1.1 uch {
1092 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1093 1.1 uch struct hpcfb_softc *sc = dc->dc_sc;
1094 1.1 uch struct rasops_info *ri = &dc->dc_rinfo;
1095 1.1 uch int srcxoff,dstxoff;
1096 1.1 uch int srcyoff,dstyoff;
1097 1.1 uch int height, width;
1098 1.1 uch
1099 1.1 uch hpcfb_tv_copycols(dc, row, srccol, dstcol, ncols);
1100 1.1 uch #ifdef HPCFB_JUMP
1101 1.1 uch if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
1102 1.1 uch dc->dc_state |= HPCFB_DC_UPDATE;
1103 1.1 uch return;
1104 1.1 uch }
1105 1.1 uch #endif /* HPCFB_JUMP */
1106 1.12 sato if (!IS_DRAWABLE(dc)) {
1107 1.1 uch return;
1108 1.12 sato }
1109 1.12 sato
1110 1.1 uch if (ri->ri_bits == NULL)
1111 1.1 uch return;
1112 1.1 uch
1113 1.1 uch dc->dc_state |= HPCFB_DC_DRAWING;
1114 1.1 uch if (sc && sc->sc_accessops->bitblit
1115 1.4 uch && (dc->dc_state&HPCFB_DC_CURRENT)) {
1116 1.1 uch srcxoff = srccol * ri->ri_font->fontwidth;
1117 1.1 uch srcyoff = row * ri->ri_font->fontheight;
1118 1.1 uch dstxoff = dstcol * ri->ri_font->fontwidth;
1119 1.1 uch dstyoff = row * ri->ri_font->fontheight;
1120 1.1 uch width = ncols * ri->ri_font->fontwidth;
1121 1.1 uch height = ri->ri_font->fontheight;
1122 1.1 uch (*sc->sc_accessops->bitblit)(sc->sc_accessctx,
1123 1.4 uch srcxoff, srcyoff, dstxoff, dstyoff, height, width);
1124 1.1 uch } else
1125 1.1 uch rasops_emul.copycols(ri, row, srccol, dstcol, ncols);
1126 1.1 uch dc->dc_state &= ~HPCFB_DC_DRAWING;
1127 1.1 uch #ifdef HPCFB_JUMP
1128 1.1 uch hpcfb_check_update(dc);
1129 1.1 uch #endif /* HPCFB_JUMP */
1130 1.1 uch }
1131 1.1 uch
1132 1.1 uch
1133 1.1 uch /*
1134 1.1 uch * erasecols
1135 1.1 uch */
1136 1.1 uch void
1137 1.39 uwe hpcfb_tv_erasecols(struct hpcfb_devconfig *dc,
1138 1.40 christos int row, int startcol, int ncols, long attr)
1139 1.1 uch {
1140 1.1 uch struct hpcfb_tvrow *vscn = dc->dc_tvram;
1141 1.1 uch
1142 1.1 uch if (vscn == 0)
1143 1.1 uch return;
1144 1.1 uch
1145 1.1 uch dc->dc_state |= HPCFB_DC_TDRAWING;
1146 1.1 uch #ifdef HPCFB_JUMP
1147 1.1 uch if (row < dc->dc_min_row)
1148 1.1 uch dc->dc_min_row = row;
1149 1.1 uch if (row > dc->dc_max_row)
1150 1.1 uch dc->dc_max_row = row;
1151 1.1 uch #endif /* HPCFB_JUMP */
1152 1.1 uch
1153 1.1 uch vscn[row].maxcol = startcol-1;
1154 1.1 uch if (vscn[row].spacecol < startcol+ncols-1)
1155 1.1 uch vscn[row].spacecol = startcol+ncols-1;
1156 1.1 uch dc->dc_state &= ~HPCFB_DC_TDRAWING;
1157 1.1 uch #ifdef HPCFB_JUMP
1158 1.1 uch hpcfb_check_update(dc);
1159 1.1 uch #endif /* HPCFB_JUMP */
1160 1.1 uch }
1161 1.1 uch
1162 1.1 uch void
1163 1.4 uch hpcfb_erasecols(void *cookie, int row, int startcol, int ncols, long attr)
1164 1.1 uch {
1165 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1166 1.1 uch struct hpcfb_softc *sc = dc->dc_sc;
1167 1.1 uch struct rasops_info *ri = &dc->dc_rinfo;
1168 1.1 uch int xoff, yoff;
1169 1.1 uch int width, height;
1170 1.1 uch
1171 1.1 uch hpcfb_tv_erasecols(dc, row, startcol, ncols, attr);
1172 1.1 uch #ifdef HPCFB_JUMP
1173 1.1 uch if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
1174 1.1 uch dc->dc_state |= HPCFB_DC_UPDATE;
1175 1.1 uch return;
1176 1.1 uch }
1177 1.1 uch #endif /* HPCFB_JUMP */
1178 1.12 sato if (!IS_DRAWABLE(dc)) {
1179 1.1 uch return;
1180 1.12 sato }
1181 1.12 sato
1182 1.1 uch if (ri->ri_bits == NULL)
1183 1.1 uch return;
1184 1.1 uch
1185 1.1 uch dc->dc_state |= HPCFB_DC_DRAWING;
1186 1.1 uch if (sc && sc->sc_accessops->erase
1187 1.4 uch && (dc->dc_state&HPCFB_DC_CURRENT)) {
1188 1.1 uch xoff = startcol * ri->ri_font->fontwidth;
1189 1.1 uch yoff = row * ri->ri_font->fontheight;
1190 1.1 uch width = ncols * ri->ri_font->fontwidth;
1191 1.1 uch height = ri->ri_font->fontheight;
1192 1.1 uch (*sc->sc_accessops->erase)(sc->sc_accessctx,
1193 1.4 uch xoff, yoff, height, width, attr);
1194 1.31 perry } else
1195 1.1 uch rasops_emul.erasecols(ri, row, startcol, ncols, attr);
1196 1.1 uch dc->dc_state &= ~HPCFB_DC_DRAWING;
1197 1.1 uch #ifdef HPCFB_JUMP
1198 1.1 uch hpcfb_check_update(dc);
1199 1.1 uch #endif /* HPCFB_JUMP */
1200 1.1 uch }
1201 1.1 uch
1202 1.1 uch /*
1203 1.1 uch * Copy rows.
1204 1.1 uch */
1205 1.1 uch void
1206 1.4 uch hpcfb_tv_copyrows(struct hpcfb_devconfig *dc, int src, int dst, int num)
1207 1.1 uch {
1208 1.1 uch struct hpcfb_tvrow *vscn = dc->dc_tvram;
1209 1.1 uch struct hpcfb_tvrow *svc = &vscn[src];
1210 1.1 uch struct hpcfb_tvrow *dvc = &vscn[dst];
1211 1.1 uch int i;
1212 1.1 uch int d;
1213 1.1 uch
1214 1.1 uch if (vscn == 0)
1215 1.1 uch return;
1216 1.1 uch
1217 1.1 uch dc->dc_state |= HPCFB_DC_TDRAWING;
1218 1.1 uch #ifdef HPCFB_JUMP
1219 1.1 uch if (dst < dc->dc_min_row)
1220 1.1 uch dc->dc_min_row = dst;
1221 1.1 uch if (dst + num > dc->dc_max_row)
1222 1.1 uch dc->dc_max_row = dst + num -1;
1223 1.1 uch #endif /* HPCFB_JUMP */
1224 1.1 uch
1225 1.1 uch if (svc > dvc)
1226 1.1 uch d = 1;
1227 1.1 uch else if (svc < dvc) {
1228 1.1 uch svc += num-1;
1229 1.1 uch dvc += num-1;
1230 1.1 uch d = -1;
1231 1.1 uch } else {
1232 1.1 uch dc->dc_state &= ~HPCFB_DC_TDRAWING;
1233 1.1 uch #ifdef HPCFB_JUMP
1234 1.1 uch hpcfb_check_update(dc);
1235 1.1 uch #endif /* HPCFB_JUMP */
1236 1.31 perry return;
1237 1.1 uch }
1238 1.1 uch
1239 1.1 uch for (i = 0; i < num; i++) {
1240 1.7 toshii memcpy(&dvc->col[0], &svc->col[0], sizeof(struct hpcfb_vchar)*(svc->maxcol+1));
1241 1.1 uch if (svc->maxcol < dvc->maxcol && dvc->spacecol < dvc->maxcol)
1242 1.1 uch dvc->spacecol = dvc->maxcol;
1243 1.1 uch dvc->maxcol = svc->maxcol;
1244 1.1 uch svc+=d;
1245 1.1 uch dvc+=d;
1246 1.1 uch }
1247 1.1 uch dc->dc_state &= ~HPCFB_DC_TDRAWING;
1248 1.1 uch #ifdef HPCFB_JUMP
1249 1.1 uch hpcfb_check_update(dc);
1250 1.1 uch #endif /* HPCFB_JUMP */
1251 1.1 uch }
1252 1.1 uch
1253 1.1 uch void
1254 1.48 dsl hpcfb_redraw(void *cookie, int row, int num, int all)
1255 1.1 uch {
1256 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1257 1.1 uch struct rasops_info *ri = &dc->dc_rinfo;
1258 1.1 uch int cols;
1259 1.1 uch struct hpcfb_tvrow *vscn = dc->dc_tvram;
1260 1.1 uch struct hpcfb_vchar *svc;
1261 1.1 uch int i, j;
1262 1.1 uch
1263 1.1 uch #ifdef HPCFB_JUMP
1264 1.1 uch if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
1265 1.1 uch dc->dc_state |= HPCFB_DC_UPDATE;
1266 1.1 uch return;
1267 1.1 uch }
1268 1.1 uch #endif /* HPCFB_JUMP */
1269 1.1 uch if (dc->dc_sc != NULL
1270 1.1 uch && !dc->dc_sc->sc_polling
1271 1.1 uch && dc->dc_sc->sc_mapping)
1272 1.1 uch return;
1273 1.1 uch
1274 1.1 uch dc->dc_state &= ~HPCFB_DC_ABORT;
1275 1.1 uch
1276 1.12 sato if (vscn == 0)
1277 1.1 uch return;
1278 1.12 sato
1279 1.12 sato if (!IS_DRAWABLE(dc)) {
1280 1.1 uch return;
1281 1.12 sato }
1282 1.1 uch
1283 1.1 uch if (ri->ri_bits == NULL)
1284 1.1 uch return;
1285 1.1 uch
1286 1.1 uch dc->dc_state |= HPCFB_DC_DRAWING;
1287 1.1 uch dc->dc_state |= HPCFB_DC_TDRAWING;
1288 1.1 uch for (i = 0; i < num; i++) {
1289 1.1 uch if (dc->dc_state&HPCFB_DC_ABORT)
1290 1.1 uch break;
1291 1.12 sato if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
1292 1.12 sato break;
1293 1.1 uch cols = vscn[row+i].maxcol;
1294 1.1 uch for (j = 0; j <= cols; j++) {
1295 1.1 uch if (dc->dc_state&HPCFB_DC_ABORT)
1296 1.1 uch continue;
1297 1.12 sato if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
1298 1.12 sato continue;
1299 1.1 uch svc = &vscn[row+i].col[j];
1300 1.1 uch rasops_emul.putchar(ri, row + i, j, svc->c, svc->attr);
1301 1.1 uch }
1302 1.1 uch if (all)
1303 1.1 uch cols = dc->dc_cols-1;
1304 1.1 uch else
1305 1.1 uch cols = vscn[row+i].spacecol;
1306 1.1 uch for (; j <= cols; j++) {
1307 1.1 uch if (dc->dc_state&HPCFB_DC_ABORT)
1308 1.1 uch continue;
1309 1.12 sato if ((dc->dc_state&HPCFB_DC_CURRENT) == 0)
1310 1.12 sato continue;
1311 1.1 uch rasops_emul.putchar(ri, row + i, j, ' ', 0);
1312 1.1 uch }
1313 1.1 uch vscn[row+i].spacecol = 0;
1314 1.1 uch }
1315 1.1 uch if (dc->dc_state&HPCFB_DC_ABORT)
1316 1.1 uch dc->dc_state &= ~HPCFB_DC_ABORT;
1317 1.1 uch dc->dc_state &= ~HPCFB_DC_DRAWING;
1318 1.1 uch dc->dc_state &= ~HPCFB_DC_TDRAWING;
1319 1.1 uch #ifdef HPCFB_JUMP
1320 1.1 uch hpcfb_check_update(dc);
1321 1.1 uch #endif /* HPCFB_JUMP */
1322 1.1 uch }
1323 1.1 uch
1324 1.1 uch #ifdef HPCFB_JUMP
1325 1.1 uch void
1326 1.4 uch hpcfb_update(void *v)
1327 1.1 uch {
1328 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)v;
1329 1.1 uch
1330 1.1 uch /* callout_stop(&dc->dc_scroll_ch); */
1331 1.1 uch dc->dc_state &= ~HPCFB_DC_SCROLLPENDING;
1332 1.1 uch if (dc->dc_curx > 0 && dc->dc_cury > 0)
1333 1.31 perry hpcfb_cursor_raw(dc, 0, dc->dc_cury, dc->dc_curx);
1334 1.1 uch if ((dc->dc_state&HPCFB_DC_UPDATEALL)) {
1335 1.1 uch hpcfb_redraw(dc, 0, dc->dc_rows, 1);
1336 1.1 uch dc->dc_state &= ~(HPCFB_DC_UPDATE|HPCFB_DC_UPDATEALL);
1337 1.1 uch } else if ((dc->dc_state&HPCFB_DC_UPDATE)) {
1338 1.31 perry hpcfb_redraw(dc, dc->dc_min_row,
1339 1.4 uch dc->dc_max_row - dc->dc_min_row, 0);
1340 1.1 uch dc->dc_state &= ~HPCFB_DC_UPDATE;
1341 1.1 uch } else {
1342 1.1 uch hpcfb_redraw(dc, dc->dc_scroll_dst, dc->dc_scroll_num, 0);
1343 1.1 uch }
1344 1.1 uch if (dc->dc_curx > 0 && dc->dc_cury > 0)
1345 1.31 perry hpcfb_cursor_raw(dc, 1, dc->dc_cury, dc->dc_curx);
1346 1.1 uch }
1347 1.1 uch
1348 1.1 uch void
1349 1.4 uch hpcfb_do_scroll(void *v)
1350 1.1 uch {
1351 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)v;
1352 1.1 uch
1353 1.31 perry dc->dc_state |= HPCFB_DC_SCRTHREAD;
1354 1.1 uch if (dc->dc_state&(HPCFB_DC_DRAWING|HPCFB_DC_TDRAWING))
1355 1.1 uch dc->dc_state |= HPCFB_DC_SCRDELAY;
1356 1.1 uch else if (dc->dc_sc != NULL && dc->dc_sc->sc_thread)
1357 1.1 uch wakeup(dc->dc_sc);
1358 1.1 uch else if (dc->dc_sc != NULL && !dc->dc_sc->sc_mapping) {
1359 1.1 uch /* draw only EMUL mode */
1360 1.1 uch hpcfb_update(v);
1361 1.1 uch }
1362 1.31 perry dc->dc_state &= ~HPCFB_DC_SCRTHREAD;
1363 1.1 uch }
1364 1.1 uch
1365 1.1 uch void
1366 1.4 uch hpcfb_check_update(void *v)
1367 1.1 uch {
1368 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)v;
1369 1.1 uch
1370 1.31 perry if (dc->dc_sc != NULL
1371 1.31 perry && dc->dc_sc->sc_polling
1372 1.4 uch && (dc->dc_state&HPCFB_DC_SCROLLPENDING)){
1373 1.1 uch callout_stop(&dc->dc_scroll_ch);
1374 1.1 uch dc->dc_state &= ~HPCFB_DC_SCRDELAY;
1375 1.1 uch hpcfb_update(v);
1376 1.1 uch }
1377 1.1 uch else if (dc->dc_state&HPCFB_DC_SCRDELAY){
1378 1.1 uch dc->dc_state &= ~HPCFB_DC_SCRDELAY;
1379 1.1 uch hpcfb_update(v);
1380 1.1 uch } else if (dc->dc_state&HPCFB_DC_UPDATEALL){
1381 1.1 uch dc->dc_state &= ~HPCFB_DC_UPDATEALL;
1382 1.1 uch hpcfb_update(v);
1383 1.1 uch }
1384 1.1 uch }
1385 1.1 uch #endif /* HPCFB_JUMP */
1386 1.1 uch
1387 1.1 uch void
1388 1.4 uch hpcfb_copyrows(void *cookie, int src, int dst, int num)
1389 1.1 uch {
1390 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1391 1.1 uch struct rasops_info *ri = &dc->dc_rinfo;
1392 1.1 uch struct hpcfb_softc *sc = dc->dc_sc;
1393 1.1 uch int srcyoff, dstyoff;
1394 1.1 uch int width, height;
1395 1.1 uch
1396 1.1 uch hpcfb_tv_copyrows(cookie, src, dst, num);
1397 1.1 uch
1398 1.12 sato if (!IS_DRAWABLE(dc)) {
1399 1.1 uch return;
1400 1.12 sato }
1401 1.12 sato
1402 1.1 uch if (ri->ri_bits == NULL)
1403 1.1 uch return;
1404 1.1 uch
1405 1.1 uch if (sc && sc->sc_accessops->bitblit
1406 1.4 uch && (dc->dc_state&HPCFB_DC_CURRENT)) {
1407 1.1 uch dc->dc_state |= HPCFB_DC_DRAWING;
1408 1.1 uch srcyoff = src * ri->ri_font->fontheight;
1409 1.1 uch dstyoff = dst * ri->ri_font->fontheight;
1410 1.1 uch width = dc->dc_cols * ri->ri_font->fontwidth;
1411 1.1 uch height = num * ri->ri_font->fontheight;
1412 1.1 uch (*sc->sc_accessops->bitblit)(sc->sc_accessctx,
1413 1.4 uch 0, srcyoff, 0, dstyoff, height, width);
1414 1.1 uch dc->dc_state &= ~HPCFB_DC_DRAWING;
1415 1.1 uch }
1416 1.1 uch else {
1417 1.1 uch #ifdef HPCFB_JUMP
1418 1.1 uch if (sc && sc->sc_polling) {
1419 1.1 uch hpcfb_check_update(dc);
1420 1.1 uch } else if ((dc->dc_state&HPCFB_DC_SCROLLPENDING) == 0) {
1421 1.1 uch dc->dc_state |= HPCFB_DC_SCROLLPENDING;
1422 1.1 uch dc->dc_scroll = 1;
1423 1.1 uch dc->dc_scroll_src = src;
1424 1.1 uch dc->dc_scroll_dst = dst;
1425 1.1 uch dc->dc_scroll_num = num;
1426 1.1 uch callout_reset(&dc->dc_scroll_ch, hz/100, &hpcfb_do_scroll, dc);
1427 1.1 uch return;
1428 1.1 uch } else if (dc->dc_scroll++ < dc->dc_rows/HPCFB_MAX_JUMP) {
1429 1.1 uch dc->dc_state |= HPCFB_DC_UPDATE;
1430 1.1 uch return;
1431 1.1 uch } else {
1432 1.1 uch dc->dc_state &= ~HPCFB_DC_SCROLLPENDING;
1433 1.1 uch callout_stop(&dc->dc_scroll_ch);
1434 1.1 uch }
1435 1.1 uch if (dc->dc_state&HPCFB_DC_UPDATE) {
1436 1.1 uch dc->dc_state &= ~HPCFB_DC_UPDATE;
1437 1.31 perry hpcfb_redraw(cookie, dc->dc_min_row,
1438 1.4 uch dc->dc_max_row - dc->dc_min_row, 0);
1439 1.1 uch dc->dc_max_row = 0;
1440 1.1 uch dc->dc_min_row = dc->dc_rows;
1441 1.1 uch if (dc->dc_curx > 0 && dc->dc_cury > 0)
1442 1.31 perry hpcfb_cursor(dc, 1, dc->dc_cury, dc->dc_curx);
1443 1.1 uch return;
1444 1.1 uch }
1445 1.1 uch #endif /* HPCFB_JUMP */
1446 1.1 uch hpcfb_redraw(cookie, dst, num, 0);
1447 1.1 uch }
1448 1.1 uch #ifdef HPCFB_JUMP
1449 1.1 uch hpcfb_check_update(dc);
1450 1.1 uch #endif /* HPCFB_JUMP */
1451 1.1 uch }
1452 1.1 uch
1453 1.1 uch /*
1454 1.1 uch * eraserows
1455 1.1 uch */
1456 1.1 uch void
1457 1.39 uwe hpcfb_tv_eraserows(struct hpcfb_devconfig *dc,
1458 1.40 christos int row, int nrow, long attr)
1459 1.1 uch {
1460 1.1 uch struct hpcfb_tvrow *vscn = dc->dc_tvram;
1461 1.1 uch int cols;
1462 1.1 uch int i;
1463 1.1 uch
1464 1.1 uch if (vscn == 0)
1465 1.1 uch return;
1466 1.1 uch
1467 1.1 uch dc->dc_state |= HPCFB_DC_TDRAWING;
1468 1.1 uch dc->dc_state &= ~HPCFB_DC_TDRAWING;
1469 1.1 uch #ifdef HPCFB_JUMP
1470 1.1 uch if (row < dc->dc_min_row)
1471 1.1 uch dc->dc_min_row = row;
1472 1.1 uch if (row + nrow > dc->dc_max_row)
1473 1.1 uch dc->dc_max_row = row + nrow;
1474 1.1 uch #endif /* HPCFB_JUMP */
1475 1.1 uch
1476 1.1 uch for (i = 0; i < nrow; i++) {
1477 1.1 uch cols = vscn[row+i].maxcol;
1478 1.1 uch if (vscn[row+i].spacecol < cols)
1479 1.1 uch vscn[row+i].spacecol = cols;
1480 1.1 uch vscn[row+i].maxcol = -1;
1481 1.1 uch }
1482 1.1 uch #ifdef HPCFB_JUMP
1483 1.1 uch hpcfb_check_update(dc);
1484 1.1 uch #endif /* HPCFB_JUMP */
1485 1.1 uch }
1486 1.1 uch
1487 1.1 uch void
1488 1.4 uch hpcfb_eraserows(void *cookie, int row, int nrow, long attr)
1489 1.1 uch {
1490 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1491 1.1 uch struct hpcfb_softc *sc = dc->dc_sc;
1492 1.1 uch struct rasops_info *ri = &dc->dc_rinfo;
1493 1.1 uch int yoff;
1494 1.1 uch int width;
1495 1.1 uch int height;
1496 1.1 uch
1497 1.1 uch hpcfb_tv_eraserows(dc, row, nrow, attr);
1498 1.1 uch #ifdef HPCFB_JUMP
1499 1.1 uch if (dc->dc_state&HPCFB_DC_SCROLLPENDING) {
1500 1.1 uch dc->dc_state |= HPCFB_DC_UPDATE;
1501 1.1 uch return;
1502 1.1 uch }
1503 1.1 uch #endif /* HPCFB_JUMP */
1504 1.12 sato if (!IS_DRAWABLE(dc)) {
1505 1.1 uch return;
1506 1.12 sato }
1507 1.12 sato
1508 1.1 uch if (ri->ri_bits == NULL)
1509 1.1 uch return;
1510 1.1 uch
1511 1.1 uch dc->dc_state |= HPCFB_DC_DRAWING;
1512 1.1 uch if (sc && sc->sc_accessops->erase
1513 1.4 uch && (dc->dc_state&HPCFB_DC_CURRENT)) {
1514 1.1 uch yoff = row * ri->ri_font->fontheight;
1515 1.1 uch width = dc->dc_cols * ri->ri_font->fontwidth;
1516 1.1 uch height = nrow * ri->ri_font->fontheight;
1517 1.1 uch (*sc->sc_accessops->erase)(sc->sc_accessctx,
1518 1.4 uch 0, yoff, height, width, attr);
1519 1.31 perry } else
1520 1.1 uch rasops_emul.eraserows(ri, row, nrow, attr);
1521 1.1 uch dc->dc_state &= ~HPCFB_DC_DRAWING;
1522 1.1 uch #ifdef HPCFB_JUMP
1523 1.1 uch hpcfb_check_update(dc);
1524 1.1 uch #endif /* HPCFB_JUMP */
1525 1.1 uch }
1526 1.1 uch
1527 1.1 uch /*
1528 1.21 junyoung * allocattr
1529 1.1 uch */
1530 1.1 uch int
1531 1.21 junyoung hpcfb_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
1532 1.1 uch {
1533 1.1 uch struct hpcfb_devconfig *dc = (struct hpcfb_devconfig *)cookie;
1534 1.1 uch struct rasops_info *ri = &dc->dc_rinfo;
1535 1.1 uch
1536 1.21 junyoung return (rasops_emul.allocattr(ri, fg, bg, flags, attrp));
1537 1.1 uch }
1538