Home | History | Annotate | Line # | Download | only in pci
machfb.c revision 1.2
      1  1.2    martin /*	$NetBSD: machfb.c,v 1.2 2002/10/24 20:41:59 martin Exp $	*/
      2  1.1  junyoung 
      3  1.1  junyoung /*
      4  1.1  junyoung  * Copyright (c) 2002 Bang Jun-Young
      5  1.1  junyoung  * All rights reserved.
      6  1.1  junyoung  *
      7  1.1  junyoung  * Redistribution and use in source and binary forms, with or without
      8  1.1  junyoung  * modification, are permitted provided that the following conditions
      9  1.1  junyoung  * are met:
     10  1.1  junyoung  * 1. Redistributions of source code must retain the above copyright
     11  1.1  junyoung  *    notice, this list of conditions and the following disclaimer.
     12  1.1  junyoung  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  junyoung  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  junyoung  *    documentation and/or other materials provided with the distribution.
     15  1.1  junyoung  * 3. The name of the author may not be used to endorse or promote products
     16  1.1  junyoung  *    derived from this software without specific prior written permission
     17  1.1  junyoung  *
     18  1.1  junyoung  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1  junyoung  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1  junyoung  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1  junyoung  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1  junyoung  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.1  junyoung  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.1  junyoung  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.1  junyoung  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.1  junyoung  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.1  junyoung  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1  junyoung  */
     29  1.1  junyoung 
     30  1.1  junyoung /*
     31  1.1  junyoung  * Some code is derived from ATI Rage Pro and Derivatives Programmer's Guide.
     32  1.1  junyoung  */
     33  1.1  junyoung 
     34  1.1  junyoung #include <sys/cdefs.h>
     35  1.1  junyoung 
     36  1.1  junyoung #include <sys/param.h>
     37  1.1  junyoung #include <sys/systm.h>
     38  1.1  junyoung #include <sys/kernel.h>
     39  1.1  junyoung #include <sys/device.h>
     40  1.1  junyoung #include <sys/malloc.h>
     41  1.1  junyoung #include <sys/callout.h>
     42  1.1  junyoung 
     43  1.1  junyoung #include <dev/ic/videomode.h>
     44  1.1  junyoung 
     45  1.1  junyoung #include <dev/pci/pcivar.h>
     46  1.1  junyoung #include <dev/pci/pcireg.h>
     47  1.1  junyoung #include <dev/pci/pcidevs.h>
     48  1.1  junyoung #include <dev/pci/pciio.h>
     49  1.1  junyoung #include <dev/pci/machfbreg.h>
     50  1.1  junyoung 
     51  1.1  junyoung #include <dev/wscons/wsdisplayvar.h>
     52  1.1  junyoung #include <dev/wscons/wsconsio.h>
     53  1.1  junyoung #include <dev/wsfont/wsfont.h>
     54  1.1  junyoung #include <dev/rasops/rasops.h>
     55  1.1  junyoung 
     56  1.1  junyoung #define MACH64_REG_SIZE		1024
     57  1.1  junyoung 
     58  1.1  junyoung #define	NBARS		3	/* number of Mach64 PCI BARs */
     59  1.1  junyoung 
     60  1.1  junyoung struct vga_bar {
     61  1.1  junyoung 	bus_addr_t vb_base;
     62  1.1  junyoung 	bus_size_t vb_size;
     63  1.1  junyoung 	pcireg_t vb_type;
     64  1.1  junyoung 	int vb_flags;
     65  1.1  junyoung };
     66  1.1  junyoung 
     67  1.1  junyoung struct mach64_softc {
     68  1.1  junyoung 	struct device sc_dev;
     69  1.1  junyoung 	pci_chipset_tag_t sc_pc;
     70  1.1  junyoung 	pcitag_t sc_pcitag;
     71  1.1  junyoung 
     72  1.1  junyoung 	struct vga_bar sc_bars[NBARS];
     73  1.1  junyoung 	struct vga_bar sc_rom;
     74  1.1  junyoung 
     75  1.1  junyoung #define sc_aperbase 	sc_bars[0].vb_base
     76  1.1  junyoung #define sc_apersize	sc_bars[0].vb_size
     77  1.1  junyoung 
     78  1.1  junyoung #define sc_iobase	sc_bars[1].vb_base
     79  1.1  junyoung #define sc_iosize	sc_bars[1].vb_size
     80  1.1  junyoung 
     81  1.1  junyoung #define sc_regbase	sc_bars[2].vb_base
     82  1.1  junyoung #define sc_regsize	sc_bars[2].vb_size
     83  1.1  junyoung 
     84  1.1  junyoung 	bus_space_handle_t sc_regh;
     85  1.1  junyoung 	bus_space_handle_t sc_memh;
     86  1.1  junyoung 
     87  1.2    martin 	u_long aperbase;
     88  1.1  junyoung 	size_t apersize;
     89  1.2    martin 	u_long regbase;
     90  1.1  junyoung 	size_t regsize;
     91  1.1  junyoung 	size_t memsize;
     92  1.1  junyoung 	int memtype;
     93  1.1  junyoung 
     94  1.1  junyoung 	int has_dsp;
     95  1.1  junyoung 	int bits_per_pixel;
     96  1.1  junyoung 	int max_x, max_y;
     97  1.1  junyoung 	int virt_x, virt_y;
     98  1.1  junyoung 	int color_depth;
     99  1.1  junyoung 
    100  1.1  junyoung 	int mem_freq;
    101  1.1  junyoung 	int ramdac_freq;
    102  1.1  junyoung 	int ref_freq;
    103  1.1  junyoung 
    104  1.1  junyoung 	int ref_div;
    105  1.1  junyoung 	int log2_vclk_post_div;
    106  1.1  junyoung 	int vclk_post_div;
    107  1.1  junyoung 	int vclk_fb_div;
    108  1.1  junyoung 	int mclk_post_div;
    109  1.1  junyoung 	int mclk_fb_div;
    110  1.1  junyoung 
    111  1.1  junyoung 	struct mach64screen *wanted;
    112  1.1  junyoung 	struct mach64screen *active;
    113  1.1  junyoung 	void (*switchcb)(void *, int, int);
    114  1.1  junyoung 	void *switchcbarg;
    115  1.1  junyoung 	struct callout switch_callout;
    116  1.1  junyoung 	int nscreens;
    117  1.1  junyoung 	LIST_HEAD(, mach64screen) screens;
    118  1.1  junyoung 	const struct wsscreen_descr *currenttype;
    119  1.1  junyoung };
    120  1.1  junyoung 
    121  1.1  junyoung struct mach64screen {
    122  1.1  junyoung 	LIST_ENTRY(mach64screen) next;
    123  1.1  junyoung 	struct mach64_softc *sc;
    124  1.1  junyoung 	const struct wsscreen_descr *type;
    125  1.1  junyoung 	int active;
    126  1.1  junyoung 	u_int16_t *mem;
    127  1.1  junyoung 	int dispoffset;
    128  1.1  junyoung 	int mindispoffset;
    129  1.1  junyoung 	int maxdispoffset;
    130  1.1  junyoung 
    131  1.1  junyoung 	int cursoron;
    132  1.1  junyoung 	int cursorcol;
    133  1.1  junyoung 	int cursorrow;
    134  1.1  junyoung 	u_int16_t cursortmp;
    135  1.1  junyoung };
    136  1.1  junyoung 
    137  1.1  junyoung struct mach64_crtcregs {
    138  1.1  junyoung 	u_int32_t h_total_disp;
    139  1.1  junyoung 	u_int32_t h_sync_strt_wid;
    140  1.1  junyoung 	u_int32_t v_total_disp;
    141  1.1  junyoung 	u_int32_t v_sync_strt_wid;
    142  1.1  junyoung 	u_int32_t gen_cntl;
    143  1.1  junyoung 	u_int32_t clock_cntl;
    144  1.1  junyoung 	u_int32_t color_depth;
    145  1.1  junyoung 	u_int32_t dot_clock;
    146  1.1  junyoung };
    147  1.1  junyoung 
    148  1.1  junyoung struct {
    149  1.1  junyoung 	u_int16_t chip_id;
    150  1.1  junyoung 	u_int32_t ramdac_freq;
    151  1.1  junyoung } mach64_info[] = {
    152  1.1  junyoung 	{ PCI_PRODUCT_ATI_MACH64_CT, 135000 },
    153  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_PRO_AGP, 230000 },
    154  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_PRO_AGP1X, 230000 },
    155  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_PRO_PCI_B, 230000 },
    156  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_XL_AGP, 230000 },
    157  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_PRO_PCI_P, 230000 },
    158  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_PRO_PCI_L, 230000 },
    159  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_XL_PCI, 230000 },
    160  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_II, 135000 },
    161  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_IIP, 200000 },
    162  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_IIC_PCI, 230000 },
    163  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_IIC_AGP_B, 230000 },
    164  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_IIC_AGP_P, 230000 },
    165  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_LT_PRO_AGP, 230000 },
    166  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_MOB_M3_PCI, 230000 },
    167  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_MOB_M3_AGP, 230000 },
    168  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_LT, 230000 },
    169  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_LT_PRO_PCI, 230000 },
    170  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_MOBILITY, 230000 },
    171  1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_LT_PRO, 230000 },
    172  1.1  junyoung 	{ PCI_PRODUCT_ATI_MACH64_VT, 170000 },
    173  1.1  junyoung 	{ PCI_PRODUCT_ATI_MACH64_VTB, 200000 },
    174  1.1  junyoung 	{ PCI_PRODUCT_ATI_MACH64_VT4, 230000 }
    175  1.1  junyoung };
    176  1.1  junyoung 
    177  1.1  junyoung static int mach64_chip_id, mach64_chip_rev;
    178  1.1  junyoung static struct videomode default_mode;
    179  1.1  junyoung struct rasops_info mach64_rasops_info;
    180  1.1  junyoung static struct mach64screen mach64_console_screen;
    181  1.1  junyoung 
    182  1.1  junyoung static char *mach64_memtype_names[] = {
    183  1.1  junyoung 	"(N/A)", "DRAM", "EDO DRAM", "EDO DRAM", "SDRAM", "SGRAM", "WRAM",
    184  1.1  junyoung 	"(unknown type)"
    185  1.1  junyoung };
    186  1.1  junyoung 
    187  1.1  junyoung struct videomode mach64_modes[] = {
    188  1.1  junyoung 	/* 640x400 @ 70 Hz, 31.5 kHz */
    189  1.1  junyoung 	{ 25175, 640, 664, 760, 800, 400, 409, 411, 450, 0 },
    190  1.1  junyoung 	/* 640x480 @ 72 Hz, 36.5 kHz */
    191  1.1  junyoung 	{ 25175, 640, 664, 760, 800, 480, 491, 493, 525, 0 },
    192  1.1  junyoung 	/* 800x600 @ 72 Hz, 48.0 kHz */
    193  1.1  junyoung 	{ 50000, 800, 856, 976, 1040, 600, 637, 643, 666,
    194  1.1  junyoung 	  VID_PHSYNC | VID_PVSYNC },
    195  1.1  junyoung 	/* 1024x768 @ 70 Hz, 56.5 kHz */
    196  1.1  junyoung 	{ 75000, 1024, 1048, 1184, 1328, 768, 771, 777, 806,
    197  1.1  junyoung 	  VID_NHSYNC | VID_NVSYNC },
    198  1.1  junyoung 	/* 1152x864 @ 70 Hz, 62.4 kHz */
    199  1.1  junyoung 	{ 92000, 1152, 1208, 1368, 1474, 864, 865, 875, 895, 0 },
    200  1.1  junyoung 	/* 1280x1024 @ 70 Hz, 74.59 kHz */
    201  1.1  junyoung 	{ 126500, 1280, 1312, 1472, 1696, 1024, 1032, 1040, 1068,
    202  1.1  junyoung 	  VID_NHSYNC | VID_NVSYNC }
    203  1.1  junyoung };
    204  1.1  junyoung 
    205  1.1  junyoung /* FIXME values are wrong! */
    206  1.1  junyoung const u_char mach64_cmap[16 * 3] = {
    207  1.1  junyoung 	0x00, 0x00, 0x00, /* black */
    208  1.1  junyoung 	0x7f, 0x00, 0x00, /* red */
    209  1.1  junyoung 	0x00, 0x7f, 0x00, /* green */
    210  1.1  junyoung 	0x7f, 0x7f, 0x00, /* brown */
    211  1.1  junyoung 	0x00, 0x00, 0x7f, /* blue */
    212  1.1  junyoung 	0x7f, 0x00, 0x7f, /* magenta */
    213  1.1  junyoung 	0x00, 0x7f, 0x7f, /* cyan */
    214  1.1  junyoung 	0xff, 0xff, 0xff, /* white */
    215  1.1  junyoung 
    216  1.1  junyoung 	0x7f, 0x7f, 0x7f, /* black */
    217  1.1  junyoung 	0xff, 0x00, 0x00, /* red */
    218  1.1  junyoung 	0x00, 0xff, 0x00, /* green */
    219  1.1  junyoung 	0xff, 0xff, 0x00, /* brown */
    220  1.1  junyoung 	0x00, 0x00, 0xff, /* blue */
    221  1.1  junyoung 	0xff, 0x00, 0xff, /* magenta */
    222  1.1  junyoung 	0x00, 0xff, 0xff, /* cyan */
    223  1.1  junyoung 	0xff, 0xff, 0xff, /* white */
    224  1.1  junyoung };
    225  1.1  junyoung 
    226  1.1  junyoung int	mach64_match(struct device *, struct cfdata *, void *);
    227  1.1  junyoung void	mach64_attach(struct device *, struct device *, void *);
    228  1.1  junyoung 
    229  1.1  junyoung CFATTACH_DECL(machfb, sizeof(struct mach64_softc), mach64_match, mach64_attach,
    230  1.1  junyoung     NULL, NULL);
    231  1.1  junyoung 
    232  1.1  junyoung void	mach64_init(struct mach64_softc *, bus_space_tag_t);
    233  1.1  junyoung int	mach64_get_memsize(struct mach64_softc *);
    234  1.1  junyoung int	mach64_get_max_ramdac(struct mach64_softc *);
    235  1.1  junyoung void	mach64_get_mode(struct mach64_softc *, struct videomode *);
    236  1.1  junyoung int	mach64_calc_crtcregs(struct mach64_softc *, struct mach64_crtcregs *,
    237  1.1  junyoung 	    struct videomode *);
    238  1.1  junyoung void	mach64_set_crtcregs(struct mach64_softc *, struct mach64_crtcregs *);
    239  1.1  junyoung int	mach64_modeswitch(struct mach64_softc *, struct videomode *);
    240  1.1  junyoung void	mach64_set_dsp(struct mach64_softc *);
    241  1.1  junyoung void	mach64_set_pll(struct mach64_softc *, int);
    242  1.1  junyoung void	mach64_reset_engine(struct mach64_softc *);
    243  1.1  junyoung void	mach64_init_engine(struct mach64_softc *);
    244  1.1  junyoung void	mach64_adjust_frame(struct mach64_softc *, int, int);
    245  1.1  junyoung void	mach64_init_lut(struct mach64_softc *);
    246  1.1  junyoung void	mach64_switch_screen(struct mach64_softc *);
    247  1.1  junyoung void	mach64_init_screen(struct mach64_softc *, struct mach64screen *,
    248  1.1  junyoung 	    const struct wsscreen_descr *, int, long *);
    249  1.1  junyoung void	mach64_restore_screen(struct mach64screen *,
    250  1.1  junyoung 	    const struct wsscreen_descr *, u_int16_t *);
    251  1.1  junyoung void 	mach64_set_screentype(struct mach64_softc *,
    252  1.1  junyoung 	    const struct wsscreen_descr *);
    253  1.1  junyoung 
    254  1.1  junyoung void	mach64_cursor(void *, int, int, int);
    255  1.1  junyoung int	mach64_mapchar(void *, int, u_int *);
    256  1.1  junyoung void	mach64_putchar(void *, int, int, u_int, long);
    257  1.1  junyoung void	mach64_copycols(void *, int, int, int, int);
    258  1.1  junyoung void	mach64_erasecols(void *, int, int, int, long);
    259  1.1  junyoung void	mach64_copyrows(void *, int, int, int);
    260  1.1  junyoung void	mach64_eraserows(void *, int, int, long);
    261  1.1  junyoung int	mach64_allocattr(void *, int, int, int, long *);
    262  1.1  junyoung 
    263  1.1  junyoung const struct wsdisplay_emulops mach64_emulops = {
    264  1.1  junyoung 	mach64_cursor,
    265  1.1  junyoung 	mach64_mapchar,
    266  1.1  junyoung 	mach64_putchar,
    267  1.1  junyoung 	mach64_copycols,
    268  1.1  junyoung 	mach64_erasecols,
    269  1.1  junyoung 	mach64_copyrows,
    270  1.1  junyoung 	mach64_eraserows,
    271  1.1  junyoung 	mach64_allocattr,
    272  1.1  junyoung };
    273  1.1  junyoung 
    274  1.1  junyoung struct wsscreen_descr mach64_defaultscreen = {
    275  1.1  junyoung 	"default",
    276  1.1  junyoung 	0, 0,
    277  1.1  junyoung 	&mach64_rasops_info.ri_ops,
    278  1.1  junyoung 	8, 16,
    279  1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    280  1.1  junyoung 	&default_mode
    281  1.1  junyoung }, mach64_80x25_screen = {
    282  1.1  junyoung 	"80x25", 80, 25,
    283  1.1  junyoung 	&mach64_rasops_info.ri_ops,
    284  1.1  junyoung 	8, 16,
    285  1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    286  1.1  junyoung 	&mach64_modes[0]
    287  1.1  junyoung }, mach64_80x30_screen = {
    288  1.1  junyoung 	"80x30", 80, 30,
    289  1.1  junyoung 	&mach64_rasops_info.ri_ops,
    290  1.1  junyoung 	8, 16,
    291  1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    292  1.1  junyoung 	&mach64_modes[1]
    293  1.1  junyoung }, mach64_80x40_screen = {
    294  1.1  junyoung 	"80x40", 80, 40,
    295  1.1  junyoung 	&mach64_rasops_info.ri_ops,
    296  1.1  junyoung 	8, 10,
    297  1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    298  1.1  junyoung 	&mach64_modes[0]
    299  1.1  junyoung }, mach64_80x50_screen = {
    300  1.1  junyoung 	"80x50", 80, 50,
    301  1.1  junyoung 	&mach64_rasops_info.ri_ops,
    302  1.1  junyoung 	8, 8,
    303  1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    304  1.1  junyoung 	&mach64_modes[0]
    305  1.1  junyoung }, mach64_100x37_screen = {
    306  1.1  junyoung 	"100x37", 100, 37,
    307  1.1  junyoung 	&mach64_rasops_info.ri_ops,
    308  1.1  junyoung 	8, 16,
    309  1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    310  1.1  junyoung 	&mach64_modes[2]
    311  1.1  junyoung }, mach64_128x48_screen = {
    312  1.1  junyoung 	"128x48", 128, 48,
    313  1.1  junyoung 	&mach64_rasops_info.ri_ops,
    314  1.1  junyoung 	8, 16,
    315  1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    316  1.1  junyoung 	&mach64_modes[3]
    317  1.1  junyoung }, mach64_144x54_screen = {
    318  1.1  junyoung 	"144x54", 144, 54,
    319  1.1  junyoung 	&mach64_rasops_info.ri_ops,
    320  1.1  junyoung 	8, 16,
    321  1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    322  1.1  junyoung 	&mach64_modes[4]
    323  1.1  junyoung }, mach64_160x64_screen = {
    324  1.1  junyoung 	"160x54", 160, 64,
    325  1.1  junyoung 	&mach64_rasops_info.ri_ops,
    326  1.1  junyoung 	8, 16,
    327  1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    328  1.1  junyoung 	&mach64_modes[5]
    329  1.1  junyoung };
    330  1.1  junyoung 
    331  1.1  junyoung const struct wsscreen_descr *_mach64_scrlist[] = {
    332  1.1  junyoung 	&mach64_defaultscreen,
    333  1.1  junyoung 	&mach64_80x25_screen,
    334  1.1  junyoung 	&mach64_80x30_screen,
    335  1.1  junyoung 	&mach64_80x40_screen,
    336  1.1  junyoung 	&mach64_80x50_screen,
    337  1.1  junyoung 	&mach64_100x37_screen,
    338  1.1  junyoung 	&mach64_128x48_screen,
    339  1.1  junyoung 	&mach64_144x54_screen,
    340  1.1  junyoung 	&mach64_160x64_screen
    341  1.1  junyoung };
    342  1.1  junyoung 
    343  1.1  junyoung struct wsscreen_list mach64_screenlist = {
    344  1.1  junyoung 	sizeof(_mach64_scrlist) / sizeof(struct wsscreen_descr *),
    345  1.1  junyoung 	_mach64_scrlist
    346  1.1  junyoung };
    347  1.1  junyoung 
    348  1.1  junyoung int	mach64_ioctl(void *, u_long, caddr_t, int, struct proc *);
    349  1.1  junyoung paddr_t	mach64_mmap(void *, off_t, int);
    350  1.1  junyoung int	mach64_alloc_screen(void *, const struct wsscreen_descr *, void **,
    351  1.1  junyoung 	    int *, int *, long *);
    352  1.1  junyoung void	mach64_free_screen(void *, void *);
    353  1.1  junyoung int	mach64_show_screen(void *, void *, int, void (*)(void *, int, int),
    354  1.1  junyoung 	    void *);
    355  1.1  junyoung int	mach64_load_font(void *, void *, struct wsdisplay_font *);
    356  1.1  junyoung 
    357  1.1  junyoung struct wsdisplay_accessops mach64_accessops = {
    358  1.1  junyoung 	mach64_ioctl,
    359  1.1  junyoung 	mach64_mmap,
    360  1.1  junyoung 	mach64_alloc_screen,
    361  1.1  junyoung 	mach64_free_screen,
    362  1.1  junyoung 	mach64_show_screen,
    363  1.1  junyoung 	NULL
    364  1.1  junyoung };
    365  1.1  junyoung 
    366  1.1  junyoung /*
    367  1.1  junyoung  * Inline functions for getting access to register aperture.
    368  1.1  junyoung  */
    369  1.1  junyoung static inline u_int32_t regr(struct mach64_softc *, u_int32_t);
    370  1.1  junyoung static inline u_int8_t regrb(struct mach64_softc *, u_int32_t);
    371  1.1  junyoung static inline void regw(struct mach64_softc *, u_int32_t, u_int32_t);
    372  1.1  junyoung static inline void regwb(struct mach64_softc *, u_int32_t, u_int8_t);
    373  1.1  junyoung static inline void regwb_pll(struct mach64_softc *, u_int32_t, u_int8_t);
    374  1.1  junyoung 
    375  1.1  junyoung static inline u_int32_t
    376  1.1  junyoung regr(struct mach64_softc *sc, u_int32_t index)
    377  1.1  junyoung {
    378  1.1  junyoung 
    379  1.1  junyoung 	return (*(u_int32_t *)(sc->regbase + index));
    380  1.1  junyoung }
    381  1.1  junyoung 
    382  1.1  junyoung static inline u_int8_t
    383  1.1  junyoung regrb(struct mach64_softc *sc, u_int32_t index)
    384  1.1  junyoung {
    385  1.1  junyoung 
    386  1.1  junyoung 	return (*(u_int8_t *)(sc->regbase + index));
    387  1.1  junyoung }
    388  1.1  junyoung 
    389  1.1  junyoung static inline void
    390  1.1  junyoung regw(struct mach64_softc *sc, u_int32_t index, u_int32_t data)
    391  1.1  junyoung {
    392  1.1  junyoung 
    393  1.1  junyoung 	*(u_int32_t *)(sc->regbase + index) = data;
    394  1.1  junyoung }
    395  1.1  junyoung 
    396  1.1  junyoung static inline void
    397  1.1  junyoung regwb(struct mach64_softc *sc, u_int32_t index, u_int8_t data)
    398  1.1  junyoung {
    399  1.1  junyoung 
    400  1.1  junyoung 	*(u_int8_t *)(sc->regbase + index) = data;
    401  1.1  junyoung }
    402  1.1  junyoung 
    403  1.1  junyoung static inline void
    404  1.1  junyoung regwb_pll(struct mach64_softc *sc, u_int32_t index, u_int8_t data)
    405  1.1  junyoung {
    406  1.1  junyoung 
    407  1.1  junyoung 	regwb(sc, CLOCK_CNTL + 1, (index << 2) | PLL_WR_EN);
    408  1.1  junyoung 	regwb(sc, CLOCK_CNTL + 2, data);
    409  1.1  junyoung 	regwb(sc, CLOCK_CNTL + 1, (index << 2) & ~PLL_WR_EN);
    410  1.1  junyoung }
    411  1.1  junyoung 
    412  1.1  junyoung static inline void
    413  1.1  junyoung wait_for_fifo(struct mach64_softc *sc, u_int8_t v)
    414  1.1  junyoung {
    415  1.1  junyoung 
    416  1.1  junyoung 	while ((regr(sc, FIFO_STAT) & 0xffff) > (0x8000 >> v))
    417  1.1  junyoung 		;
    418  1.1  junyoung }
    419  1.1  junyoung 
    420  1.1  junyoung static inline void
    421  1.1  junyoung wait_for_idle(struct mach64_softc *sc)
    422  1.1  junyoung {
    423  1.1  junyoung 
    424  1.1  junyoung 	wait_for_fifo(sc, 16);
    425  1.1  junyoung 	while ((regr(sc, GUI_STAT) & 1) != 0)
    426  1.1  junyoung 		;
    427  1.1  junyoung }
    428  1.1  junyoung 
    429  1.1  junyoung int
    430  1.1  junyoung mach64_match(struct device *parent, struct cfdata *match, void *aux)
    431  1.1  junyoung {
    432  1.1  junyoung 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
    433  1.1  junyoung 	int i;
    434  1.1  junyoung 
    435  1.1  junyoung 	if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
    436  1.1  junyoung 	    PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
    437  1.1  junyoung 		return 0;
    438  1.1  junyoung 
    439  1.1  junyoung 	for (i = 0; i < sizeof(mach64_info) / sizeof(mach64_info[0]); i++)
    440  1.1  junyoung 		if (PCI_PRODUCT(pa->pa_id) == mach64_info[i].chip_id) {
    441  1.1  junyoung 			mach64_chip_id = PCI_PRODUCT(pa->pa_id);
    442  1.1  junyoung 			mach64_chip_rev = PCI_REVISION(pa->pa_class);
    443  1.1  junyoung 			return 1;
    444  1.1  junyoung 		}
    445  1.1  junyoung 
    446  1.1  junyoung 	return 0;
    447  1.1  junyoung }
    448  1.1  junyoung 
    449  1.1  junyoung void
    450  1.1  junyoung mach64_attach(struct device *parent, struct device *self, void *aux)
    451  1.1  junyoung {
    452  1.1  junyoung 	struct mach64_softc *sc = (void *)self;
    453  1.1  junyoung 	struct pci_attach_args *pa = aux;
    454  1.1  junyoung 	char devinfo[256];
    455  1.1  junyoung 	int bar, reg, id;
    456  1.1  junyoung 	struct wsemuldisplaydev_attach_args aa;
    457  1.1  junyoung 	int console;
    458  1.1  junyoung 	long defattr;
    459  1.1  junyoung 
    460  1.1  junyoung 	sc->sc_pc = pa->pa_pc;
    461  1.1  junyoung 	sc->sc_pcitag = pa->pa_tag;
    462  1.1  junyoung 
    463  1.1  junyoung 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    464  1.1  junyoung 	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
    465  1.1  junyoung 
    466  1.1  junyoung 	for (bar = 0; bar < NBARS; bar++) {
    467  1.1  junyoung 		reg = PCI_MAPREG_START + (bar * 4);
    468  1.1  junyoung 		sc->sc_bars[bar].vb_type = pci_mapreg_type(sc->sc_pc,
    469  1.1  junyoung 		    sc->sc_pcitag, reg);
    470  1.1  junyoung 		(void)pci_mapreg_info(sc->sc_pc, sc->sc_pcitag, reg,
    471  1.1  junyoung 		    sc->sc_bars[bar].vb_type, &sc->sc_bars[bar].vb_base,
    472  1.1  junyoung 		    &sc->sc_bars[bar].vb_size, &sc->sc_bars[bar].vb_flags);
    473  1.1  junyoung 	}
    474  1.1  junyoung 
    475  1.1  junyoung 	mach64_init(sc, pa->pa_memt);
    476  1.1  junyoung 
    477  1.1  junyoung 	sc->aperbase = (vaddr_t)bus_space_vaddr(pa->pa_memt, sc->sc_memh);
    478  1.1  junyoung 	sc->apersize = sc->sc_apersize;
    479  1.1  junyoung 
    480  1.1  junyoung 	sc->regbase = sc->aperbase + 0x7ffc00;
    481  1.1  junyoung 	sc->regsize = MACH64_REG_SIZE;
    482  1.1  junyoung 
    483  1.1  junyoung #if _BYTE_ORDER == _BIG_ENDIAN
    484  1.1  junyoung 	sc->aperbase += 0x800000;
    485  1.1  junyoung 	sc->apersize -= 0x800000;
    486  1.1  junyoung #endif
    487  1.1  junyoung 
    488  1.1  junyoung 	printf("%s: %d MB aperture at 0x%08x, %d KB registers at 0x%08x\n",
    489  1.1  junyoung 	    sc->sc_dev.dv_xname, (u_int)(sc->apersize / (1024 * 1024)),
    490  1.1  junyoung 	    (u_int)sc->aperbase, (u_int)(sc->regsize / 1024),
    491  1.1  junyoung 	    (u_int)sc->regbase);
    492  1.1  junyoung 
    493  1.1  junyoung 	if (mach64_chip_id == PCI_PRODUCT_ATI_MACH64_CT ||
    494  1.1  junyoung 	    ((mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||
    495  1.1  junyoung 	      mach64_chip_id == PCI_PRODUCT_ATI_RAGE_II) &&
    496  1.1  junyoung 	      (mach64_chip_rev & 0x07) == 0))
    497  1.1  junyoung 		sc->has_dsp = 0;
    498  1.1  junyoung 	else
    499  1.1  junyoung 		sc->has_dsp = 1;
    500  1.1  junyoung 
    501  1.1  junyoung 	sc->memsize = mach64_get_memsize(sc);
    502  1.1  junyoung 	if (sc->memsize == 8192)
    503  1.1  junyoung 		/* The last page is used as register aperture. */
    504  1.1  junyoung 		sc->memsize -= 4;
    505  1.1  junyoung 	sc->memtype = regr(sc, CONFIG_STAT0) & 0x07;
    506  1.1  junyoung 
    507  1.1  junyoung 	/* XXX is there any way to calculate reference frequency from
    508  1.1  junyoung 	   known values? */
    509  1.1  junyoung 	if (mach64_chip_id == PCI_PRODUCT_ATI_RAGE_XL_PCI)
    510  1.1  junyoung 		sc->ref_freq = 29498;
    511  1.1  junyoung 	else
    512  1.1  junyoung 		sc->ref_freq = 14318;
    513  1.1  junyoung 
    514  1.1  junyoung 	regwb(sc, CLOCK_CNTL + 1, PLL_REF_DIV << 2);
    515  1.1  junyoung 	sc->ref_div = regrb(sc, CLOCK_CNTL + 2);
    516  1.1  junyoung 	regwb(sc, CLOCK_CNTL + 1, MCLK_FB_DIV << 2);
    517  1.1  junyoung 	sc->mclk_fb_div = regrb(sc, CLOCK_CNTL + 2);
    518  1.1  junyoung 	sc->mem_freq = (2 * sc->ref_freq * sc->mclk_fb_div) /
    519  1.1  junyoung 	    (sc->ref_div * 2);
    520  1.1  junyoung 	sc->mclk_post_div = (sc->mclk_fb_div * 2 * sc->ref_freq) /
    521  1.1  junyoung 	    (sc->mem_freq * sc->ref_div);
    522  1.1  junyoung 	sc->ramdac_freq = mach64_get_max_ramdac(sc);
    523  1.2    martin 	printf("%s: %ld KB %s %d.%d MHz, maximum RAMDAC clock %d MHz\n",
    524  1.1  junyoung 	    sc->sc_dev.dv_xname, sc->memsize,
    525  1.1  junyoung 	    mach64_memtype_names[sc->memtype],
    526  1.1  junyoung 	    sc->mem_freq / 1000, sc->mem_freq % 1000,
    527  1.1  junyoung 	    sc->ramdac_freq / 1000);
    528  1.1  junyoung 
    529  1.1  junyoung 	id = regr(sc, CONFIG_CHIP_ID) & 0xffff;
    530  1.1  junyoung 	if (id != mach64_chip_id) {
    531  1.1  junyoung 		printf("%s: chip ID mismatch, 0x%x != 0x%x\n",
    532  1.1  junyoung 		    sc->sc_dev.dv_xname, id, mach64_chip_id);
    533  1.1  junyoung 		return;
    534  1.1  junyoung 	}
    535  1.1  junyoung 
    536  1.1  junyoung #ifdef __sparc__
    537  1.1  junyoung 	mach64_get_mode(sc, &default_mode);
    538  1.1  junyoung #else
    539  1.1  junyoung 	memcpy(&default_mode, &mach64_modes[0], sizeof(struct videomode)) ;
    540  1.1  junyoung #endif
    541  1.1  junyoung 
    542  1.1  junyoung 	sc->bits_per_pixel = 8;
    543  1.1  junyoung 	sc->virt_x = default_mode.hdisplay;
    544  1.1  junyoung 	sc->virt_y = default_mode.vdisplay;
    545  1.1  junyoung 	sc->max_x = sc->virt_x - 1;
    546  1.1  junyoung 	sc->max_y = (sc->memsize * 1024) /
    547  1.1  junyoung 	    (sc->virt_x * (sc->bits_per_pixel / 8)) - 1;
    548  1.1  junyoung 
    549  1.1  junyoung 	sc->color_depth = CRTC_PIX_WIDTH_8BPP;
    550  1.1  junyoung 
    551  1.1  junyoung 	mach64_init_engine(sc);
    552  1.1  junyoung #if 0
    553  1.1  junyoung 	mach64_adjust_frame(0, 0);
    554  1.1  junyoung 	if (sc->bits_per_pixel == 8)
    555  1.1  junyoung 		mach64_init_lut(sc);
    556  1.1  junyoung #endif
    557  1.1  junyoung 
    558  1.1  junyoung 	printf("%s: initial resolution %dx%d at %d bpp\n", sc->sc_dev.dv_xname,
    559  1.1  junyoung 	    default_mode.hdisplay, default_mode.vdisplay,
    560  1.1  junyoung 	    sc->bits_per_pixel);
    561  1.1  junyoung 
    562  1.1  junyoung 	mach64_rasops_info.ri_depth = sc->bits_per_pixel;
    563  1.1  junyoung 	mach64_rasops_info.ri_bits = (void *)sc->aperbase;
    564  1.1  junyoung 	mach64_rasops_info.ri_width = default_mode.hdisplay;
    565  1.1  junyoung 	mach64_rasops_info.ri_height = default_mode.vdisplay;
    566  1.1  junyoung 	mach64_rasops_info.ri_stride = mach64_rasops_info.ri_width;
    567  1.1  junyoung 	mach64_rasops_info.ri_flg = RI_CLEAR;
    568  1.1  junyoung 
    569  1.1  junyoung 	rasops_init(&mach64_rasops_info, mach64_rasops_info.ri_height / 16,
    570  1.1  junyoung 	    mach64_rasops_info.ri_width / 8);
    571  1.1  junyoung 
    572  1.1  junyoung 	mach64_defaultscreen.nrows = mach64_rasops_info.ri_rows;
    573  1.1  junyoung 	mach64_defaultscreen.ncols = mach64_rasops_info.ri_cols;
    574  1.1  junyoung 
    575  1.1  junyoung 	mach64_init_screen(sc, &mach64_console_screen,
    576  1.1  junyoung 	    &mach64_defaultscreen, 1, &defattr);
    577  1.1  junyoung 
    578  1.1  junyoung 	mach64_rasops_info.ri_ops.allocattr(&mach64_rasops_info, 0, 0, 0,
    579  1.1  junyoung 	    &defattr);
    580  1.1  junyoung 	wsdisplay_cnattach(&mach64_defaultscreen, &mach64_rasops_info,
    581  1.1  junyoung 	    0, 0, defattr);
    582  1.1  junyoung 
    583  1.1  junyoung 	console = 1;
    584  1.1  junyoung 
    585  1.1  junyoung 	aa.console = console;
    586  1.1  junyoung 	aa.scrdata = &mach64_screenlist;
    587  1.1  junyoung 	aa.accessops = &mach64_accessops;
    588  1.1  junyoung 	aa.accesscookie = sc;
    589  1.1  junyoung 
    590  1.1  junyoung 	config_found(self, &aa, wsemuldisplaydevprint);
    591  1.1  junyoung }
    592  1.1  junyoung 
    593  1.1  junyoung void
    594  1.1  junyoung mach64_init_screen(struct mach64_softc *sc, struct mach64screen *scr,
    595  1.1  junyoung     const struct wsscreen_descr *type, int existing, long *attrp)
    596  1.1  junyoung {
    597  1.2    martin #if !defined(__sparc__)
    598  1.1  junyoung 	struct videomode *mode = (struct videomode *)type->modecookie;
    599  1.2    martin #endif
    600  1.1  junyoung 
    601  1.1  junyoung 	scr->sc = sc;
    602  1.1  junyoung 	scr->type = type;
    603  1.1  junyoung 	scr->mindispoffset = 0;
    604  1.1  junyoung 	scr->maxdispoffset = sc->memsize * 1024;
    605  1.1  junyoung 	scr->dispoffset = 0;
    606  1.1  junyoung 	scr->cursorcol = 0;
    607  1.1  junyoung 	scr->cursorrow = 0;
    608  1.1  junyoung 
    609  1.1  junyoung 	if (existing) {
    610  1.1  junyoung 		scr->mem = (u_int16_t *)malloc(type->nrows * type->ncols * 2,
    611  1.1  junyoung 		    M_DEVBUF, M_WAITOK);
    612  1.1  junyoung 		scr->active = 1;
    613  1.1  junyoung 
    614  1.1  junyoung #if !defined(__sparc__)
    615  1.1  junyoung 		if (mach64_modeswitch(sc, mode)) {
    616  1.1  junyoung 			panic("%s: failed to switch video mode",
    617  1.1  junyoung 			    sc->sc_dev.dv_xname);
    618  1.1  junyoung 		}
    619  1.1  junyoung #endif
    620  1.1  junyoung 	} else {
    621  1.1  junyoung 		scr->active = 0;
    622  1.1  junyoung 		scr->mem = NULL;
    623  1.1  junyoung 	}
    624  1.1  junyoung 
    625  1.1  junyoung 	wsfont_init();
    626  1.1  junyoung 
    627  1.1  junyoung 	sc->nscreens++;
    628  1.1  junyoung 	LIST_INSERT_HEAD(&sc->screens, scr, next);
    629  1.1  junyoung }
    630  1.1  junyoung 
    631  1.1  junyoung void
    632  1.1  junyoung mach64_init(struct mach64_softc *sc, bus_space_tag_t memt)
    633  1.1  junyoung {
    634  1.1  junyoung 
    635  1.1  junyoung 	if (bus_space_map(memt, sc->sc_aperbase, sc->sc_apersize,
    636  1.1  junyoung 		BUS_SPACE_MAP_LINEAR, &sc->sc_memh)) {
    637  1.1  junyoung 		panic("%s: failed to map aperture", sc->sc_dev.dv_xname);
    638  1.1  junyoung 	}
    639  1.1  junyoung 
    640  1.1  junyoung 	sc->nscreens = 0;
    641  1.1  junyoung 	LIST_INIT(&sc->screens);
    642  1.1  junyoung 	sc->active = NULL;
    643  1.1  junyoung 	sc->currenttype = &mach64_defaultscreen;
    644  1.1  junyoung 	callout_init(&sc->switch_callout);
    645  1.1  junyoung }
    646  1.1  junyoung 
    647  1.1  junyoung int
    648  1.1  junyoung mach64_get_memsize(struct mach64_softc *sc)
    649  1.1  junyoung {
    650  1.1  junyoung 	int tmp, memsize;
    651  1.1  junyoung 	int mem_tab[] = {
    652  1.1  junyoung 		512, 1024, 2048, 4096, 6144, 8192, 12288, 16384
    653  1.1  junyoung 	};
    654  1.1  junyoung 
    655  1.1  junyoung 	tmp = regr(sc, MEM_CNTL);
    656  1.1  junyoung 	if (sc->has_dsp) {
    657  1.1  junyoung 		tmp &= 0x0000000f;
    658  1.1  junyoung 		if (tmp < 8)
    659  1.1  junyoung 			memsize = (tmp + 1) * 512;
    660  1.1  junyoung 		else if (tmp < 12)
    661  1.1  junyoung 			memsize = (tmp - 3) * 1024;
    662  1.1  junyoung 		else
    663  1.1  junyoung 			memsize = (tmp - 7) * 2048;
    664  1.1  junyoung 	} else {
    665  1.1  junyoung 		memsize = mem_tab[tmp & 0x07];
    666  1.1  junyoung 	}
    667  1.1  junyoung 
    668  1.1  junyoung 	return memsize;
    669  1.1  junyoung }
    670  1.1  junyoung 
    671  1.1  junyoung int
    672  1.1  junyoung mach64_get_max_ramdac(struct mach64_softc *sc)
    673  1.1  junyoung {
    674  1.1  junyoung 	int i;
    675  1.1  junyoung 
    676  1.1  junyoung 	if ((mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||
    677  1.1  junyoung 	     mach64_chip_id == PCI_PRODUCT_ATI_RAGE_II) &&
    678  1.1  junyoung 	     (mach64_chip_rev & 0x07))
    679  1.1  junyoung 		return 170000;
    680  1.1  junyoung 
    681  1.1  junyoung 	for (i = 0; i < sizeof(mach64_info) / sizeof(mach64_info[0]); i++)
    682  1.1  junyoung 		if (mach64_chip_id == mach64_info[i].chip_id)
    683  1.1  junyoung 			return mach64_info[i].ramdac_freq;
    684  1.1  junyoung 
    685  1.1  junyoung 	if (sc->bits_per_pixel == 8)
    686  1.1  junyoung 		return 135000;
    687  1.1  junyoung 	else
    688  1.1  junyoung 		return 80000;
    689  1.1  junyoung }
    690  1.1  junyoung 
    691  1.1  junyoung void
    692  1.1  junyoung mach64_get_mode(struct mach64_softc *sc, struct videomode *mode)
    693  1.1  junyoung {
    694  1.1  junyoung 	struct mach64_crtcregs crtc;
    695  1.1  junyoung 
    696  1.1  junyoung 	crtc.h_total_disp = regr(sc, CRTC_H_TOTAL_DISP);
    697  1.1  junyoung 	crtc.h_sync_strt_wid = regr(sc, CRTC_H_SYNC_STRT_WID);
    698  1.1  junyoung 	crtc.v_total_disp = regr(sc, CRTC_V_TOTAL_DISP);
    699  1.1  junyoung 	crtc.v_sync_strt_wid = regr(sc, CRTC_V_SYNC_STRT_WID);
    700  1.1  junyoung 
    701  1.1  junyoung 	mode->htotal = ((crtc.h_total_disp & 0xffff) + 1) << 3;
    702  1.1  junyoung 	mode->hdisplay = ((crtc.h_total_disp >> 16) + 1) << 3;
    703  1.1  junyoung 	mode->hsync_start = ((crtc.h_sync_strt_wid & 0xffff) + 1) << 3;
    704  1.1  junyoung 	mode->hsync_end = ((crtc.h_sync_strt_wid >> 16) << 3) +
    705  1.1  junyoung 	    mode->hsync_start;
    706  1.1  junyoung 	mode->vtotal = (crtc.v_total_disp & 0xffff) + 1;
    707  1.1  junyoung 	mode->vdisplay = (crtc.v_total_disp >> 16) + 1;
    708  1.1  junyoung 	mode->vsync_start = (crtc.v_sync_strt_wid & 0xffff) + 1;
    709  1.1  junyoung 	mode->vsync_end = (crtc.v_sync_strt_wid >> 16) + mode->vsync_start;
    710  1.1  junyoung 
    711  1.1  junyoung #ifdef MACH64_DEBUG
    712  1.1  junyoung 	printf("mach64_get_mode: %d %d %d %d %d %d %d %d\n",
    713  1.1  junyoung 	    mode->hdisplay, mode->hsync_start, mode->hsync_end, mode->htotal,
    714  1.1  junyoung 	    mode->vdisplay, mode->vsync_start, mode->vsync_end, mode->vtotal);
    715  1.1  junyoung #endif
    716  1.1  junyoung }
    717  1.1  junyoung 
    718  1.1  junyoung int
    719  1.1  junyoung mach64_calc_crtcregs(struct mach64_softc *sc, struct mach64_crtcregs *crtc,
    720  1.1  junyoung     struct videomode *mode)
    721  1.1  junyoung {
    722  1.1  junyoung 
    723  1.1  junyoung 	if (mode->dot_clock > sc->ramdac_freq)
    724  1.1  junyoung 		/* Clock too high. */
    725  1.1  junyoung 		return 1;
    726  1.1  junyoung 
    727  1.1  junyoung 	crtc->h_total_disp = (((mode->hdisplay >> 3) - 1) << 16) |
    728  1.1  junyoung 	    ((mode->htotal >> 3) - 1);
    729  1.1  junyoung 	crtc->h_sync_strt_wid =
    730  1.1  junyoung 	    (((mode->hsync_end - mode->hsync_start) >> 3) << 16) |
    731  1.1  junyoung 	    ((mode->hsync_start >> 3) - 1);
    732  1.1  junyoung 
    733  1.1  junyoung 	crtc->v_total_disp = ((mode->vdisplay - 1) << 16) |
    734  1.1  junyoung 	    (mode->vtotal - 1);
    735  1.1  junyoung 	crtc->v_sync_strt_wid =
    736  1.1  junyoung 	    ((mode->vsync_end - mode->vsync_start) << 16) |
    737  1.1  junyoung 	    (mode->vsync_start - 1);
    738  1.1  junyoung 
    739  1.1  junyoung 	if (mode->flags & VID_NVSYNC)
    740  1.1  junyoung 		crtc->v_sync_strt_wid |= CRTC_VSYNC_NEG;
    741  1.1  junyoung 
    742  1.1  junyoung 	switch (sc->bits_per_pixel) {
    743  1.1  junyoung 	case 8:
    744  1.1  junyoung 		crtc->color_depth = CRTC_PIX_WIDTH_8BPP;
    745  1.1  junyoung 		break;
    746  1.1  junyoung 	case 16:
    747  1.1  junyoung 		crtc->color_depth = CRTC_PIX_WIDTH_16BPP;
    748  1.1  junyoung 		break;
    749  1.1  junyoung 	case 32:
    750  1.1  junyoung 		crtc->color_depth = CRTC_PIX_WIDTH_32BPP;
    751  1.1  junyoung 		break;
    752  1.1  junyoung 	}
    753  1.1  junyoung 
    754  1.1  junyoung 	crtc->gen_cntl = 0;
    755  1.1  junyoung 	if (mode->flags & VID_INTERLACE)
    756  1.1  junyoung 		crtc->gen_cntl |= CRTC_INTERLACE_EN;
    757  1.1  junyoung 	if (mode->flags & VID_CSYNC)
    758  1.1  junyoung 		crtc->gen_cntl |= CRTC_CSYNC_EN;
    759  1.1  junyoung 
    760  1.1  junyoung 	crtc->dot_clock = mode->dot_clock;
    761  1.1  junyoung 
    762  1.1  junyoung 	return 0;
    763  1.1  junyoung }
    764  1.1  junyoung 
    765  1.1  junyoung void
    766  1.1  junyoung mach64_set_crtcregs(struct mach64_softc *sc, struct mach64_crtcregs *crtc)
    767  1.1  junyoung {
    768  1.1  junyoung 
    769  1.1  junyoung 	mach64_set_pll(sc, crtc->dot_clock);
    770  1.1  junyoung 
    771  1.1  junyoung 	if (sc->has_dsp)
    772  1.1  junyoung 		mach64_set_dsp(sc);
    773  1.1  junyoung 
    774  1.1  junyoung 	regw(sc, CRTC_H_TOTAL_DISP, crtc->h_total_disp);
    775  1.1  junyoung 	regw(sc, CRTC_H_SYNC_STRT_WID, crtc->h_sync_strt_wid);
    776  1.1  junyoung 	regw(sc, CRTC_V_TOTAL_DISP, crtc->v_total_disp);
    777  1.1  junyoung 	regw(sc, CRTC_V_SYNC_STRT_WID, crtc->v_sync_strt_wid);
    778  1.1  junyoung 
    779  1.1  junyoung 	regw(sc, CRTC_VLINE_CRNT_VLINE, 0);
    780  1.1  junyoung 
    781  1.1  junyoung 	regw(sc, CRTC_OFF_PITCH, (sc->virt_x >> 3) << 22);
    782  1.1  junyoung 
    783  1.1  junyoung 	regw(sc, CRTC_GEN_CNTL, crtc->gen_cntl | crtc->color_depth |
    784  1.1  junyoung 	    CRTC_EXT_DISP_EN | CRTC_EXT_EN);
    785  1.1  junyoung }
    786  1.1  junyoung 
    787  1.1  junyoung int
    788  1.1  junyoung mach64_modeswitch(struct mach64_softc *sc, struct videomode *mode)
    789  1.1  junyoung {
    790  1.1  junyoung 	struct mach64_crtcregs crtc;
    791  1.1  junyoung 
    792  1.1  junyoung 	if (mach64_calc_crtcregs(sc, &crtc, mode))
    793  1.1  junyoung 		return 1;
    794  1.1  junyoung 
    795  1.1  junyoung 	mach64_set_crtcregs(sc, &crtc);
    796  1.1  junyoung 	return 0;
    797  1.1  junyoung }
    798  1.1  junyoung 
    799  1.1  junyoung void
    800  1.1  junyoung mach64_reset_engine(struct mach64_softc *sc)
    801  1.1  junyoung {
    802  1.1  junyoung 
    803  1.1  junyoung 	/* Reset engine.*/
    804  1.1  junyoung 	regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) & ~GUI_ENGINE_ENABLE);
    805  1.1  junyoung 
    806  1.1  junyoung 	/* Enable engine. */
    807  1.1  junyoung 	regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) | GUI_ENGINE_ENABLE);
    808  1.1  junyoung 
    809  1.1  junyoung 	/* Ensure engine is not locked up by clearing any FIFO or
    810  1.1  junyoung 	   host errors. */
    811  1.1  junyoung 	regw(sc, BUS_CNTL, regr(sc, BUS_CNTL) | BUS_HOST_ERR_ACK |
    812  1.1  junyoung 	    BUS_FIFO_ERR_ACK);
    813  1.1  junyoung }
    814  1.1  junyoung 
    815  1.1  junyoung void
    816  1.1  junyoung mach64_init_engine(struct mach64_softc *sc)
    817  1.1  junyoung {
    818  1.1  junyoung 	u_int32_t pitch_value;
    819  1.1  junyoung 
    820  1.1  junyoung 	pitch_value = sc->virt_x;
    821  1.1  junyoung 
    822  1.1  junyoung 	if (sc->bits_per_pixel == 24)
    823  1.1  junyoung 		pitch_value *= 3;
    824  1.1  junyoung 
    825  1.1  junyoung 	mach64_reset_engine(sc);
    826  1.1  junyoung 
    827  1.1  junyoung 	wait_for_fifo(sc, 14);
    828  1.1  junyoung 
    829  1.1  junyoung 	regw(sc, CONTEXT_MASK, 0xffffffff);
    830  1.1  junyoung 
    831  1.1  junyoung 	regw(sc, DST_OFF_PITCH, (pitch_value / 8) << 22);
    832  1.1  junyoung 
    833  1.1  junyoung 	regw(sc, DST_Y_X, 0);
    834  1.1  junyoung 	regw(sc, DST_HEIGHT, 0);
    835  1.1  junyoung 	regw(sc, DST_BRES_ERR, 0);
    836  1.1  junyoung 	regw(sc, DST_BRES_INC, 0);
    837  1.1  junyoung 	regw(sc, DST_BRES_DEC, 0);
    838  1.1  junyoung 
    839  1.1  junyoung 	regw(sc, DST_CNTL, DST_LAST_PEL | DST_X_LEFT_TO_RIGHT |
    840  1.1  junyoung 	    DST_Y_TOP_TO_BOTTOM);
    841  1.1  junyoung 
    842  1.1  junyoung 	regw(sc, SRC_OFF_PITCH, (pitch_value / 8) << 22);
    843  1.1  junyoung 
    844  1.1  junyoung 	regw(sc, SRC_Y_X, 0);
    845  1.1  junyoung 	regw(sc, SRC_HEIGHT1_WIDTH1, 1);
    846  1.1  junyoung 	regw(sc, SRC_Y_X_START, 0);
    847  1.1  junyoung 	regw(sc, SRC_HEIGHT2_WIDTH2, 1);
    848  1.1  junyoung 
    849  1.1  junyoung 	regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
    850  1.1  junyoung 
    851  1.1  junyoung 	wait_for_fifo(sc, 13);
    852  1.1  junyoung 	regw(sc, HOST_CNTL, 0);
    853  1.1  junyoung 
    854  1.1  junyoung 	regw(sc, PAT_REG0, 0);
    855  1.1  junyoung 	regw(sc, PAT_REG1, 0);
    856  1.1  junyoung 	regw(sc, PAT_CNTL, 0);
    857  1.1  junyoung 
    858  1.1  junyoung 	regw(sc, SC_LEFT, 0);
    859  1.1  junyoung 	regw(sc, SC_TOP, 0);
    860  1.1  junyoung 	regw(sc, SC_BOTTOM, default_mode.vdisplay - 1);
    861  1.1  junyoung 	regw(sc, SC_RIGHT, pitch_value - 1);
    862  1.1  junyoung 
    863  1.1  junyoung 	regw(sc, DP_BKGD_CLR, 0);
    864  1.1  junyoung 	regw(sc, DP_FRGD_CLR, 0xffffffff);
    865  1.1  junyoung 	regw(sc, DP_WRITE_MASK, 0xffffffff);
    866  1.1  junyoung 	regw(sc, DP_MIX, (MIX_SRC << 16) | MIX_DST);
    867  1.1  junyoung 
    868  1.1  junyoung 	regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR);
    869  1.1  junyoung 
    870  1.1  junyoung 	wait_for_fifo(sc, 3);
    871  1.1  junyoung 	regw(sc, CLR_CMP_CLR, 0);
    872  1.1  junyoung 	regw(sc, CLR_CMP_MASK, 0xffffffff);
    873  1.1  junyoung 	regw(sc, CLR_CMP_CNTL, 0);
    874  1.1  junyoung 
    875  1.1  junyoung 	wait_for_fifo(sc, 2);
    876  1.1  junyoung 	switch (sc->bits_per_pixel) {
    877  1.1  junyoung 	case 8:
    878  1.1  junyoung 		regw(sc, DP_PIX_WIDTH, HOST_8BPP | SRC_8BPP | DST_8BPP);
    879  1.1  junyoung 		regw(sc, DP_CHAIN_MASK, DP_CHAIN_8BPP);
    880  1.1  junyoung 		regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) & ~DAC_8BIT_EN);
    881  1.1  junyoung 		break;
    882  1.1  junyoung #if 0
    883  1.1  junyoung 	case 32:
    884  1.1  junyoung 		regw(sc, DP_PIX_WIDTH, HOST_32BPP | SRC_32BPP | DST_32BPP);
    885  1.1  junyoung 		regw(sc, DP_CHAIN_MASK, DP_CHAIN_32BPP);
    886  1.1  junyoung 		regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
    887  1.1  junyoung 		break;
    888  1.1  junyoung #endif
    889  1.1  junyoung 	}
    890  1.1  junyoung 
    891  1.1  junyoung 	wait_for_fifo(sc, 5);
    892  1.1  junyoung 	regw(sc, CRTC_INT_CNTL, regr(sc, CRTC_INT_CNTL) & ~0x20);
    893  1.1  junyoung 	regw(sc, GUI_TRAJ_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
    894  1.1  junyoung 
    895  1.1  junyoung 	wait_for_idle(sc);
    896  1.1  junyoung }
    897  1.1  junyoung 
    898  1.1  junyoung void
    899  1.1  junyoung mach64_adjust_frame(struct mach64_softc *sc, int x, int y)
    900  1.1  junyoung {
    901  1.1  junyoung 	int offset;
    902  1.1  junyoung 
    903  1.1  junyoung 	offset = ((x + y * sc->virt_x) * (sc->bits_per_pixel >> 3)) >> 3;
    904  1.1  junyoung 
    905  1.1  junyoung 	regw(sc, CRTC_OFF_PITCH, (regr(sc, CRTC_OFF_PITCH) & 0xfff00000) |
    906  1.1  junyoung 	     offset);
    907  1.1  junyoung }
    908  1.1  junyoung 
    909  1.1  junyoung void
    910  1.1  junyoung mach64_set_dsp(struct mach64_softc *sc)
    911  1.1  junyoung {
    912  1.1  junyoung 	u_int32_t fifo_depth, page_size, dsp_precision, dsp_loop_latency;
    913  1.1  junyoung 	u_int32_t dsp_off, dsp_on, dsp_xclks_per_qw;
    914  1.1  junyoung 	u_int32_t xclks_per_qw, y;
    915  1.1  junyoung 	u_int32_t fifo_off, fifo_on;
    916  1.1  junyoung 
    917  1.1  junyoung 	if (mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||
    918  1.1  junyoung 	    mach64_chip_id == PCI_PRODUCT_ATI_RAGE_II ||
    919  1.1  junyoung 	    mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIP ||
    920  1.1  junyoung 	    mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIC_PCI ||
    921  1.1  junyoung 	    mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIC_AGP_B ||
    922  1.1  junyoung 	    mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIC_AGP_P) {
    923  1.1  junyoung 		dsp_loop_latency = 0;
    924  1.1  junyoung 		fifo_depth = 24;
    925  1.1  junyoung 	} else {
    926  1.1  junyoung 		dsp_loop_latency = 2;
    927  1.1  junyoung 		fifo_depth = 32;
    928  1.1  junyoung 	}
    929  1.1  junyoung 
    930  1.1  junyoung 	dsp_precision = 0;
    931  1.1  junyoung 	xclks_per_qw = (sc->mclk_fb_div * sc->vclk_post_div * 64 << 11) /
    932  1.1  junyoung 	    (sc->vclk_fb_div * sc->mclk_post_div * sc->bits_per_pixel);
    933  1.1  junyoung 	y = (xclks_per_qw * fifo_depth) >> 11;
    934  1.1  junyoung 	while (y) {
    935  1.1  junyoung 		y >>= 1;
    936  1.1  junyoung 		dsp_precision++;
    937  1.1  junyoung 	}
    938  1.1  junyoung 	dsp_precision -= 5;
    939  1.1  junyoung 	fifo_off = ((xclks_per_qw * (fifo_depth - 1)) >> 5) + (3 << 6);
    940  1.1  junyoung 
    941  1.1  junyoung 	switch (sc->memtype) {
    942  1.1  junyoung 	case DRAM:
    943  1.1  junyoung 	case EDO_DRAM:
    944  1.1  junyoung 	case PSEUDO_EDO:
    945  1.1  junyoung 		if (sc->memsize > 1024) {
    946  1.1  junyoung 			page_size = 9;
    947  1.1  junyoung 			dsp_loop_latency += 6;
    948  1.1  junyoung 		} else {
    949  1.1  junyoung 			page_size = 10;
    950  1.1  junyoung 			if (sc->memtype == DRAM)
    951  1.1  junyoung 				dsp_loop_latency += 8;
    952  1.1  junyoung 			else
    953  1.1  junyoung 				dsp_loop_latency += 7;
    954  1.1  junyoung 		}
    955  1.1  junyoung 		break;
    956  1.1  junyoung 	case SDRAM:
    957  1.1  junyoung 	case SGRAM:
    958  1.1  junyoung 		if (sc->memsize > 1024) {
    959  1.1  junyoung 			page_size = 8;
    960  1.1  junyoung 			dsp_loop_latency += 8;
    961  1.1  junyoung 		} else {
    962  1.1  junyoung 			page_size = 10;
    963  1.1  junyoung 			dsp_loop_latency += 9;
    964  1.1  junyoung 		}
    965  1.1  junyoung 		break;
    966  1.1  junyoung 	default:
    967  1.1  junyoung 		page_size = 10;
    968  1.1  junyoung 		dsp_loop_latency += 9;
    969  1.1  junyoung 		break;
    970  1.1  junyoung 	}
    971  1.1  junyoung 
    972  1.1  junyoung 	if (xclks_per_qw >= (page_size << 11))
    973  1.1  junyoung 		fifo_on = ((2 * page_size + 1) << 6) + (xclks_per_qw >> 5);
    974  1.1  junyoung 	else
    975  1.1  junyoung 		fifo_on = (3 * page_size + 2) << 6;
    976  1.1  junyoung 
    977  1.1  junyoung 	dsp_xclks_per_qw = xclks_per_qw >> dsp_precision;
    978  1.1  junyoung 	dsp_on = fifo_on >> dsp_precision;
    979  1.1  junyoung 	dsp_off = fifo_off >> dsp_precision;
    980  1.1  junyoung 
    981  1.1  junyoung #ifdef MACH64_DEBUG
    982  1.1  junyoung 	printf("dsp_xclks_per_qw = %d, dsp_on = %d, dsp_off = %d,\n"
    983  1.1  junyoung 	    "dsp_precision = %d, dsp_loop_latency = %d,\n"
    984  1.1  junyoung 	    "mclk_fb_div = %d, vclk_fb_div = %d,\n"
    985  1.1  junyoung 	    "mclk_post_div = %d, vclk_post_div = %d\n",
    986  1.1  junyoung 	    dsp_xclks_per_qw, dsp_on, dsp_off, dsp_precision, dsp_loop_latency,
    987  1.1  junyoung 	    sc->mclk_fb_div, sc->vclk_fb_div,
    988  1.1  junyoung 	    sc->mclk_post_div, sc->vclk_post_div);
    989  1.1  junyoung #endif
    990  1.1  junyoung 
    991  1.1  junyoung 	regw(sc, DSP_ON_OFF, ((dsp_on << 16) & DSP_ON) | (dsp_off & DSP_OFF));
    992  1.1  junyoung 	regw(sc, DSP_CONFIG, ((dsp_precision << 20) & DSP_PRECISION) |
    993  1.1  junyoung 	    ((dsp_loop_latency << 16) & DSP_LOOP_LATENCY) |
    994  1.1  junyoung 	    (dsp_xclks_per_qw & DSP_XCLKS_PER_QW));
    995  1.1  junyoung }
    996  1.1  junyoung 
    997  1.1  junyoung void
    998  1.1  junyoung mach64_set_pll(struct mach64_softc *sc, int clock)
    999  1.1  junyoung {
   1000  1.1  junyoung 	int q;
   1001  1.1  junyoung 
   1002  1.1  junyoung 	q = (clock * sc->ref_div * 100) / (2 * sc->ref_freq);
   1003  1.1  junyoung #ifdef MACH64_DEBUG
   1004  1.1  junyoung 	printf("q = %d\n", q);
   1005  1.1  junyoung #endif
   1006  1.1  junyoung 	if (q > 25500) {
   1007  1.1  junyoung 		printf("Warning: q > 25500\n");
   1008  1.1  junyoung 		q = 25500;
   1009  1.1  junyoung 		sc->vclk_post_div = 1;
   1010  1.1  junyoung 		sc->log2_vclk_post_div = 0;
   1011  1.1  junyoung 	} else if (q > 12750) {
   1012  1.1  junyoung 		sc->vclk_post_div = 1;
   1013  1.1  junyoung 		sc->log2_vclk_post_div = 0;
   1014  1.1  junyoung 	} else if (q > 6350) {
   1015  1.1  junyoung 		sc->vclk_post_div = 2;
   1016  1.1  junyoung 		sc->log2_vclk_post_div = 1;
   1017  1.1  junyoung 	} else if (q > 3150) {
   1018  1.1  junyoung 		sc->vclk_post_div = 4;
   1019  1.1  junyoung 		sc->log2_vclk_post_div = 2;
   1020  1.1  junyoung 	} else if (q >= 1600) {
   1021  1.1  junyoung 		sc->vclk_post_div = 8;
   1022  1.1  junyoung 		sc->log2_vclk_post_div = 3;
   1023  1.1  junyoung 	} else {
   1024  1.1  junyoung 		printf("Warning: q < 1600\n");
   1025  1.1  junyoung 		sc->vclk_post_div = 8;
   1026  1.1  junyoung 		sc->log2_vclk_post_div = 3;
   1027  1.1  junyoung 	}
   1028  1.1  junyoung 	sc->vclk_fb_div = q * sc->vclk_post_div / 100;
   1029  1.1  junyoung 
   1030  1.1  junyoung 	regwb_pll(sc, MCLK_FB_DIV, sc->mclk_fb_div);
   1031  1.1  junyoung 	regwb_pll(sc, VCLK_POST_DIV, sc->log2_vclk_post_div);
   1032  1.1  junyoung 	regwb_pll(sc, VCLK0_FB_DIV, sc->vclk_fb_div);
   1033  1.1  junyoung }
   1034  1.1  junyoung 
   1035  1.1  junyoung void
   1036  1.1  junyoung mach64_init_lut(struct mach64_softc *sc)
   1037  1.1  junyoung {
   1038  1.1  junyoung 	int i;
   1039  1.1  junyoung 
   1040  1.1  junyoung 	regwb(sc, DAC_REGS, 0);
   1041  1.1  junyoung 
   1042  1.1  junyoung 	for (i = 0; i < 16; i++) {
   1043  1.1  junyoung 		regwb(sc, DAC_REGS + 1, mach64_cmap[i * 3]);
   1044  1.1  junyoung 		regwb(sc, DAC_REGS + 1, mach64_cmap[i * 3 + 1]);
   1045  1.1  junyoung 		regwb(sc, DAC_REGS + 1, mach64_cmap[i + 3 + 2]);
   1046  1.1  junyoung 	}
   1047  1.1  junyoung }
   1048  1.1  junyoung 
   1049  1.1  junyoung void
   1050  1.1  junyoung mach64_switch_screen(struct mach64_softc *sc)
   1051  1.1  junyoung {
   1052  1.1  junyoung 	struct mach64screen *scr, *oldscr;
   1053  1.1  junyoung 	const struct wsscreen_descr *type;
   1054  1.1  junyoung 
   1055  1.1  junyoung 	scr = sc->wanted;
   1056  1.1  junyoung 	if (!scr) {
   1057  1.1  junyoung 		printf("mach64_switch_screen: disappeared\n");
   1058  1.1  junyoung 		(*sc->switchcb)(sc->switchcbarg, EIO, 0);
   1059  1.1  junyoung 		return;
   1060  1.1  junyoung 	}
   1061  1.1  junyoung 	type = scr->type;
   1062  1.1  junyoung 	oldscr = sc->active; /* can be NULL! */
   1063  1.1  junyoung #ifdef DIAGNOSTIC
   1064  1.1  junyoung 	if (oldscr) {
   1065  1.1  junyoung 		if (!oldscr->active)
   1066  1.1  junyoung 			panic("mach64_switch_screen: not active");
   1067  1.1  junyoung 		if (oldscr->type != vc->currenttype)
   1068  1.1  junyoung 			panic("mach64_switch_screen: bad type");
   1069  1.1  junyoung 	}
   1070  1.1  junyoung #endif
   1071  1.1  junyoung 	if (scr == oldscr)
   1072  1.1  junyoung 		return;
   1073  1.1  junyoung 
   1074  1.1  junyoung #ifdef DIAGNOSTIC
   1075  1.1  junyoung 	if (scr->active)
   1076  1.1  junyoung 		panic("mach64_switch_screen: active");
   1077  1.1  junyoung #endif
   1078  1.1  junyoung 
   1079  1.1  junyoung 	if (oldscr)
   1080  1.1  junyoung 		oldscr->active = 0;
   1081  1.1  junyoung 
   1082  1.1  junyoung 	if (sc->currenttype != type) {
   1083  1.1  junyoung 		mach64_set_screentype(sc, type);
   1084  1.1  junyoung 		sc->currenttype = type;
   1085  1.1  junyoung 	}
   1086  1.1  junyoung 
   1087  1.1  junyoung 	scr->dispoffset = scr->mindispoffset;
   1088  1.1  junyoung 
   1089  1.1  junyoung 	if (!oldscr || (scr->dispoffset != oldscr->dispoffset)) {
   1090  1.1  junyoung 
   1091  1.1  junyoung 	}
   1092  1.1  junyoung 
   1093  1.1  junyoung 	/* Clear the entire screen. */
   1094  1.1  junyoung 
   1095  1.1  junyoung 	scr->active = 1;
   1096  1.1  junyoung 	mach64_restore_screen(scr, type, scr->mem);
   1097  1.1  junyoung 
   1098  1.1  junyoung 	sc->active = scr;
   1099  1.1  junyoung 
   1100  1.1  junyoung 	mach64_cursor(scr, scr->cursoron, scr->cursorrow, scr->cursorcol);
   1101  1.1  junyoung 
   1102  1.1  junyoung 	sc->wanted = 0;
   1103  1.1  junyoung 	if (sc->switchcb)
   1104  1.1  junyoung 		(*sc->switchcb)(sc->switchcbarg, 0, 0);
   1105  1.1  junyoung }
   1106  1.1  junyoung 
   1107  1.1  junyoung void
   1108  1.1  junyoung mach64_restore_screen(struct mach64screen *scr,
   1109  1.1  junyoung     const struct wsscreen_descr *type, u_int16_t *mem)
   1110  1.1  junyoung {
   1111  1.1  junyoung 
   1112  1.1  junyoung }
   1113  1.1  junyoung 
   1114  1.1  junyoung void
   1115  1.1  junyoung mach64_set_screentype(struct mach64_softc *sc, const struct wsscreen_descr *des)
   1116  1.1  junyoung {
   1117  1.1  junyoung 
   1118  1.1  junyoung }
   1119  1.1  junyoung 
   1120  1.1  junyoung /*
   1121  1.1  junyoung  * wsdisplay_emulops
   1122  1.1  junyoung  */
   1123  1.1  junyoung 
   1124  1.1  junyoung void
   1125  1.1  junyoung mach64_cursor(void *cookie, int on, int row, int col)
   1126  1.1  junyoung {
   1127  1.1  junyoung 
   1128  1.1  junyoung }
   1129  1.1  junyoung 
   1130  1.1  junyoung int
   1131  1.1  junyoung mach64_mapchar(void *cookie, int uni, u_int *index)
   1132  1.1  junyoung {
   1133  1.1  junyoung 
   1134  1.1  junyoung 	return 0;
   1135  1.1  junyoung }
   1136  1.1  junyoung 
   1137  1.1  junyoung void
   1138  1.1  junyoung mach64_putchar(void *cookie, int row, int col, u_int c, long attr)
   1139  1.1  junyoung {
   1140  1.1  junyoung 
   1141  1.1  junyoung }
   1142  1.1  junyoung 
   1143  1.1  junyoung void
   1144  1.1  junyoung mach64_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
   1145  1.1  junyoung {
   1146  1.1  junyoung 
   1147  1.1  junyoung }
   1148  1.1  junyoung 
   1149  1.1  junyoung void
   1150  1.1  junyoung mach64_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
   1151  1.1  junyoung {
   1152  1.1  junyoung 
   1153  1.1  junyoung }
   1154  1.1  junyoung 
   1155  1.1  junyoung void
   1156  1.1  junyoung mach64_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
   1157  1.1  junyoung {
   1158  1.1  junyoung 
   1159  1.1  junyoung }
   1160  1.1  junyoung 
   1161  1.1  junyoung void
   1162  1.1  junyoung mach64_eraserows(void *cookie, int row, int nrows, long fillattr)
   1163  1.1  junyoung {
   1164  1.1  junyoung 
   1165  1.1  junyoung }
   1166  1.1  junyoung 
   1167  1.1  junyoung int
   1168  1.1  junyoung mach64_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
   1169  1.1  junyoung {
   1170  1.1  junyoung 
   1171  1.1  junyoung 	return 0;
   1172  1.1  junyoung }
   1173  1.1  junyoung 
   1174  1.1  junyoung /*
   1175  1.1  junyoung  * wsdisplay_accessops
   1176  1.1  junyoung  */
   1177  1.1  junyoung 
   1178  1.1  junyoung int
   1179  1.1  junyoung mach64_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
   1180  1.1  junyoung {
   1181  1.1  junyoung 
   1182  1.1  junyoung 	return ENOTTY;
   1183  1.1  junyoung }
   1184  1.1  junyoung 
   1185  1.1  junyoung paddr_t
   1186  1.1  junyoung mach64_mmap(void *v, off_t offset, int prot)
   1187  1.1  junyoung {
   1188  1.1  junyoung 
   1189  1.1  junyoung 	return -1;
   1190  1.1  junyoung }
   1191  1.1  junyoung 
   1192  1.1  junyoung int
   1193  1.1  junyoung mach64_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
   1194  1.1  junyoung     int *curxp, int *curyp, long *defattrp)
   1195  1.1  junyoung {
   1196  1.1  junyoung 	struct mach64_softc *sc = v;
   1197  1.1  junyoung 	struct mach64screen *scr;
   1198  1.1  junyoung 
   1199  1.1  junyoung 	if (sc->nscreens == 1)
   1200  1.1  junyoung 		sc->screens.lh_first->mem = scr->mem;
   1201  1.1  junyoung 
   1202  1.1  junyoung 	scr = malloc(sizeof(struct mach64screen), M_DEVBUF, M_WAITOK);
   1203  1.1  junyoung 	mach64_init_screen(sc, scr, type, 0, defattrp);
   1204  1.1  junyoung 
   1205  1.1  junyoung 	if (sc->nscreens == 1) {
   1206  1.1  junyoung 		scr->active = 1;
   1207  1.1  junyoung 		sc->active = scr;
   1208  1.1  junyoung 		sc->currenttype = type;
   1209  1.1  junyoung 	} else {
   1210  1.1  junyoung 		scr->mem = malloc(type->ncols * type->nrows * 2, M_DEVBUF,
   1211  1.1  junyoung 		     M_WAITOK);
   1212  1.1  junyoung 		mach64_eraserows(sc, 0, type->nrows, *defattrp);
   1213  1.1  junyoung 	}
   1214  1.1  junyoung 
   1215  1.1  junyoung 	*cookiep = scr;
   1216  1.1  junyoung 	*curxp = scr->cursorcol;
   1217  1.1  junyoung 	*curyp = scr->cursorrow;
   1218  1.1  junyoung 
   1219  1.1  junyoung 	return 0;
   1220  1.1  junyoung }
   1221  1.1  junyoung 
   1222  1.1  junyoung void
   1223  1.1  junyoung mach64_free_screen(void *v, void *cookie)
   1224  1.1  junyoung {
   1225  1.1  junyoung 	struct mach64_softc *sc = v;
   1226  1.1  junyoung 	struct mach64screen *scr = cookie;
   1227  1.1  junyoung 
   1228  1.1  junyoung 	LIST_REMOVE(scr, next);
   1229  1.1  junyoung 	if (scr != &mach64_console_screen)
   1230  1.1  junyoung 		free(scr, M_DEVBUF);
   1231  1.1  junyoung 	else
   1232  1.1  junyoung 		panic("mach64_free_screen: console");
   1233  1.1  junyoung 
   1234  1.1  junyoung 	if (sc->active == scr)
   1235  1.1  junyoung 		sc->active = 0;
   1236  1.1  junyoung }
   1237  1.1  junyoung 
   1238  1.1  junyoung int
   1239  1.1  junyoung mach64_show_screen(void *v, void *cookie, int waitok,
   1240  1.1  junyoung     void (*cb)(void *, int, int), void *cbarg)
   1241  1.1  junyoung {
   1242  1.1  junyoung 	struct mach64_softc *sc = v;
   1243  1.1  junyoung 	struct mach64screen *scr, *oldscr;
   1244  1.1  junyoung 
   1245  1.1  junyoung 	scr = cookie;
   1246  1.1  junyoung 	oldscr = sc->active;
   1247  1.1  junyoung 	if (scr == oldscr)
   1248  1.1  junyoung 		return 0;
   1249  1.1  junyoung 
   1250  1.1  junyoung 	sc->wanted = scr;
   1251  1.1  junyoung 	sc->switchcb = cb;
   1252  1.1  junyoung 	sc->switchcbarg = cbarg;
   1253  1.1  junyoung 	if (cb) {
   1254  1.1  junyoung 		callout_reset(&sc->switch_callout, 0,
   1255  1.1  junyoung 		    (void(*)(void *))mach64_switch_screen, sc);
   1256  1.1  junyoung 		return EAGAIN;
   1257  1.1  junyoung 	}
   1258  1.1  junyoung 
   1259  1.1  junyoung 	mach64_switch_screen(sc);
   1260  1.1  junyoung 
   1261  1.1  junyoung 	return 0;
   1262  1.1  junyoung }
   1263  1.1  junyoung 
   1264  1.1  junyoung int
   1265  1.1  junyoung mach64_load_font(void *v, void *cookie, struct wsdisplay_font *data)
   1266  1.1  junyoung {
   1267  1.1  junyoung 
   1268  1.1  junyoung 	return 0;
   1269  1.1  junyoung }
   1270