Home | History | Annotate | Line # | Download | only in wscons
wsdisplay_vconsvar.h revision 1.19
      1  1.19  macallan /*	$NetBSD: wsdisplay_vconsvar.h,v 1.19 2011/05/25 06:01:38 macallan Exp $ */
      2   1.1  macallan 
      3   1.1  macallan /*-
      4   1.1  macallan  * Copyright (c) 2005, 2006 Michael Lorenz
      5   1.1  macallan  * All rights reserved.
      6   1.1  macallan  *
      7   1.1  macallan  * Redistribution and use in source and binary forms, with or without
      8   1.1  macallan  * modification, are permitted provided that the following conditions
      9   1.1  macallan  * are met:
     10   1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     11   1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     12   1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  macallan  *    documentation and/or other materials provided with the distribution.
     15   1.1  macallan  *
     16   1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17   1.1  macallan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18   1.1  macallan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19   1.1  macallan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20   1.1  macallan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21   1.1  macallan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22   1.1  macallan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23   1.1  macallan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24   1.1  macallan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25   1.1  macallan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26   1.1  macallan  * POSSIBILITY OF SUCH DAMAGE.
     27   1.1  macallan  */
     28   1.1  macallan 
     29   1.1  macallan #ifndef _WSDISPLAY_VCONS_H_
     30   1.1  macallan #define _WSDISPLAY_VCONS_H_
     31   1.1  macallan 
     32   1.8  macallan #include "opt_wsdisplay_compat.h"
     33   1.8  macallan #include "opt_vcons.h"
     34   1.8  macallan 
     35   1.1  macallan struct vcons_data;
     36   1.1  macallan 
     37   1.1  macallan struct vcons_screen {
     38   1.1  macallan 	struct rasops_info scr_ri;
     39   1.1  macallan 	LIST_ENTRY(vcons_screen) next;
     40   1.1  macallan 	void *scr_cookie;
     41   1.1  macallan 	struct vcons_data *scr_vd;
     42   1.2  jmcneill 	struct vcons_data *scr_origvd;
     43   1.1  macallan 	const struct wsscreen_descr *scr_type;
     44   1.1  macallan 	uint16_t *scr_chars;
     45   1.1  macallan 	long *scr_attrs;
     46   1.1  macallan 	long scr_defattr;
     47   1.1  macallan 	/* static flags set by the driver */
     48   1.1  macallan 	uint32_t scr_flags;
     49   1.1  macallan #define VCONS_NO_REDRAW		1	/* don't readraw in switch_screen */
     50   1.1  macallan #define	VCONS_SCREEN_IS_STATIC	2	/* don't free() this vcons_screen */
     51   1.1  macallan #define VCONS_SWITCH_NEEDS_POLLING 4	/* rasops can overlap so we need to
     52   1.1  macallan 					 * poll the busy flag when switching
     53   1.1  macallan 					 * - for drivers that use software
     54   1.1  macallan 					 * drawing */
     55   1.3  macallan #define VCONS_DONT_DRAW		8	/* don't draw on this screen at all */
     56  1.12  macallan /*
     57  1.12  macallan  * the following flags are for drivers which either can't accelerate (all) copy
     58  1.12  macallan  * operations or where drawing characters is faster than the blitter
     59  1.12  macallan  * for example, Sun's Creator boards can't accelerate copycols()
     60  1.12  macallan  */
     61  1.12  macallan #define VCONS_NO_COPYCOLS	0x10	/* use putchar() based copycols() */
     62  1.12  macallan #define VCONS_NO_COPYROWS	0x20	/* use putchar() basec copyrows() */
     63  1.12  macallan #define VCONS_DONT_READ		0x30	/* avoid framebuffer reads */
     64   1.1  macallan 	/* status flags used by vcons */
     65   1.1  macallan 	uint32_t scr_status;
     66   1.1  macallan #define VCONS_IS_VISIBLE	1	/* this screen is currently visible */
     67   1.1  macallan 	/* non zero when some rasops operation is in progress */
     68   1.1  macallan 	int scr_busy;
     69   1.8  macallan #ifdef WSDISPLAY_SCROLLSUPPORT
     70   1.8  macallan 	int scr_lines_in_buffer;
     71   1.8  macallan 	int scr_current_line;
     72   1.8  macallan 	int scr_line_wanted;
     73   1.8  macallan 	int scr_offset_to_zero;
     74   1.8  macallan 	int scr_current_offset;
     75   1.8  macallan #endif
     76  1.14  jmcneill #ifdef VCONS_DRAW_INTR
     77  1.16  jmcneill 	unsigned int scr_dirty;
     78  1.14  jmcneill #endif
     79   1.1  macallan };
     80   1.1  macallan 
     81   1.1  macallan #define SCREEN_IS_VISIBLE(scr) (((scr)->scr_status & VCONS_IS_VISIBLE) != 0)
     82   1.1  macallan #define SCREEN_IS_BUSY(scr) ((scr)->scr_busy != 0)
     83   1.3  macallan #define SCREEN_CAN_DRAW(scr) (((scr)->scr_flags & VCONS_DONT_DRAW) == 0)
     84   1.1  macallan #define SCREEN_BUSY(scr) ((scr)->scr_busy = 1)
     85   1.1  macallan #define SCREEN_IDLE(scr) ((scr)->scr_busy = 0)
     86   1.1  macallan #define SCREEN_VISIBLE(scr) ((scr)->scr_status |= VCONS_IS_VISIBLE)
     87   1.1  macallan #define SCREEN_INVISIBLE(scr) ((scr)->scr_status &= ~VCONS_IS_VISIBLE)
     88   1.3  macallan #define SCREEN_DISABLE_DRAWING(scr) ((scr)->scr_flags |= VCONS_DONT_DRAW)
     89   1.3  macallan #define SCREEN_ENABLE_DRAWING(scr) ((scr)->scr_flags &= ~VCONS_DONT_DRAW)
     90   1.8  macallan 
     91   1.1  macallan struct vcons_data {
     92   1.1  macallan 	/* usually the drivers softc */
     93   1.1  macallan 	void *cookie;
     94   1.1  macallan 
     95   1.1  macallan 	/*
     96   1.1  macallan 	 * setup the rasops part of the passed vcons_screen, like
     97   1.1  macallan 	 * geometry, framebuffer address, font, characters, acceleration.
     98   1.1  macallan 	 * we pass the cookie as 1st parameter
     99   1.1  macallan 	 */
    100   1.1  macallan 	void (*init_screen)(void *, struct vcons_screen *, int,
    101   1.1  macallan 	    long *);
    102   1.1  macallan 
    103   1.4      jmmv 	/* accessops */
    104   1.6  christos 	int (*ioctl)(void *, void *, u_long, void *, int, struct lwp *);
    105   1.4      jmmv 
    106   1.1  macallan 	/* rasops */
    107   1.1  macallan 	void (*copycols)(void *, int, int, int, int);
    108   1.1  macallan 	void (*erasecols)(void *, int, int, int, long);
    109   1.1  macallan 	void (*copyrows)(void *, int, int, int);
    110   1.1  macallan 	void (*eraserows)(void *, int, int, long);
    111   1.1  macallan 	void (*putchar)(void *, int, int, u_int, long);
    112   1.1  macallan 	void (*cursor)(void *, int, int, int);
    113   1.8  macallan 	/* called before vcons_redraw_screen */
    114   1.1  macallan 	void (*show_screen_cb)(struct vcons_screen *);
    115   1.1  macallan 	/* virtual screen management stuff */
    116   1.1  macallan 	void (*switch_cb)(void *, int, int);
    117   1.1  macallan 	void *switch_cb_arg;
    118   1.8  macallan 	struct callout switch_callout;
    119   1.1  macallan 	uint32_t switch_pending;
    120   1.1  macallan 	LIST_HEAD(, vcons_screen) screens;
    121   1.1  macallan 	struct vcons_screen *active, *wanted;
    122   1.1  macallan 	const struct wsscreen_descr *currenttype;
    123   1.1  macallan 	int switch_poll_count;
    124  1.13  macallan #ifdef VCONS_DRAW_ASYNC
    125  1.13  macallan 	lwp_t *drawing_thread;
    126  1.13  macallan 	kmutex_t drawing_mutex;
    127  1.13  macallan 	kcondvar_t go_draw;	/* wakeup the drawing thread */
    128  1.13  macallan 	kcondvar_t go_buffer;	/* wakeup anyone waiting for room in the
    129  1.13  macallan 				 * buffer */
    130  1.13  macallan 	kmutex_t go_draw_il, go_buffer_il; /* interlocks for above */
    131  1.13  macallan 	int use_async;		/* use async drawing when non-zero */
    132  1.13  macallan #define VCONS_RING_BUFFER_LENGTH 2048
    133  1.13  macallan 	uint32_t rb_read;	/* to be written by the drawing thread only */
    134  1.13  macallan 	uint32_t rb_write;	/* written by the async drawing methods with
    135  1.13  macallan 				 * drawing_mutex held */
    136  1.13  macallan 	uint32_t rb_buffer[VCONS_RING_BUFFER_LENGTH];
    137  1.13  macallan #endif
    138  1.14  jmcneill #ifdef VCONS_DRAW_INTR
    139  1.19  macallan 	int cells;
    140  1.19  macallan 	long *attrs;
    141  1.19  macallan 	uint16_t *chars;
    142  1.19  macallan 	int cursor_offset;
    143  1.14  jmcneill 	callout_t intr;
    144  1.17  jmcneill 	int intr_valid;
    145  1.16  jmcneill 	void *intr_softint;
    146  1.15  jmcneill 	int use_intr;		/* use intr drawing when non-zero */
    147  1.14  jmcneill #endif
    148   1.1  macallan };
    149   1.1  macallan 
    150  1.13  macallan /*
    151  1.13  macallan  * the ring buffer contains commands in the form:
    152  1.13  macallan  * uint32_t command
    153  1.13  macallan  * uint32_t parameters[]
    154  1.13  macallan  * uint32_t command
    155  1.13  macallan  * ...
    156  1.13  macallan  * parameters are exactly what the corresponding rasops method would take as a
    157  1.13  macallan  * series of uint32_ts, except for the cookie which is always assumed to be
    158  1.13  macallan  * the active screen
    159  1.13  macallan  * There should probably be a command to do vcons_redraw_screen() as a single
    160  1.13  macallan  * operation, not a huge series of VCMD_PUTCHAR, Also, when we find a buffer
    161  1.13  macallan  * with lots of commands in it we should probably ignore all VCMD_CURSOR except
    162  1.13  macallan  * the first that removes the cursor and the last that draws it again
    163  1.13  macallan  */
    164  1.13  macallan 
    165  1.13  macallan #define VCMD_COPYCOLS	0x80000001
    166  1.13  macallan #define VCMD_COPYROWS	0x80000002
    167  1.13  macallan #define VCMD_ERASECOLS	0x80000003
    168  1.13  macallan #define VCMD_ERASEROWS	0x80000004
    169  1.13  macallan #define VCMD_PUTCHAR	0x80000005
    170  1.13  macallan #define VCMD_CURSOR	0x80000006
    171  1.13  macallan 
    172   1.1  macallan int	vcons_init(struct vcons_data *, void *cookie, struct wsscreen_descr *,
    173   1.1  macallan     struct wsdisplay_accessops *);
    174   1.1  macallan 
    175   1.1  macallan int	vcons_init_screen(struct vcons_data *, struct vcons_screen *, int,
    176   1.1  macallan     long *);
    177   1.1  macallan 
    178  1.19  macallan /* completely redraw the screen, clear it if RI_FULLCLEAR is set */
    179   1.1  macallan void	vcons_redraw_screen(struct vcons_screen *);
    180   1.1  macallan 
    181  1.19  macallan #ifdef VCONS_DRAW_INTR
    182  1.19  macallan /* redraw all dirty character cells */
    183  1.19  macallan void	vcons_update_screen(struct vcons_screen *);
    184  1.19  macallan void	vcons_invalidate_cache(struct vcons_data *);
    185  1.19  macallan #else
    186  1.19  macallan #define vcons_update_screen vcons_redraw_screen
    187  1.19  macallan #endif
    188  1.19  macallan 
    189  1.10  macallan void	vcons_replay_msgbuf(struct vcons_screen *);
    190   1.1  macallan 
    191  1.17  jmcneill void	vcons_enable_polling(struct vcons_data *);
    192  1.17  jmcneill void	vcons_disable_polling(struct vcons_data *);
    193  1.18  jmcneill void	vcons_hard_switch(struct vcons_screen *);
    194  1.17  jmcneill 
    195   1.1  macallan #endif /* _WSDISPLAY_VCONS_H_ */
    196