Index: head/sys/dev/fb/creator.c =================================================================== --- head/sys/dev/fb/creator.c (revision 174984) +++ head/sys/dev/fb/creator.c (revision 174985) @@ -1,1130 +1,1130 @@ /*- * Copyright (c) 2003 Jake Burkholder. * Copyright (c) 2005 - 2006 Marius Strobl * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define CREATOR_DRIVER_NAME "creator" struct creator_softc { video_adapter_t sc_va; /* XXX must be first */ phandle_t sc_node; struct cdev *sc_si; struct resource *sc_reg[FFB_NREG]; bus_space_tag_t sc_bt[FFB_NREG]; bus_space_handle_t sc_bh[FFB_NREG]; int sc_height; int sc_width; int sc_xmargin; int sc_ymargin; const u_char *sc_font; int sc_bg_cache; int sc_fg_cache; int sc_fifo_cache; int sc_fontinc_cache; int sc_fontw_cache; int sc_pmask_cache; int sc_flags; #define CREATOR_AFB (1 << 0) #define CREATOR_CONSOLE (1 << 1) #define CREATOR_CUREN (1 << 2) #define CREATOR_CURINV (1 << 3) #define CREATOR_PAC1 (1 << 4) }; #define FFB_READ(sc, reg, off) \ bus_space_read_4((sc)->sc_bt[(reg)], (sc)->sc_bh[(reg)], (off)) #define FFB_WRITE(sc, reg, off, val) \ bus_space_write_4((sc)->sc_bt[(reg)], (sc)->sc_bh[(reg)], (off), (val)) #define C(r, g, b) ((b << 16) | (g << 8) | (r)) static const uint32_t creator_cmap[] = { C(0x00, 0x00, 0x00), /* black */ C(0x00, 0x00, 0xff), /* blue */ C(0x00, 0xff, 0x00), /* green */ C(0x00, 0xc0, 0xc0), /* cyan */ C(0xff, 0x00, 0x00), /* red */ C(0xc0, 0x00, 0xc0), /* magenta */ C(0xc0, 0xc0, 0x00), /* brown */ C(0xc0, 0xc0, 0xc0), /* light grey */ C(0x80, 0x80, 0x80), /* dark grey */ C(0x80, 0x80, 0xff), /* light blue */ C(0x80, 0xff, 0x80), /* light green */ C(0x80, 0xff, 0xff), /* light cyan */ C(0xff, 0x80, 0x80), /* light red */ C(0xff, 0x80, 0xff), /* light magenta */ C(0xff, 0xff, 0x80), /* yellow */ C(0xff, 0xff, 0xff), /* white */ }; #undef C static const struct { vm_offset_t virt; vm_paddr_t phys; vm_size_t size; } creator_fb_map[] = { { FFB_VIRT_SFB8R, FFB_PHYS_SFB8R, FFB_SIZE_SFB8R }, { FFB_VIRT_SFB8G, FFB_PHYS_SFB8G, FFB_SIZE_SFB8G }, { FFB_VIRT_SFB8B, FFB_PHYS_SFB8B, FFB_SIZE_SFB8B }, { FFB_VIRT_SFB8X, FFB_PHYS_SFB8X, FFB_SIZE_SFB8X }, { FFB_VIRT_SFB32, FFB_PHYS_SFB32, FFB_SIZE_SFB32 }, { FFB_VIRT_SFB64, FFB_PHYS_SFB64, FFB_SIZE_SFB64 }, { FFB_VIRT_FBC, FFB_PHYS_FBC, FFB_SIZE_FBC }, { FFB_VIRT_FBC_BM, FFB_PHYS_FBC_BM, FFB_SIZE_FBC_BM }, { FFB_VIRT_DFB8R, FFB_PHYS_DFB8R, FFB_SIZE_DFB8R }, { FFB_VIRT_DFB8G, FFB_PHYS_DFB8G, FFB_SIZE_DFB8G }, { FFB_VIRT_DFB8B, FFB_PHYS_DFB8B, FFB_SIZE_DFB8B }, { FFB_VIRT_DFB8X, FFB_PHYS_DFB8X, FFB_SIZE_DFB8X }, { FFB_VIRT_DFB24, FFB_PHYS_DFB24, FFB_SIZE_DFB24 }, { FFB_VIRT_DFB32, FFB_PHYS_DFB32, FFB_SIZE_DFB32 }, { FFB_VIRT_DFB422A, FFB_PHYS_DFB422A, FFB_SIZE_DFB422A }, { FFB_VIRT_DFB422AD, FFB_PHYS_DFB422AD, FFB_SIZE_DFB422AD }, { FFB_VIRT_DFB24B, FFB_PHYS_DFB24B, FFB_SIZE_DFB24B }, { FFB_VIRT_DFB422B, FFB_PHYS_DFB422B, FFB_SIZE_DFB422B }, { FFB_VIRT_DFB422BD, FFB_PHYS_DFB422BD, FFB_SIZE_DFB422BD }, { FFB_VIRT_SFB16Z, FFB_PHYS_SFB16Z, FFB_SIZE_SFB16Z }, { FFB_VIRT_SFB8Z, FFB_PHYS_SFB8Z, FFB_SIZE_SFB8Z }, { FFB_VIRT_SFB422, FFB_PHYS_SFB422, FFB_SIZE_SFB422 }, { FFB_VIRT_SFB422D, FFB_PHYS_SFB422D, FFB_SIZE_SFB422D }, { FFB_VIRT_FBC_KREG, FFB_PHYS_FBC_KREG, FFB_SIZE_FBC_KREG }, { FFB_VIRT_DAC, FFB_PHYS_DAC, FFB_SIZE_DAC }, { FFB_VIRT_PROM, FFB_PHYS_PROM, FFB_SIZE_PROM }, { FFB_VIRT_EXP, FFB_PHYS_EXP, FFB_SIZE_EXP }, }; #define CREATOR_FB_MAP_SIZE \ (sizeof(creator_fb_map) / sizeof(creator_fb_map[0])) extern const struct gfb_font gallant12x22; static struct creator_softc creator_softc; static struct bus_space_tag creator_bst_store[FFB_FBC]; static device_probe_t creator_bus_probe; static device_attach_t creator_bus_attach; static device_method_t creator_bus_methods[] = { DEVMETHOD(device_probe, creator_bus_probe), DEVMETHOD(device_attach, creator_bus_attach), { 0, 0 } }; static devclass_t creator_devclass; DEFINE_CLASS_0(creator, creator_bus_driver, creator_bus_methods, sizeof(struct creator_softc)); DRIVER_MODULE(creator, nexus, creator_bus_driver, creator_devclass, 0, 0); DRIVER_MODULE(creator, upa, creator_bus_driver, creator_devclass, 0, 0); static d_open_t creator_fb_open; static d_close_t creator_fb_close; static d_ioctl_t creator_fb_ioctl; static d_mmap_t creator_fb_mmap; static struct cdevsw creator_fb_devsw = { .d_version = D_VERSION, .d_flags = D_NEEDGIANT, .d_open = creator_fb_open, .d_close = creator_fb_close, .d_ioctl = creator_fb_ioctl, .d_mmap = creator_fb_mmap, .d_name = "fb", }; static void creator_cursor_enable(struct creator_softc *sc, int onoff); static void creator_cursor_install(struct creator_softc *sc); static void creator_shutdown(void *xsc); static int creator_configure(int flags); static vi_probe_t creator_probe; static vi_init_t creator_init; static vi_get_info_t creator_get_info; static vi_query_mode_t creator_query_mode; static vi_set_mode_t creator_set_mode; static vi_save_font_t creator_save_font; static vi_load_font_t creator_load_font; static vi_show_font_t creator_show_font; static vi_save_palette_t creator_save_palette; static vi_load_palette_t creator_load_palette; static vi_set_border_t creator_set_border; static vi_save_state_t creator_save_state; static vi_load_state_t creator_load_state; static vi_set_win_org_t creator_set_win_org; static vi_read_hw_cursor_t creator_read_hw_cursor; static vi_set_hw_cursor_t creator_set_hw_cursor; static vi_set_hw_cursor_shape_t creator_set_hw_cursor_shape; static vi_blank_display_t creator_blank_display; static vi_mmap_t creator_mmap; static vi_ioctl_t creator_ioctl; static vi_clear_t creator_clear; static vi_fill_rect_t creator_fill_rect; static vi_bitblt_t creator_bitblt; static vi_diag_t creator_diag; static vi_save_cursor_palette_t creator_save_cursor_palette; static vi_load_cursor_palette_t creator_load_cursor_palette; static vi_copy_t creator_copy; static vi_putp_t creator_putp; static vi_putc_t creator_putc; static vi_puts_t creator_puts; static vi_putm_t creator_putm; static video_switch_t creatorvidsw = { .probe = creator_probe, .init = creator_init, .get_info = creator_get_info, .query_mode = creator_query_mode, .set_mode = creator_set_mode, .save_font = creator_save_font, .load_font = creator_load_font, .show_font = creator_show_font, .save_palette = creator_save_palette, .load_palette = creator_load_palette, .set_border = creator_set_border, .save_state = creator_save_state, .load_state = creator_load_state, .set_win_org = creator_set_win_org, .read_hw_cursor = creator_read_hw_cursor, .set_hw_cursor = creator_set_hw_cursor, .set_hw_cursor_shape = creator_set_hw_cursor_shape, .blank_display = creator_blank_display, .mmap = creator_mmap, .ioctl = creator_ioctl, .clear = creator_clear, .fill_rect = creator_fill_rect, .bitblt = creator_bitblt, NULL, /* XXX brain damage */ NULL, /* XXX brain damage */ .diag = creator_diag, .save_cursor_palette = creator_save_cursor_palette, .load_cursor_palette = creator_load_cursor_palette, .copy = creator_copy, .putp = creator_putp, .putc = creator_putc, .puts = creator_puts, .putm = creator_putm }; VIDEO_DRIVER(creator, creatorvidsw, creator_configure); extern sc_rndr_sw_t txtrndrsw; RENDERER(creator, 0, txtrndrsw, gfb_set); RENDERER_MODULE(creator, gfb_set); static const u_char creator_mouse_pointer[64][8] __aligned(8) = { { 0x00, 0x00, }, /* ............ */ { 0x80, 0x00, }, /* *........... */ { 0xc0, 0x00, }, /* **.......... */ { 0xe0, 0x00, }, /* ***......... */ { 0xf0, 0x00, }, /* ****........ */ { 0xf8, 0x00, }, /* *****....... */ { 0xfc, 0x00, }, /* ******...... */ { 0xfe, 0x00, }, /* *******..... */ { 0xff, 0x00, }, /* ********.... */ { 0xff, 0x80, }, /* *********... */ { 0xfc, 0xc0, }, /* ******..**.. */ { 0xdc, 0x00, }, /* **.***...... */ { 0x8e, 0x00, }, /* *...***..... */ { 0x0e, 0x00, }, /* ....***..... */ { 0x07, 0x00, }, /* .....***.... */ { 0x04, 0x00, }, /* .....*...... */ { 0x00, 0x00, }, /* ............ */ { 0x00, 0x00, }, /* ............ */ { 0x00, 0x00, }, /* ............ */ { 0x00, 0x00, }, /* ............ */ { 0x00, 0x00, }, /* ............ */ { 0x00, 0x00, }, /* ............ */ }; static inline void creator_ras_fifo_wait(struct creator_softc *sc, int n); static inline void creator_ras_setfontinc(struct creator_softc *sc, int fontinc); static inline void creator_ras_setfontw(struct creator_softc *sc, int fontw); static inline void creator_ras_setbg(struct creator_softc *sc, int bg); static inline void creator_ras_setfg(struct creator_softc *sc, int fg); static inline void creator_ras_setpmask(struct creator_softc *sc, int pmask); static inline void creator_ras_wait(struct creator_softc *sc); static inline void creator_ras_wait(struct creator_softc *sc) { int ucsr; int r; for (;;) { ucsr = FFB_READ(sc, FFB_FBC, FFB_FBC_UCSR); if ((ucsr & (FBC_UCSR_FB_BUSY | FBC_UCSR_RP_BUSY)) == 0) break; r = ucsr & (FBC_UCSR_READ_ERR | FBC_UCSR_FIFO_OVFL); if (r != 0) FFB_WRITE(sc, FFB_FBC, FFB_FBC_UCSR, r); } } static inline void creator_ras_fifo_wait(struct creator_softc *sc, int n) { int cache; cache = sc->sc_fifo_cache; while (cache < n) cache = (FFB_READ(sc, FFB_FBC, FFB_FBC_UCSR) & FBC_UCSR_FIFO_MASK) - 8; sc->sc_fifo_cache = cache - n; } static inline void creator_ras_setfontinc(struct creator_softc *sc, int fontinc) { if (fontinc == sc->sc_fontinc_cache) return; sc->sc_fontinc_cache = fontinc; creator_ras_fifo_wait(sc, 1); FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTINC, fontinc); creator_ras_wait(sc); } static inline void creator_ras_setfontw(struct creator_softc *sc, int fontw) { if (fontw == sc->sc_fontw_cache) return; sc->sc_fontw_cache = fontw; creator_ras_fifo_wait(sc, 1); FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTW, fontw); creator_ras_wait(sc); } static inline void creator_ras_setbg(struct creator_softc *sc, int bg) { if (bg == sc->sc_bg_cache) return; sc->sc_bg_cache = bg; creator_ras_fifo_wait(sc, 1); FFB_WRITE(sc, FFB_FBC, FFB_FBC_BG, bg); creator_ras_wait(sc); } static inline void creator_ras_setfg(struct creator_softc *sc, int fg) { if (fg == sc->sc_fg_cache) return; sc->sc_fg_cache = fg; creator_ras_fifo_wait(sc, 1); FFB_WRITE(sc, FFB_FBC, FFB_FBC_FG, fg); creator_ras_wait(sc); } static inline void creator_ras_setpmask(struct creator_softc *sc, int pmask) { if (pmask == sc->sc_pmask_cache) return; sc->sc_pmask_cache = pmask; creator_ras_fifo_wait(sc, 1); FFB_WRITE(sc, FFB_FBC, FFB_FBC_PMASK, pmask); creator_ras_wait(sc); } /* * video driver interface */ static int creator_configure(int flags) { struct creator_softc *sc; phandle_t chosen; phandle_t output; ihandle_t stdout; bus_addr_t addr; char buf[sizeof("SUNW,ffb")]; int i; int space; /* * For the high-level console probing return the number of * registered adapters. */ if (!(flags & VIO_PROBE_ONLY)) { for (i = 0; vid_find_adapter(CREATOR_DRIVER_NAME, i) >= 0; i++) ; return (i); } /* Low-level console probing and initialization. */ sc = &creator_softc; if (sc->sc_va.va_flags & V_ADP_REGISTERED) goto found; if ((chosen = OF_finddevice("/chosen")) == -1) return (0); if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1) return (0); if ((output = OF_instance_to_package(stdout)) == -1) return (0); if (OF_getprop(output, "name", buf, sizeof(buf)) == -1) return (0); if (strcmp(buf, "SUNW,ffb") == 0 || strcmp(buf, "SUNW,afb") == 0) { sc->sc_flags = CREATOR_CONSOLE; if (strcmp(buf, "SUNW,afb") == 0) sc->sc_flags |= CREATOR_AFB; sc->sc_node = output; } else return (0); for (i = FFB_DAC; i <= FFB_FBC; i++) { if (OF_decode_addr(output, i, &space, &addr) != 0) return (0); sc->sc_bt[i] = &creator_bst_store[i - FFB_DAC]; sc->sc_bh[i] = sparc64_fake_bustag(space, addr, sc->sc_bt[i]); } if (creator_init(0, &sc->sc_va, 0) < 0) return (0); found: /* Return number of found adapters. */ return (1); } static int creator_probe(int unit, video_adapter_t **adpp, void *arg, int flags) { return (0); } static int creator_init(int unit, video_adapter_t *adp, int flags) { struct creator_softc *sc; phandle_t options; video_info_t *vi; char buf[sizeof("screen-#columns")]; sc = (struct creator_softc *)adp; vi = &adp->va_info; vid_init_struct(adp, CREATOR_DRIVER_NAME, -1, unit); if (OF_getprop(sc->sc_node, "height", &sc->sc_height, sizeof(sc->sc_height)) == -1) return (ENXIO); if (OF_getprop(sc->sc_node, "width", &sc->sc_width, sizeof(sc->sc_width)) == -1) return (ENXIO); if ((options = OF_finddevice("/options")) == -1) return (ENXIO); if (OF_getprop(options, "screen-#rows", buf, sizeof(buf)) == -1) return (ENXIO); vi->vi_height = strtol(buf, NULL, 10); if (OF_getprop(options, "screen-#columns", buf, sizeof(buf)) == -1) return (ENXIO); vi->vi_width = strtol(buf, NULL, 10); vi->vi_cwidth = gallant12x22.width; vi->vi_cheight = gallant12x22.height; vi->vi_flags = V_INFO_COLOR; vi->vi_mem_model = V_INFO_MM_OTHER; sc->sc_font = gallant12x22.data; sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2; sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight)) / 2; creator_set_mode(adp, 0); if (!(sc->sc_flags & CREATOR_AFB)) { FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_DID); if (((FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE) & FFB_DAC_CFG_DID_PNUM) >> 12) != 0x236e) { sc->sc_flags |= CREATOR_PAC1; FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_UCTRL); if (((FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE) & FFB_DAC_UCTRL_MANREV) >> 8) <= 2) sc->sc_flags |= CREATOR_CURINV; } } creator_blank_display(adp, V_DISPLAY_ON); creator_clear(adp); /* * Setting V_ADP_MODECHANGE serves as hack so creator_set_mode() * (which will invalidate our caches and restore our settings) is * called when the X server shuts down. Otherwise screen corruption * happens most of the time. */ adp->va_flags |= V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_BORDER | V_ADP_INITIALIZED; if (vid_register(adp) < 0) return (ENXIO); adp->va_flags |= V_ADP_REGISTERED; return (0); } static int creator_get_info(video_adapter_t *adp, int mode, video_info_t *info) { bcopy(&adp->va_info, info, sizeof(*info)); return (0); } static int creator_query_mode(video_adapter_t *adp, video_info_t *info) { return (ENODEV); } static int creator_set_mode(video_adapter_t *adp, int mode) { struct creator_softc *sc; sc = (struct creator_softc *)adp; sc->sc_bg_cache = -1; sc->sc_fg_cache = -1; sc->sc_fontinc_cache = -1; sc->sc_fontw_cache = -1; sc->sc_pmask_cache = -1; creator_ras_wait(sc); sc->sc_fifo_cache = 0; creator_ras_fifo_wait(sc, 2); FFB_WRITE(sc, FFB_FBC, FFB_FBC_PPC, FBC_PPC_VCE_DIS | FBC_PPC_TBE_OPAQUE | FBC_PPC_APE_DIS | FBC_PPC_CS_CONST); FFB_WRITE(sc, FFB_FBC, FFB_FBC_FBC, FFB_FBC_WB_A | FFB_FBC_RB_A | FFB_FBC_SB_BOTH | FFB_FBC_XE_OFF | FFB_FBC_RGBE_MASK); return (0); } static int creator_save_font(video_adapter_t *adp, int page, int size, int width, u_char *data, int c, int count) { return (ENODEV); } static int creator_load_font(video_adapter_t *adp, int page, int size, int width, u_char *data, int c, int count) { return (ENODEV); } static int creator_show_font(video_adapter_t *adp, int page) { return (ENODEV); } static int creator_save_palette(video_adapter_t *adp, u_char *palette) { return (ENODEV); } static int creator_load_palette(video_adapter_t *adp, u_char *palette) { return (ENODEV); } static int creator_set_border(video_adapter_t *adp, int border) { struct creator_softc *sc; sc = (struct creator_softc *)adp; creator_fill_rect(adp, border, 0, 0, sc->sc_width, sc->sc_ymargin); creator_fill_rect(adp, border, 0, sc->sc_height - sc->sc_ymargin, sc->sc_width, sc->sc_ymargin); creator_fill_rect(adp, border, 0, 0, sc->sc_xmargin, sc->sc_height); creator_fill_rect(adp, border, sc->sc_width - sc->sc_xmargin, 0, sc->sc_xmargin, sc->sc_height); return (0); } static int creator_save_state(video_adapter_t *adp, void *p, size_t size) { return (ENODEV); } static int creator_load_state(video_adapter_t *adp, void *p) { return (ENODEV); } static int creator_set_win_org(video_adapter_t *adp, off_t offset) { return (ENODEV); } static int creator_read_hw_cursor(video_adapter_t *adp, int *col, int *row) { *col = 0; *row = 0; return (0); } static int creator_set_hw_cursor(video_adapter_t *adp, int col, int row) { return (ENODEV); } static int creator_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, int celsize, int blink) { return (ENODEV); } static int creator_blank_display(video_adapter_t *adp, int mode) { struct creator_softc *sc; uint32_t v; int i; sc = (struct creator_softc *)adp; FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN); v = FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE); switch (mode) { case V_DISPLAY_ON: v |= FFB_DAC_CFG_TGEN_VIDE; break; case V_DISPLAY_BLANK: case V_DISPLAY_STAND_BY: case V_DISPLAY_SUSPEND: v &= ~FFB_DAC_CFG_TGEN_VIDE; break; } FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN); FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE, v); for (i = 0; i < 10; i++) { FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN); (void)FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE); } return (0); } static int creator_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr, int prot) { return (EINVAL); } static int creator_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data) { struct creator_softc *sc; struct fbcursor *fbc; struct fbtype *fb; sc = (struct creator_softc *)adp; switch (cmd) { case FBIOGTYPE: fb = (struct fbtype *)data; fb->fb_type = FBTYPE_CREATOR; fb->fb_height = sc->sc_height; fb->fb_width = sc->sc_width; fb->fb_depth = fb->fb_cmsize = fb->fb_size = 0; break; case FBIOSCURSOR: fbc = (struct fbcursor *)data; if (fbc->set & FB_CUR_SETCUR && fbc->enable == 0) { creator_cursor_enable(sc, 0); sc->sc_flags &= ~CREATOR_CUREN; } else return (ENODEV); break; break; default: return (fb_commonioctl(adp, cmd, data)); } return (0); } static int creator_clear(video_adapter_t *adp) { struct creator_softc *sc; sc = (struct creator_softc *)adp; creator_fill_rect(adp, (SC_NORM_ATTR >> 4) & 0xf, 0, 0, sc->sc_width, sc->sc_height); return (0); } static int creator_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) { struct creator_softc *sc; sc = (struct creator_softc *)adp; creator_ras_setpmask(sc, 0xffffffff); creator_ras_fifo_wait(sc, 2); FFB_WRITE(sc, FFB_FBC, FFB_FBC_ROP, FBC_ROP_NEW); FFB_WRITE(sc, FFB_FBC, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE); creator_ras_setfg(sc, creator_cmap[val & 0xf]); /* * Note that at least the Elite3D cards are sensitive to the order * of operations here. */ creator_ras_fifo_wait(sc, 4); FFB_WRITE(sc, FFB_FBC, FFB_FBC_BY, y); FFB_WRITE(sc, FFB_FBC, FFB_FBC_BX, x); FFB_WRITE(sc, FFB_FBC, FFB_FBC_BH, cy); FFB_WRITE(sc, FFB_FBC, FFB_FBC_BW, cx); creator_ras_wait(sc); return (0); } static int creator_bitblt(video_adapter_t *adp, ...) { return (ENODEV); } static int creator_diag(video_adapter_t *adp, int level) { video_info_t info; fb_dump_adp_info(adp->va_name, adp, level); creator_get_info(adp, 0, &info); fb_dump_mode_info(adp->va_name, adp, &info, level); return (0); } static int creator_save_cursor_palette(video_adapter_t *adp, u_char *palette) { return (ENODEV); } static int creator_load_cursor_palette(video_adapter_t *adp, u_char *palette) { return (ENODEV); } static int creator_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n) { return (ENODEV); } static int creator_putp(video_adapter_t *adp, vm_offset_t off, u_int32_t p, u_int32_t a, int size, int bpp, int bit_ltor, int byte_ltor) { return (ENODEV); } static int creator_putc(video_adapter_t *adp, vm_offset_t off, u_int8_t c, u_int8_t a) { struct creator_softc *sc; const uint16_t *p; int row; int col; int i; sc = (struct creator_softc *)adp; row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; p = (const uint16_t *)sc->sc_font + (c * adp->va_info.vi_cheight); creator_ras_setfg(sc, creator_cmap[a & 0xf]); creator_ras_setbg(sc, creator_cmap[(a >> 4) & 0xf]); creator_ras_fifo_wait(sc, 1 + adp->va_info.vi_cheight); FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTXY, ((row + sc->sc_ymargin) << 16) | (col + sc->sc_xmargin)); creator_ras_setfontw(sc, adp->va_info.vi_cwidth); creator_ras_setfontinc(sc, 0x10000); for (i = 0; i < adp->va_info.vi_cheight; i++) { FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONT, *p++ << 16); } return (0); } static int creator_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len) { int i; for (i = 0; i < len; i++) { - (*vidsw[adp->va_index]->putc)(adp, off + i, s[i] & 0xff, - (s[i] & 0xff00) >> 8); + vidd_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8); } + return (0); } static int creator_putm(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image, u_int32_t pixel_mask, int size, int width) { struct creator_softc *sc; sc = (struct creator_softc *)adp; if (!(sc->sc_flags & CREATOR_CUREN)) { creator_cursor_install(sc); creator_cursor_enable(sc, 1); sc->sc_flags |= CREATOR_CUREN; } FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_POS); FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, ((y + sc->sc_ymargin) << 16) | (x + sc->sc_xmargin)); return (0); } /* * bus interface */ static int creator_bus_probe(device_t dev) { const char *name; phandle_t node; int type; name = ofw_bus_get_name(dev); node = ofw_bus_get_node(dev); if (strcmp(name, "SUNW,ffb") == 0) { if (OF_getprop(node, "board_type", &type, sizeof(type)) == -1) return (ENXIO); switch (type & 7) { case 0x0: device_set_desc(dev, "Creator"); break; case 0x3: device_set_desc(dev, "Creator3D"); break; default: return (ENXIO); } } else if (strcmp(name, "SUNW,afb") == 0) device_set_desc(dev, "Elite3D"); else return (ENXIO); return (BUS_PROBE_DEFAULT); } static int creator_bus_attach(device_t dev) { struct creator_softc *sc; video_adapter_t *adp; video_switch_t *sw; phandle_t node; int error; int rid; int unit; int i; node = ofw_bus_get_node(dev); if ((sc = (struct creator_softc *)vid_get_adapter(vid_find_adapter( CREATOR_DRIVER_NAME, 0))) != NULL && sc->sc_node == node) { device_printf(dev, "console\n"); device_set_softc(dev, sc); } else { sc = device_get_softc(dev); sc->sc_node = node; } adp = &sc->sc_va; /* * Allocate resources regardless of whether we are the console * and already obtained the bus tags and handles for the FFB_DAC * and FFB_FBC register banks in creator_configure() or not so * the resources are marked as taken in the respective RMAN. * The supported cards use either 15 (Creator, Elite3D?) or 24 * (Creator3D?) register banks. We make sure that we can also * allocate the resources for at least the FFB_DAC and FFB_FBC * banks here. We try but don't actually care whether we can * allocate more than these two resources and just limit the * range accessible via creator_fb_mmap() accordingly. */ for (i = 0; i < FFB_NREG; i++) { rid = i; sc->sc_reg[i] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->sc_reg[i] == NULL) { if (i <= FFB_FBC) { device_printf(dev, "cannot allocate resources\n"); error = ENXIO; goto fail; } break; } sc->sc_bt[i] = rman_get_bustag(sc->sc_reg[i]); sc->sc_bh[i] = rman_get_bushandle(sc->sc_reg[i]); } /* * The XFree86/Xorg sunffb(4) expects to be able to access the * memory spanned by the first and the last resource as one chunk * via creator_fb_mmap(), using offsets from the first resource, * even though the backing resources are actually non-continuous. * So make sure that the memory we provide is at least backed by * increasing resources. */ adp->va_mem_base = rman_get_start(sc->sc_reg[0]); for (i = 1; i < FFB_NREG && sc->sc_reg[i] != NULL && rman_get_start(sc->sc_reg[i]) > rman_get_start(sc->sc_reg[i - 1]); i++) ; adp->va_mem_size = rman_get_end(sc->sc_reg[i - 1]) - adp->va_mem_base + 1; if (!(sc->sc_flags & CREATOR_CONSOLE)) { if ((sw = vid_get_switch(CREATOR_DRIVER_NAME)) == NULL) { device_printf(dev, "cannot get video switch\n"); error = ENODEV; goto fail; } /* * During device configuration we don't necessarily probe * the adapter which is the console first so we can't use * the device unit number for the video adapter unit. The * worst case would be that we use the video adapter unit * 0 twice. As it doesn't really matter which unit number * the corresponding video adapter has just use the next * unused one. */ for (i = 0; i < devclass_get_maxunit(creator_devclass); i++) if (vid_find_adapter(CREATOR_DRIVER_NAME, i) < 0) break; if (strcmp(ofw_bus_get_name(dev), "SUNW,afb") == 0) sc->sc_flags |= CREATOR_AFB; if ((error = sw->init(i, adp, 0)) != 0) { device_printf(dev, "cannot initialize adapter\n"); goto fail; } } if (bootverbose) { if (sc->sc_flags & CREATOR_PAC1) device_printf(dev, "BT9068/PAC1 RAMDAC (%s cursor control)\n", sc->sc_flags & CREATOR_CURINV ? "inverted" : "normal"); else device_printf(dev, "BT498/PAC2 RAMDAC\n"); } device_printf(dev, "resolution %dx%d\n", sc->sc_width, sc->sc_height); unit = device_get_unit(dev); sc->sc_si = make_dev(&creator_fb_devsw, unit, UID_ROOT, GID_WHEEL, 0600, "fb%d", unit); sc->sc_si->si_drv1 = sc; EVENTHANDLER_REGISTER(shutdown_final, creator_shutdown, sc, SHUTDOWN_PRI_DEFAULT); return (0); fail: for (i = 0; i < FFB_NREG && sc->sc_reg[i] != NULL; i++) bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(sc->sc_reg[i]), sc->sc_reg[i]); return (error); } /* * /dev/fb interface */ static int creator_fb_open(struct cdev *dev, int flags, int mode, struct thread *td) { return (0); } static int creator_fb_close(struct cdev *dev, int flags, int mode, struct thread *td) { return (0); } static int creator_fb_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td) { struct creator_softc *sc; sc = dev->si_drv1; return (creator_ioctl(&sc->sc_va, cmd, data)); } static int creator_fb_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot) { struct creator_softc *sc; int i; /* * NB: This is a special implementation based on the /dev/fb * requirements of the XFree86/Xorg sunffb(4). */ sc = dev->si_drv1; for (i = 0; i < CREATOR_FB_MAP_SIZE; i++) { if (offset >= creator_fb_map[i].virt && offset < creator_fb_map[i].virt + creator_fb_map[i].size) { offset += creator_fb_map[i].phys - creator_fb_map[i].virt; if (offset >= sc->sc_va.va_mem_size) return (EINVAL); *paddr = sc->sc_bh[0] + offset; return (0); } } return (EINVAL); } /* * internal functions */ static void creator_cursor_enable(struct creator_softc *sc, int onoff) { int v; FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_CTRL); if (sc->sc_flags & CREATOR_CURINV) v = onoff ? FFB_DAC_CUR_CTRL_P0 | FFB_DAC_CUR_CTRL_P1 : 0; else v = onoff ? 0 : FFB_DAC_CUR_CTRL_P0 | FFB_DAC_CUR_CTRL_P1; FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, v); } static void creator_cursor_install(struct creator_softc *sc) { int i, j; creator_cursor_enable(sc, 0); FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_COLOR1); FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, 0xffffff); FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, 0x0); for (i = 0; i < 2; i++) { FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, i ? FFB_DAC_CUR_BITMAP_P0 : FFB_DAC_CUR_BITMAP_P1); for (j = 0; j < 64; j++) { FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, *(const uint32_t *)(&creator_mouse_pointer[j][0])); FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, *(const uint32_t *)(&creator_mouse_pointer[j][4])); } } } static void creator_shutdown(void *xsc) { struct creator_softc *sc = xsc; creator_cursor_enable(sc, 0); /* * In case this is the console set the cursor of the stdout * instance to the start of the last line so OFW output ends * up beneath what FreeBSD left on the screen. */ if (sc->sc_flags & CREATOR_CONSOLE) { OF_interpret("stdout @ is my-self 0 to column#", 0); OF_interpret("stdout @ is my-self #lines 1 - to line#", 0); } } Index: head/sys/dev/fb/fb.c =================================================================== --- head/sys/dev/fb/fb.c (revision 174984) +++ head/sys/dev/fb/fb.c (revision 174985) @@ -1,762 +1,761 @@ /*- * Copyright (c) 1999 Kazutaka YOKOTA * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer as * the first lines of this file unmodified. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_fb.h" #include #include #include #include #include #include #include #include #include #include #include #include #include SET_DECLARE(videodriver_set, const video_driver_t); /* local arrays */ /* * We need at least one entry each in order to initialize a video card * for the kernel console. The arrays will be increased dynamically * when necessary. */ static int vid_malloc; static int adapters = 1; static video_adapter_t *adp_ini; static video_adapter_t **adapter = &adp_ini; static video_switch_t *vidsw_ini; video_switch_t **vidsw = &vidsw_ini; #ifdef FB_INSTALL_CDEV static struct cdevsw *vidcdevsw_ini; static struct cdevsw **vidcdevsw = &vidcdevsw_ini; #endif #define ARRAY_DELTA 4 static int vid_realloc_array(void) { video_adapter_t **new_adp; video_switch_t **new_vidsw; #ifdef FB_INSTALL_CDEV struct cdevsw **new_cdevsw; #endif int newsize; int s; if (!vid_malloc) return ENOMEM; s = spltty(); newsize = ((adapters + ARRAY_DELTA)/ARRAY_DELTA)*ARRAY_DELTA; new_adp = malloc(sizeof(*new_adp)*newsize, M_DEVBUF, M_WAITOK | M_ZERO); new_vidsw = malloc(sizeof(*new_vidsw)*newsize, M_DEVBUF, M_WAITOK | M_ZERO); #ifdef FB_INSTALL_CDEV new_cdevsw = malloc(sizeof(*new_cdevsw)*newsize, M_DEVBUF, M_WAITOK | M_ZERO); #endif bcopy(adapter, new_adp, sizeof(*adapter)*adapters); bcopy(vidsw, new_vidsw, sizeof(*vidsw)*adapters); #ifdef FB_INSTALL_CDEV bcopy(vidcdevsw, new_cdevsw, sizeof(*vidcdevsw)*adapters); #endif if (adapters > 1) { free(adapter, M_DEVBUF); free(vidsw, M_DEVBUF); #ifdef FB_INSTALL_CDEV free(vidcdevsw, M_DEVBUF); #endif } adapter = new_adp; vidsw = new_vidsw; #ifdef FB_INSTALL_CDEV vidcdevsw = new_cdevsw; #endif adapters = newsize; splx(s); if (bootverbose) printf("fb: new array size %d\n", adapters); return 0; } static void vid_malloc_init(void *arg) { vid_malloc = TRUE; } SYSINIT(vid_mem, SI_SUB_KMEM, SI_ORDER_ANY, vid_malloc_init, NULL); /* * Low-level frame buffer driver functions * frame buffer subdrivers, such as the VGA driver, call these functions * to initialize the video_adapter structure and register it to the virtual * frame buffer driver `fb'. */ /* initialize the video_adapter_t structure */ void vid_init_struct(video_adapter_t *adp, char *name, int type, int unit) { adp->va_flags = 0; adp->va_name = name; adp->va_type = type; adp->va_unit = unit; } /* Register a video adapter */ int vid_register(video_adapter_t *adp) { const video_driver_t **list; const video_driver_t *p; int index; for (index = 0; index < adapters; ++index) { if (adapter[index] == NULL) break; } if (index >= adapters) { if (vid_realloc_array()) return -1; } adp->va_index = index; adp->va_token = NULL; SET_FOREACH(list, videodriver_set) { p = *list; if (strcmp(p->name, adp->va_name) == 0) { adapter[index] = adp; vidsw[index] = p->vidsw; return index; } } return -1; } int vid_unregister(video_adapter_t *adp) { if ((adp->va_index < 0) || (adp->va_index >= adapters)) return ENOENT; if (adapter[adp->va_index] != adp) return ENOENT; adapter[adp->va_index] = NULL; vidsw[adp->va_index] = NULL; return 0; } /* Get video I/O function table */ video_switch_t *vid_get_switch(char *name) { const video_driver_t **list; const video_driver_t *p; SET_FOREACH(list, videodriver_set) { p = *list; if (strcmp(p->name, name) == 0) return p->vidsw; } return NULL; } /* * Video card client functions * Video card clients, such as the console driver `syscons' and the frame * buffer cdev driver, use these functions to claim and release a card for * exclusive use. */ /* find the video card specified by a driver name and a unit number */ int vid_find_adapter(char *driver, int unit) { int i; for (i = 0; i < adapters; ++i) { if (adapter[i] == NULL) continue; if (strcmp("*", driver) && strcmp(adapter[i]->va_name, driver)) continue; if ((unit != -1) && (adapter[i]->va_unit != unit)) continue; return i; } return -1; } /* allocate a video card */ int vid_allocate(char *driver, int unit, void *id) { int index; int s; s = spltty(); index = vid_find_adapter(driver, unit); if (index >= 0) { if (adapter[index]->va_token) { splx(s); return -1; } adapter[index]->va_token = id; } splx(s); return index; } int vid_release(video_adapter_t *adp, void *id) { int error; int s; s = spltty(); if (adp->va_token == NULL) { error = EINVAL; } else if (adp->va_token != id) { error = EPERM; } else { adp->va_token = NULL; error = 0; } splx(s); return error; } /* Get a video adapter structure */ video_adapter_t *vid_get_adapter(int index) { if ((index < 0) || (index >= adapters)) return NULL; return adapter[index]; } /* Configure drivers: this is a backdoor for the console driver XXX */ int vid_configure(int flags) { const video_driver_t **list; const video_driver_t *p; SET_FOREACH(list, videodriver_set) { p = *list; if (p->configure != NULL) (*p->configure)(flags); } return 0; } /* * Virtual frame buffer cdev driver functions * The virtual frame buffer driver dispatches driver functions to * appropriate subdrivers. */ #define FB_DRIVER_NAME "fb" #ifdef FB_INSTALL_CDEV #if 0 /* experimental */ static devclass_t fb_devclass; static int fbprobe(device_t dev); static int fbattach(device_t dev); static device_method_t fb_methods[] = { DEVMETHOD(device_probe, fbprobe), DEVMETHOD(device_attach, fbattach), DEVMETHOD(bus_print_child, bus_generic_print_child), { 0, 0 } }; static driver_t fb_driver = { FB_DRIVER_NAME, fb_methods, 0, }; static int fbprobe(device_t dev) { int unit; unit = device_get_unit(dev); if (unit >= adapters) return ENXIO; if (adapter[unit] == NULL) return ENXIO; device_set_desc(dev, "generic frame buffer"); return 0; } static int fbattach(device_t dev) { printf("fbattach: about to attach children\n"); bus_generic_attach(dev); return 0; } #endif #define FB_UNIT(dev) minor(dev) #define FB_MKMINOR(unit) (u) #if 0 /* experimental */ static d_open_t fbopen; static d_close_t fbclose; static d_read_t fbread; static d_write_t fbwrite; static d_ioctl_t fbioctl; static d_mmap_t fbmmap; static struct cdevsw fb_cdevsw = { .d_version = D_VERSION, .d_flags = D_NEEDGIANT, .d_open = fbopen, .d_close = fbclose, .d_read = fbread, .d_write = fbwrite, .d_ioctl = fbioctl, .d_mmap = fbmmap, .d_name = FB_DRIVER_NAME, }; #endif static int fb_modevent(module_t mod, int type, void *data) { switch (type) { case MOD_LOAD: break; case MOD_UNLOAD: printf("fb module unload - not possible for this module type\n"); return EINVAL; default: return EOPNOTSUPP; } return 0; } static moduledata_t fb_mod = { "fb", fb_modevent, NULL }; DECLARE_MODULE(fb, fb_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); int fb_attach(int unit, video_adapter_t *adp, struct cdevsw *cdevsw) { int s; if (adp->va_index >= adapters) return EINVAL; if (adapter[adp->va_index] != adp) return EINVAL; s = spltty(); adp->va_minor = unit; vidcdevsw[adp->va_index] = cdevsw; splx(s); printf("fb%d at %s%d\n", adp->va_index, adp->va_name, adp->va_unit); return 0; } int fb_detach(int unit, video_adapter_t *adp, struct cdevsw *cdevsw) { int s; if (adp->va_index >= adapters) return EINVAL; if (adapter[adp->va_index] != adp) return EINVAL; if (vidcdevsw[adp->va_index] != cdevsw) return EINVAL; s = spltty(); vidcdevsw[adp->va_index] = NULL; splx(s); return 0; } /* * Generic frame buffer cdev driver functions * Frame buffer subdrivers may call these functions to implement common * driver functions. */ int genfbopen(genfb_softc_t *sc, video_adapter_t *adp, int flag, int mode, struct thread *td) { int s; s = spltty(); if (!(sc->gfb_flags & FB_OPEN)) sc->gfb_flags |= FB_OPEN; splx(s); return 0; } int genfbclose(genfb_softc_t *sc, video_adapter_t *adp, int flag, int mode, struct thread *td) { int s; s = spltty(); sc->gfb_flags &= ~FB_OPEN; splx(s); return 0; } int genfbread(genfb_softc_t *sc, video_adapter_t *adp, struct uio *uio, int flag) { int size; int offset; int error; int len; error = 0; size = adp->va_buffer_size/adp->va_info.vi_planes; while (uio->uio_resid > 0) { if (uio->uio_offset >= size) break; offset = uio->uio_offset%adp->va_window_size; len = imin(uio->uio_resid, size - uio->uio_offset); len = imin(len, adp->va_window_size - offset); if (len <= 0) break; - (*vidsw[adp->va_index]->set_win_org)(adp, uio->uio_offset); + vidd_set_win_org(adp, uio->uio_offset); error = uiomove((caddr_t)(adp->va_window + offset), len, uio); if (error) break; } return error; } int genfbwrite(genfb_softc_t *sc, video_adapter_t *adp, struct uio *uio, int flag) { return ENODEV; } int genfbioctl(genfb_softc_t *sc, video_adapter_t *adp, u_long cmd, caddr_t arg, int flag, struct thread *td) { int error; if (adp == NULL) /* XXX */ return ENXIO; - error = (*vidsw[adp->va_index]->ioctl)(adp, cmd, arg); + error = vidd_ioctl(adp, cmd, arg); if (error == ENOIOCTL) error = ENODEV; return error; } int genfbmmap(genfb_softc_t *sc, video_adapter_t *adp, vm_offset_t offset, vm_offset_t *paddr, int prot) { - return (*vidsw[adp->va_index]->mmap)(adp, offset, paddr, prot); + return vidd_mmap(adp, offset, paddr, prot); } #endif /* FB_INSTALL_CDEV */ static char *adapter_name(int type) { static struct { int type; char *name; } names[] = { { KD_MONO, "MDA" }, { KD_HERCULES, "Hercules" }, { KD_CGA, "CGA" }, { KD_EGA, "EGA" }, { KD_VGA, "VGA" }, { KD_PC98, "PC-98x1" }, { KD_TGA, "TGA" }, { -1, "Unknown" }, }; int i; for (i = 0; names[i].type != -1; ++i) if (names[i].type == type) break; return names[i].name; } /* * Generic low-level frame buffer functions * The low-level functions in the frame buffer subdriver may use these * functions. */ void fb_dump_adp_info(char *driver, video_adapter_t *adp, int level) { if (level <= 0) return; printf("%s%d: %s%d, %s, type:%s (%d), flags:0x%x\n", FB_DRIVER_NAME, adp->va_index, driver, adp->va_unit, adp->va_name, adapter_name(adp->va_type), adp->va_type, adp->va_flags); printf("%s%d: port:0x%lx-0x%lx, crtc:0x%lx, mem:0x%lx 0x%x\n", FB_DRIVER_NAME, adp->va_index, (u_long)adp->va_io_base, (u_long)adp->va_io_base + adp->va_io_size - 1, (u_long)adp->va_crtc_addr, (u_long)adp->va_mem_base, adp->va_mem_size); printf("%s%d: init mode:%d, bios mode:%d, current mode:%d\n", FB_DRIVER_NAME, adp->va_index, adp->va_initial_mode, adp->va_initial_bios_mode, adp->va_mode); printf("%s%d: window:%p size:%dk gran:%dk, buf:%p size:%dk\n", FB_DRIVER_NAME, adp->va_index, (void *)adp->va_window, (int)adp->va_window_size/1024, (int)adp->va_window_gran/1024, (void *)adp->va_buffer, (int)adp->va_buffer_size/1024); } void fb_dump_mode_info(char *driver, video_adapter_t *adp, video_info_t *info, int level) { if (level <= 0) return; printf("%s%d: %s, mode:%d, flags:0x%x ", driver, adp->va_unit, adp->va_name, info->vi_mode, info->vi_flags); if (info->vi_flags & V_INFO_GRAPHICS) printf("G %dx%dx%d, %d plane(s), font:%dx%d, ", info->vi_width, info->vi_height, info->vi_depth, info->vi_planes, info->vi_cwidth, info->vi_cheight); else printf("T %dx%d, font:%dx%d, ", info->vi_width, info->vi_height, info->vi_cwidth, info->vi_cheight); printf("win:0x%lx\n", (u_long)info->vi_window); } int fb_type(int adp_type) { static struct { int fb_type; int va_type; } types[] = { { FBTYPE_MDA, KD_MONO }, { FBTYPE_HERCULES, KD_HERCULES }, { FBTYPE_CGA, KD_CGA }, { FBTYPE_EGA, KD_EGA }, { FBTYPE_VGA, KD_VGA }, { FBTYPE_PC98, KD_PC98 }, { FBTYPE_TGA, KD_TGA }, }; int i; for (i = 0; i < sizeof(types)/sizeof(types[0]); ++i) { if (types[i].va_type == adp_type) return types[i].fb_type; } return -1; } int fb_commonioctl(video_adapter_t *adp, u_long cmd, caddr_t arg) { int error; int s; /* assert(adp != NULL) */ error = 0; s = spltty(); switch (cmd) { case FBIO_ADAPTER: /* get video adapter index */ *(int *)arg = adp->va_index; break; case FBIO_ADPTYPE: /* get video adapter type */ *(int *)arg = adp->va_type; break; case FBIO_ADPINFO: /* get video adapter info */ ((video_adapter_info_t *)arg)->va_index = adp->va_index; ((video_adapter_info_t *)arg)->va_type = adp->va_type; bcopy(adp->va_name, ((video_adapter_info_t *)arg)->va_name, imin(strlen(adp->va_name) + 1, sizeof(((video_adapter_info_t *)arg)->va_name))); ((video_adapter_info_t *)arg)->va_unit = adp->va_unit; ((video_adapter_info_t *)arg)->va_flags = adp->va_flags; ((video_adapter_info_t *)arg)->va_io_base = adp->va_io_base; ((video_adapter_info_t *)arg)->va_io_size = adp->va_io_size; ((video_adapter_info_t *)arg)->va_crtc_addr = adp->va_crtc_addr; ((video_adapter_info_t *)arg)->va_mem_base = adp->va_mem_base; ((video_adapter_info_t *)arg)->va_mem_size = adp->va_mem_size; ((video_adapter_info_t *)arg)->va_window #ifdef __i386__ = vtophys(adp->va_window); #else = adp->va_window; #endif ((video_adapter_info_t *)arg)->va_window_size = adp->va_window_size; ((video_adapter_info_t *)arg)->va_window_gran = adp->va_window_gran; ((video_adapter_info_t *)arg)->va_window_orig = adp->va_window_orig; ((video_adapter_info_t *)arg)->va_unused0 #ifdef __i386__ = (adp->va_buffer) ? vtophys(adp->va_buffer) : 0; #else = adp->va_buffer; #endif ((video_adapter_info_t *)arg)->va_buffer_size = adp->va_buffer_size; ((video_adapter_info_t *)arg)->va_mode = adp->va_mode; ((video_adapter_info_t *)arg)->va_initial_mode = adp->va_initial_mode; ((video_adapter_info_t *)arg)->va_initial_bios_mode = adp->va_initial_bios_mode; ((video_adapter_info_t *)arg)->va_line_width = adp->va_line_width; ((video_adapter_info_t *)arg)->va_disp_start.x = adp->va_disp_start.x; ((video_adapter_info_t *)arg)->va_disp_start.y = adp->va_disp_start.y; break; case FBIO_MODEINFO: /* get mode information */ - error = (*vidsw[adp->va_index]->get_info)(adp, - ((video_info_t *)arg)->vi_mode, - (video_info_t *)arg); + error = vidd_get_info(adp, + ((video_info_t *)arg)->vi_mode, + (video_info_t *)arg); if (error) error = ENODEV; break; case FBIO_FINDMODE: /* find a matching video mode */ - error = (*vidsw[adp->va_index]->query_mode)(adp, - (video_info_t *)arg); + error = vidd_query_mode(adp, (video_info_t *)arg); break; case FBIO_GETMODE: /* get video mode */ *(int *)arg = adp->va_mode; break; case FBIO_SETMODE: /* set video mode */ - error = (*vidsw[adp->va_index]->set_mode)(adp, *(int *)arg); + error = vidd_set_mode(adp, *(int *)arg); if (error) error = ENODEV; /* EINVAL? */ break; case FBIO_GETWINORG: /* get frame buffer window origin */ *(u_int *)arg = adp->va_window_orig; break; case FBIO_GETDISPSTART: /* get display start address */ ((video_display_start_t *)arg)->x = adp->va_disp_start.x; ((video_display_start_t *)arg)->y = adp->va_disp_start.y; break; case FBIO_GETLINEWIDTH: /* get scan line width in bytes */ *(u_int *)arg = adp->va_line_width; break; case FBIO_BLANK: /* blank display */ - error = (*vidsw[adp->va_index]->blank_display)(adp, *(int *)arg); + error = vidd_blank_display(adp, *(int *)arg); break; case FBIO_GETPALETTE: /* get color palette */ case FBIO_SETPALETTE: /* set color palette */ /* XXX */ case FBIOPUTCMAP: case FBIOGETCMAP: case FBIOPUTCMAPI: case FBIOGETCMAPI: /* XXX */ case FBIO_SETWINORG: /* set frame buffer window origin */ case FBIO_SETDISPSTART: /* set display start address */ case FBIO_SETLINEWIDTH: /* set scan line width in pixel */ case FBIOGTYPE: case FBIOGATTR: case FBIOSVIDEO: case FBIOGVIDEO: case FBIOVERTICAL: case FBIOSCURSOR: case FBIOGCURSOR: case FBIOSCURPOS: case FBIOGCURPOS: case FBIOGCURMAX: case FBIOMONINFO: case FBIOGXINFO: default: error = ENODEV; break; } splx(s); return error; } Index: head/sys/dev/fb/fbreg.h =================================================================== --- head/sys/dev/fb/fbreg.h (revision 174984) +++ head/sys/dev/fb/fbreg.h (revision 174985) @@ -1,280 +1,334 @@ /*- * Copyright (c) 1999 Kazutaka YOKOTA * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer as * the first lines of this file unmodified. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _DEV_FB_FBREG_H_ #define _DEV_FB_FBREG_H_ #ifdef _KERNEL #define V_MAX_ADAPTERS 8 /* XXX */ /* some macros */ #ifdef __i386__ #define bcopy_io(s, d, c) generic_bcopy((void *)(s), (void *)(d), (c)) #define bcopy_toio(s, d, c) generic_bcopy((void *)(s), (void *)(d), (c)) #define bcopy_fromio(s, d, c) generic_bcopy((void *)(s), (void *)(d), (c)) #define bzero_io(d, c) generic_bzero((void *)(d), (c)) #define fill_io(p, d, c) fill((p), (void *)(d), (c)) #define fillw_io(p, d, c) fillw((p), (void *)(d), (c)) void generic_bcopy(const void *s, void *d, size_t c); void generic_bzero(void *d, size_t c); #elif defined(__amd64__) #define bcopy_io(s, d, c) bcopy((void *)(s), (void *)(d), (c)) #define bcopy_toio(s, d, c) bcopy((void *)(s), (void *)(d), (c)) #define bcopy_fromio(s, d, c) bcopy((void *)(s), (void *)(d), (c)) #define bzero_io(d, c) bzero((void *)(d), (c)) #define fill_io(p, d, c) fill((p), (void *)(d), (c)) #define fillw_io(p, d, c) fillw((p), (void *)(d), (c)) #elif defined(__ia64__) || defined(__sparc64__) #if defined(__ia64__) #include #define bcopy_fromio(s, d, c) \ bus_space_read_region_1(IA64_BUS_SPACE_MEM, s, 0, (void*)(d), c) #define bcopy_io(s, d, c) \ bus_space_copy_region_1(IA64_BUS_SPACE_MEM, s, 0, d, 0, c) #define bcopy_toio(s, d, c) \ bus_space_write_region_1(IA64_BUS_SPACE_MEM, d, 0, (void*)(s), c) #define bzero_io(d, c) \ bus_space_set_region_1(IA64_BUS_SPACE_MEM, (intptr_t)(d), 0, 0, c) #define fill_io(p, d, c) \ bus_space_set_region_1(IA64_BUS_SPACE_MEM, (intptr_t)(d), 0, p, c) #define fillw_io(p, d, c) \ bus_space_set_region_2(IA64_BUS_SPACE_MEM, (intptr_t)(d), 0, p, c) #define readb(a) bus_space_read_1(IA64_BUS_SPACE_MEM, a, 0) #define readw(a) bus_space_read_2(IA64_BUS_SPACE_MEM, a, 0) #define writeb(a, v) bus_space_write_1(IA64_BUS_SPACE_MEM, a, 0, v) #define writew(a, v) bus_space_write_2(IA64_BUS_SPACE_MEM, a, 0, v) #define writel(a, v) bus_space_write_4(IA64_BUS_SPACE_MEM, a, 0, v) #endif /* __ia64__ */ static __inline void fillw(int val, uint16_t *buf, size_t size) { while (size--) *buf++ = val; } #elif defined(__powerpc__) #define bcopy_io(s, d, c) ofwfb_bcopy((void *)(s), (void *)(d), (c)) #define bcopy_toio(s, d, c) ofwfb_bcopy((void *)(s), (void *)(d), (c)) #define bcopy_fromio(s, d, c) ofwfb_bcopy((void *)(s), (void *)(d), (c)) #define bzero_io(d, c) ofwfb_bzero((void *)(d), (c)) #define fillw(p, d, c) ofwfb_fillw((p), (void *)(d), (c)) #define fillw_io(p, d, c) ofwfb_fillw((p), (void *)(d), (c)) #define readw(a) ofwfb_readw((u_int16_t *)(a)) #define writew(a, v) ofwfb_writew((u_int16_t *)(a), (v)) void ofwfb_bcopy(const void *s, void *d, size_t c); void ofwfb_bzero(void *d, size_t c); void ofwfb_fillw(int pat, void *base, size_t cnt); u_int16_t ofwfb_readw(u_int16_t *addr); void ofwfb_writew(u_int16_t *addr, u_int16_t val); #else /* !__i386__ && !__amd64__ && !__ia64__ && !__sparc64__ && !__powerpc__ */ #define bcopy_io(s, d, c) memcpy_io((d), (s), (c)) #define bcopy_toio(s, d, c) memcpy_toio((d), (void *)(s), (c)) #define bcopy_fromio(s, d, c) memcpy_fromio((void *)(d), (s), (c)) #define bzero_io(d, c) memset_io((d), 0, (c)) #define fill_io(p, d, c) memset_io((d), (p), (c)) #define fillw(p, d, c) memsetw((d), (p), (c)) #define fillw_io(p, d, c) memsetw_io((d), (p), (c)) #endif /* !__i386__ */ /* video function table */ typedef int vi_probe_t(int unit, video_adapter_t **adpp, void *arg, int flags); typedef int vi_init_t(int unit, video_adapter_t *adp, int flags); typedef int vi_get_info_t(video_adapter_t *adp, int mode, video_info_t *info); typedef int vi_query_mode_t(video_adapter_t *adp, video_info_t *info); typedef int vi_set_mode_t(video_adapter_t *adp, int mode); typedef int vi_save_font_t(video_adapter_t *adp, int page, int size, int width, u_char *data, int c, int count); typedef int vi_load_font_t(video_adapter_t *adp, int page, int size, int width, u_char *data, int c, int count); typedef int vi_show_font_t(video_adapter_t *adp, int page); typedef int vi_save_palette_t(video_adapter_t *adp, u_char *palette); typedef int vi_load_palette_t(video_adapter_t *adp, u_char *palette); typedef int vi_set_border_t(video_adapter_t *adp, int border); typedef int vi_save_state_t(video_adapter_t *adp, void *p, size_t size); typedef int vi_load_state_t(video_adapter_t *adp, void *p); typedef int vi_set_win_org_t(video_adapter_t *adp, off_t offset); typedef int vi_read_hw_cursor_t(video_adapter_t *adp, int *col, int *row); typedef int vi_set_hw_cursor_t(video_adapter_t *adp, int col, int row); typedef int vi_set_hw_cursor_shape_t(video_adapter_t *adp, int base, int height, int celsize, int blink); typedef int vi_blank_display_t(video_adapter_t *adp, int mode); /* defined in sys/fbio.h #define V_DISPLAY_ON 0 #define V_DISPLAY_BLANK 1 #define V_DISPLAY_STAND_BY 2 #define V_DISPLAY_SUSPEND 3 */ typedef int vi_mmap_t(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr, int prot); typedef int vi_ioctl_t(video_adapter_t *adp, u_long cmd, caddr_t data); typedef int vi_clear_t(video_adapter_t *adp); typedef int vi_fill_rect_t(video_adapter_t *adp, int val, int x, int y, int cx, int cy); typedef int vi_bitblt_t(video_adapter_t *adp, ...); typedef int vi_diag_t(video_adapter_t *adp, int level); typedef int vi_save_cursor_palette_t(video_adapter_t *adp, u_char *palette); typedef int vi_load_cursor_palette_t(video_adapter_t *adp, u_char *palette); typedef int vi_copy_t(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n); typedef int vi_putp_t(video_adapter_t *adp, vm_offset_t off, u_int32_t p, u_int32_t a, int size, int bpp, int bit_ltor, int byte_ltor); typedef int vi_putc_t(video_adapter_t *adp, vm_offset_t off, u_int8_t c, u_int8_t a); typedef int vi_puts_t(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len); typedef int vi_putm_t(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image, u_int32_t pixel_mask, int size, int width); typedef struct video_switch { vi_probe_t *probe; vi_init_t *init; vi_get_info_t *get_info; vi_query_mode_t *query_mode; vi_set_mode_t *set_mode; vi_save_font_t *save_font; vi_load_font_t *load_font; vi_show_font_t *show_font; vi_save_palette_t *save_palette; vi_load_palette_t *load_palette; vi_set_border_t *set_border; vi_save_state_t *save_state; vi_load_state_t *load_state; vi_set_win_org_t *set_win_org; vi_read_hw_cursor_t *read_hw_cursor; vi_set_hw_cursor_t *set_hw_cursor; vi_set_hw_cursor_shape_t *set_hw_cursor_shape; vi_blank_display_t *blank_display; vi_mmap_t *mmap; vi_ioctl_t *ioctl; vi_clear_t *clear; vi_fill_rect_t *fill_rect; vi_bitblt_t *bitblt; int (*reserved1)(void); int (*reserved2)(void); vi_diag_t *diag; vi_save_cursor_palette_t *save_cursor_palette; vi_load_cursor_palette_t *load_cursor_palette; vi_copy_t *copy; vi_putp_t *putp; vi_putc_t *putc; vi_puts_t *puts; vi_putm_t *putm; } video_switch_t; -#define save_palette(adp, pal) \ - (*vidsw[(adp)->va_index]->save_palette)((adp), (pal)) -#define load_palette(adp, pal) \ - (*vidsw[(adp)->va_index]->load_palette)((adp), (pal)) -#define get_mode_info(adp, mode, buf) \ - (*vidsw[(adp)->va_index]->get_info)((adp), (mode), (buf)) -#define set_video_mode(adp, mode) \ +#define vidd_probe(unit, adpp, arg, flags) \ + (*vidsw[(adp)->va_index]->probe)((unit), (adpp), (arg), (flags)) +#define vidd_init(unit, adp, flags) \ + (*vidsw[(adp)->va_index]->init)((unit), (adp), (flags)) +#define vidd_get_info(adp, mode, info) \ + (*vidsw[(adp)->va_index]->get_info)((adp), (mode), (info)) +#define vidd_query_mode(adp, mode) \ + (*vidsw[(adp)->va_index]->query_mode)((adp), (mode)) +#define vidd_set_mode(adp, mode) \ (*vidsw[(adp)->va_index]->set_mode)((adp), (mode)) -#define set_border(adp, border) \ +#define vidd_save_font(adp, page, size, width, data, c, count) \ + (*vidsw[(adp)->va_index]->save_font)((adp), (page), (size), \ + (width), (data), (c), (count)) +#define vidd_load_font(adp, page, size, width, data, c, count) \ + (*vidsw[(adp)->va_index]->load_font)((adp), (page), (size), \ + (width), (data), (c), (count)) +#define vidd_show_font(adp, page) \ + (*vidsw[(adp)->va_index]->show_font)((adp), (page)) +#define vidd_save_palette(adp, pallete) \ + (*vidsw[(adp)->va_index]->save_palette)((adp), (pallete)) +#define vidd_load_palette(adp, pallete) \ + (*vidsw[(adp)->va_index]->load_palette)((adp), (pallete)) +#define vidd_set_border(adp, border) \ (*vidsw[(adp)->va_index]->set_border)((adp), (border)) -#define set_origin(adp, o) \ - (*vidsw[(adp)->va_index]->set_win_org)(adp, o) - -/* XXX - add more macros */ +#define vidd_save_state(adp, p, size) \ + (*vidsw[(adp)->va_index]->save_state)((adp), (p), (size)) +#define vidd_load_state(adp, p) \ + (*vidsw[(adp)->va_index]->load_state)((adp), (p)) +#define vidd_set_win_org(adp, offset) \ + (*vidsw[(adp)->va_index]->set_win_org)((adp), (offset)) +#define vidd_read_hw_cursor(adp, col, row) \ + (*vidsw[(adp)->va_index]->read_hw_cursor)((adp), (col), (row)) +#define vidd_set_hw_cursor(adp, col, row) \ + (*vidsw[(adp)->va_index]->set_hw_cursor)((adp), (col), (row)) +#define vidd_set_hw_cursor_shape(adp, base, height, celsize, blink) \ + (*vidsw[(adp)->va_index]->set_hw_cursor_shape)((adp), (base), \ + (height), (celsize), (blink)) +#define vidd_blank_display(adp, mode) \ + (*vidsw[(adp)->va_index]->blank_display)((adp), (mode)) +#define vidd_mmap(adp, offset, paddr, prot) \ + (*vidsw[(adp)->va_index]->mmap)((adp), (offset), (paddr), (prot)) +#define vidd_ioctl(adp, cmd, data) \ + (*vidsw[(adp)->va_index]->ioctl)((adp), (cmd), (data)) +#define vidd_clear(adp) \ + (*vidsw[(adp)->va_index]->clear)((adp)) +#define vidd_fill_rect(adp, val, x, y, cx, cy) \ + (*vidsw[(adp)->va_index]->fill_rect)((adp), (val), (x), (y), \ + (cx), (cy)) +#define vidd_bitblt(adp, ...) \ + (*vidsw[(adp)->va_index]->bitblt)(adp, __VA_ARGS__) +#define vidd_diag(adp, level) \ + (*vidsw[(adp)->va_index]->diag)((adp), (level)) +#define vidd_save_cursor_palette(adp, palette) \ + (*vidsw[(adp)->va_index]->save_cursor_palette)((adp), (palette)) +#define vidd_load_cursor_palette(adp, palette) \ + (*vidsw[(adp)->va_index]->load_cursor_palette)((adp), (palette)) +#define vidd_copy(adp, src, dst, n) \ + (*vidsw[(adp)->va_index]->copy)((adp), (src), (dst), (n)) +#define vidd_putp(adp, offset, p, a, size, bpp, bit_ltor1, byte_ltor2) \ + (*vidsw[(adp)->va_index]->putp)((adp), (offset), (p), (a), \ + (size), (bpp), (bit_ltor1), (bit_ltor2)) +#define vidd_putc(adp, offset, c, a) \ + (*vidsw[(adp)->va_index]->putc)((adp), (offset), (c), (a)) +#define vidd_puts(adp, offset, s, len) \ + (*vidsw[(adp)->va_index]->puts)((adp), (offset), (s), (len)) +#define vidd_putm(adp, x, y, pixel_image, pixel_mask, size, width) \ + (*vidsw[(adp)->va_index]->putm)((adp), (x), (y), (pixel_image), \ + (pixel_mask), (size), (width)) /* video driver */ typedef struct video_driver { char *name; video_switch_t *vidsw; int (*configure)(int); /* backdoor for the console driver */ } video_driver_t; #define VIDEO_DRIVER(name, sw, config) \ static struct video_driver name##_driver = { \ #name, &sw, config \ }; \ DATA_SET(videodriver_set, name##_driver); /* global variables */ extern struct video_switch **vidsw; /* functions for the video card driver */ int vid_register(video_adapter_t *adp); int vid_unregister(video_adapter_t *adp); video_switch_t *vid_get_switch(char *name); void vid_init_struct(video_adapter_t *adp, char *name, int type, int unit); /* functions for the video card client */ int vid_allocate(char *driver, int unit, void *id); int vid_release(video_adapter_t *adp, void *id); int vid_find_adapter(char *driver, int unit); video_adapter_t *vid_get_adapter(int index); /* a backdoor for the console driver to tickle the video driver XXX */ int vid_configure(int flags); #define VIO_PROBE_ONLY (1 << 0) /* probe only, don't initialize */ #ifdef FB_INSTALL_CDEV /* virtual frame buffer driver functions */ int fb_attach(int unit, video_adapter_t *adp, struct cdevsw *cdevsw); int fb_detach(int unit, video_adapter_t *adp, struct cdevsw *cdevsw); /* generic frame buffer cdev driver functions */ typedef struct genfb_softc { int gfb_flags; /* flag/status bits */ #define FB_OPEN (1 << 0) } genfb_softc_t; int genfbopen(genfb_softc_t *sc, video_adapter_t *adp, int flag, int mode, struct thread *td); int genfbclose(genfb_softc_t *sc, video_adapter_t *adp, int flag, int mode, struct thread *td); int genfbread(genfb_softc_t *sc, video_adapter_t *adp, struct uio *uio, int flag); int genfbwrite(genfb_softc_t *sc, video_adapter_t *adp, struct uio *uio, int flag); int genfbioctl(genfb_softc_t *sc, video_adapter_t *adp, u_long cmd, caddr_t arg, int flag, struct thread *td); int genfbmmap(genfb_softc_t *sc, video_adapter_t *adp, vm_offset_t offset, vm_offset_t *paddr, int prot); #endif /* FB_INSTALL_CDEV */ /* generic low-level driver functions */ void fb_dump_adp_info(char *driver, video_adapter_t *adp, int level); void fb_dump_mode_info(char *driver, video_adapter_t *adp, video_info_t *info, int level); int fb_type(int adp_type); int fb_commonioctl(video_adapter_t *adp, u_long cmd, caddr_t arg); #endif /* _KERNEL */ #endif /* !_DEV_FB_FBREG_H_ */ Index: head/sys/dev/fb/machfb.c =================================================================== --- head/sys/dev/fb/machfb.c (revision 174984) +++ head/sys/dev/fb/machfb.c (revision 174985) @@ -1,1586 +1,1586 @@ /*- * Copyright (c) 2002 Bang Jun-Young * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * from: NetBSD: machfb.c,v 1.23 2005/03/07 21:45:24 martin Exp */ /*- * Copyright (c) 2005 Marius Strobl * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); /* * Driver for ATI Mach64 graphics chips. Some code is derived from the * ATI Rage Pro and Derivatives Programmer's Guide. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* #define MACHFB_DEBUG */ #define MACHFB_DRIVER_NAME "machfb" #define MACH64_REG_OFF 0x7ffc00 #define MACH64_REG_SIZE 1024 struct machfb_softc { video_adapter_t sc_va; /* must be first */ phandle_t sc_node; uint16_t sc_chip_id; uint8_t sc_chip_rev; int sc_memrid; int sc_viorid; int sc_vmemrid; struct resource *sc_memres; struct resource *sc_viores; struct resource *sc_vmemres; bus_space_tag_t sc_memt; bus_space_tag_t sc_regt; bus_space_tag_t sc_viot; bus_space_tag_t sc_vmemt; bus_space_handle_t sc_memh; bus_space_handle_t sc_regh; bus_space_handle_t sc_vioh; bus_space_handle_t sc_vmemh; int sc_height; int sc_width; int sc_depth; int sc_xmargin; int sc_ymargin; size_t sc_memsize; int sc_memtype; int sc_mem_freq; int sc_ramdac_freq; int sc_ref_freq; int sc_ref_div; int sc_mclk_post_div; int sc_mclk_fb_div; const u_char *sc_font; int sc_cbwidth; vm_offset_t sc_curoff; int sc_bg_cache; int sc_fg_cache; int sc_draw_cache; #define MACHFB_DRAW_CHAR (1 << 0) #define MACHFB_DRAW_FILLRECT (1 << 1) int sc_flags; #define MACHFB_CONSOLE (1 << 0) #define MACHFB_CUREN (1 << 1) #define MACHFB_DSP (1 << 2) }; static const struct { uint16_t chip_id; const char *name; uint32_t ramdac_freq; } machfb_info[] = { { ATI_MACH64_CT, "ATI Mach64 CT", 135000 }, { ATI_RAGE_PRO_AGP, "ATI 3D Rage Pro (AGP)", 230000 }, { ATI_RAGE_PRO_AGP1X, "ATI 3D Rage Pro (AGP 1x)", 230000 }, { ATI_RAGE_PRO_PCI_B, "ATI 3D Rage Pro Turbo", 230000 }, { ATI_RAGE_XC_PCI66, "ATI Rage XL (PCI66)", 230000 }, { ATI_RAGE_XL_AGP, "ATI Rage XL (AGP)", 230000 }, { ATI_RAGE_XC_AGP, "ATI Rage XC (AGP)", 230000 }, { ATI_RAGE_XL_PCI66, "ATI Rage XL (PCI66)", 230000 }, { ATI_RAGE_PRO_PCI_P, "ATI 3D Rage Pro", 230000 }, { ATI_RAGE_PRO_PCI_L, "ATI 3D Rage Pro (limited 3D)", 230000 }, { ATI_RAGE_XL_PCI, "ATI Rage XL", 230000 }, { ATI_RAGE_XC_PCI, "ATI Rage XC", 230000 }, { ATI_RAGE_II, "ATI 3D Rage I/II", 135000 }, { ATI_RAGE_IIP, "ATI 3D Rage II+", 200000 }, { ATI_RAGE_IIC_PCI, "ATI 3D Rage IIC", 230000 }, { ATI_RAGE_IIC_AGP_B, "ATI 3D Rage IIC (AGP)", 230000 }, { ATI_RAGE_IIC_AGP_P, "ATI 3D Rage IIC (AGP)", 230000 }, { ATI_RAGE_LT_PRO_AGP, "ATI 3D Rage LT Pro (AGP 133MHz)", 230000 }, { ATI_RAGE_MOB_M3_PCI, "ATI Rage Mobility M3", 230000 }, { ATI_RAGE_MOB_M3_AGP, "ATI Rage Mobility M3 (AGP)", 230000 }, { ATI_RAGE_LT, "ATI 3D Rage LT", 230000 }, { ATI_RAGE_LT_PRO_PCI, "ATI 3D Rage LT Pro", 230000 }, { ATI_RAGE_MOBILITY, "ATI Rage Mobility", 230000 }, { ATI_RAGE_L_MOBILITY, "ATI Rage L Mobility", 230000 }, { ATI_RAGE_LT_PRO, "ATI 3D Rage LT Pro", 230000 }, { ATI_RAGE_LT_PRO2, "ATI 3D Rage LT Pro", 230000 }, { ATI_RAGE_MOB_M1_PCI, "ATI Rage Mobility M1 (PCI)", 230000 }, { ATI_RAGE_L_MOB_M1_PCI, "ATI Rage L Mobility (PCI)", 230000 }, { ATI_MACH64_VT, "ATI Mach64 VT", 170000 }, { ATI_MACH64_VTB, "ATI Mach64 VTB", 200000 }, { ATI_MACH64_VT4, "ATI Mach64 VT4", 230000 } }; static const struct machfb_cmap { uint8_t red; uint8_t green; uint8_t blue; } machfb_default_cmap[16] = { {0x00, 0x00, 0x00}, /* black */ {0x00, 0x00, 0xff}, /* blue */ {0x00, 0xff, 0x00}, /* green */ {0x00, 0xc0, 0xc0}, /* cyan */ {0xff, 0x00, 0x00}, /* red */ {0xc0, 0x00, 0xc0}, /* magenta */ {0xc0, 0xc0, 0x00}, /* brown */ {0xc0, 0xc0, 0xc0}, /* light grey */ {0x80, 0x80, 0x80}, /* dark grey */ {0x80, 0x80, 0xff}, /* light blue */ {0x80, 0xff, 0x80}, /* light green */ {0x80, 0xff, 0xff}, /* light cyan */ {0xff, 0x80, 0x80}, /* light red */ {0xff, 0x80, 0xff}, /* light magenta */ {0xff, 0xff, 0x80}, /* yellow */ {0xff, 0xff, 0xff} /* white */ }; #define MACHFB_CMAP_OFF 16 static const u_char machfb_mouse_pointer_bits[64][8] = { { 0x00, 0x00, }, /* ............ */ { 0x80, 0x00, }, /* *........... */ { 0xc0, 0x00, }, /* **.......... */ { 0xe0, 0x00, }, /* ***......... */ { 0xf0, 0x00, }, /* ****........ */ { 0xf8, 0x00, }, /* *****....... */ { 0xfc, 0x00, }, /* ******...... */ { 0xfe, 0x00, }, /* *******..... */ { 0xff, 0x00, }, /* ********.... */ { 0xff, 0x80, }, /* *********... */ { 0xfc, 0xc0, }, /* ******..**.. */ { 0xdc, 0x00, }, /* **.***...... */ { 0x8e, 0x00, }, /* *...***..... */ { 0x0e, 0x00, }, /* ....***..... */ { 0x07, 0x00, }, /* .....***.... */ { 0x04, 0x00, }, /* .....*...... */ { 0x00, 0x00, }, /* ............ */ { 0x00, 0x00, }, /* ............ */ { 0x00, 0x00, }, /* ............ */ { 0x00, 0x00, }, /* ............ */ { 0x00, 0x00, }, /* ............ */ { 0x00, 0x00, }, /* ............ */ }; /* * Lookup table to perform a bit-swap of the mouse pointer bits, * map set bits to CUR_CLR0 and unset bits to transparent. */ static const u_char machfb_mouse_pointer_lut[] = { 0xaa, 0x2a, 0x8a, 0x0a, 0xa2, 0x22, 0x82, 0x02, 0xa8, 0x28, 0x88, 0x08, 0xa0, 0x20, 0x80, 0x00 }; static const char *machfb_memtype_names[] = { "(N/A)", "DRAM", "EDO DRAM", "EDO DRAM", "SDRAM", "SGRAM", "WRAM", "(unknown type)" }; extern const struct gfb_font gallant12x22; static struct machfb_softc machfb_softc; static struct bus_space_tag machfb_bst_store[1]; static device_probe_t machfb_pci_probe; static device_attach_t machfb_pci_attach; static device_detach_t machfb_pci_detach; static device_method_t machfb_methods[] = { /* Device interface */ DEVMETHOD(device_probe, machfb_pci_probe), DEVMETHOD(device_attach, machfb_pci_attach), DEVMETHOD(device_detach, machfb_pci_detach), { 0, 0 } }; static driver_t machfb_pci_driver = { MACHFB_DRIVER_NAME, machfb_methods, sizeof(struct machfb_softc), }; static devclass_t machfb_devclass; DRIVER_MODULE(machfb, pci, machfb_pci_driver, machfb_devclass, 0, 0); MODULE_DEPEND(machfb, pci, 1, 1, 1); static void machfb_cursor_enable(struct machfb_softc *, int); static int machfb_cursor_install(struct machfb_softc *); static int machfb_get_memsize(struct machfb_softc *); static void machfb_reset_engine(struct machfb_softc *); static void machfb_init_engine(struct machfb_softc *); #if 0 static void machfb_adjust_frame(struct machfb_softc *, int, int); #endif static void machfb_shutdown_final(void *); static void machfb_shutdown_reset(void *); static int machfb_configure(int); static vi_probe_t machfb_probe; static vi_init_t machfb_init; static vi_get_info_t machfb_get_info; static vi_query_mode_t machfb_query_mode; static vi_set_mode_t machfb_set_mode; static vi_save_font_t machfb_save_font; static vi_load_font_t machfb_load_font; static vi_show_font_t machfb_show_font; static vi_save_palette_t machfb_save_palette; static vi_load_palette_t machfb_load_palette; static vi_set_border_t machfb_set_border; static vi_save_state_t machfb_save_state; static vi_load_state_t machfb_load_state; static vi_set_win_org_t machfb_set_win_org; static vi_read_hw_cursor_t machfb_read_hw_cursor; static vi_set_hw_cursor_t machfb_set_hw_cursor; static vi_set_hw_cursor_shape_t machfb_set_hw_cursor_shape; static vi_blank_display_t machfb_blank_display; static vi_mmap_t machfb_mmap; static vi_ioctl_t machfb_ioctl; static vi_clear_t machfb_clear; static vi_fill_rect_t machfb_fill_rect; static vi_bitblt_t machfb_bitblt; static vi_diag_t machfb_diag; static vi_save_cursor_palette_t machfb_save_cursor_palette; static vi_load_cursor_palette_t machfb_load_cursor_palette; static vi_copy_t machfb_copy; static vi_putp_t machfb_putp; static vi_putc_t machfb_putc; static vi_puts_t machfb_puts; static vi_putm_t machfb_putm; static video_switch_t machfbvidsw = { .probe = machfb_probe, .init = machfb_init, .get_info = machfb_get_info, .query_mode = machfb_query_mode, .set_mode = machfb_set_mode, .save_font = machfb_save_font, .load_font = machfb_load_font, .show_font = machfb_show_font, .save_palette = machfb_save_palette, .load_palette = machfb_load_palette, .set_border = machfb_set_border, .save_state = machfb_save_state, .load_state = machfb_load_state, .set_win_org = machfb_set_win_org, .read_hw_cursor = machfb_read_hw_cursor, .set_hw_cursor = machfb_set_hw_cursor, .set_hw_cursor_shape = machfb_set_hw_cursor_shape, .blank_display = machfb_blank_display, .mmap = machfb_mmap, .ioctl = machfb_ioctl, .clear = machfb_clear, .fill_rect = machfb_fill_rect, .bitblt = machfb_bitblt, NULL, NULL, .diag = machfb_diag, .save_cursor_palette = machfb_save_cursor_palette, .load_cursor_palette = machfb_load_cursor_palette, .copy = machfb_copy, .putp = machfb_putp, .putc = machfb_putc, .puts = machfb_puts, .putm = machfb_putm }; VIDEO_DRIVER(machfb, machfbvidsw, machfb_configure); extern sc_rndr_sw_t txtrndrsw; RENDERER(machfb, 0, txtrndrsw, gfb_set); RENDERER_MODULE(machfb, gfb_set); /* * Inline functions for getting access to register aperture. */ static inline uint32_t regr(struct machfb_softc *, uint32_t); static inline uint8_t regrb(struct machfb_softc *, uint32_t); static inline void regw(struct machfb_softc *, uint32_t, uint32_t); static inline void regwb(struct machfb_softc *, uint32_t, uint8_t); static inline void regwb_pll(struct machfb_softc *, uint32_t, uint8_t); static inline uint32_t regr(struct machfb_softc *sc, uint32_t index) { return bus_space_read_4(sc->sc_regt, sc->sc_regh, index); } static inline uint8_t regrb(struct machfb_softc *sc, uint32_t index) { return bus_space_read_1(sc->sc_regt, sc->sc_regh, index); } static inline void regw(struct machfb_softc *sc, uint32_t index, uint32_t data) { bus_space_write_4(sc->sc_regt, sc->sc_regh, index, data); bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 4, BUS_SPACE_BARRIER_WRITE); } static inline void regwb(struct machfb_softc *sc, uint32_t index, uint8_t data) { bus_space_write_1(sc->sc_regt, sc->sc_regh, index, data); bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 1, BUS_SPACE_BARRIER_WRITE); } static inline void regwb_pll(struct machfb_softc *sc, uint32_t index, uint8_t data) { regwb(sc, CLOCK_CNTL + 1, (index << 2) | PLL_WR_EN); regwb(sc, CLOCK_CNTL + 2, data); regwb(sc, CLOCK_CNTL + 1, (index << 2) & ~PLL_WR_EN); } static inline void wait_for_fifo(struct machfb_softc *sc, uint8_t v) { while ((regr(sc, FIFO_STAT) & 0xffff) > (0x8000 >> v)) ; } static inline void wait_for_idle(struct machfb_softc *sc) { wait_for_fifo(sc, 16); while ((regr(sc, GUI_STAT) & 1) != 0) ; } /* * Inline functions for setting the background and foreground colors. */ static inline void machfb_setbg(struct machfb_softc *sc, int bg); static inline void machfb_setfg(struct machfb_softc *sc, int fg); static inline void machfb_setbg(struct machfb_softc *sc, int bg) { if (bg == sc->sc_bg_cache) return; sc->sc_bg_cache = bg; wait_for_fifo(sc, 1); regw(sc, DP_BKGD_CLR, bg + MACHFB_CMAP_OFF); } static inline void machfb_setfg(struct machfb_softc *sc, int fg) { if (fg == sc->sc_fg_cache) return; sc->sc_fg_cache = fg; wait_for_fifo(sc, 1); regw(sc, DP_FRGD_CLR, fg + MACHFB_CMAP_OFF); } /* * video driver interface */ static int machfb_configure(int flags) { struct machfb_softc *sc; phandle_t chosen, output; ihandle_t stdout; bus_addr_t addr; uint32_t id; int i, space; /* * For the high-level console probing return the number of * registered adapters. */ if (!(flags & VIO_PROBE_ONLY)) { for (i = 0; vid_find_adapter(MACHFB_DRIVER_NAME, i) >= 0; i++) ; return (i); } /* Low-level console probing and initialization. */ sc = &machfb_softc; if (sc->sc_va.va_flags & V_ADP_REGISTERED) goto found; if ((chosen = OF_finddevice("/chosen")) == -1) /* Quis contra nos? */ return (0); if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1) return (0); if ((output = OF_instance_to_package(stdout)) == -1) return (0); if ((OF_getprop(output, "vendor-id", &id, sizeof(id)) == -1) || id != ATI_VENDOR) return (0); if (OF_getprop(output, "device-id", &id, sizeof(id)) == -1) return (0); for (i = 0; i < sizeof(machfb_info) / sizeof(machfb_info[0]); i++) { if (id == machfb_info[i].chip_id) { sc->sc_flags = MACHFB_CONSOLE; sc->sc_node = output; sc->sc_chip_id = id; break; } } if (!(sc->sc_flags & MACHFB_CONSOLE)) return (0); if (OF_getprop(output, "revision-id", &sc->sc_chip_rev, sizeof(sc->sc_chip_rev)) == -1) return (0); if (OF_decode_addr(output, 0, &space, &addr) != 0) return (0); sc->sc_memt = &machfb_bst_store[0]; sc->sc_memh = sparc64_fake_bustag(space, addr, sc->sc_memt); sc->sc_regt = sc->sc_memt; bus_space_subregion(sc->sc_regt, sc->sc_memh, MACH64_REG_OFF, MACH64_REG_SIZE, &sc->sc_regh); if (machfb_init(0, &sc->sc_va, 0) < 0) return (0); found: /* Return number of found adapters. */ return (1); } static int machfb_probe(int unit, video_adapter_t **adpp, void *arg, int flags) { return (0); } static int machfb_init(int unit, video_adapter_t *adp, int flags) { struct machfb_softc *sc; phandle_t options; video_info_t *vi; char buf[32]; int i; uint8_t dac_mask, dac_rindex, dac_windex; sc = (struct machfb_softc *)adp; vi = &adp->va_info; if ((regr(sc, CONFIG_CHIP_ID) & 0xffff) != sc->sc_chip_id) return (ENXIO); sc->sc_ramdac_freq = 0; for (i = 0; i < sizeof(machfb_info) / sizeof(machfb_info[0]); i++) { if (sc->sc_chip_id == machfb_info[i].chip_id) { sc->sc_ramdac_freq = machfb_info[i].ramdac_freq; break; } } if (sc->sc_ramdac_freq == 0) return (ENXIO); if (sc->sc_chip_id == ATI_RAGE_II && sc->sc_chip_rev & 0x07) sc->sc_ramdac_freq = 170000; vid_init_struct(adp, MACHFB_DRIVER_NAME, -1, unit); if (OF_getprop(sc->sc_node, "height", &sc->sc_height, sizeof(sc->sc_height)) == -1) return (ENXIO); if (OF_getprop(sc->sc_node, "width", &sc->sc_width, sizeof(sc->sc_width)) == -1) return (ENXIO); if (OF_getprop(sc->sc_node, "depth", &sc->sc_depth, sizeof(sc->sc_depth)) == -1) return (ENXIO); if ((options = OF_finddevice("/options")) == -1) return (ENXIO); if (OF_getprop(options, "screen-#rows", buf, sizeof(buf)) == -1) return (ENXIO); vi->vi_height = strtol(buf, NULL, 10); if (OF_getprop(options, "screen-#columns", buf, sizeof(buf)) == -1) return (ENXIO); vi->vi_width = strtol(buf, NULL, 10); vi->vi_cwidth = gallant12x22.width; vi->vi_cheight = gallant12x22.height; vi->vi_flags = V_INFO_COLOR; vi->vi_mem_model = V_INFO_MM_OTHER; sc->sc_font = gallant12x22.data; sc->sc_cbwidth = howmany(vi->vi_cwidth, NBBY); /* width in bytes */ sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2; sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight)) / 2; if (sc->sc_chip_id != ATI_MACH64_CT && !((sc->sc_chip_id == ATI_MACH64_VT || sc->sc_chip_id == ATI_RAGE_II) && (sc->sc_chip_rev & 0x07) == 0)) sc->sc_flags |= MACHFB_DSP; sc->sc_memsize = machfb_get_memsize(sc); if (sc->sc_memsize == 8192) /* The last page is used as register aperture. */ sc->sc_memsize -= 4; sc->sc_memtype = regr(sc, CONFIG_STAT0) & 0x07; if ((sc->sc_chip_id >= ATI_RAGE_XC_PCI66 && sc->sc_chip_id <= ATI_RAGE_XL_PCI66) || (sc->sc_chip_id >= ATI_RAGE_XL_PCI && sc->sc_chip_id <= ATI_RAGE_XC_PCI)) sc->sc_ref_freq = 29498; else sc->sc_ref_freq = 14318; regwb(sc, CLOCK_CNTL + 1, PLL_REF_DIV << 2); sc->sc_ref_div = regrb(sc, CLOCK_CNTL + 2); regwb(sc, CLOCK_CNTL + 1, MCLK_FB_DIV << 2); sc->sc_mclk_fb_div = regrb(sc, CLOCK_CNTL + 2); sc->sc_mem_freq = (2 * sc->sc_ref_freq * sc->sc_mclk_fb_div) / (sc->sc_ref_div * 2); sc->sc_mclk_post_div = (sc->sc_mclk_fb_div * 2 * sc->sc_ref_freq) / (sc->sc_mem_freq * sc->sc_ref_div); machfb_init_engine(sc); #if 0 mach64_adjust_frame(0, 0); #endif machfb_set_mode(adp, 0); /* * Install our 16-color color map. This is done only once and with * an offset of 16 on sparc64 as there the OBP driver expects white * to be at index 0 and black at 255 (some versions also use 1 - 8 * for color text support or the full palette for the boot banner * logo but no versions seems to use the ISO 6429-1983 color map). * Otherwise the colors are inverted when back in the OFW. */ dac_rindex = regrb(sc, DAC_RINDEX); dac_windex = regrb(sc, DAC_WINDEX); dac_mask = regrb(sc, DAC_MASK); regwb(sc, DAC_MASK, 0xff); regwb(sc, DAC_WINDEX, MACHFB_CMAP_OFF); for (i = 0; i < 16; i++) { regwb(sc, DAC_DATA, machfb_default_cmap[i].red); regwb(sc, DAC_DATA, machfb_default_cmap[i].green); regwb(sc, DAC_DATA, machfb_default_cmap[i].blue); } regwb(sc, DAC_MASK, dac_mask); regwb(sc, DAC_RINDEX, dac_rindex); regwb(sc, DAC_WINDEX, dac_windex); machfb_blank_display(adp, V_DISPLAY_ON); machfb_clear(adp); /* * Setting V_ADP_MODECHANGE serves as hack so machfb_set_mode() * (which will invalidate our caches) is called as a precaution * when the X server shuts down. */ adp->va_flags |= V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_PALETTE | V_ADP_BORDER | V_ADP_INITIALIZED; if (vid_register(adp) < 0) return (ENXIO); adp->va_flags |= V_ADP_REGISTERED; return (0); } static int machfb_get_info(video_adapter_t *adp, int mode, video_info_t *info) { bcopy(&adp->va_info, info, sizeof(*info)); return (0); } static int machfb_query_mode(video_adapter_t *adp, video_info_t *info) { return (ENODEV); } static int machfb_set_mode(video_adapter_t *adp, int mode) { struct machfb_softc *sc; sc = (struct machfb_softc *)adp; sc->sc_bg_cache = -1; sc->sc_fg_cache = -1; sc->sc_draw_cache = -1; return (0); } static int machfb_save_font(video_adapter_t *adp, int page, int size, int width, u_char *data, int c, int count) { return (ENODEV); } static int machfb_load_font(video_adapter_t *adp, int page, int size, int width, u_char *data, int c, int count) { return (ENODEV); } static int machfb_show_font(video_adapter_t *adp, int page) { return (ENODEV); } static int machfb_save_palette(video_adapter_t *adp, u_char *palette) { struct machfb_softc *sc; int i; uint8_t dac_mask, dac_rindex, dac_windex; sc = (struct machfb_softc *)adp; dac_rindex = regrb(sc, DAC_RINDEX); dac_windex = regrb(sc, DAC_WINDEX); dac_mask = regrb(sc, DAC_MASK); regwb(sc, DAC_MASK, 0xff); regwb(sc, DAC_RINDEX, 0x0); for (i = 0; i < 256 * 3; i++) palette[i] = regrb(sc, DAC_DATA); regwb(sc, DAC_MASK, dac_mask); regwb(sc, DAC_RINDEX, dac_rindex); regwb(sc, DAC_WINDEX, dac_windex); return (0); } static int machfb_load_palette(video_adapter_t *adp, u_char *palette) { struct machfb_softc *sc; int i; uint8_t dac_mask, dac_rindex, dac_windex; sc = (struct machfb_softc *)adp; dac_rindex = regrb(sc, DAC_RINDEX); dac_windex = regrb(sc, DAC_WINDEX); dac_mask = regrb(sc, DAC_MASK); regwb(sc, DAC_MASK, 0xff); regwb(sc, DAC_WINDEX, 0x0); for (i = 0; i < 256 * 3; i++) regwb(sc, DAC_DATA, palette[i]); regwb(sc, DAC_MASK, dac_mask); regwb(sc, DAC_RINDEX, dac_rindex); regwb(sc, DAC_WINDEX, dac_windex); return (0); } static int machfb_set_border(video_adapter_t *adp, int border) { struct machfb_softc *sc; sc = (struct machfb_softc *)adp; machfb_fill_rect(adp, border, 0, 0, sc->sc_width, sc->sc_ymargin); machfb_fill_rect(adp, border, 0, sc->sc_height - sc->sc_ymargin, sc->sc_width, sc->sc_ymargin); machfb_fill_rect(adp, border, 0, 0, sc->sc_xmargin, sc->sc_height); machfb_fill_rect(adp, border, sc->sc_width - sc->sc_xmargin, 0, sc->sc_xmargin, sc->sc_height); return (0); } static int machfb_save_state(video_adapter_t *adp, void *p, size_t size) { return (ENODEV); } static int machfb_load_state(video_adapter_t *adp, void *p) { return (ENODEV); } static int machfb_set_win_org(video_adapter_t *adp, off_t offset) { return (ENODEV); } static int machfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row) { *col = 0; *row = 0; return (0); } static int machfb_set_hw_cursor(video_adapter_t *adp, int col, int row) { return (ENODEV); } static int machfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, int celsize, int blink) { return (ENODEV); } static int machfb_blank_display(video_adapter_t *adp, int mode) { struct machfb_softc *sc; uint32_t crtc_gen_cntl; sc = (struct machfb_softc *)adp; crtc_gen_cntl = (regr(sc, CRTC_GEN_CNTL) | CRTC_EXT_DISP_EN | CRTC_EN) & ~(CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS); switch (mode) { case V_DISPLAY_ON: break; case V_DISPLAY_BLANK: crtc_gen_cntl |= CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS; break; case V_DISPLAY_STAND_BY: crtc_gen_cntl |= CRTC_HSYNC_DIS | CRTC_DISPLAY_DIS; break; case V_DISPLAY_SUSPEND: crtc_gen_cntl |= CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS; break; } regw(sc, CRTC_GEN_CNTL, crtc_gen_cntl); return (0); } static int machfb_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr, int prot) { struct machfb_softc *sc; sc = (struct machfb_softc *)adp; if (adp->va_io_base != 0 && offset >= adp->va_io_base && offset < adp->va_io_base + adp->va_io_size) { *paddr = sc->sc_vioh + offset - adp->va_io_size; return (0); } if (adp->va_mem_base != 0 && offset >= adp->va_mem_base && offset < adp->va_mem_base + adp->va_mem_size) { *paddr = sc->sc_vmemh + offset - adp->va_mem_base; return (0); } if (offset >= adp->va_registers && offset < adp->va_registers + adp->va_registers_size) { *paddr = sc->sc_memh + offset - adp->va_registers; return (0); } /* 'regular' framebuffer mmap()ing */ if (offset < adp->va_window_size) { *paddr = adp->va_window + offset; return (0); } return (EINVAL); } static int machfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data) { struct machfb_softc *sc; struct fbcursor *fbc; struct fbtype *fb; sc = (struct machfb_softc *)adp; switch (cmd) { case FBIOGTYPE: fb = (struct fbtype *)data; fb->fb_type = FBTYPE_PCIMISC; fb->fb_height = sc->sc_height; fb->fb_width = sc->sc_width; fb->fb_depth = sc->sc_depth; if (sc->sc_depth <= 1 || sc->sc_depth > 8) fb->fb_cmsize = 0; else fb->fb_cmsize = 1 << sc->sc_depth; fb->fb_size = adp->va_buffer_size; break; case FBIOSCURSOR: fbc = (struct fbcursor *)data; if (fbc->set & FB_CUR_SETCUR && fbc->enable == 0) { machfb_cursor_enable(sc, 0); sc->sc_flags &= ~MACHFB_CUREN; } else return (ENODEV); break; default: return (fb_commonioctl(adp, cmd, data)); } return (0); } static int machfb_clear(video_adapter_t *adp) { struct machfb_softc *sc; sc = (struct machfb_softc *)adp; machfb_fill_rect(adp, (SC_NORM_ATTR >> 4) & 0xf, 0, 0, sc->sc_width, sc->sc_height); return (0); } static int machfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) { struct machfb_softc *sc; sc = (struct machfb_softc *)adp; if (sc->sc_draw_cache != MACHFB_DRAW_FILLRECT) { wait_for_fifo(sc, 7); regw(sc, DP_WRITE_MASK, 0xff); regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_8BPP | HOST_8BPP); regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR); regw(sc, DP_MIX, MIX_SRC << 16); regw(sc, CLR_CMP_CNTL, 0); /* no transparency */ regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT); regw(sc, DST_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM); sc->sc_draw_cache = MACHFB_DRAW_FILLRECT; } machfb_setfg(sc, val); wait_for_fifo(sc, 4); regw(sc, SRC_Y_X, (x << 16) | y); regw(sc, SRC_WIDTH1, cx); regw(sc, DST_Y_X, (x << 16) | y); regw(sc, DST_HEIGHT_WIDTH, (cx << 16) | cy); return (0); } static int machfb_bitblt(video_adapter_t *adp, ...) { return (ENODEV); } static int machfb_diag(video_adapter_t *adp, int level) { video_info_t info; fb_dump_adp_info(adp->va_name, adp, level); machfb_get_info(adp, 0, &info); fb_dump_mode_info(adp->va_name, adp, &info, level); return (0); } static int machfb_save_cursor_palette(video_adapter_t *adp, u_char *palette) { return (ENODEV); } static int machfb_load_cursor_palette(video_adapter_t *adp, u_char *palette) { return (ENODEV); } static int machfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n) { return (ENODEV); } static int machfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a, int size, int bpp, int bit_ltor, int byte_ltor) { return (ENODEV); } static int machfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a) { struct machfb_softc *sc; const uint8_t *p; int i; sc = (struct machfb_softc *)adp; if (sc->sc_draw_cache != MACHFB_DRAW_CHAR) { wait_for_fifo(sc, 8); regw(sc, DP_WRITE_MASK, 0xff); /* XXX only good for 8 bit */ regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_1BPP | HOST_1BPP); regw(sc, DP_SRC, MONO_SRC_HOST | BKGD_SRC_BKGD_CLR | FRGD_SRC_FRGD_CLR); regw(sc, DP_MIX ,((MIX_SRC & 0xffff) << 16) | MIX_SRC); regw(sc, CLR_CMP_CNTL, 0); /* no transparency */ regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT); regw(sc, DST_CNTL, DST_Y_TOP_TO_BOTTOM | DST_X_LEFT_TO_RIGHT); regw(sc, HOST_CNTL, HOST_BYTE_ALIGN); sc->sc_draw_cache = MACHFB_DRAW_CHAR; } machfb_setbg(sc, (a >> 4) & 0xf); machfb_setfg(sc, a & 0xf); wait_for_fifo(sc, 4 + (adp->va_info.vi_cheight / sc->sc_cbwidth)); regw(sc, SRC_Y_X, 0); regw(sc, SRC_WIDTH1, adp->va_info.vi_cwidth); regw(sc, DST_Y_X, ((((off % adp->va_info.vi_width) * adp->va_info.vi_cwidth) + sc->sc_xmargin) << 16) | (((off / adp->va_info.vi_width) * adp->va_info.vi_cheight) + sc->sc_ymargin)); regw(sc, DST_HEIGHT_WIDTH, (adp->va_info.vi_cwidth << 16) | adp->va_info.vi_cheight); p = sc->sc_font + (c * adp->va_info.vi_cheight * sc->sc_cbwidth); for (i = 0; i < adp->va_info.vi_cheight * sc->sc_cbwidth; i += 4) regw(sc, HOST_DATA0 + i, (p[i + 3] << 24 | p[i + 2] << 16 | p[i + 1] << 8 | p[i])); return (0); } static int machfb_puts(video_adapter_t *adp, vm_offset_t off, uint16_t *s, int len) { struct machfb_softc *sc; int blanks, i, x1, x2, y1, y2; uint8_t a, c, color1, color2; sc = (struct machfb_softc *)adp; #define MACHFB_BLANK machfb_fill_rect(adp, color1, x1, y1, \ blanks * adp->va_info.vi_cwidth, \ adp->va_info.vi_cheight) blanks = color1 = x1 = y1 = 0; for (i = 0; i < len; i++) { /* * Accelerate continuous blanks by drawing a respective * rectangle instead. Drawing a rectangle of any size * takes about the same number of operations as drawing * a single character. */ c = s[i] & 0xff; a = (s[i] & 0xff00) >> 8; if (c == 0x00 || c == 0x20 || c == 0xdb || c == 0xff) { color2 = (a >> (c == 0xdb ? 0 : 4) & 0xf); x2 = (((off + i) % adp->va_info.vi_width) * adp->va_info.vi_cwidth) + sc->sc_xmargin; y2 = (((off + i) / adp->va_info.vi_width) * adp->va_info.vi_cheight) + sc->sc_ymargin; if (blanks == 0) { color1 = color2; x1 = x2; y1 = y2; blanks++; } else if (color1 != color2 || y1 != y2) { MACHFB_BLANK; color1 = color2; x1 = x2; y1 = y2; blanks = 1; } else blanks++; } else { if (blanks != 0) { MACHFB_BLANK; blanks = 0; } - (*vidsw[adp->va_index]->putc)(adp, off + i, c, a); + vidd_putc(adp, off + i, c, a); } } if (blanks != 0) MACHFB_BLANK; #undef MACHFB_BLANK return (0); } static int machfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image, uint32_t pixel_mask, int size, int width) { struct machfb_softc *sc; int error; sc = (struct machfb_softc *)adp; if ((!(sc->sc_flags & MACHFB_CUREN)) && (error = machfb_cursor_install(sc)) < 0) return (error); else { /* * The hardware cursor always must be disabled when * fiddling with its bits otherwise some artifacts * may appear on the screen. */ machfb_cursor_enable(sc, 0); } regw(sc, CUR_HORZ_VERT_OFF, 0); if ((regr(sc, GEN_TEST_CNTL) & CRTC_DBL_SCAN_EN) != 0) y <<= 1; regw(sc, CUR_HORZ_VERT_POSN, ((y + sc->sc_ymargin) << 16) | (x + sc->sc_xmargin)); machfb_cursor_enable(sc, 1); sc->sc_flags |= MACHFB_CUREN; return (0); } /* * PCI bus interface */ static int machfb_pci_probe(device_t dev) { int i; if (pci_get_class(dev) != PCIC_DISPLAY || pci_get_subclass(dev) != PCIS_DISPLAY_VGA) return (ENXIO); for (i = 0; i < sizeof(machfb_info) / sizeof(machfb_info[0]); i++) { if (pci_get_device(dev) == machfb_info[i].chip_id) { device_set_desc(dev, machfb_info[i].name); return (BUS_PROBE_DEFAULT); } } return (ENXIO); } static int machfb_pci_attach(device_t dev) { struct machfb_softc *sc; video_adapter_t *adp; video_switch_t *sw; phandle_t node; uint32_t *p32, saved_value; uint8_t *p; int error, i; node = ofw_bus_get_node(dev); if ((sc = (struct machfb_softc *)vid_get_adapter(vid_find_adapter( MACHFB_DRIVER_NAME, 0))) != NULL && sc->sc_node == node) { device_printf(dev, "console\n"); device_set_softc(dev, sc); } else { sc = device_get_softc(dev); bzero(sc, sizeof(struct machfb_softc)); sc->sc_node = node; sc->sc_chip_id = pci_get_device(dev); sc->sc_chip_rev = pci_get_revid(dev); } adp = &sc->sc_va; /* * Regardless whether we are the console and already allocated * resources in machfb_configure() or not we have to allocate * them here (again) in order for rman_get_virtual() to work. */ /* Enable memory and IO access. */ pci_write_config(dev, PCIR_COMMAND, pci_read_config(dev, PCIR_COMMAND, 2) | PCIM_CMD_PORTEN | PCIM_CMD_MEMEN, 2); sc->sc_memrid = PCIR_BAR(0); if ((sc->sc_memres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_memrid, RF_ACTIVE)) == NULL) { device_printf(dev, "cannot allocate memory resources\n"); return (ENXIO); } sc->sc_memt = rman_get_bustag(sc->sc_memres); sc->sc_memh = rman_get_bushandle(sc->sc_memres); adp->va_registers = rman_get_start(sc->sc_memres); adp->va_registers_size = rman_get_size(sc->sc_memres); sc->sc_regt = sc->sc_memt; bus_space_subregion(sc->sc_regt, sc->sc_memh, MACH64_REG_OFF, MACH64_REG_SIZE, &sc->sc_regh); adp->va_buffer = (vm_offset_t)rman_get_virtual(sc->sc_memres); adp->va_buffer_size = rman_get_size(sc->sc_memres); /* * Depending on the firmware version the VGA I/O and/or memory * resources of the Mach64 chips come up disabled. We generally * enable them above (pci(4) actually already did this unless * pci_enable_io_modes is not set) but this doesn't necessarily * mean that we get valid ones. Invalid resources seem to have * in common that they start at address 0. We don't allocate * them in this case in order to avoid warnings in apb(4) and * crashes when using these invalid resources. Xorg is aware * of this and doesn't use the VGA resources in this case (but * demands them if they are valid). */ sc->sc_viorid = PCIR_BAR(1); if (bus_get_resource_start(dev, SYS_RES_IOPORT, sc->sc_viorid) != 0) { if ((sc->sc_viores = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->sc_viorid, RF_ACTIVE)) == NULL) { device_printf(dev, "cannot allocate VGA I/O resources\n"); error = ENXIO; goto fail_memres; } sc->sc_viot = rman_get_bustag(sc->sc_viores); sc->sc_vioh = rman_get_bushandle(sc->sc_viores); adp->va_io_base = rman_get_start(sc->sc_viores); adp->va_io_size = rman_get_size(sc->sc_viores); } sc->sc_vmemrid = PCIR_BAR(2); if (bus_get_resource_start(dev, SYS_RES_MEMORY, sc->sc_vmemrid) != 0) { if ((sc->sc_vmemres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->sc_vmemrid, RF_ACTIVE)) == NULL) { device_printf(dev, "cannot allocate VGA memory resources\n"); error = ENXIO; goto fail_viores; } sc->sc_vmemt = rman_get_bustag(sc->sc_vmemres); sc->sc_vmemh = rman_get_bushandle(sc->sc_vmemres); adp->va_mem_base = rman_get_start(sc->sc_vmemres); adp->va_mem_size = rman_get_size(sc->sc_vmemres); } device_printf(dev, "%d MB aperture at 0x%08x, %d KB registers at 0x%08x\n", (u_int)(adp->va_buffer_size / (1024 * 1024)), (u_int)adp->va_buffer, MACH64_REG_SIZE / 1024, (u_int)sc->sc_regh); if (!(sc->sc_flags & MACHFB_CONSOLE)) { if ((sw = vid_get_switch(MACHFB_DRIVER_NAME)) == NULL) { device_printf(dev, "cannot get video switch\n"); error = ENODEV; goto fail_vmemres; } /* * During device configuration we don't necessarily probe * the adapter which is the console first so we can't use * the device unit number for the video adapter unit. The * worst case would be that we use the video adapter unit * 0 twice. As it doesn't really matter which unit number * the corresponding video adapter has just use the next * unused one. */ for (i = 0; i < devclass_get_maxunit(machfb_devclass); i++) if (vid_find_adapter(MACHFB_DRIVER_NAME, i) < 0) break; if ((error = sw->init(i, adp, 0)) != 0) { device_printf(dev, "cannot initialize adapter\n"); goto fail_vmemres; } } device_printf(dev, "%ld KB %s %d.%d MHz, maximum RAMDAC clock %d MHz, %sDSP\n", (u_long)sc->sc_memsize, machfb_memtype_names[sc->sc_memtype], sc->sc_mem_freq / 1000, sc->sc_mem_freq % 1000, sc->sc_ramdac_freq / 1000, (sc->sc_flags & MACHFB_DSP) ? "" : "no "); device_printf(dev, "resolution %dx%d at %d bpp\n", sc->sc_width, sc->sc_height, sc->sc_depth); /* * Test whether the aperture is byte swapped or not, set * va_window and va_window_size as appropriate. */ p32 = (uint32_t *)adp->va_buffer; saved_value = *p32; p = (uint8_t *)adp->va_buffer; *p32 = 0x12345678; if (!(p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78)) { adp->va_window = adp->va_buffer + 0x800000; adp->va_window_size = adp->va_buffer_size - 0x800000; } else { adp->va_window = adp->va_buffer; adp->va_window_size = adp->va_buffer_size; } *p32 = saved_value; adp->va_window_gran = adp->va_window_size; /* * Allocate one page for the mouse pointer image at the end of * the little endian aperture, right before the memory mapped * registers that might also reside there. Must be done after * sc_memsize was set and possibly adjusted to account for the * memory mapped registers. */ sc->sc_curoff = (sc->sc_memsize * 1024) - PAGE_SIZE; sc->sc_memsize -= PAGE_SIZE / 1024; machfb_cursor_enable(sc, 0); /* Initialize with an all transparent image. */ memset((void *)(adp->va_buffer + sc->sc_curoff), 0xaa, PAGE_SIZE); /* * Register a handler that performs some cosmetic surgery like * turning off the mouse pointer on halt in preparation for * handing the screen over to the OFW. Register another handler * that turns off the CRTC when resetting, otherwise the OFW * boot command issued by cpu_reset() just doesn't work. */ EVENTHANDLER_REGISTER(shutdown_final, machfb_shutdown_final, sc, SHUTDOWN_PRI_DEFAULT); EVENTHANDLER_REGISTER(shutdown_reset, machfb_shutdown_reset, sc, SHUTDOWN_PRI_DEFAULT); return (0); fail_vmemres: if (sc->sc_vmemres != NULL) bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_vmemrid, sc->sc_vmemres); fail_viores: if (sc->sc_viores != NULL) bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_viorid, sc->sc_viores); fail_memres: bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_memrid, sc->sc_memres); return (error); } static int machfb_pci_detach(device_t dev) { return (EINVAL); } /* * internal functions */ static void machfb_cursor_enable(struct machfb_softc *sc, int onoff) { if (onoff) regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) | HWCURSOR_ENABLE); else regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) &~ HWCURSOR_ENABLE); } static int machfb_cursor_install(struct machfb_softc *sc) { uint16_t *p; uint8_t fg; int i, j; if (sc->sc_curoff == 0) return (ENODEV); machfb_cursor_enable(sc, 0); regw(sc, CUR_OFFSET, sc->sc_curoff >> 3); fg = SC_NORM_ATTR & 0xf; regw(sc, CUR_CLR0, machfb_default_cmap[fg].red << 24 | machfb_default_cmap[fg].green << 16 | machfb_default_cmap[fg].blue << 8); p = (uint16_t *)(sc->sc_va.va_buffer + sc->sc_curoff); for (i = 0; i < 64; i++) for (j = 0; j < 8; j++) *(p++) = machfb_mouse_pointer_lut[ machfb_mouse_pointer_bits[i][j] >> 4] | machfb_mouse_pointer_lut[ machfb_mouse_pointer_bits[i][j] & 0x0f] << 8; return (0); } static int machfb_get_memsize(struct machfb_softc *sc) { int tmp, memsize; int mem_tab[] = { 512, 1024, 2048, 4096, 6144, 8192, 12288, 16384 }; tmp = regr(sc, MEM_CNTL); #ifdef MACHFB_DEBUG printf("memcntl=0x%08x\n", tmp); #endif if (sc->sc_flags & MACHFB_DSP) { tmp &= 0x0000000f; if (tmp < 8) memsize = (tmp + 1) * 512; else if (tmp < 12) memsize = (tmp - 3) * 1024; else memsize = (tmp - 7) * 2048; } else memsize = mem_tab[tmp & 0x07]; return (memsize); } static void machfb_reset_engine(struct machfb_softc *sc) { /* Reset engine.*/ regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) & ~GUI_ENGINE_ENABLE); /* Enable engine. */ regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) | GUI_ENGINE_ENABLE); /* * Ensure engine is not locked up by clearing any FIFO or * host errors. */ regw(sc, BUS_CNTL, regr(sc, BUS_CNTL) | BUS_HOST_ERR_ACK | BUS_FIFO_ERR_ACK); } static void machfb_init_engine(struct machfb_softc *sc) { uint32_t pitch_value; pitch_value = sc->sc_width; if (sc->sc_depth == 24) pitch_value *= 3; machfb_reset_engine(sc); wait_for_fifo(sc, 14); regw(sc, CONTEXT_MASK, 0xffffffff); regw(sc, DST_OFF_PITCH, (pitch_value / 8) << 22); regw(sc, DST_Y_X, 0); regw(sc, DST_HEIGHT, 0); regw(sc, DST_BRES_ERR, 0); regw(sc, DST_BRES_INC, 0); regw(sc, DST_BRES_DEC, 0); regw(sc, DST_CNTL, DST_LAST_PEL | DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM); regw(sc, SRC_OFF_PITCH, (pitch_value / 8) << 22); regw(sc, SRC_Y_X, 0); regw(sc, SRC_HEIGHT1_WIDTH1, 1); regw(sc, SRC_Y_X_START, 0); regw(sc, SRC_HEIGHT2_WIDTH2, 1); regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT); wait_for_fifo(sc, 13); regw(sc, HOST_CNTL, 0); regw(sc, PAT_REG0, 0); regw(sc, PAT_REG1, 0); regw(sc, PAT_CNTL, 0); regw(sc, SC_LEFT, 0); regw(sc, SC_TOP, 0); regw(sc, SC_BOTTOM, sc->sc_height - 1); regw(sc, SC_RIGHT, pitch_value - 1); regw(sc, DP_BKGD_CLR, 0); regw(sc, DP_FRGD_CLR, 0xffffffff); regw(sc, DP_WRITE_MASK, 0xffffffff); regw(sc, DP_MIX, (MIX_SRC << 16) | MIX_DST); regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR); wait_for_fifo(sc, 3); regw(sc, CLR_CMP_CLR, 0); regw(sc, CLR_CMP_MASK, 0xffffffff); regw(sc, CLR_CMP_CNTL, 0); wait_for_fifo(sc, 2); switch (sc->sc_depth) { case 8: regw(sc, DP_PIX_WIDTH, HOST_8BPP | SRC_8BPP | DST_8BPP); regw(sc, DP_CHAIN_MASK, DP_CHAIN_8BPP); regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN); break; #if 0 case 32: regw(sc, DP_PIX_WIDTH, HOST_32BPP | SRC_32BPP | DST_32BPP); regw(sc, DP_CHAIN_MASK, DP_CHAIN_32BPP); regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN); break; #endif } wait_for_fifo(sc, 2); regw(sc, CRTC_INT_CNTL, regr(sc, CRTC_INT_CNTL) & ~0x20); regw(sc, GUI_TRAJ_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM); wait_for_idle(sc); } #if 0 static void machfb_adjust_frame(struct machfb_softc *sc, int x, int y) { int offset; offset = ((x + y * sc->sc_width) * (sc->sc_depth >> 3)) >> 3; regw(sc, CRTC_OFF_PITCH, (regr(sc, CRTC_OFF_PITCH) & 0xfff00000) | offset); } #endif static void machfb_shutdown_final(void *v) { struct machfb_softc *sc = v; machfb_cursor_enable(sc, 0); /* * In case this is the console set the cursor of the stdout * instance to the start of the last line so OFW output ends * up beneath what FreeBSD left on the screen. */ if (sc->sc_flags & MACHFB_CONSOLE) { OF_interpret("stdout @ is my-self 0 to column#", 0); OF_interpret("stdout @ is my-self #lines 1 - to line#", 0); } } static void machfb_shutdown_reset(void *v) { struct machfb_softc *sc = v; machfb_blank_display(&sc->sc_va, V_DISPLAY_STAND_BY); } Index: head/sys/dev/fb/splash_bmp.c =================================================================== --- head/sys/dev/fb/splash_bmp.c (revision 174984) +++ head/sys/dev/fb/splash_bmp.c (revision 174985) @@ -1,643 +1,643 @@ /*- * Copyright (c) 1999 Michael Smith * Copyright (c) 1999 Kazutaka YOKOTA * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #ifndef PC98 #include #include #endif #define FADE_TIMEOUT 15 /* sec */ #define FADE_LEVELS 10 static int splash_mode = -1; static int splash_on = FALSE; static int bmp_start(video_adapter_t *adp); static int bmp_end(video_adapter_t *adp); static int bmp_splash(video_adapter_t *adp, int on); static int bmp_Init(char *data, int swidth, int sheight, int sdepth); static int bmp_Draw(video_adapter_t *adp); static splash_decoder_t bmp_decoder = { "splash_bmp", bmp_start, bmp_end, bmp_splash, SPLASH_IMAGE, }; SPLASH_DECODER(splash_bmp, bmp_decoder); static int bmp_start(video_adapter_t *adp) { /* currently only 256-color modes are supported XXX */ static int modes[] = { #ifdef PC98 /* * As 640x400 doesn't generally look great, * it's least preferred here. */ M_PC98_PEGC640x400, M_PC98_PEGC640x480, M_PC98_EGC640x400, #else M_VESA_CG640x480, M_VESA_CG800x600, M_VESA_CG1024x768, M_CG640x480, /* * As 320x200 doesn't generally look great, * it's least preferred here. */ M_VGA_CG320, #endif -1, }; video_info_t info; int i; if ((bmp_decoder.data == NULL) || (bmp_decoder.data_size <= 0)) { printf("splash_bmp: No bitmap file found\n"); return ENODEV; } for (i = 0; modes[i] >= 0; ++i) { - if (((*vidsw[adp->va_index]->get_info)(adp, modes[i], &info) == 0) - && (bmp_Init((u_char *)bmp_decoder.data, - info.vi_width, info.vi_height, info.vi_depth) == 0)) + if ((vidd_get_info(adp, modes[i], &info) == 0) && + (bmp_Init((u_char *)bmp_decoder.data, info.vi_width, + info.vi_height, info.vi_depth) == 0)) break; } splash_mode = modes[i]; if (splash_mode < 0) printf("splash_bmp: No appropriate video mode found\n"); if (bootverbose) printf("bmp_start(): splash_mode:%d\n", splash_mode); return ((splash_mode < 0) ? ENODEV : 0); } static int bmp_end(video_adapter_t *adp) { /* nothing to do */ return 0; } static int bmp_splash(video_adapter_t *adp, int on) { static u_char pal[256*3]; static long time_stamp; u_char tpal[256*3]; static int fading = TRUE, brightness = FADE_LEVELS; struct timeval tv; int i; if (on) { if (!splash_on) { /* set up the video mode and draw something */ - if ((*vidsw[adp->va_index]->set_mode)(adp, splash_mode)) + if (vidd_set_mode(adp, splash_mode)) return 1; if (bmp_Draw(adp)) return 1; - (*vidsw[adp->va_index]->save_palette)(adp, pal); + vidd_save_palette(adp, pal); time_stamp = 0; splash_on = TRUE; } /* * This is a kludge to fade the image away. This section of the * code takes effect only after the system is completely up. * FADE_TIMEOUT should be configurable. */ if (!cold) { getmicrotime(&tv); if (time_stamp == 0) time_stamp = tv.tv_sec; if (tv.tv_sec > time_stamp + FADE_TIMEOUT) { if (fading) if (brightness == 0) { fading = FALSE; brightness++; } else brightness--; else if (brightness == FADE_LEVELS) { fading = TRUE; brightness--; } else brightness++; for (i = 0; i < sizeof(pal); ++i) { tpal[i] = pal[i] * brightness / FADE_LEVELS; } - (*vidsw[adp->va_index]->load_palette)(adp, tpal); + vidd_load_palette(adp, tpal); time_stamp = tv.tv_sec; } } return 0; } else { /* the video mode will be restored by the caller */ splash_on = FALSE; return 0; } } /* ** Code to handle Microsoft DIB (".BMP") format images. ** ** Blame me (msmith@freebsd.org) if this is broken, not Soren. */ typedef struct tagBITMAPFILEHEADER { /* bmfh */ u_short bfType; int bfSize; u_short bfReserved1; u_short bfReserved2; int bfOffBits; } __packed BITMAPFILEHEADER; typedef struct tagBITMAPINFOHEADER { /* bmih */ int biSize; int biWidth; int biHeight; short biPlanes; short biBitCount; int biCompression; int biSizeImage; int biXPelsPerMeter; int biYPelsPerMeter; int biClrUsed; int biClrImportant; } __packed BITMAPINFOHEADER; typedef struct tagRGBQUAD { /* rgbq */ u_char rgbBlue; u_char rgbGreen; u_char rgbRed; u_char rgbReserved; } __packed RGBQUAD; typedef struct tagBITMAPINFO { /* bmi */ BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors[256]; } __packed BITMAPINFO; typedef struct tagBITMAPF { BITMAPFILEHEADER bmfh; BITMAPINFO bmfi; } __packed BITMAPF; #define BI_RGB 0 #define BI_RLE8 1 #define BI_RLE4 2 /* ** all we actually care about the image */ typedef struct { int width,height; /* image dimensions */ int swidth,sheight; /* screen dimensions for the current mode */ u_char depth; /* image depth (1, 4, 8, 24 bits) */ u_char sdepth; /* screen depth (1, 4, 8 bpp) */ int ncols; /* number of colours */ u_char palette[256][3]; /* raw palette data */ u_char format; /* one of the BI_* constants above */ u_char *data; /* pointer to the raw data */ u_char *index; /* running pointer to the data while drawing */ u_char *vidmem; /* video memory allocated for drawing */ video_adapter_t *adp; int bank; #ifdef PC98 u_char prev_val; #endif } BMP_INFO; static BMP_INFO bmp_info; /* ** bmp_SetPix ** ** Given (info), set the pixel at (x),(y) to (val) ** */ static void bmp_SetPix(BMP_INFO *info, int x, int y, u_char val) { int sofs, bofs; int newbank; /* * range check to avoid explosions */ if ((x < 0) || (x >= info->swidth) || (y < 0) || (y >= info->sheight)) return; /* * calculate offset into video memory; * because 0,0 is bottom-left for DIB, we have to convert. */ sofs = ((info->height - (y+1) + (info->sheight - info->height) / 2) * info->adp->va_line_width); x += (info->swidth - info->width) / 2; switch(info->sdepth) { #ifdef PC98 case 4: sofs += (x >> 3); bofs = x & 0x7; /* offset within byte */ outb(0x7c, 0x80 | 0x40); /* GRCG on & RMW mode */ if (val != info->prev_val) { outb(0x7e, (val & 1) ? 0xff : 0); /* tile B */ outb(0x7e, (val & 2) ? 0xff : 0); /* tile R */ outb(0x7e, (val & 4) ? 0xff : 0); /* tile G */ outb(0x7e, (val & 8) ? 0xff : 0); /* tile I */ info->prev_val = val; } *(info->vidmem+sofs) = (0x80 >> bofs); /* write new bit */ outb(0x7c, 0); /* GRCG off */ break; #else case 4: case 1: /* EGA/VGA planar modes */ sofs += (x >> 3); newbank = sofs/info->adp->va_window_size; if (info->bank != newbank) { - (*vidsw[info->adp->va_index]->set_win_org)(info->adp, newbank*info->adp->va_window_size); + vidd_set_win_org(info->adp, newbank*info->adp->va_window_size); info->bank = newbank; } sofs %= info->adp->va_window_size; bofs = x & 0x7; /* offset within byte */ outw(GDCIDX, (0x8000 >> bofs) | 0x08); /* bit mask */ outw(GDCIDX, (val << 8) | 0x00); /* set/reset */ *(info->vidmem + sofs) ^= 0xff; /* read-modify-write */ break; #endif case 8: sofs += x; newbank = sofs/info->adp->va_window_size; if (info->bank != newbank) { - (*vidsw[info->adp->va_index]->set_win_org)(info->adp, newbank*info->adp->va_window_size); + vidd_set_win_org(info->adp, newbank*info->adp->va_window_size); info->bank = newbank; } sofs %= info->adp->va_window_size; *(info->vidmem+sofs) = val; break; } } /* ** bmp_DecodeRLE4 ** ** Given (data) pointing to a line of RLE4-format data and (line) being the starting ** line onscreen, decode the line. */ static void bmp_DecodeRLE4(BMP_INFO *info, int line) { int count; /* run count */ u_char val; int x,y; /* screen position */ x = 0; /* starting position */ y = line; /* loop reading data */ for (;;) { /* * encoded mode starts with a run length, and then a byte with * two colour indexes to alternate between for the run */ if (*info->index) { for (count = 0; count < *info->index; count++, x++) { if (count & 1) { /* odd count, low nybble */ bmp_SetPix(info, x, y, *(info->index+1) & 0x0f); } else { /* even count, high nybble */ bmp_SetPix(info, x, y, (*(info->index+1) >>4) & 0x0f); } } info->index += 2; /* * A leading zero is an escape; it may signal the end of the * bitmap, a cursor move, or some absolute data. */ } else { /* zero tag may be absolute mode or an escape */ switch (*(info->index+1)) { case 0: /* end of line */ info->index += 2; return; case 1: /* end of bitmap */ info->index = NULL; return; case 2: /* move */ x += *(info->index + 2); /* new coords */ y += *(info->index + 3); info->index += 4; break; default: /* literal bitmap data */ for (count = 0; count < *(info->index + 1); count++, x++) { val = *(info->index + 2 + (count / 2)); /* byte with nybbles */ if (count & 1) { val &= 0xf; /* get low nybble */ } else { val = (val >> 4); /* get high nybble */ } bmp_SetPix(info, x, y, val); } /* warning, this depends on integer truncation, do not hand-optimise! */ info->index += 2 + ((count + 3) / 4) * 2; break; } } } } /* ** bmp_DecodeRLE8 ** Given (data) pointing to a line of RLE8-format data and (line) being the starting ** line onscreen, decode the line. */ static void bmp_DecodeRLE8(BMP_INFO *info, int line) { int count; /* run count */ int x,y; /* screen position */ x = 0; /* starting position */ y = line; /* loop reading data */ for(;;) { /* * encoded mode starts with a run length, and then a byte with * two colour indexes to alternate between for the run */ if (*info->index) { for (count = 0; count < *info->index; count++, x++) bmp_SetPix(info, x, y, *(info->index+1)); info->index += 2; /* * A leading zero is an escape; it may signal the end of the * bitmap, a cursor move, or some absolute data. */ } else { /* zero tag may be absolute mode or an escape */ switch(*(info->index+1)) { case 0: /* end of line */ info->index += 2; return; case 1: /* end of bitmap */ info->index = NULL; return; case 2: /* move */ x += *(info->index + 2); /* new coords */ y += *(info->index + 3); info->index += 4; break; default: /* literal bitmap data */ for (count = 0; count < *(info->index + 1); count++, x++) bmp_SetPix(info, x, y, *(info->index + 2 + count)); /* must be an even count */ info->index += 2 + count + (count & 1); break; } } } } /* ** bmp_DecodeLine ** ** Given (info) pointing to an image being decoded, (line) being the line currently ** being displayed, decode a line of data. */ static void bmp_DecodeLine(BMP_INFO *info, int line) { int x; u_char val, mask, *p; switch(info->format) { case BI_RGB: switch(info->depth) { case 8: for (x = 0; x < info->width; x++, info->index++) bmp_SetPix(info, x, line, *info->index); info->index += 3 - (--x % 4); break; case 4: p = info->index; for (x = 0; x < info->width; x++) { if (x & 1) { val = *p & 0xf; /* get low nybble */ p++; } else { val = *p >> 4; /* get high nybble */ } bmp_SetPix(info, x, line, val); } /* warning, this depends on integer truncation, do not hand-optimise! */ info->index += ((x + 7) / 8) * 4; break; case 1: p = info->index; mask = 0x80; for (x = 0; x < info->width; x++) { val = (*p & mask) ? 1 : 0; mask >>= 1; if (mask == 0) { mask = 0x80; p++; } bmp_SetPix(info, x, line, val); } /* warning, this depends on integer truncation, do not hand-optimise! */ info->index += ((x + 31) / 32) * 4; break; } break; case BI_RLE4: bmp_DecodeRLE4(info, line); break; case BI_RLE8: bmp_DecodeRLE8(info, line); break; } } /* ** bmp_Init ** ** Given a pointer (data) to the image of a BMP file, fill in bmp_info with what ** can be learnt from it. Return nonzero if the file isn't usable. ** ** Take screen dimensions (swidth), (sheight) and (sdepth) and make sure we ** can work with these. */ static int bmp_Init(char *data, int swidth, int sheight, int sdepth) { BITMAPF *bmf = (BITMAPF *)data; int pind; bmp_info.data = NULL; /* assume setup failed */ /* check file ID */ if (bmf->bmfh.bfType != 0x4d42) { printf("splash_bmp: not a BMP file\n"); return(1); /* XXX check word ordering for big-endian ports? */ } /* do we understand this bitmap format? */ if (bmf->bmfi.bmiHeader.biSize > sizeof(bmf->bmfi.bmiHeader)) { printf("splash_bmp: unsupported BMP format (size=%d)\n", bmf->bmfi.bmiHeader.biSize); return(1); } /* save what we know about the screen */ bmp_info.swidth = swidth; bmp_info.sheight = sheight; bmp_info.sdepth = sdepth; /* where's the data? */ bmp_info.data = (u_char *)data + bmf->bmfh.bfOffBits; /* image parameters */ bmp_info.width = bmf->bmfi.bmiHeader.biWidth; bmp_info.height = bmf->bmfi.bmiHeader.biHeight; bmp_info.depth = bmf->bmfi.bmiHeader.biBitCount; bmp_info.format = bmf->bmfi.bmiHeader.biCompression; switch(bmp_info.format) { /* check compression format */ case BI_RGB: case BI_RLE4: case BI_RLE8: break; default: printf("splash_bmp: unsupported compression format\n"); return(1); /* unsupported compression format */ } /* palette details */ bmp_info.ncols = (bmf->bmfi.bmiHeader.biClrUsed); bzero(bmp_info.palette,sizeof(bmp_info.palette)); if (bmp_info.ncols == 0) { /* uses all of them */ bmp_info.ncols = 1 << bmf->bmfi.bmiHeader.biBitCount; } if ((bmp_info.height > bmp_info.sheight) || (bmp_info.width > bmp_info.swidth) || (bmp_info.ncols > (1 << sdepth))) { if (bootverbose) printf("splash_bmp: beyond screen capacity (%dx%d, %d colors)\n", bmp_info.width, bmp_info.height, bmp_info.ncols); return(1); } /* read palette */ for (pind = 0; pind < bmp_info.ncols; pind++) { bmp_info.palette[pind][0] = bmf->bmfi.bmiColors[pind].rgbRed; bmp_info.palette[pind][1] = bmf->bmfi.bmiColors[pind].rgbGreen; bmp_info.palette[pind][2] = bmf->bmfi.bmiColors[pind].rgbBlue; } return(0); } /* ** bmp_Draw ** ** Render the image. Return nonzero if that's not possible. ** */ static int bmp_Draw(video_adapter_t *adp) { int line; #if 0 #ifndef PC98 int i; #endif #endif if (bmp_info.data == NULL) { /* init failed, do nothing */ return(1); } /* clear the screen */ bmp_info.vidmem = (u_char *)adp->va_window; bmp_info.adp = adp; - (*vidsw[adp->va_index]->clear)(adp); - (*vidsw[adp->va_index]->set_win_org)(adp, 0); + vidd_clear(adp); + vidd_set_win_org(adp, 0); bmp_info.bank = 0; /* initialise the info structure for drawing */ bmp_info.index = bmp_info.data; #ifdef PC98 bmp_info.prev_val = 255; #endif /* set the palette for our image */ - (*vidsw[adp->va_index]->load_palette)(adp, (u_char *)&bmp_info.palette); + vidd_load_palette(adp, (u_char *)&bmp_info.palette); #if 0 #ifndef PC98 /* XXX: this is ugly, but necessary for EGA/VGA 1bpp/4bpp modes */ if ((adp->va_type == KD_EGA) || (adp->va_type == KD_VGA)) { inb(adp->va_crtc_addr + 6); /* reset flip-flop */ outb(ATC, 0x14); outb(ATC, 0); for (i = 0; i < 16; ++i) { outb(ATC, i); outb(ATC, i); } inb(adp->va_crtc_addr + 6); /* reset flip-flop */ outb(ATC, 0x20); /* enable palette */ outw(GDCIDX, 0x0f01); /* set/reset enable */ if (bmp_info.sdepth == 1) outw(TSIDX, 0x0102); /* unmask plane #0 */ } #endif #endif for (line = 0; (line < bmp_info.height) && bmp_info.index; line++) { bmp_DecodeLine(&bmp_info, line); } return(0); } Index: head/sys/dev/fb/splash_pcx.c =================================================================== --- head/sys/dev/fb/splash_pcx.c (revision 174984) +++ head/sys/dev/fb/splash_pcx.c (revision 174985) @@ -1,271 +1,271 @@ /*- * Copyright (c) 1999 Michael Smith * Copyright (c) 1999 Kazutaka YOKOTA * Copyright (c) 1999 Dag-Erling Coïdan Smørgrav * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer * in this position and unchanged. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include static int splash_mode = -1; static int splash_on = FALSE; static int pcx_start(video_adapter_t *adp); static int pcx_end(video_adapter_t *adp); static int pcx_splash(video_adapter_t *adp, int on); static int pcx_init(void *data, int sdepth); static int pcx_draw(video_adapter_t *adp); static splash_decoder_t pcx_decoder = { .name = "splash_pcx", .init = pcx_start, .term = pcx_end, .splash = pcx_splash, .data_type = SPLASH_IMAGE, }; SPLASH_DECODER(splash_pcx, pcx_decoder); static struct { int width; int height; int bpsl; int bpp; int planes; int zlen; const uint8_t *zdata; uint8_t *palette; } pcx_info; static int pcx_start(video_adapter_t *adp) { static int modes[] = { M_VGA_CG320, M_VESA_CG640x480, M_VESA_CG800x600, M_VESA_CG1024x768, -1, }; video_info_t info; int i; if (pcx_decoder.data == NULL || pcx_decoder.data_size <= 0 || pcx_init(pcx_decoder.data, pcx_decoder.data_size)) return (ENODEV); if (bootverbose) printf("splash_pcx: image good:\n" " width = %d\n" " height = %d\n" " depth = %d\n" " planes = %d\n", pcx_info.width, pcx_info.height, pcx_info.bpp, pcx_info.planes); for (i = 0; modes[i] >= 0; ++i) { - if (get_mode_info(adp, modes[i], &info) != 0) + if (vidd_get_info(adp, modes[i], &info) != 0) continue; if (bootverbose) printf("splash_pcx: considering mode %d:\n" " vi_width = %d\n" " vi_height = %d\n" " vi_depth = %d\n" " vi_planes = %d\n", modes[i], info.vi_width, info.vi_height, info.vi_depth, info.vi_planes); if (info.vi_width >= pcx_info.width && info.vi_height >= pcx_info.height && info.vi_depth == pcx_info.bpp && info.vi_planes == pcx_info.planes) break; } splash_mode = modes[i]; if (splash_mode == -1) return (ENODEV); if (bootverbose) printf("splash_pcx: selecting mode %d\n", splash_mode); return (0); } static int pcx_end(video_adapter_t *adp) { /* nothing to do */ return (0); } static int pcx_splash(video_adapter_t *adp, int on) { if (on) { if (!splash_on) { - if (set_video_mode(adp, splash_mode) || pcx_draw(adp)) + if (vidd_set_mode(adp, splash_mode) || pcx_draw(adp)) return 1; splash_on = TRUE; } return (0); } else { splash_on = FALSE; return (0); } } struct pcx_header { uint8_t manufactor; uint8_t version; uint8_t encoding; uint8_t bpp; uint16_t xmin; uint16_t ymin; uint16_t xmax; uint16_t ymax; uint16_t hres; uint16_t vres; uint8_t colormap[48]; uint8_t rsvd; uint8_t nplanes; uint16_t bpsl; uint16_t palinfo; uint16_t hsize; uint16_t vsize; }; #define MAXSCANLINE 1024 static int pcx_init(void *data, int size) { const struct pcx_header *hdr = data; if (size < 128 + 1 + 1 + 768 || hdr->manufactor != 10 || hdr->version != 5 || hdr->encoding != 1 || hdr->nplanes != 1 || hdr->bpp != 8 || hdr->bpsl > MAXSCANLINE || ((uint8_t *)data)[size - 769] != 12) { printf("splash_pcx: invalid PCX image\n"); return (1); } pcx_info.width = hdr->xmax - hdr->xmin + 1; pcx_info.height = hdr->ymax - hdr->ymin + 1; pcx_info.bpsl = hdr->bpsl; pcx_info.bpp = hdr->bpp; pcx_info.planes = hdr->nplanes; pcx_info.zlen = size - (128 + 1 + 768); pcx_info.zdata = (uint8_t *)data + 128; pcx_info.palette = (uint8_t *)data + size - 768; return (0); } static int pcx_draw(video_adapter_t *adp) { uint8_t *vidmem; int swidth, sheight, sbpsl, sdepth, splanes; int banksize, origin; int c, i, j, pos, scan, x, y; uint8_t line[MAXSCANLINE]; if (pcx_info.zlen < 1) return (1); - load_palette(adp, pcx_info.palette); + vidd_load_palette(adp, pcx_info.palette); vidmem = (uint8_t *)adp->va_window; swidth = adp->va_info.vi_width; sheight = adp->va_info.vi_height; sbpsl = adp->va_line_width; sdepth = adp->va_info.vi_depth; splanes = adp->va_info.vi_planes; banksize = adp->va_window_size; for (origin = 0; origin < sheight*sbpsl; origin += banksize) { - set_origin(adp, origin); + vidd_set_win_org(adp, origin); bzero(vidmem, banksize); } x = (swidth - pcx_info.width) / 2; y = (sheight - pcx_info.height) / 2; origin = 0; pos = y * sbpsl + x; while (pos > banksize) { pos -= banksize; origin += banksize; } - set_origin(adp, origin); + vidd_set_win_org(adp, origin); for (scan = i = 0; scan < pcx_info.height; ++scan, ++y, pos += sbpsl) { for (j = 0; j < pcx_info.bpsl && i < pcx_info.zlen; ++i) { if ((pcx_info.zdata[i] & 0xc0) == 0xc0) { c = pcx_info.zdata[i++] & 0x3f; if (i >= pcx_info.zlen) return (1); } else { c = 1; } if (j + c > pcx_info.bpsl) return (1); while (c--) line[j++] = pcx_info.zdata[i]; } if (pos > banksize) { origin += banksize; pos -= banksize; - set_origin(adp, origin); + vidd_set_win_org(adp, origin); } if (pos + pcx_info.width > banksize) { /* scanline crosses bank boundary */ j = banksize - pos; bcopy(line, vidmem + pos, j); origin += banksize; pos -= banksize; - set_origin(adp, origin); + vidd_set_win_org(adp, origin); bcopy(line + j, vidmem, pcx_info.width - j); } else { bcopy(line, vidmem + pos, pcx_info.width); } } return (0); } Index: head/sys/dev/fb/vga.c =================================================================== --- head/sys/dev/fb/vga.c (revision 174984) +++ head/sys/dev/fb/vga.c (revision 174985) @@ -1,3068 +1,3068 @@ /*- * Copyright (c) 1999 Kazutaka YOKOTA * Copyright (c) 1992-1998 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer as * the first lines of this file unmodified. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include __FBSDID("$FreeBSD$"); #include "opt_vga.h" #include "opt_fb.h" #ifndef FB_DEBUG #define FB_DEBUG 0 #endif #include "opt_syscons.h" /* should be removed in the future, XXX */ #include #include #include #include #include #include #include #include #include #include #include #if defined(__i386__) || defined(__amd64__) #include #endif #include #include #include #include #ifndef VGA_DEBUG #define VGA_DEBUG 0 #endif /* XXX machine/pc/bios.h has got too much i386-specific stuff in it */ #ifndef BIOS_PADDRTOVADDR #define BIOS_PADDRTOVADDR(x) (x) #endif int vga_probe_unit(int unit, video_adapter_t *buf, int flags) { video_adapter_t *adp; video_switch_t *sw; int error; sw = vid_get_switch(VGA_DRIVER_NAME); if (sw == NULL) return 0; error = (*sw->probe)(unit, &adp, NULL, flags); if (error) return error; bcopy(adp, buf, sizeof(*buf)); return 0; } int vga_attach_unit(int unit, vga_softc_t *sc, int flags) { video_switch_t *sw; int error; sw = vid_get_switch(VGA_DRIVER_NAME); if (sw == NULL) return ENXIO; error = (*sw->probe)(unit, &sc->adp, NULL, flags); if (error) return error; return (*sw->init)(unit, sc->adp, flags); } /* cdev driver functions */ #ifdef FB_INSTALL_CDEV int vga_open(struct cdev *dev, vga_softc_t *sc, int flag, int mode, struct thread *td) { if (sc == NULL) return ENXIO; if (mode & (O_CREAT | O_APPEND | O_TRUNC)) return ENODEV; return genfbopen(&sc->gensc, sc->adp, flag, mode, td); } int vga_close(struct cdev *dev, vga_softc_t *sc, int flag, int mode, struct thread *td) { return genfbclose(&sc->gensc, sc->adp, flag, mode, td); } int vga_read(struct cdev *dev, vga_softc_t *sc, struct uio *uio, int flag) { return genfbread(&sc->gensc, sc->adp, uio, flag); } int vga_write(struct cdev *dev, vga_softc_t *sc, struct uio *uio, int flag) { return genfbread(&sc->gensc, sc->adp, uio, flag); } int vga_ioctl(struct cdev *dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag, struct thread *td) { return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, td); } int vga_mmap(struct cdev *dev, vga_softc_t *sc, vm_offset_t offset, vm_offset_t *paddr, int prot) { return genfbmmap(&sc->gensc, sc->adp, offset, paddr, prot); } #endif /* FB_INSTALL_CDEV */ /* LOW-LEVEL */ #include #ifdef __i386__ #include #endif #define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED) #define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED) #define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED) /* for compatibility with old kernel options */ #ifdef SC_ALT_SEQACCESS #undef SC_ALT_SEQACCESS #undef VGA_ALT_SEQACCESS #define VGA_ALT_SEQACCESS 1 #endif #ifdef SLOW_VGA #undef SLOW_VGA #undef VGA_SLOW_IOACCESS #define VGA_SLOW_IOACCESS #endif /* architecture dependent option */ #ifndef __i386__ #define VGA_NO_BIOS 1 #endif /* this should really be in `rtc.h' */ #define RTC_EQUIPMENT 0x14 /* various sizes */ #define V_MODE_MAP_SIZE (M_VGA_CG320 + 1) #define V_MODE_PARAM_SIZE 64 /* video adapter state buffer */ struct adp_state { int sig; #define V_STATE_SIG 0x736f6962 u_char regs[V_MODE_PARAM_SIZE]; }; typedef struct adp_state adp_state_t; /* video adapter information */ #define DCC_MONO 0 #define DCC_CGA40 1 #define DCC_CGA80 2 #define DCC_EGAMONO 3 #define DCC_EGA40 4 #define DCC_EGA80 5 /* * NOTE: `va_window' should have a virtual address, but is initialized * with a physical address in the following table, as verify_adapter() * will perform address conversion at run-time. */ static video_adapter_t adapter_init_value[] = { /* DCC_MONO */ { 0, KD_MONO, "mda", 0, 0, 0, IO_MDA, IO_MDASIZE, MONO_CRTC, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, 0, 0, 7, 0, }, /* DCC_CGA40 */ { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, 0, 0, 3, 0, }, /* DCC_CGA80 */ { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, 0, 0, 3, 0, }, /* DCC_EGAMONO */ { 0, KD_EGA, "ega", 0, 0, 0, IO_MDA, 48, MONO_CRTC, EGA_BUF_BASE, EGA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, 0, 0, 7, 0, }, /* DCC_EGA40 */ { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC, EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, 0, 0, 3, 0, }, /* DCC_EGA80 */ { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC, EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, 0, 0, 3, 0, }, }; static video_adapter_t biosadapter[2]; static int biosadapters = 0; /* video driver declarations */ static int vga_configure(int flags); int (*vga_sub_configure)(int flags); #if 0 static int vga_nop(void); #endif static int vga_error(void); static vi_probe_t vga_probe; static vi_init_t vga_init; static vi_get_info_t vga_get_info; static vi_query_mode_t vga_query_mode; static vi_set_mode_t vga_set_mode; static vi_save_font_t vga_save_font; static vi_load_font_t vga_load_font; static vi_show_font_t vga_show_font; static vi_save_palette_t vga_save_palette; static vi_load_palette_t vga_load_palette; static vi_set_border_t vga_set_border; static vi_save_state_t vga_save_state; static vi_load_state_t vga_load_state; static vi_set_win_org_t vga_set_origin; static vi_read_hw_cursor_t vga_read_hw_cursor; static vi_set_hw_cursor_t vga_set_hw_cursor; static vi_set_hw_cursor_shape_t vga_set_hw_cursor_shape; static vi_blank_display_t vga_blank_display; static vi_mmap_t vga_mmap_buf; static vi_ioctl_t vga_dev_ioctl; #ifndef VGA_NO_MODE_CHANGE static vi_clear_t vga_clear; static vi_fill_rect_t vga_fill_rect; static vi_bitblt_t vga_bitblt; #else /* VGA_NO_MODE_CHANGE */ #define vga_clear (vi_clear_t *)vga_error #define vga_fill_rect (vi_fill_rect_t *)vga_error #define vga_bitblt (vi_bitblt_t *)vga_error #endif static vi_diag_t vga_diag; static video_switch_t vgavidsw = { vga_probe, vga_init, vga_get_info, vga_query_mode, vga_set_mode, vga_save_font, vga_load_font, vga_show_font, vga_save_palette, vga_load_palette, vga_set_border, vga_save_state, vga_load_state, vga_set_origin, vga_read_hw_cursor, vga_set_hw_cursor, vga_set_hw_cursor_shape, vga_blank_display, vga_mmap_buf, vga_dev_ioctl, vga_clear, vga_fill_rect, vga_bitblt, vga_error, vga_error, vga_diag, }; VIDEO_DRIVER(mda, vgavidsw, NULL); VIDEO_DRIVER(cga, vgavidsw, NULL); VIDEO_DRIVER(ega, vgavidsw, NULL); VIDEO_DRIVER(vga, vgavidsw, vga_configure); /* VGA BIOS standard video modes */ #define EOT (-1) #define NA (-2) static video_info_t bios_vmode[] = { /* CGA */ { M_B40x25, V_INFO_COLOR, 40, 25, 8, 8, 2, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_C40x25, V_INFO_COLOR, 40, 25, 8, 8, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_B80x25, V_INFO_COLOR, 80, 25, 8, 8, 2, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_C80x25, V_INFO_COLOR, 80, 25, 8, 8, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, /* EGA */ { M_ENH_B40x25, V_INFO_COLOR, 40, 25, 8, 14, 2, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_ENH_C40x25, V_INFO_COLOR, 40, 25, 8, 14, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_ENH_B80x25, V_INFO_COLOR, 80, 25, 8, 14, 2, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_ENH_C80x25, V_INFO_COLOR, 80, 25, 8, 14, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, /* VGA */ { M_VGA_C40x25, V_INFO_COLOR, 40, 25, 8, 16, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_M80x25, 0, 80, 25, 8, 16, 2, 1, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_C80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, /* MDA */ { M_EGAMONO80x25, 0, 80, 25, 8, 14, 2, 1, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, /* EGA */ { M_ENH_B80x43, 0, 80, 43, 8, 8, 2, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_ENH_C80x43, V_INFO_COLOR, 80, 43, 8, 8, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, /* VGA */ { M_VGA_M80x30, 0, 80, 30, 8, 16, 2, 1, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_C80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_M80x50, 0, 80, 50, 8, 8, 2, 1, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_C80x50, V_INFO_COLOR, 80, 50, 8, 8, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_M80x60, 0, 80, 60, 8, 8, 2, 1, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_C80x60, V_INFO_COLOR, 80, 60, 8, 8, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, #ifndef VGA_NO_MODE_CHANGE #ifdef VGA_WIDTH90 { M_VGA_M90x25, 0, 90, 25, 8, 16, 2, 1, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_C90x25, V_INFO_COLOR, 90, 25, 8, 16, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_M90x30, 0, 90, 30, 8, 16, 2, 1, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_C90x30, V_INFO_COLOR, 90, 30, 8, 16, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_M90x43, 0, 90, 43, 8, 8, 2, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_C90x43, V_INFO_COLOR, 90, 43, 8, 8, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_M90x50, 0, 90, 50, 8, 8, 2, 1, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_C90x50, V_INFO_COLOR, 90, 50, 8, 8, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_M90x60, 0, 90, 60, 8, 8, 2, 1, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, { M_VGA_C90x60, V_INFO_COLOR, 90, 60, 8, 8, 4, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, #endif /* VGA_WIDTH90 */ /* CGA */ { M_BG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA }, { M_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA }, { M_BG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 1, 1, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA }, /* EGA */ { M_CG320_D, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 4, 4, GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0, V_INFO_MM_PLANAR }, { M_CG640_E, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 4, 4, GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 , V_INFO_MM_PLANAR }, { M_EGAMONOAPA, V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4, GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, 64*1024, 0, 0 , V_INFO_MM_PLANAR }, { M_ENHMONOAPA2,V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4, GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 , V_INFO_MM_PLANAR }, { M_CG640x350, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 2, 2, GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 , V_INFO_MM_PLANAR }, { M_ENH_CG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4, GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 , V_INFO_MM_PLANAR }, /* VGA */ { M_BG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4, GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 , V_INFO_MM_PLANAR }, { M_CG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4, GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 , V_INFO_MM_PLANAR }, { M_VGA_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 8, 1, GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0, V_INFO_MM_PACKED, 1 }, { M_VGA_MODEX, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 240, 8, 8, 8, 4, GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0, V_INFO_MM_VGAX, 1 }, #endif /* VGA_NO_MODE_CHANGE */ { EOT }, }; static int vga_init_done = FALSE; #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) static u_char *video_mode_ptr = NULL; /* EGA/VGA */ static u_char *video_mode_ptr2 = NULL; /* CGA/MDA */ #endif static u_char *mode_map[V_MODE_MAP_SIZE]; static adp_state_t adpstate; static adp_state_t adpstate2; static int rows_offset = 1; /* local macros and functions */ #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff)) #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) static void map_mode_table(u_char *map[], u_char *table, int max); #endif static void clear_mode_map(video_adapter_t *adp, u_char *map[], int max, int color); #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) static int map_mode_num(int mode); #endif static int map_gen_mode_num(int type, int color, int mode); static int map_bios_mode_num(int type, int color, int bios_mode); static u_char *get_mode_param(int mode); #ifndef VGA_NO_BIOS static void fill_adapter_param(int code, video_adapter_t *adp); #endif static int verify_adapter(video_adapter_t *adp); static void update_adapter_info(video_adapter_t *adp, video_info_t *info); #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) #define COMP_IDENTICAL 0 #define COMP_SIMILAR 1 #define COMP_DIFFERENT 2 static int comp_adpregs(u_char *buf1, u_char *buf2); #endif static int probe_adapters(void); static int set_line_length(video_adapter_t *adp, int pixel); static int set_display_start(video_adapter_t *adp, int x, int y); #ifndef VGA_NO_MODE_CHANGE #ifdef VGA_WIDTH90 static void set_width90(adp_state_t *params); #endif #endif /* !VGA_NO_MODE_CHANGE */ #ifndef VGA_NO_FONT_LOADING #define PARAM_BUFSIZE 6 static void set_font_mode(video_adapter_t *adp, u_char *buf); static void set_normal_mode(video_adapter_t *adp, u_char *buf); #endif #ifndef VGA_NO_MODE_CHANGE static void filll_io(int val, vm_offset_t d, size_t size); static void planar_fill(video_adapter_t *adp, int val); static void packed_fill(video_adapter_t *adp, int val); static void direct_fill(video_adapter_t *adp, int val); #ifdef notyet static void planar_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy); static void packed_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy); static void direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, int cx, int cy); static void direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, int cx, int cy); static void direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, int cx, int cy); #endif /* notyet */ #endif /* !VGA_NO_MODE_CHANGE */ static void dump_buffer(u_char *buf, size_t len); #define ISMAPPED(pa, width) \ (((pa) <= (u_long)0x1000 - (width)) \ || ((pa) >= ISA_HOLE_START && (pa) <= 0x100000 - (width))) #define prologue(adp, flag, err) \ if (!vga_init_done || !((adp)->va_flags & (flag))) \ return (err) /* a backdoor for the console driver */ static int vga_configure(int flags) { int i; probe_adapters(); for (i = 0; i < biosadapters; ++i) { if (!probe_done(&biosadapter[i])) continue; biosadapter[i].va_flags |= V_ADP_INITIALIZED; if (!config_done(&biosadapter[i])) { if (vid_register(&biosadapter[i]) < 0) continue; biosadapter[i].va_flags |= V_ADP_REGISTERED; } } if (vga_sub_configure != NULL) (*vga_sub_configure)(flags); return biosadapters; } /* local subroutines */ #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) /* construct the mode parameter map */ static void map_mode_table(u_char *map[], u_char *table, int max) { int i; for(i = 0; i < max; ++i) map[i] = table + i*V_MODE_PARAM_SIZE; for(; i < V_MODE_MAP_SIZE; ++i) map[i] = NULL; } #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */ static void clear_mode_map(video_adapter_t *adp, u_char *map[], int max, int color) { video_info_t info; int i; /* * NOTE: we don't touch `bios_vmode[]' because it is shared * by all adapters. */ for(i = 0; i < max; ++i) { if (vga_get_info(adp, i, &info)) continue; if ((info.vi_flags & V_INFO_COLOR) != color) map[i] = NULL; } } #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) /* map the non-standard video mode to a known mode number */ static int map_mode_num(int mode) { static struct { int from; int to; } mode_map[] = { { M_ENH_B80x43, M_ENH_B80x25 }, { M_ENH_C80x43, M_ENH_C80x25 }, { M_VGA_M80x30, M_VGA_M80x25 }, { M_VGA_C80x30, M_VGA_C80x25 }, { M_VGA_M80x50, M_VGA_M80x25 }, { M_VGA_C80x50, M_VGA_C80x25 }, { M_VGA_M80x60, M_VGA_M80x25 }, { M_VGA_C80x60, M_VGA_C80x25 }, #ifdef VGA_WIDTH90 { M_VGA_M90x25, M_VGA_M80x25 }, { M_VGA_C90x25, M_VGA_C80x25 }, { M_VGA_M90x30, M_VGA_M80x25 }, { M_VGA_C90x30, M_VGA_C80x25 }, { M_VGA_M90x43, M_ENH_B80x25 }, { M_VGA_C90x43, M_ENH_C80x25 }, { M_VGA_M90x50, M_VGA_M80x25 }, { M_VGA_C90x50, M_VGA_C80x25 }, { M_VGA_M90x60, M_VGA_M80x25 }, { M_VGA_C90x60, M_VGA_C80x25 }, #endif { M_VGA_MODEX, M_VGA_CG320 }, }; int i; for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) { if (mode_map[i].from == mode) return mode_map[i].to; } return mode; } #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */ /* map a generic video mode to a known mode number */ static int map_gen_mode_num(int type, int color, int mode) { static struct { int from; int to_color; int to_mono; } mode_map[] = { { M_TEXT_80x30, M_VGA_C80x30, M_VGA_M80x30, }, { M_TEXT_80x43, M_ENH_C80x43, M_ENH_B80x43, }, { M_TEXT_80x50, M_VGA_C80x50, M_VGA_M80x50, }, { M_TEXT_80x60, M_VGA_C80x60, M_VGA_M80x60, }, }; int i; if (mode == M_TEXT_80x25) { switch (type) { case KD_VGA: if (color) return M_VGA_C80x25; else return M_VGA_M80x25; break; case KD_EGA: if (color) return M_ENH_C80x25; else return M_EGAMONO80x25; break; case KD_CGA: return M_C80x25; case KD_MONO: case KD_HERCULES: return M_EGAMONO80x25; /* XXX: this name is confusing */ default: return -1; } } for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) { if (mode_map[i].from == mode) return ((color) ? mode_map[i].to_color : mode_map[i].to_mono); } return mode; } /* turn the BIOS video number into our video mode number */ static int map_bios_mode_num(int type, int color, int bios_mode) { static int cga_modes[7] = { M_B40x25, M_C40x25, /* 0, 1 */ M_B80x25, M_C80x25, /* 2, 3 */ M_BG320, M_CG320, M_BG640, }; static int ega_modes[17] = { M_ENH_B40x25, M_ENH_C40x25, /* 0, 1 */ M_ENH_B80x25, M_ENH_C80x25, /* 2, 3 */ M_BG320, M_CG320, M_BG640, M_EGAMONO80x25, /* 7 */ 8, 9, 10, 11, 12, M_CG320_D, M_CG640_E, M_ENHMONOAPA2, /* XXX: video momery > 64K */ M_ENH_CG640, /* XXX: video momery > 64K */ }; static int vga_modes[20] = { M_VGA_C40x25, M_VGA_C40x25, /* 0, 1 */ M_VGA_C80x25, M_VGA_C80x25, /* 2, 3 */ M_BG320, M_CG320, M_BG640, M_VGA_M80x25, /* 7 */ 8, 9, 10, 11, 12, M_CG320_D, M_CG640_E, M_ENHMONOAPA2, M_ENH_CG640, M_BG640x480, M_CG640x480, M_VGA_CG320, }; switch (type) { case KD_VGA: if (bios_mode < sizeof(vga_modes)/sizeof(vga_modes[0])) return vga_modes[bios_mode]; else if (color) return M_VGA_C80x25; else return M_VGA_M80x25; break; case KD_EGA: if (bios_mode < sizeof(ega_modes)/sizeof(ega_modes[0])) return ega_modes[bios_mode]; else if (color) return M_ENH_C80x25; else return M_EGAMONO80x25; break; case KD_CGA: if (bios_mode < sizeof(cga_modes)/sizeof(cga_modes[0])) return cga_modes[bios_mode]; else return M_C80x25; break; case KD_MONO: case KD_HERCULES: return M_EGAMONO80x25; /* XXX: this name is confusing */ default: break; } return -1; } /* look up a parameter table entry */ static u_char *get_mode_param(int mode) { #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) if (mode >= V_MODE_MAP_SIZE) mode = map_mode_num(mode); #endif if ((mode >= 0) && (mode < V_MODE_MAP_SIZE)) return mode_map[mode]; else return NULL; } #ifndef VGA_NO_BIOS static void fill_adapter_param(int code, video_adapter_t *adp) { static struct { int primary; int secondary; } dcc[] = { { DCC_MONO, DCC_EGA40 /* CGA monitor */ }, { DCC_MONO, DCC_EGA80 /* CGA monitor */ }, { DCC_MONO, DCC_EGA80 }, { DCC_MONO, DCC_EGA80 }, { DCC_CGA40, DCC_EGAMONO }, { DCC_CGA80, DCC_EGAMONO }, { DCC_EGA40 /* CGA monitor */, DCC_MONO}, { DCC_EGA80 /* CGA monitor */, DCC_MONO}, { DCC_EGA80, DCC_MONO }, { DCC_EGA80, DCC_MONO }, { DCC_EGAMONO, DCC_CGA40 }, { DCC_EGAMONO, DCC_CGA80 }, }; if ((code < 0) || (code >= sizeof(dcc)/sizeof(dcc[0]))) { adp[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO]; adp[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80]; } else { adp[V_ADP_PRIMARY] = adapter_init_value[dcc[code].primary]; adp[V_ADP_SECONDARY] = adapter_init_value[dcc[code].secondary]; } } #endif /* VGA_NO_BIOS */ static int verify_adapter(video_adapter_t *adp) { vm_offset_t buf; u_int16_t v; #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) u_int32_t p; #endif buf = BIOS_PADDRTOVADDR(adp->va_window); v = readw(buf); writew(buf, 0xA55A); if (readw(buf) != 0xA55A) return ENXIO; writew(buf, v); switch (adp->va_type) { case KD_EGA: outb(adp->va_crtc_addr, 7); if (inb(adp->va_crtc_addr) == 7) { adp->va_type = KD_VGA; adp->va_name = "vga"; adp->va_flags |= V_ADP_STATESAVE | V_ADP_PALETTE; } adp->va_flags |= V_ADP_STATELOAD | V_ADP_BORDER; /* the color adapter may be in the 40x25 mode... XXX */ #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) /* get the BIOS video mode pointer */ p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8); p = BIOS_SADDRTOLADDR(p); if (ISMAPPED(p, sizeof(u_int32_t))) { p = *(u_int32_t *)BIOS_PADDRTOVADDR(p); p = BIOS_SADDRTOLADDR(p); if (ISMAPPED(p, V_MODE_PARAM_SIZE)) video_mode_ptr = (u_char *)BIOS_PADDRTOVADDR(p); } #endif break; case KD_CGA: adp->va_flags |= V_ADP_COLOR | V_ADP_BORDER; /* may be in the 40x25 mode... XXX */ #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) /* get the BIOS video mode pointer */ p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4); p = BIOS_SADDRTOLADDR(p); video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p); #endif break; case KD_MONO: #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) /* get the BIOS video mode pointer */ p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4); p = BIOS_SADDRTOLADDR(p); video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p); #endif break; } return 0; } static void update_adapter_info(video_adapter_t *adp, video_info_t *info) { adp->va_flags &= ~V_ADP_COLOR; adp->va_flags |= (info->vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0; adp->va_crtc_addr = (adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC; adp->va_window = BIOS_PADDRTOVADDR(info->vi_window); adp->va_window_size = info->vi_window_size; adp->va_window_gran = info->vi_window_gran; adp->va_window_orig = 0; /* XXX */ adp->va_buffer = info->vi_buffer; adp->va_buffer_size = info->vi_buffer_size; if (info->vi_mem_model == V_INFO_MM_VGAX) { adp->va_line_width = info->vi_width/2; } else if (info->vi_flags & V_INFO_GRAPHICS) { switch (info->vi_depth/info->vi_planes) { case 1: adp->va_line_width = info->vi_width/8; break; case 2: adp->va_line_width = info->vi_width/4; break; case 4: adp->va_line_width = info->vi_width/2; break; case 8: default: /* shouldn't happen */ adp->va_line_width = info->vi_width; break; } } else { adp->va_line_width = info->vi_width; } adp->va_disp_start.x = 0; adp->va_disp_start.y = 0; bcopy(info, &adp->va_info, sizeof(adp->va_info)); } #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) /* compare two parameter table entries */ static int comp_adpregs(u_char *buf1, u_char *buf2) { static struct { u_char mask; } params[V_MODE_PARAM_SIZE] = { {0xff}, {0x00}, {0xff}, /* COLS}, ROWS}, POINTS */ {0x00}, {0x00}, /* page length */ {0xfe}, {0xff}, {0xff}, {0xff}, /* sequencer registers */ {0xf3}, /* misc register */ {0xff}, {0xff}, {0xff}, {0x7f}, {0xff}, /* CRTC */ {0xff}, {0xff}, {0xff}, {0x7f}, {0xff}, {0x00}, {0x00}, {0x00}, {0x00}, {0x00}, {0x00}, {0xff}, {0x7f}, {0xff}, {0xff}, {0x7f}, {0xff}, {0xff}, {0xef}, {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* attribute controller regs */ {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, {0xf0}, {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* GDC register */ {0xff}, {0xff}, {0xff}, {0xff}, }; int identical = TRUE; int i; if ((buf1 == NULL) || (buf2 == NULL)) return COMP_DIFFERENT; for (i = 0; i < sizeof(params)/sizeof(params[0]); ++i) { if (params[i].mask == 0) /* don't care */ continue; if ((buf1[i] & params[i].mask) != (buf2[i] & params[i].mask)) return COMP_DIFFERENT; if (buf1[i] != buf2[i]) identical = FALSE; } return (identical) ? COMP_IDENTICAL : COMP_SIMILAR; } #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */ /* probe video adapters and return the number of detected adapters */ static int probe_adapters(void) { video_adapter_t *adp; video_info_t info; #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) u_char *mp; #endif int i; /* do this test only once */ if (vga_init_done) return biosadapters; vga_init_done = TRUE; /* * Locate display adapters. * The AT architecture supports upto two adapters. `syscons' allows * the following combinations of adapters: * 1) MDA + CGA * 2) MDA + EGA/VGA color * 3) CGA + EGA/VGA mono * Note that `syscons' doesn't bother with MCGA as it is only * avaiable for low end PS/2 models which has 80286 or earlier CPUs, * thus, they are not running FreeBSD! * When there are two adapaters in the system, one becomes `primary' * and the other `secondary'. The EGA adapter has a set of DIP * switches on board for this information and the EGA BIOS copies * it in the BIOS data area BIOSDATA_VIDEOSWITCH (40:88). * The VGA BIOS has more sophisticated mechanism and has this * information in BIOSDATA_DCCINDEX (40:8a), but it also maintains * compatibility with the EGA BIOS by updating BIOSDATA_VIDEOSWITCH. */ /* * Check rtc and BIOS data area. * XXX: we don't use BIOSDATA_EQUIPMENT, since it is not a dead * copy of RTC_EQUIPMENT. Bits 4 and 5 of ETC_EQUIPMENT are * zeros for EGA and VGA. However, the EGA/VGA BIOS sets * these bits in BIOSDATA_EQUIPMENT according to the monitor * type detected. */ #ifndef VGA_NO_BIOS if (*(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8)) { /* EGA/VGA BIOS is present */ fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f, biosadapter); } else { switch ((rtcin(RTC_EQUIPMENT) >> 4) & 3) { /* bit 4 and 5 */ case 0: /* EGA/VGA: shouldn't be happening */ fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f, biosadapter); break; case 1: /* CGA 40x25 */ /* FIXME: switch to the 80x25 mode? XXX */ biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA40]; biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO]; break; case 2: /* CGA 80x25 */ biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA80]; biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO]; break; case 3: /* MDA */ biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO]; biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80]; break; } } #else /* assume EGA/VGA? XXX */ biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_EGA80]; biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO]; #endif /* VGA_NO_BIOS */ biosadapters = 0; if (verify_adapter(&biosadapter[V_ADP_SECONDARY]) == 0) { ++biosadapters; biosadapter[V_ADP_SECONDARY].va_flags |= V_ADP_PROBED; biosadapter[V_ADP_SECONDARY].va_mode = biosadapter[V_ADP_SECONDARY].va_initial_mode = map_bios_mode_num(biosadapter[V_ADP_SECONDARY].va_type, biosadapter[V_ADP_SECONDARY].va_flags & V_ADP_COLOR, biosadapter[V_ADP_SECONDARY].va_initial_bios_mode); } else { biosadapter[V_ADP_SECONDARY].va_type = -1; } if (verify_adapter(&biosadapter[V_ADP_PRIMARY]) == 0) { ++biosadapters; biosadapter[V_ADP_PRIMARY].va_flags |= V_ADP_PROBED; #ifndef VGA_NO_BIOS biosadapter[V_ADP_PRIMARY].va_initial_bios_mode = readb(BIOS_PADDRTOVADDR(0x449)); #else biosadapter[V_ADP_PRIMARY].va_initial_bios_mode = 3; /* XXX */ #endif biosadapter[V_ADP_PRIMARY].va_mode = biosadapter[V_ADP_PRIMARY].va_initial_mode = map_bios_mode_num(biosadapter[V_ADP_PRIMARY].va_type, biosadapter[V_ADP_PRIMARY].va_flags & V_ADP_COLOR, biosadapter[V_ADP_PRIMARY].va_initial_bios_mode); } else { biosadapter[V_ADP_PRIMARY] = biosadapter[V_ADP_SECONDARY]; biosadapter[V_ADP_SECONDARY].va_type = -1; } if (biosadapters == 0) return biosadapters; biosadapter[V_ADP_PRIMARY].va_unit = V_ADP_PRIMARY; biosadapter[V_ADP_SECONDARY].va_unit = V_ADP_SECONDARY; #if 0 /* we don't need these... */ fb_init_struct(&biosadapter[V_ADP_PRIMARY], ...); fb_init_struct(&biosadapter[V_ADP_SECONDARY], ...); #endif #ifdef notyet /* * We cannot have two video adapter of the same type; there must be * only one of color or mono adapter, or one each of them. */ if (biosadapters > 1) { if (!((biosadapter[0].va_flags ^ biosadapter[1].va_flags) & V_ADP_COLOR)) /* we have two mono or color adapters!! */ return (biosadapters = 0); } #endif /* * Ensure a zero start address. The registers are w/o * for old hardware so it's too hard to relocate the active screen * memory. * This must be done before vga_save_state() for VGA. */ outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 12); outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0); outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 13); outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0); /* the video mode parameter table in EGA/VGA BIOS */ /* NOTE: there can be only one EGA/VGA, wheather color or mono, * recognized by the video BIOS. */ if ((biosadapter[V_ADP_PRIMARY].va_type == KD_EGA) || (biosadapter[V_ADP_PRIMARY].va_type == KD_VGA)) { adp = &biosadapter[V_ADP_PRIMARY]; } else if ((biosadapter[V_ADP_SECONDARY].va_type == KD_EGA) || (biosadapter[V_ADP_SECONDARY].va_type == KD_VGA)) { adp = &biosadapter[V_ADP_SECONDARY]; } else { adp = NULL; } bzero(mode_map, sizeof(mode_map)); if (adp != NULL) { if (adp->va_type == KD_VGA) { vga_save_state(adp, &adpstate, sizeof(adpstate)); #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE) mode_map[adp->va_initial_mode] = adpstate.regs; rows_offset = 1; #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */ if (video_mode_ptr == NULL) { mode_map[adp->va_initial_mode] = adpstate.regs; rows_offset = 1; } else { /* discard the table if we are not familiar with it... */ map_mode_table(mode_map, video_mode_ptr, M_VGA_CG320 + 1); mp = get_mode_param(adp->va_initial_mode); if (mp != NULL) bcopy(mp, adpstate2.regs, sizeof(adpstate2.regs)); switch (comp_adpregs(adpstate.regs, mp)) { case COMP_IDENTICAL: /* * OK, this parameter table looks reasonably familiar * to us... */ /* * This is a kludge for Toshiba DynaBook SS433 * whose BIOS video mode table entry has the actual # * of rows at the offset 1; BIOSes from other * manufacturers store the # of rows - 1 there. XXX */ rows_offset = adpstate.regs[1] + 1 - mp[1]; break; case COMP_SIMILAR: /* * Not exactly the same, but similar enough to be * trusted. However, use the saved register values * for the initial mode and other modes which are * based on the initial mode. */ mode_map[adp->va_initial_mode] = adpstate.regs; rows_offset = adpstate.regs[1] + 1 - mp[1]; adpstate.regs[1] -= rows_offset - 1; break; case COMP_DIFFERENT: default: /* * Don't use the paramter table in BIOS. It doesn't * look familiar to us. Video mode switching is allowed * only if the new mode is the same as or based on * the initial mode. */ video_mode_ptr = NULL; bzero(mode_map, sizeof(mode_map)); mode_map[adp->va_initial_mode] = adpstate.regs; rows_offset = 1; break; } } #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */ #ifndef VGA_NO_MODE_CHANGE adp->va_flags |= V_ADP_MODECHANGE; #endif #ifndef VGA_NO_FONT_LOADING adp->va_flags |= V_ADP_FONT; #endif } else if (adp->va_type == KD_EGA) { #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE) rows_offset = 1; #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */ if (video_mode_ptr == NULL) { rows_offset = 1; } else { map_mode_table(mode_map, video_mode_ptr, M_ENH_C80x25 + 1); /* XXX how can one validate the EGA table... */ mp = get_mode_param(adp->va_initial_mode); if (mp != NULL) { adp->va_flags |= V_ADP_MODECHANGE; #ifndef VGA_NO_FONT_LOADING adp->va_flags |= V_ADP_FONT; #endif rows_offset = 1; } else { /* * This is serious. We will not be able to switch video * modes at all... */ video_mode_ptr = NULL; bzero(mode_map, sizeof(mode_map)); rows_offset = 1; } } #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */ } } /* remove conflicting modes if we have more than one adapter */ if (biosadapters > 0) { for (i = 0; i < biosadapters; ++i) { if (!(biosadapter[i].va_flags & V_ADP_MODECHANGE)) continue; clear_mode_map(&biosadapter[i], mode_map, M_VGA_CG320 + 1, (biosadapter[i].va_flags & V_ADP_COLOR) ? V_INFO_COLOR : 0); if ((biosadapter[i].va_type == KD_VGA) || (biosadapter[i].va_type == KD_EGA)) { biosadapter[i].va_io_base = (biosadapter[i].va_flags & V_ADP_COLOR) ? IO_VGA : IO_MDA; biosadapter[i].va_io_size = 32; } } } /* buffer address */ vga_get_info(&biosadapter[V_ADP_PRIMARY], biosadapter[V_ADP_PRIMARY].va_initial_mode, &info); info.vi_flags &= ~V_INFO_LINEAR; /* XXX */ update_adapter_info(&biosadapter[V_ADP_PRIMARY], &info); if (biosadapters > 1) { vga_get_info(&biosadapter[V_ADP_SECONDARY], biosadapter[V_ADP_SECONDARY].va_initial_mode, &info); info.vi_flags &= ~V_INFO_LINEAR; /* XXX */ update_adapter_info(&biosadapter[V_ADP_SECONDARY], &info); } /* * XXX: we should verify the following values for the primary adapter... * crtc I/O port address: *(u_int16_t *)BIOS_PADDRTOVADDR(0x463); * color/mono display: (*(u_int8_t *)BIOS_PADDRTOVADDR(0x487) & 0x02) * ? 0 : V_ADP_COLOR; * columns: *(u_int8_t *)BIOS_PADDRTOVADDR(0x44a); * rows: *(u_int8_t *)BIOS_PADDRTOVADDR(0x484); * font size: *(u_int8_t *)BIOS_PADDRTOVADDR(0x485); * buffer size: *(u_int16_t *)BIOS_PADDRTOVADDR(0x44c); */ return biosadapters; } /* set the scan line length in pixel */ static int set_line_length(video_adapter_t *adp, int pixel) { u_char *mp; int ppw; /* pixels per word */ int bpl; /* bytes per line */ int count; if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA)) return ENODEV; mp = get_mode_param(adp->va_mode); if (mp == NULL) return EINVAL; switch (adp->va_info.vi_mem_model) { case V_INFO_MM_PLANAR: ppw = 16/(adp->va_info.vi_depth/adp->va_info.vi_planes); count = (pixel + ppw - 1)/ppw/2; bpl = ((pixel + ppw - 1)/ppw/2)*4; break; case V_INFO_MM_PACKED: count = (pixel + 7)/8; bpl = ((pixel + 7)/8)*8; break; case V_INFO_MM_TEXT: count = (pixel + 7)/8; /* columns */ bpl = (pixel + 7)/8; /* columns */ break; default: return ENODEV; } if (mp[10 + 0x17] & 0x40) /* CRTC mode control reg */ count *= 2; /* byte mode */ outb(adp->va_crtc_addr, 0x13); outb(adp->va_crtc_addr + 1, count); adp->va_line_width = bpl; return 0; } static int set_display_start(video_adapter_t *adp, int x, int y) { int off; /* byte offset (graphics mode)/word offset (text mode) */ int poff; /* pixel offset */ int roff; /* row offset */ int ppb; /* pixels per byte */ if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA)) x &= ~7; if (adp->va_info.vi_flags & V_INFO_GRAPHICS) { ppb = 8/(adp->va_info.vi_depth/adp->va_info.vi_planes); off = y*adp->va_line_width + x/ppb; roff = 0; poff = x%ppb; } else { if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) { outb(TSIDX, 1); if (inb(TSREG) & 1) ppb = 9; else ppb = 8; } else { ppb = 8; } off = y/adp->va_info.vi_cheight*adp->va_line_width + x/ppb; roff = y%adp->va_info.vi_cheight; /* FIXME: is this correct? XXX */ if (ppb == 8) poff = x%ppb; else poff = (x + 8)%ppb; } /* start address */ outb(adp->va_crtc_addr, 0xc); /* high */ outb(adp->va_crtc_addr + 1, off >> 8); outb(adp->va_crtc_addr, 0xd); /* low */ outb(adp->va_crtc_addr + 1, off & 0xff); /* horizontal pel pan */ if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) { inb(adp->va_crtc_addr + 6); outb(ATC, 0x13 | 0x20); outb(ATC, poff); inb(adp->va_crtc_addr + 6); outb(ATC, 0x20); } /* preset raw scan */ outb(adp->va_crtc_addr, 8); outb(adp->va_crtc_addr + 1, roff); adp->va_disp_start.x = x; adp->va_disp_start.y = y; return 0; } #ifndef VGA_NO_MODE_CHANGE #if defined(__i386__) || defined(__amd64__) /* XXX */ static void fill(int val, void *d, size_t size) { u_char *p = d; while (size-- > 0) *p++ = val; } #endif /* __i386__ */ static void filll_io(int val, vm_offset_t d, size_t size) { while (size-- > 0) { writel(d, val); d += sizeof(u_int32_t); } } #endif /* !VGA_NO_MODE_CHANGE */ /* entry points */ #if 0 static int vga_nop(void) { return 0; } #endif static int vga_error(void) { return ENODEV; } static int vga_probe(int unit, video_adapter_t **adpp, void *arg, int flags) { probe_adapters(); if (unit >= biosadapters) return ENXIO; *adpp = &biosadapter[unit]; return 0; } static int vga_init(int unit, video_adapter_t *adp, int flags) { if ((unit >= biosadapters) || (adp == NULL) || !probe_done(adp)) return ENXIO; if (!init_done(adp)) { /* nothing to do really... */ adp->va_flags |= V_ADP_INITIALIZED; } if (!config_done(adp)) { if (vid_register(adp) < 0) return ENXIO; adp->va_flags |= V_ADP_REGISTERED; } if (vga_sub_configure != NULL) (*vga_sub_configure)(0); return 0; } /* * get_info(): * Return the video_info structure of the requested video mode. * * all adapters */ static int vga_get_info(video_adapter_t *adp, int mode, video_info_t *info) { int i; if (!vga_init_done) return ENXIO; mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode); #ifndef VGA_NO_MODE_CHANGE if (adp->va_flags & V_ADP_MODECHANGE) { /* * If the parameter table entry for this mode is not found, * the mode is not supported... */ if (get_mode_param(mode) == NULL) return EINVAL; } else #endif /* VGA_NO_MODE_CHANGE */ { /* * Even if we don't support video mode switching on this adapter, * the information on the initial (thus current) video mode * should be made available. */ if (mode != adp->va_initial_mode) return EINVAL; } for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) { if (bios_vmode[i].vi_mode == NA) continue; if (mode == bios_vmode[i].vi_mode) { *info = bios_vmode[i]; /* XXX */ info->vi_buffer_size = info->vi_window_size*info->vi_planes; return 0; } } return EINVAL; } /* * query_mode(): * Find a video mode matching the requested parameters. * Fields filled with 0 are considered "don't care" fields and * match any modes. * * all adapters */ static int vga_query_mode(video_adapter_t *adp, video_info_t *info) { int i; if (!vga_init_done) return ENXIO; for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) { if (bios_vmode[i].vi_mode == NA) continue; if ((info->vi_width != 0) && (info->vi_width != bios_vmode[i].vi_width)) continue; if ((info->vi_height != 0) && (info->vi_height != bios_vmode[i].vi_height)) continue; if ((info->vi_cwidth != 0) && (info->vi_cwidth != bios_vmode[i].vi_cwidth)) continue; if ((info->vi_cheight != 0) && (info->vi_cheight != bios_vmode[i].vi_cheight)) continue; if ((info->vi_depth != 0) && (info->vi_depth != bios_vmode[i].vi_depth)) continue; if ((info->vi_planes != 0) && (info->vi_planes != bios_vmode[i].vi_planes)) continue; /* XXX: should check pixel format, memory model */ if ((info->vi_flags != 0) && (info->vi_flags != bios_vmode[i].vi_flags)) continue; /* verify if this mode is supported on this adapter */ if (vga_get_info(adp, bios_vmode[i].vi_mode, info)) continue; return 0; } return ENODEV; } /* * set_mode(): * Change the video mode. * * EGA/VGA */ #ifndef VGA_NO_MODE_CHANGE #ifdef VGA_WIDTH90 static void set_width90(adp_state_t *params) { /* * Based on code submitted by Kelly Yancey (kbyanc@freedomnet.com) * and alexv@sui.gda.itesm.mx. */ params->regs[5] |= 1; /* toggle 8 pixel wide fonts */ params->regs[10+0x0] = 0x6b; params->regs[10+0x1] = 0x59; params->regs[10+0x2] = 0x5a; params->regs[10+0x3] = 0x8e; params->regs[10+0x4] = 0x5e; params->regs[10+0x5] = 0x8a; params->regs[10+0x13] = 45; params->regs[35+0x13] = 0; } #endif /* VGA_WIDTH90 */ #endif /* !VGA_NO_MODE_CHANGE */ static int vga_set_mode(video_adapter_t *adp, int mode) { #ifndef VGA_NO_MODE_CHANGE video_info_t info; adp_state_t params; prologue(adp, V_ADP_MODECHANGE, ENODEV); mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode); if (vga_get_info(adp, mode, &info)) return EINVAL; #if VGA_DEBUG > 1 printf("vga_set_mode(): setting mode %d\n", mode); #endif params.sig = V_STATE_SIG; bcopy(get_mode_param(mode), params.regs, sizeof(params.regs)); switch (mode) { #ifdef VGA_WIDTH90 case M_VGA_C90x60: case M_VGA_M90x60: set_width90(¶ms); /* FALLTHROUGH */ #endif case M_VGA_C80x60: case M_VGA_M80x60: params.regs[2] = 0x08; params.regs[19] = 0x47; goto special_480l; #ifdef VGA_WIDTH90 case M_VGA_C90x30: case M_VGA_M90x30: set_width90(¶ms); /* FALLTHROUGH */ #endif case M_VGA_C80x30: case M_VGA_M80x30: params.regs[19] = 0x4f; special_480l: params.regs[9] |= 0xc0; params.regs[16] = 0x08; params.regs[17] = 0x3e; params.regs[26] = 0xea; params.regs[28] = 0xdf; params.regs[31] = 0xe7; params.regs[32] = 0x04; goto setup_mode; #ifdef VGA_WIDTH90 case M_VGA_C90x43: case M_VGA_M90x43: set_width90(¶ms); /* FALLTHROUGH */ #endif case M_ENH_C80x43: case M_ENH_B80x43: params.regs[28] = 87; goto special_80x50; #ifdef VGA_WIDTH90 case M_VGA_C90x50: case M_VGA_M90x50: set_width90(¶ms); /* FALLTHROUGH */ #endif case M_VGA_C80x50: case M_VGA_M80x50: special_80x50: params.regs[2] = 8; params.regs[19] = 7; goto setup_mode; #ifdef VGA_WIDTH90 case M_VGA_C90x25: case M_VGA_M90x25: set_width90(¶ms); /* FALLTHROUGH */ #endif case M_VGA_C40x25: case M_VGA_C80x25: case M_VGA_M80x25: case M_B40x25: case M_C40x25: case M_B80x25: case M_C80x25: case M_ENH_B40x25: case M_ENH_C40x25: case M_ENH_B80x25: case M_ENH_C80x25: case M_EGAMONO80x25: setup_mode: vga_load_state(adp, ¶ms); break; case M_VGA_MODEX: /* "unchain" the VGA mode */ params.regs[5-1+0x04] &= 0xf7; params.regs[5-1+0x04] |= 0x04; /* turn off doubleword mode */ params.regs[10+0x14] &= 0xbf; /* turn off word addressing */ params.regs[10+0x17] |= 0x40; /* set logical screen width */ params.regs[10+0x13] = 80; /* set 240 lines */ params.regs[10+0x11] = 0x2c; params.regs[10+0x06] = 0x0d; params.regs[10+0x07] = 0x3e; params.regs[10+0x10] = 0xea; params.regs[10+0x11] = 0xac; params.regs[10+0x12] = 0xdf; params.regs[10+0x15] = 0xe7; params.regs[10+0x16] = 0x06; /* set vertical sync polarity to reflect aspect ratio */ params.regs[9] = 0xe3; goto setup_grmode; case M_BG320: case M_CG320: case M_BG640: case M_CG320_D: case M_CG640_E: case M_CG640x350: case M_ENH_CG640: case M_BG640x480: case M_CG640x480: case M_VGA_CG320: setup_grmode: vga_load_state(adp, ¶ms); break; default: return EINVAL; } adp->va_mode = mode; info.vi_flags &= ~V_INFO_LINEAR; /* XXX */ update_adapter_info(adp, &info); /* move hardware cursor out of the way */ - (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1); + vidd_set_hw_cursor(adp, -1, -1); return 0; #else /* VGA_NO_MODE_CHANGE */ return ENODEV; #endif /* VGA_NO_MODE_CHANGE */ } #ifndef VGA_NO_FONT_LOADING static void set_font_mode(video_adapter_t *adp, u_char *buf) { u_char *mp; int s; s = splhigh(); /* save register values */ if (adp->va_type == KD_VGA) { outb(TSIDX, 0x02); buf[0] = inb(TSREG); outb(TSIDX, 0x04); buf[1] = inb(TSREG); outb(GDCIDX, 0x04); buf[2] = inb(GDCREG); outb(GDCIDX, 0x05); buf[3] = inb(GDCREG); outb(GDCIDX, 0x06); buf[4] = inb(GDCREG); inb(adp->va_crtc_addr + 6); outb(ATC, 0x10); buf[5] = inb(ATC + 1); } else /* if (adp->va_type == KD_EGA) */ { /* * EGA cannot be read; copy parameters from the mode parameter * table. */ mp = get_mode_param(adp->va_mode); buf[0] = mp[5 + 0x02 - 1]; buf[1] = mp[5 + 0x04 - 1]; buf[2] = mp[55 + 0x04]; buf[3] = mp[55 + 0x05]; buf[4] = mp[55 + 0x06]; buf[5] = mp[35 + 0x10]; } /* setup vga for loading fonts */ inb(adp->va_crtc_addr + 6); /* reset flip-flop */ outb(ATC, 0x10); outb(ATC, buf[5] & ~0x01); inb(adp->va_crtc_addr + 6); /* reset flip-flop */ outb(ATC, 0x20); /* enable palette */ #ifdef VGA_SLOW_IOACCESS #ifdef VGA_ALT_SEQACCESS outb(TSIDX, 0x00); outb(TSREG, 0x01); #endif outb(TSIDX, 0x02); outb(TSREG, 0x04); outb(TSIDX, 0x04); outb(TSREG, 0x07); #ifdef VGA_ALT_SEQACCESS outb(TSIDX, 0x00); outb(TSREG, 0x03); #endif outb(GDCIDX, 0x04); outb(GDCREG, 0x02); outb(GDCIDX, 0x05); outb(GDCREG, 0x00); outb(GDCIDX, 0x06); outb(GDCREG, 0x04); #else /* VGA_SLOW_IOACCESS */ #ifdef VGA_ALT_SEQACCESS outw(TSIDX, 0x0100); #endif outw(TSIDX, 0x0402); outw(TSIDX, 0x0704); #ifdef VGA_ALT_SEQACCESS outw(TSIDX, 0x0300); #endif outw(GDCIDX, 0x0204); outw(GDCIDX, 0x0005); outw(GDCIDX, 0x0406); /* addr = a0000, 64kb */ #endif /* VGA_SLOW_IOACCESS */ splx(s); } static void set_normal_mode(video_adapter_t *adp, u_char *buf) { int s; s = splhigh(); /* setup vga for normal operation mode again */ inb(adp->va_crtc_addr + 6); /* reset flip-flop */ outb(ATC, 0x10); outb(ATC, buf[5]); inb(adp->va_crtc_addr + 6); /* reset flip-flop */ outb(ATC, 0x20); /* enable palette */ #ifdef VGA_SLOW_IOACCESS #ifdef VGA_ALT_SEQACCESS outb(TSIDX, 0x00); outb(TSREG, 0x01); #endif outb(TSIDX, 0x02); outb(TSREG, buf[0]); outb(TSIDX, 0x04); outb(TSREG, buf[1]); #ifdef VGA_ALT_SEQACCESS outb(TSIDX, 0x00); outb(TSREG, 0x03); #endif outb(GDCIDX, 0x04); outb(GDCREG, buf[2]); outb(GDCIDX, 0x05); outb(GDCREG, buf[3]); if (adp->va_crtc_addr == MONO_CRTC) { outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x08); } else { outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x0c); } #else /* VGA_SLOW_IOACCESS */ #ifdef VGA_ALT_SEQACCESS outw(TSIDX, 0x0100); #endif outw(TSIDX, 0x0002 | (buf[0] << 8)); outw(TSIDX, 0x0004 | (buf[1] << 8)); #ifdef VGA_ALT_SEQACCESS outw(TSIDX, 0x0300); #endif outw(GDCIDX, 0x0004 | (buf[2] << 8)); outw(GDCIDX, 0x0005 | (buf[3] << 8)); if (adp->va_crtc_addr == MONO_CRTC) outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x08)<<8)); else outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x0c)<<8)); #endif /* VGA_SLOW_IOACCESS */ splx(s); } #endif /* VGA_NO_FONT_LOADING */ /* * save_font(): * Read the font data in the requested font page from the video adapter. * * EGA/VGA */ static int vga_save_font(video_adapter_t *adp, int page, int fontsize, int fontwidth, u_char *data, int ch, int count) { #ifndef VGA_NO_FONT_LOADING u_char buf[PARAM_BUFSIZE]; vm_offset_t segment; int c; #ifdef VGA_ALT_SEQACCESS int s; u_char val = 0; #endif prologue(adp, V_ADP_FONT, ENODEV); if (fontsize < 14) { /* FONT_8 */ fontsize = 8; } else if (fontsize >= 32) { fontsize = 32; } else if (fontsize >= 16) { /* FONT_16 */ fontsize = 16; } else { /* FONT_14 */ fontsize = 14; } if (page < 0 || page >= 8 || fontwidth != 8) return EINVAL; segment = FONT_BUF + 0x4000*page; if (page > 3) segment -= 0xe000; #ifdef VGA_ALT_SEQACCESS if (adp->va_type == KD_VGA) { /* what about EGA? XXX */ s = splhigh(); outb(TSIDX, 0x00); outb(TSREG, 0x01); outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */ outb(TSIDX, 0x01); outb(TSREG, val | 0x20); outb(TSIDX, 0x00); outb(TSREG, 0x03); splx(s); } #endif set_font_mode(adp, buf); if (fontsize == 32) { bcopy_fromio((uintptr_t)segment + ch*32, data, fontsize*count); } else { for (c = ch; count > 0; ++c, --count) { bcopy_fromio((uintptr_t)segment + c*32, data, fontsize); data += fontsize; } } set_normal_mode(adp, buf); #ifdef VGA_ALT_SEQACCESS if (adp->va_type == KD_VGA) { s = splhigh(); outb(TSIDX, 0x00); outb(TSREG, 0x01); outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */ outb(TSIDX, 0x00); outb(TSREG, 0x03); splx(s); } #endif return 0; #else /* VGA_NO_FONT_LOADING */ return ENODEV; #endif /* VGA_NO_FONT_LOADING */ } /* * load_font(): * Set the font data in the requested font page. * NOTE: it appears that some recent video adapters do not support * the font page other than 0... XXX * * EGA/VGA */ static int vga_load_font(video_adapter_t *adp, int page, int fontsize, int fontwidth, u_char *data, int ch, int count) { #ifndef VGA_NO_FONT_LOADING u_char buf[PARAM_BUFSIZE]; vm_offset_t segment; int c; #ifdef VGA_ALT_SEQACCESS int s; u_char val = 0; #endif prologue(adp, V_ADP_FONT, ENODEV); if (fontsize < 14) { /* FONT_8 */ fontsize = 8; } else if (fontsize >= 32) { fontsize = 32; } else if (fontsize >= 16) { /* FONT_16 */ fontsize = 16; } else { /* FONT_14 */ fontsize = 14; } if (page < 0 || page >= 8 || fontwidth != 8) return EINVAL; segment = FONT_BUF + 0x4000*page; if (page > 3) segment -= 0xe000; #ifdef VGA_ALT_SEQACCESS if (adp->va_type == KD_VGA) { /* what about EGA? XXX */ s = splhigh(); outb(TSIDX, 0x00); outb(TSREG, 0x01); outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */ outb(TSIDX, 0x01); outb(TSREG, val | 0x20); outb(TSIDX, 0x00); outb(TSREG, 0x03); splx(s); } #endif set_font_mode(adp, buf); if (fontsize == 32) { bcopy_toio(data, (uintptr_t)segment + ch*32, fontsize*count); } else { for (c = ch; count > 0; ++c, --count) { bcopy_toio(data, (uintptr_t)segment + c*32, fontsize); data += fontsize; } } set_normal_mode(adp, buf); #ifdef VGA_ALT_SEQACCESS if (adp->va_type == KD_VGA) { s = splhigh(); outb(TSIDX, 0x00); outb(TSREG, 0x01); outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */ outb(TSIDX, 0x00); outb(TSREG, 0x03); splx(s); } #endif return 0; #else /* VGA_NO_FONT_LOADING */ return ENODEV; #endif /* VGA_NO_FONT_LOADING */ } /* * show_font(): * Activate the requested font page. * NOTE: it appears that some recent video adapters do not support * the font page other than 0... XXX * * EGA/VGA */ static int vga_show_font(video_adapter_t *adp, int page) { #ifndef VGA_NO_FONT_LOADING static u_char cg[] = { 0x00, 0x05, 0x0a, 0x0f, 0x30, 0x35, 0x3a, 0x3f }; int s; prologue(adp, V_ADP_FONT, ENODEV); if (page < 0 || page >= 8) return EINVAL; s = splhigh(); outb(TSIDX, 0x03); outb(TSREG, cg[page]); splx(s); return 0; #else /* VGA_NO_FONT_LOADING */ return ENODEV; #endif /* VGA_NO_FONT_LOADING */ } /* * save_palette(): * Read DAC values. The values have expressed in 8 bits. * * VGA */ static int vga_save_palette(video_adapter_t *adp, u_char *palette) { int i; prologue(adp, V_ADP_PALETTE, ENODEV); /* * We store 8 bit values in the palette buffer, while the standard * VGA has 6 bit DAC . */ outb(PALRADR, 0x00); for (i = 0; i < 256*3; ++i) palette[i] = inb(PALDATA) << 2; inb(adp->va_crtc_addr + 6); /* reset flip/flop */ return 0; } static int vga_save_palette2(video_adapter_t *adp, int base, int count, u_char *r, u_char *g, u_char *b) { int i; prologue(adp, V_ADP_PALETTE, ENODEV); outb(PALRADR, base); for (i = 0; i < count; ++i) { r[i] = inb(PALDATA) << 2; g[i] = inb(PALDATA) << 2; b[i] = inb(PALDATA) << 2; } inb(adp->va_crtc_addr + 6); /* reset flip/flop */ return 0; } /* * load_palette(): * Set DAC values. * * VGA */ static int vga_load_palette(video_adapter_t *adp, u_char *palette) { int i; prologue(adp, V_ADP_PALETTE, ENODEV); outb(PIXMASK, 0xff); /* no pixelmask */ outb(PALWADR, 0x00); for (i = 0; i < 256*3; ++i) outb(PALDATA, palette[i] >> 2); inb(adp->va_crtc_addr + 6); /* reset flip/flop */ outb(ATC, 0x20); /* enable palette */ return 0; } static int vga_load_palette2(video_adapter_t *adp, int base, int count, u_char *r, u_char *g, u_char *b) { int i; prologue(adp, V_ADP_PALETTE, ENODEV); outb(PIXMASK, 0xff); /* no pixelmask */ outb(PALWADR, base); for (i = 0; i < count; ++i) { outb(PALDATA, r[i] >> 2); outb(PALDATA, g[i] >> 2); outb(PALDATA, b[i] >> 2); } inb(adp->va_crtc_addr + 6); /* reset flip/flop */ outb(ATC, 0x20); /* enable palette */ return 0; } /* * set_border(): * Change the border color. * * CGA/EGA/VGA */ static int vga_set_border(video_adapter_t *adp, int color) { prologue(adp, V_ADP_BORDER, ENODEV); switch (adp->va_type) { case KD_EGA: case KD_VGA: inb(adp->va_crtc_addr + 6); /* reset flip-flop */ outb(ATC, 0x31); outb(ATC, color & 0xff); break; case KD_CGA: outb(adp->va_crtc_addr + 5, color & 0x0f); /* color select register */ break; case KD_MONO: case KD_HERCULES: default: break; } return 0; } /* * save_state(): * Read video register values. * NOTE: this function only reads the standard EGA/VGA registers. * any extra/extended registers of SVGA adapters are not saved. * * VGA */ static int vga_save_state(video_adapter_t *adp, void *p, size_t size) { video_info_t info; u_char *buf; int crtc_addr; int i, j; int s; if (size == 0) { /* return the required buffer size */ prologue(adp, V_ADP_STATESAVE, 0); return sizeof(adp_state_t); } else { prologue(adp, V_ADP_STATESAVE, ENODEV); if (size < sizeof(adp_state_t)) return EINVAL; } ((adp_state_t *)p)->sig = V_STATE_SIG; buf = ((adp_state_t *)p)->regs; bzero(buf, V_MODE_PARAM_SIZE); crtc_addr = adp->va_crtc_addr; s = splhigh(); outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */ for (i = 0, j = 5; i < 4; i++) { outb(TSIDX, i + 1); buf[j++] = inb(TSREG); } buf[9] = inb(MISC + 10); /* dot-clock */ outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */ for (i = 0, j = 10; i < 25; i++) { /* crtc */ outb(crtc_addr, i); buf[j++] = inb(crtc_addr + 1); } for (i = 0, j = 35; i < 20; i++) { /* attribute ctrl */ inb(crtc_addr + 6); /* reset flip-flop */ outb(ATC, i); buf[j++] = inb(ATC + 1); } for (i = 0, j = 55; i < 9; i++) { /* graph data ctrl */ outb(GDCIDX, i); buf[j++] = inb(GDCREG); } inb(crtc_addr + 6); /* reset flip-flop */ outb(ATC, 0x20); /* enable palette */ splx(s); #if 1 if (vga_get_info(adp, adp->va_mode, &info) == 0) { if (info.vi_flags & V_INFO_GRAPHICS) { buf[0] = info.vi_width/info.vi_cwidth; /* COLS */ buf[1] = info.vi_height/info.vi_cheight - 1; /* ROWS */ } else { buf[0] = info.vi_width; /* COLS */ buf[1] = info.vi_height - 1; /* ROWS */ } buf[2] = info.vi_cheight; /* POINTS */ } else { /* XXX: shouldn't be happening... */ printf("vga%d: %s: failed to obtain mode info. (vga_save_state())\n", adp->va_unit, adp->va_name); } #else buf[0] = readb(BIOS_PADDRTOVADDR(0x44a)); /* COLS */ buf[1] = readb(BIOS_PADDRTOVADDR(0x484)); /* ROWS */ buf[2] = readb(BIOS_PADDRTOVADDR(0x485)); /* POINTS */ buf[3] = readb(BIOS_PADDRTOVADDR(0x44c)); buf[4] = readb(BIOS_PADDRTOVADDR(0x44d)); #endif return 0; } /* * load_state(): * Set video registers at once. * NOTE: this function only updates the standard EGA/VGA registers. * any extra/extended registers of SVGA adapters are not changed. * * EGA/VGA */ static int vga_load_state(video_adapter_t *adp, void *p) { u_char *buf; int crtc_addr; int s; int i; prologue(adp, V_ADP_STATELOAD, ENODEV); if (((adp_state_t *)p)->sig != V_STATE_SIG) return EINVAL; buf = ((adp_state_t *)p)->regs; crtc_addr = adp->va_crtc_addr; #if VGA_DEBUG > 1 dump_buffer(buf, V_MODE_PARAM_SIZE); #endif s = splhigh(); outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */ for (i = 0; i < 4; ++i) { /* program sequencer */ outb(TSIDX, i + 1); outb(TSREG, buf[i + 5]); } outb(MISC, buf[9]); /* set dot-clock */ outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */ outb(crtc_addr, 0x11); outb(crtc_addr + 1, inb(crtc_addr + 1) & 0x7F); for (i = 0; i < 25; ++i) { /* program crtc */ outb(crtc_addr, i); outb(crtc_addr + 1, buf[i + 10]); } inb(crtc_addr+6); /* reset flip-flop */ for (i = 0; i < 20; ++i) { /* program attribute ctrl */ outb(ATC, i); outb(ATC, buf[i + 35]); } for (i = 0; i < 9; ++i) { /* program graph data ctrl */ outb(GDCIDX, i); outb(GDCREG, buf[i + 55]); } inb(crtc_addr + 6); /* reset flip-flop */ outb(ATC, 0x20); /* enable palette */ #ifdef notyet /* a temporary workaround for kernel panic, XXX */ #ifndef VGA_NO_BIOS if (adp->va_unit == V_ADP_PRIMARY) { writeb(BIOS_PADDRTOVADDR(0x44a), buf[0]); /* COLS */ writeb(BIOS_PADDRTOVADDR(0x484), buf[1] + rows_offset - 1); /* ROWS */ writeb(BIOS_PADDRTOVADDR(0x485), buf[2]); /* POINTS */ #if 0 writeb(BIOS_PADDRTOVADDR(0x44c), buf[3]); writeb(BIOS_PADDRTOVADDR(0x44d), buf[4]); #endif } #endif /* VGA_NO_BIOS */ #endif /* notyet */ splx(s); return 0; } /* * set_origin(): * Change the origin (window mapping) of the banked frame buffer. */ static int vga_set_origin(video_adapter_t *adp, off_t offset) { /* * The standard video modes do not require window mapping; * always return error. */ return ENODEV; } /* * read_hw_cursor(): * Read the position of the hardware text cursor. * * all adapters */ static int vga_read_hw_cursor(video_adapter_t *adp, int *col, int *row) { u_int16_t off; int s; if (!vga_init_done) return ENXIO; if (adp->va_info.vi_flags & V_INFO_GRAPHICS) return ENODEV; s = spltty(); outb(adp->va_crtc_addr, 14); off = inb(adp->va_crtc_addr + 1); outb(adp->va_crtc_addr, 15); off = (off << 8) | inb(adp->va_crtc_addr + 1); splx(s); *row = off / adp->va_info.vi_width; *col = off % adp->va_info.vi_width; return 0; } /* * set_hw_cursor(): * Move the hardware text cursor. If col and row are both -1, * the cursor won't be shown. * * all adapters */ static int vga_set_hw_cursor(video_adapter_t *adp, int col, int row) { u_int16_t off; int s; if (!vga_init_done) return ENXIO; if ((col == -1) && (row == -1)) { off = -1; } else { if (adp->va_info.vi_flags & V_INFO_GRAPHICS) return ENODEV; off = row*adp->va_info.vi_width + col; } s = spltty(); outb(adp->va_crtc_addr, 14); outb(adp->va_crtc_addr + 1, off >> 8); outb(adp->va_crtc_addr, 15); outb(adp->va_crtc_addr + 1, off & 0x00ff); splx(s); return 0; } /* * set_hw_cursor_shape(): * Change the shape of the hardware text cursor. If the height is * zero or negative, the cursor won't be shown. * * all adapters */ static int vga_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, int celsize, int blink) { int s; if (!vga_init_done) return ENXIO; s = spltty(); switch (adp->va_type) { case KD_VGA: case KD_CGA: case KD_MONO: case KD_HERCULES: default: if (height <= 0) { /* make the cursor invisible */ outb(adp->va_crtc_addr, 10); outb(adp->va_crtc_addr + 1, 32); outb(adp->va_crtc_addr, 11); outb(adp->va_crtc_addr + 1, 0); } else { outb(adp->va_crtc_addr, 10); outb(adp->va_crtc_addr + 1, celsize - base - height); outb(adp->va_crtc_addr, 11); outb(adp->va_crtc_addr + 1, celsize - base - 1); } break; case KD_EGA: if (height <= 0) { /* make the cursor invisible */ outb(adp->va_crtc_addr, 10); outb(adp->va_crtc_addr + 1, celsize); outb(adp->va_crtc_addr, 11); outb(adp->va_crtc_addr + 1, 0); } else { outb(adp->va_crtc_addr, 10); outb(adp->va_crtc_addr + 1, celsize - base - height); outb(adp->va_crtc_addr, 11); outb(adp->va_crtc_addr + 1, celsize - base); } break; } splx(s); return 0; } /* * blank_display() * Put the display in power save/power off mode. * * all adapters */ static int vga_blank_display(video_adapter_t *adp, int mode) { u_char val; int s; s = splhigh(); switch (adp->va_type) { case KD_VGA: switch (mode) { case V_DISPLAY_SUSPEND: case V_DISPLAY_STAND_BY: outb(TSIDX, 0x01); val = inb(TSREG); outb(TSIDX, 0x01); outb(TSREG, val | 0x20); outb(adp->va_crtc_addr, 0x17); val = inb(adp->va_crtc_addr + 1); outb(adp->va_crtc_addr + 1, val & ~0x80); break; case V_DISPLAY_BLANK: outb(TSIDX, 0x01); val = inb(TSREG); outb(TSIDX, 0x01); outb(TSREG, val | 0x20); break; case V_DISPLAY_ON: outb(TSIDX, 0x01); val = inb(TSREG); outb(TSIDX, 0x01); outb(TSREG, val & 0xDF); outb(adp->va_crtc_addr, 0x17); val = inb(adp->va_crtc_addr + 1); outb(adp->va_crtc_addr + 1, val | 0x80); break; } break; case KD_EGA: /* no support yet */ splx(s); return ENODEV; case KD_CGA: switch (mode) { case V_DISPLAY_SUSPEND: case V_DISPLAY_STAND_BY: case V_DISPLAY_BLANK: outb(adp->va_crtc_addr + 4, 0x25); break; case V_DISPLAY_ON: outb(adp->va_crtc_addr + 4, 0x2d); break; } break; case KD_MONO: case KD_HERCULES: switch (mode) { case V_DISPLAY_SUSPEND: case V_DISPLAY_STAND_BY: case V_DISPLAY_BLANK: outb(adp->va_crtc_addr + 4, 0x21); break; case V_DISPLAY_ON: outb(adp->va_crtc_addr + 4, 0x29); break; } break; default: break; } splx(s); return 0; } /* * mmap(): * Mmap frame buffer. * * all adapters */ static int vga_mmap_buf(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr, int prot) { if (adp->va_info.vi_flags & V_INFO_LINEAR) return -1; #if VGA_DEBUG > 0 printf("vga_mmap_buf(): window:0x%jx, offset:0x%jx\n", (uintmax_t)adp->va_info.vi_window, (uintmax_t)offset); #endif /* XXX: is this correct? */ if (offset > adp->va_window_size - PAGE_SIZE) return -1; *paddr = adp->va_info.vi_window + offset; return 0; } #ifndef VGA_NO_MODE_CHANGE static void planar_fill(video_adapter_t *adp, int val) { int length; int at; /* position in the frame buffer */ int l; outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, 0x0003); /* data rotate/function select */ outw(GDCIDX, 0x0f01); /* set/reset enable */ outw(GDCIDX, 0xff08); /* bit mask */ outw(GDCIDX, (val << 8) | 0x00); /* set/reset */ at = 0; length = adp->va_line_width*adp->va_info.vi_height; while (length > 0) { l = imin(length, adp->va_window_size); - (*vidsw[adp->va_index]->set_win_org)(adp, at); + vidd_set_win_org(adp, at); bzero_io(adp->va_window, l); length -= l; at += l; } outw(GDCIDX, 0x0000); /* set/reset */ outw(GDCIDX, 0x0001); /* set/reset enable */ } static void packed_fill(video_adapter_t *adp, int val) { int length; int at; /* position in the frame buffer */ int l; at = 0; length = adp->va_line_width*adp->va_info.vi_height; while (length > 0) { l = imin(length, adp->va_window_size); - (*vidsw[adp->va_index]->set_win_org)(adp, at); + vidd_set_win_org(adp, at); fill_io(val, adp->va_window, l); length -= l; at += l; } } static void direct_fill(video_adapter_t *adp, int val) { int length; int at; /* position in the frame buffer */ int l; at = 0; length = adp->va_line_width*adp->va_info.vi_height; while (length > 0) { l = imin(length, adp->va_window_size); - (*vidsw[adp->va_index]->set_win_org)(adp, at); + vidd_set_win_org(adp, at); switch (adp->va_info.vi_pixel_size) { case sizeof(u_int16_t): fillw_io(val, adp->va_window, l/sizeof(u_int16_t)); break; case 3: /* FIXME */ break; case sizeof(u_int32_t): filll_io(val, adp->va_window, l/sizeof(u_int32_t)); break; } length -= l; at += l; } } static int vga_clear(video_adapter_t *adp) { switch (adp->va_info.vi_mem_model) { case V_INFO_MM_TEXT: /* do nothing? XXX */ break; case V_INFO_MM_PLANAR: planar_fill(adp, 0); break; case V_INFO_MM_PACKED: packed_fill(adp, 0); break; case V_INFO_MM_DIRECT: direct_fill(adp, 0); break; } return 0; } #ifdef notyet static void planar_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) { int banksize; int bank; int pos; int offset; /* offset within window */ int bx; int l; outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, 0x0003); /* data rotate/function select */ outw(GDCIDX, 0x0f01); /* set/reset enable */ outw(GDCIDX, 0xff08); /* bit mask */ outw(GDCIDX, (val << 8) | 0x00); /* set/reset */ banksize = adp->va_window_size; bank = -1; while (cy > 0) { pos = adp->va_line_width*y + x/8; if (bank != pos/banksize) { - (*vidsw[adp->va_index]->set_win_org)(adp, pos); + vidd_set_win_org(adp, pos); bank = pos/banksize; } offset = pos%banksize; bx = (x + cx)/8 - x/8; if (x % 8) { outw(GDCIDX, ((0xff00 >> (x % 8)) & 0xff00) | 0x08); writeb(adp->va_window + offset, 0); ++offset; --bx; if (offset >= banksize) { offset = 0; ++bank; /* next bank */ - (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); + vidd_set_win_org(adp, bank*banksize); } outw(GDCIDX, 0xff08); /* bit mask */ } while (bx > 0) { l = imin(bx, banksize); bzero_io(adp->va_window + offset, l); offset += l; bx -= l; if (offset >= banksize) { offset = 0; ++bank; /* next bank */ - (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); + vidd_set_win_org(adp, bank*banksize); } } if ((x + cx) % 8) { outw(GDCIDX, (~(0xff00 >> ((x + cx) % 8)) & 0xff00) | 0x08); writeb(adp->va_window + offset, 0); ++offset; if (offset >= banksize) { offset = 0; ++bank; /* next bank */ - (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); + vidd_set_win_org(adp, bank*banksize); } outw(GDCIDX, 0xff08); /* bit mask */ } ++y; --cy; } outw(GDCIDX, 0xff08); /* bit mask */ outw(GDCIDX, 0x0000); /* set/reset */ outw(GDCIDX, 0x0001); /* set/reset enable */ } static void packed_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) { int banksize; int bank; int pos; int offset; /* offset within window */ int end; banksize = adp->va_window_size; bank = -1; cx *= adp->va_info.vi_pixel_size; while (cy > 0) { pos = adp->va_line_width*y + x*adp->va_info.vi_pixel_size; if (bank != pos/banksize) { - (*vidsw[adp->va_index]->set_win_org)(adp, pos); + vidd_set_win_org(adp, pos); bank = pos/banksize; } offset = pos%banksize; end = imin(offset + cx, banksize); fill_io(val, adp->va_window + offset, (end - offset)/adp->va_info.vi_pixel_size); /* the line may cross the window boundary */ if (offset + cx > banksize) { ++bank; /* next bank */ - (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); + vidd_set_win_org(adp, bank*banksize); end = offset + cx - banksize; fill_io(val, adp->va_window, end/adp->va_info.vi_pixel_size); } ++y; --cy; } } static void direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, int cx, int cy) { int banksize; int bank; int pos; int offset; /* offset within window */ int end; /* * XXX: the function assumes that banksize is a muliple of * sizeof(u_int16_t). */ banksize = adp->va_window_size; bank = -1; cx *= sizeof(u_int16_t); while (cy > 0) { pos = adp->va_line_width*y + x*sizeof(u_int16_t); if (bank != pos/banksize) { - (*vidsw[adp->va_index]->set_win_org)(adp, pos); + vidd_set_win_org(adp, pos); bank = pos/banksize; } offset = pos%banksize; end = imin(offset + cx, banksize); fillw_io(val, adp->va_window + offset, (end - offset)/sizeof(u_int16_t)); /* the line may cross the window boundary */ if (offset + cx > banksize) { ++bank; /* next bank */ - (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); + vidd_set_win_org(adp, bank*banksize); end = offset + cx - banksize; fillw_io(val, adp->va_window, end/sizeof(u_int16_t)); } ++y; --cy; } } static void direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, int cx, int cy) { int banksize; int bank; int pos; int offset; /* offset within window */ int end; int i; int j; u_int8_t b[3]; b[0] = val & 0x0000ff; b[1] = (val >> 8) & 0x0000ff; b[2] = (val >> 16) & 0x0000ff; banksize = adp->va_window_size; bank = -1; cx *= 3; while (cy > 0) { pos = adp->va_line_width*y + x*3; if (bank != pos/banksize) { - (*vidsw[adp->va_index]->set_win_org)(adp, pos); + vidd_set_win_org(adp, pos); bank = pos/banksize; } offset = pos%banksize; end = imin(offset + cx, banksize); for (i = 0, j = offset; j < end; i = (++i)%3, ++j) { writeb(adp->va_window + j, b[i]); } /* the line may cross the window boundary */ if (offset + cx >= banksize) { ++bank; /* next bank */ - (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); + vidd_set_win_org(adp, bank*banksize); j = 0; end = offset + cx - banksize; for (; j < end; i = (++i)%3, ++j) { writeb(adp->va_window + j, b[i]); } } ++y; --cy; } } static void direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, int cx, int cy) { int banksize; int bank; int pos; int offset; /* offset within window */ int end; /* * XXX: the function assumes that banksize is a muliple of * sizeof(u_int32_t). */ banksize = adp->va_window_size; bank = -1; cx *= sizeof(u_int32_t); while (cy > 0) { pos = adp->va_line_width*y + x*sizeof(u_int32_t); if (bank != pos/banksize) { - (*vidsw[adp->va_index]->set_win_org)(adp, pos); + vidd_set_win_org(adp, pos); bank = pos/banksize; } offset = pos%banksize; end = imin(offset + cx, banksize); filll_io(val, adp->va_window + offset, (end - offset)/sizeof(u_int32_t)); /* the line may cross the window boundary */ if (offset + cx > banksize) { ++bank; /* next bank */ - (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); + vidd_set_win_org(adp, bank*banksize); end = offset + cx - banksize; filll_io(val, adp->va_window, end/sizeof(u_int32_t)); } ++y; --cy; } } static int vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) { switch (adp->va_info.vi_mem_model) { case V_INFO_MM_TEXT: /* do nothing? XXX */ break; case V_INFO_MM_PLANAR: planar_fill_rect(adp, val, x, y, cx, cy); break; case V_INFO_MM_PACKED: packed_fill_rect(adp, val, x, y, cx, cy); break; case V_INFO_MM_DIRECT: switch (adp->va_info.vi_pixel_size) { case sizeof(u_int16_t): direct_fill_rect16(adp, val, x, y, cx, cy); break; case 3: direct_fill_rect24(adp, val, x, y, cx, cy); break; case sizeof(u_int32_t): direct_fill_rect32(adp, val, x, y, cx, cy); break; } break; } return 0; } #else /* !notyet */ static int vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) { return ENODEV; } #endif /* notyet */ static int vga_bitblt(video_adapter_t *adp,...) { /* FIXME */ return ENODEV; } #endif /* !VGA_NO_MODE_CHANGE */ static int get_palette(video_adapter_t *adp, int base, int count, u_char *red, u_char *green, u_char *blue, u_char *trans) { u_char *r; u_char *g; u_char *b; if (count < 0 || base < 0 || count > 256 || base > 256 || base + count > 256) return EINVAL; r = malloc(count*3, M_DEVBUF, M_WAITOK); g = r + count; b = g + count; if (vga_save_palette2(adp, base, count, r, g, b)) { free(r, M_DEVBUF); return ENODEV; } copyout(r, red, count); copyout(g, green, count); copyout(b, blue, count); if (trans != NULL) { bzero(r, count); copyout(r, trans, count); } free(r, M_DEVBUF); return 0; } static int set_palette(video_adapter_t *adp, int base, int count, u_char *red, u_char *green, u_char *blue, u_char *trans) { u_char *r; u_char *g; u_char *b; int err; if (count < 0 || base < 0 || count > 256 || base > 256 || base + count > 256) return EINVAL; r = malloc(count*3, M_DEVBUF, M_WAITOK); g = r + count; b = g + count; err = copyin(red, r, count); if (!err) err = copyin(green, g, count); if (!err) err = copyin(blue, b, count); if (!err) err = vga_load_palette2(adp, base, count, r, g, b); free(r, M_DEVBUF); return (err ? ENODEV : 0); } static int vga_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg) { switch (cmd) { case FBIO_GETWINORG: /* get frame buffer window origin */ *(u_int *)arg = 0; return 0; case FBIO_SETWINORG: /* set frame buffer window origin */ return ENODEV; case FBIO_SETDISPSTART: /* set display start address */ return (set_display_start(adp, ((video_display_start_t *)arg)->x, ((video_display_start_t *)arg)->y) ? ENODEV : 0); case FBIO_SETLINEWIDTH: /* set scan line length in pixel */ return (set_line_length(adp, *(u_int *)arg) ? ENODEV : 0); case FBIO_GETPALETTE: /* get color palette */ return get_palette(adp, ((video_color_palette_t *)arg)->index, ((video_color_palette_t *)arg)->count, ((video_color_palette_t *)arg)->red, ((video_color_palette_t *)arg)->green, ((video_color_palette_t *)arg)->blue, ((video_color_palette_t *)arg)->transparent); case FBIO_SETPALETTE: /* set color palette */ return set_palette(adp, ((video_color_palette_t *)arg)->index, ((video_color_palette_t *)arg)->count, ((video_color_palette_t *)arg)->red, ((video_color_palette_t *)arg)->green, ((video_color_palette_t *)arg)->blue, ((video_color_palette_t *)arg)->transparent); case FBIOGTYPE: /* get frame buffer type info. */ ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type); ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height; ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width; ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth; if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8)) ((struct fbtype *)arg)->fb_cmsize = 0; else ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth; ((struct fbtype *)arg)->fb_size = adp->va_buffer_size; return 0; case FBIOGETCMAP: /* get color palette */ return get_palette(adp, ((struct fbcmap *)arg)->index, ((struct fbcmap *)arg)->count, ((struct fbcmap *)arg)->red, ((struct fbcmap *)arg)->green, ((struct fbcmap *)arg)->blue, NULL); case FBIOPUTCMAP: /* set color palette */ return set_palette(adp, ((struct fbcmap *)arg)->index, ((struct fbcmap *)arg)->count, ((struct fbcmap *)arg)->red, ((struct fbcmap *)arg)->green, ((struct fbcmap *)arg)->blue, NULL); default: return fb_commonioctl(adp, cmd, arg); } } static void dump_buffer(u_char *buf, size_t len) { int i; for(i = 0; i < len;) { printf("%02x ", buf[i]); if ((++i % 16) == 0) printf("\n"); } } /* * diag(): * Print some information about the video adapter and video modes, * with requested level of details. * * all adapters */ static int vga_diag(video_adapter_t *adp, int level) { u_char *mp; #if FB_DEBUG > 1 video_info_t info; int i; #endif if (!vga_init_done) return ENXIO; #if FB_DEBUG > 1 #ifndef VGA_NO_BIOS printf("vga: RTC equip. code:0x%02x, DCC code:0x%02x\n", rtcin(RTC_EQUIPMENT), readb(BIOS_PADDRTOVADDR(0x488))); printf("vga: CRTC:0x%x, video option:0x%02x, ", readw(BIOS_PADDRTOVADDR(0x463)), readb(BIOS_PADDRTOVADDR(0x487))); printf("rows:%d, cols:%d, font height:%d\n", readb(BIOS_PADDRTOVADDR(0x44a)), readb(BIOS_PADDRTOVADDR(0x484)) + 1, readb(BIOS_PADDRTOVADDR(0x485))); #endif /* VGA_NO_BIOS */ #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) printf("vga: param table EGA/VGA:%p", video_mode_ptr); printf(", CGA/MDA:%p\n", video_mode_ptr2); printf("vga: rows_offset:%d\n", rows_offset); #endif #endif /* FB_DEBUG > 1 */ fb_dump_adp_info(VGA_DRIVER_NAME, adp, level); #if FB_DEBUG > 1 if (adp->va_flags & V_ADP_MODECHANGE) { for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) { if (bios_vmode[i].vi_mode == NA) continue; if (get_mode_param(bios_vmode[i].vi_mode) == NULL) continue; fb_dump_mode_info(VGA_DRIVER_NAME, adp, &bios_vmode[i], level); } } else { vga_get_info(adp, adp->va_initial_mode, &info); /* shouldn't fail */ fb_dump_mode_info(VGA_DRIVER_NAME, adp, &info, level); } #endif /* FB_DEBUG > 1 */ if ((adp->va_type != KD_EGA) && (adp->va_type != KD_VGA)) return 0; #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) if (video_mode_ptr == NULL) printf("vga%d: %s: WARNING: video mode switching is not " "fully supported on this adapter\n", adp->va_unit, adp->va_name); #endif if (level <= 0) return 0; if (adp->va_type == KD_VGA) { printf("VGA parameters upon power-up\n"); dump_buffer(adpstate.regs, sizeof(adpstate.regs)); printf("VGA parameters in BIOS for mode %d\n", adp->va_initial_mode); dump_buffer(adpstate2.regs, sizeof(adpstate2.regs)); } mp = get_mode_param(adp->va_initial_mode); if (mp == NULL) /* this shouldn't be happening */ return 0; printf("EGA/VGA parameters to be used for mode %d\n", adp->va_initial_mode); dump_buffer(mp, V_MODE_PARAM_SIZE); return 0; } Index: head/sys/dev/syscons/blank/blank_saver.c =================================================================== --- head/sys/dev/syscons/blank/blank_saver.c (revision 174984) +++ head/sys/dev/syscons/blank/blank_saver.c (revision 174985) @@ -1,69 +1,67 @@ /*- * Copyright (c) 1995-1998 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include static int blank_saver(video_adapter_t *adp, int blank) { - (*vidsw[adp->va_index]->blank_display)(adp, - (blank) ? V_DISPLAY_BLANK - : V_DISPLAY_ON); + vidd_blank_display(adp, (blank) ? V_DISPLAY_BLANK : V_DISPLAY_ON); return 0; } static int blank_init(video_adapter_t *adp) { - if ((*vidsw[adp->va_index]->blank_display)(adp, V_DISPLAY_ON) == 0) + if (vidd_blank_display(adp, V_DISPLAY_ON) == 0) return 0; return ENODEV; } static int blank_term(video_adapter_t *adp) { return 0; } static scrn_saver_t blank_module = { "blank_saver", blank_init, blank_term, blank_saver, NULL, }; SAVER_MODULE(blank_saver, blank_module); Index: head/sys/dev/syscons/daemon/daemon_saver.c =================================================================== --- head/sys/dev/syscons/daemon/daemon_saver.c (revision 174984) +++ head/sys/dev/syscons/daemon/daemon_saver.c (revision 174985) @@ -1,382 +1,382 @@ /*- * Copyright (c) 1997 Sandro Sigala, Brescia, Italy. * Copyright (c) 1997 Chris Shenton * Copyright (c) 1995 S ren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer * in this position and unchanged. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #include #include #define DAEMON_MAX_WIDTH 32 #define DAEMON_MAX_HEIGHT 19 static u_char *message; static int messagelen; static int blanked; static int attr_mask; #define ATTR(attr) (((attr) & attr_mask) << 8) /* Who is the author of this ASCII pic? */ static u_char *daemon_pic[] = { " , ,", " /( )`", " \\ \\___ / |", " /- _ `-/ '", " (/\\/ \\ \\ /\\", " / / | ` \\", " O O ) / |", " `-^--'`< '", " (_.) _ ) /", " `.___/` /", " `-----' /", "<----. __ / __ \\", "<----|====O)))==) \\) /====", "<----' `--' `.__,' \\", " | |", " \\ / /\\", " ______( (_ / \\______/", " ,' ,-----' |", " `--{__________)", NULL }; static u_char *daemon_attr[] = { " R R", " RR RR", " R RRRR R R", " RR W RRR R", " RWWW W R RR", " W W W R R", " B B W R R", " WWWWWWRR R", " RRRR R R R", " RRRRRRR R", " RRRRRRR R", "YYYYYY RR R RR R", "YYYYYYYYYYRRRRYYR RR RYYYY", "YYYYYY RRRR RRRRRR R", " R R", " R R RR", " CCCCCCR RR R RRRRRRRR", " CC CCCCCCC C", " CCCCCCCCCCCCCCC", NULL }; /* * Reverse a graphics character, or return unaltered if no mirror; * should do alphanumerics too, but I'm too lazy. */ static u_char xflip_symbol(u_char symbol) { static const u_char lchars[] = "`'(){}[]\\/<>"; static const u_char rchars[] = "'`)(}{][/\\><"; int pos; for (pos = 0; lchars[pos] != '\0'; pos++) if (lchars[pos] == symbol) return rchars[pos]; return symbol; } static void clear_daemon(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff, int xlen, int ylen) { int y; if (xlen <= 0) return; for (y = yoff; y < ylen; y++) { sc_vtb_erase(&sc->cur_scp->scr, (ypos + y)*sc->cur_scp->xsize + xpos + xoff, xlen - xoff, sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK)); } } static void draw_daemon(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff, int xlen, int ylen) { int x, y; int px; int attr; for (y = yoff; y < ylen; y++) { if (dxdir < 0) px = xoff; else px = DAEMON_MAX_WIDTH - xlen; if (px >= strlen(daemon_pic[y])) continue; for (x = xoff; (x < xlen) && (daemon_pic[y][px] != '\0'); x++, px++) { switch (daemon_attr[y][px]) { case 'R': attr = FG_LIGHTRED | BG_BLACK; break; case 'Y': attr = FG_YELLOW | BG_BLACK; break; case 'B': attr = FG_LIGHTBLUE | BG_BLACK; break; case 'W': attr = FG_LIGHTGREY | BG_BLACK; break; case 'C': attr = FG_CYAN | BG_BLACK; break; default: attr = FG_WHITE | BG_BLACK; break; } if (dxdir < 0) { /* Moving left */ sc_vtb_putc(&sc->cur_scp->scr, (ypos + y)*sc->cur_scp->xsize + xpos + x, sc->scr_map[daemon_pic[y][px]], ATTR(attr)); } else { /* Moving right */ sc_vtb_putc(&sc->cur_scp->scr, (ypos + y)*sc->cur_scp->xsize + xpos + DAEMON_MAX_WIDTH - px - 1, sc->scr_map[xflip_symbol(daemon_pic[y][px])], ATTR(attr)); } } } } static void clear_string(sc_softc_t *sc, int xpos, int ypos, int xoff, char *s, int len) { if (len <= 0) return; sc_vtb_erase(&sc->cur_scp->scr, ypos*sc->cur_scp->xsize + xpos + xoff, len - xoff, sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK)); } static void draw_string(sc_softc_t *sc, int xpos, int ypos, int xoff, u_char *s, int len) { int x; for (x = xoff; x < len; x++) sc_vtb_putc(&sc->cur_scp->scr, ypos*sc->cur_scp->xsize + xpos + x, sc->scr_map[s[x]], ATTR(FG_LIGHTGREEN | BG_BLACK)); } static int daemon_saver(video_adapter_t *adp, int blank) { static int txpos = 10, typos = 10; static int txdir = -1, tydir = -1; static int dxpos = 0, dypos = 0; static int dxdir = 1, dydir = 1; static int moved_daemon = 0; static int xoff, yoff, toff; static int xlen, ylen, tlen; sc_softc_t *sc; scr_stat *scp; int min, max; sc = sc_find_softc(adp, NULL); if (sc == NULL) return EAGAIN; scp = sc->cur_scp; if (blank) { if (adp->va_info.vi_flags & V_INFO_GRAPHICS) return EAGAIN; if (blanked == 0) { /* clear the screen and set the border color */ sc_vtb_clear(&scp->scr, sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK)); - (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1); + vidd_set_hw_cursor(adp, -1, -1); sc_set_border(scp, 0); xlen = ylen = tlen = 0; } if (blanked++ < 2) return 0; blanked = 1; clear_daemon(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen); clear_string(sc, txpos, typos, toff, message, tlen); if (++moved_daemon) { /* * The daemon picture may be off the screen, if * screen size is chagened while the screen * saver is inactive. Make sure the origin of * the picture is between min and max. */ if (scp->xsize <= DAEMON_MAX_WIDTH) { /* * If the screen width is too narrow, we * allow part of the picture go off * the screen so that the daemon won't * flip too often. */ min = scp->xsize - DAEMON_MAX_WIDTH - 10; max = 10; } else { min = 0; max = scp->xsize - DAEMON_MAX_WIDTH; } if (dxpos <= min) { dxpos = min; dxdir = 1; } else if (dxpos >= max) { dxpos = max; dxdir = -1; } if (scp->ysize <= DAEMON_MAX_HEIGHT) { min = scp->ysize - DAEMON_MAX_HEIGHT - 10; max = 10; } else { min = 0; max = scp->ysize - DAEMON_MAX_HEIGHT; } if (dypos <= min) { dypos = min; dydir = 1; } else if (dypos >= max) { dypos = max; dydir = -1; } moved_daemon = -1; dxpos += dxdir; dypos += dydir; /* clip the picture */ xoff = 0; xlen = DAEMON_MAX_WIDTH; if (dxpos + xlen <= 0) xlen = 0; else if (dxpos < 0) xoff = -dxpos; if (dxpos >= scp->xsize) xlen = 0; else if (dxpos + xlen > scp->xsize) xlen = scp->xsize - dxpos; yoff = 0; ylen = DAEMON_MAX_HEIGHT; if (dypos + ylen <= 0) ylen = 0; else if (dypos < 0) yoff = -dypos; if (dypos >= scp->ysize) ylen = 0; else if (dypos + ylen > scp->ysize) ylen = scp->ysize - dypos; } if (scp->xsize <= messagelen) { min = scp->xsize - messagelen - 10; max = 10; } else { min = 0; max = scp->xsize - messagelen; } if (txpos <= min) { txpos = min; txdir = 1; } else if (txpos >= max) { txpos = max; txdir = -1; } if (typos <= 0) { typos = 0; tydir = 1; } else if (typos >= scp->ysize - 1) { typos = scp->ysize - 1; tydir = -1; } txpos += txdir; typos += tydir; toff = 0; tlen = messagelen; if (txpos + tlen <= 0) tlen = 0; else if (txpos < 0) toff = -txpos; if (txpos >= scp->xsize) tlen = 0; else if (txpos + tlen > scp->xsize) tlen = scp->xsize - txpos; draw_daemon(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen); draw_string(sc, txpos, typos, toff, message, tlen); } else blanked = 0; return 0; } static int daemon_init(video_adapter_t *adp) { messagelen = strlen(hostname) + 3 + strlen(ostype) + 1 + strlen(osrelease); message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK); sprintf(message, "%s - %s %s", hostname, ostype, osrelease); blanked = 0; switch (adp->va_mode) { case M_PC98_80x25: case M_PC98_80x30: attr_mask = ~FG_UNDERLINE; break; default: attr_mask = ~0; break; } return 0; } static int daemon_term(video_adapter_t *adp) { free(message, M_DEVBUF); return 0; } static scrn_saver_t daemon_module = { "daemon_saver", daemon_init, daemon_term, daemon_saver, NULL, }; SAVER_MODULE(daemon_saver, daemon_module); Index: head/sys/dev/syscons/dragon/dragon_saver.c =================================================================== --- head/sys/dev/syscons/dragon/dragon_saver.c (revision 174984) +++ head/sys/dev/syscons/dragon/dragon_saver.c (revision 174985) @@ -1,257 +1,257 @@ /*- * Copyright (c) 2000 Chiharu Shibata * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer * in this position and unchanged. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #include #define SAVER_NAME "dragon_saver" static u_char *vid; static int blanked; #ifdef PC98 #define VIDEO_MODE M_PC98_EGC640x400 #define VIDEO_MODE_NAME "M_PC98_EGC640x400" #define SCRW 640 #define SCRH 400 #else #define VIDEO_MODE M_VGA_CG320 #define VIDEO_MODE_NAME "M_VGA_CG320" #define SCRW 320 #define SCRH 200 #endif #define ORDER 13 #define CURVE 3 #define OUT 100 static int cur_x, cur_y; static int curve; static u_char dragon_pal[3*256]; /* zero-filled by the compiler */ static __inline int gpset(int x, int y, int val) { if (x < 0 || y < 0 || SCRW <= x || SCRH <= y) { return 0; } #ifdef PC98 vid[(x + y * SCRW) >> 3] = (0x80 >> (x & 7)); /* write new dot */ #else vid[x + y * SCRW] = val; #endif return 1; } static int gdraw(int dx, int dy, int val) { int i; int set = 0; #ifdef PC98 outb(0x7c, 0xcc); /* GRCG on & RMW mode(disable planeI,G) */ outb(0x7e, (val & 1) ? 0xff: 0); /* tile B */ outb(0x7e, (val & 2) ? 0xff: 0); /* tile R */ #endif if (dx != 0) { i = cur_x; cur_x += dx; if (dx < 0) { i += dx; dx = -dx; } /* horizontal line */ for (; dx >= 0; --dx, ++i) { set |= gpset(i, cur_y, val); } } else { /* dy != 0 */ i = cur_y; cur_y += dy; if (dy < 0) { i += dy; dy = -dy; } /* vertical line */ for (; dy >= 0; --dy, ++i) { set |= gpset(cur_x, i, val); } } #ifdef PC98 outb(0x7c, 0); /* GRCG off */ #endif return set; } static void dragon_update(video_adapter_t *adp) { static int i, p, q; static int order, mul, out; static int org_x, org_y; static int dx, dy; static unsigned char fold[1 << (ORDER - 3)]; #define GET_FOLD(x) (fold[(x) >> 3] & (1 << ((x) & 7))) #define SET_FOLD(x) (fold[(x) >> 3] |= (1 << ((x) & 7))) #define CLR_FOLD(x) (fold[(x) >> 3] &= ~(1 << ((x) & 7))) int tmp; if (curve > CURVE) { - (*vidsw[adp->va_index]->clear)(adp); + vidd_clear(adp); /* set palette of each curves */ for (tmp = 0; tmp < 3*CURVE; ++tmp) { dragon_pal[3+tmp] = (u_char)random(); } - load_palette(adp, dragon_pal); + vidd_load_palette(adp, dragon_pal); mul = ((random() & 7) + 1) * (SCRW / 320); org_x = random() % SCRW; org_y = random() % SCRH; curve = 0; order = ORDER; } if (order >= ORDER) { ++curve; cur_x = org_x; cur_y = org_y; switch (curve) { case 1: dx = 0; dy = mul; break; case 2: dx = mul; dy = 0; break; case 3: dx = 0; dy = -mul; break; } (void)gdraw(dx, dy, curve); out = 0; order = 0; q = p = 0; i = q + 1; } if (i > q) { SET_FOLD(p); q = p * 2; ++order; i = p; p = q + 1; } if (GET_FOLD(q-i) != 0) { CLR_FOLD(i); tmp = dx; dx = dy; dy = -tmp; /* turn right */ } else { SET_FOLD(i); tmp = dx; dx = -dy; dy = tmp; /* turn left */ } if (gdraw(dx, dy, curve)) { out = 0; } else { if (++out > OUT) { order = ORDER; /* force to terminate this curve */ } } ++i; } static int dragon_saver(video_adapter_t *adp, int blank) { int pl; if (blank) { /* switch to graphics mode */ if (blanked <= 0) { pl = splhigh(); - set_video_mode(adp, VIDEO_MODE); + vidd_set_mode(adp, VIDEO_MODE); vid = (u_char *)adp->va_window; curve = CURVE + 1; ++blanked; splx(pl); } /* update display */ dragon_update(adp); } else { blanked = 0; } return 0; } static int dragon_init(video_adapter_t *adp) { video_info_t info; /* check that the console is capable of running in 320x200x256 */ - if (get_mode_info(adp, VIDEO_MODE, &info)) { + if (vidd_get_info(adp, VIDEO_MODE, &info)) { log(LOG_NOTICE, "%s: the console does not support " VIDEO_MODE_NAME "\n", SAVER_NAME); return ENODEV; } blanked = 0; return 0; } static int dragon_term(video_adapter_t *adp) { return 0; } static scrn_saver_t dragon_module = { SAVER_NAME, dragon_init, dragon_term, dragon_saver, NULL, }; SAVER_MODULE(dragon_saver, dragon_module); Index: head/sys/dev/syscons/fade/fade_saver.c =================================================================== --- head/sys/dev/syscons/fade/fade_saver.c (revision 174984) +++ head/sys/dev/syscons/fade/fade_saver.c (revision 174985) @@ -1,101 +1,99 @@ /*- * Copyright (c) 1995-1998 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include static u_char palette[256*3]; static int fade_saver(video_adapter_t *adp, int blank) { static int count = 0; u_char pal[256*3]; int i; if (blank) { if (ISPALAVAIL(adp->va_flags)) { if (count <= 0) - save_palette(adp, palette); + vidd_save_palette(adp, palette); if (count < 256) { pal[0] = pal[1] = pal[2] = 0; for (i = 3; i < 256*3; i++) { if (palette[i] - count > 60) pal[i] = palette[i] - count; else pal[i] = 60; } - load_palette(adp, pal); + vidd_load_palette(adp, pal); count++; } } else { - (*vidsw[adp->va_index]->blank_display)(adp, - V_DISPLAY_BLANK); + vidd_blank_display(adp, V_DISPLAY_BLANK); } } else { if (ISPALAVAIL(adp->va_flags)) { - load_palette(adp, palette); + vidd_load_palette(adp, palette); count = 0; } else { - (*vidsw[adp->va_index]->blank_display)(adp, - V_DISPLAY_ON); + vidd_blank_display(adp, V_DISPLAY_ON); } } return 0; } static int fade_init(video_adapter_t *adp) { - if (!ISPALAVAIL(adp->va_flags) - && (*vidsw[adp->va_index]->blank_display)(adp, V_DISPLAY_ON) != 0) + if (!ISPALAVAIL(adp->va_flags) && + vidd_blank_display(adp, V_DISPLAY_ON) != 0) return ENODEV; return 0; } static int fade_term(video_adapter_t *adp) { return 0; } static scrn_saver_t fade_module = { "fade_saver", fade_init, fade_term, fade_saver, NULL, }; SAVER_MODULE(fade_saver, fade_module); Index: head/sys/dev/syscons/fire/fire_saver.c =================================================================== --- head/sys/dev/syscons/fire/fire_saver.c (revision 174984) +++ head/sys/dev/syscons/fire/fire_saver.c (revision 174985) @@ -1,199 +1,199 @@ /*- * Copyright (c) 1999 Brad Forschinger * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ /* * brad forschinger, 19990504 * * written with much help from warp_saver.c * */ #include #include #include #include #include #include #include #include #include #include #include #define SAVER_NAME "fire_saver" #define RED(n) ((n) * 3 + 0) #define GREEN(n) ((n) * 3 + 1) #define BLUE(n) ((n) * 3 + 2) #define SET_ORIGIN(adp, o) do { \ int oo = o; \ if (oo != last_origin) \ - set_origin(adp, last_origin = oo); \ + vidd_set_win_org(adp, last_origin = oo); \ } while (0) static u_char *buf; static u_char *vid; static int banksize, scrmode, bpsl, scrw, scrh; static u_char fire_pal[768]; static int blanked; static void fire_update(video_adapter_t *adp) { int x, y; int o, p; int last_origin = -1; /* make a new bottom line */ for (x = 0, y = scrh; x < scrw; x++) buf[x + (y * bpsl)] = random() % 160 + 96; /* fade the flames out */ for (y = 0; y < scrh; y++) { for (x = 0; x < scrw; x++) { buf[x + (y * scrw)] = (buf[(x + 0) + ((y + 0) * scrw)] + buf[(x - 1) + ((y + 1) * scrw)] + buf[(x + 0) + ((y + 1) * scrw)] + buf[(x + 1) + ((y + 1) * scrw)]) / 4; if (buf[x + (y * scrw)] > 0) buf[x + (y * scrw)]--; } } /* blit our buffer into video ram */ for (y = 0, p = 0, o = 0; y < scrh; y++, p += bpsl) { while (p > banksize) { p -= banksize; o += banksize; } SET_ORIGIN(adp, o); if (p + scrw < banksize) { bcopy(buf + y * scrw, vid + p, scrw); } else { bcopy(buf + y * scrw, vid + p, banksize - p); SET_ORIGIN(adp, o + banksize); bcopy(buf + y * scrw + (banksize - p), vid, scrw - (banksize - p)); p -= banksize; o += banksize; } } } static int fire_saver(video_adapter_t *adp, int blank) { int pl; if (blank) { /* switch to graphics mode */ if (blanked <= 0) { pl = splhigh(); - set_video_mode(adp, scrmode); - load_palette(adp, fire_pal); + vidd_set_mode(adp, scrmode); + vidd_load_palette(adp, fire_pal); blanked++; vid = (u_char *)adp->va_window; banksize = adp->va_window_size; bpsl = adp->va_line_width; splx(pl); - (*vidsw[adp->va_index]->clear)(adp); + vidd_clear(adp); } fire_update(adp); } else { blanked = 0; } return 0; } static int fire_init(video_adapter_t *adp) { video_info_t info; int i, red, green, blue; - if (!get_mode_info(adp, M_VGA_CG320, &info)) { + if (!vidd_get_info(adp, M_VGA_CG320, &info)) { scrmode = M_VGA_CG320; - } else if (!get_mode_info(adp, M_PC98_PEGC640x480, &info)) { + } else if (!vidd_get_info(adp, M_PC98_PEGC640x480, &info)) { scrmode = M_PC98_PEGC640x480; - } else if (!get_mode_info(adp, M_PC98_PEGC640x400, &info)) { + } else if (!vidd_get_info(adp, M_PC98_PEGC640x400, &info)) { scrmode = M_PC98_PEGC640x400; } else { log(LOG_NOTICE, "%s: the console does not support M_VGA_CG320\n", SAVER_NAME); return (ENODEV); } scrw = info.vi_width; scrh = info.vi_height; buf = (u_char *)malloc(scrw * (scrh + 1), M_DEVBUF, M_NOWAIT); if (buf) { bzero(buf, scrw * (scrh + 1)); } else { log(LOG_NOTICE, "%s: buffer allocation is failed\n", SAVER_NAME); return (ENODEV); } /* intialize the palette */ red = green = blue = 0; for (i = 0; i < 256; i++) { red++; if (red > 128) green += 2; fire_pal[RED(i)] = red; fire_pal[GREEN(i)] = green; fire_pal[BLUE(i)] = blue; } return (0); } static int fire_term(video_adapter_t *adp) { free(buf, M_DEVBUF); return (0); } static scrn_saver_t fire_module = { SAVER_NAME, fire_init, fire_term, fire_saver, NULL }; SAVER_MODULE(fire_saver, fire_module); Index: head/sys/dev/syscons/green/green_saver.c =================================================================== --- head/sys/dev/syscons/green/green_saver.c (revision 174984) +++ head/sys/dev/syscons/green/green_saver.c (revision 174985) @@ -1,69 +1,68 @@ /*- * Copyright (c) 1995-1998 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include static int green_saver(video_adapter_t *adp, int blank) { - (*vidsw[adp->va_index]->blank_display)(adp, - (blank) ? V_DISPLAY_STAND_BY - : V_DISPLAY_ON); + vidd_blank_display(adp, + (blank) ? V_DISPLAY_STAND_BY : V_DISPLAY_ON); return 0; } static int green_init(video_adapter_t *adp) { - if ((*vidsw[adp->va_index]->blank_display)(adp, V_DISPLAY_ON) == 0) + if (vidd_blank_display(adp, V_DISPLAY_ON) == 0) return 0; return ENODEV; } static int green_term(video_adapter_t *adp) { return 0; } static scrn_saver_t green_module = { "green_saver", green_init, green_term, green_saver, NULL, }; SAVER_MODULE(green_saver, green_module); Index: head/sys/dev/syscons/logo/logo_saver.c =================================================================== --- head/sys/dev/syscons/logo/logo_saver.c (revision 174984) +++ head/sys/dev/syscons/logo/logo_saver.c (revision 174985) @@ -1,174 +1,174 @@ /*- * Copyright (c) 1998 Dag-Erling Coïdan Smørgrav * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer * in this position and unchanged. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #define SAVER_NAME "logo_saver" #define SET_ORIGIN(adp, o) do { \ int oo = o; \ if (oo != last_origin) \ - set_origin(adp, last_origin = oo); \ + vidd_set_win_org(adp, last_origin = oo); \ } while (0) extern unsigned int logo_w; extern unsigned int logo_h; extern unsigned char logo_pal[]; extern unsigned char logo_img[]; extern unsigned int logo_img_size; static u_char *vid; static int banksize, scrmode, bpsl, scrw, scrh; static int blanked; static void logo_blit(video_adapter_t *adp, int x, int y) { int d, l, o, p; int last_origin = -1; for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize) o += banksize; SET_ORIGIN(adp, o); for (d = 0; d < logo_img_size; d += logo_w) { if (p + logo_w < banksize) { bcopy(logo_img + d, vid + p, logo_w); p += bpsl; } else if (p < banksize) { l = banksize - p; bcopy(logo_img + d, vid + p, l); SET_ORIGIN(adp, (o += banksize)); bcopy(logo_img + d + l, vid, logo_w - l); p += bpsl - banksize; } else { p -= banksize; SET_ORIGIN(adp, (o += banksize)); bcopy(logo_img + d, vid + p, logo_w); p += bpsl; } } } static void logo_update(video_adapter_t *adp) { static int xpos = 0, ypos = 0; static int xinc = 1, yinc = 1; /* Turn when you hit the edge */ if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0)) xinc = -xinc; if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0)) yinc = -yinc; xpos += xinc; ypos += yinc; /* XXX Relies on margin around logo to erase trail */ logo_blit(adp, xpos, ypos); } static int logo_saver(video_adapter_t *adp, int blank) { int pl; if (blank) { /* switch to graphics mode */ if (blanked <= 0) { pl = splhigh(); - set_video_mode(adp, scrmode); - load_palette(adp, logo_pal); - set_border(adp, 0); + vidd_set_mode(adp, scrmode); + vidd_load_palette(adp, logo_pal); + vidd_set_border(adp, 0); blanked++; vid = (u_char *)adp->va_window; banksize = adp->va_window_size; bpsl = adp->va_line_width; splx(pl); - (*vidsw[adp->va_index]->clear)(adp); + vidd_clear(adp); } logo_update(adp); } else { blanked = 0; } return (0); } static int logo_init(video_adapter_t *adp) { video_info_t info; - if (!get_mode_info(adp, M_VESA_CG800x600, &info)) { + if (!vidd_get_info(adp, M_VESA_CG800x600, &info)) { scrmode = M_VESA_CG800x600; - } else if (!get_mode_info(adp, M_VGA_CG320, &info)) { + } else if (!vidd_get_info(adp, M_VGA_CG320, &info)) { scrmode = M_VGA_CG320; - } else if (!get_mode_info(adp, M_PC98_PEGC640x480, &info)) { + } else if (!vidd_get_info(adp, M_PC98_PEGC640x480, &info)) { scrmode = M_PC98_PEGC640x480; - } else if (!get_mode_info(adp, M_PC98_PEGC640x400, &info)) { + } else if (!vidd_get_info(adp, M_PC98_PEGC640x400, &info)) { scrmode = M_PC98_PEGC640x400; } else { log(LOG_NOTICE, "%s: the console does not support M_VGA_CG320\n", SAVER_NAME); return (ENODEV); } scrw = info.vi_width; scrh = info.vi_height; return (0); } static int logo_term(video_adapter_t *adp) { return (0); } static scrn_saver_t logo_module = { SAVER_NAME, logo_init, logo_term, logo_saver, NULL }; SAVER_MODULE(logo_saver, logo_module); Index: head/sys/dev/syscons/rain/rain_saver.c =================================================================== --- head/sys/dev/syscons/rain/rain_saver.c (revision 174984) +++ head/sys/dev/syscons/rain/rain_saver.c (revision 174985) @@ -1,181 +1,181 @@ /*- * Copyright (c) 1998 Dag-Erling Coïdan Smørgrav * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer * in this position and unchanged. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #define SAVER_NAME "rain_saver" #ifdef MAX #undef MAX #endif #define MAX 63 /* number of colors (in addition to black) */ #define INCREMENT 4 /* increment between colors */ #define RED(n) ((n) * 3 + 0) #define GREEN(n) ((n) * 3 + 1) #define BLUE(n) ((n) * 3 + 2) #define SET_ORIGIN(adp, o) do { \ int oo = o; \ if (oo != last_origin) \ - set_origin(adp, last_origin = oo); \ + vidd_set_win_org(adp, last_origin = oo); \ } while (0) static u_char *vid; static int banksize, scrmode, bpsl, scrw, scrh; static u_char rain_pal[768]; static int blanked; static void rain_update(video_adapter_t *adp) { int i, t; t = rain_pal[BLUE(MAX)]; for (i = MAX; i > 1; i--) rain_pal[BLUE(i)] = rain_pal[BLUE(i - 1)]; rain_pal[BLUE(1)] = t; - load_palette(adp, rain_pal); + vidd_load_palette(adp, rain_pal); } static int rain_saver(video_adapter_t *adp, int blank) { int i, j, o, p, pl; u_char temp; int last_origin = -1; if (blank) { /* switch to graphics mode */ if (blanked <= 0) { pl = splhigh(); - set_video_mode(adp, scrmode); - load_palette(adp, rain_pal); - set_border(adp, 0); + vidd_set_mode(adp, scrmode); + vidd_load_palette(adp, rain_pal); + vidd_set_border(adp, 0); blanked++; vid = (u_char *)adp->va_window; banksize = adp->va_window_size; bpsl = adp->va_line_width; splx(pl); for (i = 0; i < bpsl*scrh; i += banksize) { SET_ORIGIN(adp, i); if ((bpsl * scrh - i) < banksize) bzero(vid, bpsl * scrh - i); else bzero(vid, banksize); } SET_ORIGIN(adp, 0); for (i = 0, o = 0, p = 0; i < scrw; i += 2, p += 2) { if (p > banksize) { p -= banksize; o += banksize; SET_ORIGIN(adp, o); } vid[p] = 1 + (random() % MAX); } o = 0; p = 0; for (j = 1; j < scrh; j++) for (i = 0, p = bpsl * (j - 1) - o; i < scrw; i += 2, p+= 2) { while (p > banksize) { p -= banksize; o += banksize; } SET_ORIGIN(adp, o); temp = (vid[p] < MAX) ? 1 + vid[p] : 1; if (p + bpsl < banksize) { vid[p + bpsl] = temp; } else { SET_ORIGIN(adp, o + banksize); vid[p + bpsl - banksize] = temp; } } } /* update display */ rain_update(adp); } else { blanked = 0; } return (0); } static int rain_init(video_adapter_t *adp) { video_info_t info; int i; - if (!get_mode_info(adp, M_VGA_CG320, &info)) { + if (!vidd_get_info(adp, M_VGA_CG320, &info)) { scrmode = M_VGA_CG320; - } else if (!get_mode_info(adp, M_PC98_PEGC640x480, &info)) { + } else if (!vidd_get_info(adp, M_PC98_PEGC640x480, &info)) { scrmode = M_PC98_PEGC640x480; - } else if (!get_mode_info(adp, M_PC98_PEGC640x400, &info)) { + } else if (!vidd_get_info(adp, M_PC98_PEGC640x400, &info)) { scrmode = M_PC98_PEGC640x400; } else { log(LOG_NOTICE, "%s: the console does not support M_VGA_CG320\n", SAVER_NAME); return (ENODEV); } scrw = info.vi_width; scrh = info.vi_height; /* intialize the palette */ for (i = 1; i < MAX; i++) rain_pal[BLUE(i)] = rain_pal[BLUE(i - 1)] + INCREMENT; return (0); } static int rain_term(video_adapter_t *adp) { return (0); } static scrn_saver_t rain_module = { SAVER_NAME, rain_init, rain_term, rain_saver, NULL }; SAVER_MODULE(rain_saver, rain_module); Index: head/sys/dev/syscons/scgfbrndr.c =================================================================== --- head/sys/dev/syscons/scgfbrndr.c (revision 174984) +++ head/sys/dev/syscons/scgfbrndr.c (revision 174985) @@ -1,373 +1,366 @@ /*- * Copyright (c) 1999 Kazutaka YOKOTA * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer as * the first lines of this file unmodified. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright (c) 2000 Andrew Miklic */ #include __FBSDID("$FreeBSD$"); #include "opt_syscons.h" #include "opt_gfb.h" #ifdef __powerpc__ #include "opt_ofwfb.h" #endif #include #include #include #include #include #include #include #include #ifndef SC_RENDER_DEBUG #define SC_RENDER_DEBUG 0 #endif static vr_clear_t gfb_clear; static vr_draw_border_t gfb_border; static vr_draw_t gfb_draw; static vr_set_cursor_t gfb_cursor_shape; static vr_draw_cursor_t gfb_cursor; static vr_blink_cursor_t gfb_blink; #ifndef SC_NO_CUTPASTE static vr_draw_mouse_t gfb_mouse; #else #define gfb_mouse (vr_draw_mouse_t *)gfb_nop #endif static void gfb_nop(scr_stat *scp); sc_rndr_sw_t txtrndrsw = { (vr_init_t *)gfb_nop, gfb_clear, gfb_border, gfb_draw, gfb_cursor_shape, gfb_cursor, gfb_blink, (vr_set_mouse_t *)gfb_nop, gfb_mouse, }; #ifdef SC_PIXEL_MODE sc_rndr_sw_t gfbrndrsw = { (vr_init_t *)gfb_nop, gfb_clear, gfb_border, gfb_draw, gfb_cursor_shape, gfb_cursor, gfb_blink, (vr_set_mouse_t *)gfb_nop, gfb_mouse, }; #endif /* SC_PIXEL_MODE */ #ifndef SC_NO_MODE_CHANGE sc_rndr_sw_t grrndrsw = { (vr_init_t *)gfb_nop, (vr_clear_t *)gfb_nop, gfb_border, (vr_draw_t *)gfb_nop, (vr_set_cursor_t *)gfb_nop, (vr_draw_cursor_t *)gfb_nop, (vr_blink_cursor_t *)gfb_nop, (vr_set_mouse_t *)gfb_nop, (vr_draw_mouse_t *)gfb_nop, }; #endif /* SC_NO_MODE_CHANGE */ #ifndef SC_NO_CUTPASTE #ifdef __sparc64__ static u_char mouse_pointer[22 * 2] = { 0x00, 0x00, /* ............ */ 0x80, 0x00, /* *........... */ 0xc0, 0x00, /* **.......... */ 0xe0, 0x00, /* ***......... */ 0xf0, 0x00, /* ****........ */ 0xf8, 0x00, /* *****....... */ 0xfc, 0x00, /* ******...... */ 0xfe, 0x00, /* *******..... */ 0xff, 0x00, /* ********.... */ 0xff, 0x80, /* *********... */ 0xfc, 0xc0, /* ******..**.. */ 0xdc, 0x00, /* **.***...... */ 0x8e, 0x00, /* *...***..... */ 0x0e, 0x00, /* ....***..... */ 0x07, 0x00, /* .....***.... */ 0x04, 0x00, /* .....*...... */ 0x00, 0x00, /* ............ */ 0x00, 0x00, /* ............ */ 0x00, 0x00, /* ............ */ 0x00, 0x00, /* ............ */ 0x00, 0x00, /* ............ */ 0x00, 0x00 /* ............ */ }; #else static u_char mouse_pointer[16] = { 0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68, 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00 }; #endif #endif static void gfb_nop(scr_stat *scp) { } /* text mode renderer */ static void gfb_clear(scr_stat *scp, int c, int attr) { - (*vidsw[scp->sc->adapter]->clear)(scp->sc->adp); + vidd_clear(scp->sc->adp); } static void gfb_border(scr_stat *scp, int color) { - (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color); + vidd_set_border(scp->sc->adp, color); } static void gfb_draw(scr_stat *scp, int from, int count, int flip) { int c; int a; int i, n; video_adapter_t *adp; adp = scp->sc->adp; /* Determine if we need to scroll based on the offset and the number of characters to be displayed... */ if (from + count > scp->xsize*scp->ysize) { /* Calculate the number of characters past the end of the visible screen... */ count = (from + count) - (adp->va_info.vi_width * adp->va_info.vi_height); /* Calculate the number of rows past the end of the visible screen... */ n = (count / adp->va_info.vi_width) + 1; /* Scroll to make room for new text rows... */ - (*vidsw[scp->sc->adapter]->copy)(adp, n, 0, n); + vidd_copy(adp, n, 0, n); #if 0 - (*vidsw[scp->sc->adapter]->clear)(adp, n); + vidd_clear(adp, n); #endif /* Display new text rows... */ - (*vidsw[scp->sc->adapter]->puts)(adp, from, + vidd_puts(adp, from, (u_int16_t *)sc_vtb_pointer(&scp->vtb, from), count); } /* We don't need to scroll, so we can just put the characters all-at-once... */ else { /* Determine the method by which we are to display characters (are we going to print forwards or backwards? do we need to do a character-by-character copy, then?)... */ if (flip) for (i = count; i-- > 0; ++from) { c = sc_vtb_getc(&scp->vtb, from); a = sc_vtb_geta(&scp->vtb, from) >> 8; - (*vidsw[scp->sc->adapter]->putc)(adp, from, c, + vidd_putc(adp, from, c, (a >> 4) | ((a & 0xf) << 4)); } else { - (*vidsw[scp->sc->adapter]->puts)(adp, from, + vidd_puts(adp, from, (u_int16_t *)sc_vtb_pointer(&scp->vtb, from), count); } } } static void gfb_cursor_shape(scr_stat *scp, int base, int height, int blink) { if (base < 0 || base >= scp->font_size) return; /* the caller may set height <= 0 in order to disable the cursor */ #if 0 scp->cursor_base = base; scp->cursor_height = height; #endif - (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp, - base, height, scp->font_size, blink); + vidd_set_hw_cursor_shape(scp->sc->adp, base, height, scp->font_size, + blink); } static int pxlblinkrate = 0; #if defined(__sparc64__) || defined(SC_OFWFB) static void gfb_cursor(scr_stat *scp, int at, int blink, int on, int flip) { video_adapter_t *adp; int a, c; if (scp->curs_attr.height <= 0) /* the text cursor is disabled */ return; adp = scp->sc->adp; if(blink) { scp->status |= VR_CURSOR_BLINK; if (on) { scp->status |= VR_CURSOR_ON; - (*vidsw[adp->va_index]->set_hw_cursor)(adp, - at%scp->xsize, - at/scp->xsize); + vidd_set_hw_cursor(adp, at%scp->xsize, at/scp->xsize); } else { if (scp->status & VR_CURSOR_ON) - (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, - -1); + vidd_set_hw_cursor(adp, -1, -1); scp->status &= ~VR_CURSOR_ON; } } else { scp->status &= ~VR_CURSOR_BLINK; if(on) { scp->status |= VR_CURSOR_ON; - (*vidsw[scp->sc->adapter]->putc)(scp->sc->adp, - scp->cursor_oldpos, + vidd_putc(scp->sc->adp, scp->cursor_oldpos, sc_vtb_getc(&scp->vtb, scp->cursor_oldpos), sc_vtb_geta(&scp->vtb, scp->cursor_oldpos) >> 8); a = sc_vtb_geta(&scp->vtb, at) >> 8; c = sc_vtb_getc(&scp->vtb, at); - (*vidsw[scp->sc->adapter]->putc)(scp->sc->adp, at, - c, (a >> 4) | ((a & 0xf) << 4)); + vidd_putc(scp->sc->adp, at, c, + (a >> 4) | ((a & 0xf) << 4)); scp->cursor_saveunder_attr = a; scp->cursor_saveunder_char = c; } else { if (scp->status & VR_CURSOR_ON) - (*vidsw[scp->sc->adapter]->putc)(scp->sc->adp, - at, scp->cursor_saveunder_char, + vidd_putc(scp->sc->adp, at, + scp->cursor_saveunder_char, scp->cursor_saveunder_attr); scp->status &= ~VR_CURSOR_ON; } } } #else static void gfb_cursor(scr_stat *scp, int at, int blink, int on, int flip) { video_adapter_t *adp; adp = scp->sc->adp; if (scp->curs_attr.height <= 0) /* the text cursor is disabled */ return; if (on) { if (!blink) { scp->status |= VR_CURSOR_ON; - (*vidsw[adp->va_index]->set_hw_cursor)(adp, - at%scp->xsize, at/scp->xsize); + vidd_set_hw_cursor(adp, at%scp->xsize, at/scp->xsize); } else if (++pxlblinkrate & 4) { pxlblinkrate = 0; scp->status ^= VR_CURSOR_ON; if(scp->status & VR_CURSOR_ON) - (*vidsw[adp->va_index]->set_hw_cursor)(adp, - at%scp->xsize, at/scp->xsize); + vidd_set_hw_cursor(adp, at%scp->xsize, + at/scp->xsize); else - (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, - -1); + vidd_set_hw_cursor(adp, -1, -1); } } else { if (scp->status & VR_CURSOR_ON) - (*vidsw[adp->va_index]->set_hw_cursor)(adp, - at%scp->xsize, at/scp->xsize); + vidd_set_hw_cursor(adp, at%scp->xsize, at/scp->xsize); scp->status &= ~VR_CURSOR_ON; } if (blink) scp->status |= VR_CURSOR_BLINK; else scp->status &= ~VR_CURSOR_BLINK; } #endif static void gfb_blink(scr_stat *scp, int at, int flip) { if (!(scp->status & VR_CURSOR_BLINK)) return; if (!(++pxlblinkrate & 4)) return; pxlblinkrate = 0; scp->status ^= VR_CURSOR_ON; gfb_cursor(scp, at, scp->status & VR_CURSOR_BLINK, scp->status & VR_CURSOR_ON, flip); } #ifndef SC_NO_CUTPASTE static void gfb_mouse(scr_stat *scp, int x, int y, int on) { #ifdef __sparc64__ - (*vidsw[scp->sc->adapter]->putm)(scp->sc->adp, x, y, - mouse_pointer, on ? 0xffffffff : 0x0, 22, 12); + vidd_putm(scp->sc->adp, x, y, mouse_pointer, + on ? 0xffffffff : 0x0, 22, 12); #else int i, pos; if (on) { /* Display the mouse pointer image... */ - (*vidsw[scp->sc->adapter]->putm)(scp->sc->adp, x, y, - mouse_pointer, 0xffffffff, 16, 8); + vidd_putm(scp->sc->adp, x, y, mouse_pointer, + 0xffffffff, 16, 8); } else { /* Erase the mouse cursor image by redrawing the text underneath it... */ return; pos = x*scp->xsize + y; i = (y < scp->xsize - 1) ? 2 : 1; (*scp->rndr->draw)(scp, pos, i, FALSE); if (x < scp->ysize - 1) (*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE); } #endif } #endif /* SC_NO_CUTPASTE */ Index: head/sys/dev/syscons/scvgarndr.c =================================================================== --- head/sys/dev/syscons/scvgarndr.c (revision 174984) +++ head/sys/dev/syscons/scvgarndr.c (revision 174985) @@ -1,1256 +1,1251 @@ /*- * Copyright (c) 1999 Kazutaka YOKOTA * All rights reserved. * * This code is derived from software contributed to The DragonFly Project * by Sascha Wildner * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer as * the first lines of this file unmodified. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include __FBSDID("$FreeBSD$"); #include "opt_syscons.h" #include "opt_vga.h" #include #include #include #include #include #include #include #include #include #include #include #ifndef SC_RENDER_DEBUG #define SC_RENDER_DEBUG 0 #endif static vr_clear_t vga_txtclear; static vr_draw_border_t vga_txtborder; static vr_draw_t vga_txtdraw; static vr_set_cursor_t vga_txtcursor_shape; static vr_draw_cursor_t vga_txtcursor; static vr_blink_cursor_t vga_txtblink; #ifndef SC_NO_CUTPASTE static vr_draw_mouse_t vga_txtmouse; #else #define vga_txtmouse (vr_draw_mouse_t *)vga_nop #endif #ifdef SC_PIXEL_MODE static vr_init_t vga_rndrinit; static vr_clear_t vga_pxlclear_direct; static vr_clear_t vga_pxlclear_planar; static vr_draw_border_t vga_pxlborder_direct; static vr_draw_border_t vga_pxlborder_planar; static vr_draw_t vga_egadraw; static vr_draw_t vga_vgadraw_direct; static vr_draw_t vga_vgadraw_planar; static vr_set_cursor_t vga_pxlcursor_shape; static vr_draw_cursor_t vga_pxlcursor_direct; static vr_draw_cursor_t vga_pxlcursor_planar; static vr_blink_cursor_t vga_pxlblink_direct; static vr_blink_cursor_t vga_pxlblink_planar; #ifndef SC_NO_CUTPASTE static vr_draw_mouse_t vga_pxlmouse_direct; static vr_draw_mouse_t vga_pxlmouse_planar; #else #define vga_pxlmouse_direct (vr_draw_mouse_t *)vga_nop #define vga_pxlmouse_planar (vr_draw_mouse_t *)vga_nop #endif #endif /* SC_PIXEL_MODE */ #ifndef SC_NO_MODE_CHANGE static vr_draw_border_t vga_grborder; #endif static void vga_nop(scr_stat *scp); static sc_rndr_sw_t txtrndrsw = { (vr_init_t *)vga_nop, vga_txtclear, vga_txtborder, vga_txtdraw, vga_txtcursor_shape, vga_txtcursor, vga_txtblink, (vr_set_mouse_t *)vga_nop, vga_txtmouse, }; RENDERER(mda, 0, txtrndrsw, vga_set); RENDERER(cga, 0, txtrndrsw, vga_set); RENDERER(ega, 0, txtrndrsw, vga_set); RENDERER(vga, 0, txtrndrsw, vga_set); #ifdef SC_PIXEL_MODE static sc_rndr_sw_t egarndrsw = { (vr_init_t *)vga_nop, vga_pxlclear_planar, vga_pxlborder_planar, vga_egadraw, vga_pxlcursor_shape, vga_pxlcursor_planar, vga_pxlblink_planar, (vr_set_mouse_t *)vga_nop, vga_pxlmouse_planar, }; RENDERER(ega, PIXEL_MODE, egarndrsw, vga_set); static sc_rndr_sw_t vgarndrsw = { vga_rndrinit, (vr_clear_t *)vga_nop, (vr_draw_border_t *)vga_nop, (vr_draw_t *)vga_nop, vga_pxlcursor_shape, (vr_draw_cursor_t *)vga_nop, (vr_blink_cursor_t *)vga_nop, (vr_set_mouse_t *)vga_nop, (vr_draw_mouse_t *)vga_nop, }; RENDERER(vga, PIXEL_MODE, vgarndrsw, vga_set); #endif /* SC_PIXEL_MODE */ #ifndef SC_NO_MODE_CHANGE static sc_rndr_sw_t grrndrsw = { (vr_init_t *)vga_nop, (vr_clear_t *)vga_nop, vga_grborder, (vr_draw_t *)vga_nop, (vr_set_cursor_t *)vga_nop, (vr_draw_cursor_t *)vga_nop, (vr_blink_cursor_t *)vga_nop, (vr_set_mouse_t *)vga_nop, (vr_draw_mouse_t *)vga_nop, }; RENDERER(cga, GRAPHICS_MODE, grrndrsw, vga_set); RENDERER(ega, GRAPHICS_MODE, grrndrsw, vga_set); RENDERER(vga, GRAPHICS_MODE, grrndrsw, vga_set); #endif /* SC_NO_MODE_CHANGE */ RENDERER_MODULE(vga, vga_set); #ifndef SC_NO_CUTPASTE #if !defined(SC_ALT_MOUSE_IMAGE) || defined(SC_PIXEL_MODE) static u_short mouse_and_mask[16] = { 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00, 0xff80, 0xfe00, 0x1e00, 0x1f00, 0x0f00, 0x0f00, 0x0000, 0x0000, 0x0000 }; static u_short mouse_or_mask[16] = { 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x6800, 0x0c00, 0x0c00, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, 0x0000 }; #endif #endif #ifdef SC_PIXEL_MODE #define VIDEO_MEMORY_POS(scp, pos, x) \ scp->sc->adp->va_window + \ x * scp->xoff + \ scp->yoff * scp->font_size * scp->sc->adp->va_line_width + \ x * (pos % scp->xsize) + \ scp->font_size * scp->sc->adp->va_line_width * (pos / scp->xsize) #define vga_drawpxl(pos, color) \ switch (scp->sc->adp->va_info.vi_depth) { \ case 32: \ case 24: \ writel(pos, vga_palette32[color]); \ break; \ case 16: \ if (scp->sc->adp->va_info.vi_pixel_fsizes[1] == 5)\ writew(pos, vga_palette15[color]); \ else \ writew(pos, vga_palette16[color]); \ break; \ case 15: \ writew(pos, vga_palette15[color]); \ break; \ } static uint32_t vga_palette32[16] = { 0x000000, 0x0000ad, 0x00ad00, 0x00adad, 0xad0000, 0xad00ad, 0xad5200, 0xadadad, 0x525252, 0x5252ff, 0x52ff52, 0x52ffff, 0xff5252, 0xff52ff, 0xffff52, 0xffffff }; static uint16_t vga_palette16[16] = { 0x0000, 0x0016, 0x0560, 0x0576, 0xb000, 0xb016, 0xb2a0, 0xb576, 0x52aa, 0x52bf, 0x57ea, 0x57ff, 0xfaaa, 0xfabf, 0xffea, 0xffff }; static uint16_t vga_palette15[16] = { 0x0000, 0x0016, 0x02c0, 0x02d6, 0x5800, 0x5816, 0x5940, 0x5ad6, 0x294a, 0x295f, 0x2bea, 0x2bff, 0x7d4a, 0x7d5f, 0x7fea, 0x7fff }; #ifndef SC_NO_CUTPASTE static uint32_t mouse_buf32[256]; static uint16_t mouse_buf16[256]; #endif #endif static void vga_nop(scr_stat *scp) { } /* text mode renderer */ static void vga_txtclear(scr_stat *scp, int c, int attr) { sc_vtb_clear(&scp->scr, c, attr); } static void vga_txtborder(scr_stat *scp, int color) { - (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color); + vidd_set_border(scp->sc->adp, color); } static void vga_txtdraw(scr_stat *scp, int from, int count, int flip) { vm_offset_t p; int c; int a; if (from + count > scp->xsize*scp->ysize) count = scp->xsize*scp->ysize - from; if (flip) { for (p = sc_vtb_pointer(&scp->scr, from); count-- > 0; ++from) { c = sc_vtb_getc(&scp->vtb, from); a = sc_vtb_geta(&scp->vtb, from); a = (a & 0x8800) | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4); p = sc_vtb_putchar(&scp->scr, p, c, a); } } else { sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count); } } static void vga_txtcursor_shape(scr_stat *scp, int base, int height, int blink) { if (base < 0 || base >= scp->font_size) return; /* the caller may set height <= 0 in order to disable the cursor */ #if 0 scp->curs_attr.base = base; scp->curs_attr.height = height; #endif - (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp, - base, height, - scp->font_size, blink); + vidd_set_hw_cursor_shape(scp->sc->adp, base, height, + scp->font_size, blink); } static void draw_txtcharcursor(scr_stat *scp, int at, u_short c, u_short a, int flip) { sc_softc_t *sc; sc = scp->sc; scp->cursor_saveunder_char = c; scp->cursor_saveunder_attr = a; #ifndef SC_NO_FONT_LOADING if (scp->curs_attr.flags & CONS_CHAR_CURSOR) { unsigned char *font; int h; int i; if (scp->font_size < 14) { font = sc->font_8; h = 8; } else if (scp->font_size >= 16) { font = sc->font_16; h = 16; } else { font = sc->font_14; h = 14; } if (scp->curs_attr.base >= h) return; if (flip) a = (a & 0x8800) | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4); bcopy(font + c*h, font + sc->cursor_char*h, h); font = font + sc->cursor_char*h; for (i = imax(h - scp->curs_attr.base - scp->curs_attr.height, 0); i < h - scp->curs_attr.base; ++i) { font[i] ^= 0xff; } /* XXX */ - (*vidsw[sc->adapter]->load_font)(sc->adp, 0, h, 8, font, - sc->cursor_char, 1); + vidd_load_font(sc->adp, 0, h, 8, font, sc->cursor_char, 1); sc_vtb_putc(&scp->scr, at, sc->cursor_char, a); } else #endif /* SC_NO_FONT_LOADING */ { if ((a & 0x7000) == 0x7000) { a &= 0x8f00; if ((a & 0x0700) == 0) a |= 0x0700; } else { a |= 0x7000; if ((a & 0x0700) == 0x0700) a &= 0xf000; } if (flip) a = (a & 0x8800) | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4); sc_vtb_putc(&scp->scr, at, c, a); } } static void vga_txtcursor(scr_stat *scp, int at, int blink, int on, int flip) { video_adapter_t *adp; int cursor_attr; if (scp->curs_attr.height <= 0) /* the text cursor is disabled */ return; adp = scp->sc->adp; if (blink) { scp->status |= VR_CURSOR_BLINK; if (on) { scp->status |= VR_CURSOR_ON; - (*vidsw[adp->va_index]->set_hw_cursor)(adp, - at%scp->xsize, - at/scp->xsize); + vidd_set_hw_cursor(adp, at%scp->xsize, + at/scp->xsize); } else { if (scp->status & VR_CURSOR_ON) - (*vidsw[adp->va_index]->set_hw_cursor)(adp, - -1, -1); + vidd_set_hw_cursor(adp, -1, -1); scp->status &= ~VR_CURSOR_ON; } } else { scp->status &= ~VR_CURSOR_BLINK; if (on) { scp->status |= VR_CURSOR_ON; draw_txtcharcursor(scp, at, sc_vtb_getc(&scp->scr, at), sc_vtb_geta(&scp->scr, at), flip); } else { cursor_attr = scp->cursor_saveunder_attr; if (flip) cursor_attr = (cursor_attr & 0x8800) | ((cursor_attr & 0x7000) >> 4) | ((cursor_attr & 0x0700) << 4); if (scp->status & VR_CURSOR_ON) sc_vtb_putc(&scp->scr, at, scp->cursor_saveunder_char, cursor_attr); scp->status &= ~VR_CURSOR_ON; } } } static void vga_txtblink(scr_stat *scp, int at, int flip) { } #ifndef SC_NO_CUTPASTE static void draw_txtmouse(scr_stat *scp, int x, int y) { #ifndef SC_ALT_MOUSE_IMAGE if (ISMOUSEAVAIL(scp->sc->adp->va_flags)) { u_char font_buf[128]; u_short cursor[32]; u_char c; int pos; int xoffset, yoffset; int crtc_addr; int i; /* prepare mousepointer char's bitmaps */ pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff; bcopy(scp->font + sc_vtb_getc(&scp->scr, pos)*scp->font_size, &font_buf[0], scp->font_size); bcopy(scp->font + sc_vtb_getc(&scp->scr, pos + 1)*scp->font_size, &font_buf[32], scp->font_size); bcopy(scp->font + sc_vtb_getc(&scp->scr, pos + scp->xsize)*scp->font_size, &font_buf[64], scp->font_size); bcopy(scp->font + sc_vtb_getc(&scp->scr, pos + scp->xsize + 1)*scp->font_size, &font_buf[96], scp->font_size); for (i = 0; i < scp->font_size; ++i) { cursor[i] = font_buf[i]<<8 | font_buf[i+32]; cursor[i + scp->font_size] = font_buf[i+64]<<8 | font_buf[i+96]; } /* now and-or in the mousepointer image */ xoffset = x%8; yoffset = y%scp->font_size; for (i = 0; i < 16; ++i) { cursor[i + yoffset] = (cursor[i + yoffset] & ~(mouse_and_mask[i] >> xoffset)) | (mouse_or_mask[i] >> xoffset); } for (i = 0; i < scp->font_size; ++i) { font_buf[i] = (cursor[i] & 0xff00) >> 8; font_buf[i + 32] = cursor[i] & 0xff; font_buf[i + 64] = (cursor[i + scp->font_size] & 0xff00) >> 8; font_buf[i + 96] = cursor[i + scp->font_size] & 0xff; } #if 1 /* wait for vertical retrace to avoid jitter on some videocards */ crtc_addr = scp->sc->adp->va_crtc_addr; while (!(inb(crtc_addr + 6) & 0x08)) /* idle */ ; #endif c = scp->sc->mouse_char; - (*vidsw[scp->sc->adapter]->load_font)(scp->sc->adp, 0, 32, 8, font_buf, - c, 4); + vidd_load_font(scp->sc->adp, 0, 32, 8, font_buf, c, 4); sc_vtb_putc(&scp->scr, pos, c, sc_vtb_geta(&scp->scr, pos)); /* FIXME: may be out of range! */ sc_vtb_putc(&scp->scr, pos + scp->xsize, c + 2, sc_vtb_geta(&scp->scr, pos + scp->xsize)); if (x < (scp->xsize - 1)*8) { sc_vtb_putc(&scp->scr, pos + 1, c + 1, sc_vtb_geta(&scp->scr, pos + 1)); sc_vtb_putc(&scp->scr, pos + scp->xsize + 1, c + 3, sc_vtb_geta(&scp->scr, pos + scp->xsize + 1)); } } else #endif /* SC_ALT_MOUSE_IMAGE */ { /* Red, magenta and brown are mapped to green to to keep it readable */ static const int col_conv[16] = { 6, 6, 6, 6, 2, 2, 2, 6, 14, 14, 14, 14, 10, 10, 10, 14 }; int pos; int color; int a; pos = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff; a = sc_vtb_geta(&scp->scr, pos); if (scp->sc->adp->va_flags & V_ADP_COLOR) color = (col_conv[(a & 0xf000) >> 12] << 12) | ((a & 0x0f00) | 0x0800); else color = ((a & 0xf000) >> 4) | ((a & 0x0f00) << 4); sc_vtb_putc(&scp->scr, pos, sc_vtb_getc(&scp->scr, pos), color); } } static void remove_txtmouse(scr_stat *scp, int x, int y) { } static void vga_txtmouse(scr_stat *scp, int x, int y, int on) { if (on) draw_txtmouse(scp, x, y); else remove_txtmouse(scp, x, y); } #endif /* SC_NO_CUTPASTE */ #ifdef SC_PIXEL_MODE /* pixel (raster text) mode renderer */ static void vga_rndrinit(scr_stat *scp) { if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_PLANAR) { scp->rndr->clear = vga_pxlclear_planar; scp->rndr->draw_border = vga_pxlborder_planar; scp->rndr->draw = vga_vgadraw_planar; scp->rndr->draw_cursor = vga_pxlcursor_planar; scp->rndr->blink_cursor = vga_pxlblink_planar; scp->rndr->draw_mouse = vga_pxlmouse_planar; } else if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT) { scp->rndr->clear = vga_pxlclear_direct; scp->rndr->draw_border = vga_pxlborder_direct; scp->rndr->draw = vga_vgadraw_direct; scp->rndr->draw_cursor = vga_pxlcursor_direct; scp->rndr->blink_cursor = vga_pxlblink_direct; scp->rndr->draw_mouse = vga_pxlmouse_direct; } } static void vga_pxlclear_direct(scr_stat *scp, int c, int attr) { vm_offset_t p; int line_width; int pixel_size; int lines; int i; line_width = scp->sc->adp->va_line_width; pixel_size = scp->sc->adp->va_info.vi_pixel_size; lines = scp->ysize * scp->font_size; p = scp->sc->adp->va_window + line_width * scp->yoff * scp->font_size + scp->xoff * 8 * pixel_size; for (i = 0; i < lines; ++i) { bzero_io((void *)p, scp->xsize * 8 * pixel_size); p += line_width; } } static void vga_pxlclear_planar(scr_stat *scp, int c, int attr) { vm_offset_t p; int line_width; int lines; int i; /* XXX: we are just filling the screen with the background color... */ outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, 0x0003); /* data rotate/function select */ outw(GDCIDX, 0x0f01); /* set/reset enable */ outw(GDCIDX, 0xff08); /* bit mask */ outw(GDCIDX, ((attr & 0xf000) >> 4) | 0x00); /* set/reset */ line_width = scp->sc->adp->va_line_width; lines = scp->ysize*scp->font_size; p = scp->sc->adp->va_window + line_width*scp->yoff*scp->font_size + scp->xoff; for (i = 0; i < lines; ++i) { bzero_io((void *)p, scp->xsize); p += line_width; } outw(GDCIDX, 0x0000); /* set/reset */ outw(GDCIDX, 0x0001); /* set/reset enable */ } static void vga_pxlborder_direct(scr_stat *scp, int color) { vm_offset_t s; vm_offset_t e; vm_offset_t f; int line_width; int pixel_size; int x; int y; int i; line_width = scp->sc->adp->va_line_width; pixel_size = scp->sc->adp->va_info.vi_pixel_size; if (scp->yoff > 0) { s = scp->sc->adp->va_window; e = s + line_width * scp->yoff * scp->font_size; for (f = s; f < e; f += pixel_size) vga_drawpxl(f, color); } y = (scp->yoff + scp->ysize) * scp->font_size; if (scp->ypixel > y) { s = scp->sc->adp->va_window + line_width * y; e = s + line_width * (scp->ypixel - y); for (f = s; f < e; f += pixel_size) vga_drawpxl(f, color); } y = scp->yoff * scp->font_size; x = scp->xpixel / 8 - scp->xoff - scp->xsize; for (i = 0; i < scp->ysize * scp->font_size; ++i) { if (scp->xoff > 0) { s = scp->sc->adp->va_window + line_width * (y + i); e = s + scp->xoff * 8 * pixel_size; for (f = s; f < e; f += pixel_size) vga_drawpxl(f, color); } if (x > 0) { s = scp->sc->adp->va_window + line_width * (y + i) + scp->xoff * 8 * pixel_size + scp->xsize * 8 * pixel_size; e = s + x * 8 * pixel_size; for (f = s; f < e; f += pixel_size) vga_drawpxl(f, color); } } } static void vga_pxlborder_planar(scr_stat *scp, int color) { vm_offset_t p; int line_width; int x; int y; int i; - (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color); + vidd_set_border(scp->sc->adp, color); outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, 0x0003); /* data rotate/function select */ outw(GDCIDX, 0x0f01); /* set/reset enable */ outw(GDCIDX, 0xff08); /* bit mask */ outw(GDCIDX, (color << 8) | 0x00); /* set/reset */ line_width = scp->sc->adp->va_line_width; p = scp->sc->adp->va_window; if (scp->yoff > 0) bzero_io((void *)p, line_width*scp->yoff*scp->font_size); y = (scp->yoff + scp->ysize)*scp->font_size; if (scp->ypixel > y) bzero_io((void *)(p + line_width*y), line_width*(scp->ypixel - y)); y = scp->yoff*scp->font_size; x = scp->xpixel/8 - scp->xoff - scp->xsize; for (i = 0; i < scp->ysize*scp->font_size; ++i) { if (scp->xoff > 0) bzero_io((void *)(p + line_width*(y + i)), scp->xoff); if (x > 0) bzero_io((void *)(p + line_width*(y + i) + scp->xoff + scp->xsize), x); } outw(GDCIDX, 0x0000); /* set/reset */ outw(GDCIDX, 0x0001); /* set/reset enable */ } static void vga_egadraw(scr_stat *scp, int from, int count, int flip) { vm_offset_t d; vm_offset_t e; u_char *f; u_short bg; u_short col1, col2; int line_width; int i, j; int a; u_char c; line_width = scp->sc->adp->va_line_width; d = VIDEO_MEMORY_POS(scp, from, 1); outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, 0x0003); /* data rotate/function select */ outw(GDCIDX, 0x0f01); /* set/reset enable */ bg = -1; if (from + count > scp->xsize*scp->ysize) count = scp->xsize*scp->ysize - from; for (i = from; count-- > 0; ++i) { a = sc_vtb_geta(&scp->vtb, i); if (flip) { col1 = ((a & 0x7000) >> 4) | (a & 0x0800); col2 = ((a & 0x8000) >> 4) | (a & 0x0700); } else { col1 = (a & 0x0f00); col2 = (a & 0xf000) >> 4; } /* set background color in EGA/VGA latch */ if (bg != col2) { bg = col2; outw(GDCIDX, bg | 0x00); /* set/reset */ outw(GDCIDX, 0xff08); /* bit mask */ writeb(d, 0); c = readb(d); /* set bg color in the latch */ } /* foreground color */ outw(GDCIDX, col1 | 0x00); /* set/reset */ e = d; f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]); for (j = 0; j < scp->font_size; ++j, ++f) { outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */ writeb(e, 0); e += line_width; } ++d; if ((i % scp->xsize) == scp->xsize - 1) d += scp->xoff*2 + (scp->font_size - 1)*line_width; } outw(GDCIDX, 0x0000); /* set/reset */ outw(GDCIDX, 0x0001); /* set/reset enable */ outw(GDCIDX, 0xff08); /* bit mask */ } static void vga_vgadraw_direct(scr_stat *scp, int from, int count, int flip) { vm_offset_t d = 0; vm_offset_t e; u_char *f; u_short col1, col2, color; int line_width, pixel_size; int i, j, k; int a; line_width = scp->sc->adp->va_line_width; pixel_size = scp->sc->adp->va_info.vi_pixel_size; d = VIDEO_MEMORY_POS(scp, from, 8 * pixel_size); if (from + count > scp->xsize * scp->ysize) count = scp->xsize * scp->ysize - from; for (i = from; count-- > 0; ++i) { a = sc_vtb_geta(&scp->vtb, i); if (flip) { col1 = (((a & 0x7000) >> 4) | (a & 0x0800)) >> 8; col2 = (((a & 0x8000) >> 4) | (a & 0x0700)) >> 8; } else { col1 = (a & 0x0f00) >> 8; col2 = (a & 0xf000) >> 12; } e = d; f = &(scp->font[sc_vtb_getc(&scp->vtb, i) * scp->font_size]); for (j = 0; j < scp->font_size; ++j, ++f) { for (k = 0; k < 8; ++k) { color = *f & (1 << (7 - k)) ? col1 : col2; vga_drawpxl(e + pixel_size * k, color); } e += line_width; } d += 8 * pixel_size; if ((i % scp->xsize) == scp->xsize - 1) d += scp->xoff * 16 * pixel_size + (scp->font_size - 1) * line_width; } } static void vga_vgadraw_planar(scr_stat *scp, int from, int count, int flip) { vm_offset_t d; vm_offset_t e; u_char *f; u_short bg; u_short col1, col2; int line_width; int i, j; int a; u_char c; d = VIDEO_MEMORY_POS(scp, from, 1); line_width = scp->sc->adp->va_line_width; outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */ outw(GDCIDX, 0x0003); /* data rotate/function select */ outw(GDCIDX, 0x0f01); /* set/reset enable */ outw(GDCIDX, 0xff08); /* bit mask */ bg = -1; if (from + count > scp->xsize*scp->ysize) count = scp->xsize*scp->ysize - from; for (i = from; count-- > 0; ++i) { a = sc_vtb_geta(&scp->vtb, i); if (flip) { col1 = ((a & 0x7000) >> 4) | (a & 0x0800); col2 = ((a & 0x8000) >> 4) | (a & 0x0700); } else { col1 = (a & 0x0f00); col2 = (a & 0xf000) >> 4; } /* set background color in EGA/VGA latch */ if (bg != col2) { bg = col2; outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, bg | 0x00); /* set/reset */ writeb(d, 0); c = readb(d); /* set bg color in the latch */ outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */ } /* foreground color */ outw(GDCIDX, col1 | 0x00); /* set/reset */ e = d; f = &(scp->font[sc_vtb_getc(&scp->vtb, i)*scp->font_size]); for (j = 0; j < scp->font_size; ++j, ++f) { writeb(e, *f); e += line_width; } ++d; if ((i % scp->xsize) == scp->xsize - 1) d += scp->xoff*2 + (scp->font_size - 1)*line_width; } outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, 0x0000); /* set/reset */ outw(GDCIDX, 0x0001); /* set/reset enable */ } static void vga_pxlcursor_shape(scr_stat *scp, int base, int height, int blink) { if (base < 0 || base >= scp->font_size) return; /* the caller may set height <= 0 in order to disable the cursor */ #if 0 scp->curs_attr.base = base; scp->curs_attr.height = height; #endif } static void draw_pxlcursor_direct(scr_stat *scp, int at, int on, int flip) { vm_offset_t d = 0; u_char *f; int line_width, pixel_size; int height; int col1, col2, color; int a; int i, j; line_width = scp->sc->adp->va_line_width; pixel_size = scp->sc->adp->va_info.vi_pixel_size; d = VIDEO_MEMORY_POS(scp, at, 8 * pixel_size) + (scp->font_size - scp->curs_attr.base - 1) * line_width; a = sc_vtb_geta(&scp->vtb, at); if (flip) { col1 = ((on) ? (a & 0x0f00) : ((a & 0xf000) >> 4)) >> 8; col2 = ((on) ? ((a & 0xf000) >> 4) : (a & 0x0f00)) >> 8; } else { col1 = ((on) ? ((a & 0xf000) >> 4) : (a & 0x0f00)) >> 8; col2 = ((on) ? (a & 0x0f00) : ((a & 0xf000) >> 4)) >> 8; } f = &(scp->font[sc_vtb_getc(&scp->vtb, at) * scp->font_size + scp->font_size - scp->curs_attr.base - 1]); height = imin(scp->curs_attr.height, scp->font_size); for (i = 0; i < height; ++i, --f) { for (j = 0; j < 8; ++j) { color = *f & (1 << (7 - j)) ? col1 : col2; vga_drawpxl(d + pixel_size * j, color); } d -= line_width; } } static void draw_pxlcursor_planar(scr_stat *scp, int at, int on, int flip) { vm_offset_t d; u_char *f; int line_width; int height; int col; int a; int i; u_char c; line_width = scp->sc->adp->va_line_width; d = VIDEO_MEMORY_POS(scp, at, 1) + (scp->font_size - scp->curs_attr.base - 1) * line_width; outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, 0x0003); /* data rotate/function select */ outw(GDCIDX, 0x0f01); /* set/reset enable */ /* set background color in EGA/VGA latch */ a = sc_vtb_geta(&scp->vtb, at); if (flip) col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00); else col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4); outw(GDCIDX, col | 0x00); /* set/reset */ outw(GDCIDX, 0xff08); /* bit mask */ writeb(d, 0); c = readb(d); /* set bg color in the latch */ /* foreground color */ if (flip) col = (on) ? (a & 0x0f00) : ((a & 0xf000) >> 4); else col = (on) ? ((a & 0xf000) >> 4) : (a & 0x0f00); outw(GDCIDX, col | 0x00); /* set/reset */ f = &(scp->font[sc_vtb_getc(&scp->vtb, at)*scp->font_size + scp->font_size - scp->curs_attr.base - 1]); height = imin(scp->curs_attr.height, scp->font_size); for (i = 0; i < height; ++i, --f) { outw(GDCIDX, (*f << 8) | 0x08); /* bit mask */ writeb(d, 0); d -= line_width; } outw(GDCIDX, 0x0000); /* set/reset */ outw(GDCIDX, 0x0001); /* set/reset enable */ outw(GDCIDX, 0xff08); /* bit mask */ } static int pxlblinkrate = 0; static void vga_pxlcursor_direct(scr_stat *scp, int at, int blink, int on, int flip) { if (scp->curs_attr.height <= 0) /* the text cursor is disabled */ return; if (on) { if (!blink) { scp->status |= VR_CURSOR_ON; draw_pxlcursor_direct(scp, at, on, flip); } else if (++pxlblinkrate & 4) { pxlblinkrate = 0; scp->status ^= VR_CURSOR_ON; draw_pxlcursor_direct(scp, at, scp->status & VR_CURSOR_ON, flip); } } else { if (scp->status & VR_CURSOR_ON) draw_pxlcursor_direct(scp, at, on, flip); scp->status &= ~VR_CURSOR_ON; } if (blink) scp->status |= VR_CURSOR_BLINK; else scp->status &= ~VR_CURSOR_BLINK; } static void vga_pxlcursor_planar(scr_stat *scp, int at, int blink, int on, int flip) { if (scp->curs_attr.height <= 0) /* the text cursor is disabled */ return; if (on) { if (!blink) { scp->status |= VR_CURSOR_ON; draw_pxlcursor_planar(scp, at, on, flip); } else if (++pxlblinkrate & 4) { pxlblinkrate = 0; scp->status ^= VR_CURSOR_ON; draw_pxlcursor_planar(scp, at, scp->status & VR_CURSOR_ON, flip); } } else { if (scp->status & VR_CURSOR_ON) draw_pxlcursor_planar(scp, at, on, flip); scp->status &= ~VR_CURSOR_ON; } if (blink) scp->status |= VR_CURSOR_BLINK; else scp->status &= ~VR_CURSOR_BLINK; } static void vga_pxlblink_direct(scr_stat *scp, int at, int flip) { if (!(scp->status & VR_CURSOR_BLINK)) return; if (!(++pxlblinkrate & 4)) return; pxlblinkrate = 0; scp->status ^= VR_CURSOR_ON; draw_pxlcursor_direct(scp, at, scp->status & VR_CURSOR_ON, flip); } static void vga_pxlblink_planar(scr_stat *scp, int at, int flip) { if (!(scp->status & VR_CURSOR_BLINK)) return; if (!(++pxlblinkrate & 4)) return; pxlblinkrate = 0; scp->status ^= VR_CURSOR_ON; draw_pxlcursor_planar(scp, at, scp->status & VR_CURSOR_ON, flip); } #ifndef SC_NO_CUTPASTE static void draw_pxlmouse_planar(scr_stat *scp, int x, int y) { vm_offset_t p; int line_width; int xoff, yoff; int ymax; u_short m; int i, j; line_width = scp->sc->adp->va_line_width; xoff = (x - scp->xoff*8)%8; yoff = y - (y/line_width)*line_width; ymax = imin(y + 16, scp->ypixel); outw(GDCIDX, 0x0805); /* read mode 1, write mode 0 */ outw(GDCIDX, 0x0001); /* set/reset enable */ outw(GDCIDX, 0x0002); /* color compare */ outw(GDCIDX, 0x0007); /* color don't care */ outw(GDCIDX, 0xff08); /* bit mask */ outw(GDCIDX, 0x0803); /* data rotate/function select (and) */ p = scp->sc->adp->va_window + line_width*y + x/8; if (x < scp->xpixel - 8) { for (i = y, j = 0; i < ymax; ++i, ++j) { m = ~(mouse_and_mask[j] >> xoff); #if defined(__i386__) || defined(__amd64__) *(u_char *)p &= m >> 8; *(u_char *)(p + 1) &= m; #else writeb(p, readb(p) & (m >> 8)); writeb(p + 1, readb(p + 1) & (m >> 8)); #endif p += line_width; } } else { xoff += 8; for (i = y, j = 0; i < ymax; ++i, ++j) { m = ~(mouse_and_mask[j] >> xoff); #if defined(__i386__) || defined(__amd64__) *(u_char *)p &= m; #else writeb(p, readb(p) & (m >> 8)); #endif p += line_width; } } outw(GDCIDX, 0x1003); /* data rotate/function select (or) */ p = scp->sc->adp->va_window + line_width*y + x/8; if (x < scp->xpixel - 8) { for (i = y, j = 0; i < ymax; ++i, ++j) { m = mouse_or_mask[j] >> xoff; #if defined(__i386__) || defined(__amd64__) *(u_char *)p &= m >> 8; *(u_char *)(p + 1) &= m; #else writeb(p, readb(p) & (m >> 8)); writeb(p + 1, readb(p + 1) & (m >> 8)); #endif p += line_width; } } else { for (i = y, j = 0; i < ymax; ++i, ++j) { m = mouse_or_mask[j] >> xoff; #if defined(__i386__) || defined(__amd64__) *(u_char *)p &= m; #else writeb(p, readb(p) & (m >> 8)); #endif p += line_width; } } outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, 0x0003); /* data rotate/function select */ } static void remove_pxlmouse_planar(scr_stat *scp, int x, int y) { vm_offset_t p; int col, row; int pos; int line_width; int ymax; int i; /* erase the mouse cursor image */ col = x/8 - scp->xoff; row = y/scp->font_size - scp->yoff; pos = row*scp->xsize + col; i = (col < scp->xsize - 1) ? 2 : 1; (*scp->rndr->draw)(scp, pos, i, FALSE); if (row < scp->ysize - 1) (*scp->rndr->draw)(scp, pos + scp->xsize, i, FALSE); /* paint border if necessary */ line_width = scp->sc->adp->va_line_width; outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, 0x0003); /* data rotate/function select */ outw(GDCIDX, 0x0f01); /* set/reset enable */ outw(GDCIDX, 0xff08); /* bit mask */ outw(GDCIDX, (scp->border << 8) | 0x00); /* set/reset */ if (row == scp->ysize - 1) { i = (scp->ysize + scp->yoff)*scp->font_size; ymax = imin(i + scp->font_size, scp->ypixel); p = scp->sc->adp->va_window + i*line_width + scp->xoff + col; if (col < scp->xsize - 1) { for (; i < ymax; ++i) { writeb(p, 0); writeb(p + 1, 0); p += line_width; } } else { for (; i < ymax; ++i) { writeb(p, 0); p += line_width; } } } if ((col == scp->xsize - 1) && (scp->xoff > 0)) { i = (row + scp->yoff)*scp->font_size; ymax = imin(i + scp->font_size*2, scp->ypixel); p = scp->sc->adp->va_window + i*line_width + scp->xoff + scp->xsize; for (; i < ymax; ++i) { writeb(p, 0); p += line_width; } } outw(GDCIDX, 0x0000); /* set/reset */ outw(GDCIDX, 0x0001); /* set/reset enable */ } static void vga_pxlmouse_direct(scr_stat *scp, int x, int y, int on) { vm_offset_t p; int line_width, pixel_size; int xend, yend; static int x_old = 0, xend_old = 0; static int y_old = 0, yend_old = 0; int i, j; uint32_t *u32; uint16_t *u16; int bpp; if (!on) return; bpp = scp->sc->adp->va_info.vi_depth; if ((bpp == 16) && (scp->sc->adp->va_info.vi_pixel_fsizes[1] == 5)) bpp = 15; line_width = scp->sc->adp->va_line_width; pixel_size = scp->sc->adp->va_info.vi_pixel_size; xend = imin(x + 16, scp->xpixel); yend = imin(y + 16, scp->ypixel); p = scp->sc->adp->va_window + y_old * line_width + x_old * pixel_size; for (i = 0; i < (yend_old - y_old); i++) { for (j = (xend_old - x_old - 1); j >= 0; j--) { switch (bpp) { case 32: u32 = (uint32_t*)(p + j * pixel_size); writel(u32, mouse_buf32[i * 16 + j]); break; case 16: /* FALLTHROUGH */ case 15: u16 = (uint16_t*)(p + j * pixel_size); writew(u16, mouse_buf16[i * 16 + j]); break; } } p += line_width; } p = scp->sc->adp->va_window + y * line_width + x * pixel_size; for (i = 0; i < (yend - y); i++) { for (j = (xend - x - 1); j >= 0; j--) { switch (bpp) { case 32: u32 = (uint32_t*)(p + j * pixel_size); mouse_buf32[i * 16 + j] = *u32; if (mouse_or_mask[i] & (1 << (15 - j))) writel(u32, vga_palette32[15]); else if (mouse_and_mask[i] & (1 << (15 - j))) writel(u32, 0); break; case 16: u16 = (uint16_t*)(p + j * pixel_size); mouse_buf16[i * 16 + j] = *u16; if (mouse_or_mask[i] & (1 << (15 - j))) writew(u16, vga_palette16[15]); else if (mouse_and_mask[i] & (1 << (15 - j))) writew(u16, 0); break; case 15: u16 = (uint16_t*)(p + j * pixel_size); mouse_buf16[i * 16 + j] = *u16; if (mouse_or_mask[i] & (1 << (15 - j))) writew(u16, vga_palette15[15]); else if (mouse_and_mask[i] & (1 << (15 - j))) writew(u16, 0); break; } } p += line_width; } x_old = x; y_old = y; xend_old = xend; yend_old = yend; } static void vga_pxlmouse_planar(scr_stat *scp, int x, int y, int on) { if (on) draw_pxlmouse_planar(scp, x, y); else remove_pxlmouse_planar(scp, x, y); } #endif /* SC_NO_CUTPASTE */ #endif /* SC_PIXEL_MODE */ #ifndef SC_NO_MODE_CHANGE /* graphics mode renderer */ static void vga_grborder(scr_stat *scp, int color) { - (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color); + vidd_set_border(scp->sc->adp, color); } #endif Index: head/sys/dev/syscons/scvidctl.c =================================================================== --- head/sys/dev/syscons/scvidctl.c (revision 174984) +++ head/sys/dev/syscons/scvidctl.c (revision 174985) @@ -1,890 +1,890 @@ /*- * Copyright (c) 1998 Kazutaka YOKOTA * All rights reserved. * * This code is derived from software contributed to The DragonFly Project * by Sascha Wildner * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer as * the first lines of this file unmodified. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_compat.h" #include "opt_syscons.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include SET_DECLARE(scrndr_set, const sc_renderer_t); /* for compatibility with previous versions */ /* 3.0-RELEASE used the following structure */ typedef struct old_video_adapter { int va_index; int va_type; int va_flags; /* flag bits are the same as the -CURRENT #define V_ADP_COLOR (1<<0) #define V_ADP_MODECHANGE (1<<1) #define V_ADP_STATESAVE (1<<2) #define V_ADP_STATELOAD (1<<3) #define V_ADP_FONT (1<<4) #define V_ADP_PALETTE (1<<5) #define V_ADP_BORDER (1<<6) #define V_ADP_VESA (1<<7) */ int va_crtc_addr; u_int va_window; /* virtual address */ size_t va_window_size; size_t va_window_gran; u_int va_buffer; /* virtual address */ size_t va_buffer_size; int va_initial_mode; int va_initial_bios_mode; int va_mode; } old_video_adapter_t; #define OLD_CONS_ADPINFO _IOWR('c', 101, old_video_adapter_t) /* 3.1-RELEASE used the following structure */ typedef struct old_video_adapter_info { int va_index; int va_type; char va_name[16]; int va_unit; int va_flags; int va_io_base; int va_io_size; int va_crtc_addr; int va_mem_base; int va_mem_size; u_int va_window; /* virtual address */ size_t va_window_size; size_t va_window_gran; u_int va_buffer; size_t va_buffer_size; int va_initial_mode; int va_initial_bios_mode; int va_mode; int va_line_width; } old_video_adapter_info_t; #define OLD_CONS_ADPINFO2 _IOWR('c', 101, old_video_adapter_info_t) /* 3.0-RELEASE and 3.1-RELEASE used the following structure */ typedef struct old_video_info { int vi_mode; int vi_flags; /* flag bits are the same as the -CURRENT #define V_INFO_COLOR (1<<0) #define V_INFO_GRAPHICS (1<<1) #define V_INFO_LINEAR (1<<2) #define V_INFO_VESA (1<<3) */ int vi_width; int vi_height; int vi_cwidth; int vi_cheight; int vi_depth; int vi_planes; u_int vi_window; /* physical address */ size_t vi_window_size; size_t vi_window_gran; u_int vi_buffer; /* physical address */ size_t vi_buffer_size; } old_video_info_t; #define OLD_CONS_MODEINFO _IOWR('c', 102, old_video_info_t) #define OLD_CONS_FINDMODE _IOWR('c', 103, old_video_info_t) int sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode, int xsize, int ysize, int fontsize, int fontwidth) { video_info_t info; u_char *font; int prev_ysize; int error; int s; - if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, mode, &info)) + if (vidd_get_info(scp->sc->adp, mode, &info)) return ENODEV; /* adjust argument values */ if (fontwidth <= 0) fontwidth = info.vi_cwidth; if (fontsize <= 0) fontsize = info.vi_cheight; if (fontsize < 14) { fontsize = 8; #ifndef SC_NO_FONT_LOADING if (!(scp->sc->fonts_loaded & FONT_8)) return EINVAL; font = scp->sc->font_8; #else font = NULL; #endif } else if (fontsize >= 16) { fontsize = 16; #ifndef SC_NO_FONT_LOADING if (!(scp->sc->fonts_loaded & FONT_16)) return EINVAL; font = scp->sc->font_16; #else font = NULL; #endif } else { fontsize = 14; #ifndef SC_NO_FONT_LOADING if (!(scp->sc->fonts_loaded & FONT_14)) return EINVAL; font = scp->sc->font_14; #else font = NULL; #endif } if ((xsize <= 0) || (xsize > info.vi_width)) xsize = info.vi_width; if ((ysize <= 0) || (ysize > info.vi_height)) ysize = info.vi_height; /* stop screen saver, etc */ s = spltty(); if ((error = sc_clean_up(scp))) { splx(s); return error; } if (sc_render_match(scp, scp->sc->adp->va_name, 0) == NULL) { splx(s); return ENODEV; } /* set up scp */ #ifndef SC_NO_HISTORY if (scp->history != NULL) sc_hist_save(scp); #endif prev_ysize = scp->ysize; /* * This is a kludge to fend off scrn_update() while we * muck around with scp. XXX */ scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN; scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE | MOUSE_VISIBLE); scp->mode = mode; scp->xsize = xsize; scp->ysize = ysize; scp->xoff = 0; scp->yoff = 0; scp->xpixel = scp->xsize*8; scp->ypixel = scp->ysize*fontsize; scp->font = font; scp->font_size = fontsize; scp->font_width = fontwidth; /* allocate buffers */ sc_alloc_scr_buffer(scp, TRUE, TRUE); sc_init_emulator(scp, NULL); #ifndef SC_NO_CUTPASTE sc_alloc_cut_buffer(scp, FALSE); #endif #ifndef SC_NO_HISTORY sc_alloc_history_buffer(scp, 0, prev_ysize, FALSE); #endif splx(s); if (scp == scp->sc->cur_scp) set_mode(scp); scp->status &= ~UNKNOWN_MODE; if (tp == NULL) return 0; DPRINTF(5, ("ws_*size (%d,%d), size (%d,%d)\n", tp->t_winsize.ws_col, tp->t_winsize.ws_row, scp->xsize, scp->ysize)); if (tp->t_winsize.ws_col != scp->xsize || tp->t_winsize.ws_row != scp->ysize) { tp->t_winsize.ws_col = scp->xsize; tp->t_winsize.ws_row = scp->ysize; if (tp->t_pgrp != NULL) { PGRP_LOCK(tp->t_pgrp); pgsignal(tp->t_pgrp, SIGWINCH, 1); PGRP_UNLOCK(tp->t_pgrp); } } return 0; } int sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode) { #ifdef SC_NO_MODE_CHANGE return ENODEV; #else video_info_t info; int error; int s; - if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, mode, &info)) + if (vidd_get_info(scp->sc->adp, mode, &info)) return ENODEV; /* stop screen saver, etc */ s = spltty(); if ((error = sc_clean_up(scp))) { splx(s); return error; } if (sc_render_match(scp, scp->sc->adp->va_name, GRAPHICS_MODE) == NULL) { splx(s); return ENODEV; } /* set up scp */ scp->status |= (UNKNOWN_MODE | GRAPHICS_MODE | MOUSE_HIDDEN); scp->status &= ~(PIXEL_MODE | MOUSE_VISIBLE); scp->mode = mode; /* * Don't change xsize and ysize; preserve the previous vty * and history buffers. */ scp->xoff = 0; scp->yoff = 0; scp->xpixel = info.vi_width; scp->ypixel = info.vi_height; scp->font = NULL; scp->font_size = 0; #ifndef SC_NO_SYSMOUSE /* move the mouse cursor at the center of the screen */ sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2); #endif sc_init_emulator(scp, NULL); splx(s); if (scp == scp->sc->cur_scp) set_mode(scp); /* clear_graphics();*/ scp->status &= ~UNKNOWN_MODE; if (tp == NULL) return 0; if (tp->t_winsize.ws_xpixel != scp->xpixel || tp->t_winsize.ws_ypixel != scp->ypixel) { tp->t_winsize.ws_xpixel = scp->xpixel; tp->t_winsize.ws_ypixel = scp->ypixel; if (tp->t_pgrp != NULL) { PGRP_LOCK(tp->t_pgrp); pgsignal(tp->t_pgrp, SIGWINCH, 1); PGRP_UNLOCK(tp->t_pgrp); } } return 0; #endif /* SC_NO_MODE_CHANGE */ } int sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize, int fontsize, int fontwidth) { #ifndef SC_PIXEL_MODE return ENODEV; #else video_info_t info; u_char *font; int prev_ysize; int error; int s; - if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info)) + if (vidd_get_info(scp->sc->adp, scp->mode, &info)) return ENODEV; /* this shouldn't happen */ /* adjust argument values */ if (fontsize <= 0) fontsize = info.vi_cheight; if (fontsize < 14) { fontsize = 8; #ifndef SC_NO_FONT_LOADING if (!(scp->sc->fonts_loaded & FONT_8)) return EINVAL; font = scp->sc->font_8; #else font = NULL; #endif } else if (fontsize >= 16) { fontsize = 16; #ifndef SC_NO_FONT_LOADING if (!(scp->sc->fonts_loaded & FONT_16)) return EINVAL; font = scp->sc->font_16; #else font = NULL; #endif } else { fontsize = 14; #ifndef SC_NO_FONT_LOADING if (!(scp->sc->fonts_loaded & FONT_14)) return EINVAL; font = scp->sc->font_14; #else font = NULL; #endif } if (xsize <= 0) xsize = info.vi_width/8; if (ysize <= 0) ysize = info.vi_height/fontsize; if ((info.vi_width < xsize*8) || (info.vi_height < ysize*fontsize)) return EINVAL; /* * We currently support the following graphic modes: * * - 4 bpp planar modes whose memory size does not exceed 64K * - 15, 16, 24 and 32 bpp linear modes */ if (info.vi_mem_model == V_INFO_MM_PLANAR) { if (info.vi_planes != 4) return ENODEV; /* * A memory size >64K requires bank switching to access the entire * screen. XXX */ if (info.vi_width * info.vi_height / 8 > info.vi_window_size) return ENODEV; } else if (info.vi_mem_model == V_INFO_MM_DIRECT) { if (!(info.vi_flags & V_INFO_LINEAR) && (info.vi_depth != 15) && (info.vi_depth != 16) && (info.vi_depth != 24) && (info.vi_depth != 32)) return ENODEV; } else return ENODEV; /* stop screen saver, etc */ s = spltty(); if ((error = sc_clean_up(scp))) { splx(s); return error; } if (sc_render_match(scp, scp->sc->adp->va_name, PIXEL_MODE) == NULL) { splx(s); return ENODEV; } #if 0 if (scp->tsw) (*scp->tsw->te_term)(scp, scp->ts); scp->tsw = NULL; scp->ts = NULL; #endif /* set up scp */ #ifndef SC_NO_HISTORY if (scp->history != NULL) sc_hist_save(scp); #endif prev_ysize = scp->ysize; scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN); scp->status &= ~(GRAPHICS_MODE | MOUSE_VISIBLE); scp->xsize = xsize; scp->ysize = ysize; scp->xoff = (scp->xpixel/8 - xsize)/2; scp->yoff = (scp->ypixel/fontsize - ysize)/2; scp->font = font; scp->font_size = fontsize; scp->font_width = fontwidth; /* allocate buffers */ sc_alloc_scr_buffer(scp, TRUE, TRUE); sc_init_emulator(scp, NULL); #ifndef SC_NO_CUTPASTE sc_alloc_cut_buffer(scp, FALSE); #endif #ifndef SC_NO_HISTORY sc_alloc_history_buffer(scp, 0, prev_ysize, FALSE); #endif splx(s); if (scp == scp->sc->cur_scp) { sc_set_border(scp, scp->border); sc_set_cursor_image(scp); } scp->status &= ~UNKNOWN_MODE; if (tp == NULL) return 0; if (tp->t_winsize.ws_col != scp->xsize || tp->t_winsize.ws_row != scp->ysize) { tp->t_winsize.ws_col = scp->xsize; tp->t_winsize.ws_row = scp->ysize; if (tp->t_pgrp != NULL) { PGRP_LOCK(tp->t_pgrp); pgsignal(tp->t_pgrp, SIGWINCH, 1); PGRP_UNLOCK(tp->t_pgrp); } } return 0; #endif /* SC_PIXEL_MODE */ } #define fb_ioctl(a, c, d) \ (((a) == NULL) ? ENODEV : \ - (*vidsw[(a)->va_index]->ioctl)((a), (c), (caddr_t)(d))) + vidd_ioctl((a), (c), (caddr_t)(d))) int sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct thread *td) { scr_stat *scp; video_adapter_t *adp; video_info_t info; video_adapter_info_t adp_info; int error; int s; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) int ival; #endif scp = SC_STAT(tp->t_dev); if (scp == NULL) /* tp == SC_MOUSE */ return ENOIOCTL; adp = scp->sc->adp; if (adp == NULL) /* shouldn't happen??? */ return ENODEV; switch (cmd) { case CONS_CURRENTADP: /* get current adapter index */ case FBIO_ADAPTER: return fb_ioctl(adp, FBIO_ADAPTER, data); case CONS_CURRENT: /* get current adapter type */ case FBIO_ADPTYPE: return fb_ioctl(adp, FBIO_ADPTYPE, data); case OLD_CONS_ADPINFO: /* adapter information (old interface) */ if (((old_video_adapter_t *)data)->va_index >= 0) { adp = vid_get_adapter(((old_video_adapter_t *)data)->va_index); if (adp == NULL) return ENODEV; } ((old_video_adapter_t *)data)->va_index = adp->va_index; ((old_video_adapter_t *)data)->va_type = adp->va_type; ((old_video_adapter_t *)data)->va_flags = adp->va_flags; ((old_video_adapter_t *)data)->va_crtc_addr = adp->va_crtc_addr; ((old_video_adapter_t *)data)->va_window = adp->va_window; ((old_video_adapter_t *)data)->va_window_size = adp->va_window_size; ((old_video_adapter_t *)data)->va_window_gran = adp->va_window_gran; ((old_video_adapter_t *)data)->va_buffer = adp->va_buffer; ((old_video_adapter_t *)data)->va_buffer_size = adp->va_buffer_size; ((old_video_adapter_t *)data)->va_mode = adp->va_mode; ((old_video_adapter_t *)data)->va_initial_mode = adp->va_initial_mode; ((old_video_adapter_t *)data)->va_initial_bios_mode = adp->va_initial_bios_mode; return 0; case OLD_CONS_ADPINFO2: /* adapter information (yet another old I/F) */ adp_info.va_index = ((old_video_adapter_info_t *)data)->va_index; if (adp_info.va_index >= 0) { adp = vid_get_adapter(adp_info.va_index); if (adp == NULL) return ENODEV; } error = fb_ioctl(adp, FBIO_ADPINFO, &adp_info); if (error == 0) bcopy(&adp_info, data, sizeof(old_video_adapter_info_t)); return error; case CONS_ADPINFO: /* adapter information */ case FBIO_ADPINFO: if (((video_adapter_info_t *)data)->va_index >= 0) { adp = vid_get_adapter(((video_adapter_info_t *)data)->va_index); if (adp == NULL) return ENODEV; } return fb_ioctl(adp, FBIO_ADPINFO, data); case CONS_GET: /* get current video mode */ case FBIO_GETMODE: *(int *)data = scp->mode; return 0; #ifndef SC_NO_MODE_CHANGE case FBIO_SETMODE: /* set video mode */ if (!(adp->va_flags & V_ADP_MODECHANGE)) return ENODEV; info.vi_mode = *(int *)data; error = fb_ioctl(adp, FBIO_MODEINFO, &info); if (error) return error; if (info.vi_flags & V_INFO_GRAPHICS) return sc_set_graphics_mode(scp, tp, *(int *)data); else return sc_set_text_mode(scp, tp, *(int *)data, 0, 0, 0, 0); #endif /* SC_NO_MODE_CHANGE */ case OLD_CONS_MODEINFO: /* get mode information (old infterface) */ info.vi_mode = ((old_video_info_t *)data)->vi_mode; error = fb_ioctl(adp, FBIO_MODEINFO, &info); if (error == 0) bcopy(&info, (old_video_info_t *)data, sizeof(old_video_info_t)); return error; case CONS_MODEINFO: /* get mode information */ case FBIO_MODEINFO: return fb_ioctl(adp, FBIO_MODEINFO, data); case OLD_CONS_FINDMODE: /* find a matching video mode (old interface) */ bzero(&info, sizeof(info)); bcopy((old_video_info_t *)data, &info, sizeof(old_video_info_t)); error = fb_ioctl(adp, FBIO_FINDMODE, &info); if (error == 0) bcopy(&info, (old_video_info_t *)data, sizeof(old_video_info_t)); return error; case CONS_FINDMODE: /* find a matching video mode */ case FBIO_FINDMODE: return fb_ioctl(adp, FBIO_FINDMODE, data); #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('c', 104): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case CONS_SETWINORG: /* set frame buffer window origin */ case FBIO_SETWINORG: if (scp != scp->sc->cur_scp) return ENODEV; /* XXX */ return fb_ioctl(adp, FBIO_SETWINORG, data); case FBIO_GETWINORG: /* get frame buffer window origin */ if (scp != scp->sc->cur_scp) return ENODEV; /* XXX */ return fb_ioctl(adp, FBIO_GETWINORG, data); case FBIO_GETDISPSTART: case FBIO_SETDISPSTART: case FBIO_GETLINEWIDTH: case FBIO_SETLINEWIDTH: if (scp != scp->sc->cur_scp) return ENODEV; /* XXX */ return fb_ioctl(adp, cmd, data); case FBIO_GETPALETTE: case FBIO_SETPALETTE: case FBIOPUTCMAP: case FBIOGETCMAP: case FBIOGTYPE: case FBIOGATTR: case FBIOSVIDEO: case FBIOGVIDEO: case FBIOSCURSOR: case FBIOGCURSOR: case FBIOSCURPOS: case FBIOGCURPOS: case FBIOGCURMAX: if (scp != scp->sc->cur_scp) return ENODEV; /* XXX */ return fb_ioctl(adp, cmd, data); case FBIO_BLANK: if (scp != scp->sc->cur_scp) return ENODEV; /* XXX */ return fb_ioctl(adp, cmd, data); #ifndef SC_NO_MODE_CHANGE /* generic text modes */ case SW_TEXT_80x25: case SW_TEXT_80x30: case SW_TEXT_80x43: case SW_TEXT_80x50: case SW_TEXT_80x60: /* FALLTHROUGH */ /* VGA TEXT MODES */ case SW_VGA_C40x25: case SW_VGA_C80x25: case SW_VGA_M80x25: case SW_VGA_C80x30: case SW_VGA_M80x30: case SW_VGA_C80x50: case SW_VGA_M80x50: case SW_VGA_C80x60: case SW_VGA_M80x60: case SW_VGA_C90x25: case SW_VGA_M90x25: case SW_VGA_C90x30: case SW_VGA_M90x30: case SW_VGA_C90x43: case SW_VGA_M90x43: case SW_VGA_C90x50: case SW_VGA_M90x50: case SW_VGA_C90x60: case SW_VGA_M90x60: case SW_B40x25: case SW_C40x25: case SW_B80x25: case SW_C80x25: case SW_ENH_B40x25: case SW_ENH_C40x25: case SW_ENH_B80x25: case SW_ENH_C80x25: case SW_ENH_B80x43: case SW_ENH_C80x43: case SW_EGAMONO80x25: #ifdef PC98 /* PC98 TEXT MODES */ case SW_PC98_80x25: case SW_PC98_80x30: #endif if (!(adp->va_flags & V_ADP_MODECHANGE)) return ENODEV; return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0, 0); /* GRAPHICS MODES */ case SW_BG320: case SW_BG640: case SW_CG320: case SW_CG320_D: case SW_CG640_E: case SW_CG640x350: case SW_ENH_CG640: case SW_BG640x480: case SW_CG640x480: case SW_VGA_CG320: case SW_VGA_MODEX: #ifdef PC98 /* PC98 GRAPHICS MODES */ case SW_PC98_EGC640x400: case SW_PC98_PEGC640x400: case SW_PC98_PEGC640x480: #endif if (!(adp->va_flags & V_ADP_MODECHANGE)) return ENODEV; return sc_set_graphics_mode(scp, tp, cmd & 0xff); #endif /* SC_NO_MODE_CHANGE */ #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 10): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSETMODE: /* set current mode of this (virtual) console */ switch (*(int *)data) { case KD_TEXT: /* switch to TEXT (known) mode */ /* * If scp->mode is of graphics modes, we don't know which * text mode to switch back to... */ if (scp->status & GRAPHICS_MODE) return EINVAL; /* restore fonts & palette ! */ #if 0 #ifndef SC_NO_FONT_LOADING if (ISFONTAVAIL(adp->va_flags) && !(scp->status & (GRAPHICS_MODE | PIXEL_MODE))) /* * FONT KLUDGE * Don't load fonts for now... XXX */ if (scp->sc->fonts_loaded & FONT_8) sc_load_font(scp, 0, 8, 8, scp->sc->font_8, 0, 256); if (scp->sc->fonts_loaded & FONT_14) sc_load_font(scp, 0, 14, 8, scp->sc->font_14, 0, 256); if (scp->sc->fonts_loaded & FONT_16) sc_load_font(scp, 0, 16, 8, scp->sc->font_16, 0, 256); } #endif /* SC_NO_FONT_LOADING */ #endif #ifndef SC_NO_PALETTE_LOADING - load_palette(adp, scp->sc->palette); + vidd_load_palette(adp, scp->sc->palette); #endif #ifndef PC98 /* move hardware cursor out of the way */ - (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1); + vidd_set_hw_cursor(adp, -1, -1); #endif /* FALLTHROUGH */ case KD_TEXT1: /* switch to TEXT (known) mode */ /* * If scp->mode is of graphics modes, we don't know which * text/pixel mode to switch back to... */ if (scp->status & GRAPHICS_MODE) return EINVAL; s = spltty(); if ((error = sc_clean_up(scp))) { splx(s); return error; } #ifndef PC98 scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN; splx(s); /* no restore fonts & palette */ if (scp == scp->sc->cur_scp) set_mode(scp); sc_clear_screen(scp); scp->status &= ~UNKNOWN_MODE; #else /* PC98 */ scp->status &= ~UNKNOWN_MODE; /* no restore fonts & palette */ if (scp == scp->sc->cur_scp) set_mode(scp); sc_clear_screen(scp); splx(s); #endif /* PC98 */ return 0; #ifdef SC_PIXEL_MODE case KD_PIXEL: /* pixel (raster) display */ if (!(scp->status & (GRAPHICS_MODE | PIXEL_MODE))) return EINVAL; if (scp->status & GRAPHICS_MODE) return sc_set_pixel_mode(scp, tp, scp->xsize, scp->ysize, scp->font_size, scp->font_width); s = spltty(); if ((error = sc_clean_up(scp))) { splx(s); return error; } scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN); splx(s); if (scp == scp->sc->cur_scp) { set_mode(scp); #ifndef SC_NO_PALETTE_LOADING - load_palette(adp, scp->sc->palette); + vidd_load_palette(adp, scp->sc->palette); #endif } sc_clear_screen(scp); scp->status &= ~UNKNOWN_MODE; return 0; #endif /* SC_PIXEL_MODE */ case KD_GRAPHICS: /* switch to GRAPHICS (unknown) mode */ s = spltty(); if ((error = sc_clean_up(scp))) { splx(s); return error; } scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN; splx(s); #ifdef PC98 if (scp == scp->sc->cur_scp) set_mode(scp); #endif return 0; default: return EINVAL; } /* NOT REACHED */ #ifdef SC_PIXEL_MODE case KDRASTER: /* set pixel (raster) display mode */ if (ISUNKNOWNSC(scp) || ISTEXTSC(scp)) return ENODEV; return sc_set_pixel_mode(scp, tp, ((int *)data)[0], ((int *)data)[1], ((int *)data)[2], 8); #endif /* SC_PIXEL_MODE */ case KDGETMODE: /* get current mode of this (virtual) console */ /* * From the user program's point of view, KD_PIXEL is the same * as KD_TEXT... */ *data = ISGRAPHSC(scp) ? KD_GRAPHICS : KD_TEXT; return 0; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 13): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSBORDER: /* set border color of this (virtual) console */ scp->border = *(int *)data; if (scp == scp->sc->cur_scp) sc_set_border(scp, scp->border); return 0; } return ENOIOCTL; } static LIST_HEAD(, sc_renderer) sc_rndr_list = LIST_HEAD_INITIALIZER(sc_rndr_list); int sc_render_add(sc_renderer_t *rndr) { LIST_INSERT_HEAD(&sc_rndr_list, rndr, link); return 0; } int sc_render_remove(sc_renderer_t *rndr) { /* LIST_REMOVE(rndr, link); */ return EBUSY; /* XXX */ } sc_rndr_sw_t *sc_render_match(scr_stat *scp, char *name, int mode) { const sc_renderer_t **list; const sc_renderer_t *p; if (!LIST_EMPTY(&sc_rndr_list)) { LIST_FOREACH(p, &sc_rndr_list, link) { if ((strcmp(p->name, name) == 0) && (mode == p->mode)) { scp->status &= ~(VR_CURSOR_ON | VR_CURSOR_BLINK); return p->rndrsw; } } } else { SET_FOREACH(list, scrndr_set) { p = *list; if ((strcmp(p->name, name) == 0) && (mode == p->mode)) { scp->status &= ~(VR_CURSOR_ON | VR_CURSOR_BLINK); return p->rndrsw; } } } return NULL; } Index: head/sys/dev/syscons/snake/snake_saver.c =================================================================== --- head/sys/dev/syscons/snake/snake_saver.c (revision 174984) +++ head/sys/dev/syscons/snake/snake_saver.c (revision 174985) @@ -1,133 +1,133 @@ /*- * Copyright (c) 1995-1998 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #include #include static u_char *message; static int *messagep; static int messagelen; static int blanked; static int snake_saver(video_adapter_t *adp, int blank) { static int dirx, diry; int f; sc_softc_t *sc; scr_stat *scp; /* XXX hack for minimal changes. */ #define save message #define savs messagep sc = sc_find_softc(adp, NULL); if (sc == NULL) return EAGAIN; scp = sc->cur_scp; if (blank) { if (adp->va_info.vi_flags & V_INFO_GRAPHICS) return EAGAIN; if (blanked <= 0) { sc_vtb_clear(&scp->scr, sc->scr_map[0x20], (FG_LIGHTGREY | BG_BLACK) << 8); - (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1); + vidd_set_hw_cursor(adp, -1, -1); sc_set_border(scp, 0); dirx = (scp->xpos ? 1 : -1); diry = (scp->ypos ? scp->xsize : -scp->xsize); for (f=0; f< messagelen; f++) savs[f] = scp->xpos + scp->ypos*scp->xsize; sc_vtb_putc(&scp->scr, savs[0], sc->scr_map[*save], (FG_LIGHTGREY | BG_BLACK) << 8); blanked = 1; } if (blanked++ < 4) return 0; blanked = 1; sc_vtb_putc(&scp->scr, savs[messagelen - 1], sc->scr_map[0x20], (FG_LIGHTGREY | BG_BLACK) << 8); for (f=messagelen-1; f > 0; f--) savs[f] = savs[f-1]; f = savs[0]; if ((f % scp->xsize) == 0 || (f % scp->xsize) == scp->xsize - 1 || (random() % 50) == 0) dirx = -dirx; if ((f / scp->xsize) == 0 || (f / scp->xsize) == scp->ysize - 1 || (random() % 20) == 0) diry = -diry; savs[0] += dirx + diry; for (f=messagelen-1; f>=0; f--) sc_vtb_putc(&scp->scr, savs[f], sc->scr_map[save[f]], (FG_LIGHTGREY | BG_BLACK) << 8); } else blanked = 0; return 0; } static int snake_init(video_adapter_t *adp) { messagelen = strlen(ostype) + 1 + strlen(osrelease); message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK); sprintf(message, "%s %s", ostype, osrelease); messagep = malloc(messagelen * sizeof *messagep, M_DEVBUF, M_WAITOK); return 0; } static int snake_term(video_adapter_t *adp) { free(message, M_DEVBUF); free(messagep, M_DEVBUF); return 0; } static scrn_saver_t snake_module = { "snake_saver", snake_init, snake_term, snake_saver, NULL, }; SAVER_MODULE(snake_saver, snake_module); Index: head/sys/dev/syscons/star/star_saver.c =================================================================== --- head/sys/dev/syscons/star/star_saver.c (revision 174984) +++ head/sys/dev/syscons/star/star_saver.c (revision 174985) @@ -1,128 +1,128 @@ /*- * Copyright (c) 1995-1998 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #define NUM_STARS 50 static int blanked; /* * Alternate saver that got its inspiration from a well known utility * package for an inferior^H^H^H^H^H^Hfamous OS. */ static int star_saver(video_adapter_t *adp, int blank) { sc_softc_t *sc; scr_stat *scp; int cell, i; static u_char pattern[] = {"...........++++*** "}; static char color16[] = {FG_DARKGREY, FG_LIGHTGREY, FG_WHITE, FG_LIGHTCYAN}; static char color8[] = {FG_BLUE, FG_BROWN, FG_LIGHTGREY, FG_CYAN}; static char *colors; static u_short stars[NUM_STARS][2]; sc = sc_find_softc(adp, NULL); if (sc == NULL) return EAGAIN; scp = sc->cur_scp; if (blank) { if (adp->va_info.vi_flags & V_INFO_GRAPHICS) return EAGAIN; if (!blanked) { switch (adp->va_mode) { case M_PC98_80x25: case M_PC98_80x30: colors = color8; break; default: colors = color16; break; } /* clear the screen and set the border color */ sc_vtb_clear(&scp->scr, sc->scr_map[0x20], (FG_LIGHTGREY | BG_BLACK) << 8); - (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1); + vidd_set_hw_cursor(adp, -1, -1); sc_set_border(scp, 0); blanked = TRUE; for(i=0; ixsize*scp->ysize); stars[i][1] = 0; } } cell = random() % NUM_STARS; sc_vtb_putc(&scp->scr, stars[cell][0], sc->scr_map[pattern[stars[cell][1]]], colors[random()%sizeof(color16)] << 8); if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) { stars[cell][0] = random() % (scp->xsize*scp->ysize); stars[cell][1] = 0; } } else blanked = FALSE; return 0; } static int star_init(video_adapter_t *adp) { blanked = FALSE; return 0; } static int star_term(video_adapter_t *adp) { return 0; } static scrn_saver_t star_module = { "star_saver", star_init, star_term, star_saver, NULL, }; SAVER_MODULE(star_saver, star_module); Index: head/sys/dev/syscons/syscons.c =================================================================== --- head/sys/dev/syscons/syscons.c (revision 174984) +++ head/sys/dev/syscons/syscons.c (revision 174985) @@ -1,3702 +1,3700 @@ /*- * Copyright (c) 1992-1998 Søren Schmidt * All rights reserved. * * This code is derived from software contributed to The DragonFly Project * by Sascha Wildner * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_compat.h" #include "opt_syscons.h" #include "opt_splash.h" #include "opt_ddb.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined(__sparc64__) || defined(__powerpc__) #include #else #include #endif #if defined( __i386__) || defined(__amd64__) #include #include #endif #include #include #include #include #define COLD 0 #define WARM 1 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */ #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */ #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */ typedef struct default_attr { int std_color; /* normal hardware color */ int rev_color; /* reverse hardware color */ } default_attr; static default_attr user_default = { SC_NORM_ATTR, SC_NORM_REV_ATTR, }; static default_attr kernel_default = { SC_KERNEL_CONS_ATTR, SC_KERNEL_CONS_REV_ATTR, }; static int sc_console_unit = -1; static int sc_saver_keyb_only = 1; static scr_stat *sc_console; static struct tty *sc_console_tty; static struct consdev *sc_consptr; static void *kernel_console_ts; static scr_stat main_console; static struct cdev *main_devs[MAXCONS]; static char init_done = COLD; static char shutdown_in_progress = FALSE; static char sc_malloc = FALSE; static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */ static int run_scrn_saver = FALSE; /* should run the saver? */ static int enable_bell = TRUE; /* enable beeper */ #ifndef SC_DISABLE_REBOOT static int enable_reboot = TRUE; /* enable keyboard reboot */ #endif #ifndef SC_DISABLE_KDBKEY static int enable_kdbkey = TRUE; /* enable keyboard debug */ #endif static long scrn_blank_time = 0; /* screen saver timeout value */ #ifdef DEV_SPLASH static int scrn_blanked; /* # of blanked screen */ static int sticky_splash = FALSE; static void none_saver(sc_softc_t *sc, int blank) { } static void (*current_saver)(sc_softc_t *, int) = none_saver; #endif SYSCTL_NODE(_hw, OID_AUTO, syscons, CTLFLAG_RD, 0, "syscons"); SYSCTL_NODE(_hw_syscons, OID_AUTO, saver, CTLFLAG_RD, 0, "saver"); SYSCTL_INT(_hw_syscons_saver, OID_AUTO, keybonly, CTLFLAG_RW, &sc_saver_keyb_only, 0, "screen saver interrupted by input only"); SYSCTL_INT(_hw_syscons, OID_AUTO, bell, CTLFLAG_RW, &enable_bell, 0, "enable bell"); #ifndef SC_DISABLE_REBOOT SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_reboot, CTLFLAG_RW|CTLFLAG_SECURE, &enable_reboot, 0, "enable keyboard reboot"); #endif #ifndef SC_DISABLE_KDBKEY SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_debug, CTLFLAG_RW|CTLFLAG_SECURE, &enable_kdbkey, 0, "enable keyboard debug"); #endif #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT) #include "font.h" #endif d_ioctl_t *sc_user_ioctl; static bios_values_t bios_value; static int enable_panic_key; SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key, 0, "Enable panic via keypress specified in kbdmap(5)"); #define SC_CONSOLECTL 255 #define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ? \ SC_DEV((sc), (x))->si_tty : NULL) #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN)) static int debugger; /* prototypes */ static int sc_allocate_keyboard(sc_softc_t *sc, int unit); static struct tty *sc_alloc_tty(struct cdev *dev); static int scvidprobe(int unit, int flags, int cons); static int sckbdprobe(int unit, int flags, int cons); static void scmeminit(void *arg); static int scdevtounit(struct cdev *dev); static kbd_callback_func_t sckbdevent; static int scparam(struct tty *tp, struct termios *t); static void scstart(struct tty *tp); static void scinit(int unit, int flags); static scr_stat *sc_get_stat(struct cdev *devptr); static void scterm(int unit, int flags); static void scshutdown(void *arg, int howto); static u_int scgetc(sc_softc_t *sc, u_int flags); #define SCGETC_CN 1 #define SCGETC_NONBLOCK 2 static int sccngetch(int flags); static void sccnupdate(scr_stat *scp); static scr_stat *alloc_scp(sc_softc_t *sc, int vty); static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp); static timeout_t scrn_timer; static int and_region(int *s1, int *e1, int s2, int e2); static void scrn_update(scr_stat *scp, int show_cursor); #ifdef DEV_SPLASH static int scsplash_callback(int event, void *arg); static void scsplash_saver(sc_softc_t *sc, int show); static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int)); static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int)); static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border); static int restore_scrn_saver_mode(scr_stat *scp, int changemode); static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int)); static int wait_scrn_saver_stop(sc_softc_t *sc); #define scsplash_stick(stick) (sticky_splash = (stick)) #else /* !DEV_SPLASH */ #define scsplash_stick(stick) #endif /* DEV_SPLASH */ static int do_switch_scr(sc_softc_t *sc, int s); static int vt_proc_alive(scr_stat *scp); static int signal_vt_rel(scr_stat *scp); static int signal_vt_acq(scr_stat *scp); static int finish_vt_rel(scr_stat *scp, int release, int *s); static int finish_vt_acq(scr_stat *scp); static void exchange_scr(sc_softc_t *sc); static void update_cursor_image(scr_stat *scp); static void change_cursor_shape(scr_stat *scp, int flags, int base, int height); static int save_kbd_state(scr_stat *scp); static int update_kbd_state(scr_stat *scp, int state, int mask); static int update_kbd_leds(scr_stat *scp, int which); static timeout_t blink_screen; static cn_probe_t sc_cnprobe; static cn_init_t sc_cninit; static cn_term_t sc_cnterm; static cn_getc_t sc_cngetc; static cn_putc_t sc_cnputc; CONSOLE_DRIVER(sc); static d_open_t scopen; static d_close_t scclose; static d_read_t scread; static d_ioctl_t scioctl; static d_mmap_t scmmap; static struct cdevsw sc_cdevsw = { .d_version = D_VERSION, .d_open = scopen, .d_close = scclose, .d_read = scread, .d_ioctl = scioctl, .d_mmap = scmmap, .d_name = "sc", .d_flags = D_TTY | D_NEEDGIANT, }; int sc_probe_unit(int unit, int flags) { if (!scvidprobe(unit, flags, FALSE)) { if (bootverbose) printf("%s%d: no video adapter found.\n", SC_DRIVER_NAME, unit); return ENXIO; } /* syscons will be attached even when there is no keyboard */ sckbdprobe(unit, flags, FALSE); return 0; } /* probe video adapters, return TRUE if found */ static int scvidprobe(int unit, int flags, int cons) { /* * Access the video adapter driver through the back door! * Video adapter drivers need to be configured before syscons. * However, when syscons is being probed as the low-level console, * they have not been initialized yet. We force them to initialize * themselves here. XXX */ vid_configure(cons ? VIO_PROBE_ONLY : 0); return (vid_find_adapter("*", unit) >= 0); } /* probe the keyboard, return TRUE if found */ static int sckbdprobe(int unit, int flags, int cons) { /* access the keyboard driver through the backdoor! */ kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0); return (kbd_find_keyboard("*", unit) >= 0); } static char *adapter_name(video_adapter_t *adp) { static struct { int type; char *name[2]; } names[] = { { KD_MONO, { "MDA", "MDA" } }, { KD_HERCULES, { "Hercules", "Hercules" } }, { KD_CGA, { "CGA", "CGA" } }, { KD_EGA, { "EGA", "EGA (mono)" } }, { KD_VGA, { "VGA", "VGA (mono)" } }, { KD_PC98, { "PC-98x1", "PC-98x1" } }, { KD_TGA, { "TGA", "TGA" } }, { -1, { "Unknown", "Unknown" } }, }; int i; for (i = 0; names[i].type != -1; ++i) if (names[i].type == adp->va_type) break; return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1]; } static struct tty * sc_alloc_tty(struct cdev *dev) { struct tty *tp; tp = dev->si_tty = ttyalloc(); ttyinitmode(tp, 1, 0); tp->t_oproc = scstart; tp->t_param = scparam; tp->t_stop = nottystop; tp->t_dev = dev; return (tp); } int sc_attach_unit(int unit, int flags) { sc_softc_t *sc; scr_stat *scp; #ifdef SC_PIXEL_MODE video_info_t info; #endif int vc; struct cdev *dev; flags &= ~SC_KERNEL_CONSOLE; if (sc_console_unit == unit) { /* * If this unit is being used as the system console, we need to * adjust some variables and buffers before and after scinit(). */ /* assert(sc_console != NULL) */ flags |= SC_KERNEL_CONSOLE; scmeminit(NULL); scinit(unit, flags); if (sc_console->tsw->te_size > 0) { /* assert(sc_console->ts != NULL); */ kernel_console_ts = sc_console->ts; sc_console->ts = malloc(sc_console->tsw->te_size, M_DEVBUF, M_WAITOK); bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size); (*sc_console->tsw->te_default_attr)(sc_console, user_default.std_color, user_default.rev_color); } } else { scinit(unit, flags); } sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE); sc->config = flags; scp = sc_get_stat(sc->dev[0]); if (sc_console == NULL) /* sc_console_unit < 0 */ sc_console = scp; #ifdef SC_PIXEL_MODE if ((sc->config & SC_VESA800X600) - && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) { + && (vidd_get_info(sc->adp, M_VESA_800x600, &info) == 0)) { #ifdef DEV_SPLASH if (sc->flags & SC_SPLASH_SCRN) splash_term(sc->adp); #endif sc_set_graphics_mode(scp, NULL, M_VESA_800x600); sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8); sc->initial_mode = M_VESA_800x600; #ifdef DEV_SPLASH /* put up the splash again! */ if (sc->flags & SC_SPLASH_SCRN) splash_init(sc->adp, scsplash_callback, sc); #endif } #endif /* SC_PIXEL_MODE */ /* initialize cursor */ if (!ISGRAPHSC(scp)) update_cursor_image(scp); /* get screen update going */ scrn_timer(sc); /* set up the keyboard */ kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); update_kbd_state(scp, scp->status, LOCK_MASK); printf("%s%d: %s <%d virtual consoles, flags=0x%x>\n", SC_DRIVER_NAME, unit, adapter_name(sc->adp), sc->vtys, sc->config); if (bootverbose) { printf("%s%d:", SC_DRIVER_NAME, unit); if (sc->adapter >= 0) printf(" fb%d", sc->adapter); if (sc->keyboard >= 0) printf(", kbd%d", sc->keyboard); if (scp->tsw) printf(", terminal emulator: %s (%s)", scp->tsw->te_name, scp->tsw->te_desc); printf("\n"); } /* register a shutdown callback for the kernel console */ if (sc_console_unit == unit) EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown, (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT); for (vc = 0; vc < sc->vtys; vc++) { if (sc->dev[vc] == NULL) { sc->dev[vc] = make_dev(&sc_cdevsw, vc + unit * MAXCONS, UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS); sc_alloc_tty(sc->dev[vc]); if (vc == 0 && sc->dev == main_devs) SC_STAT(sc->dev[0]) = &main_console; } /* * The first vty already has struct tty and scr_stat initialized * in scinit(). The other vtys will have these structs when * first opened. */ } dev = make_dev(&sc_cdevsw, SC_CONSOLECTL, UID_ROOT, GID_WHEEL, 0600, "consolectl"); sc_console_tty = sc_alloc_tty(dev); ttyconsolemode(sc_console_tty, 0); SC_STAT(dev) = sc_console; return 0; } static void scmeminit(void *arg) { if (sc_malloc) return; sc_malloc = TRUE; /* * As soon as malloc() becomes functional, we had better allocate * various buffers for the kernel console. */ if (sc_console_unit < 0) /* sc_console == NULL */ return; /* copy the temporary buffer to the final buffer */ sc_alloc_scr_buffer(sc_console, FALSE, FALSE); #ifndef SC_NO_CUTPASTE sc_alloc_cut_buffer(sc_console, FALSE); #endif #ifndef SC_NO_HISTORY /* initialize history buffer & pointers */ sc_alloc_history_buffer(sc_console, 0, 0, FALSE); #endif } /* XXX */ SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL); static int scdevtounit(struct cdev *dev) { int vty = SC_VTY(dev); if (vty == SC_CONSOLECTL) return ((sc_console != NULL) ? sc_console->sc->unit : -1); else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit())) return -1; else return vty/MAXCONS; } static int scopen(struct cdev *dev, int flag, int mode, struct thread *td) { int unit = scdevtounit(dev); sc_softc_t *sc; struct tty *tp; scr_stat *scp; #ifndef __sparc64__ keyarg_t key; #endif int error; DPRINTF(5, ("scopen: dev:%s, unit:%d, vty:%d\n", devtoname(dev), unit, SC_VTY(dev))); tp = dev->si_tty; sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0); if (sc == NULL) return ENXIO; if (!ISTTYOPEN(tp)) { tp->t_termios = tp->t_init_in; /* Use the current setting of the <-- key as default VERASE. */ /* If the Delete key is preferable, an stty is necessary */ #ifndef __sparc64__ if (sc->kbd != NULL) { key.keynum = KEYCODE_BS; kbdd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key); tp->t_cc[VERASE] = key.key.map[0]; } #endif scparam(tp, &tp->t_termios); ttyld_modem(tp, 1); } else if (tp->t_state & TS_XCLUDE && priv_check(td, PRIV_TTY_EXCLUSIVE)) return(EBUSY); error = ttyld_open(tp, dev); scp = sc_get_stat(dev); if (scp == NULL) { scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev)); if (ISGRAPHSC(scp)) sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8); } if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) { tp->t_winsize.ws_col = scp->xsize; tp->t_winsize.ws_row = scp->ysize; } return error; } static int scclose(struct cdev *dev, int flag, int mode, struct thread *td) { struct tty *tp = dev->si_tty; scr_stat *scp; int s; if (SC_VTY(dev) != SC_CONSOLECTL) { scp = sc_get_stat(tp->t_dev); /* were we in the middle of the VT switching process? */ DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit)); s = spltty(); if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit)) cnavailable(sc_consptr, TRUE); if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */ DPRINTF(5, ("reset WAIT_REL, ")); if (finish_vt_acq(scp) == 0) /* force acknowledge */ DPRINTF(5, ("reset WAIT_ACQ, ")); #ifdef not_yet_done if (scp == &main_console) { scp->pid = 0; scp->proc = NULL; scp->smode.mode = VT_AUTO; } else { sc_vtb_destroy(&scp->vtb); #ifndef __sparc64__ sc_vtb_destroy(&scp->scr); #endif sc_free_history_buffer(scp, scp->ysize); SC_STAT(dev) = NULL; free(scp, M_DEVBUF); } #else scp->pid = 0; scp->proc = NULL; scp->smode.mode = VT_AUTO; #endif scp->kbd_mode = K_XLATE; if (scp == scp->sc->cur_scp) kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); DPRINTF(5, ("done.\n")); } spltty(); ttyld_close(tp, flag); tty_close(tp); spl0(); return(0); } static int scread(struct cdev *dev, struct uio *uio, int flag) { if (!sc_saver_keyb_only) sc_touch_scrn_saver(); return ttyread(dev, uio, flag); } static int sckbdevent(keyboard_t *thiskbd, int event, void *arg) { sc_softc_t *sc; struct tty *cur_tty; int c; size_t len; u_char *cp; sc = (sc_softc_t *)arg; /* assert(thiskbd == sc->kbd) */ switch (event) { case KBDIO_KEYINPUT: break; case KBDIO_UNLOADING: sc->kbd = NULL; sc->keyboard = -1; kbd_release(thiskbd, (void *)&sc->keyboard); return 0; default: return EINVAL; } /* * Loop while there is still input to get from the keyboard. * I don't think this is nessesary, and it doesn't fix * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX */ while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) { cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index); if (!ISTTYOPEN(cur_tty)) { cur_tty = sc_console_tty; if (!ISTTYOPEN(cur_tty)) continue; } if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty)) continue; switch (KEYFLAGS(c)) { case 0x0000: /* normal key */ ttyld_rint(cur_tty, KEYCHAR(c)); break; case FKEY: /* function key, return string */ cp = kbdd_get_fkeystr(thiskbd, KEYCHAR(c), &len); if (cp != NULL) { while (len-- > 0) ttyld_rint(cur_tty, *cp++); } break; case MKEY: /* meta is active, prepend ESC */ ttyld_rint(cur_tty, 0x1b); ttyld_rint(cur_tty, KEYCHAR(c)); break; case BKEY: /* backtab fixed sequence (esc [ Z) */ ttyld_rint(cur_tty, 0x1b); ttyld_rint(cur_tty, '['); ttyld_rint(cur_tty, 'Z'); break; } } sc->cur_scp->status |= MOUSE_HIDDEN; return 0; } static int scparam(struct tty *tp, struct termios *t) { tp->t_ispeed = t->c_ispeed; tp->t_ospeed = t->c_ospeed; tp->t_cflag = t->c_cflag; return 0; } static int scioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) { int error; int i; struct tty *tp; sc_softc_t *sc; scr_stat *scp; int s; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) int ival; #endif tp = dev->si_tty; /* If there is a user_ioctl function call that first */ if (sc_user_ioctl) { error = (*sc_user_ioctl)(dev, cmd, data, flag, td); if (error != ENOIOCTL) return error; } error = sc_vid_ioctl(tp, cmd, data, flag, td); if (error != ENOIOCTL) return error; #ifndef SC_NO_HISTORY error = sc_hist_ioctl(tp, cmd, data, flag, td); if (error != ENOIOCTL) return error; #endif #ifndef SC_NO_SYSMOUSE error = sc_mouse_ioctl(tp, cmd, data, flag, td); if (error != ENOIOCTL) return error; #endif scp = sc_get_stat(tp->t_dev); /* assert(scp != NULL) */ /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */ sc = scp->sc; if (scp->tsw) { error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td); if (error != ENOIOCTL) return error; } switch (cmd) { /* process console hardware related ioctl's */ case GIO_ATTR: /* get current attributes */ /* this ioctl is not processed here, but in the terminal emulator */ return ENOTTY; case GIO_COLOR: /* is this a color console ? */ *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0; return 0; case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */ if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME) return EINVAL; s = spltty(); scrn_blank_time = *(int *)data; run_scrn_saver = (scrn_blank_time != 0); splx(s); return 0; case CONS_CURSORTYPE: /* set cursor type (obsolete) */ s = spltty(); *(int *)data &= CONS_CURSOR_ATTRS; sc_change_cursor_shape(scp, *(int *)data, -1, -1); splx(s); return 0; case CONS_GETCURSORSHAPE: /* get cursor shape (new interface) */ if (((int *)data)[0] & CONS_LOCAL_CURSOR) { ((int *)data)[0] = scp->curr_curs_attr.flags; ((int *)data)[1] = scp->curr_curs_attr.base; ((int *)data)[2] = scp->curr_curs_attr.height; } else { ((int *)data)[0] = sc->curs_attr.flags; ((int *)data)[1] = sc->curs_attr.base; ((int *)data)[2] = sc->curs_attr.height; } return 0; case CONS_SETCURSORSHAPE: /* set cursor shape (new interface) */ s = spltty(); sc_change_cursor_shape(scp, ((int *)data)[0], ((int *)data)[1], ((int *)data)[2]); splx(s); return 0; case CONS_BELLTYPE: /* set bell type sound/visual */ if ((*(int *)data) & CONS_VISUAL_BELL) sc->flags |= SC_VISUAL_BELL; else sc->flags &= ~SC_VISUAL_BELL; if ((*(int *)data) & CONS_QUIET_BELL) sc->flags |= SC_QUIET_BELL; else sc->flags &= ~SC_QUIET_BELL; return 0; case CONS_GETINFO: /* get current (virtual) console info */ { vid_info_t *ptr = (vid_info_t*)data; if (ptr->size == sizeof(struct vid_info)) { ptr->m_num = sc->cur_scp->index; ptr->font_size = scp->font_size; ptr->mv_col = scp->xpos; ptr->mv_row = scp->ypos; ptr->mv_csz = scp->xsize; ptr->mv_rsz = scp->ysize; ptr->mv_hsz = (scp->history != NULL) ? scp->history->vtb_rows : 0; /* * The following fields are filled by the terminal emulator. XXX * * ptr->mv_norm.fore * ptr->mv_norm.back * ptr->mv_rev.fore * ptr->mv_rev.back */ ptr->mv_grfc.fore = 0; /* not supported */ ptr->mv_grfc.back = 0; /* not supported */ ptr->mv_ovscan = scp->border; if (scp == sc->cur_scp) save_kbd_state(scp); ptr->mk_keylock = scp->status & LOCK_MASK; return 0; } return EINVAL; } case CONS_GETVERS: /* get version number */ *(int*)data = 0x200; /* version 2.0 */ return 0; case CONS_IDLE: /* see if the screen has been idle */ /* * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE, * the user process may have been writing something on the * screen and syscons is not aware of it. Declare the screen * is NOT idle if it is in one of these modes. But there is * an exception to it; if a screen saver is running in the * graphics mode in the current screen, we should say that the * screen has been idle. */ *(int *)data = (sc->flags & SC_SCRN_IDLE) && (!ISGRAPHSC(sc->cur_scp) || (sc->cur_scp->status & SAVER_RUNNING)); return 0; case CONS_SAVERMODE: /* set saver mode */ switch(*(int *)data) { case CONS_NO_SAVER: case CONS_USR_SAVER: /* if a LKM screen saver is running, stop it first. */ scsplash_stick(FALSE); saver_mode = *(int *)data; s = spltty(); #ifdef DEV_SPLASH if ((error = wait_scrn_saver_stop(NULL))) { splx(s); return error; } #endif run_scrn_saver = TRUE; if (saver_mode == CONS_USR_SAVER) scp->status |= SAVER_RUNNING; else scp->status &= ~SAVER_RUNNING; scsplash_stick(TRUE); splx(s); break; case CONS_LKM_SAVER: s = spltty(); if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING)) scp->status &= ~SAVER_RUNNING; saver_mode = *(int *)data; splx(s); break; default: return EINVAL; } return 0; case CONS_SAVERSTART: /* immediately start/stop the screen saver */ /* * Note that this ioctl does not guarantee the screen saver * actually starts or stops. It merely attempts to do so... */ s = spltty(); run_scrn_saver = (*(int *)data != 0); if (run_scrn_saver) sc->scrn_time_stamp -= scrn_blank_time; splx(s); return 0; case CONS_SCRSHOT: /* get a screen shot */ { int retval, hist_rsz; size_t lsize, csize; vm_offset_t frbp, hstp; unsigned lnum; scrshot_t *ptr = (scrshot_t *)data; void *outp = ptr->buf; if (ptr->x < 0 || ptr->y < 0 || ptr->xsize < 0 || ptr->ysize < 0) return EINVAL; s = spltty(); if (ISGRAPHSC(scp)) { splx(s); return EOPNOTSUPP; } hist_rsz = (scp->history != NULL) ? scp->history->vtb_rows : 0; if (((u_int)ptr->x + ptr->xsize) > scp->xsize || ((u_int)ptr->y + ptr->ysize) > (scp->ysize + hist_rsz)) { splx(s); return EINVAL; } lsize = scp->xsize * sizeof(u_int16_t); csize = ptr->xsize * sizeof(u_int16_t); /* Pointer to the last line of framebuffer */ frbp = scp->vtb.vtb_buffer + scp->ysize * lsize + ptr->x * sizeof(u_int16_t); /* Pointer to the last line of target buffer */ outp = (char *)outp + ptr->ysize * csize; /* Pointer to the last line of history buffer */ if (scp->history != NULL) hstp = scp->history->vtb_buffer + sc_vtb_tail(scp->history) * sizeof(u_int16_t) + ptr->x * sizeof(u_int16_t); else hstp = 0; retval = 0; for (lnum = 0; lnum < (ptr->y + ptr->ysize); lnum++) { if (lnum < scp->ysize) { frbp -= lsize; } else { hstp -= lsize; if (hstp < scp->history->vtb_buffer) hstp += scp->history->vtb_rows * lsize; frbp = hstp; } if (lnum < ptr->y) continue; outp = (char *)outp - csize; retval = copyout((void *)frbp, outp, csize); if (retval != 0) break; } splx(s); return retval; } case VT_SETMODE: /* set screen switcher mode */ { struct vt_mode *mode; struct proc *p1; mode = (struct vt_mode *)data; DPRINTF(5, ("%s%d: VT_SETMODE ", SC_DRIVER_NAME, sc->unit)); if (scp->smode.mode == VT_PROCESS) { p1 = pfind(scp->pid); if (scp->proc == p1 && scp->proc != td->td_proc) { if (p1) PROC_UNLOCK(p1); DPRINTF(5, ("error EPERM\n")); return EPERM; } if (p1) PROC_UNLOCK(p1); } s = spltty(); if (mode->mode == VT_AUTO) { scp->smode.mode = VT_AUTO; scp->proc = NULL; scp->pid = 0; DPRINTF(5, ("VT_AUTO, ")); if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit)) cnavailable(sc_consptr, TRUE); /* were we in the middle of the vty switching process? */ if (finish_vt_rel(scp, TRUE, &s) == 0) DPRINTF(5, ("reset WAIT_REL, ")); if (finish_vt_acq(scp) == 0) DPRINTF(5, ("reset WAIT_ACQ, ")); } else { if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig) || !ISSIGVALID(mode->frsig)) { splx(s); DPRINTF(5, ("error EINVAL\n")); return EINVAL; } DPRINTF(5, ("VT_PROCESS %d, ", td->td_proc->p_pid)); bcopy(data, &scp->smode, sizeof(struct vt_mode)); scp->proc = td->td_proc; scp->pid = scp->proc->p_pid; if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit)) cnavailable(sc_consptr, FALSE); } splx(s); DPRINTF(5, ("\n")); return 0; } case VT_GETMODE: /* get screen switcher mode */ bcopy(&scp->smode, data, sizeof(struct vt_mode)); return 0; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('v', 4): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case VT_RELDISP: /* screen switcher ioctl */ s = spltty(); /* * This must be the current vty which is in the VT_PROCESS * switching mode... */ if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) { splx(s); return EINVAL; } /* ...and this process is controlling it. */ if (scp->proc != td->td_proc) { splx(s); return EPERM; } error = EINVAL; switch(*(int *)data) { case VT_FALSE: /* user refuses to release screen, abort */ if ((error = finish_vt_rel(scp, FALSE, &s)) == 0) DPRINTF(5, ("%s%d: VT_FALSE\n", SC_DRIVER_NAME, sc->unit)); break; case VT_TRUE: /* user has released screen, go on */ if ((error = finish_vt_rel(scp, TRUE, &s)) == 0) DPRINTF(5, ("%s%d: VT_TRUE\n", SC_DRIVER_NAME, sc->unit)); break; case VT_ACKACQ: /* acquire acknowledged, switch completed */ if ((error = finish_vt_acq(scp)) == 0) DPRINTF(5, ("%s%d: VT_ACKACQ\n", SC_DRIVER_NAME, sc->unit)); break; default: break; } splx(s); return error; case VT_OPENQRY: /* return free virtual console */ for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) { tp = VIRTUAL_TTY(sc, i); if (!ISTTYOPEN(tp)) { *(int *)data = i + 1; return 0; } } return EINVAL; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('v', 5): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case VT_ACTIVATE: /* switch to screen *data */ i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1); s = spltty(); error = sc_clean_up(sc->cur_scp); splx(s); if (error) return error; return sc_switch_scr(sc, i); #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('v', 6): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case VT_WAITACTIVE: /* wait for switch to occur */ i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1); if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys)) return EINVAL; s = spltty(); error = sc_clean_up(sc->cur_scp); splx(s); if (error) return error; scp = sc_get_stat(SC_DEV(sc, i)); if (scp == scp->sc->cur_scp) return 0; error = tsleep(&scp->smode, PZERO | PCATCH, "waitvt", 0); return error; case VT_GETACTIVE: /* get active vty # */ *(int *)data = sc->cur_scp->index + 1; return 0; case VT_GETINDEX: /* get this vty # */ *(int *)data = scp->index + 1; return 0; case VT_LOCKSWITCH: /* prevent vty switching */ if ((*(int *)data) & 0x01) sc->flags |= SC_SCRN_VTYLOCK; else sc->flags &= ~SC_SCRN_VTYLOCK; return 0; case KDENABIO: /* allow io operations */ error = priv_check(td, PRIV_IO); if (error != 0) return error; error = securelevel_gt(td->td_ucred, 0); if (error != 0) return error; #ifdef __i386__ td->td_frame->tf_eflags |= PSL_IOPL; #elif defined(__amd64__) td->td_frame->tf_rflags |= PSL_IOPL; #endif return 0; case KDDISABIO: /* disallow io operations (default) */ #ifdef __i386__ td->td_frame->tf_eflags &= ~PSL_IOPL; #elif defined(__amd64__) td->td_frame->tf_rflags &= ~PSL_IOPL; #endif return 0; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 20): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSKBSTATE: /* set keyboard state (locks) */ if (*(int *)data & ~LOCK_MASK) return EINVAL; scp->status &= ~LOCK_MASK; scp->status |= *(int *)data; if (scp == sc->cur_scp) update_kbd_state(scp, scp->status, LOCK_MASK); return 0; case KDGKBSTATE: /* get keyboard state (locks) */ if (scp == sc->cur_scp) save_kbd_state(scp); *(int *)data = scp->status & LOCK_MASK; return 0; case KDGETREPEAT: /* get keyboard repeat & delay rates */ case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */ error = kbdd_ioctl(sc->kbd, cmd, data); if (error == ENOIOCTL) error = ENODEV; return error; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 67): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSETRAD: /* set keyboard repeat & delay rates (old) */ if (*(int *)data & ~0x7f) return EINVAL; error = kbdd_ioctl(sc->kbd, KDSETRAD, data); if (error == ENOIOCTL) error = ENODEV; return error; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 7): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSKBMODE: /* set keyboard mode */ switch (*(int *)data) { case K_XLATE: /* switch to XLT ascii mode */ case K_RAW: /* switch to RAW scancode mode */ case K_CODE: /* switch to CODE mode */ scp->kbd_mode = *(int *)data; if (scp == sc->cur_scp) kbdd_ioctl(sc->kbd, KDSKBMODE, data); return 0; default: return EINVAL; } /* NOT REACHED */ case KDGKBMODE: /* get keyboard mode */ *(int *)data = scp->kbd_mode; return 0; case KDGKBINFO: error = kbdd_ioctl(sc->kbd, cmd, data); if (error == ENOIOCTL) error = ENODEV; return error; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 8): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDMKTONE: /* sound the bell */ if (*(int*)data) sc_bell(scp, (*(int*)data)&0xffff, (((*(int*)data)>>16)&0xffff)*hz/1000); else sc_bell(scp, scp->bell_pitch, scp->bell_duration); return 0; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 63): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KIOCSOUND: /* make tone (*data) hz */ if (scp == sc->cur_scp) { if (*(int *)data) return sc_tone(*(int *)data); else return sc_tone(0); } return 0; case KDGKBTYPE: /* get keyboard type */ error = kbdd_ioctl(sc->kbd, cmd, data); if (error == ENOIOCTL) { /* always return something? XXX */ *(int *)data = 0; } return 0; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 66): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSETLED: /* set keyboard LED status */ if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */ return EINVAL; scp->status &= ~LED_MASK; scp->status |= *(int *)data; if (scp == sc->cur_scp) update_kbd_leds(scp, scp->status); return 0; case KDGETLED: /* get keyboard LED status */ if (scp == sc->cur_scp) save_kbd_state(scp); *(int *)data = scp->status & LED_MASK; return 0; case KBADDKBD: /* add/remove keyboard to/from mux */ case KBRELKBD: error = kbdd_ioctl(sc->kbd, cmd, data); if (error == ENOIOCTL) error = ENODEV; return error; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('c', 110): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case CONS_SETKBD: /* set the new keyboard */ { keyboard_t *newkbd; s = spltty(); newkbd = kbd_get_keyboard(*(int *)data); if (newkbd == NULL) { splx(s); return EINVAL; } error = 0; if (sc->kbd != newkbd) { i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit, (void *)&sc->keyboard, sckbdevent, sc); /* i == newkbd->kb_index */ if (i >= 0) { if (sc->kbd != NULL) { save_kbd_state(sc->cur_scp); kbd_release(sc->kbd, (void *)&sc->keyboard); } sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */ sc->keyboard = i; kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&sc->cur_scp->kbd_mode); update_kbd_state(sc->cur_scp, sc->cur_scp->status, LOCK_MASK); } else { error = EPERM; /* XXX */ } } splx(s); return error; } case CONS_RELKBD: /* release the current keyboard */ s = spltty(); error = 0; if (sc->kbd != NULL) { save_kbd_state(sc->cur_scp); error = kbd_release(sc->kbd, (void *)&sc->keyboard); if (error == 0) { sc->kbd = NULL; sc->keyboard = -1; } } splx(s); return error; case CONS_GETTERM: /* get the current terminal emulator info */ { sc_term_sw_t *sw; if (((term_info_t *)data)->ti_index == 0) { sw = scp->tsw; } else { sw = sc_term_match_by_number(((term_info_t *)data)->ti_index); } if (sw != NULL) { strncpy(((term_info_t *)data)->ti_name, sw->te_name, sizeof(((term_info_t *)data)->ti_name)); strncpy(((term_info_t *)data)->ti_desc, sw->te_desc, sizeof(((term_info_t *)data)->ti_desc)); ((term_info_t *)data)->ti_flags = 0; return 0; } else { ((term_info_t *)data)->ti_name[0] = '\0'; ((term_info_t *)data)->ti_desc[0] = '\0'; ((term_info_t *)data)->ti_flags = 0; return EINVAL; } } case CONS_SETTERM: /* set the current terminal emulator */ s = spltty(); error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name); /* FIXME: what if scp == sc_console! XXX */ splx(s); return error; case GIO_SCRNMAP: /* get output translation table */ bcopy(&sc->scr_map, data, sizeof(sc->scr_map)); return 0; case PIO_SCRNMAP: /* set output translation table */ bcopy(data, &sc->scr_map, sizeof(sc->scr_map)); for (i=0; iscr_map); i++) { sc->scr_rmap[sc->scr_map[i]] = i; } return 0; case GIO_KEYMAP: /* get keyboard translation table */ case PIO_KEYMAP: /* set keyboard translation table */ case GIO_DEADKEYMAP: /* get accent key translation table */ case PIO_DEADKEYMAP: /* set accent key translation table */ case GETFKEY: /* get function key string */ case SETFKEY: /* set function key string */ error = kbdd_ioctl(sc->kbd, cmd, data); if (error == ENOIOCTL) error = ENODEV; return error; #ifndef SC_NO_FONT_LOADING case PIO_FONT8x8: /* set 8x8 dot font */ if (!ISFONTAVAIL(sc->adp->va_flags)) return ENXIO; bcopy(data, sc->font_8, 8*256); sc->fonts_loaded |= FONT_8; /* * FONT KLUDGE * Always use the font page #0. XXX * Don't load if the current font size is not 8x8. */ if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14)) sc_load_font(sc->cur_scp, 0, 8, 8, sc->font_8, 0, 256); return 0; case GIO_FONT8x8: /* get 8x8 dot font */ if (!ISFONTAVAIL(sc->adp->va_flags)) return ENXIO; if (sc->fonts_loaded & FONT_8) { bcopy(sc->font_8, data, 8*256); return 0; } else return ENXIO; case PIO_FONT8x14: /* set 8x14 dot font */ if (!ISFONTAVAIL(sc->adp->va_flags)) return ENXIO; bcopy(data, sc->font_14, 14*256); sc->fonts_loaded |= FONT_14; /* * FONT KLUDGE * Always use the font page #0. XXX * Don't load if the current font size is not 8x14. */ if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 14) && (sc->cur_scp->font_size < 16)) sc_load_font(sc->cur_scp, 0, 14, 8, sc->font_14, 0, 256); return 0; case GIO_FONT8x14: /* get 8x14 dot font */ if (!ISFONTAVAIL(sc->adp->va_flags)) return ENXIO; if (sc->fonts_loaded & FONT_14) { bcopy(sc->font_14, data, 14*256); return 0; } else return ENXIO; case PIO_FONT8x16: /* set 8x16 dot font */ if (!ISFONTAVAIL(sc->adp->va_flags)) return ENXIO; bcopy(data, sc->font_16, 16*256); sc->fonts_loaded |= FONT_16; /* * FONT KLUDGE * Always use the font page #0. XXX * Don't load if the current font size is not 8x16. */ if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16)) sc_load_font(sc->cur_scp, 0, 16, 8, sc->font_16, 0, 256); return 0; case GIO_FONT8x16: /* get 8x16 dot font */ if (!ISFONTAVAIL(sc->adp->va_flags)) return ENXIO; if (sc->fonts_loaded & FONT_16) { bcopy(sc->font_16, data, 16*256); return 0; } else return ENXIO; #endif /* SC_NO_FONT_LOADING */ default: break; } return (ttyioctl(dev, cmd, data, flag, td)); } static void scstart(struct tty *tp) { struct clist *rbp; int s, len; u_char buf[PCBURST]; scr_stat *scp = sc_get_stat(tp->t_dev); if (scp->status & SLKED || (scp == scp->sc->cur_scp && scp->sc->blink_in_progress)) return; s = spltty(); if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) { tp->t_state |= TS_BUSY; rbp = &tp->t_outq; while (rbp->c_cc) { len = q_to_b(rbp, buf, PCBURST); splx(s); sc_puts(scp, buf, len); s = spltty(); } tp->t_state &= ~TS_BUSY; ttwwakeup(tp); } splx(s); } static void sc_cnprobe(struct consdev *cp) { int unit; int flags; cp->cn_pri = sc_get_cons_priority(&unit, &flags); /* a video card is always required */ if (!scvidprobe(unit, flags, TRUE)) cp->cn_pri = CN_DEAD; /* syscons will become console even when there is no keyboard */ sckbdprobe(unit, flags, TRUE); if (cp->cn_pri == CN_DEAD) return; /* initialize required fields */ sprintf(cp->cn_name, "consolectl"); } static void sc_cninit(struct consdev *cp) { int unit; int flags; sc_get_cons_priority(&unit, &flags); scinit(unit, flags | SC_KERNEL_CONSOLE); sc_console_unit = unit; sc_console = sc_get_stat(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]); sc_consptr = cp; } static void sc_cnterm(struct consdev *cp) { /* we are not the kernel console any more, release everything */ if (sc_console_unit < 0) return; /* shouldn't happen */ #if 0 /* XXX */ sc_clear_screen(sc_console); sccnupdate(sc_console); #endif scterm(sc_console_unit, SC_KERNEL_CONSOLE); sc_console_unit = -1; sc_console = NULL; } static void sc_cnputc(struct consdev *cd, int c) { u_char buf[1]; scr_stat *scp = sc_console; void *save; #ifndef SC_NO_HISTORY struct tty *tp; #endif /* !SC_NO_HISTORY */ int s; /* assert(sc_console != NULL) */ #ifndef SC_NO_HISTORY if (scp == scp->sc->cur_scp && scp->status & SLKED) { scp->status &= ~SLKED; update_kbd_state(scp, scp->status, SLKED); if (scp->status & BUFFER_SAVED) { if (!sc_hist_restore(scp)) sc_remove_cutmarking(scp); scp->status &= ~BUFFER_SAVED; scp->status |= CURSOR_ENABLED; sc_draw_cursor_image(scp); } tp = VIRTUAL_TTY(scp->sc, scp->index); if (ISTTYOPEN(tp)) scstart(tp); } #endif /* !SC_NO_HISTORY */ save = scp->ts; if (kernel_console_ts != NULL) scp->ts = kernel_console_ts; buf[0] = c; sc_puts(scp, buf, 1); scp->ts = save; s = spltty(); /* block sckbdevent and scrn_timer */ sccnupdate(scp); splx(s); } static int sc_cngetc(struct consdev *cd) { return sccngetch(SCGETC_NONBLOCK); } static int sccngetch(int flags) { static struct fkeytab fkey; static int fkeycp; scr_stat *scp; u_char *p; int cur_mode; int s = spltty(); /* block sckbdevent and scrn_timer while we poll */ int c; /* assert(sc_console != NULL) */ /* * Stop the screen saver and update the screen if necessary. * What if we have been running in the screen saver code... XXX */ sc_touch_scrn_saver(); scp = sc_console->sc->cur_scp; /* XXX */ sccnupdate(scp); if (fkeycp < fkey.len) { splx(s); return fkey.str[fkeycp++]; } if (scp->sc->kbd == NULL) { splx(s); return -1; } /* * Make sure the keyboard is accessible even when the kbd device * driver is disabled. */ kbdd_enable(scp->sc->kbd); /* we shall always use the keyboard in the XLATE mode here */ cur_mode = scp->kbd_mode; scp->kbd_mode = K_XLATE; kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); kbdd_poll(scp->sc->kbd, TRUE); c = scgetc(scp->sc, SCGETC_CN | flags); kbdd_poll(scp->sc->kbd, FALSE); scp->kbd_mode = cur_mode; kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); kbdd_disable(scp->sc->kbd); splx(s); switch (KEYFLAGS(c)) { case 0: /* normal char */ return KEYCHAR(c); case FKEY: /* function key */ p = kbdd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp); fkey.len = fkeycp; if ((p != NULL) && (fkey.len > 0)) { bcopy(p, fkey.str, fkey.len); fkeycp = 1; return fkey.str[0]; } return c; /* XXX */ case NOKEY: case ERRKEY: default: return -1; } /* NOT REACHED */ } static void sccnupdate(scr_stat *scp) { /* this is a cut-down version of scrn_timer()... */ if (scp->sc->font_loading_in_progress) return; if (debugger > 0 || panicstr || shutdown_in_progress) { sc_touch_scrn_saver(); } else if (scp != scp->sc->cur_scp) { return; } if (!run_scrn_saver) scp->sc->flags &= ~SC_SCRN_IDLE; #ifdef DEV_SPLASH if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE)) if (scp->sc->flags & SC_SCRN_BLANKED) stop_scrn_saver(scp->sc, current_saver); #endif if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress || scp->sc->switch_in_progress) return; /* * FIXME: unlike scrn_timer(), we call scrn_update() from here even * when write_in_progress is non-zero. XXX */ if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED)) scrn_update(scp, TRUE); } static void scrn_timer(void *arg) { #ifndef PC98 static int kbd_interval = 0; #endif struct timeval tv; sc_softc_t *sc; scr_stat *scp; int again; int s; again = (arg != NULL); if (arg != NULL) sc = (sc_softc_t *)arg; else if (sc_console != NULL) sc = sc_console->sc; else return; /* don't do anything when we are performing some I/O operations */ if (sc->font_loading_in_progress) { if (again) timeout(scrn_timer, sc, hz / 10); return; } s = spltty(); #ifndef PC98 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) { /* try to allocate a keyboard automatically */ if (++kbd_interval >= 25) { sc->keyboard = sc_allocate_keyboard(sc, -1); if (sc->keyboard >= 0) { sc->kbd = kbd_get_keyboard(sc->keyboard); kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&sc->cur_scp->kbd_mode); update_kbd_state(sc->cur_scp, sc->cur_scp->status, LOCK_MASK); } kbd_interval = 0; } } #endif /* PC98 */ /* find the vty to update */ scp = sc->cur_scp; /* should we stop the screen saver? */ getmicrouptime(&tv); if (debugger > 0 || panicstr || shutdown_in_progress) sc_touch_scrn_saver(); if (run_scrn_saver) { if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time) sc->flags |= SC_SCRN_IDLE; else sc->flags &= ~SC_SCRN_IDLE; } else { sc->scrn_time_stamp = tv.tv_sec; sc->flags &= ~SC_SCRN_IDLE; if (scrn_blank_time > 0) run_scrn_saver = TRUE; } #ifdef DEV_SPLASH if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE)) if (sc->flags & SC_SCRN_BLANKED) stop_scrn_saver(sc, current_saver); #endif /* should we just return ? */ if (sc->blink_in_progress || sc->switch_in_progress || sc->write_in_progress) { if (again) timeout(scrn_timer, sc, hz / 10); splx(s); return; } /* Update the screen */ scp = sc->cur_scp; /* cur_scp may have changed... */ if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED)) scrn_update(scp, TRUE); #ifdef DEV_SPLASH /* should we activate the screen saver? */ if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE)) if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED)) (*current_saver)(sc, TRUE); #endif if (again) timeout(scrn_timer, sc, hz / 25); splx(s); } static int and_region(int *s1, int *e1, int s2, int e2) { if (*e1 < s2 || e2 < *s1) return FALSE; *s1 = imax(*s1, s2); *e1 = imin(*e1, e2); return TRUE; } static void scrn_update(scr_stat *scp, int show_cursor) { int start; int end; int s; int e; /* assert(scp == scp->sc->cur_scp) */ SC_VIDEO_LOCK(scp->sc); #ifndef SC_NO_CUTPASTE /* remove the previous mouse pointer image if necessary */ if (scp->status & MOUSE_VISIBLE) { s = scp->mouse_pos; e = scp->mouse_pos + scp->xsize + 1; if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN)) || and_region(&s, &e, scp->start, scp->end) || ((scp->status & CURSOR_ENABLED) && (scp->cursor_pos != scp->cursor_oldpos) && (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos) || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) { sc_remove_mouse_image(scp); if (scp->end >= scp->xsize*scp->ysize) scp->end = scp->xsize*scp->ysize - 1; } } #endif /* !SC_NO_CUTPASTE */ #if 1 /* debug: XXX */ if (scp->end >= scp->xsize*scp->ysize) { printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end); scp->end = scp->xsize*scp->ysize - 1; } if (scp->start < 0) { printf("scrn_update(): scp->start %d < 0\n", scp->start); scp->start = 0; } #endif /* update screen image */ if (scp->start <= scp->end) { if (scp->mouse_cut_end >= 0) { /* there is a marked region for cut & paste */ if (scp->mouse_cut_start <= scp->mouse_cut_end) { start = scp->mouse_cut_start; end = scp->mouse_cut_end; } else { start = scp->mouse_cut_end; end = scp->mouse_cut_start - 1; } s = start; e = end; /* does the cut-mark region overlap with the update region? */ if (and_region(&s, &e, scp->start, scp->end)) { (*scp->rndr->draw)(scp, s, e - s + 1, TRUE); s = 0; e = start - 1; if (and_region(&s, &e, scp->start, scp->end)) (*scp->rndr->draw)(scp, s, e - s + 1, FALSE); s = end + 1; e = scp->xsize*scp->ysize - 1; if (and_region(&s, &e, scp->start, scp->end)) (*scp->rndr->draw)(scp, s, e - s + 1, FALSE); } else { (*scp->rndr->draw)(scp, scp->start, scp->end - scp->start + 1, FALSE); } } else { (*scp->rndr->draw)(scp, scp->start, scp->end - scp->start + 1, FALSE); } } /* we are not to show the cursor and the mouse pointer... */ if (!show_cursor) { scp->end = 0; scp->start = scp->xsize*scp->ysize - 1; SC_VIDEO_UNLOCK(scp->sc); return; } /* update cursor image */ if (scp->status & CURSOR_ENABLED) { s = scp->start; e = scp->end; /* did cursor move since last time ? */ if (scp->cursor_pos != scp->cursor_oldpos) { /* do we need to remove old cursor image ? */ if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)) sc_remove_cursor_image(scp); sc_draw_cursor_image(scp); } else { if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)) /* cursor didn't move, but has been overwritten */ sc_draw_cursor_image(scp); else if (scp->curs_attr.flags & CONS_BLINK_CURSOR) /* if it's a blinking cursor, update it */ (*scp->rndr->blink_cursor)(scp, scp->cursor_pos, sc_inside_cutmark(scp, scp->cursor_pos)); } } #ifndef SC_NO_CUTPASTE /* update "pseudo" mouse pointer image */ if (scp->sc->flags & SC_MOUSE_ENABLED) { if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) { scp->status &= ~MOUSE_MOVED; sc_draw_mouse_image(scp); } } #endif /* SC_NO_CUTPASTE */ scp->end = 0; scp->start = scp->xsize*scp->ysize - 1; SC_VIDEO_UNLOCK(scp->sc); } #ifdef DEV_SPLASH static int scsplash_callback(int event, void *arg) { sc_softc_t *sc; int error; sc = (sc_softc_t *)arg; switch (event) { case SPLASH_INIT: if (add_scrn_saver(scsplash_saver) == 0) { sc->flags &= ~SC_SAVER_FAILED; run_scrn_saver = TRUE; if (cold && !(boothowto & RB_VERBOSE)) { scsplash_stick(TRUE); (*current_saver)(sc, TRUE); } } return 0; case SPLASH_TERM: if (current_saver == scsplash_saver) { scsplash_stick(FALSE); error = remove_scrn_saver(scsplash_saver); if (error) return error; } return 0; default: return EINVAL; } } static void scsplash_saver(sc_softc_t *sc, int show) { static int busy = FALSE; scr_stat *scp; if (busy) return; busy = TRUE; scp = sc->cur_scp; if (show) { if (!(sc->flags & SC_SAVER_FAILED)) { if (!(sc->flags & SC_SCRN_BLANKED)) set_scrn_saver_mode(scp, -1, NULL, 0); switch (splash(sc->adp, TRUE)) { case 0: /* succeeded */ break; case EAGAIN: /* try later */ restore_scrn_saver_mode(scp, FALSE); sc_touch_scrn_saver(); /* XXX */ break; default: sc->flags |= SC_SAVER_FAILED; scsplash_stick(FALSE); restore_scrn_saver_mode(scp, TRUE); printf("scsplash_saver(): failed to put up the image\n"); break; } } } else if (!sticky_splash) { if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0)) restore_scrn_saver_mode(scp, TRUE); } busy = FALSE; } static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int)) { #if 0 int error; if (current_saver != none_saver) { error = remove_scrn_saver(current_saver); if (error) return error; } #endif if (current_saver != none_saver) return EBUSY; run_scrn_saver = FALSE; saver_mode = CONS_LKM_SAVER; current_saver = this_saver; return 0; } static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int)) { if (current_saver != this_saver) return EINVAL; #if 0 /* * In order to prevent `current_saver' from being called by * the timeout routine `scrn_timer()' while we manipulate * the saver list, we shall set `current_saver' to `none_saver' * before stopping the current saver, rather than blocking by `splXX()'. */ current_saver = none_saver; if (scrn_blanked) stop_scrn_saver(this_saver); #endif /* unblank all blanked screens */ wait_scrn_saver_stop(NULL); if (scrn_blanked) return EBUSY; current_saver = none_saver; return 0; } static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border) { int s; /* assert(scp == scp->sc->cur_scp) */ s = spltty(); if (!ISGRAPHSC(scp)) sc_remove_cursor_image(scp); scp->splash_save_mode = scp->mode; scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE); scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE); scp->status |= (UNKNOWN_MODE | SAVER_RUNNING); scp->sc->flags |= SC_SCRN_BLANKED; ++scrn_blanked; splx(s); if (mode < 0) return 0; scp->mode = mode; if (set_mode(scp) == 0) { if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS) scp->status |= GRAPHICS_MODE; #ifndef SC_NO_PALETTE_LOADING if (pal != NULL) - load_palette(scp->sc->adp, pal); + vidd_load_palette(scp->sc->adp, pal); #endif sc_set_border(scp, border); return 0; } else { s = spltty(); scp->mode = scp->splash_save_mode; scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING); scp->status |= scp->splash_save_status; splx(s); return 1; } } static int restore_scrn_saver_mode(scr_stat *scp, int changemode) { int mode; int status; int s; /* assert(scp == scp->sc->cur_scp) */ s = spltty(); mode = scp->mode; status = scp->status; scp->mode = scp->splash_save_mode; scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING); scp->status |= scp->splash_save_status; scp->sc->flags &= ~SC_SCRN_BLANKED; if (!changemode) { if (!ISGRAPHSC(scp)) sc_draw_cursor_image(scp); --scrn_blanked; splx(s); return 0; } if (set_mode(scp) == 0) { #ifndef SC_NO_PALETTE_LOADING - load_palette(scp->sc->adp, scp->sc->palette); + vidd_load_palette(scp->sc->adp, scp->sc->palette); #endif --scrn_blanked; splx(s); return 0; } else { scp->mode = mode; scp->status = status; splx(s); return 1; } } static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int)) { (*saver)(sc, FALSE); run_scrn_saver = FALSE; /* the screen saver may have chosen not to stop after all... */ if (sc->flags & SC_SCRN_BLANKED) return; mark_all(sc->cur_scp); if (sc->delayed_next_scr) sc_switch_scr(sc, sc->delayed_next_scr - 1); if (debugger == 0) wakeup(&scrn_blanked); } static int wait_scrn_saver_stop(sc_softc_t *sc) { int error = 0; while (scrn_blanked > 0) { run_scrn_saver = FALSE; if (sc && !(sc->flags & SC_SCRN_BLANKED)) { error = 0; break; } error = tsleep(&scrn_blanked, PZERO | PCATCH, "scrsav", 0); if ((error != 0) && (error != ERESTART)) break; } run_scrn_saver = FALSE; return error; } #endif /* DEV_SPLASH */ void sc_touch_scrn_saver(void) { scsplash_stick(FALSE); run_scrn_saver = FALSE; } int sc_switch_scr(sc_softc_t *sc, u_int next_scr) { scr_stat *cur_scp; struct tty *tp; struct proc *p; int s; DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1)); if (sc->cur_scp == NULL) return (0); /* prevent switch if previously requested */ if (sc->flags & SC_SCRN_VTYLOCK) { sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch, sc->cur_scp->bell_duration); return EPERM; } /* delay switch if the screen is blanked or being updated */ if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress || sc->blink_in_progress) { sc->delayed_next_scr = next_scr + 1; sc_touch_scrn_saver(); DPRINTF(5, ("switch delayed\n")); return 0; } sc->delayed_next_scr = 0; s = spltty(); cur_scp = sc->cur_scp; /* we are in the middle of the vty switching process... */ if (sc->switch_in_progress && (cur_scp->smode.mode == VT_PROCESS) && cur_scp->proc) { p = pfind(cur_scp->pid); if (cur_scp->proc != p) { if (p) PROC_UNLOCK(p); /* * The controlling process has died!!. Do some clean up. * NOTE:`cur_scp->proc' and `cur_scp->smode.mode' * are not reset here yet; they will be cleared later. */ DPRINTF(5, ("cur_scp controlling process %d died, ", cur_scp->pid)); if (cur_scp->status & SWITCH_WAIT_REL) { /* * Force the previous switch to finish, but return now * with error. */ DPRINTF(5, ("reset WAIT_REL, ")); finish_vt_rel(cur_scp, TRUE, &s); splx(s); DPRINTF(5, ("finishing previous switch\n")); return EINVAL; } else if (cur_scp->status & SWITCH_WAIT_ACQ) { /* let's assume screen switch has been completed. */ DPRINTF(5, ("reset WAIT_ACQ, ")); finish_vt_acq(cur_scp); } else { /* * We are in between screen release and acquisition, and * reached here via scgetc() or scrn_timer() which has * interrupted exchange_scr(). Don't do anything stupid. */ DPRINTF(5, ("waiting nothing, ")); } } else { if (p) PROC_UNLOCK(p); /* * The controlling process is alive, but not responding... * It is either buggy or it may be just taking time. * The following code is a gross kludge to cope with this * problem for which there is no clean solution. XXX */ if (cur_scp->status & SWITCH_WAIT_REL) { switch (sc->switch_in_progress++) { case 1: break; case 2: DPRINTF(5, ("sending relsig again, ")); signal_vt_rel(cur_scp); break; case 3: break; case 4: default: /* * Act as if the controlling program returned * VT_FALSE. */ DPRINTF(5, ("force reset WAIT_REL, ")); finish_vt_rel(cur_scp, FALSE, &s); splx(s); DPRINTF(5, ("act as if VT_FALSE was seen\n")); return EINVAL; } } else if (cur_scp->status & SWITCH_WAIT_ACQ) { switch (sc->switch_in_progress++) { case 1: break; case 2: DPRINTF(5, ("sending acqsig again, ")); signal_vt_acq(cur_scp); break; case 3: break; case 4: default: /* clear the flag and finish the previous switch */ DPRINTF(5, ("force reset WAIT_ACQ, ")); finish_vt_acq(cur_scp); break; } } } } /* * Return error if an invalid argument is given, or vty switch * is still in progress. */ if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys) || sc->switch_in_progress) { splx(s); sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION); DPRINTF(5, ("error 1\n")); return EINVAL; } /* * Don't allow switching away from the graphics mode vty * if the switch mode is VT_AUTO, unless the next vty is the same * as the current or the current vty has been closed (but showing). */ tp = VIRTUAL_TTY(sc, cur_scp->index); if ((cur_scp->index != next_scr) && ISTTYOPEN(tp) && (cur_scp->smode.mode == VT_AUTO) && ISGRAPHSC(cur_scp)) { splx(s); sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION); DPRINTF(5, ("error, graphics mode\n")); return EINVAL; } /* * Is the wanted vty open? Don't allow switching to a closed vty. * If we are in DDB, don't switch to a vty in the VT_PROCESS mode. * Note that we always allow the user to switch to the kernel * console even if it is closed. */ if ((sc_console == NULL) || (next_scr != sc_console->index)) { tp = VIRTUAL_TTY(sc, next_scr); if (!ISTTYOPEN(tp)) { splx(s); sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION); DPRINTF(5, ("error 2, requested vty isn't open!\n")); return EINVAL; } if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) { splx(s); DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n")); return EINVAL; } } /* this is the start of vty switching process... */ ++sc->switch_in_progress; sc->old_scp = cur_scp; sc->new_scp = sc_get_stat(SC_DEV(sc, next_scr)); if (sc->new_scp == sc->old_scp) { sc->switch_in_progress = 0; /* * XXX wakeup() locks the scheduler lock which will hang if * the lock is in an in-between state, e.g., when we stop at * a breakpoint at fork_exit. It has always been wrong to call * wakeup() when the debugger is active. In RELENG_4, wakeup() * is supposed to be locked by splhigh(), but the debugger may * be invoked at splhigh(). */ if (debugger == 0) wakeup(&sc->new_scp->smode); splx(s); DPRINTF(5, ("switch done (new == old)\n")); return 0; } /* has controlling process died? */ vt_proc_alive(sc->old_scp); vt_proc_alive(sc->new_scp); /* wait for the controlling process to release the screen, if necessary */ if (signal_vt_rel(sc->old_scp)) { splx(s); return 0; } /* go set up the new vty screen */ splx(s); exchange_scr(sc); s = spltty(); /* wake up processes waiting for this vty */ if (debugger == 0) wakeup(&sc->cur_scp->smode); /* wait for the controlling process to acknowledge, if necessary */ if (signal_vt_acq(sc->cur_scp)) { splx(s); return 0; } sc->switch_in_progress = 0; if (sc->unit == sc_console_unit) cnavailable(sc_consptr, TRUE); splx(s); DPRINTF(5, ("switch done\n")); return 0; } static int do_switch_scr(sc_softc_t *sc, int s) { vt_proc_alive(sc->new_scp); splx(s); exchange_scr(sc); s = spltty(); /* sc->cur_scp == sc->new_scp */ wakeup(&sc->cur_scp->smode); /* wait for the controlling process to acknowledge, if necessary */ if (!signal_vt_acq(sc->cur_scp)) { sc->switch_in_progress = 0; if (sc->unit == sc_console_unit) cnavailable(sc_consptr, TRUE); } return s; } static int vt_proc_alive(scr_stat *scp) { struct proc *p; if (scp->proc) { if ((p = pfind(scp->pid)) != NULL) PROC_UNLOCK(p); if (scp->proc == p) return TRUE; scp->proc = NULL; scp->smode.mode = VT_AUTO; DPRINTF(5, ("vt controlling process %d died\n", scp->pid)); } return FALSE; } static int signal_vt_rel(scr_stat *scp) { if (scp->smode.mode != VT_PROCESS) return FALSE; scp->status |= SWITCH_WAIT_REL; PROC_LOCK(scp->proc); psignal(scp->proc, scp->smode.relsig); PROC_UNLOCK(scp->proc); DPRINTF(5, ("sending relsig to %d\n", scp->pid)); return TRUE; } static int signal_vt_acq(scr_stat *scp) { if (scp->smode.mode != VT_PROCESS) return FALSE; if (scp->sc->unit == sc_console_unit) cnavailable(sc_consptr, FALSE); scp->status |= SWITCH_WAIT_ACQ; PROC_LOCK(scp->proc); psignal(scp->proc, scp->smode.acqsig); PROC_UNLOCK(scp->proc); DPRINTF(5, ("sending acqsig to %d\n", scp->pid)); return TRUE; } static int finish_vt_rel(scr_stat *scp, int release, int *s) { if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) { scp->status &= ~SWITCH_WAIT_REL; if (release) *s = do_switch_scr(scp->sc, *s); else scp->sc->switch_in_progress = 0; return 0; } return EINVAL; } static int finish_vt_acq(scr_stat *scp) { if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) { scp->status &= ~SWITCH_WAIT_ACQ; scp->sc->switch_in_progress = 0; return 0; } return EINVAL; } static void exchange_scr(sc_softc_t *sc) { scr_stat *scp; /* save the current state of video and keyboard */ sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos); if (!ISGRAPHSC(sc->old_scp)) sc_remove_cursor_image(sc->old_scp); if (sc->old_scp->kbd_mode == K_XLATE) save_kbd_state(sc->old_scp); /* set up the video for the new screen */ scp = sc->cur_scp = sc->new_scp; #ifdef PC98 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp) || ISUNKNOWNSC(sc->new_scp)) #else if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp)) #endif set_mode(scp); #ifndef __sparc64__ else sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize, (void *)sc->adp->va_window, FALSE); #endif scp->status |= MOUSE_HIDDEN; sc_move_cursor(scp, scp->xpos, scp->ypos); if (!ISGRAPHSC(scp)) sc_set_cursor_image(scp); #ifndef SC_NO_PALETTE_LOADING if (ISGRAPHSC(sc->old_scp)) - load_palette(sc->adp, sc->palette); + vidd_load_palette(sc->adp, sc->palette); #endif sc_set_border(scp, scp->border); /* set up the keyboard for the new screen */ if (sc->old_scp->kbd_mode != scp->kbd_mode) kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode); update_kbd_state(scp, scp->status, LOCK_MASK); mark_all(scp); } void sc_puts(scr_stat *scp, u_char *buf, int len) { int need_unlock = 0; #ifdef DEV_SPLASH /* make screensaver happy */ if (!sticky_splash && scp == scp->sc->cur_scp && !sc_saver_keyb_only) run_scrn_saver = FALSE; #endif if (scp->tsw) { if (!kdb_active && !mtx_owned(&scp->scr_lock)) { need_unlock = 1; mtx_lock_spin(&scp->scr_lock); } (*scp->tsw->te_puts)(scp, buf, len); if (need_unlock) mtx_unlock_spin(&scp->scr_lock); } if (scp->sc->delayed_next_scr) sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1); } void sc_draw_cursor_image(scr_stat *scp) { /* assert(scp == scp->sc->cur_scp); */ SC_VIDEO_LOCK(scp->sc); (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, scp->curs_attr.flags & CONS_BLINK_CURSOR, TRUE, sc_inside_cutmark(scp, scp->cursor_pos)); scp->cursor_oldpos = scp->cursor_pos; SC_VIDEO_UNLOCK(scp->sc); } void sc_remove_cursor_image(scr_stat *scp) { /* assert(scp == scp->sc->cur_scp); */ SC_VIDEO_LOCK(scp->sc); (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, scp->curs_attr.flags & CONS_BLINK_CURSOR, FALSE, sc_inside_cutmark(scp, scp->cursor_oldpos)); SC_VIDEO_UNLOCK(scp->sc); } static void update_cursor_image(scr_stat *scp) { /* assert(scp == scp->sc->cur_scp); */ sc_remove_cursor_image(scp); sc_set_cursor_image(scp); sc_draw_cursor_image(scp); } void sc_set_cursor_image(scr_stat *scp) { scp->curs_attr.flags = scp->curr_curs_attr.flags; if (scp->curs_attr.flags & CONS_HIDDEN_CURSOR) { /* hidden cursor is internally represented as zero-height underline */ scp->curs_attr.flags = CONS_CHAR_CURSOR; scp->curs_attr.base = scp->curs_attr.height = 0; } else if (scp->curs_attr.flags & CONS_CHAR_CURSOR) { scp->curs_attr.base = imin(scp->curr_curs_attr.base, scp->font_size - 1); scp->curs_attr.height = imin(scp->curr_curs_attr.height, scp->font_size - scp->curs_attr.base); } else { /* block cursor */ scp->curs_attr.base = 0; scp->curs_attr.height = scp->font_size; } /* assert(scp == scp->sc->cur_scp); */ SC_VIDEO_LOCK(scp->sc); (*scp->rndr->set_cursor)(scp, scp->curs_attr.base, scp->curs_attr.height, scp->curs_attr.flags & CONS_BLINK_CURSOR); SC_VIDEO_UNLOCK(scp->sc); } static void change_cursor_shape(scr_stat *scp, int flags, int base, int height) { if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) sc_remove_cursor_image(scp); if (base >= 0) scp->curr_curs_attr.base = base; if (height >= 0) scp->curr_curs_attr.height = height; if (flags & CONS_RESET_CURSOR) scp->curr_curs_attr = scp->dflt_curs_attr; else scp->curr_curs_attr.flags = flags & CONS_CURSOR_ATTRS; if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) { sc_set_cursor_image(scp); sc_draw_cursor_image(scp); } } void sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height) { sc_softc_t *sc; struct cdev *dev; int s; int i; s = spltty(); if ((flags != -1) && (flags & CONS_LOCAL_CURSOR)) { /* local (per vty) change */ change_cursor_shape(scp, flags, base, height); splx(s); return; } /* global change */ sc = scp->sc; if (base >= 0) sc->curs_attr.base = base; if (height >= 0) sc->curs_attr.height = height; if (flags != -1) { if (flags & CONS_RESET_CURSOR) sc->curs_attr = sc->dflt_curs_attr; else sc->curs_attr.flags = flags & CONS_CURSOR_ATTRS; } for (i = sc->first_vty; i < sc->first_vty + sc->vtys; ++i) { if ((dev = SC_DEV(sc, i)) == NULL) continue; if ((scp = sc_get_stat(dev)) == NULL) continue; scp->dflt_curs_attr = sc->curs_attr; change_cursor_shape(scp, CONS_RESET_CURSOR, -1, -1); } splx(s); } static void scinit(int unit, int flags) { /* * When syscons is being initialized as the kernel console, malloc() * is not yet functional, because various kernel structures has not been * fully initialized yet. Therefore, we need to declare the following * static buffers for the console. This is less than ideal, * but is necessry evil for the time being. XXX */ #ifdef PC98 static u_short sc_buffer[ROW*COL*2];/* XXX */ #else static u_short sc_buffer[ROW*COL]; /* XXX */ #endif #ifndef SC_NO_FONT_LOADING static u_char font_8[256*8]; static u_char font_14[256*14]; static u_char font_16[256*16]; #endif sc_softc_t *sc; scr_stat *scp; video_adapter_t *adp; int col; int row; int i; /* one time initialization */ if (init_done == COLD) sc_get_bios_values(&bios_value); init_done = WARM; /* * Allocate resources. Even if we are being called for the second * time, we must allocate them again, because they might have * disappeared... */ sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE); if ((sc->flags & SC_INIT_DONE) == 0) SC_VIDEO_LOCKINIT(sc); adp = NULL; if (sc->adapter >= 0) { vid_release(sc->adp, (void *)&sc->adapter); adp = sc->adp; sc->adp = NULL; } if (sc->keyboard >= 0) { DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard)); i = kbd_release(sc->kbd, (void *)&sc->keyboard); DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i)); if (sc->kbd != NULL) { DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n", unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags)); } sc->kbd = NULL; } sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter); sc->adp = vid_get_adapter(sc->adapter); /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */ sc->keyboard = sc_allocate_keyboard(sc, unit); DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard)); sc->kbd = kbd_get_keyboard(sc->keyboard); if (sc->kbd != NULL) { DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n", unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags)); } if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) { sc->initial_mode = sc->adp->va_initial_mode; #ifndef SC_NO_FONT_LOADING if (flags & SC_KERNEL_CONSOLE) { sc->font_8 = font_8; sc->font_14 = font_14; sc->font_16 = font_16; } else if (sc->font_8 == NULL) { /* assert(sc_malloc) */ sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK); sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK); sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK); } #endif /* extract the hardware cursor location and hide the cursor for now */ - (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row); - (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1); + vidd_read_hw_cursor(sc->adp, &col, &row); + vidd_set_hw_cursor(sc->adp, -1, -1); /* set up the first console */ sc->first_vty = unit*MAXCONS; sc->vtys = MAXCONS; /* XXX: should be configurable */ if (flags & SC_KERNEL_CONSOLE) { /* * Set up devs structure but don't use it yet, calling make_dev() * might panic kernel. Wait for sc_attach_unit() to actually * create the devices. */ sc->dev = main_devs; scp = &main_console; init_scp(sc, sc->first_vty, scp); sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize, (void *)sc_buffer, FALSE); if (sc_init_emulator(scp, SC_DFLT_TERM)) sc_init_emulator(scp, "*"); (*scp->tsw->te_default_attr)(scp, kernel_default.std_color, kernel_default.rev_color); } else { /* assert(sc_malloc) */ sc->dev = malloc(sizeof(struct cdev *)*sc->vtys, M_DEVBUF, M_WAITOK|M_ZERO); sc->dev[0] = make_dev(&sc_cdevsw, unit * MAXCONS, UID_ROOT, GID_WHEEL, 0600, "ttyv%r", unit * MAXCONS); sc_alloc_tty(sc->dev[0]); scp = alloc_scp(sc, sc->first_vty); SC_STAT(sc->dev[0]) = scp; } sc->cur_scp = scp; #ifndef __sparc64__ /* copy screen to temporary buffer */ sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize, (void *)scp->sc->adp->va_window, FALSE); if (ISTEXTSC(scp)) sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize); #endif /* move cursors to the initial positions */ if (col >= scp->xsize) col = 0; if (row >= scp->ysize) row = scp->ysize - 1; scp->xpos = col; scp->ypos = row; scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col; if (bios_value.cursor_end < scp->font_size) sc->dflt_curs_attr.base = scp->font_size - bios_value.cursor_end - 1; else sc->dflt_curs_attr.base = 0; i = bios_value.cursor_end - bios_value.cursor_start + 1; sc->dflt_curs_attr.height = imin(i, scp->font_size); sc->dflt_curs_attr.flags = 0; sc->curs_attr = sc->dflt_curs_attr; scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr; #ifndef SC_NO_SYSMOUSE sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2); #endif if (!ISGRAPHSC(scp)) { sc_set_cursor_image(scp); sc_draw_cursor_image(scp); } /* save font and palette */ #ifndef SC_NO_FONT_LOADING sc->fonts_loaded = 0; if (ISFONTAVAIL(sc->adp->va_flags)) { #ifdef SC_DFLT_FONT bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8)); bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14)); bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16)); sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8; if (scp->font_size < 14) { sc_load_font(scp, 0, 8, 8, sc->font_8, 0, 256); } else if (scp->font_size >= 16) { sc_load_font(scp, 0, 16, 8, sc->font_16, 0, 256); } else { sc_load_font(scp, 0, 14, 8, sc->font_14, 0, 256); } #else /* !SC_DFLT_FONT */ if (scp->font_size < 14) { sc_save_font(scp, 0, 8, 8, sc->font_8, 0, 256); sc->fonts_loaded = FONT_8; } else if (scp->font_size >= 16) { sc_save_font(scp, 0, 16, 8, sc->font_16, 0, 256); sc->fonts_loaded = FONT_16; } else { sc_save_font(scp, 0, 14, 8, sc->font_14, 0, 256); sc->fonts_loaded = FONT_14; } #endif /* SC_DFLT_FONT */ /* FONT KLUDGE: always use the font page #0. XXX */ sc_show_font(scp, 0); } #endif /* !SC_NO_FONT_LOADING */ #ifndef SC_NO_PALETTE_LOADING - save_palette(sc->adp, sc->palette); + vidd_save_palette(sc->adp, sc->palette); #endif #ifdef DEV_SPLASH if (!(sc->flags & SC_SPLASH_SCRN)) { /* we are ready to put up the splash image! */ splash_init(sc->adp, scsplash_callback, sc); sc->flags |= SC_SPLASH_SCRN; } #endif } /* the rest is not necessary, if we have done it once */ if (sc->flags & SC_INIT_DONE) return; /* initialize mapscrn arrays to a one to one map */ for (i = 0; i < sizeof(sc->scr_map); i++) sc->scr_map[i] = sc->scr_rmap[i] = i; #ifdef PC98 sc->scr_map[0x5c] = (u_char)0xfc; /* for backslash */ #endif sc->flags |= SC_INIT_DONE; } static void scterm(int unit, int flags) { sc_softc_t *sc; scr_stat *scp; sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE); if (sc == NULL) return; /* shouldn't happen */ #ifdef DEV_SPLASH /* this console is no longer available for the splash screen */ if (sc->flags & SC_SPLASH_SCRN) { splash_term(sc->adp); sc->flags &= ~SC_SPLASH_SCRN; } #endif #if 0 /* XXX */ /* move the hardware cursor to the upper-left corner */ - (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0); + vidd_set_hw_cursor(sc->adp, 0, 0); #endif /* release the keyboard and the video card */ if (sc->keyboard >= 0) kbd_release(sc->kbd, &sc->keyboard); if (sc->adapter >= 0) vid_release(sc->adp, &sc->adapter); /* stop the terminal emulator, if any */ scp = sc_get_stat(sc->dev[0]); if (scp->tsw) (*scp->tsw->te_term)(scp, &scp->ts); if (scp->ts != NULL) free(scp->ts, M_DEVBUF); mtx_destroy(&scp->scr_lock); /* clear the structure */ if (!(flags & SC_KERNEL_CONSOLE)) { /* XXX: We need delete_dev() for this */ free(sc->dev, M_DEVBUF); #if 0 /* XXX: We need a ttyunregister for this */ free(sc->tty, M_DEVBUF); #endif #ifndef SC_NO_FONT_LOADING free(sc->font_8, M_DEVBUF); free(sc->font_14, M_DEVBUF); free(sc->font_16, M_DEVBUF); #endif /* XXX vtb, history */ } bzero(sc, sizeof(*sc)); sc->keyboard = -1; sc->adapter = -1; } static void scshutdown(void *arg, int howto) { /* assert(sc_console != NULL) */ sc_touch_scrn_saver(); if (!cold && sc_console && sc_console->sc->cur_scp->smode.mode == VT_AUTO && sc_console->smode.mode == VT_AUTO) sc_switch_scr(sc_console->sc, sc_console->index); shutdown_in_progress = TRUE; } int sc_clean_up(scr_stat *scp) { #ifdef DEV_SPLASH int error; #endif if (scp->sc->flags & SC_SCRN_BLANKED) { sc_touch_scrn_saver(); #ifdef DEV_SPLASH if ((error = wait_scrn_saver_stop(scp->sc))) return error; #endif } scp->status |= MOUSE_HIDDEN; sc_remove_mouse_image(scp); sc_remove_cutmarking(scp); return 0; } void sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard) { sc_vtb_t new; sc_vtb_t old; old = scp->vtb; sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait); if (!discard && (old.vtb_flags & VTB_VALID)) { /* retain the current cursor position and buffer contants */ scp->cursor_oldpos = scp->cursor_pos; /* * This works only if the old buffer has the same size as or larger * than the new one. XXX */ sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize); scp->vtb = new; } else { scp->vtb = new; sc_vtb_destroy(&old); } #ifndef SC_NO_SYSMOUSE /* move the mouse cursor at the center of the screen */ sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2); #endif } static scr_stat *alloc_scp(sc_softc_t *sc, int vty) { scr_stat *scp; /* assert(sc_malloc) */ scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK); init_scp(sc, vty, scp); sc_alloc_scr_buffer(scp, TRUE, TRUE); if (sc_init_emulator(scp, SC_DFLT_TERM)) sc_init_emulator(scp, "*"); #ifndef SC_NO_CUTPASTE sc_alloc_cut_buffer(scp, TRUE); #endif #ifndef SC_NO_HISTORY sc_alloc_history_buffer(scp, 0, 0, TRUE); #endif return scp; } static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp) { video_info_t info; bzero(scp, sizeof(*scp)); scp->index = vty; scp->sc = sc; scp->status = 0; scp->mode = sc->initial_mode; - (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info); + vidd_get_info(sc->adp, scp->mode, &info); if (info.vi_flags & V_INFO_GRAPHICS) { scp->status |= GRAPHICS_MODE; scp->xpixel = info.vi_width; scp->ypixel = info.vi_height; scp->xsize = info.vi_width/info.vi_cwidth; scp->ysize = info.vi_height/info.vi_cheight; scp->font_size = 0; scp->font = NULL; } else { scp->xsize = info.vi_width; scp->ysize = info.vi_height; scp->xpixel = scp->xsize*info.vi_cwidth; scp->ypixel = scp->ysize*info.vi_cheight; scp->font_size = info.vi_cheight; scp->font_width = info.vi_cwidth; if (info.vi_cheight < 14) { #ifndef SC_NO_FONT_LOADING scp->font = sc->font_8; #else scp->font = NULL; #endif } else if (info.vi_cheight >= 16) { #ifndef SC_NO_FONT_LOADING scp->font = sc->font_16; #else scp->font = NULL; #endif } else { #ifndef SC_NO_FONT_LOADING scp->font = sc->font_14; #else scp->font = NULL; #endif } } sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE); #ifndef __sparc64__ sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE); #endif scp->xoff = scp->yoff = 0; scp->xpos = scp->ypos = 0; scp->start = scp->xsize * scp->ysize - 1; scp->end = 0; scp->tsw = NULL; scp->ts = NULL; scp->rndr = NULL; scp->border = (SC_NORM_ATTR >> 4) & 0x0f; scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr; scp->mouse_cut_start = scp->xsize*scp->ysize; scp->mouse_cut_end = -1; scp->mouse_signal = 0; scp->mouse_pid = 0; scp->mouse_proc = NULL; scp->kbd_mode = K_XLATE; scp->bell_pitch = bios_value.bell_pitch; scp->bell_duration = BELL_DURATION; scp->status |= (bios_value.shift_state & NLKED); scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN; scp->pid = 0; scp->proc = NULL; scp->smode.mode = VT_AUTO; scp->history = NULL; scp->history_pos = 0; scp->history_size = 0; mtx_init(&scp->scr_lock, "scrlock", NULL, MTX_SPIN); } int sc_init_emulator(scr_stat *scp, char *name) { sc_term_sw_t *sw; sc_rndr_sw_t *rndr; void *p; int error; if (name == NULL) /* if no name is given, use the current emulator */ sw = scp->tsw; else /* ...otherwise find the named emulator */ sw = sc_term_match(name); if (sw == NULL) return EINVAL; rndr = NULL; if (strcmp(sw->te_renderer, "*") != 0) { rndr = sc_render_match(scp, sw->te_renderer, scp->status & (GRAPHICS_MODE | PIXEL_MODE)); } if (rndr == NULL) { rndr = sc_render_match(scp, scp->sc->adp->va_name, scp->status & (GRAPHICS_MODE | PIXEL_MODE)); if (rndr == NULL) return ENODEV; } if (sw == scp->tsw) { error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT); scp->rndr = rndr; scp->rndr->init(scp); sc_clear_screen(scp); /* assert(error == 0); */ return error; } if (sc_malloc && (sw->te_size > 0)) p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT); else p = NULL; error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT); if (error) return error; if (scp->tsw) (*scp->tsw->te_term)(scp, &scp->ts); if (scp->ts != NULL) free(scp->ts, M_DEVBUF); scp->tsw = sw; scp->ts = p; scp->rndr = rndr; scp->rndr->init(scp); /* XXX */ (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color); sc_clear_screen(scp); return 0; } /* * scgetc(flags) - get character from keyboard. * If flags & SCGETC_CN, then avoid harmful side effects. * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else * return NOKEY if there is nothing there. */ static u_int scgetc(sc_softc_t *sc, u_int flags) { scr_stat *scp; #ifndef SC_NO_HISTORY struct tty *tp; #endif u_int c; int this_scr; int f; int i; if (sc->kbd == NULL) return NOKEY; next_code: #if 1 /* I don't like this, but... XXX */ if (flags & SCGETC_CN) sccnupdate(sc->cur_scp); #endif scp = sc->cur_scp; /* first see if there is something in the keyboard port */ for (;;) { c = kbdd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK)); if (c == ERRKEY) { if (!(flags & SCGETC_CN)) sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); } else if (c == NOKEY) return c; else break; } /* make screensaver happy */ if (!(c & RELKEY)) sc_touch_scrn_saver(); if (!(flags & SCGETC_CN)) random_harvest(&c, sizeof(c), 1, 0, RANDOM_KEYBOARD); if (scp->kbd_mode != K_XLATE) return KEYCHAR(c); /* if scroll-lock pressed allow history browsing */ if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) { scp->status &= ~CURSOR_ENABLED; sc_remove_cursor_image(scp); #ifndef SC_NO_HISTORY if (!(scp->status & BUFFER_SAVED)) { scp->status |= BUFFER_SAVED; sc_hist_save(scp); } switch (c) { /* FIXME: key codes */ case SPCLKEY | FKEY | F(49): /* home key */ sc_remove_cutmarking(scp); sc_hist_home(scp); goto next_code; case SPCLKEY | FKEY | F(57): /* end key */ sc_remove_cutmarking(scp); sc_hist_end(scp); goto next_code; case SPCLKEY | FKEY | F(50): /* up arrow key */ sc_remove_cutmarking(scp); if (sc_hist_up_line(scp)) if (!(flags & SCGETC_CN)) sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); goto next_code; case SPCLKEY | FKEY | F(58): /* down arrow key */ sc_remove_cutmarking(scp); if (sc_hist_down_line(scp)) if (!(flags & SCGETC_CN)) sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); goto next_code; case SPCLKEY | FKEY | F(51): /* page up key */ sc_remove_cutmarking(scp); for (i=0; iysize; i++) if (sc_hist_up_line(scp)) { if (!(flags & SCGETC_CN)) sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); break; } goto next_code; case SPCLKEY | FKEY | F(59): /* page down key */ sc_remove_cutmarking(scp); for (i=0; iysize; i++) if (sc_hist_down_line(scp)) { if (!(flags & SCGETC_CN)) sc_bell(scp, bios_value.bell_pitch, BELL_DURATION); break; } goto next_code; } #endif /* SC_NO_HISTORY */ } /* * Process and consume special keys here. Return a plain char code * or a char code with the META flag or a function key code. */ if (c & RELKEY) { /* key released */ /* goto next_code */ } else { /* key pressed */ if (c & SPCLKEY) { c &= ~SPCLKEY; switch (KEYCHAR(c)) { /* LOCKING KEYS */ case NLK: case CLK: case ALK: break; case SLK: kbdd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f); if (f & SLKED) { scp->status |= SLKED; } else { if (scp->status & SLKED) { scp->status &= ~SLKED; #ifndef SC_NO_HISTORY if (scp->status & BUFFER_SAVED) { if (!sc_hist_restore(scp)) sc_remove_cutmarking(scp); scp->status &= ~BUFFER_SAVED; scp->status |= CURSOR_ENABLED; sc_draw_cursor_image(scp); } tp = VIRTUAL_TTY(sc, scp->index); if (ISTTYOPEN(tp)) scstart(tp); #endif } } break; case PASTE: #ifndef SC_NO_CUTPASTE sc_mouse_paste(scp); #endif break; /* NON-LOCKING KEYS */ case NOP: case LSH: case RSH: case LCTR: case RCTR: case LALT: case RALT: case ASH: case META: break; case BTAB: if (!(sc->flags & SC_SCRN_BLANKED)) return c; break; case SPSC: #ifdef DEV_SPLASH /* force activatation/deactivation of the screen saver */ if (!(sc->flags & SC_SCRN_BLANKED)) { run_scrn_saver = TRUE; sc->scrn_time_stamp -= scrn_blank_time; } if (cold) { /* * While devices are being probed, the screen saver need * to be invoked explictly. XXX */ if (sc->flags & SC_SCRN_BLANKED) { scsplash_stick(FALSE); stop_scrn_saver(sc, current_saver); } else { if (!ISGRAPHSC(scp)) { scsplash_stick(TRUE); (*current_saver)(sc, TRUE); } } } #endif /* DEV_SPLASH */ break; case RBT: #ifndef SC_DISABLE_REBOOT if (enable_reboot) shutdown_nice(0); #endif break; case HALT: #ifndef SC_DISABLE_REBOOT if (enable_reboot) shutdown_nice(RB_HALT); #endif break; case PDWN: #ifndef SC_DISABLE_REBOOT if (enable_reboot) shutdown_nice(RB_HALT|RB_POWEROFF); #endif break; case SUSP: power_pm_suspend(POWER_SLEEP_STATE_SUSPEND); break; case STBY: power_pm_suspend(POWER_SLEEP_STATE_STANDBY); break; case DBG: #ifndef SC_DISABLE_KDBKEY if (enable_kdbkey) kdb_enter(KDB_WHY_BREAK, "manual escape to debugger"); #endif break; case PNC: if (enable_panic_key) panic("Forced by the panic key"); break; case NEXT: this_scr = scp->index; for (i = (this_scr - sc->first_vty + 1)%sc->vtys; sc->first_vty + i != this_scr; i = (i + 1)%sc->vtys) { struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i); if (ISTTYOPEN(tp)) { sc_switch_scr(scp->sc, sc->first_vty + i); break; } } break; case PREV: this_scr = scp->index; for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys; sc->first_vty + i != this_scr; i = (i + sc->vtys - 1)%sc->vtys) { struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i); if (ISTTYOPEN(tp)) { sc_switch_scr(scp->sc, sc->first_vty + i); break; } } break; default: if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) { sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR); break; } /* assert(c & FKEY) */ if (!(sc->flags & SC_SCRN_BLANKED)) return c; break; } /* goto next_code */ } else { /* regular keys (maybe MKEY is set) */ if (!(sc->flags & SC_SCRN_BLANKED)) return c; } } goto next_code; } static int scmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot) { scr_stat *scp; scp = sc_get_stat(dev); if (scp != scp->sc->cur_scp) return -1; - return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, paddr, nprot); + return vidd_mmap(scp->sc->adp, offset, paddr, nprot); } static int save_kbd_state(scr_stat *scp) { int state; int error; error = kbdd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state); if (error == ENOIOCTL) error = ENODEV; if (error == 0) { scp->status &= ~LOCK_MASK; scp->status |= state; } return error; } static int update_kbd_state(scr_stat *scp, int new_bits, int mask) { int state; int error; if (mask != LOCK_MASK) { error = kbdd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state); if (error == ENOIOCTL) error = ENODEV; if (error) return error; state &= ~mask; state |= new_bits & mask; } else { state = new_bits & LOCK_MASK; } error = kbdd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state); if (error == ENOIOCTL) error = ENODEV; return error; } static int update_kbd_leds(scr_stat *scp, int which) { int error; which &= LOCK_MASK; error = kbdd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which); if (error == ENOIOCTL) error = ENODEV; return error; } int set_mode(scr_stat *scp) { video_info_t info; /* reject unsupported mode */ - if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info)) + if (vidd_get_info(scp->sc->adp, scp->mode, &info)) return 1; /* if this vty is not currently showing, do nothing */ if (scp != scp->sc->cur_scp) return 0; /* setup video hardware for the given mode */ - (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode); + vidd_set_mode(scp->sc->adp, scp->mode); scp->rndr->init(scp); #ifndef __sparc64__ sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize, (void *)scp->sc->adp->va_window, FALSE); #endif #ifndef SC_NO_FONT_LOADING /* load appropriate font */ if (!(scp->status & GRAPHICS_MODE)) { if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) { if (scp->font_size < 14) { if (scp->sc->fonts_loaded & FONT_8) sc_load_font(scp, 0, 8, 8, scp->sc->font_8, 0, 256); } else if (scp->font_size >= 16) { if (scp->sc->fonts_loaded & FONT_16) sc_load_font(scp, 0, 16, 8, scp->sc->font_16, 0, 256); } else { if (scp->sc->fonts_loaded & FONT_14) sc_load_font(scp, 0, 14, 8, scp->sc->font_14, 0, 256); } /* * FONT KLUDGE: * This is an interim kludge to display correct font. * Always use the font page #0 on the video plane 2. * Somehow we cannot show the font in other font pages on * some video cards... XXX */ sc_show_font(scp, 0); } mark_all(scp); } #endif /* !SC_NO_FONT_LOADING */ sc_set_border(scp, scp->border); sc_set_cursor_image(scp); return 0; } void sc_set_border(scr_stat *scp, int color) { SC_VIDEO_LOCK(scp->sc); (*scp->rndr->draw_border)(scp, color); SC_VIDEO_UNLOCK(scp->sc); } #ifndef SC_NO_FONT_LOADING void sc_load_font(scr_stat *scp, int page, int size, int width, u_char *buf, int base, int count) { sc_softc_t *sc; sc = scp->sc; sc->font_loading_in_progress = TRUE; - (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, width, buf, base, - count); + vidd_load_font(sc->adp, page, size, width, buf, base, count); sc->font_loading_in_progress = FALSE; } void sc_save_font(scr_stat *scp, int page, int size, int width, u_char *buf, int base, int count) { sc_softc_t *sc; sc = scp->sc; sc->font_loading_in_progress = TRUE; - (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, width, buf, base, - count); + vidd_save_font(sc->adp, page, size, width, buf, base, count); sc->font_loading_in_progress = FALSE; } void sc_show_font(scr_stat *scp, int page) { - (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page); + vidd_show_font(scp->sc->adp, page); } #endif /* !SC_NO_FONT_LOADING */ void sc_paste(scr_stat *scp, u_char *p, int count) { struct tty *tp; u_char *rmap; tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index); if (!ISTTYOPEN(tp)) return; rmap = scp->sc->scr_rmap; for (; count > 0; --count) ttyld_rint(tp, rmap[*p++]); } void sc_bell(scr_stat *scp, int pitch, int duration) { if (cold || shutdown_in_progress || !enable_bell) return; if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL)) return; if (scp->sc->flags & SC_VISUAL_BELL) { if (scp->sc->blink_in_progress) return; scp->sc->blink_in_progress = 3; if (scp != scp->sc->cur_scp) scp->sc->blink_in_progress += 2; blink_screen(scp->sc->cur_scp); } else if (duration != 0 && pitch != 0) { if (scp != scp->sc->cur_scp) pitch *= 2; sysbeep(pitch, duration); } } static void blink_screen(void *arg) { scr_stat *scp = arg; struct tty *tp; if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) { scp->sc->blink_in_progress = 0; mark_all(scp); tp = VIRTUAL_TTY(scp->sc, scp->index); if (ISTTYOPEN(tp)) scstart(tp); if (scp->sc->delayed_next_scr) sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1); } else { (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize, scp->sc->blink_in_progress & 1); scp->sc->blink_in_progress--; timeout(blink_screen, scp, hz / 10); } } /* * Until sc_attach_unit() gets called no dev structures will be available * to store the per-screen current status. This is the case when the * kernel is initially booting and needs access to its console. During * this early phase of booting the console's current status is kept in * one statically defined scr_stat structure, and any pointers to the * dev structures will be NULL. */ static scr_stat * sc_get_stat(struct cdev *devptr) { if (devptr == NULL) return (&main_console); return (SC_STAT(devptr)); } /* * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and, * if found, add all non-busy keyboards to "kbdmux". Otherwise look for * any keyboard. */ static int sc_allocate_keyboard(sc_softc_t *sc, int unit) { int idx0, idx; keyboard_t *k0, *k; keyboard_info_t ki; idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc); if (idx0 != -1) { k0 = kbd_get_keyboard(idx0); for (idx = kbd_find_keyboard2("*", -1, 0); idx != -1; idx = kbd_find_keyboard2("*", -1, idx + 1)) { k = kbd_get_keyboard(idx); if (idx == idx0 || KBD_IS_BUSY(k)) continue; bzero(&ki, sizeof(ki)); strcpy(ki.kb_name, k->kb_name); ki.kb_unit = k->kb_unit; kbdd_ioctl(k0, KBADDKBD, (caddr_t) &ki); } } else idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc); return (idx0); } Index: head/sys/dev/syscons/warp/warp_saver.c =================================================================== --- head/sys/dev/syscons/warp/warp_saver.c (revision 174984) +++ head/sys/dev/syscons/warp/warp_saver.c (revision 174985) @@ -1,167 +1,167 @@ /*- * Copyright (c) 1998 Dag-Erling Coïdan Smørgrav * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer * in this position and unchanged. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #define SAVER_NAME "warp_saver" #define SPP 15 #define STARS (SPP * (1 + 2 + 4 + 8)) #define SET_ORIGIN(adp, o) do { \ int oo = o; \ if (oo != last_origin) \ - set_origin(adp, last_origin = oo); \ + vidd_set_win_org(adp, last_origin = oo); \ } while (0) static u_char *vid; static int banksize, scrmode, bpsl, scrw, scrh; static int blanked; static int star[STARS]; static u_char warp_pal[768] = { 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xff, 0xff, 0xff /* the rest is zero-filled by the compiler */ }; static void warp_update(video_adapter_t *adp) { int i, j, k, n, o, p; int last_origin = -1; for (i = 1, k = 0, n = SPP*8; i < 5; i++, n /= 2) { for (j = 0; j < n; j++, k++) { p = (star[k] / scrw) * bpsl + (star[k] % scrw); o = 0; while (p > banksize) { p -= banksize; o += banksize; } SET_ORIGIN(adp, o); vid[p] = 0; star[k] += i; if (star[k] > scrw*scrh) star[k] -= scrw*scrh; p = (star[k] / scrw) * bpsl + (star[k] % scrw); o = 0; while (p > banksize) { p -= banksize; o += banksize; } SET_ORIGIN(adp, o); vid[p] = i; } } } static int warp_saver(video_adapter_t *adp, int blank) { int pl; if (blank) { /* switch to graphics mode */ if (blanked <= 0) { pl = splhigh(); - set_video_mode(adp, scrmode); - load_palette(adp, warp_pal); - set_border(adp, 0); + vidd_set_mode(adp, scrmode); + vidd_load_palette(adp, warp_pal); + vidd_set_border(adp, 0); blanked++; vid = (u_char *)adp->va_window; banksize = adp->va_window_size; bpsl = adp->va_line_width; splx(pl); - (*vidsw[adp->va_index]->clear)(adp); + vidd_clear(adp); } /* update display */ warp_update(adp); } else { blanked = 0; } return (0); } static int warp_init(video_adapter_t *adp) { video_info_t info; int i; - if (!get_mode_info(adp, M_VGA_CG320, &info)) { + if (!vidd_get_info(adp, M_VGA_CG320, &info)) { scrmode = M_VGA_CG320; - } else if (!get_mode_info(adp, M_PC98_PEGC640x480, &info)) { + } else if (!vidd_get_info(adp, M_PC98_PEGC640x480, &info)) { scrmode = M_PC98_PEGC640x480; - } else if (!get_mode_info(adp, M_PC98_PEGC640x400, &info)) { + } else if (!vidd_get_info(adp, M_PC98_PEGC640x400, &info)) { scrmode = M_PC98_PEGC640x400; } else { log(LOG_NOTICE, "%s: the console does not support M_VGA_CG320\n", SAVER_NAME); return (ENODEV); } scrw = info.vi_width; scrh = info.vi_height; /* randomize the star field */ for (i = 0; i < STARS; i++) star[i] = random() % (scrw * scrh); return (0); } static int warp_term(video_adapter_t *adp) { return (0); } static scrn_saver_t warp_module = { SAVER_NAME, warp_init, warp_term, warp_saver, NULL }; SAVER_MODULE(warp_saver, warp_module); Index: head/sys/i386/xbox/xboxfb.c =================================================================== --- head/sys/i386/xbox/xboxfb.c (revision 174984) +++ head/sys/i386/xbox/xboxfb.c (revision 174985) @@ -1,656 +1,655 @@ /*- * Copyright (c) 2005, 2006 Rink Springer * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); /* * This is the syscon(4)-ized version of the Xbox Frame Buffer driver. It * supports about all features required, such as mouse support. * * A lot of functions that are not useful to us have not been implemented. * It appears that some functions are never called, but these implementations * are here nevertheless. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include struct xboxfb_softc { video_adapter_t sc_va; /* screen height (pixels) */ uint32_t sc_height; /* screen width (pixels) */ uint32_t sc_width; /* pointer to the actual XBOX video memory */ char* sc_framebuffer; /* pointer to the font used */ const struct gfb_font* sc_font; }; #define SCREEN_WIDTH 640 #define SCREEN_HEIGHT 480 #define XBOXFB_DRIVER_NAME "xboxsc" extern const struct gfb_font bold8x16; static vi_probe_t xboxfb_probe; static vi_init_t xboxfb_init; static vi_get_info_t xboxfb_get_info; static vi_query_mode_t xboxfb_query_mode; static vi_set_mode_t xboxfb_set_mode; static vi_save_font_t xboxfb_save_font; static vi_load_font_t xboxfb_load_font; static vi_show_font_t xboxfb_show_font; static vi_save_palette_t xboxfb_save_palette; static vi_load_palette_t xboxfb_load_palette; static vi_set_border_t xboxfb_set_border; static vi_save_state_t xboxfb_save_state; static vi_load_state_t xboxfb_load_state; static vi_set_win_org_t xboxfb_set_win_org; static vi_read_hw_cursor_t xboxfb_read_hw_cursor; static vi_set_hw_cursor_t xboxfb_set_hw_cursor; static vi_set_hw_cursor_shape_t xboxfb_set_hw_cursor_shape; static vi_blank_display_t xboxfb_blank_display; static vi_mmap_t xboxfb_mmap; static vi_ioctl_t xboxfb_ioctl; static vi_clear_t xboxfb_clear; static vi_fill_rect_t xboxfb_fill_rect; static vi_bitblt_t xboxfb_bitblt; static vi_diag_t xboxfb_diag; static vi_save_cursor_palette_t xboxfb_save_cursor_palette; static vi_load_cursor_palette_t xboxfb_load_cursor_palette; static vi_copy_t xboxfb_copy; static vi_putp_t xboxfb_putp; static vi_putc_t xboxfb_putc; static vi_puts_t xboxfb_puts; static vi_putm_t xboxfb_putm; static video_switch_t xboxvidsw = { .probe = xboxfb_probe, .init = xboxfb_init, .get_info = xboxfb_get_info, .query_mode = xboxfb_query_mode, .set_mode = xboxfb_set_mode, .save_font = xboxfb_save_font, .load_font = xboxfb_load_font, .show_font = xboxfb_show_font, .save_palette = xboxfb_save_palette, .load_palette = xboxfb_load_palette, .set_border = xboxfb_set_border, .save_state = xboxfb_save_state, .load_state = xboxfb_load_state, .set_win_org = xboxfb_set_win_org, .read_hw_cursor = xboxfb_read_hw_cursor, .set_hw_cursor = xboxfb_set_hw_cursor, .set_hw_cursor_shape = xboxfb_set_hw_cursor_shape, .blank_display = xboxfb_blank_display, .mmap = xboxfb_mmap, .ioctl = xboxfb_ioctl, .clear = xboxfb_clear, .fill_rect = xboxfb_fill_rect, .bitblt = xboxfb_bitblt, NULL, NULL, .diag = xboxfb_diag, .save_cursor_palette = xboxfb_save_cursor_palette, .load_cursor_palette = xboxfb_load_cursor_palette, .copy = xboxfb_copy, .putp = xboxfb_putp, .putc = xboxfb_putc, .puts = xboxfb_puts, .putm = xboxfb_putm }; static int xboxfb_configure(int flags); VIDEO_DRIVER(xboxsc, xboxvidsw, xboxfb_configure); static vr_init_t xbr_init; static vr_clear_t xbr_clear; static vr_draw_border_t xbr_draw_border; static vr_draw_t xbr_draw; static vr_set_cursor_t xbr_set_cursor; static vr_draw_cursor_t xbr_draw_cursor; static vr_blink_cursor_t xbr_blink_cursor; static vr_set_mouse_t xbr_set_mouse; static vr_draw_mouse_t xbr_draw_mouse; /* * We use our own renderer; this is because we must emulate a hardware * cursor. */ static sc_rndr_sw_t xboxrend = { xbr_init, xbr_clear, xbr_draw_border, xbr_draw, xbr_set_cursor, xbr_draw_cursor, xbr_blink_cursor, xbr_set_mouse, xbr_draw_mouse }; RENDERER(xboxsc, 0, xboxrend, gfb_set); static struct xboxfb_softc xboxfb_sc; /* color mappings, from dev/fb/creator.c */ static const uint32_t cmap[] = { 0x00000000, /* black */ 0x000000ff, /* blue */ 0x0000ff00, /* green */ 0x0000c0c0, /* cyan */ 0x00ff0000, /* red */ 0x00c000c0, /* magenta */ 0x00c0c000, /* brown */ 0x00c0c0c0, /* light grey */ 0x00808080, /* dark grey */ 0x008080ff, /* light blue */ 0x0080ff80, /* light green */ 0x0080ffff, /* light cyan */ 0x00ff8080, /* light red */ 0x00ff80ff, /* light magenta */ 0x00ffff80, /* yellow */ 0x00ffffff /* white */ }; /* mouse pointer from dev/syscons/scgfbrndr.c */ static u_char mouse_pointer[16] = { 0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68, 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00 }; static int xboxfb_init(int unit, video_adapter_t* adp, int flags) { struct xboxfb_softc* sc = &xboxfb_sc; video_info_t* vi; int i; int* iptr; vi = &adp->va_info; vid_init_struct (adp, XBOXFB_DRIVER_NAME, -1, unit); sc->sc_height = SCREEN_HEIGHT; sc->sc_width = SCREEN_WIDTH; sc->sc_font = &bold8x16; if (!(adp->va_flags & V_ADP_INITIALIZED)) { /* * We must make a mapping from video framebuffer memory * to real. This is very crude: we map the entire * videomemory to PAGE_SIZE! Since our kernel lives at * it's relocated address range (0xc0xxxxxx), it won't * care. * * We use address PAGE_SIZE and up so we can still trap * NULL pointers. Once the real init is called, the * mapping will be done via the OS and stored in a more * sensible location ... but since we're not fully * initialized, this is our only way to go :-( */ for (i = 0; i < (XBOX_FB_SIZE / PAGE_SIZE); i++) { pmap_kenter (((i + 1) * PAGE_SIZE), XBOX_FB_START + (i * PAGE_SIZE)); } pmap_kenter ((i + 1) * PAGE_SIZE, XBOX_FB_START_PTR - XBOX_FB_START_PTR % PAGE_SIZE); sc->sc_framebuffer = (char*)PAGE_SIZE; /* ensure the framebuffer is where we want it to be */ *(uint32_t*)((i + 1) * PAGE_SIZE + XBOX_FB_START_PTR % PAGE_SIZE) = XBOX_FB_START; /* clear the screen */ iptr = (uint32_t*)sc->sc_framebuffer; for (i = 0; i < sc->sc_height * sc->sc_width; i++) *iptr++ = cmap[0]; /* don't ever do this again! */ adp->va_flags |= V_ADP_INITIALIZED; } vi->vi_mode = M_TEXT_80x25; vi->vi_cwidth = sc->sc_font->width; vi->vi_cheight = sc->sc_font->height; vi->vi_height = (sc->sc_height / vi->vi_cheight); vi->vi_width = (sc->sc_width / vi->vi_cwidth); vi->vi_flags = V_INFO_COLOR | V_INFO_LINEAR; vi->vi_mem_model = V_INFO_MM_DIRECT; adp->va_flags |= V_ADP_COLOR; if (vid_register(adp) < 0) return (ENXIO); adp->va_flags |= V_ADP_REGISTERED; return 0; } static int xboxfb_probe(int unit, video_adapter_t** adp, void* arg, int flags) { return 0; } static int xboxfb_configure(int flags) { struct xboxfb_softc* sc = &xboxfb_sc; /* Don't init the framebuffer on non-XBOX-es */ if (!arch_i386_is_xbox) return 0; /* * If we do only a probe, we are in such an early boot stadium * that we cannot yet do a 'clean' initialization. */ if (flags & VIO_PROBE_ONLY) { xboxfb_init(0, &sc->sc_va, 0); return 1; } /* Do a clean mapping of the framebuffer memory */ sc->sc_framebuffer = pmap_mapdev (XBOX_FB_START, XBOX_FB_SIZE); return 1; } static void sc_identify(driver_t* driver, device_t parent) { BUS_ADD_CHILD(parent, INT_MAX, SC_DRIVER_NAME, 0); } static int sc_probe(device_t dev) { device_set_desc(dev, "XBox System console"); return (sc_probe_unit(device_get_unit(dev), device_get_flags(dev) | SC_AUTODETECT_KBD)); } static int sc_attach(device_t dev) { return (sc_attach_unit(device_get_unit(dev), device_get_flags(dev) | SC_AUTODETECT_KBD)); } static device_method_t sc_methods[] = { /* Device interface */ DEVMETHOD(device_identify, sc_identify), DEVMETHOD(device_probe, sc_probe), DEVMETHOD(device_attach, sc_attach), { 0, 0 } }; static driver_t xboxfb_sc_driver = { SC_DRIVER_NAME, sc_methods, sizeof(sc_softc_t) }; static devclass_t sc_devclass; DRIVER_MODULE(sc, legacy, xboxfb_sc_driver, sc_devclass, 0, 0); static void xbr_init(scr_stat* scp) { } static void xbr_clear(scr_stat* scp, int c, int attr) { } static void xbr_draw_border(scr_stat* scp, int color) { } static void xbr_draw(scr_stat* scp, int from, int count, int flip) { video_adapter_t* adp = scp->sc->adp; int i, c, a; if (!flip) { /* Normal printing */ - (*vidsw[scp->sc->adapter]->puts)(adp, from, (uint16_t*)sc_vtb_pointer(&scp->vtb, from), count); + vidd_puts(adp, from, (uint16_t*)sc_vtb_pointer(&scp->vtb, from), count); } else { /* This is for selections and such: invert the color attribute */ for (i = count; i-- > 0; ++from) { c = sc_vtb_getc(&scp->vtb, from); a = sc_vtb_geta(&scp->vtb, from) >> 8; - (*vidsw[scp->sc->adapter]->putc)(adp, from, c, (a >> 4) | ((a & 0xf) << 4)); + vidd_putc(adp, from, c, (a >> 4) | ((a & 0xf) << 4)); } } } static void xbr_set_cursor(scr_stat* scp, int base, int height, int blink) { } static void xbr_draw_cursor(scr_stat* scp, int at, int blink, int on, int flip) { struct xboxfb_softc* sc = &xboxfb_sc; video_adapter_t* adp = scp->sc->adp; uint32_t* ptri = (uint32_t*)sc->sc_framebuffer; int row, col, i, j; if (scp->curs_attr.height <= 0) return; /* calculate the coordinates in the video buffer */ row = (at / adp->va_info.vi_width) * adp->va_info.vi_cheight; col = (at % adp->va_info.vi_width) * adp->va_info.vi_cwidth; ptri += (row * sc->sc_width) + col; /* our cursor consists of simply inverting the char under it */ for (i = 0; i < adp->va_info.vi_cheight; i++) { for (j = 0; j < adp->va_info.vi_cwidth; j++) { *ptri++ ^= 0x00FFFFFF; } ptri += (sc->sc_width - adp->va_info.vi_cwidth); } } static void xbr_blink_cursor(scr_stat* scp, int at, int flip) { } static void xbr_set_mouse(scr_stat* scp) { } static void xbr_draw_mouse(scr_stat* scp, int x, int y, int on) { - (*vidsw[scp->sc->adapter]->putm)(scp->sc->adp, x, y, mouse_pointer, 0xffffffff, 16, 8); + vidd_putm(scp->sc->adp, x, y, mouse_pointer, 0xffffffff, 16, 8); } static int xboxfb_get_info(video_adapter_t *adp, int mode, video_info_t *info) { bcopy(&adp->va_info, info, sizeof(*info)); return (0); } static int xboxfb_query_mode(video_adapter_t *adp, video_info_t *info) { return (ENODEV); } static int xboxfb_set_mode(video_adapter_t *adp, int mode) { return (0); } static int xboxfb_save_font(video_adapter_t *adp, int page, int size, int width, u_char *data, int c, int count) { return (ENODEV); } static int xboxfb_load_font(video_adapter_t *adp, int page, int size, int width, u_char *data, int c, int count) { return (ENODEV); } static int xboxfb_show_font(video_adapter_t *adp, int page) { return (ENODEV); } static int xboxfb_save_palette(video_adapter_t *adp, u_char *palette) { return (ENODEV); } static int xboxfb_load_palette(video_adapter_t *adp, u_char *palette) { return (ENODEV); } static int xboxfb_set_border(video_adapter_t *adp, int border) { return (0); } static int xboxfb_save_state(video_adapter_t *adp, void *p, size_t size) { return (ENODEV); } static int xboxfb_load_state(video_adapter_t *adp, void *p) { return (ENODEV); } static int xboxfb_set_win_org(video_adapter_t *adp, off_t offset) { return (ENODEV); } static int xboxfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row) { *col = 0; *row = 0; return (0); } static int xboxfb_set_hw_cursor(video_adapter_t *adp, int col, int row) { return (ENODEV); } static int xboxfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, int celsize, int blink) { return (ENODEV); } static int xboxfb_blank_display(video_adapter_t *adp, int mode) { return (0); } static int xboxfb_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr, int prot) { return (EINVAL); } static int xboxfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data) { return (fb_commonioctl(adp, cmd, data)); } static int xboxfb_clear(video_adapter_t *adp) { return (0); } static int xboxfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) { return (0); } static int xboxfb_bitblt(video_adapter_t *adp, ...) { return (ENODEV); } static int xboxfb_diag(video_adapter_t *adp, int level) { video_info_t info; fb_dump_adp_info(adp->va_name, adp, level); xboxfb_get_info(adp, 0, &info); fb_dump_mode_info(adp->va_name, adp, &info, level); return (0); } static int xboxfb_save_cursor_palette(video_adapter_t *adp, u_char *palette) { return (ENODEV); } static int xboxfb_load_cursor_palette(video_adapter_t *adp, u_char *palette) { return (ENODEV); } static int xboxfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n) { return (ENODEV); } static int xboxfb_putp(video_adapter_t *adp, vm_offset_t off, u_int32_t p, u_int32_t a, int size, int bpp, int bit_ltor, int byte_ltor) { return (ENODEV); } static int xboxfb_putc(video_adapter_t *adp, vm_offset_t off, u_int8_t c, u_int8_t a) { int row, col; int i, j; struct xboxfb_softc* sc = &xboxfb_sc; uint32_t* ptri = (uint32_t*)sc->sc_framebuffer; const uint8_t* fontdata; uint32_t clr; uint8_t mask; /* calculate the position in the frame buffer */ row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; fontdata = &sc->sc_font->data[c * adp->va_info.vi_cheight]; ptri += (row * sc->sc_width) + col; /* Place the character on the screen, pixel by pixel */ for (j = 0; j < adp->va_info.vi_cheight; j++) { mask = 0x80; for (i = 0; i < adp->va_info.vi_cwidth; i++) { clr = (*fontdata & mask) ? cmap[a & 0xf] : cmap[(a >> 4) & 0xf]; *ptri++ = clr; mask >>= 1; } ptri += (sc->sc_width - adp->va_info.vi_cwidth); fontdata++; } return (0); } static int xboxfb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len) { int i; for (i = 0; i < len; i++) { - (*vidsw[adp->va_index]->putc)(adp, off + i, s[i] & 0xff, - (s[i] & 0xff00) >> 8); + vidd_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8); } return (0); } static int xboxfb_putm(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image, u_int32_t pixel_mask, int size, int width) { struct xboxfb_softc* sc = &xboxfb_sc; uint32_t* ptri = (uint32_t*)sc->sc_framebuffer; int i, j; if (x < 0 || y < 0 || x + width > sc->sc_width || y + (2 * size) > sc->sc_height) return 0; ptri += (y * sc->sc_width) + x; /* plot the mousecursor wherever the user wants it */ for (j = 0; j < size; j++) { for (i = width; i > 0; i--) { if (pixel_image[j] & (1 << i)) *ptri = cmap[0xf]; ptri++; } ptri += (sc->sc_width - width); } return (0); } Index: head/sys/isa/vga_isa.c =================================================================== --- head/sys/isa/vga_isa.c (revision 174984) +++ head/sys/isa/vga_isa.c (revision 174985) @@ -1,272 +1,270 @@ /*- * Copyright (c) 1999 Kazutaka YOKOTA * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer as * the first lines of this file unmodified. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_vga.h" #include "opt_fb.h" #include "opt_syscons.h" /* should be removed in the future, XXX */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef __i386__ #include #endif #include #include #include #include #define VGA_SOFTC(unit) \ ((vga_softc_t *)devclass_get_softc(isavga_devclass, unit)) static devclass_t isavga_devclass; #ifdef FB_INSTALL_CDEV static d_open_t isavga_open; static d_close_t isavga_close; static d_read_t isavga_read; static d_write_t isavga_write; static d_ioctl_t isavga_ioctl; static d_mmap_t isavga_mmap; static struct cdevsw isavga_cdevsw = { .d_version = D_VERSION, .d_flags = D_NEEDGIANT, .d_open = isavga_open, .d_close = isavga_close, .d_read = isavga_read, .d_write = isavga_write, .d_ioctl = isavga_ioctl, .d_mmap = isavga_mmap, .d_name = VGA_DRIVER_NAME, }; #endif /* FB_INSTALL_CDEV */ static void isavga_identify(driver_t *driver, device_t parent) { BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, VGA_DRIVER_NAME, 0); } static int isavga_probe(device_t dev) { video_adapter_t adp; int error; /* No pnp support */ if (isa_get_vendorid(dev)) return (ENXIO); device_set_desc(dev, "Generic ISA VGA"); error = vga_probe_unit(device_get_unit(dev), &adp, device_get_flags(dev)); if (error == 0) { bus_set_resource(dev, SYS_RES_IOPORT, 0, adp.va_io_base, adp.va_io_size); bus_set_resource(dev, SYS_RES_MEMORY, 0, adp.va_mem_base, adp.va_mem_size); #if 0 isa_set_port(dev, adp.va_io_base); isa_set_portsize(dev, adp.va_io_size); isa_set_maddr(dev, adp.va_mem_base); isa_set_msize(dev, adp.va_mem_size); #endif } return error; } static int isavga_attach(device_t dev) { vga_softc_t *sc; int unit; int rid; int error; unit = device_get_unit(dev); sc = device_get_softc(dev); rid = 0; bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); rid = 0; bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0, ~0, 0, RF_ACTIVE | RF_SHAREABLE); error = vga_attach_unit(unit, sc, device_get_flags(dev)); if (error) return error; #ifdef FB_INSTALL_CDEV /* attach a virtual frame buffer device */ error = fb_attach(VGA_MKMINOR(unit), sc->adp, &isavga_cdevsw); if (error) return error; #endif /* FB_INSTALL_CDEV */ if (0 && bootverbose) - (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose); + vidd_diag(sc->adp, bootverbose); #if 0 /* experimental */ device_add_child(dev, "fb", -1); bus_generic_attach(dev); #endif return 0; } static int isavga_suspend(device_t dev) { vga_softc_t *sc; int err, nbytes; sc = device_get_softc(dev); err = bus_generic_suspend(dev); if (err) return (err); /* Save the video state across the suspend. */ if (sc->state_buf != NULL) { free(sc->state_buf, M_TEMP); sc->state_buf = NULL; } - nbytes = (*vidsw[sc->adp->va_index]->save_state)(sc->adp, NULL, 0); + nbytes = vidd_save_state(sc->adp, NULL, 0); if (nbytes <= 0) return (0); sc->state_buf = malloc(nbytes, M_TEMP, M_NOWAIT | M_ZERO); if (sc->state_buf == NULL) return (0); if (bootverbose) device_printf(dev, "saving %d bytes of video state\n", nbytes); - if ((*vidsw[sc->adp->va_index]->save_state)(sc->adp, sc->state_buf, - nbytes) != 0) { + if (vidd_save_state(sc->adp, sc->state_buf, nbytes) != 0) { device_printf(dev, "failed to save state (nbytes=%d)\n", nbytes); free(sc->state_buf, M_TEMP); sc->state_buf = NULL; } return (0); } static int isavga_resume(device_t dev) { vga_softc_t *sc; sc = device_get_softc(dev); if (sc->state_buf != NULL) { - if ((*vidsw[sc->adp->va_index]->load_state)(sc->adp, - sc->state_buf) != 0) + if (vidd_load_state(sc->adp, sc->state_buf) != 0) device_printf(dev, "failed to reload state\n"); free(sc->state_buf, M_TEMP); sc->state_buf = NULL; } bus_generic_resume(dev); return 0; } #ifdef FB_INSTALL_CDEV static int isavga_open(struct cdev *dev, int flag, int mode, struct thread *td) { return vga_open(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); } static int isavga_close(struct cdev *dev, int flag, int mode, struct thread *td) { return vga_close(dev, VGA_SOFTC(VGA_UNIT(dev)), flag, mode, td); } static int isavga_read(struct cdev *dev, struct uio *uio, int flag) { return vga_read(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); } static int isavga_write(struct cdev *dev, struct uio *uio, int flag) { return vga_write(dev, VGA_SOFTC(VGA_UNIT(dev)), uio, flag); } static int isavga_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td) { return vga_ioctl(dev, VGA_SOFTC(VGA_UNIT(dev)), cmd, arg, flag, td); } static int isavga_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot) { return vga_mmap(dev, VGA_SOFTC(VGA_UNIT(dev)), offset, paddr, prot); } #endif /* FB_INSTALL_CDEV */ static device_method_t isavga_methods[] = { DEVMETHOD(device_identify, isavga_identify), DEVMETHOD(device_probe, isavga_probe), DEVMETHOD(device_attach, isavga_attach), DEVMETHOD(device_suspend, isavga_suspend), DEVMETHOD(device_resume, isavga_resume), DEVMETHOD(bus_print_child, bus_generic_print_child), { 0, 0 } }; static driver_t isavga_driver = { VGA_DRIVER_NAME, isavga_methods, sizeof(vga_softc_t), }; DRIVER_MODULE(vga, isa, isavga_driver, isavga_devclass, 0, 0); Index: head/sys/pc98/cbus/gdc.c =================================================================== --- head/sys/pc98/cbus/gdc.c (revision 174984) +++ head/sys/pc98/cbus/gdc.c (revision 174985) @@ -1,1486 +1,1486 @@ /*- * Copyright (c) 1999 FreeBSD(98) port team. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer as * the first lines of this file unmodified. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include "opt_gdc.h" #include "opt_fb.h" #include "opt_syscons.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef LINE30 #include #endif #include #include #define TEXT_GDC 0x60 #define GRAPHIC_GDC 0xa0 #define ROW 25 #define COL 80 #define DRIVER_NAME "gdc" /* cdev driver declaration */ #define GDC_UNIT(dev) minor(dev) #define GDC_MKMINOR(unit) (unit) typedef struct gdc_softc { video_adapter_t *adp; struct resource *res_tgdc, *res_ggdc; struct resource *res_egc, *res_pegc, *res_grcg, *res_kcg; struct resource *res_tmem, *res_gmem1, *res_gmem2; #ifdef FB_INSTALL_CDEV genfb_softc_t gensc; #endif } gdc_softc_t; #define GDC_SOFTC(unit) \ ((gdc_softc_t *)devclass_get_softc(gdc_devclass, unit)) static bus_addr_t gdc_iat[] = {0, 2, 4, 6, 8, 10, 12, 14}; static devclass_t gdc_devclass; static int gdc_probe_unit(int unit, gdc_softc_t *sc, int flags); static int gdc_attach_unit(int unit, gdc_softc_t *sc, int flags); static int gdc_alloc_resource(device_t dev); static int gdc_release_resource(device_t dev); #ifdef FB_INSTALL_CDEV static d_open_t gdcopen; static d_close_t gdcclose; static d_read_t gdcread; static d_write_t gdcwrite; static d_ioctl_t gdcioctl; static d_mmap_t gdcmmap; static struct cdevsw gdc_cdevsw = { .d_version = D_VERSION, .d_flags = D_NEEDGIANT, .d_open = gdcopen, .d_close = gdcclose, .d_read = gdcread, .d_write = gdcwrite, .d_ioctl = gdcioctl, .d_mmap = gdcmmap, .d_name = DRIVER_NAME, }; #endif /* FB_INSTALL_CDEV */ static void gdc_identify(driver_t *driver, device_t parent) { BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, DRIVER_NAME, 0); } static int gdcprobe(device_t dev) { int error; /* Check isapnp ids */ if (isa_get_vendorid(dev)) return (ENXIO); device_set_desc(dev, "Generic GDC"); error = gdc_alloc_resource(dev); if (error) return (error); error = gdc_probe_unit(device_get_unit(dev), device_get_softc(dev), device_get_flags(dev)); gdc_release_resource(dev); return (error); } static int gdc_attach(device_t dev) { gdc_softc_t *sc; int error; error = gdc_alloc_resource(dev); if (error) return (error); sc = device_get_softc(dev); error = gdc_attach_unit(device_get_unit(dev), sc, device_get_flags(dev)); if (error) { gdc_release_resource(dev); return error; } #ifdef FB_INSTALL_CDEV /* attach a virtual frame buffer device */ error = fb_attach(GDC_MKMINOR(device_get_unit(dev)), sc->adp, &gdc_cdevsw); if (error) { gdc_release_resource(dev); return error; } #endif /* FB_INSTALL_CDEV */ if (bootverbose) - (*vidsw[sc->adp->va_index]->diag)(sc->adp, bootverbose); + vidd_diag(sc->adp, bootverbose); return 0; } static int gdc_probe_unit(int unit, gdc_softc_t *sc, int flags) { video_switch_t *sw; sw = vid_get_switch(DRIVER_NAME); if (sw == NULL) return ENXIO; return (*sw->probe)(unit, &sc->adp, NULL, flags); } static int gdc_attach_unit(int unit, gdc_softc_t *sc, int flags) { video_switch_t *sw; sw = vid_get_switch(DRIVER_NAME); if (sw == NULL) return ENXIO; return (*sw->init)(unit, sc->adp, flags); } static int gdc_alloc_resource(device_t dev) { int rid; gdc_softc_t *sc; sc = device_get_softc(dev); /* TEXT GDC */ rid = 0; bus_set_resource(dev, SYS_RES_IOPORT, rid, TEXT_GDC, 1); sc->res_tgdc = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, gdc_iat, 8, RF_ACTIVE); if (sc->res_tgdc == NULL) { gdc_release_resource(dev); return (ENXIO); } isa_load_resourcev(sc->res_tgdc, gdc_iat, 8); /* GRAPHIC GDC */ rid = 8; bus_set_resource(dev, SYS_RES_IOPORT, rid, GRAPHIC_GDC, 1); sc->res_ggdc = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, gdc_iat, 8, RF_ACTIVE); if (sc->res_ggdc == NULL) { gdc_release_resource(dev); return (ENXIO); } isa_load_resourcev(sc->res_ggdc, gdc_iat, 8); /* EGC */ rid = 16; bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x4a0, 1); sc->res_egc = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, gdc_iat, 8, RF_ACTIVE); if (sc->res_egc == NULL) { gdc_release_resource(dev); return (ENXIO); } isa_load_resourcev(sc->res_egc, gdc_iat, 8); /* PEGC */ rid = 24; bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x9a0, 1); sc->res_pegc = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, gdc_iat, 8, RF_ACTIVE); if (sc->res_pegc == NULL) { gdc_release_resource(dev); return (ENXIO); } isa_load_resourcev(sc->res_pegc, gdc_iat, 8); /* CRTC/GRCG */ rid = 32; bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x70, 1); sc->res_grcg = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, gdc_iat, 8, RF_ACTIVE); if (sc->res_grcg == NULL) { gdc_release_resource(dev); return (ENXIO); } isa_load_resourcev(sc->res_grcg, gdc_iat, 8); /* KCG */ rid = 40; bus_set_resource(dev, SYS_RES_IOPORT, rid, 0xa1, 1); sc->res_kcg = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, gdc_iat, 8, RF_ACTIVE); if (sc->res_kcg == NULL) { gdc_release_resource(dev); return (ENXIO); } isa_load_resourcev(sc->res_kcg, gdc_iat, 8); /* TEXT Memory */ rid = 0; sc->res_tmem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0xa0000, 0xa4fff, 0x5000, RF_ACTIVE); if (sc->res_tmem == NULL) { gdc_release_resource(dev); return (ENXIO); } /* GRAPHIC Memory */ rid = 1; sc->res_gmem1 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0xa8000, 0xbffff, 0x18000, RF_ACTIVE); if (sc->res_gmem1 == NULL) { gdc_release_resource(dev); return (ENXIO); } rid = 2; sc->res_gmem2 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0xe0000, 0xe7fff, 0x8000, RF_ACTIVE); if (sc->res_gmem2 == NULL) { gdc_release_resource(dev); return (ENXIO); } return (0); } static int gdc_release_resource(device_t dev) { gdc_softc_t *sc; sc = device_get_softc(dev); if (sc->res_tgdc) bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->res_tgdc); if (sc->res_ggdc) bus_release_resource(dev, SYS_RES_IOPORT, 8, sc->res_ggdc); if (sc->res_egc) bus_release_resource(dev, SYS_RES_IOPORT, 16, sc->res_egc); if (sc->res_pegc) bus_release_resource(dev, SYS_RES_IOPORT, 24, sc->res_pegc); if (sc->res_grcg) bus_release_resource(dev, SYS_RES_IOPORT, 32, sc->res_grcg); if (sc->res_kcg) bus_release_resource(dev, SYS_RES_IOPORT, 40, sc->res_kcg); if (sc->res_tmem) bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->res_tmem); if (sc->res_gmem1) bus_release_resource(dev, SYS_RES_MEMORY, 1, sc->res_gmem1); if (sc->res_gmem2) bus_release_resource(dev, SYS_RES_MEMORY, 2, sc->res_gmem2); return (0); } /* cdev driver functions */ #ifdef FB_INSTALL_CDEV static int gdcopen(struct cdev *dev, int flag, int mode, struct thread *td) { gdc_softc_t *sc; sc = GDC_SOFTC(GDC_UNIT(dev)); if (sc == NULL) return ENXIO; if (mode & (O_CREAT | O_APPEND | O_TRUNC)) return ENODEV; return genfbopen(&sc->gensc, sc->adp, flag, mode, td); } static int gdcclose(struct cdev *dev, int flag, int mode, struct thread *td) { gdc_softc_t *sc; sc = GDC_SOFTC(GDC_UNIT(dev)); return genfbclose(&sc->gensc, sc->adp, flag, mode, td); } static int gdcread(struct cdev *dev, struct uio *uio, int flag) { gdc_softc_t *sc; sc = GDC_SOFTC(GDC_UNIT(dev)); return genfbread(&sc->gensc, sc->adp, uio, flag); } static int gdcwrite(struct cdev *dev, struct uio *uio, int flag) { gdc_softc_t *sc; sc = GDC_SOFTC(GDC_UNIT(dev)); return genfbread(&sc->gensc, sc->adp, uio, flag); } static int gdcioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td) { gdc_softc_t *sc; sc = GDC_SOFTC(GDC_UNIT(dev)); return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, td); } static int gdcmmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int prot) { gdc_softc_t *sc; sc = GDC_SOFTC(GDC_UNIT(dev)); return genfbmmap(&sc->gensc, sc->adp, offset, paddr, prot); } #endif /* FB_INSTALL_CDEV */ static device_method_t gdc_methods[] = { DEVMETHOD(device_identify, gdc_identify), DEVMETHOD(device_probe, gdcprobe), DEVMETHOD(device_attach, gdc_attach), { 0, 0 } }; static driver_t gdcdriver = { DRIVER_NAME, gdc_methods, sizeof(gdc_softc_t), }; DRIVER_MODULE(gdc, isa, gdcdriver, gdc_devclass, 0, 0); /* LOW-LEVEL */ #include #define TEXT_BUF_BASE 0x000a0000 #define TEXT_BUF_SIZE 0x00008000 #define GRAPHICS_BUF_BASE 0x000a8000 #define GRAPHICS_BUF_SIZE 0x00040000 #define VIDEO_BUF_BASE 0x000a0000 #define VIDEO_BUF_SIZE 0x00048000 #define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED) #define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED) #define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED) /* * NOTE: `va_window' should have a virtual address, but is initialized * with a physical address in the following table, they will be * converted at run-time. */ static video_adapter_t adapter_init_value[] = { { 0, KD_PC98, "gdc", /* va_type, va_name */ 0, 0, /* va_unit, va_minor */ V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_BORDER, TEXT_GDC, 16, TEXT_GDC, /* va_io*, XXX */ VIDEO_BUF_BASE, VIDEO_BUF_SIZE, /* va_mem* */ TEXT_BUF_BASE, TEXT_BUF_SIZE, TEXT_BUF_SIZE, 0, /* va_window* */ 0, 0, /* va_buffer, va_buffer_size */ 0, M_PC98_80x25, 0, /* va_*mode* */ }, }; static video_adapter_t biosadapter[1]; /* video driver declarations */ static int gdc_configure(int flags); static int gdc_err(video_adapter_t *adp, ...); static vi_probe_t gdc_probe; static vi_init_t gdc_init; static vi_get_info_t gdc_get_info; static vi_query_mode_t gdc_query_mode; static vi_set_mode_t gdc_set_mode; static vi_set_border_t gdc_set_border; static vi_save_state_t gdc_save_state; static vi_load_state_t gdc_load_state; static vi_read_hw_cursor_t gdc_read_hw_cursor; static vi_set_hw_cursor_t gdc_set_hw_cursor; static vi_set_hw_cursor_shape_t gdc_set_hw_cursor_shape; static vi_blank_display_t gdc_blank_display; static vi_mmap_t gdc_mmap_buf; static vi_ioctl_t gdc_dev_ioctl; static vi_clear_t gdc_clear; static vi_fill_rect_t gdc_fill_rect; static vi_bitblt_t gdc_bitblt; static vi_diag_t gdc_diag; static vi_save_palette_t gdc_save_palette; static vi_load_palette_t gdc_load_palette; static vi_set_win_org_t gdc_set_origin; static video_switch_t gdcvidsw = { gdc_probe, gdc_init, gdc_get_info, gdc_query_mode, gdc_set_mode, (vi_save_font_t *)gdc_err, (vi_load_font_t *)gdc_err, (vi_show_font_t *)gdc_err, gdc_save_palette, gdc_load_palette, gdc_set_border, gdc_save_state, gdc_load_state, gdc_set_origin, gdc_read_hw_cursor, gdc_set_hw_cursor, gdc_set_hw_cursor_shape, gdc_blank_display, gdc_mmap_buf, gdc_dev_ioctl, gdc_clear, gdc_fill_rect, gdc_bitblt, (int (*)(void))gdc_err, (int (*)(void))gdc_err, gdc_diag, }; VIDEO_DRIVER(gdc, gdcvidsw, gdc_configure); /* GDC BIOS standard video modes */ #define EOT (-1) #define NA (-2) static video_info_t bios_vmode[] = { { M_PC98_80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1, TEXT_BUF_BASE, TEXT_BUF_SIZE, TEXT_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, #ifdef LINE30 { M_PC98_80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1, TEXT_BUF_BASE, TEXT_BUF_SIZE, TEXT_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, #endif #ifndef GDC_NOGRAPHICS { M_PC98_EGC640x400, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 400, 8, 16, 4, 4, GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0, V_INFO_MM_PLANAR }, { M_PC98_PEGC640x400, V_INFO_COLOR | V_INFO_GRAPHICS | V_INFO_VESA, 640, 400, 8, 16, 8, 1, GRAPHICS_BUF_BASE, 0x00008000, 0x00008000, 0, 0, V_INFO_MM_PACKED, 1 }, #ifdef LINE30 { M_PC98_PEGC640x480, V_INFO_COLOR | V_INFO_GRAPHICS | V_INFO_VESA, 640, 480, 8, 16, 8, 1, GRAPHICS_BUF_BASE, 0x00008000, 0x00008000, 0, 0, V_INFO_MM_PACKED, 1 }, #endif #endif { EOT }, }; static int gdc_init_done = FALSE; /* local functions */ static int map_gen_mode_num(int type, int color, int mode); static int probe_adapters(void); #define prologue(adp, flag, err) \ if (!gdc_init_done || !((adp)->va_flags & (flag))) \ return (err) /* a backdoor for the console driver */ static int gdc_configure(int flags) { probe_adapters(); biosadapter[0].va_flags |= V_ADP_INITIALIZED; if (!config_done(&biosadapter[0])) { if (vid_register(&biosadapter[0]) < 0) return 1; biosadapter[0].va_flags |= V_ADP_REGISTERED; } return 1; } /* local subroutines */ /* map a generic video mode to a known mode number */ static int map_gen_mode_num(int type, int color, int mode) { static struct { int from; int to; } mode_map[] = { { M_TEXT_80x25, M_PC98_80x25, }, #ifdef LINE30 { M_TEXT_80x30, M_PC98_80x30, }, #endif }; int i; for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) { if (mode_map[i].from == mode) return mode_map[i].to; } return mode; } static int verify_adapter(video_adapter_t *adp) { #ifndef GDC_NOGRAPHICS int i; if (PC98_SYSTEM_PARAMETER(0x45c) & 0x40) { /* PEGC exists */ adp->va_flags |= V_ADP_VESA; /* XXX */ } else { for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) { if (bios_vmode[i].vi_flags & V_INFO_VESA) bios_vmode[i].vi_mode = NA; } } #endif return 0; } /* probe video adapters and return the number of detected adapters */ static int probe_adapters(void) { video_info_t info; /* do this test only once */ if (gdc_init_done) return 1; gdc_init_done = TRUE; biosadapter[0] = adapter_init_value[0]; biosadapter[0].va_flags |= V_ADP_PROBED; biosadapter[0].va_mode = biosadapter[0].va_initial_mode = biosadapter[0].va_initial_bios_mode; if ((PC98_SYSTEM_PARAMETER(0x597) & 0x80) || (PC98_SYSTEM_PARAMETER(0x458) & 0x80)) { gdc_FH = (inb(0x9a8) & 1) ? _31KHZ : _24KHZ; } else { gdc_FH = _24KHZ; } gdc_get_info(&biosadapter[0], biosadapter[0].va_initial_mode, &info); initialize_gdc(T25_G400, info.vi_flags & V_INFO_GRAPHICS); biosadapter[0].va_window = BIOS_PADDRTOVADDR(info.vi_window); biosadapter[0].va_window_size = info.vi_window_size; biosadapter[0].va_window_gran = info.vi_window_gran; biosadapter[0].va_buffer = 0; biosadapter[0].va_buffer_size = 0; if (info.vi_flags & V_INFO_GRAPHICS) { switch (info.vi_depth/info.vi_planes) { case 1: biosadapter[0].va_line_width = info.vi_width/8; break; case 2: biosadapter[0].va_line_width = info.vi_width/4; break; case 4: biosadapter[0].va_line_width = info.vi_width/2; break; case 8: default: /* shouldn't happen */ biosadapter[0].va_line_width = info.vi_width; break; } } else { biosadapter[0].va_line_width = info.vi_width; } bcopy(&info, &biosadapter[0].va_info, sizeof(info)); verify_adapter(&biosadapter[0]); return 1; } static void master_gdc_cmd(unsigned int cmd) { while ( (inb(TEXT_GDC) & 2) != 0); outb(TEXT_GDC+2, cmd); } static void master_gdc_prm(unsigned int pmtr) { while ( (inb(TEXT_GDC) & 2) != 0); outb(TEXT_GDC, pmtr); } static void master_gdc_word_prm(unsigned int wpmtr) { master_gdc_prm(wpmtr & 0x00ff); master_gdc_prm((wpmtr >> 8) & 0x00ff); } #ifdef LINE30 static void master_gdc_fifo_empty(void) { while ( (inb(TEXT_GDC) & 4) == 0); } #endif static void master_gdc_wait_vsync(void) { while ( (inb(TEXT_GDC) & 0x20) != 0); while ( (inb(TEXT_GDC) & 0x20) == 0); } static void gdc_cmd(unsigned int cmd) { while ( (inb(GRAPHIC_GDC) & 2) != 0); outb( GRAPHIC_GDC+2, cmd); } #ifdef LINE30 static void gdc_prm(unsigned int pmtr) { while ( (inb(GRAPHIC_GDC) & 2) != 0); outb( GRAPHIC_GDC, pmtr); } static void gdc_word_prm(unsigned int wpmtr) { gdc_prm(wpmtr & 0x00ff); gdc_prm((wpmtr >> 8) & 0x00ff); } static void gdc_fifo_empty(void) { while ( (inb(GRAPHIC_GDC) & 0x04) == 0); } #endif static void gdc_wait_vsync(void) { while ( (inb(GRAPHIC_GDC) & 0x20) != 0); while ( (inb(GRAPHIC_GDC) & 0x20) == 0); } #ifdef LINE30 static int check_gdc_clock(void) { if ((inb(IO_SYSPORT) & 0x80) == 0){ return _5MHZ; } else { return _2_5MHZ; } } #endif static void initialize_gdc(unsigned int mode, int isGraph) { #ifdef LINE30 /* start 30line initialize */ int m_mode, s_mode, gdc_clock, hsync_clock; gdc_clock = check_gdc_clock(); m_mode = (mode == T25_G400) ? _25L : _30L; s_mode = 2*mode+gdc_clock; gdc_INFO = m_mode; master_gdc_wait_vsync(); if ((PC98_SYSTEM_PARAMETER(0x597) & 0x80) || (PC98_SYSTEM_PARAMETER(0x458) & 0x80)) { if (PC98_SYSTEM_PARAMETER(0x481) & 0x08) { hsync_clock = (m_mode == _25L) ? gdc_FH : _31KHZ; outb(0x9a8, (hsync_clock == _31KHZ) ? 1 : 0); } else { hsync_clock = gdc_FH; } } else { hsync_clock = _24KHZ; } if ((gdc_clock == _2_5MHZ) && (slave_param[hsync_clock][s_mode][GDC_LF] > 400)) { outb(0x6a, 0x83); outb(0x6a, 0x85); gdc_clock = _5MHZ; s_mode = 2*mode+gdc_clock; } master_gdc_cmd(_GDC_RESET); master_gdc_cmd(_GDC_MASTER); gdc_cmd(_GDC_RESET); gdc_cmd(_GDC_SLAVE); /* GDC Master */ master_gdc_cmd(_GDC_SYNC); master_gdc_prm(0x00); /* flush less */ /* text & graph */ master_gdc_prm(master_param[hsync_clock][m_mode][GDC_CR]); master_gdc_word_prm(((master_param[hsync_clock][m_mode][GDC_HFP] << 10) + (master_param[hsync_clock][m_mode][GDC_VS] << 5) + master_param[hsync_clock][m_mode][GDC_HS])); master_gdc_prm(master_param[hsync_clock][m_mode][GDC_HBP]); master_gdc_prm(master_param[hsync_clock][m_mode][GDC_VFP]); master_gdc_word_prm(((master_param[hsync_clock][m_mode][GDC_VBP] << 10) + (master_param[hsync_clock][m_mode][GDC_LF]))); master_gdc_fifo_empty(); master_gdc_cmd(_GDC_PITCH); master_gdc_prm(MasterPCH); master_gdc_fifo_empty(); /* GDC slave */ gdc_cmd(_GDC_SYNC); gdc_prm(0x06); gdc_prm(slave_param[hsync_clock][s_mode][GDC_CR]); gdc_word_prm((slave_param[hsync_clock][s_mode][GDC_HFP] << 10) + (slave_param[hsync_clock][s_mode][GDC_VS] << 5) + (slave_param[hsync_clock][s_mode][GDC_HS])); gdc_prm(slave_param[hsync_clock][s_mode][GDC_HBP]); gdc_prm(slave_param[hsync_clock][s_mode][GDC_VFP]); gdc_word_prm((slave_param[hsync_clock][s_mode][GDC_VBP] << 10) + (slave_param[hsync_clock][s_mode][GDC_LF])); gdc_fifo_empty(); gdc_cmd(_GDC_PITCH); gdc_prm(SlavePCH[gdc_clock]); gdc_fifo_empty(); /* set Master GDC scroll param */ master_gdc_wait_vsync(); master_gdc_wait_vsync(); master_gdc_wait_vsync(); master_gdc_cmd(_GDC_SCROLL); master_gdc_word_prm(0); master_gdc_word_prm((master_param[hsync_clock][m_mode][GDC_LF] << 4) | 0x0000); master_gdc_fifo_empty(); /* set Slave GDC scroll param */ gdc_wait_vsync(); gdc_cmd(_GDC_SCROLL); gdc_word_prm(0); if (gdc_clock == _5MHZ) { gdc_word_prm((SlaveScrlLF[mode] << 4) | 0x4000); } else { gdc_word_prm(SlaveScrlLF[mode] << 4); } gdc_fifo_empty(); gdc_word_prm(0); if (gdc_clock == _5MHZ) { gdc_word_prm((SlaveScrlLF[mode] << 4) | 0x4000); } else { gdc_word_prm(SlaveScrlLF[mode] << 4); } gdc_fifo_empty(); /* sync start */ gdc_cmd(isGraph ? _GDC_START : _GDC_STOP); gdc_wait_vsync(); gdc_wait_vsync(); gdc_wait_vsync(); master_gdc_cmd(isGraph ? _GDC_STOP : _GDC_START); #else master_gdc_wait_vsync(); master_gdc_cmd(isGraph ? _GDC_STOP : _GDC_START); /* text */ gdc_wait_vsync(); gdc_cmd(isGraph ? _GDC_START : _GDC_STOP); /* graphics */ #endif } #ifndef GDC_NOGRAPHICS static u_char b_palette[] = { /* R G B */ 0x00, 0x00, 0x00, /* 0 */ 0x00, 0x00, 0x7f, /* 1 */ 0x7f, 0x00, 0x00, /* 2 */ 0x7f, 0x00, 0x7f, /* 3 */ 0x00, 0x7f, 0x00, /* 4 */ 0x00, 0x7f, 0x7f, /* 5 */ 0x7f, 0x7f, 0x00, /* 6 */ 0x7f, 0x7f, 0x7f, /* 7 */ 0x40, 0x40, 0x40, /* 8 */ 0x00, 0x00, 0xff, /* 9 */ 0xff, 0x00, 0x00, /* 10 */ 0xff, 0x00, 0xff, /* 11 */ 0x00, 0xff, 0x00, /* 12 */ 0x00, 0xff, 0xff, /* 13 */ 0xff, 0xff, 0x00, /* 14 */ 0xff, 0xff, 0xff, /* 15 */ }; #endif static int gdc_load_palette(video_adapter_t *adp, u_char *palette) { #ifndef GDC_NOGRAPHICS int i; if (adp->va_info.vi_flags & V_INFO_VESA) { gdc_wait_vsync(); for (i = 0; i < 256; ++i) { outb(0xa8, i); outb(0xac, *palette++); /* R */ outb(0xaa, *palette++); /* G */ outb(0xae, *palette++); /* B */ } } else { /* * XXX - Even though PC-98 text color is independent of palette, * we should set palette in text mode. * Because the background color of text mode is palette 0's one. */ outb(0x6a, 1); /* 16 colors mode */ bcopy(palette, b_palette, sizeof(b_palette)); gdc_wait_vsync(); for (i = 0; i < 16; ++i) { outb(0xa8, i); outb(0xac, *palette++ >> 4); /* R */ outb(0xaa, *palette++ >> 4); /* G */ outb(0xae, *palette++ >> 4); /* B */ } } #endif return 0; } static int gdc_save_palette(video_adapter_t *adp, u_char *palette) { #ifndef GDC_NOGRAPHICS int i; if (adp->va_info.vi_flags & V_INFO_VESA) { for (i = 0; i < 256; ++i) { outb(0xa8, i); *palette++ = inb(0xac); /* R */ *palette++ = inb(0xaa); /* G */ *palette++ = inb(0xae); /* B */ } } else { bcopy(b_palette, palette, sizeof(b_palette)); } #endif return 0; } static int gdc_set_origin(video_adapter_t *adp, off_t offset) { #ifndef GDC_NOGRAPHICS if (adp->va_info.vi_flags & V_INFO_VESA) { writew(BIOS_PADDRTOVADDR(0x000e0004), offset >> 15); } #endif return 0; } /* entry points */ static int gdc_err(video_adapter_t *adp, ...) { return ENODEV; } static int gdc_probe(int unit, video_adapter_t **adpp, void *arg, int flags) { probe_adapters(); if (unit >= 1) return ENXIO; *adpp = &biosadapter[unit]; return 0; } static int gdc_init(int unit, video_adapter_t *adp, int flags) { if ((unit >= 1) || (adp == NULL) || !probe_done(adp)) return ENXIO; if (!init_done(adp)) { /* nothing to do really... */ adp->va_flags |= V_ADP_INITIALIZED; } if (!config_done(adp)) { if (vid_register(adp) < 0) return ENXIO; adp->va_flags |= V_ADP_REGISTERED; } return 0; } /* * get_info(): * Return the video_info structure of the requested video mode. */ static int gdc_get_info(video_adapter_t *adp, int mode, video_info_t *info) { int i; if (!gdc_init_done) return ENXIO; mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode); for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) { if (bios_vmode[i].vi_mode == NA) continue; if (mode == bios_vmode[i].vi_mode) { *info = bios_vmode[i]; info->vi_buffer_size = info->vi_window_size*info->vi_planes; return 0; } } return EINVAL; } /* * query_mode(): * Find a video mode matching the requested parameters. * Fields filled with 0 are considered "don't care" fields and * match any modes. */ static int gdc_query_mode(video_adapter_t *adp, video_info_t *info) { int i; if (!gdc_init_done) return ENXIO; for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) { if (bios_vmode[i].vi_mode == NA) continue; if ((info->vi_width != 0) && (info->vi_width != bios_vmode[i].vi_width)) continue; if ((info->vi_height != 0) && (info->vi_height != bios_vmode[i].vi_height)) continue; if ((info->vi_cwidth != 0) && (info->vi_cwidth != bios_vmode[i].vi_cwidth)) continue; if ((info->vi_cheight != 0) && (info->vi_cheight != bios_vmode[i].vi_cheight)) continue; if ((info->vi_depth != 0) && (info->vi_depth != bios_vmode[i].vi_depth)) continue; if ((info->vi_planes != 0) && (info->vi_planes != bios_vmode[i].vi_planes)) continue; /* XXX: should check pixel format, memory model */ if ((info->vi_flags != 0) && (info->vi_flags != bios_vmode[i].vi_flags)) continue; /* verify if this mode is supported on this adapter */ if (gdc_get_info(adp, bios_vmode[i].vi_mode, info)) continue; return 0; } return ENODEV; } /* * set_mode(): * Change the video mode. */ static int gdc_set_mode(video_adapter_t *adp, int mode) { video_info_t info; prologue(adp, V_ADP_MODECHANGE, ENODEV); mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode); if (gdc_get_info(adp, mode, &info)) return EINVAL; switch (info.vi_mode) { #ifndef GDC_NOGRAPHICS case M_PC98_PEGC640x480: /* PEGC 640x480 */ initialize_gdc(T30_G480, info.vi_flags & V_INFO_GRAPHICS); break; case M_PC98_PEGC640x400: /* PEGC 640x400 */ case M_PC98_EGC640x400: /* EGC GRAPHICS */ #endif case M_PC98_80x25: /* VGA TEXT */ initialize_gdc(T25_G400, info.vi_flags & V_INFO_GRAPHICS); break; case M_PC98_80x30: /* VGA TEXT */ initialize_gdc(T30_G400, info.vi_flags & V_INFO_GRAPHICS); break; default: break; } #ifndef GDC_NOGRAPHICS if (info.vi_flags & V_INFO_VESA) { outb(0x6a, 0x07); /* enable mode F/F change */ outb(0x6a, 0x21); /* enhanced graphics */ if (info.vi_height > 400) outb(0x6a, 0x69); /* 800 lines */ writeb(BIOS_PADDRTOVADDR(0x000e0100), 0); /* packed pixel */ } else { if (adp->va_flags & V_ADP_VESA) { outb(0x6a, 0x07); /* enable mode F/F change */ outb(0x6a, 0x20); /* normal graphics */ outb(0x6a, 0x68); /* 400 lines */ } outb(0x6a, 1); /* 16 colors */ } #endif adp->va_mode = mode; adp->va_flags &= ~V_ADP_COLOR; adp->va_flags |= (info.vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0; #if 0 adp->va_crtc_addr = (adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC; #endif adp->va_window = BIOS_PADDRTOVADDR(info.vi_window); adp->va_window_size = info.vi_window_size; adp->va_window_gran = info.vi_window_gran; if (info.vi_buffer_size == 0) { adp->va_buffer = 0; adp->va_buffer_size = 0; } else { adp->va_buffer = BIOS_PADDRTOVADDR(info.vi_buffer); adp->va_buffer_size = info.vi_buffer_size; } if (info.vi_flags & V_INFO_GRAPHICS) { switch (info.vi_depth/info.vi_planes) { case 1: adp->va_line_width = info.vi_width/8; break; case 2: adp->va_line_width = info.vi_width/4; break; case 4: adp->va_line_width = info.vi_width/2; break; case 8: default: /* shouldn't happen */ adp->va_line_width = info.vi_width; break; } } else { adp->va_line_width = info.vi_width; } bcopy(&info, &adp->va_info, sizeof(info)); /* move hardware cursor out of the way */ - (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1); + vidd_set_hw_cursor(adp, -1, -1); return 0; } /* * set_border(): * Change the border color. */ static int gdc_set_border(video_adapter_t *adp, int color) { outb(0x6c, color << 4); return 0; } /* * save_state(): * Read video card register values. */ static int gdc_save_state(video_adapter_t *adp, void *p, size_t size) { return ENODEV; } /* * load_state(): * Set video card registers at once. */ static int gdc_load_state(video_adapter_t *adp, void *p) { return ENODEV; } /* * read_hw_cursor(): * Read the position of the hardware text cursor. */ static int gdc_read_hw_cursor(video_adapter_t *adp, int *col, int *row) { u_int16_t off; int s; if (!gdc_init_done) return ENXIO; if (adp->va_info.vi_flags & V_INFO_GRAPHICS) return ENODEV; s = spltty(); master_gdc_cmd(0xe0); /* _GDC_CSRR */ while((inb(TEXT_GDC + 0) & 0x1) == 0) {} /* GDC wait */ off = inb(TEXT_GDC + 2); /* EADl */ off |= (inb(TEXT_GDC + 2) << 8); /* EADh */ inb(TEXT_GDC + 2); /* dummy */ inb(TEXT_GDC + 2); /* dummy */ inb(TEXT_GDC + 2); /* dummy */ splx(s); if (off >= ROW*COL) off = 0; *row = off / adp->va_info.vi_width; *col = off % adp->va_info.vi_width; return 0; } /* * set_hw_cursor(): * Move the hardware text cursor. If col and row are both -1, * the cursor won't be shown. */ static int gdc_set_hw_cursor(video_adapter_t *adp, int col, int row) { u_int16_t off; int s; if (!gdc_init_done) return ENXIO; if ((col == -1) && (row == -1)) { off = -1; } else { if (adp->va_info.vi_flags & V_INFO_GRAPHICS) return ENODEV; off = row*adp->va_info.vi_width + col; } s = spltty(); master_gdc_cmd(0x49); /* _GDC_CSRW */ master_gdc_word_prm(off); splx(s); return 0; } /* * set_hw_cursor_shape(): * Change the shape of the hardware text cursor. If the height is zero * or negative, the cursor won't be shown. */ static int gdc_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, int celsize, int blink) { int start; int end; int s; if (!gdc_init_done) return ENXIO; start = celsize - (base + height); end = celsize - base - 1; #if 0 /* * muPD7220 GDC has anomaly that if end == celsize - 1 then start * must be 0, otherwise the cursor won't be correctly shown * in the first row in the screen. We shall set end to celsize - 2; * if end == celsize -1 && start > 0. XXX */ if ((end == celsize - 1) && (start > 0) && (start < end)) --end; #endif s = spltty(); master_gdc_cmd(0x4b); /* _GDC_CSRFORM */ master_gdc_prm(((height > 0) ? 0x80 : 0) /* cursor on/off */ | ((celsize - 1) & 0x1f)); /* cel size */ master_gdc_word_prm(((end & 0x1f) << 11) /* end line */ | (12 << 6) /* blink rate */ | (blink ? 0 : 0x20) /* blink on/off */ | (start & 0x1f)); /* start line */ splx(s); return 0; } /* * blank_display() * Put the display in power save/power off mode. */ static int gdc_blank_display(video_adapter_t *adp, int mode) { int s; static int standby = 0; if (!gdc_init_done) return ENXIO; s = splhigh(); switch (mode) { case V_DISPLAY_SUSPEND: case V_DISPLAY_STAND_BY: outb(0x09a2, 0x80 | 0x40); /* V/H-SYNC mask */ if (inb(0x09a2) == (0x80 | 0x40)) standby = 1; /* FALLTHROUGH */ case V_DISPLAY_BLANK: while (!(inb(TEXT_GDC) & 0x20)) /* V-SYNC wait */ ; outb(TEXT_GDC + 8, 0x0e); /* DISP off */ break; case V_DISPLAY_ON: while (!(inb(TEXT_GDC) & 0x20)) /* V-SYNC wait */ ; outb(TEXT_GDC + 8, 0x0f); /* DISP on */ if (standby) { outb(0x09a2, 0x00); /* V/H-SYNC unmask */ standby = 0; } break; } splx(s); return 0; } /* * mmap(): * Mmap frame buffer. */ static int gdc_mmap_buf(video_adapter_t *adp, vm_offset_t offset, vm_offset_t *paddr, int prot) { /* FIXME: is this correct? XXX */ if (offset > VIDEO_BUF_SIZE - PAGE_SIZE) return -1; *paddr = adp->va_info.vi_window + offset; return 0; } #ifndef GDC_NOGRAPHICS static void planar_fill(video_adapter_t *adp, int val) { outb(0x7c, 0x80); /* GRCG on & TDW mode */ outb(0x7e, 0); /* tile B */ outb(0x7e, 0); /* tile R */ outb(0x7e, 0); /* tile G */ outb(0x7e, 0); /* tile I */ fillw_io(0, adp->va_window, 0x8000 / 2); /* XXX */ outb(0x7c, 0); /* GRCG off */ } static void packed_fill(video_adapter_t *adp, int val) { int length; int at; /* position in the frame buffer */ int l; at = 0; length = adp->va_line_width*adp->va_info.vi_height; while (length > 0) { l = imin(length, adp->va_window_size); - (*vidsw[adp->va_index]->set_win_org)(adp, at); + vidd_set_win_org(adp, at); bzero_io(adp->va_window, l); length -= l; at += l; } } static int gdc_clear(video_adapter_t *adp) { switch (adp->va_info.vi_mem_model) { case V_INFO_MM_TEXT: /* do nothing? XXX */ break; case V_INFO_MM_PLANAR: planar_fill(adp, 0); break; case V_INFO_MM_PACKED: packed_fill(adp, 0); break; } return 0; } #else /* GDC_NOGRAPHICS */ static int gdc_clear(video_adapter_t *adp) { return 0; } #endif /* GDC_NOGRAPHICS */ static int gdc_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) { return ENODEV; } static int gdc_bitblt(video_adapter_t *adp,...) { /* FIXME */ return ENODEV; } static int gdc_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg) { switch (cmd) { case FBIO_GETWINORG: /* get frame buffer window origin */ *(u_int *)arg = 0; return 0; case FBIO_SETWINORG: /* set frame buffer window origin */ case FBIO_SETDISPSTART: /* set display start address */ case FBIO_SETLINEWIDTH: /* set scan line length in pixel */ case FBIO_GETPALETTE: /* get color palette */ case FBIO_SETPALETTE: /* set color palette */ case FBIOGETCMAP: /* get color palette */ case FBIOPUTCMAP: /* set color palette */ return ENODEV; case FBIOGTYPE: /* get frame buffer type info. */ ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type); ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height; ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width; ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth; if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8)) ((struct fbtype *)arg)->fb_cmsize = 0; else ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth; ((struct fbtype *)arg)->fb_size = adp->va_buffer_size; return 0; default: return fb_commonioctl(adp, cmd, arg); } } /* * diag(): * Print some information about the video adapter and video modes, * with requested level of details. */ static int gdc_diag(video_adapter_t *adp, int level) { #if defined(FB_DEBUG) && FB_DEBUG > 1 int i; #endif if (!gdc_init_done) return ENXIO; fb_dump_adp_info(DRIVER_NAME, adp, level); #if defined(FB_DEBUG) && FB_DEBUG > 1 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) { if (bios_vmode[i].vi_mode == NA) continue; if (get_mode_param(bios_vmode[i].vi_mode) == NULL) continue; fb_dump_mode_info(DRIVER_NAME, adp, &bios_vmode[i], level); } #endif return 0; } Index: head/sys/pc98/cbus/scgdcrndr.c =================================================================== --- head/sys/pc98/cbus/scgdcrndr.c (revision 174984) +++ head/sys/pc98/cbus/scgdcrndr.c (revision 174985) @@ -1,210 +1,208 @@ /*- * Copyright (c) 1999 FreeBSD(98) Porting Team. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer as * the first lines of this file unmodified. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include "opt_syscons.h" #include "opt_gdc.h" #include #include #include #include #include #include #include #include #ifndef SC_RENDER_DEBUG #define SC_RENDER_DEBUG 0 #endif static vr_clear_t gdc_txtclear; static vr_draw_border_t gdc_txtborder; static vr_draw_t gdc_txtdraw; static vr_set_cursor_t gdc_txtcursor_shape; static vr_draw_cursor_t gdc_txtcursor; #ifndef SC_NO_CUTPASTE static vr_draw_mouse_t gdc_txtmouse; #else #define gdc_txtmouse (vr_draw_mouse_t *)gdc_nop #endif #ifndef SC_NO_MODE_CHANGE static vr_draw_border_t gdc_grborder; #endif static void gdc_nop(scr_stat *scp, ...); static sc_rndr_sw_t txtrndrsw = { (vr_init_t *)gdc_nop, gdc_txtclear, gdc_txtborder, gdc_txtdraw, gdc_txtcursor_shape, gdc_txtcursor, (vr_blink_cursor_t *)gdc_nop, (vr_set_mouse_t *)gdc_nop, gdc_txtmouse, }; RENDERER(gdc, 0, txtrndrsw, gdc_set); #ifndef SC_NO_MODE_CHANGE static sc_rndr_sw_t grrndrsw = { (vr_init_t *)gdc_nop, (vr_clear_t *)gdc_nop, gdc_grborder, (vr_draw_t *)gdc_nop, (vr_set_cursor_t *)gdc_nop, (vr_draw_cursor_t *)gdc_nop, (vr_blink_cursor_t *)gdc_nop, (vr_set_mouse_t *)gdc_nop, (vr_draw_mouse_t *)gdc_nop, }; RENDERER(gdc, GRAPHICS_MODE, grrndrsw, gdc_set); #endif /* SC_NO_MODE_CHANGE */ RENDERER_MODULE(gdc, gdc_set); static void gdc_nop(scr_stat *scp, ...) { } /* text mode renderer */ static void gdc_txtclear(scr_stat *scp, int c, int attr) { sc_vtb_clear(&scp->scr, c, attr); } static void gdc_txtborder(scr_stat *scp, int color) { - (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color); + vidd_set_border(scp->sc->adp, color); } static void gdc_txtdraw(scr_stat *scp, int from, int count, int flip) { vm_offset_t p; int c; int a; if (from + count > scp->xsize*scp->ysize) count = scp->xsize*scp->ysize - from; if (flip) { for (p = sc_vtb_pointer(&scp->scr, from); count-- > 0; ++from) { c = sc_vtb_getc(&scp->vtb, from); a = sc_vtb_geta(&scp->vtb, from); #if 0 a ^= 0x0800; #else a = (a & 0x8800) | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4); #endif p = sc_vtb_putchar(&scp->scr, p, c, a); } } else { sc_vtb_copy(&scp->vtb, from, &scp->scr, from, count); } } static void gdc_txtcursor_shape(scr_stat *scp, int base, int height, int blink) { if (base < 0 || base >= scp->font_size) return; /* the caller may set height <= 0 in order to disable the cursor */ - (*vidsw[scp->sc->adapter]->set_hw_cursor_shape)(scp->sc->adp, - base, height, - scp->font_size, blink); + vidd_set_hw_cursor_shape(scp->sc->adp, base, height, scp->font_size, + blink); } static void gdc_txtcursor(scr_stat *scp, int at, int blink, int on, int flip) { if (on) { scp->status |= VR_CURSOR_ON; - (*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp, - at%scp->xsize, at/scp->xsize); + vidd_set_hw_cursor(scp->sc->adp, at%scp->xsize, + at/scp->xsize); } else { if (scp->status & VR_CURSOR_ON) - (*vidsw[scp->sc->adapter]->set_hw_cursor)(scp->sc->adp, - -1, -1); + vidd_set_hw_cursor(scp->sc->adp, -1, -1); scp->status &= ~VR_CURSOR_ON; } } #ifndef SC_NO_CUTPASTE static void draw_txtmouse(scr_stat *scp, int x, int y) { int at; int a; at = (y/scp->font_size - scp->yoff)*scp->xsize + x/8 - scp->xoff; a = sc_vtb_geta(&scp->vtb, at); #if 0 a ^= 0x0800; #else a = (a & 0x8800) | ((a & 0x7000) >> 4) | ((a & 0x0700) << 4); #endif sc_vtb_putc(&scp->scr, at, sc_vtb_getc(&scp->scr, at), a); } static void remove_txtmouse(scr_stat *scp, int x, int y) { } static void gdc_txtmouse(scr_stat *scp, int x, int y, int on) { if (on) draw_txtmouse(scp, x, y); else remove_txtmouse(scp, x, y); } #endif /* SC_NO_CUTPASTE */ #ifndef SC_NO_MODE_CHANGE /* graphics mode renderer */ static void gdc_grborder(scr_stat *scp, int color) { - (*vidsw[scp->sc->adapter]->set_border)(scp->sc->adp, color); + vidd_set_border(scp->sc->adp, color); } #endif /* SC_NO_MODE_CHANGE */