Home | History | Annotate | Line # | Download | only in pci
voodoofb.c revision 1.28.2.3
      1  1.28.2.3      yamt /*	$NetBSD: voodoofb.c,v 1.28.2.3 2013/01/16 05:33:31 yamt Exp $	*/
      2       1.1  macallan 
      3       1.1  macallan /*
      4  1.28.2.1      yamt  * Copyright (c) 2005, 2006, 2012 Michael Lorenz
      5       1.1  macallan  * All rights reserved.
      6       1.1  macallan  *
      7       1.1  macallan  * Redistribution and use in source and binary forms, with or without
      8       1.1  macallan  * modification, are permitted provided that the following conditions
      9       1.1  macallan  * are met:
     10       1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     11       1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     12       1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     14       1.1  macallan  *    documentation and/or other materials provided with the distribution.
     15       1.1  macallan  *
     16       1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17       1.1  macallan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18       1.1  macallan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19       1.1  macallan  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20       1.1  macallan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21       1.1  macallan  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22       1.1  macallan  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23       1.1  macallan  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24       1.1  macallan  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25       1.1  macallan  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26       1.1  macallan  */
     27       1.1  macallan 
     28       1.1  macallan /*
     29       1.1  macallan  * A console driver for 3Dfx Voodoo3 graphics boards
     30       1.1  macallan  * Thanks to Andreas Drewke (andreas_dr (at) gmx.de) for his Voodoo3 driver for BeOS
     31       1.1  macallan  * which I used as reference / documentation
     32       1.1  macallan  */
     33       1.1  macallan 
     34       1.1  macallan #include <sys/cdefs.h>
     35  1.28.2.3      yamt __KERNEL_RCSID(0, "$NetBSD: voodoofb.c,v 1.28.2.3 2013/01/16 05:33:31 yamt Exp $");
     36       1.1  macallan 
     37       1.1  macallan #include <sys/param.h>
     38       1.1  macallan #include <sys/systm.h>
     39       1.1  macallan #include <sys/kernel.h>
     40       1.1  macallan #include <sys/device.h>
     41       1.1  macallan #include <sys/malloc.h>
     42       1.1  macallan #include <sys/callout.h>
     43      1.14      elad #include <sys/kauth.h>
     44       1.1  macallan 
     45       1.1  macallan #include <dev/pci/pcivar.h>
     46       1.1  macallan #include <dev/pci/pcireg.h>
     47       1.1  macallan #include <dev/pci/pcidevs.h>
     48       1.1  macallan #include <dev/pci/pciio.h>
     49       1.1  macallan #include <dev/pci/voodoofbreg.h>
     50       1.1  macallan 
     51       1.1  macallan #include <dev/wscons/wsdisplayvar.h>
     52       1.1  macallan #include <dev/wscons/wsconsio.h>
     53       1.1  macallan #include <dev/wsfont/wsfont.h>
     54       1.1  macallan #include <dev/rasops/rasops.h>
     55       1.1  macallan #include <dev/wscons/wsdisplay_vconsvar.h>
     56      1.27    cegger #include <dev/pci/wsdisplay_pci.h>
     57       1.1  macallan 
     58  1.28.2.1      yamt #include <dev/i2c/i2cvar.h>
     59  1.28.2.1      yamt #include <dev/i2c/i2c_bitbang.h>
     60  1.28.2.1      yamt #include <dev/i2c/ddcvar.h>
     61  1.28.2.1      yamt #include <dev/videomode/videomode.h>
     62  1.28.2.1      yamt #include <dev/videomode/edidvar.h>
     63  1.28.2.1      yamt #include <dev/videomode/edidreg.h>
     64  1.28.2.1      yamt 
     65       1.1  macallan #include "opt_wsemul.h"
     66       1.1  macallan 
     67       1.1  macallan struct voodoofb_softc {
     68      1.18     joerg 	device_t sc_dev;
     69       1.1  macallan 	pci_chipset_tag_t sc_pc;
     70       1.1  macallan 	pcitag_t sc_pcitag;
     71       1.9  jmcneill 	struct pci_attach_args sc_pa;
     72       1.1  macallan 
     73       1.1  macallan 	bus_space_tag_t sc_memt;
     74       1.1  macallan 	bus_space_tag_t sc_iot;
     75       1.1  macallan 	bus_space_handle_t sc_memh;
     76       1.1  macallan 
     77       1.1  macallan 	bus_space_tag_t sc_regt;
     78       1.1  macallan 	bus_space_tag_t sc_ioregt;
     79       1.1  macallan 	bus_space_handle_t sc_regh;
     80       1.1  macallan 	bus_space_handle_t sc_ioregh;
     81       1.1  macallan 	bus_addr_t sc_regs, sc_fb, sc_ioreg;
     82       1.1  macallan 	bus_size_t sc_regsize, sc_fbsize, sc_ioregsize;
     83       1.1  macallan 
     84       1.1  macallan 	void *sc_ih;
     85  1.28.2.3      yamt 
     86  1.28.2.3      yamt #define MAX_CLOCK_VB	270000	/* Voodoo Banshee */
     87  1.28.2.3      yamt #define MAX_CLOCK_V3	300000	/* Voodoo3 */
     88  1.28.2.3      yamt #define MAX_CLOCK_V45	350000	/* Voodoo4/5 (not yet) */
     89  1.28.2.3      yamt 	uint32_t sc_max_clock;
     90       1.1  macallan 
     91  1.28.2.1      yamt 	size_t sc_memsize;
     92  1.28.2.1      yamt 	int sc_memtype;
     93       1.1  macallan 
     94  1.28.2.1      yamt 	int sc_bits_per_pixel;
     95  1.28.2.1      yamt 	int sc_width, sc_height, sc_linebytes;
     96      1.23  macallan 	const struct videomode *sc_videomode;
     97       1.1  macallan 
     98  1.28.2.1      yamt 	/* glyph cache */
     99  1.28.2.1      yamt 	long sc_defattr, sc_kernattr;
    100  1.28.2.1      yamt 	uint32_t sc_glyphs_defattr[256];
    101  1.28.2.1      yamt 	uint32_t sc_glyphs_kernattr[256];
    102  1.28.2.1      yamt 	int sc_numglyphs, sc_usedglyphs;
    103  1.28.2.1      yamt 	uint32_t sc_cache;	/* offset where cache starts */
    104  1.28.2.1      yamt 	uint32_t sc_fmt;	/* *fmt register */
    105  1.28.2.1      yamt 	void *sc_font;
    106  1.28.2.1      yamt 
    107  1.28.2.1      yamt 	/* i2c stuff */
    108  1.28.2.1      yamt 	struct i2c_controller sc_i2c;
    109  1.28.2.1      yamt 	uint8_t sc_edid_data[128];
    110  1.28.2.1      yamt 	struct edid_info sc_edid_info;
    111  1.28.2.1      yamt 	uint32_t sc_i2creg;
    112  1.28.2.1      yamt 
    113       1.1  macallan 	int sc_mode;
    114       1.1  macallan 	uint32_t sc_bg;
    115       1.1  macallan 
    116       1.1  macallan 	u_char sc_cmap_red[256];
    117       1.1  macallan 	u_char sc_cmap_green[256];
    118       1.1  macallan 	u_char sc_cmap_blue[256];
    119       1.1  macallan 	int sc_dacw;
    120       1.1  macallan 
    121       1.1  macallan 	struct vcons_data vd;
    122       1.1  macallan };
    123       1.1  macallan 
    124       1.1  macallan struct voodoo_regs {
    125       1.1  macallan 	uint8_t vr_crtc[31];
    126       1.1  macallan 	uint8_t vr_graph[9];
    127       1.1  macallan 	uint8_t vr_attr[21];
    128       1.1  macallan 	uint8_t vr_seq[5];
    129       1.1  macallan };
    130       1.1  macallan 
    131       1.1  macallan static struct vcons_screen voodoofb_console_screen;
    132       1.1  macallan 
    133      1.18     joerg static int	voodoofb_match(device_t, cfdata_t, void *);
    134      1.18     joerg static void	voodoofb_attach(device_t, device_t, void *);
    135       1.1  macallan 
    136       1.9  jmcneill static int	voodoofb_drm_print(void *, const char *);
    137       1.9  jmcneill static int	voodoofb_drm_unmap(struct voodoofb_softc *);
    138       1.9  jmcneill static int	voodoofb_drm_map(struct voodoofb_softc *);
    139       1.9  jmcneill 
    140      1.18     joerg CFATTACH_DECL_NEW(voodoofb, sizeof(struct voodoofb_softc), voodoofb_match,
    141       1.1  macallan     voodoofb_attach, NULL, NULL);
    142       1.1  macallan 
    143      1.28  kiyohara static bool	voodoofb_is_console(struct voodoofb_softc *);
    144       1.1  macallan static void 	voodoofb_init(struct voodoofb_softc *);
    145       1.1  macallan 
    146       1.1  macallan static void	voodoofb_cursor(void *, int, int, int);
    147       1.1  macallan static void	voodoofb_putchar(void *, int, int, u_int, long);
    148  1.28.2.1      yamt static void	voodoofb_putchar_aa(void *, int, int, u_int, long);
    149       1.1  macallan static void	voodoofb_copycols(void *, int, int, int, int);
    150       1.1  macallan static void	voodoofb_erasecols(void *, int, int, int, long);
    151       1.1  macallan static void	voodoofb_copyrows(void *, int, int, int);
    152       1.1  macallan static void	voodoofb_eraserows(void *, int, int, long);
    153       1.1  macallan 
    154       1.1  macallan #if 0
    155       1.1  macallan static int	voodoofb_allocattr(void *, int, int, int, long *);
    156       1.1  macallan static void	voodoofb_scroll(void *, void *, int);
    157       1.1  macallan static int	voodoofb_load_font(void *, void *, struct wsdisplay_font *);
    158       1.1  macallan #endif
    159       1.1  macallan 
    160       1.1  macallan static int	voodoofb_putcmap(struct voodoofb_softc *,
    161       1.1  macallan 			    struct wsdisplay_cmap *);
    162       1.1  macallan static int 	voodoofb_getcmap(struct voodoofb_softc *,
    163       1.1  macallan 			    struct wsdisplay_cmap *);
    164       1.1  macallan static int 	voodoofb_putpalreg(struct voodoofb_softc *, uint8_t, uint8_t,
    165       1.1  macallan 			    uint8_t, uint8_t);
    166       1.1  macallan static void	voodoofb_bitblt(struct voodoofb_softc *, int, int, int, int,
    167       1.1  macallan 			    int, int);
    168       1.1  macallan static void	voodoofb_rectfill(struct voodoofb_softc *, int, int, int, int,
    169       1.1  macallan 			    int);
    170       1.1  macallan static void	voodoofb_rectinvert(struct voodoofb_softc *, int, int, int,
    171       1.1  macallan 			    int);
    172       1.1  macallan static void	voodoofb_setup_mono(struct voodoofb_softc *, int, int, int,
    173       1.1  macallan 			    int, uint32_t, uint32_t);
    174       1.1  macallan static void	voodoofb_feed_line(struct voodoofb_softc *, int, uint8_t *);
    175       1.1  macallan 
    176       1.1  macallan static void	voodoofb_wait_idle(struct voodoofb_softc *);
    177  1.28.2.1      yamt static void	voodoofb_init_glyphcache(struct voodoofb_softc *,
    178  1.28.2.1      yamt 			    struct rasops_info *);
    179       1.1  macallan 
    180       1.9  jmcneill #ifdef VOODOOFB_ENABLE_INTR
    181       1.1  macallan static int	voodoofb_intr(void *);
    182       1.9  jmcneill #endif
    183       1.1  macallan 
    184       1.1  macallan static void	voodoofb_set_videomode(struct voodoofb_softc *,
    185       1.1  macallan 			    const struct videomode *);
    186       1.1  macallan 
    187       1.1  macallan struct wsscreen_descr voodoofb_defaultscreen = {
    188       1.1  macallan 	"default",
    189       1.1  macallan 	0, 0,
    190       1.1  macallan 	NULL,
    191       1.1  macallan 	8, 16,
    192       1.1  macallan 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    193       1.6      cube 	NULL,
    194       1.1  macallan };
    195       1.1  macallan 
    196       1.1  macallan const struct wsscreen_descr *_voodoofb_scrlist[] = {
    197       1.1  macallan 	&voodoofb_defaultscreen,
    198       1.1  macallan 	/* XXX other formats, graphics screen? */
    199       1.1  macallan };
    200       1.1  macallan 
    201       1.1  macallan struct wsscreen_list voodoofb_screenlist = {
    202       1.1  macallan 	sizeof(_voodoofb_scrlist) / sizeof(struct wsscreen_descr *), _voodoofb_scrlist
    203       1.1  macallan };
    204       1.1  macallan 
    205       1.8  christos static int	voodoofb_ioctl(void *, void *, u_long, void *, int,
    206       1.2      jmmv 		    struct lwp *);
    207       1.2      jmmv static paddr_t	voodoofb_mmap(void *, void *, off_t, int);
    208       1.1  macallan 
    209       1.1  macallan static void	voodoofb_clearscreen(struct voodoofb_softc *);
    210       1.1  macallan static void	voodoofb_init_screen(void *, struct vcons_screen *, int,
    211       1.1  macallan 			    long *);
    212       1.1  macallan 
    213       1.1  macallan 
    214       1.1  macallan struct wsdisplay_accessops voodoofb_accessops = {
    215       1.1  macallan 	voodoofb_ioctl,
    216       1.1  macallan 	voodoofb_mmap,
    217       1.6      cube 	NULL,
    218       1.6      cube 	NULL,
    219       1.6      cube 	NULL,
    220       1.1  macallan 	NULL,	/* load_font */
    221       1.1  macallan 	NULL,	/* polls */
    222       1.1  macallan 	NULL,	/* scroll */
    223       1.1  macallan };
    224       1.1  macallan 
    225  1.28.2.1      yamt /* I2C glue */
    226  1.28.2.1      yamt static int voodoofb_i2c_acquire_bus(void *, int);
    227  1.28.2.1      yamt static void voodoofb_i2c_release_bus(void *, int);
    228  1.28.2.1      yamt static int voodoofb_i2c_send_start(void *, int);
    229  1.28.2.1      yamt static int voodoofb_i2c_send_stop(void *, int);
    230  1.28.2.1      yamt static int voodoofb_i2c_initiate_xfer(void *, i2c_addr_t, int);
    231  1.28.2.1      yamt static int voodoofb_i2c_read_byte(void *, uint8_t *, int);
    232  1.28.2.1      yamt static int voodoofb_i2c_write_byte(void *, uint8_t, int);
    233  1.28.2.1      yamt 
    234  1.28.2.1      yamt /* I2C bitbang glue */
    235  1.28.2.1      yamt static void voodoofb_i2cbb_set_bits(void *, uint32_t);
    236  1.28.2.1      yamt static void voodoofb_i2cbb_set_dir(void *, uint32_t);
    237  1.28.2.1      yamt static uint32_t voodoofb_i2cbb_read(void *);
    238  1.28.2.1      yamt 
    239  1.28.2.1      yamt static void voodoofb_setup_i2c(struct voodoofb_softc *);
    240  1.28.2.1      yamt 
    241  1.28.2.1      yamt static const struct i2c_bitbang_ops voodoofb_i2cbb_ops = {
    242  1.28.2.1      yamt 	voodoofb_i2cbb_set_bits,
    243  1.28.2.1      yamt 	voodoofb_i2cbb_set_dir,
    244  1.28.2.1      yamt 	voodoofb_i2cbb_read,
    245  1.28.2.1      yamt 	{
    246  1.28.2.1      yamt 		VSP_SDA0_IN,
    247  1.28.2.1      yamt 		VSP_SCL0_IN,
    248  1.28.2.1      yamt 		0,
    249  1.28.2.1      yamt 		0
    250  1.28.2.1      yamt 	}
    251  1.28.2.1      yamt };
    252  1.28.2.1      yamt 
    253  1.28.2.1      yamt extern const u_char rasops_cmap[768];
    254  1.28.2.1      yamt 
    255       1.1  macallan /*
    256       1.1  macallan  * Inline functions for getting access to register aperture.
    257       1.1  macallan  */
    258       1.1  macallan static inline void
    259       1.1  macallan voodoo3_write32(struct voodoofb_softc *sc, uint32_t reg, uint32_t val)
    260       1.1  macallan {
    261       1.1  macallan 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, val);
    262       1.1  macallan }
    263       1.1  macallan 
    264  1.28.2.1      yamt static inline void
    265  1.28.2.1      yamt voodoo3_write32s(struct voodoofb_softc *sc, uint32_t reg, uint32_t val)
    266  1.28.2.1      yamt {
    267  1.28.2.1      yamt 	bus_space_write_stream_4(sc->sc_regt, sc->sc_regh, reg, val);
    268  1.28.2.1      yamt }
    269       1.1  macallan static inline uint32_t
    270       1.1  macallan voodoo3_read32(struct voodoofb_softc *sc, uint32_t reg)
    271       1.1  macallan {
    272       1.1  macallan 	return bus_space_read_4(sc->sc_regt, sc->sc_regh, reg);
    273       1.1  macallan }
    274       1.1  macallan 
    275       1.1  macallan static inline void
    276       1.1  macallan voodoo3_write_crtc(struct voodoofb_softc *sc, uint8_t reg, uint8_t val)
    277       1.1  macallan {
    278       1.1  macallan 	bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, CRTC_INDEX - 0x300, reg);
    279       1.1  macallan 	bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, CRTC_DATA - 0x300, val);
    280       1.1  macallan }
    281       1.1  macallan 
    282       1.1  macallan static inline void
    283       1.1  macallan voodoo3_write_seq(struct voodoofb_softc *sc, uint8_t reg, uint8_t val)
    284       1.1  macallan {
    285       1.1  macallan 	bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, SEQ_INDEX - 0x300, reg);
    286       1.1  macallan 	bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, SEQ_DATA - 0x300, val);
    287       1.1  macallan }
    288       1.1  macallan 
    289       1.1  macallan static inline void
    290       1.1  macallan voodoo3_write_gra(struct voodoofb_softc *sc, uint8_t reg, uint8_t val)
    291       1.1  macallan {
    292       1.1  macallan 	bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, GRA_INDEX - 0x300, reg);
    293       1.1  macallan 	bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, GRA_DATA - 0x300, val);
    294       1.1  macallan }
    295       1.1  macallan 
    296       1.1  macallan static inline void
    297       1.1  macallan voodoo3_write_attr(struct voodoofb_softc *sc, uint8_t reg, uint8_t val)
    298       1.1  macallan {
    299       1.1  macallan 	volatile uint8_t junk;
    300       1.1  macallan 	uint8_t index;
    301       1.1  macallan 
    302       1.1  macallan 	junk = bus_space_read_1(sc->sc_ioregt, sc->sc_ioregh, IS1_R - 0x300);
    303       1.1  macallan 	index = bus_space_read_1(sc->sc_ioregt, sc->sc_ioregh, ATT_IW - 0x300);
    304       1.1  macallan 	bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, ATT_IW - 0x300, reg);
    305       1.1  macallan 	bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, ATT_IW - 0x300, val);
    306       1.1  macallan 	bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, ATT_IW - 0x300, index);
    307       1.1  macallan }
    308       1.1  macallan 
    309       1.1  macallan static inline void
    310       1.1  macallan vga_outb(struct voodoofb_softc *sc, uint32_t reg,  uint8_t val)
    311       1.1  macallan {
    312       1.1  macallan 	bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, reg - 0x300, val);
    313       1.1  macallan }
    314       1.1  macallan 
    315       1.1  macallan /* wait until there's room for len bytes in the FIFO */
    316       1.1  macallan static inline void
    317       1.1  macallan voodoo3_make_room(struct voodoofb_softc *sc, int len)
    318       1.1  macallan {
    319       1.1  macallan 	while ((voodoo3_read32(sc, STATUS) & 0x1f) < len);
    320       1.1  macallan }
    321       1.1  macallan 
    322       1.1  macallan static void
    323       1.1  macallan voodoofb_wait_idle(struct voodoofb_softc *sc)
    324       1.1  macallan {
    325       1.1  macallan 	int i = 0;
    326       1.1  macallan 
    327       1.1  macallan 	voodoo3_make_room(sc, 1);
    328       1.1  macallan 	voodoo3_write32(sc, COMMAND_3D, COMMAND_3D_NOP);
    329       1.1  macallan 
    330       1.1  macallan 	while (1) {
    331       1.1  macallan 		i = (voodoo3_read32(sc, STATUS) & STATUS_BUSY) ? 0 : i + 1;
    332       1.1  macallan 		if(i == 3) break;
    333       1.1  macallan 	}
    334       1.1  macallan }
    335       1.1  macallan 
    336       1.1  macallan static int
    337      1.18     joerg voodoofb_match(device_t parent, cfdata_t match, void *aux)
    338       1.1  macallan {
    339       1.1  macallan 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
    340       1.1  macallan 
    341       1.1  macallan 	if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
    342       1.1  macallan 	    PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
    343       1.1  macallan 		return 0;
    344       1.1  macallan 	if ((PCI_VENDOR(pa->pa_id)==PCI_VENDOR_3DFX) &&
    345       1.1  macallan 	    (PCI_PRODUCT(pa->pa_id)>=PCI_PRODUCT_3DFX_VOODOO3))
    346       1.1  macallan 		return 100;
    347  1.28.2.3      yamt 
    348  1.28.2.3      yamt 	if ((PCI_VENDOR(pa->pa_id)==PCI_VENDOR_3DFX) &&
    349  1.28.2.3      yamt 	    (PCI_PRODUCT(pa->pa_id)>=PCI_PRODUCT_3DFX_BANSHEE))
    350  1.28.2.3      yamt 		return 100;
    351       1.1  macallan 	return 0;
    352       1.1  macallan }
    353       1.1  macallan 
    354       1.1  macallan static void
    355      1.18     joerg voodoofb_attach(device_t parent, device_t self, void *aux)
    356       1.1  macallan {
    357      1.18     joerg 	struct voodoofb_softc *sc = device_private(self);
    358       1.1  macallan 	struct pci_attach_args *pa = aux;
    359       1.1  macallan 	struct wsemuldisplaydev_attach_args aa;
    360       1.1  macallan 	struct rasops_info *ri;
    361       1.9  jmcneill #ifdef VOODOOFB_ENABLE_INTR
    362       1.1  macallan 	pci_intr_handle_t ih;
    363       1.9  jmcneill 	const char *intrstr;
    364       1.9  jmcneill #endif
    365       1.1  macallan 	ulong defattr;
    366       1.6      cube 	int console, width, height, i, j;
    367      1.28  kiyohara 	prop_dictionary_t dict;
    368  1.28.2.1      yamt 	int linebytes, depth, flags;
    369       1.1  macallan 	uint32_t bg, fg, ul;
    370      1.18     joerg 
    371      1.18     joerg 	sc->sc_dev = self;
    372      1.18     joerg 
    373       1.3  macallan 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    374       1.1  macallan 	sc->sc_pc = pa->pa_pc;
    375       1.1  macallan 	sc->sc_pcitag = pa->pa_tag;
    376       1.1  macallan 	sc->sc_dacw = -1;
    377  1.28.2.1      yamt 	pci_aprint_devinfo(pa, NULL);
    378       1.1  macallan 
    379       1.1  macallan 	sc->sc_memt = pa->pa_memt;
    380       1.1  macallan 	sc->sc_iot = pa->pa_iot;
    381       1.9  jmcneill 	sc->sc_pa = *pa;
    382       1.1  macallan 
    383  1.28.2.3      yamt 	if (PCI_PRODUCT(pa->pa_id)>=PCI_PRODUCT_3DFX_BANSHEE)
    384  1.28.2.3      yamt 		sc->sc_max_clock = MAX_CLOCK_VB;
    385  1.28.2.3      yamt 	else
    386  1.28.2.3      yamt 		sc->sc_max_clock = MAX_CLOCK_V3;
    387  1.28.2.3      yamt 
    388       1.1  macallan 	/* the framebuffer */
    389  1.28.2.1      yamt 	if (pci_mapreg_info(sc->sc_pc, sc->sc_pcitag, 0x14, PCI_MAPREG_TYPE_MEM,
    390  1.28.2.1      yamt 	    &sc->sc_fb, &sc->sc_fbsize, &flags)) {
    391      1.18     joerg 		aprint_error_dev(self, "failed to map the frame buffer.\n");
    392       1.1  macallan 	}
    393  1.28.2.1      yamt 	sc->sc_memsize = sc->sc_fbsize >> 1;	/* VRAM aperture is 2x VRAM */
    394       1.1  macallan 
    395       1.1  macallan 	/* memory-mapped registers */
    396       1.3  macallan 	if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM, 0,
    397       1.1  macallan 	    &sc->sc_regt, &sc->sc_regh, &sc->sc_regs, &sc->sc_regsize)) {
    398      1.18     joerg 		aprint_error_dev(self, "failed to map memory-mapped registers.\n");
    399       1.1  macallan 	}
    400       1.1  macallan 
    401       1.1  macallan 	/* IO-mapped registers */
    402       1.3  macallan 	if (pci_mapreg_map(pa, 0x18, PCI_MAPREG_TYPE_IO, 0,
    403       1.1  macallan 	    &sc->sc_ioregt, &sc->sc_ioregh, &sc->sc_ioreg,
    404       1.1  macallan 	    &sc->sc_ioregsize)) {
    405      1.18     joerg 		aprint_error_dev(self, "failed to map IO-mapped registers.\n");
    406       1.1  macallan 	}
    407       1.1  macallan 	voodoofb_init(sc);
    408       1.1  macallan 
    409       1.1  macallan 	/* we should read these from the chip instead of depending on OF */
    410       1.1  macallan 	width = height = -1;
    411       1.1  macallan 
    412      1.28  kiyohara 	dict = device_properties(self);
    413      1.28  kiyohara 	if (!prop_dictionary_get_uint32(dict, "width", &width)) {
    414      1.28  kiyohara 		aprint_error_dev(self, "no width property\n");
    415      1.28  kiyohara 		return;
    416      1.28  kiyohara 	}
    417      1.28  kiyohara 	if (!prop_dictionary_get_uint32(dict, "height", &height)) {
    418      1.28  kiyohara 		aprint_error_dev(self, "no height property\n");
    419      1.28  kiyohara 		return;
    420      1.28  kiyohara 	}
    421      1.28  kiyohara 	if (!prop_dictionary_get_uint32(dict, "depth", &depth)) {
    422      1.28  kiyohara 		aprint_error_dev(self, "no depth property\n");
    423      1.28  kiyohara 		return;
    424      1.28  kiyohara 	}
    425      1.28  kiyohara 	linebytes = width;			/* XXX */
    426       1.1  macallan 
    427       1.1  macallan 	if (width == -1 || height == -1)
    428       1.1  macallan 		return;
    429       1.1  macallan 
    430  1.28.2.1      yamt 	sc->sc_width = width;
    431  1.28.2.1      yamt 	sc->sc_height = height;
    432  1.28.2.1      yamt 	sc->sc_bits_per_pixel = depth;
    433  1.28.2.1      yamt 	sc->sc_linebytes = linebytes;
    434      1.18     joerg 	printf("%s: initial resolution %dx%d, %d bit\n", device_xname(self),
    435  1.28.2.1      yamt 	    sc->sc_width, sc->sc_height, sc->sc_bits_per_pixel);
    436  1.28.2.1      yamt 
    437  1.28.2.1      yamt 	sc->sc_videomode = NULL;
    438  1.28.2.1      yamt 	voodoofb_setup_i2c(sc);
    439       1.1  macallan 
    440       1.1  macallan 	/* XXX this should at least be configurable via kernel config */
    441  1.28.2.1      yamt 	if (sc->sc_videomode == NULL) {
    442  1.28.2.1      yamt 		sc->sc_videomode = pick_mode_by_ref(width, height, 60);
    443  1.28.2.1      yamt 	}
    444  1.28.2.1      yamt 
    445  1.28.2.1      yamt 	voodoofb_set_videomode(sc, sc->sc_videomode);
    446  1.28.2.1      yamt 
    447  1.28.2.1      yamt 	sc->sc_font = NULL;
    448       1.1  macallan 
    449       1.1  macallan 	vcons_init(&sc->vd, sc, &voodoofb_defaultscreen, &voodoofb_accessops);
    450       1.1  macallan 	sc->vd.init_screen = voodoofb_init_screen;
    451       1.1  macallan 
    452      1.28  kiyohara 	console = voodoofb_is_console(sc);
    453       1.1  macallan 
    454       1.1  macallan 	ri = &voodoofb_console_screen.scr_ri;
    455       1.1  macallan 	if (console) {
    456       1.1  macallan 		vcons_init_screen(&sc->vd, &voodoofb_console_screen, 1,
    457       1.1  macallan 		    &defattr);
    458       1.1  macallan 		voodoofb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    459       1.1  macallan 
    460       1.1  macallan 		voodoofb_defaultscreen.textops = &ri->ri_ops;
    461       1.1  macallan 		voodoofb_defaultscreen.capabilities = ri->ri_caps;
    462       1.1  macallan 		voodoofb_defaultscreen.nrows = ri->ri_rows;
    463       1.1  macallan 		voodoofb_defaultscreen.ncols = ri->ri_cols;
    464       1.1  macallan 		wsdisplay_cnattach(&voodoofb_defaultscreen, ri, 0, 0, defattr);
    465       1.1  macallan 	} else {
    466       1.1  macallan 		/*
    467       1.1  macallan 		 * since we're not the console we can postpone the rest
    468       1.1  macallan 		 * until someone actually allocates a screen for us
    469       1.1  macallan 		 */
    470      1.23  macallan 		voodoofb_set_videomode(sc, sc->sc_videomode);
    471       1.1  macallan 	}
    472       1.1  macallan 
    473       1.1  macallan 	printf("%s: %d MB aperture at 0x%08x, %d MB registers at 0x%08x\n",
    474      1.18     joerg 	    device_xname(self), (u_int)(sc->sc_fbsize >> 20),
    475       1.1  macallan 	    (u_int)sc->sc_fb, (u_int)(sc->sc_regsize >> 20),
    476       1.1  macallan 	    (u_int)sc->sc_regs);
    477       1.1  macallan #ifdef VOODOOFB_DEBUG
    478       1.1  macallan 	printf("fb: %08lx\n", (ulong)ri->ri_bits);
    479       1.1  macallan #endif
    480       1.1  macallan 
    481       1.1  macallan 	j = 0;
    482  1.28.2.1      yamt 	if (sc->sc_bits_per_pixel == 8) {
    483  1.28.2.1      yamt 		uint8_t tmp;
    484  1.28.2.1      yamt 		for (i = 0; i < 256; i++) {
    485  1.28.2.1      yamt 			tmp = i & 0xe0;
    486  1.28.2.1      yamt 			/*
    487  1.28.2.1      yamt 			 * replicate bits so 0xe0 maps to a red value of 0xff
    488  1.28.2.1      yamt 			 * in order to make white look actually white
    489  1.28.2.1      yamt 			 */
    490  1.28.2.1      yamt 			tmp |= (tmp >> 3) | (tmp >> 6);
    491  1.28.2.1      yamt 			sc->sc_cmap_red[i] = tmp;
    492  1.28.2.1      yamt 
    493  1.28.2.1      yamt 			tmp = (i & 0x1c) << 3;
    494  1.28.2.1      yamt 			tmp |= (tmp >> 3) | (tmp >> 6);
    495  1.28.2.1      yamt 			sc->sc_cmap_green[i] = tmp;
    496  1.28.2.1      yamt 
    497  1.28.2.1      yamt 			tmp = (i & 0x03) << 6;
    498  1.28.2.1      yamt 			tmp |= tmp >> 2;
    499  1.28.2.1      yamt 			tmp |= tmp >> 4;
    500  1.28.2.1      yamt 			sc->sc_cmap_blue[i] = tmp;
    501  1.28.2.1      yamt 
    502  1.28.2.1      yamt 			voodoofb_putpalreg(sc, i, sc->sc_cmap_red[i],
    503  1.28.2.1      yamt 			    sc->sc_cmap_green[i], sc->sc_cmap_blue[i]);
    504  1.28.2.1      yamt 		}
    505  1.28.2.1      yamt 	} else {
    506  1.28.2.1      yamt 		/* linear ramp */
    507  1.28.2.1      yamt 		for (i = 0; i < 256; i++) {
    508  1.28.2.1      yamt 			sc->sc_cmap_red[i] = i;
    509  1.28.2.1      yamt 			sc->sc_cmap_green[i] = i;
    510  1.28.2.1      yamt 			sc->sc_cmap_blue[i] = i;
    511  1.28.2.1      yamt 
    512  1.28.2.1      yamt 			voodoofb_putpalreg(sc, i, sc->sc_cmap_red[i],
    513  1.28.2.1      yamt 			    sc->sc_cmap_green[i], sc->sc_cmap_blue[i]);
    514  1.28.2.1      yamt 		}
    515       1.1  macallan 	}
    516       1.1  macallan 
    517       1.9  jmcneill #ifdef VOODOOFB_ENABLE_INTR
    518       1.1  macallan 	/* Interrupt. We don't use it for anything yet */
    519       1.1  macallan 	if (pci_intr_map(pa, &ih)) {
    520      1.18     joerg 		aprint_error_dev(self, "failed to map interrupt\n");
    521       1.1  macallan 		return;
    522       1.1  macallan 	}
    523       1.1  macallan 
    524       1.1  macallan 	intrstr = pci_intr_string(sc->sc_pc, ih);
    525       1.1  macallan 	sc->sc_ih = pci_intr_establish(sc->sc_pc, ih, IPL_NET, voodoofb_intr,
    526       1.1  macallan 	    sc);
    527       1.1  macallan 	if (sc->sc_ih == NULL) {
    528      1.18     joerg 		aprint_error_dev(self, "failed to establish interrupt");
    529       1.1  macallan 		if (intrstr != NULL)
    530      1.21     njoly 			aprint_error(" at %s", intrstr);
    531      1.21     njoly 		aprint_error("\n");
    532       1.1  macallan 		return;
    533       1.1  macallan 	}
    534      1.21     njoly 	aprint_normal_dev(self, "interrupting at %s\n", intrstr);
    535       1.9  jmcneill #endif
    536       1.1  macallan 
    537       1.1  macallan 	rasops_unpack_attr(defattr, &fg, &bg, &ul);
    538       1.1  macallan 	sc->sc_bg = ri->ri_devcmap[bg];
    539       1.1  macallan 	voodoofb_clearscreen(sc);
    540       1.1  macallan 
    541      1.20  macallan 	if (console)
    542      1.20  macallan 		vcons_replay_msgbuf(&voodoofb_console_screen);
    543       1.1  macallan 	aa.console = console;
    544       1.1  macallan 	aa.scrdata = &voodoofb_screenlist;
    545       1.1  macallan 	aa.accessops = &voodoofb_accessops;
    546       1.1  macallan 	aa.accesscookie = &sc->vd;
    547       1.1  macallan 
    548       1.1  macallan 	config_found(self, &aa, wsemuldisplaydevprint);
    549       1.9  jmcneill 	config_found_ia(self, "drm", aux, voodoofb_drm_print);
    550       1.9  jmcneill }
    551       1.9  jmcneill 
    552       1.9  jmcneill static int
    553       1.9  jmcneill voodoofb_drm_print(void *opaque, const char *pnp)
    554       1.9  jmcneill {
    555       1.9  jmcneill 	if (pnp)
    556      1.16  jmcneill 		aprint_normal("drm at %s", pnp);
    557       1.9  jmcneill 
    558      1.16  jmcneill 	return UNCONF;
    559       1.9  jmcneill }
    560       1.9  jmcneill 
    561       1.9  jmcneill static int
    562       1.9  jmcneill voodoofb_drm_unmap(struct voodoofb_softc *sc)
    563       1.9  jmcneill {
    564      1.18     joerg 	printf("%s: releasing bus resources\n", device_xname(sc->sc_dev));
    565       1.9  jmcneill 
    566       1.9  jmcneill 	bus_space_unmap(sc->sc_ioregt, sc->sc_ioregh, sc->sc_ioregsize);
    567      1.10   xtraeme 	bus_space_unmap(sc->sc_regt, sc->sc_regh, sc->sc_regsize);
    568       1.9  jmcneill 
    569       1.9  jmcneill 	return 0;
    570       1.9  jmcneill }
    571       1.9  jmcneill 
    572       1.9  jmcneill static int
    573       1.9  jmcneill voodoofb_drm_map(struct voodoofb_softc *sc)
    574       1.9  jmcneill {
    575       1.9  jmcneill 
    576       1.9  jmcneill 	/* memory-mapped registers */
    577       1.9  jmcneill 	if (pci_mapreg_map(&sc->sc_pa, 0x10, PCI_MAPREG_TYPE_MEM, 0,
    578       1.9  jmcneill 	    &sc->sc_regt, &sc->sc_regh, &sc->sc_regs, &sc->sc_regsize)) {
    579      1.18     joerg 		aprint_error_dev(sc->sc_dev, "failed to map memory-mapped registers.\n");
    580       1.9  jmcneill 	}
    581       1.9  jmcneill 
    582       1.9  jmcneill 	/* IO-mapped registers */
    583       1.9  jmcneill 	if (pci_mapreg_map(&sc->sc_pa, 0x18, PCI_MAPREG_TYPE_IO, 0,
    584       1.9  jmcneill 	    &sc->sc_ioregt, &sc->sc_ioregh, &sc->sc_ioreg,
    585       1.9  jmcneill 	    &sc->sc_ioregsize)) {
    586      1.18     joerg 		aprint_error_dev(sc->sc_dev, "failed to map IO-mapped registers.\n");
    587       1.9  jmcneill 	}
    588       1.9  jmcneill 
    589       1.9  jmcneill 	voodoofb_init(sc);
    590       1.9  jmcneill 	/* XXX this should at least be configurable via kernel config */
    591      1.23  macallan 	voodoofb_set_videomode(sc, sc->sc_videomode);
    592       1.9  jmcneill 
    593       1.9  jmcneill 	return 0;
    594       1.1  macallan }
    595       1.1  macallan 
    596       1.1  macallan static int
    597       1.1  macallan voodoofb_putpalreg(struct voodoofb_softc *sc, uint8_t index, uint8_t r,
    598       1.1  macallan     uint8_t g, uint8_t b)
    599       1.1  macallan {
    600       1.1  macallan 	uint32_t color;
    601       1.1  macallan 
    602       1.1  macallan 	sc->sc_cmap_red[index] = r;
    603       1.1  macallan 	sc->sc_cmap_green[index] = g;
    604       1.1  macallan 	sc->sc_cmap_blue[index] = b;
    605       1.1  macallan 
    606       1.3  macallan 	color = (r << 16) | (g << 8) | b;
    607       1.1  macallan 	voodoo3_make_room(sc, 2);
    608       1.1  macallan 	voodoo3_write32(sc, DACADDR, index);
    609       1.1  macallan 	voodoo3_write32(sc, DACDATA, color);
    610       1.1  macallan 
    611       1.1  macallan 	return 0;
    612       1.1  macallan }
    613       1.1  macallan 
    614       1.1  macallan static int
    615       1.1  macallan voodoofb_putcmap(struct voodoofb_softc *sc, struct wsdisplay_cmap *cm)
    616       1.1  macallan {
    617       1.1  macallan 	u_char *r, *g, *b;
    618       1.1  macallan 	u_int index = cm->index;
    619       1.1  macallan 	u_int count = cm->count;
    620       1.1  macallan 	int i, error;
    621       1.1  macallan 	u_char rbuf[256], gbuf[256], bbuf[256];
    622       1.1  macallan 
    623       1.1  macallan #ifdef VOODOOFB_DEBUG
    624       1.1  macallan 	printf("putcmap: %d %d\n",index, count);
    625       1.1  macallan #endif
    626       1.1  macallan 	if (cm->index >= 256 || cm->count > 256 ||
    627       1.1  macallan 	    (cm->index + cm->count) > 256)
    628       1.1  macallan 		return EINVAL;
    629       1.1  macallan 	error = copyin(cm->red, &rbuf[index], count);
    630       1.1  macallan 	if (error)
    631       1.1  macallan 		return error;
    632       1.1  macallan 	error = copyin(cm->green, &gbuf[index], count);
    633       1.1  macallan 	if (error)
    634       1.1  macallan 		return error;
    635       1.1  macallan 	error = copyin(cm->blue, &bbuf[index], count);
    636       1.1  macallan 	if (error)
    637       1.1  macallan 		return error;
    638       1.1  macallan 
    639       1.1  macallan 	memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
    640       1.1  macallan 	memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
    641       1.1  macallan 	memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
    642       1.1  macallan 
    643       1.1  macallan 	r = &sc->sc_cmap_red[index];
    644       1.1  macallan 	g = &sc->sc_cmap_green[index];
    645       1.1  macallan 	b = &sc->sc_cmap_blue[index];
    646       1.1  macallan 
    647       1.1  macallan 	for (i = 0; i < count; i++) {
    648       1.3  macallan 		voodoofb_putpalreg(sc, index, *r, *g, *b);
    649       1.1  macallan 		index++;
    650       1.1  macallan 		r++, g++, b++;
    651       1.1  macallan 	}
    652       1.1  macallan 	return 0;
    653       1.1  macallan }
    654       1.1  macallan 
    655       1.1  macallan static int
    656       1.1  macallan voodoofb_getcmap(struct voodoofb_softc *sc, struct wsdisplay_cmap *cm)
    657       1.1  macallan {
    658       1.1  macallan 	u_int index = cm->index;
    659       1.1  macallan 	u_int count = cm->count;
    660       1.1  macallan 	int error;
    661       1.1  macallan 
    662       1.1  macallan 	if (index >= 255 || count > 256 || index + count > 256)
    663       1.1  macallan 		return EINVAL;
    664       1.1  macallan 
    665       1.1  macallan 	error = copyout(&sc->sc_cmap_red[index],   cm->red,   count);
    666       1.1  macallan 	if (error)
    667       1.1  macallan 		return error;
    668       1.1  macallan 	error = copyout(&sc->sc_cmap_green[index], cm->green, count);
    669       1.1  macallan 	if (error)
    670       1.1  macallan 		return error;
    671       1.1  macallan 	error = copyout(&sc->sc_cmap_blue[index],  cm->blue,  count);
    672       1.1  macallan 	if (error)
    673       1.1  macallan 		return error;
    674       1.1  macallan 
    675       1.1  macallan 	return 0;
    676       1.1  macallan }
    677       1.1  macallan 
    678      1.28  kiyohara static bool
    679      1.28  kiyohara voodoofb_is_console(struct voodoofb_softc *sc)
    680       1.1  macallan {
    681      1.28  kiyohara 	prop_dictionary_t dict;
    682      1.28  kiyohara 	bool console;
    683       1.1  macallan 
    684      1.28  kiyohara 	dict = device_properties(sc->sc_dev);
    685      1.28  kiyohara 	prop_dictionary_get_bool(dict, "is_console", &console);
    686      1.28  kiyohara 	return console;
    687       1.1  macallan }
    688       1.1  macallan 
    689       1.1  macallan static void
    690       1.1  macallan voodoofb_clearscreen(struct voodoofb_softc *sc)
    691       1.1  macallan {
    692  1.28.2.1      yamt 	voodoofb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height, sc->sc_bg);
    693       1.1  macallan }
    694       1.1  macallan 
    695       1.1  macallan /*
    696       1.1  macallan  * wsdisplay_emulops
    697       1.1  macallan  */
    698       1.1  macallan 
    699       1.1  macallan static void
    700       1.1  macallan voodoofb_cursor(void *cookie, int on, int row, int col)
    701       1.1  macallan {
    702       1.1  macallan 	struct rasops_info *ri = cookie;
    703       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    704       1.1  macallan 	struct voodoofb_softc *sc = scr->scr_cookie;
    705       1.3  macallan 	int x, y, wi, he;
    706       1.1  macallan 
    707       1.1  macallan 	wi = ri->ri_font->fontwidth;
    708       1.1  macallan 	he = ri->ri_font->fontheight;
    709       1.1  macallan 
    710       1.1  macallan 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    711       1.1  macallan 		x = ri->ri_ccol * wi + ri->ri_xorigin;
    712       1.1  macallan 		y = ri->ri_crow * he + ri->ri_yorigin;
    713       1.1  macallan 		if (ri->ri_flg & RI_CURSOR) {
    714       1.1  macallan 			voodoofb_rectinvert(sc, x, y, wi, he);
    715       1.1  macallan 			ri->ri_flg &= ~RI_CURSOR;
    716       1.1  macallan 		}
    717       1.1  macallan 		ri->ri_crow = row;
    718       1.1  macallan 		ri->ri_ccol = col;
    719       1.1  macallan 		if (on)
    720       1.1  macallan 		{
    721       1.1  macallan 			x = ri->ri_ccol * wi + ri->ri_xorigin;
    722       1.1  macallan 			y = ri->ri_crow * he + ri->ri_yorigin;
    723       1.1  macallan 			voodoofb_rectinvert(sc, x, y, wi, he);
    724       1.1  macallan 			ri->ri_flg |= RI_CURSOR;
    725       1.1  macallan 		}
    726       1.1  macallan 	} else {
    727       1.1  macallan 		ri->ri_flg &= ~RI_CURSOR;
    728       1.1  macallan 		ri->ri_crow = row;
    729       1.1  macallan 		ri->ri_ccol = col;
    730       1.1  macallan 	}
    731       1.1  macallan }
    732       1.1  macallan 
    733       1.1  macallan #if 0
    734       1.1  macallan int
    735       1.1  macallan voodoofb_mapchar(void *cookie, int uni, u_int *index)
    736       1.1  macallan {
    737       1.1  macallan 	return 0;
    738       1.1  macallan }
    739       1.1  macallan #endif
    740       1.1  macallan 
    741       1.1  macallan static void
    742       1.1  macallan voodoofb_putchar(void *cookie, int row, int col, u_int c, long attr)
    743       1.1  macallan {
    744       1.1  macallan 	struct rasops_info *ri = cookie;
    745      1.22  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, c);
    746       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    747       1.1  macallan 	struct voodoofb_softc *sc = scr->scr_cookie;
    748       1.1  macallan 
    749       1.1  macallan 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    750       1.1  macallan 		uint8_t *data;
    751       1.1  macallan 		int fg, bg, uc, i;
    752       1.1  macallan 		int x, y, wi, he;
    753       1.1  macallan 
    754      1.22  macallan 		wi = font->fontwidth;
    755      1.22  macallan 		he = font->fontheight;
    756       1.1  macallan 
    757      1.22  macallan 		if (!CHAR_IN_FONT(c, font))
    758       1.1  macallan 			return;
    759       1.1  macallan 		bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xf];
    760       1.1  macallan 		fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xf];
    761       1.1  macallan 		x = ri->ri_xorigin + col * wi;
    762       1.1  macallan 		y = ri->ri_yorigin + row * he;
    763       1.1  macallan 		if (c == 0x20) {
    764       1.1  macallan 			voodoofb_rectfill(sc, x, y, wi, he, bg);
    765       1.1  macallan 		} else {
    766      1.22  macallan 			uc = c - font->firstchar;
    767      1.22  macallan 			data = (uint8_t *)font->data + uc *
    768       1.1  macallan 			    ri->ri_fontscale;
    769       1.1  macallan 				voodoofb_setup_mono(sc, x, y, wi, he, fg, bg);
    770       1.1  macallan 			for (i = 0; i < he; i++) {
    771      1.22  macallan 				voodoofb_feed_line(sc, font->stride, data);
    772      1.22  macallan 				data += font->stride;
    773       1.1  macallan 			}
    774       1.1  macallan 		}
    775       1.1  macallan 	}
    776       1.1  macallan }
    777       1.1  macallan 
    778       1.1  macallan static void
    779  1.28.2.1      yamt voodoofb_putchar_aa(void *cookie, int row, int col, u_int c, long attr)
    780  1.28.2.1      yamt {
    781  1.28.2.1      yamt 	struct rasops_info *ri = cookie;
    782  1.28.2.1      yamt 	struct wsdisplay_font *font = PICK_FONT(ri, c);
    783  1.28.2.1      yamt 	struct vcons_screen *scr = ri->ri_hw;
    784  1.28.2.1      yamt 	struct voodoofb_softc *sc = scr->scr_cookie;
    785  1.28.2.1      yamt 	uint8_t *data;
    786  1.28.2.1      yamt 	uint32_t bg, latch = 0, bg8, fg8, pixel, save_offset = 0;
    787  1.28.2.1      yamt 	int i, x, y, wi, he, r, g, b, aval;
    788  1.28.2.1      yamt 	int r1, g1, b1, r0, g0, b0, fgo, bgo, j;
    789  1.28.2.1      yamt 
    790  1.28.2.1      yamt 	if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL)
    791  1.28.2.1      yamt 		return;
    792  1.28.2.1      yamt 
    793  1.28.2.1      yamt 	if (!CHAR_IN_FONT(c, font))
    794  1.28.2.1      yamt 		return;
    795  1.28.2.1      yamt 
    796  1.28.2.1      yamt 	wi = font->fontwidth;
    797  1.28.2.1      yamt 	he = font->fontheight;
    798  1.28.2.1      yamt 
    799  1.28.2.1      yamt 	bg = ri->ri_devcmap[(attr >> 16) & 0xf];
    800  1.28.2.1      yamt 	x = ri->ri_xorigin + col * wi;
    801  1.28.2.1      yamt 	y = ri->ri_yorigin + row * he;
    802  1.28.2.1      yamt 	if (c == 0x20) {
    803  1.28.2.1      yamt 		voodoofb_rectfill(sc, x, y, wi, he, bg);
    804  1.28.2.1      yamt 		return;
    805  1.28.2.1      yamt 	}
    806  1.28.2.1      yamt 
    807  1.28.2.1      yamt 	/* first, see if it's in the cache */
    808  1.28.2.1      yamt 	if ((attr == sc->sc_defattr) && (c < 256)) {
    809  1.28.2.1      yamt 		uint32_t offset = sc->sc_glyphs_defattr[c];
    810  1.28.2.1      yamt 		if (offset != 0) {
    811  1.28.2.1      yamt 			voodoo3_make_room(sc, 8);
    812  1.28.2.1      yamt 			voodoo3_write32(sc, SRCBASE, offset);
    813  1.28.2.1      yamt 			voodoo3_write32(sc, DSTBASE, 0);
    814  1.28.2.1      yamt 			voodoo3_write32(sc, SRCFORMAT,	sc->sc_fmt);
    815  1.28.2.1      yamt 			voodoo3_write32(sc, DSTFORMAT,	sc->sc_linebytes | FMT_8BIT);
    816  1.28.2.1      yamt 			voodoo3_write32(sc, DSTSIZE,	wi | (he << 16));
    817  1.28.2.1      yamt 			voodoo3_write32(sc, DSTXY,	x | (y << 16));
    818  1.28.2.1      yamt 			voodoo3_write32(sc, SRCXY,	0);
    819  1.28.2.1      yamt 			voodoo3_write32(sc, COMMAND_2D, COMMAND_2D_S2S_BITBLT |
    820  1.28.2.1      yamt 			    (ROP_COPY << 24) | SST_2D_GO);
    821  1.28.2.1      yamt 			return;
    822  1.28.2.1      yamt 		} else {
    823  1.28.2.1      yamt 			int slot = sc->sc_usedglyphs;
    824  1.28.2.1      yamt 			sc->sc_usedglyphs++;
    825  1.28.2.1      yamt 			save_offset = sc->sc_cache + (slot * ri->ri_fontscale);
    826  1.28.2.1      yamt 			sc->sc_glyphs_defattr[c] = save_offset;
    827  1.28.2.1      yamt 		}
    828  1.28.2.1      yamt 	}
    829  1.28.2.1      yamt 	data = WSFONT_GLYPH(c, font);
    830  1.28.2.1      yamt 
    831  1.28.2.1      yamt 	voodoo3_make_room(sc, 7);
    832  1.28.2.1      yamt 	voodoo3_write32(sc, DSTBASE, 0);
    833  1.28.2.1      yamt 	voodoo3_write32(sc, SRCFORMAT,	FMT_8BIT | FMT_PAD_BYTE);
    834  1.28.2.1      yamt 	voodoo3_write32(sc, DSTFORMAT,	sc->sc_linebytes | FMT_8BIT);
    835  1.28.2.1      yamt 	voodoo3_write32(sc, DSTSIZE,	wi | (he << 16));
    836  1.28.2.1      yamt 	voodoo3_write32(sc, DSTXY,	x | (y << 16));
    837  1.28.2.1      yamt 	voodoo3_write32(sc, SRCXY,	0);
    838  1.28.2.1      yamt 	voodoo3_write32(sc, COMMAND_2D, COMMAND_2D_H2S_BITBLT |
    839  1.28.2.1      yamt 	    (ROP_COPY << 24) | SST_2D_GO);
    840  1.28.2.1      yamt 
    841  1.28.2.1      yamt 	/*
    842  1.28.2.1      yamt 	 * we need the RGB colours here, so get offsets into rasops_cmap
    843  1.28.2.1      yamt 	 */
    844  1.28.2.1      yamt 	fgo = ((attr >> 24) & 0xf) * 3;
    845  1.28.2.1      yamt 	bgo = ((attr >> 16) & 0xf) * 3;
    846  1.28.2.1      yamt 
    847  1.28.2.1      yamt 	r0 = rasops_cmap[bgo];
    848  1.28.2.1      yamt 	r1 = rasops_cmap[fgo];
    849  1.28.2.1      yamt 	g0 = rasops_cmap[bgo + 1];
    850  1.28.2.1      yamt 	g1 = rasops_cmap[fgo + 1];
    851  1.28.2.1      yamt 	b0 = rasops_cmap[bgo + 2];
    852  1.28.2.1      yamt 	b1 = rasops_cmap[fgo + 2];
    853  1.28.2.1      yamt #define R3G3B2(r, g, b) ((r & 0xe0) | ((g >> 3) & 0x1c) | (b >> 6))
    854  1.28.2.1      yamt 	bg8 = R3G3B2(r0, g0, b0);
    855  1.28.2.1      yamt 	fg8 = R3G3B2(r1, g1, b1);
    856  1.28.2.1      yamt 	voodoo3_make_room(sc, 15);
    857  1.28.2.1      yamt 	j = 15;
    858  1.28.2.1      yamt 	for (i = 0; i < ri->ri_fontscale; i++) {
    859  1.28.2.1      yamt 		aval = *data;
    860  1.28.2.1      yamt 		if (aval == 0) {
    861  1.28.2.1      yamt 			pixel = bg8;
    862  1.28.2.1      yamt 		} else if (aval == 255) {
    863  1.28.2.1      yamt 			pixel = fg8;
    864  1.28.2.1      yamt 		} else {
    865  1.28.2.1      yamt 			r = aval * r1 + (255 - aval) * r0;
    866  1.28.2.1      yamt 			g = aval * g1 + (255 - aval) * g0;
    867  1.28.2.1      yamt 			b = aval * b1 + (255 - aval) * b0;
    868  1.28.2.1      yamt 			pixel = ((r & 0xe000) >> 8) |
    869  1.28.2.1      yamt 				((g & 0xe000) >> 11) |
    870  1.28.2.1      yamt 				((b & 0xc000) >> 14);
    871  1.28.2.1      yamt 		}
    872  1.28.2.1      yamt 		latch = (latch << 8) | pixel;
    873  1.28.2.1      yamt 		/* write in 32bit chunks */
    874  1.28.2.1      yamt 		if ((i & 3) == 3) {
    875  1.28.2.1      yamt 			voodoo3_write32s(sc, LAUNCH_2D, latch);
    876  1.28.2.1      yamt 			/*
    877  1.28.2.1      yamt 			 * not strictly necessary, old data should be shifted
    878  1.28.2.1      yamt 			 * out
    879  1.28.2.1      yamt 			 */
    880  1.28.2.1      yamt 			latch = 0;
    881  1.28.2.1      yamt 			/*
    882  1.28.2.1      yamt 			 * check for pipeline space every now and then
    883  1.28.2.1      yamt 			 * I don't think we can feed a Voodoo3 faster than it
    884  1.28.2.1      yamt 			 * can process simple pixel data but I have been wrong
    885  1.28.2.1      yamt 			 * about that before
    886  1.28.2.1      yamt 			 */
    887  1.28.2.1      yamt 			j--;
    888  1.28.2.1      yamt 			if (j == 0) {
    889  1.28.2.1      yamt 				voodoo3_make_room(sc, 15);
    890  1.28.2.1      yamt 				j = 15;
    891  1.28.2.1      yamt 			}
    892  1.28.2.1      yamt 		}
    893  1.28.2.1      yamt 		data++;
    894  1.28.2.1      yamt 	}
    895  1.28.2.1      yamt 	/* if we have pixels left in latch write them out */
    896  1.28.2.1      yamt 	if ((i & 3) != 0) {
    897  1.28.2.1      yamt 		latch = latch << ((4 - (i & 3)) << 3);
    898  1.28.2.1      yamt 		voodoo3_write32s(sc, LAUNCH_2D, latch);
    899  1.28.2.1      yamt 	}
    900  1.28.2.1      yamt 	if (save_offset != 0) {
    901  1.28.2.1      yamt 		/* save the glyph we just drew */
    902  1.28.2.1      yamt 		voodoo3_make_room(sc, 8);
    903  1.28.2.1      yamt 		voodoo3_write32(sc, SRCBASE, 0);
    904  1.28.2.1      yamt 		voodoo3_write32(sc, DSTBASE, save_offset);
    905  1.28.2.1      yamt 		voodoo3_write32(sc, SRCFORMAT,	sc->sc_linebytes | FMT_8BIT);
    906  1.28.2.1      yamt 		voodoo3_write32(sc, DSTFORMAT,	sc->sc_fmt);
    907  1.28.2.1      yamt 		voodoo3_write32(sc, DSTSIZE,	wi | (he << 16));
    908  1.28.2.1      yamt 		voodoo3_write32(sc, DSTXY,	0);
    909  1.28.2.1      yamt 		voodoo3_write32(sc, SRCXY,	x | (y << 16));
    910  1.28.2.1      yamt 		voodoo3_write32(sc, COMMAND_2D, COMMAND_2D_S2S_BITBLT |
    911  1.28.2.1      yamt 			    (ROP_COPY << 24) | SST_2D_GO);
    912  1.28.2.1      yamt 	}
    913  1.28.2.1      yamt }
    914  1.28.2.1      yamt 
    915  1.28.2.1      yamt static void
    916       1.1  macallan voodoofb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
    917       1.1  macallan {
    918       1.1  macallan 	struct rasops_info *ri = cookie;
    919       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    920       1.1  macallan 	struct voodoofb_softc *sc = scr->scr_cookie;
    921       1.1  macallan 	int32_t xs, xd, y, width, height;
    922       1.1  macallan 
    923       1.1  macallan 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    924       1.1  macallan 		xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
    925       1.1  macallan 		xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
    926       1.1  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    927       1.1  macallan 		width = ri->ri_font->fontwidth * ncols;
    928       1.1  macallan 		height = ri->ri_font->fontheight;
    929       1.1  macallan 		voodoofb_bitblt(sc, xs, y, xd, y, width, height);
    930       1.1  macallan 	}
    931       1.1  macallan }
    932       1.1  macallan 
    933       1.1  macallan static void
    934       1.1  macallan voodoofb_erasecols(void *cookie, int row, int startcol, int ncols,
    935       1.1  macallan     long fillattr)
    936       1.1  macallan {
    937       1.1  macallan 	struct rasops_info *ri = cookie;
    938       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    939       1.1  macallan 	struct voodoofb_softc *sc = scr->scr_cookie;
    940       1.1  macallan 	int32_t x, y, width, height, fg, bg, ul;
    941       1.1  macallan 
    942       1.1  macallan 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    943       1.1  macallan 		x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
    944       1.1  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    945       1.1  macallan 		width = ri->ri_font->fontwidth * ncols;
    946       1.1  macallan 		height = ri->ri_font->fontheight;
    947       1.1  macallan 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
    948       1.1  macallan 
    949       1.1  macallan 		voodoofb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
    950       1.1  macallan 	}
    951       1.1  macallan }
    952       1.1  macallan 
    953       1.1  macallan static void
    954       1.1  macallan voodoofb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
    955       1.1  macallan {
    956       1.1  macallan 	struct rasops_info *ri = cookie;
    957       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    958       1.1  macallan 	struct voodoofb_softc *sc = scr->scr_cookie;
    959       1.1  macallan 	int32_t x, ys, yd, width, height;
    960       1.1  macallan 
    961       1.1  macallan 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    962       1.1  macallan 		x = ri->ri_xorigin;
    963       1.1  macallan 		ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
    964       1.1  macallan 		yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
    965       1.1  macallan 		width = ri->ri_emuwidth;
    966       1.1  macallan 		height = ri->ri_font->fontheight * nrows;
    967       1.1  macallan 		voodoofb_bitblt(sc, x, ys, x, yd, width, height);
    968       1.1  macallan 	}
    969       1.1  macallan }
    970       1.1  macallan 
    971       1.1  macallan static void
    972       1.1  macallan voodoofb_eraserows(void *cookie, int row, int nrows, long fillattr)
    973       1.1  macallan {
    974       1.1  macallan 	struct rasops_info *ri = cookie;
    975       1.1  macallan 	struct vcons_screen *scr = ri->ri_hw;
    976       1.1  macallan 	struct voodoofb_softc *sc = scr->scr_cookie;
    977       1.1  macallan 	int32_t x, y, width, height, fg, bg, ul;
    978       1.1  macallan 
    979       1.1  macallan 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
    980       1.1  macallan 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
    981       1.1  macallan 		if ((row == 0) && (nrows == ri->ri_rows)) {
    982       1.1  macallan 			/* clear the whole screen */
    983       1.1  macallan 			voodoofb_rectfill(sc, 0, 0, ri->ri_width,
    984       1.1  macallan 			    ri->ri_height, ri->ri_devcmap[bg]);
    985       1.1  macallan 		} else {
    986       1.1  macallan 			x = ri->ri_xorigin;
    987       1.1  macallan 			y = ri->ri_yorigin + ri->ri_font->fontheight * row;
    988       1.1  macallan 			width = ri->ri_emuwidth;
    989       1.1  macallan 			height = ri->ri_font->fontheight * nrows;
    990       1.1  macallan 			voodoofb_rectfill(sc, x, y, width, height,
    991       1.1  macallan 			    ri->ri_devcmap[bg]);
    992       1.1  macallan 		}
    993       1.1  macallan 	}
    994       1.1  macallan }
    995       1.1  macallan 
    996       1.1  macallan static void
    997       1.1  macallan voodoofb_bitblt(struct voodoofb_softc *sc, int xs, int ys, int xd, int yd, int width, int height)
    998       1.1  macallan {
    999       1.1  macallan 	uint32_t fmt, blitcmd;
   1000       1.1  macallan 
   1001  1.28.2.1      yamt 	fmt = sc->sc_linebytes | ((sc->sc_bits_per_pixel +
   1002  1.28.2.1      yamt 	    ((sc->sc_bits_per_pixel == 8) ? 0 : 8)) << 13);
   1003       1.1  macallan 	blitcmd = COMMAND_2D_S2S_BITBLT | (ROP_COPY << 24);
   1004       1.1  macallan 
   1005       1.1  macallan 	if (xs <= xd) {
   1006       1.1  macallan 	        blitcmd |= BIT(14);
   1007       1.1  macallan 		xs += (width - 1);
   1008       1.1  macallan 		xd += (width - 1);
   1009       1.1  macallan 	}
   1010       1.1  macallan 	if (ys <= yd) {
   1011       1.1  macallan 		blitcmd |= BIT(15);
   1012       1.1  macallan 		ys += (height - 1);
   1013       1.1  macallan 		yd += (height - 1);
   1014       1.1  macallan 	}
   1015  1.28.2.1      yamt 	voodoo3_make_room(sc, 8);
   1016       1.1  macallan 
   1017  1.28.2.1      yamt 	voodoo3_write32(sc, SRCBASE, 0);
   1018  1.28.2.1      yamt 	voodoo3_write32(sc, DSTBASE, 0);
   1019       1.1  macallan 	voodoo3_write32(sc, SRCFORMAT, fmt);
   1020       1.1  macallan 	voodoo3_write32(sc, DSTFORMAT, fmt);
   1021       1.1  macallan 	voodoo3_write32(sc, DSTSIZE,   width | (height << 16));
   1022       1.1  macallan 	voodoo3_write32(sc, DSTXY,     xd | (yd << 16));
   1023       1.1  macallan 	voodoo3_write32(sc, SRCXY, xs | (ys << 16));
   1024       1.1  macallan 	voodoo3_write32(sc, COMMAND_2D, blitcmd | SST_2D_GO);
   1025       1.1  macallan }
   1026       1.1  macallan 
   1027       1.1  macallan static void
   1028       1.1  macallan voodoofb_rectfill(struct voodoofb_softc *sc, int x, int y, int width,
   1029       1.1  macallan     int height, int colour)
   1030       1.1  macallan {
   1031       1.3  macallan 	uint32_t fmt, col;
   1032       1.1  macallan 
   1033       1.1  macallan 	col = (colour << 24) | (colour << 16) | (colour << 8) | colour;
   1034  1.28.2.1      yamt 	fmt = sc->sc_linebytes | ((sc->sc_bits_per_pixel +
   1035  1.28.2.1      yamt 	    ((sc->sc_bits_per_pixel == 8) ? 0 : 8)) << 13);
   1036       1.1  macallan 
   1037  1.28.2.1      yamt 	voodoo3_make_room(sc, 7);
   1038       1.1  macallan 	voodoo3_write32(sc, DSTFORMAT, fmt);
   1039  1.28.2.1      yamt 	voodoo3_write32(sc, DSTBASE, 0);
   1040       1.1  macallan 	voodoo3_write32(sc, COLORFORE, colour);
   1041       1.1  macallan 	voodoo3_write32(sc, COLORBACK, colour);
   1042       1.1  macallan 	voodoo3_write32(sc, COMMAND_2D, COMMAND_2D_FILLRECT | (ROP_COPY << 24));
   1043       1.1  macallan 	voodoo3_write32(sc, DSTSIZE,    width | (height << 16));
   1044       1.1  macallan 	voodoo3_write32(sc, LAUNCH_2D,  x | (y << 16));
   1045       1.1  macallan }
   1046       1.1  macallan 
   1047       1.1  macallan static void
   1048       1.1  macallan voodoofb_rectinvert(struct voodoofb_softc *sc, int x, int y, int width,
   1049       1.1  macallan     int height)
   1050       1.1  macallan {
   1051       1.1  macallan 	uint32_t fmt;
   1052       1.1  macallan 
   1053  1.28.2.1      yamt 	fmt = sc->sc_linebytes | ((sc->sc_bits_per_pixel +
   1054  1.28.2.1      yamt 	    ((sc->sc_bits_per_pixel == 8) ? 0 : 8)) << 13);
   1055       1.1  macallan 
   1056  1.28.2.1      yamt 	voodoo3_make_room(sc, 8);
   1057  1.28.2.1      yamt 	voodoo3_write32(sc, SRCBASE, 0);
   1058  1.28.2.1      yamt 	voodoo3_write32(sc, DSTBASE, 0);
   1059       1.1  macallan 	voodoo3_write32(sc, DSTFORMAT,	fmt);
   1060       1.1  macallan 	voodoo3_write32(sc, COMMAND_2D,	COMMAND_2D_FILLRECT |
   1061       1.1  macallan 	    (ROP_INVERT << 24));
   1062       1.1  macallan 	voodoo3_write32(sc, DSTSIZE,	width | (height << 16));
   1063       1.1  macallan 	voodoo3_write32(sc, DSTXY,	x | (y << 16));
   1064       1.1  macallan 	voodoo3_write32(sc, LAUNCH_2D,	x | (y << 16));
   1065       1.1  macallan }
   1066       1.1  macallan 
   1067       1.1  macallan static void
   1068       1.1  macallan voodoofb_setup_mono(struct voodoofb_softc *sc, int xd, int yd, int width, int height, uint32_t fg,
   1069       1.1  macallan 					uint32_t bg)
   1070       1.1  macallan {
   1071  1.28.2.1      yamt 	uint32_t dfmt, sfmt = sc->sc_linebytes;
   1072       1.1  macallan 
   1073  1.28.2.1      yamt 	dfmt = sc->sc_linebytes | ((sc->sc_bits_per_pixel +
   1074  1.28.2.1      yamt 	    ((sc->sc_bits_per_pixel == 8) ? 0 : 8)) << 13);
   1075       1.1  macallan 
   1076  1.28.2.1      yamt 	voodoo3_make_room(sc, 10);
   1077       1.1  macallan 	voodoo3_write32(sc, SRCFORMAT,	sfmt);
   1078       1.1  macallan 	voodoo3_write32(sc, DSTFORMAT,	dfmt);
   1079  1.28.2.1      yamt 	voodoo3_write32(sc, DSTBASE, 0);
   1080       1.1  macallan 	voodoo3_write32(sc, COLORFORE,	fg);
   1081       1.1  macallan 	voodoo3_write32(sc, COLORBACK,	bg);
   1082       1.1  macallan 	voodoo3_write32(sc, DSTSIZE,	width | (height << 16));
   1083       1.1  macallan 	voodoo3_write32(sc, DSTXY,	xd | (yd << 16));
   1084       1.1  macallan 	voodoo3_write32(sc, SRCXY,	0);
   1085       1.1  macallan 	voodoo3_write32(sc, COMMAND_2D, COMMAND_2D_H2S_BITBLT |
   1086       1.1  macallan 	    (ROP_COPY << 24) | SST_2D_GO);
   1087       1.1  macallan 
   1088       1.1  macallan 	/* now feed the data into the chip */
   1089       1.1  macallan }
   1090       1.1  macallan 
   1091       1.1  macallan static void
   1092       1.1  macallan voodoofb_feed_line(struct voodoofb_softc *sc, int count, uint8_t *data)
   1093       1.1  macallan {
   1094       1.1  macallan 	int i;
   1095       1.1  macallan 	uint32_t latch = 0, bork;
   1096       1.1  macallan 	int shift = 0;
   1097       1.1  macallan 
   1098       1.1  macallan 	voodoo3_make_room(sc, count);
   1099       1.1  macallan 	for (i = 0; i < count; i++) {
   1100       1.1  macallan 		bork = data[i];
   1101       1.1  macallan 		latch |= (bork << shift);
   1102       1.1  macallan 		if (shift == 24) {
   1103       1.1  macallan 			voodoo3_write32(sc, LAUNCH_2D, latch);
   1104       1.1  macallan 			latch = 0;
   1105       1.1  macallan 			shift = 0;
   1106       1.1  macallan 		} else
   1107       1.1  macallan 			shift += 8;
   1108       1.1  macallan 		}
   1109       1.1  macallan 	if (shift != 24)
   1110       1.1  macallan 		voodoo3_write32(sc, LAUNCH_2D, latch);
   1111       1.1  macallan }
   1112       1.1  macallan 
   1113       1.1  macallan #if 0
   1114       1.1  macallan static int
   1115       1.1  macallan voodoofb_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
   1116       1.1  macallan {
   1117       1.1  macallan 
   1118       1.1  macallan 	return 0;
   1119       1.1  macallan }
   1120       1.1  macallan #endif
   1121       1.1  macallan 
   1122       1.1  macallan /*
   1123       1.1  macallan  * wsdisplay_accessops
   1124       1.1  macallan  */
   1125       1.1  macallan 
   1126       1.1  macallan static int
   1127       1.8  christos voodoofb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
   1128       1.2      jmmv 	struct lwp *l)
   1129       1.1  macallan {
   1130       1.1  macallan 	struct vcons_data *vd = v;
   1131       1.1  macallan 	struct voodoofb_softc *sc = vd->cookie;
   1132       1.1  macallan 	struct wsdisplay_fbinfo *wdf;
   1133       1.1  macallan 	struct vcons_screen *ms = vd->active;
   1134       1.1  macallan 
   1135       1.1  macallan 	switch (cmd) {
   1136      1.25    cegger 	case WSDISPLAYIO_GTYPE:
   1137      1.25    cegger 		*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
   1138      1.25    cegger 		return 0;
   1139      1.25    cegger 
   1140      1.25    cegger 	case WSDISPLAYIO_GINFO:
   1141      1.25    cegger 		wdf = (void *)data;
   1142      1.25    cegger 		wdf->height = ms->scr_ri.ri_height;
   1143      1.25    cegger 		wdf->width = ms->scr_ri.ri_width;
   1144      1.25    cegger 		wdf->depth = ms->scr_ri.ri_depth;
   1145      1.25    cegger 		wdf->cmsize = 256;
   1146      1.25    cegger 		return 0;
   1147      1.25    cegger 
   1148      1.25    cegger 	case WSDISPLAYIO_GETCMAP:
   1149      1.25    cegger 		return voodoofb_getcmap(sc,
   1150      1.25    cegger 		    (struct wsdisplay_cmap *)data);
   1151      1.25    cegger 
   1152      1.25    cegger 	case WSDISPLAYIO_PUTCMAP:
   1153      1.25    cegger 		return voodoofb_putcmap(sc,
   1154      1.25    cegger 		    (struct wsdisplay_cmap *)data);
   1155      1.25    cegger 
   1156      1.25    cegger 	/* PCI config read/write passthrough. */
   1157      1.25    cegger 	case PCI_IOC_CFGREAD:
   1158      1.25    cegger 	case PCI_IOC_CFGWRITE:
   1159      1.25    cegger 		return pci_devioctl(sc->sc_pc, sc->sc_pcitag,
   1160      1.25    cegger 		    cmd, data, flag, l);
   1161      1.27    cegger 
   1162      1.27    cegger 	case WSDISPLAYIO_GET_BUSID:
   1163      1.27    cegger 		return wsdisplayio_busid_pci(sc->sc_dev, sc->sc_pc,
   1164      1.27    cegger 		    sc->sc_pcitag, data);
   1165      1.27    cegger 
   1166      1.25    cegger 	case WSDISPLAYIO_SMODE: {
   1167      1.25    cegger 		int new_mode = *(int*)data;
   1168      1.25    cegger 		if (new_mode != sc->sc_mode) {
   1169      1.25    cegger 			sc->sc_mode = new_mode;
   1170      1.25    cegger 			if (new_mode == WSDISPLAYIO_MODE_EMUL) {
   1171      1.25    cegger 				voodoofb_drm_map(sc);
   1172      1.25    cegger 				int i;
   1173      1.25    cegger 
   1174      1.25    cegger 				/* restore the palette */
   1175      1.25    cegger 				for (i = 0; i < 256; i++) {
   1176      1.25    cegger 					voodoofb_putpalreg(sc,
   1177      1.25    cegger 					   i,
   1178      1.25    cegger 					   sc->sc_cmap_red[i],
   1179      1.25    cegger 					   sc->sc_cmap_green[i],
   1180      1.25    cegger 					   sc->sc_cmap_blue[i]);
   1181       1.1  macallan 				}
   1182  1.28.2.1      yamt 
   1183  1.28.2.1      yamt 				/* zap the glyph cache */
   1184  1.28.2.1      yamt 				for (i = 0; i < 256; i++) {
   1185  1.28.2.1      yamt 					sc->sc_glyphs_defattr[i] = 0;
   1186  1.28.2.1      yamt 					sc->sc_glyphs_kernattr[i] = 0;
   1187  1.28.2.1      yamt 				}
   1188  1.28.2.1      yamt 				sc->sc_usedglyphs = 0;
   1189  1.28.2.1      yamt 
   1190  1.28.2.1      yamt 				voodoofb_clearscreen(sc);
   1191      1.25    cegger 				vcons_redraw_screen(ms);
   1192  1.28.2.1      yamt 			} else {
   1193      1.25    cegger 				voodoofb_drm_unmap(sc);
   1194  1.28.2.1      yamt 			}
   1195      1.25    cegger 		}
   1196      1.25    cegger 		}
   1197      1.25    cegger 		return 0;
   1198       1.1  macallan 	}
   1199       1.1  macallan 	return EPASSTHROUGH;
   1200       1.1  macallan }
   1201       1.1  macallan 
   1202       1.1  macallan static paddr_t
   1203       1.2      jmmv voodoofb_mmap(void *v, void *vs, off_t offset, int prot)
   1204       1.1  macallan {
   1205       1.1  macallan 	struct vcons_data *vd = v;
   1206       1.1  macallan 	struct voodoofb_softc *sc = vd->cookie;
   1207       1.1  macallan 	paddr_t pa;
   1208       1.1  macallan 
   1209       1.1  macallan 	/* 'regular' framebuffer mmap()ing */
   1210       1.1  macallan 	if (offset < sc->sc_fbsize) {
   1211  1.28.2.1      yamt 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
   1212       1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
   1213       1.1  macallan 		return pa;
   1214       1.1  macallan 	}
   1215       1.1  macallan 
   1216      1.14      elad 	/*
   1217      1.14      elad 	 * restrict all other mappings to processes with superuser privileges
   1218      1.14      elad 	 * or the kernel itself
   1219      1.14      elad 	 */
   1220  1.28.2.1      yamt 	if (kauth_authorize_machdep(kauth_cred_get(), KAUTH_MACHDEP_UNMANAGEDMEM,
   1221  1.28.2.1      yamt 	    NULL, NULL, NULL, NULL) != 0) {
   1222      1.19      elad 		aprint_error_dev(sc->sc_dev, "mmap() rejected.\n");
   1223      1.19      elad 		return -1;
   1224      1.14      elad 	}
   1225      1.14      elad 
   1226       1.1  macallan 	if ((offset >= sc->sc_fb) && (offset < (sc->sc_fb + sc->sc_fbsize))) {
   1227       1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
   1228       1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
   1229       1.1  macallan 		return pa;
   1230       1.1  macallan 	}
   1231       1.1  macallan 
   1232       1.1  macallan 	if ((offset >= sc->sc_regs) && (offset < (sc->sc_regs +
   1233       1.1  macallan 	    sc->sc_regsize))) {
   1234       1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
   1235       1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
   1236       1.1  macallan 		return pa;
   1237       1.1  macallan 	}
   1238       1.1  macallan 
   1239      1.13  macallan #ifdef PCI_MAGIC_IO_RANGE
   1240       1.1  macallan 	/* allow mapping of IO space */
   1241      1.13  macallan 	if ((offset >= PCI_MAGIC_IO_RANGE) &&\
   1242      1.13  macallan 	    (offset < PCI_MAGIC_IO_RANGE + 0x10000)) {
   1243      1.13  macallan 		pa = bus_space_mmap(sc->sc_iot, offset - PCI_MAGIC_IO_RANGE,
   1244      1.13  macallan 		    0, prot, BUS_SPACE_MAP_LINEAR);
   1245       1.1  macallan 		return pa;
   1246       1.1  macallan 	}
   1247      1.13  macallan #endif
   1248      1.13  macallan 
   1249       1.1  macallan #ifdef OFB_ALLOW_OTHERS
   1250       1.1  macallan 	if (offset >= 0x80000000) {
   1251       1.1  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
   1252       1.1  macallan 		    BUS_SPACE_MAP_LINEAR);
   1253       1.1  macallan 		return pa;
   1254       1.1  macallan 	}
   1255       1.1  macallan #endif
   1256       1.1  macallan 	return -1;
   1257       1.1  macallan }
   1258       1.1  macallan 
   1259       1.1  macallan static void
   1260       1.1  macallan voodoofb_init_screen(void *cookie, struct vcons_screen *scr,
   1261       1.1  macallan     int existing, long *defattr)
   1262       1.1  macallan {
   1263       1.1  macallan 	struct voodoofb_softc *sc = cookie;
   1264       1.1  macallan 	struct rasops_info *ri = &scr->scr_ri;
   1265       1.1  macallan 
   1266  1.28.2.1      yamt 	ri->ri_depth = sc->sc_bits_per_pixel;
   1267  1.28.2.1      yamt 	ri->ri_width = sc->sc_width;
   1268  1.28.2.1      yamt 	ri->ri_height = sc->sc_height;
   1269  1.28.2.1      yamt 	ri->ri_stride = sc->sc_linebytes;
   1270  1.28.2.1      yamt 	ri->ri_flg = RI_CENTER | RI_8BIT_IS_RGB | RI_ENABLE_ALPHA;
   1271       1.1  macallan 
   1272  1.28.2.1      yamt 	rasops_init(ri, 0, 0);
   1273       1.1  macallan 	ri->ri_caps = WSSCREEN_WSCOLORS;
   1274       1.1  macallan 
   1275  1.28.2.1      yamt 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
   1276  1.28.2.1      yamt 		    sc->sc_width / ri->ri_font->fontwidth);
   1277       1.1  macallan 
   1278       1.1  macallan 	ri->ri_hw = scr;
   1279       1.1  macallan 	ri->ri_ops.copyrows = voodoofb_copyrows;
   1280       1.1  macallan 	ri->ri_ops.copycols = voodoofb_copycols;
   1281       1.1  macallan 	ri->ri_ops.eraserows = voodoofb_eraserows;
   1282       1.1  macallan 	ri->ri_ops.erasecols = voodoofb_erasecols;
   1283       1.1  macallan 	ri->ri_ops.cursor = voodoofb_cursor;
   1284  1.28.2.1      yamt 	if (FONT_IS_ALPHA(ri->ri_font)) {
   1285  1.28.2.1      yamt 		ri->ri_ops.putchar = voodoofb_putchar_aa;
   1286  1.28.2.1      yamt 		ri->ri_ops.allocattr(ri, WS_DEFAULT_FG, WS_DEFAULT_BG,
   1287  1.28.2.1      yamt 		     0, &sc->sc_defattr);
   1288  1.28.2.1      yamt 		sc->sc_kernattr = (WS_KERNEL_FG << 24) | (WS_KERNEL_BG << 16);
   1289  1.28.2.1      yamt 		voodoofb_init_glyphcache(sc, ri);
   1290  1.28.2.1      yamt 	} else {
   1291  1.28.2.1      yamt 		ri->ri_ops.putchar = voodoofb_putchar;
   1292  1.28.2.1      yamt 	}
   1293       1.1  macallan }
   1294       1.1  macallan 
   1295       1.1  macallan #if 0
   1296       1.1  macallan int
   1297       1.1  macallan voodoofb_load_font(void *v, void *cookie, struct wsdisplay_font *data)
   1298       1.1  macallan {
   1299       1.1  macallan 
   1300       1.1  macallan 	return 0;
   1301       1.1  macallan }
   1302       1.1  macallan #endif
   1303       1.1  macallan 
   1304       1.9  jmcneill #ifdef VOODOOFB_ENABLE_INTR
   1305       1.1  macallan static int
   1306       1.1  macallan voodoofb_intr(void *arg)
   1307       1.1  macallan {
   1308       1.1  macallan 	struct voodoofb_softc *sc = arg;
   1309       1.1  macallan 
   1310       1.1  macallan 	voodoo3_write32(sc, V3_STATUS, 0);	/* clear interrupts */
   1311       1.1  macallan 	return 1;
   1312       1.1  macallan }
   1313       1.9  jmcneill #endif
   1314       1.1  macallan 
   1315       1.1  macallan /* video mode stuff */
   1316       1.1  macallan 
   1317       1.1  macallan #define REFFREQ 14318	/* .18 */
   1318       1.1  macallan 
   1319       1.1  macallan #define ABS(a) ((a < 0) ? -a : a)
   1320       1.1  macallan 
   1321       1.1  macallan static int
   1322       1.1  macallan voodoofb_calc_pll(int freq, int *f_out, int isBanshee)
   1323       1.1  macallan {
   1324       1.1  macallan 	int m, n, k, best_m, best_n, best_k, f_cur, best_error;
   1325       1.1  macallan 	int minm, maxm;
   1326       1.1  macallan 
   1327       1.1  macallan 	best_error = freq;
   1328       1.1  macallan 	best_n = best_m = best_k = 0;
   1329       1.1  macallan 
   1330       1.1  macallan 	if (isBanshee) {
   1331       1.1  macallan 		minm = 24;
   1332       1.1  macallan 		maxm = 24;
   1333       1.1  macallan 	} else {
   1334       1.1  macallan 		minm = 1;
   1335       1.1  macallan 		maxm = 57;
   1336       1.1  macallan 		/* This used to be 64, alas it seems the last 8 (funny that ?)
   1337       1.1  macallan 		 * values cause jittering at lower resolutions. I've not done
   1338       1.1  macallan 		 * any calculations to what the adjustment affects clock ranges,
   1339       1.1  macallan 		 * but I can still run at 1600x1200@75Hz */
   1340       1.1  macallan 	}
   1341       1.1  macallan 	for (n = 1; n < 256; n++) {
   1342       1.1  macallan 		f_cur = REFFREQ * (n + 2);
   1343       1.1  macallan 		if (f_cur < freq) {
   1344       1.1  macallan 			f_cur = f_cur / 3;
   1345       1.1  macallan 			if (freq - f_cur < best_error) {
   1346       1.1  macallan 				best_error = freq - f_cur;
   1347       1.1  macallan 				best_n = n;
   1348       1.1  macallan 				best_m = 1;
   1349       1.1  macallan 				best_k = 0;
   1350       1.1  macallan 				continue;
   1351       1.1  macallan       			}
   1352       1.1  macallan 		}
   1353       1.1  macallan 		for (m = minm; m < maxm; m++) {
   1354       1.1  macallan 			for (k = 0; k < 4; k++) {
   1355       1.1  macallan 				f_cur = REFFREQ * (n + 2) / (m + 2) / (1 << k);
   1356       1.1  macallan 				if (ABS(f_cur - freq) < best_error) {
   1357       1.1  macallan 					best_error = ABS(f_cur - freq);
   1358       1.1  macallan 					best_n = n;
   1359       1.1  macallan 					best_m = m;
   1360       1.1  macallan 					best_k = k;
   1361       1.1  macallan 				}
   1362       1.1  macallan 			}
   1363       1.1  macallan 		}
   1364       1.1  macallan 	}
   1365       1.1  macallan 	n = best_n;
   1366       1.1  macallan 	m = best_m;
   1367       1.1  macallan 	k = best_k;
   1368       1.1  macallan 	*f_out = REFFREQ * (n + 2) / (m + 2) / (1 << k);
   1369       1.1  macallan 	return ( n << 8) | (m << 2) | k;
   1370       1.1  macallan }
   1371       1.1  macallan 
   1372       1.1  macallan static void
   1373       1.1  macallan voodoofb_setup_monitor(struct voodoofb_softc *sc, const struct videomode *vm)
   1374       1.1  macallan {
   1375       1.1  macallan 	struct voodoo_regs mod;
   1376       1.1  macallan 	struct voodoo_regs *mode;
   1377       1.1  macallan 	uint32_t horizontal_display_end, horizontal_sync_start,
   1378       1.1  macallan 		horizontal_sync_end, horizontal_total,
   1379       1.1  macallan 		horizontal_blanking_start, horizontal_blanking_end;
   1380       1.1  macallan 
   1381       1.1  macallan 	uint32_t vertical_display_enable_end, vertical_sync_start,
   1382       1.1  macallan 		vertical_sync_end, vertical_total, vertical_blanking_start,
   1383       1.1  macallan 		vertical_blanking_end;
   1384       1.1  macallan 
   1385       1.1  macallan 	uint32_t wd; // CRTC offset
   1386       1.1  macallan 
   1387       1.1  macallan 	int i;
   1388       1.1  macallan 
   1389       1.1  macallan 	uint8_t misc;
   1390       1.1  macallan 
   1391       1.1  macallan 	memset(&mod, 0, sizeof(mode));
   1392       1.1  macallan 
   1393       1.1  macallan 	mode = &mod;
   1394       1.1  macallan 
   1395       1.1  macallan 	wd = (vm->hdisplay >> 3) - 1;
   1396       1.1  macallan 	horizontal_display_end	= (vm->hdisplay >> 3) - 1;
   1397       1.1  macallan 	horizontal_sync_start	= (vm->hsync_start >> 3) - 1;
   1398       1.1  macallan 	horizontal_sync_end	= (vm->hsync_end >> 3) - 1;
   1399       1.1  macallan 	horizontal_total  	= (vm->htotal   >> 3) - 1;
   1400       1.1  macallan 	horizontal_blanking_start = horizontal_display_end;
   1401       1.1  macallan 	horizontal_blanking_end = horizontal_total;
   1402       1.1  macallan 
   1403       1.1  macallan 	vertical_display_enable_end  = vm->vdisplay - 1;
   1404       1.1  macallan 	vertical_sync_start  	= vm->vsync_start;	// - 1;
   1405       1.1  macallan 	vertical_sync_end	= vm->vsync_end;	// - 1;
   1406       1.1  macallan 	vertical_total		= vm->vtotal - 2;
   1407       1.1  macallan 	vertical_blanking_start	= vertical_display_enable_end;
   1408       1.1  macallan 	vertical_blanking_end	= vertical_total;
   1409       1.1  macallan 
   1410  1.28.2.1      yamt #if 0
   1411       1.1  macallan 	misc = 0x0f |
   1412       1.1  macallan 	    (vm->hdisplay < 400 ? 0xa0 :
   1413       1.1  macallan 		vm->hdisplay < 480 ? 0x60 :
   1414       1.1  macallan 		vm->hdisplay < 768 ? 0xe0 : 0x20);
   1415  1.28.2.1      yamt #else
   1416  1.28.2.1      yamt 	misc = 0x2f;
   1417  1.28.2.1      yamt 	if (vm->flags & VID_NHSYNC)
   1418  1.28.2.1      yamt 		misc |= HSYNC_NEG;
   1419  1.28.2.1      yamt 	if (vm->flags & VID_NVSYNC)
   1420  1.28.2.1      yamt 		misc |= VSYNC_NEG;
   1421  1.28.2.1      yamt #ifdef VOODOOFB_DEBUG
   1422  1.28.2.1      yamt 	printf("misc: %02x\n", misc);
   1423  1.28.2.1      yamt #endif
   1424  1.28.2.1      yamt #endif
   1425       1.1  macallan 	mode->vr_seq[0] = 3;
   1426       1.1  macallan 	mode->vr_seq[1] = 1;
   1427       1.1  macallan 	mode->vr_seq[2] = 8;
   1428       1.1  macallan 	mode->vr_seq[3] = 0;
   1429       1.1  macallan 	mode->vr_seq[4] = 6;
   1430       1.1  macallan 
   1431       1.1  macallan 	/* crtc regs start */
   1432       1.1  macallan 	mode->vr_crtc[0] = horizontal_total - 4;
   1433       1.1  macallan 	mode->vr_crtc[1] = horizontal_display_end;
   1434       1.1  macallan 	mode->vr_crtc[2] = horizontal_blanking_start;
   1435       1.1  macallan 	mode->vr_crtc[3] = 0x80 | (horizontal_blanking_end & 0x1f);
   1436       1.1  macallan 	mode->vr_crtc[4] = horizontal_sync_start;
   1437       1.1  macallan 
   1438       1.1  macallan 	mode->vr_crtc[5] = ((horizontal_blanking_end & 0x20) << 2) |
   1439       1.1  macallan 	    (horizontal_sync_end & 0x1f);
   1440       1.1  macallan 	mode->vr_crtc[6] = vertical_total;
   1441       1.1  macallan 	mode->vr_crtc[7] = ((vertical_sync_start & 0x200) >> 2) |
   1442       1.1  macallan 	    ((vertical_display_enable_end & 0x200) >> 3) |
   1443       1.1  macallan 	    ((vertical_total & 0x200) >> 4) |
   1444       1.1  macallan 	    0x10 |
   1445       1.1  macallan 	    ((vertical_blanking_start & 0x100) >> 5) |
   1446       1.1  macallan 	    ((vertical_sync_start  & 0x100) >> 6) |
   1447       1.1  macallan 	    ((vertical_display_enable_end  & 0x100) >> 7) |
   1448       1.1  macallan 	    ((vertical_total  & 0x100) >> 8);
   1449       1.1  macallan 
   1450       1.1  macallan 	mode->vr_crtc[8] = 0;
   1451       1.1  macallan 	mode->vr_crtc[9] = 0x40 |
   1452       1.1  macallan 	    ((vertical_blanking_start & 0x200) >> 4);
   1453       1.1  macallan 
   1454       1.1  macallan 	mode->vr_crtc[10] = 0;
   1455       1.1  macallan 	mode->vr_crtc[11] = 0;
   1456       1.1  macallan 	mode->vr_crtc[12] = 0;
   1457       1.1  macallan 	mode->vr_crtc[13] = 0;
   1458       1.1  macallan 	mode->vr_crtc[14] = 0;
   1459       1.1  macallan 	mode->vr_crtc[15] = 0;
   1460       1.1  macallan 
   1461       1.1  macallan 	mode->vr_crtc[16] = vertical_sync_start;
   1462       1.1  macallan 	mode->vr_crtc[17] = (vertical_sync_end & 0x0f) | 0x20;
   1463       1.1  macallan 	mode->vr_crtc[18] = vertical_display_enable_end;
   1464       1.1  macallan 	mode->vr_crtc[19] = wd; // CRTC offset
   1465       1.1  macallan 	mode->vr_crtc[20] = 0;
   1466       1.1  macallan 	mode->vr_crtc[21] = vertical_blanking_start;
   1467       1.1  macallan 	mode->vr_crtc[22] = vertical_blanking_end + 1;
   1468       1.1  macallan 	mode->vr_crtc[23] = 128;
   1469       1.1  macallan 	mode->vr_crtc[24] = 255;
   1470      1.23  macallan 
   1471      1.23  macallan 	/* overflow registers */
   1472      1.23  macallan 	mode->vr_crtc[CRTC_HDISP_EXT] =
   1473      1.23  macallan 	    (horizontal_total&0x100) >> 8 |
   1474      1.23  macallan 	    (horizontal_display_end & 0x100) >> 6 |
   1475      1.23  macallan 	    (horizontal_blanking_start & 0x100) >> 4 |
   1476      1.23  macallan 	    (horizontal_blanking_end & 0x40) >> 1 |
   1477      1.23  macallan 	    (horizontal_sync_start & 0x100) >> 2 |
   1478      1.23  macallan 	    (horizontal_sync_end & 0x20) << 2;
   1479      1.23  macallan 
   1480      1.23  macallan 	mode->vr_crtc[CRTC_VDISP_EXT] =
   1481      1.23  macallan 	    (vertical_total & 0x400) >> 10 |
   1482  1.28.2.1      yamt 	    (vertical_display_enable_end & 0x400) >> 8 | /* the manual is contradictory here */
   1483      1.23  macallan 	    (vertical_blanking_start & 0x400) >> 6 |
   1484      1.23  macallan 	    (vertical_blanking_end & 0x400) >> 4;
   1485       1.1  macallan 
   1486       1.1  macallan 	/* attr regs start */
   1487       1.1  macallan 	mode->vr_attr[0] = 0;
   1488       1.1  macallan 	mode->vr_attr[1] = 0;
   1489       1.1  macallan 	mode->vr_attr[2] = 0;
   1490       1.1  macallan 	mode->vr_attr[3] = 0;
   1491       1.1  macallan 	mode->vr_attr[4] = 0;
   1492       1.1  macallan 	mode->vr_attr[5] = 0;
   1493       1.1  macallan 	mode->vr_attr[6] = 0;
   1494       1.1  macallan 	mode->vr_attr[7] = 0;
   1495       1.1  macallan 	mode->vr_attr[8] = 0;
   1496       1.1  macallan 	mode->vr_attr[9] = 0;
   1497       1.1  macallan 	mode->vr_attr[10] = 0;
   1498       1.1  macallan 	mode->vr_attr[11] = 0;
   1499       1.1  macallan 	mode->vr_attr[12] = 0;
   1500       1.1  macallan 	mode->vr_attr[13] = 0;
   1501       1.1  macallan 	mode->vr_attr[14] = 0;
   1502       1.1  macallan 	mode->vr_attr[15] = 0;
   1503       1.1  macallan 	mode->vr_attr[16] = 1;
   1504       1.1  macallan 	mode->vr_attr[17] = 0;
   1505       1.1  macallan 	mode->vr_attr[18] = 15;
   1506       1.1  macallan 	mode->vr_attr[19] = 0;
   1507       1.1  macallan 	/* attr regs end */
   1508       1.1  macallan 
   1509       1.1  macallan 	/* graph regs start */
   1510       1.1  macallan 	mode->vr_graph[0] = 159;
   1511       1.1  macallan 	mode->vr_graph[1] = 127;
   1512       1.1  macallan 	mode->vr_graph[2] = 127;
   1513       1.1  macallan 	mode->vr_graph[3] = 131;
   1514       1.1  macallan 	mode->vr_graph[4] = 130;
   1515       1.1  macallan 	mode->vr_graph[5] = 142;
   1516       1.1  macallan 	mode->vr_graph[6] = 30;
   1517       1.1  macallan 	mode->vr_graph[7] = 245;
   1518       1.1  macallan 	mode->vr_graph[8] = 0;
   1519       1.1  macallan 
   1520       1.1  macallan 	vga_outb(sc, MISC_W, misc | 0x01);
   1521       1.1  macallan 
   1522       1.1  macallan 	for(i = 0; i < 5; i++)
   1523       1.1  macallan 		voodoo3_write_seq(sc, i, mode->vr_seq[i]);
   1524      1.23  macallan 	for (i = 0; i < CRTC_PCI_READBACK; i ++)
   1525       1.1  macallan         	voodoo3_write_crtc(sc, i, mode->vr_crtc[i]);
   1526       1.1  macallan 	for (i = 0; i < 0x14; i ++)
   1527       1.1  macallan         	voodoo3_write_attr(sc, i, mode->vr_attr[i]);
   1528       1.1  macallan 	for (i = 0; i < 0x09; i ++)
   1529       1.1  macallan         	voodoo3_write_gra(sc, i, mode->vr_graph[i]);
   1530       1.1  macallan }
   1531       1.1  macallan 
   1532       1.1  macallan static void
   1533       1.1  macallan voodoofb_set_videomode(struct voodoofb_softc *sc,
   1534       1.1  macallan     const struct videomode *vm)
   1535       1.1  macallan {
   1536       1.1  macallan 	uint32_t miscinit0 = 0;
   1537       1.1  macallan 	int vidpll, fout;
   1538       1.1  macallan 	uint32_t vp, vidproc = VIDPROCDEFAULT;
   1539       1.1  macallan 	uint32_t bpp = 1;	/* for now */
   1540       1.1  macallan 	uint32_t bytes_per_row = vm->hdisplay * bpp;
   1541       1.1  macallan 
   1542  1.28.2.1      yamt 	sc->sc_bits_per_pixel = bpp << 3;
   1543  1.28.2.1      yamt 	sc->sc_width = vm->hdisplay;
   1544  1.28.2.1      yamt 	sc->sc_height = vm->vdisplay;
   1545  1.28.2.1      yamt 	sc->sc_linebytes = bytes_per_row;
   1546       1.1  macallan 
   1547       1.1  macallan 	voodoofb_setup_monitor(sc, vm);
   1548       1.1  macallan 	vp = voodoo3_read32(sc, VIDPROCCFG);
   1549       1.1  macallan 
   1550       1.3  macallan 	vidproc &= ~(0x1c0000); /* clear bits 18 to 20, bpp in vidproccfg */
   1551       1.3  macallan 	/* enable bits 18 to 20 to the required bpp */
   1552       1.3  macallan 	vidproc |= ((bpp - 1) << VIDCFG_PIXFMT_SHIFT);
   1553       1.1  macallan 
   1554       1.1  macallan 	vidpll = voodoofb_calc_pll(vm->dot_clock, &fout, 0);
   1555       1.1  macallan 
   1556       1.1  macallan #ifdef VOODOOFB_DEBUG
   1557       1.1  macallan 	printf("old vidproc: %08x\n", vp);
   1558       1.1  macallan 	printf("pll: %08x %d\n", vidpll, fout);
   1559       1.1  macallan #endif
   1560       1.3  macallan 	/* bit 10 of vidproccfg, is enabled or disabled as needed */
   1561       1.3  macallan 	switch (bpp) {
   1562       1.1  macallan 		case 1:
   1563       1.3  macallan 			/*
   1564       1.3  macallan 			 * bit 10 off for palettized modes only, off means
   1565       1.3  macallan 			 * palette is used
   1566       1.3  macallan 			 */
   1567       1.3  macallan 			vidproc &= ~(1 << 10);
   1568       1.1  macallan 			break;
   1569       1.1  macallan #if 0
   1570       1.1  macallan 		case 2:
   1571       1.1  macallan 			#if __POWERPC__
   1572       1.1  macallan 				miscinit0 = 0xc0000000;
   1573       1.1  macallan 			#endif
   1574       1.3  macallan 			/* bypass palette for 16bit modes */
   1575       1.3  macallan 			vidproc |= (1 << 10);
   1576       1.1  macallan 			break;
   1577       1.1  macallan 		case 4:
   1578       1.1  macallan 			#if __POWERPC__
   1579       1.1  macallan 				miscinit0 = 0x40000000;
   1580       1.1  macallan 			#endif
   1581       1.3  macallan 			vidproc |= (1 << 10); /* Same for 32bit modes */
   1582       1.1  macallan 			break;
   1583       1.1  macallan #endif
   1584       1.1  macallan 		default:
   1585       1.1  macallan 			printf("We support only 8 bit for now\n");
   1586       1.1  macallan 			return;
   1587       1.1  macallan 	}
   1588       1.1  macallan 
   1589       1.1  macallan 	voodoofb_wait_idle(sc);
   1590       1.1  macallan 
   1591       1.1  macallan 	voodoo3_write32(sc, MISCINIT1, voodoo3_read32(sc, MISCINIT1) | 0x01);
   1592       1.1  macallan 
   1593       1.1  macallan 	voodoo3_make_room(sc, 4);
   1594       1.1  macallan 	voodoo3_write32(sc, VGAINIT0, 4928);
   1595       1.1  macallan 	voodoo3_write32(sc, DACMODE, 0);
   1596       1.1  macallan 	voodoo3_write32(sc, VIDDESKSTRIDE, bytes_per_row);
   1597       1.1  macallan 	voodoo3_write32(sc, PLLCTRL0, vidpll);
   1598       1.1  macallan 
   1599       1.1  macallan 	voodoo3_make_room(sc, 5);
   1600  1.28.2.1      yamt 	voodoo3_write32(sc, VIDSCREENSIZE, sc->sc_width |
   1601  1.28.2.1      yamt 	    (sc->sc_height << 12));
   1602      1.23  macallan 	voodoo3_write32(sc, VIDDESKSTART,  0);
   1603       1.1  macallan 
   1604       1.1  macallan 	vidproc &= ~VIDCFG_HWCURSOR_ENABLE;
   1605       1.1  macallan 	voodoo3_write32(sc, VIDPROCCFG, vidproc);
   1606       1.1  macallan 
   1607       1.1  macallan 	voodoo3_write32(sc, VGAINIT1, 0);
   1608       1.1  macallan 	voodoo3_write32(sc, MISCINIT0, miscinit0);
   1609       1.1  macallan #ifdef VOODOOFB_DEBUG
   1610       1.1  macallan 	printf("vidproc: %08x\n", vidproc);
   1611       1.1  macallan #endif
   1612       1.1  macallan 	voodoo3_make_room(sc, 8);
   1613       1.1  macallan 	voodoo3_write32(sc, SRCBASE, 0);
   1614       1.1  macallan 	voodoo3_write32(sc, DSTBASE, 0);
   1615       1.1  macallan 	voodoo3_write32(sc, COMMANDEXTRA_2D, 0);
   1616       1.1  macallan   	voodoo3_write32(sc, CLIP0MIN,        0);
   1617       1.1  macallan   	voodoo3_write32(sc, CLIP0MAX,        0x0fff0fff);
   1618       1.1  macallan   	voodoo3_write32(sc, CLIP1MIN,        0);
   1619       1.1  macallan   	voodoo3_write32(sc, CLIP1MAX,        0x0fff0fff);
   1620       1.1  macallan 	voodoo3_write32(sc, SRCXY, 0);
   1621       1.1  macallan 	voodoofb_wait_idle(sc);
   1622      1.18     joerg 	printf("%s: switched to %dx%d, %d bit\n", device_xname(sc->sc_dev),
   1623  1.28.2.1      yamt 	    sc->sc_width, sc->sc_height, sc->sc_bits_per_pixel);
   1624  1.28.2.1      yamt 	sc->sc_numglyphs = 0;	/* invalidate the glyph cache */
   1625       1.1  macallan }
   1626       1.1  macallan 
   1627       1.1  macallan static void
   1628       1.1  macallan voodoofb_init(struct voodoofb_softc *sc)
   1629       1.1  macallan {
   1630       1.1  macallan 	/* XXX */
   1631       1.1  macallan 	uint32_t vgainit0 = 0;
   1632       1.1  macallan 	uint32_t vidcfg = 0;
   1633       1.1  macallan 
   1634       1.1  macallan #ifdef VOODOOFB_DEBUG
   1635       1.1  macallan 	printf("initializing engine...");
   1636       1.1  macallan #endif
   1637       1.1  macallan 	vgainit0 = voodoo3_read32(sc, VGAINIT0);
   1638       1.1  macallan #ifdef VOODOOFB_DEBUG
   1639       1.1  macallan 	printf("vga: %08x", vgainit0);
   1640       1.1  macallan #endif
   1641       1.1  macallan 	vgainit0 |=
   1642       1.1  macallan 	    VGAINIT0_8BIT_DAC     |
   1643       1.1  macallan 	    VGAINIT0_EXT_ENABLE   |
   1644       1.1  macallan 	    VGAINIT0_WAKEUP_3C3   |
   1645       1.1  macallan 	    VGAINIT0_ALT_READBACK |
   1646       1.1  macallan 	    VGAINIT0_EXTSHIFTOUT;
   1647       1.1  macallan 
   1648       1.1  macallan 	vidcfg = voodoo3_read32(sc, VIDPROCCFG);
   1649       1.1  macallan #ifdef VOODOOFB_DEBUG
   1650       1.1  macallan 	printf(" vidcfg: %08x\n", vidcfg);
   1651       1.1  macallan #endif
   1652       1.1  macallan 	vidcfg |=
   1653       1.1  macallan 	    VIDCFG_VIDPROC_ENABLE |
   1654       1.1  macallan 	    VIDCFG_DESK_ENABLE;
   1655       1.1  macallan 	vidcfg &= ~VIDCFG_HWCURSOR_ENABLE;
   1656       1.1  macallan 
   1657       1.1  macallan 	voodoo3_make_room(sc, 2);
   1658       1.1  macallan 
   1659       1.1  macallan 	voodoo3_write32(sc, VGAINIT0, vgainit0);
   1660       1.1  macallan 	voodoo3_write32(sc, VIDPROCCFG, vidcfg);
   1661       1.1  macallan 
   1662       1.1  macallan 	voodoo3_make_room(sc, 8);
   1663       1.1  macallan 	voodoo3_write32(sc, SRCBASE, 0);
   1664       1.1  macallan 	voodoo3_write32(sc, DSTBASE, 0);
   1665       1.1  macallan 	voodoo3_write32(sc, COMMANDEXTRA_2D, 0);
   1666       1.1  macallan   	voodoo3_write32(sc, CLIP0MIN,        0);
   1667       1.1  macallan   	voodoo3_write32(sc, CLIP0MAX,        0x1fff1fff);
   1668       1.1  macallan   	voodoo3_write32(sc, CLIP1MIN,        0);
   1669       1.1  macallan   	voodoo3_write32(sc, CLIP1MAX,        0x1fff1fff);
   1670       1.1  macallan 	voodoo3_write32(sc, SRCXY, 0);
   1671       1.1  macallan 
   1672       1.1  macallan 	voodoofb_wait_idle(sc);
   1673       1.1  macallan }
   1674  1.28.2.1      yamt 
   1675  1.28.2.1      yamt #define MAX_HRES  1700		/*
   1676  1.28.2.1      yamt 				 * XXX in theory we can go higher but I
   1677  1.28.2.1      yamt 				 * couldn't get anything above 1680 x 1200
   1678  1.28.2.1      yamt 				 * to work, so until I find out why, it's
   1679  1.28.2.1      yamt 				 * disabled so people won't end up with a
   1680  1.28.2.1      yamt 				 * blank screen
   1681  1.28.2.1      yamt 				 */
   1682  1.28.2.3      yamt #define MODE_IS_VALID(m, mclk) (((m)->dot_clock <= (mclk)) && \
   1683  1.28.2.1      yamt 					    ((m)->hdisplay < MAX_HRES))
   1684  1.28.2.1      yamt static void
   1685  1.28.2.1      yamt voodoofb_setup_i2c(struct voodoofb_softc *sc)
   1686  1.28.2.1      yamt {
   1687  1.28.2.1      yamt 	int i;
   1688  1.28.2.1      yamt 
   1689  1.28.2.1      yamt 	/* Fill in the i2c tag */
   1690  1.28.2.1      yamt 	sc->sc_i2c.ic_cookie = sc;
   1691  1.28.2.1      yamt 	sc->sc_i2c.ic_acquire_bus = voodoofb_i2c_acquire_bus;
   1692  1.28.2.1      yamt 	sc->sc_i2c.ic_release_bus = voodoofb_i2c_release_bus;
   1693  1.28.2.1      yamt 	sc->sc_i2c.ic_send_start = voodoofb_i2c_send_start;
   1694  1.28.2.1      yamt 	sc->sc_i2c.ic_send_stop = voodoofb_i2c_send_stop;
   1695  1.28.2.1      yamt 	sc->sc_i2c.ic_initiate_xfer = voodoofb_i2c_initiate_xfer;
   1696  1.28.2.1      yamt 	sc->sc_i2c.ic_read_byte = voodoofb_i2c_read_byte;
   1697  1.28.2.1      yamt 	sc->sc_i2c.ic_write_byte = voodoofb_i2c_write_byte;
   1698  1.28.2.1      yamt 	sc->sc_i2c.ic_exec = NULL;
   1699  1.28.2.1      yamt 
   1700  1.28.2.1      yamt 	sc->sc_i2creg = voodoo3_read32(sc, VIDSERPARPORT);
   1701  1.28.2.1      yamt #ifdef VOODOOFB_DEBUG
   1702  1.28.2.1      yamt 	printf("data: %08x\n", sc->sc_i2creg);
   1703  1.28.2.1      yamt #endif
   1704  1.28.2.1      yamt 	sc->sc_i2creg |= VSP_ENABLE_IIC0;
   1705  1.28.2.1      yamt 	sc->sc_i2creg &= ~(VSP_SDA0_OUT | VSP_SCL0_OUT);
   1706  1.28.2.1      yamt 	voodoo3_write32(sc, VIDSERPARPORT, sc->sc_i2creg);
   1707  1.28.2.1      yamt 
   1708  1.28.2.1      yamt 	/* zero out the EDID buffer */
   1709  1.28.2.1      yamt 	memset(sc->sc_edid_data, 0, 128);
   1710  1.28.2.1      yamt 
   1711  1.28.2.1      yamt 	/* Some monitors don't respond first time */
   1712  1.28.2.1      yamt 	i = 0;
   1713  1.28.2.1      yamt 	while (sc->sc_edid_data[1] == 0 && i++ < 3)
   1714  1.28.2.1      yamt 		ddc_read_edid(&sc->sc_i2c, sc->sc_edid_data, 128);
   1715  1.28.2.1      yamt 	if (i < 3) {
   1716  1.28.2.1      yamt 		if (edid_parse(sc->sc_edid_data, &sc->sc_edid_info) != -1) {
   1717  1.28.2.1      yamt #ifdef VOODOOFB_DEBUG
   1718  1.28.2.1      yamt 			edid_print(&sc->sc_edid_info);
   1719  1.28.2.1      yamt #endif
   1720  1.28.2.1      yamt 			/*
   1721  1.28.2.1      yamt 			 * Now pick a mode.
   1722  1.28.2.1      yamt 			 * How do we know our max. pixel clock?
   1723  1.28.2.1      yamt 			 * All Voodoo3 should support at least 250MHz.
   1724  1.28.2.1      yamt 			 * All Voodoo3 I've seen so far have at least 8MB
   1725  1.28.2.1      yamt 			 * which we're not going to exhaust either in 8bit.
   1726  1.28.2.1      yamt 			 */
   1727  1.28.2.1      yamt 			if ((sc->sc_edid_info.edid_preferred_mode != NULL)) {
   1728  1.28.2.1      yamt 				struct videomode *m =
   1729  1.28.2.1      yamt 				    sc->sc_edid_info.edid_preferred_mode;
   1730  1.28.2.3      yamt 				if (MODE_IS_VALID(m, sc->sc_max_clock)) {
   1731  1.28.2.1      yamt 					sc->sc_videomode = m;
   1732  1.28.2.1      yamt 				} else {
   1733  1.28.2.1      yamt 					aprint_error_dev(sc->sc_dev,
   1734  1.28.2.1      yamt 					    "unable to use preferred mode\n");
   1735  1.28.2.1      yamt 				}
   1736  1.28.2.1      yamt 			}
   1737  1.28.2.1      yamt 			/*
   1738  1.28.2.1      yamt 			 * if we can't use the preferred mode go look for the
   1739  1.28.2.1      yamt 			 * best one we can support
   1740  1.28.2.1      yamt 			 */
   1741  1.28.2.1      yamt 			if (sc->sc_videomode == NULL) {
   1742  1.28.2.2      yamt 				int n = 0;
   1743  1.28.2.1      yamt 				struct videomode *m =
   1744  1.28.2.1      yamt 				     sc->sc_edid_info.edid_modes;
   1745  1.28.2.1      yamt 
   1746  1.28.2.1      yamt 				sort_modes(sc->sc_edid_info.edid_modes,
   1747  1.28.2.1      yamt 			   	    &sc->sc_edid_info.edid_preferred_mode,
   1748  1.28.2.1      yamt 				    sc->sc_edid_info.edid_nmodes);
   1749  1.28.2.1      yamt 				while ((sc->sc_videomode == NULL) &&
   1750  1.28.2.1      yamt 				       (n < sc->sc_edid_info.edid_nmodes)) {
   1751  1.28.2.3      yamt 					if (MODE_IS_VALID(&m[n],
   1752  1.28.2.3      yamt 					    sc->sc_max_clock)) {
   1753  1.28.2.1      yamt 						sc->sc_videomode = &m[n];
   1754  1.28.2.1      yamt 					}
   1755  1.28.2.1      yamt 					n++;
   1756  1.28.2.1      yamt 				}
   1757  1.28.2.1      yamt 			}
   1758  1.28.2.1      yamt 		}
   1759  1.28.2.1      yamt 	}
   1760  1.28.2.1      yamt }
   1761  1.28.2.1      yamt 
   1762  1.28.2.1      yamt /* I2C bitbanging */
   1763  1.28.2.1      yamt static void voodoofb_i2cbb_set_bits(void *cookie, uint32_t bits)
   1764  1.28.2.1      yamt {
   1765  1.28.2.1      yamt 	struct voodoofb_softc *sc = cookie;
   1766  1.28.2.1      yamt 	uint32_t out;
   1767  1.28.2.1      yamt 
   1768  1.28.2.1      yamt 	out = bits >> 2;	/* bitmasks match the IN bits */
   1769  1.28.2.1      yamt 
   1770  1.28.2.1      yamt 	voodoo3_write32(sc, VIDSERPARPORT, sc->sc_i2creg | out);
   1771  1.28.2.1      yamt }
   1772  1.28.2.1      yamt 
   1773  1.28.2.1      yamt static void voodoofb_i2cbb_set_dir(void *cookie, uint32_t dir)
   1774  1.28.2.1      yamt {
   1775  1.28.2.1      yamt 	/* Nothing to do */
   1776  1.28.2.1      yamt }
   1777  1.28.2.1      yamt 
   1778  1.28.2.1      yamt static uint32_t voodoofb_i2cbb_read(void *cookie)
   1779  1.28.2.1      yamt {
   1780  1.28.2.1      yamt 	struct voodoofb_softc *sc = cookie;
   1781  1.28.2.1      yamt 	uint32_t bits;
   1782  1.28.2.1      yamt 
   1783  1.28.2.1      yamt 	bits = voodoo3_read32(sc, VIDSERPARPORT);
   1784  1.28.2.1      yamt 
   1785  1.28.2.1      yamt 	return bits;
   1786  1.28.2.1      yamt }
   1787  1.28.2.1      yamt 
   1788  1.28.2.1      yamt /* higher level I2C stuff */
   1789  1.28.2.1      yamt static int
   1790  1.28.2.1      yamt voodoofb_i2c_acquire_bus(void *cookie, int flags)
   1791  1.28.2.1      yamt {
   1792  1.28.2.1      yamt 	/* private bus */
   1793  1.28.2.1      yamt 	return (0);
   1794  1.28.2.1      yamt }
   1795  1.28.2.1      yamt 
   1796  1.28.2.1      yamt static void
   1797  1.28.2.1      yamt voodoofb_i2c_release_bus(void *cookie, int flags)
   1798  1.28.2.1      yamt {
   1799  1.28.2.1      yamt 	/* private bus */
   1800  1.28.2.1      yamt }
   1801  1.28.2.1      yamt 
   1802  1.28.2.1      yamt static int
   1803  1.28.2.1      yamt voodoofb_i2c_send_start(void *cookie, int flags)
   1804  1.28.2.1      yamt {
   1805  1.28.2.1      yamt 	return (i2c_bitbang_send_start(cookie, flags, &voodoofb_i2cbb_ops));
   1806  1.28.2.1      yamt }
   1807  1.28.2.1      yamt 
   1808  1.28.2.1      yamt static int
   1809  1.28.2.1      yamt voodoofb_i2c_send_stop(void *cookie, int flags)
   1810  1.28.2.1      yamt {
   1811  1.28.2.1      yamt 
   1812  1.28.2.1      yamt 	return (i2c_bitbang_send_stop(cookie, flags, &voodoofb_i2cbb_ops));
   1813  1.28.2.1      yamt }
   1814  1.28.2.1      yamt 
   1815  1.28.2.1      yamt static int
   1816  1.28.2.1      yamt voodoofb_i2c_initiate_xfer(void *cookie, i2c_addr_t addr, int flags)
   1817  1.28.2.1      yamt {
   1818  1.28.2.1      yamt 
   1819  1.28.2.1      yamt 	return (i2c_bitbang_initiate_xfer(cookie, addr, flags,
   1820  1.28.2.1      yamt 	    &voodoofb_i2cbb_ops));
   1821  1.28.2.1      yamt }
   1822  1.28.2.1      yamt 
   1823  1.28.2.1      yamt static int
   1824  1.28.2.1      yamt voodoofb_i2c_read_byte(void *cookie, uint8_t *valp, int flags)
   1825  1.28.2.1      yamt {
   1826  1.28.2.1      yamt 	return (i2c_bitbang_read_byte(cookie, valp, flags, &voodoofb_i2cbb_ops));
   1827  1.28.2.1      yamt }
   1828  1.28.2.1      yamt 
   1829  1.28.2.1      yamt static int
   1830  1.28.2.1      yamt voodoofb_i2c_write_byte(void *cookie, uint8_t val, int flags)
   1831  1.28.2.1      yamt {
   1832  1.28.2.1      yamt 	return (i2c_bitbang_write_byte(cookie, val, flags, &voodoofb_i2cbb_ops));
   1833  1.28.2.1      yamt }
   1834  1.28.2.1      yamt 
   1835  1.28.2.1      yamt /* glyph cache */
   1836  1.28.2.1      yamt static void
   1837  1.28.2.1      yamt voodoofb_init_glyphcache(struct voodoofb_softc *sc, struct rasops_info *ri)
   1838  1.28.2.1      yamt {
   1839  1.28.2.1      yamt 	int bufsize, i;
   1840  1.28.2.1      yamt 
   1841  1.28.2.1      yamt 	if (sc->sc_numglyphs != 0) {
   1842  1.28.2.1      yamt 		/* re-initialize */
   1843  1.28.2.1      yamt 		if (ri->ri_font == sc->sc_font) {
   1844  1.28.2.1      yamt 			/* nothing to do, keep using the same cache */
   1845  1.28.2.1      yamt 			return;
   1846  1.28.2.1      yamt 		}
   1847  1.28.2.1      yamt 	}
   1848  1.28.2.1      yamt 	sc->sc_cache = (ri->ri_width * ri->ri_stride + 3) & 0xfffffffc;
   1849  1.28.2.1      yamt 	bufsize = sc->sc_memsize - sc->sc_cache;
   1850  1.28.2.1      yamt 	sc->sc_numglyphs = bufsize / ri->ri_fontscale;
   1851  1.28.2.1      yamt 	sc->sc_usedglyphs = 0;
   1852  1.28.2.1      yamt 	for (i = 0; i < 256; i++) {
   1853  1.28.2.1      yamt 		sc->sc_glyphs_kernattr[i] = 0;
   1854  1.28.2.1      yamt 		sc->sc_glyphs_defattr[i] = 0;
   1855  1.28.2.1      yamt 	}
   1856  1.28.2.1      yamt 	sc->sc_fmt = ri->ri_font->fontwidth | FMT_8BIT;
   1857  1.28.2.1      yamt }
   1858