Home | History | Annotate | Line # | Download | only in pci
machfb.c revision 1.38.10.2
      1  1.38.10.2      elad /*	$NetBSD: machfb.c,v 1.38.10.2 2006/05/11 23:28:48 elad 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.10  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.25  macallan __KERNEL_RCSID(0,
     36  1.38.10.2      elad 	"$NetBSD: machfb.c,v 1.38.10.2 2006/05/11 23:28:48 elad Exp $");
     37        1.1  junyoung 
     38        1.1  junyoung #include <sys/param.h>
     39        1.1  junyoung #include <sys/systm.h>
     40        1.1  junyoung #include <sys/kernel.h>
     41        1.1  junyoung #include <sys/device.h>
     42        1.1  junyoung #include <sys/malloc.h>
     43        1.1  junyoung #include <sys/callout.h>
     44        1.1  junyoung 
     45        1.3    martin #ifdef __sparc__
     46       1.16    martin #include <machine/promlib.h>
     47        1.3    martin #endif
     48        1.3    martin 
     49       1.20    martin #ifdef __powerpc__
     50       1.20    martin #include <dev/ofw/openfirm.h>
     51       1.20    martin #include <dev/ofw/ofw_pci.h>
     52       1.20    martin #endif
     53       1.20    martin 
     54  1.38.10.1      elad #include <dev/videomode/videomode.h>
     55        1.1  junyoung 
     56        1.1  junyoung #include <dev/pci/pcivar.h>
     57        1.1  junyoung #include <dev/pci/pcireg.h>
     58        1.1  junyoung #include <dev/pci/pcidevs.h>
     59        1.1  junyoung #include <dev/pci/pciio.h>
     60        1.1  junyoung #include <dev/pci/machfbreg.h>
     61        1.1  junyoung 
     62  1.38.10.1      elad #ifdef __sparc__
     63  1.38.10.1      elad #include <dev/sun/fbio.h>
     64  1.38.10.1      elad #include <dev/sun/fbvar.h>
     65  1.38.10.1      elad #include <sys/conf.h>
     66  1.38.10.1      elad #else
     67        1.1  junyoung #include <dev/wscons/wsdisplayvar.h>
     68  1.38.10.1      elad #endif
     69  1.38.10.1      elad 
     70        1.1  junyoung #include <dev/wscons/wsconsio.h>
     71        1.1  junyoung #include <dev/wsfont/wsfont.h>
     72        1.1  junyoung #include <dev/rasops/rasops.h>
     73        1.1  junyoung 
     74  1.38.10.1      elad #include <dev/wscons/wsdisplay_vconsvar.h>
     75  1.38.10.1      elad 
     76        1.1  junyoung #define MACH64_REG_SIZE		1024
     77        1.3    martin #define MACH64_REG_OFF		0x7ffc00
     78        1.1  junyoung 
     79        1.1  junyoung #define	NBARS		3	/* number of Mach64 PCI BARs */
     80        1.1  junyoung 
     81        1.1  junyoung struct vga_bar {
     82        1.1  junyoung 	bus_addr_t vb_base;
     83       1.20    martin 	pcireg_t vb_busaddr;
     84        1.1  junyoung 	bus_size_t vb_size;
     85        1.1  junyoung 	pcireg_t vb_type;
     86        1.1  junyoung 	int vb_flags;
     87        1.1  junyoung };
     88        1.1  junyoung 
     89        1.1  junyoung struct mach64_softc {
     90        1.1  junyoung 	struct device sc_dev;
     91  1.38.10.1      elad #ifdef __sparc__
     92  1.38.10.1      elad 	struct fbdevice sc_fb;
     93  1.38.10.1      elad #endif
     94        1.1  junyoung 	pci_chipset_tag_t sc_pc;
     95        1.1  junyoung 	pcitag_t sc_pcitag;
     96        1.1  junyoung 
     97        1.1  junyoung 	struct vga_bar sc_bars[NBARS];
     98        1.1  junyoung 	struct vga_bar sc_rom;
     99        1.1  junyoung 
    100        1.1  junyoung #define sc_aperbase 	sc_bars[0].vb_base
    101        1.1  junyoung #define sc_apersize	sc_bars[0].vb_size
    102       1.20    martin #define sc_aperphys 	sc_bars[0].vb_busaddr
    103        1.1  junyoung 
    104        1.1  junyoung #define sc_iobase	sc_bars[1].vb_base
    105        1.1  junyoung #define sc_iosize	sc_bars[1].vb_size
    106        1.1  junyoung 
    107        1.1  junyoung #define sc_regbase	sc_bars[2].vb_base
    108        1.1  junyoung #define sc_regsize	sc_bars[2].vb_size
    109       1.20    martin #define sc_regphys	sc_bars[2].vb_busaddr
    110        1.1  junyoung 
    111        1.4  junyoung 	bus_space_tag_t sc_regt;
    112        1.3    martin 	bus_space_tag_t sc_memt;
    113        1.4  junyoung 	bus_space_handle_t sc_regh;
    114        1.1  junyoung 	bus_space_handle_t sc_memh;
    115  1.38.10.2      elad 	caddr_t sc_aperture;		/* mapped aperture vaddr */
    116  1.38.10.2      elad 	caddr_t sc_registers;		/* mapped registers vaddr */
    117  1.38.10.2      elad 
    118  1.38.10.1      elad 	uint32_t sc_nbus, sc_ndev, sc_nfunc;
    119        1.1  junyoung 	size_t memsize;
    120        1.1  junyoung 	int memtype;
    121       1.24  macallan 
    122       1.21    martin 	int sc_mode;
    123       1.21    martin 	int sc_bg;
    124  1.38.10.1      elad 	int sc_locked;
    125        1.1  junyoung 
    126        1.1  junyoung 	int has_dsp;
    127        1.1  junyoung 	int bits_per_pixel;
    128       1.25  macallan 	int max_x;
    129       1.25  macallan 	int max_y;
    130       1.25  macallan 	int virt_x;
    131       1.25  macallan 	int virt_y;
    132        1.1  junyoung 	int color_depth;
    133        1.1  junyoung 
    134        1.1  junyoung 	int mem_freq;
    135        1.1  junyoung 	int ramdac_freq;
    136        1.1  junyoung 	int ref_freq;
    137        1.1  junyoung 
    138        1.1  junyoung 	int ref_div;
    139        1.1  junyoung 	int log2_vclk_post_div;
    140        1.1  junyoung 	int vclk_post_div;
    141        1.1  junyoung 	int vclk_fb_div;
    142        1.1  junyoung 	int mclk_post_div;
    143        1.1  junyoung 	int mclk_fb_div;
    144        1.1  junyoung 
    145       1.33  macallan 	struct videomode *sc_my_mode;
    146       1.19    martin 	u_char sc_cmap_red[256];
    147       1.19    martin 	u_char sc_cmap_green[256];
    148       1.22     perry 	u_char sc_cmap_blue[256];
    149  1.38.10.1      elad 	int sc_dacw, sc_blanked, sc_console;
    150  1.38.10.1      elad 	struct vcons_data vd;
    151        1.1  junyoung };
    152        1.1  junyoung 
    153        1.1  junyoung struct mach64_crtcregs {
    154  1.38.10.1      elad 	uint32_t h_total_disp;
    155  1.38.10.1      elad 	uint32_t h_sync_strt_wid;
    156  1.38.10.1      elad 	uint32_t v_total_disp;
    157  1.38.10.1      elad 	uint32_t v_sync_strt_wid;
    158  1.38.10.1      elad 	uint32_t gen_cntl;
    159  1.38.10.1      elad 	uint32_t clock_cntl;
    160  1.38.10.1      elad 	uint32_t color_depth;
    161  1.38.10.1      elad 	uint32_t dot_clock;
    162        1.1  junyoung };
    163        1.1  junyoung 
    164        1.1  junyoung struct {
    165  1.38.10.1      elad 	uint16_t chip_id;
    166  1.38.10.1      elad 	uint32_t ramdac_freq;
    167       1.30   thorpej } static const mach64_info[] = {
    168        1.1  junyoung 	{ PCI_PRODUCT_ATI_MACH64_CT, 135000 },
    169        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_PRO_AGP, 230000 },
    170        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_PRO_AGP1X, 230000 },
    171        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_PRO_PCI_B, 230000 },
    172        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_XL_AGP, 230000 },
    173        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_PRO_PCI_P, 230000 },
    174        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_PRO_PCI_L, 230000 },
    175        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_XL_PCI, 230000 },
    176        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_II, 135000 },
    177        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_IIP, 200000 },
    178        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_IIC_PCI, 230000 },
    179        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_IIC_AGP_B, 230000 },
    180        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_IIC_AGP_P, 230000 },
    181        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_LT_PRO_AGP, 230000 },
    182        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_MOB_M3_PCI, 230000 },
    183        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_MOB_M3_AGP, 230000 },
    184        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_LT, 230000 },
    185        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_LT_PRO_PCI, 230000 },
    186        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_MOBILITY, 230000 },
    187        1.1  junyoung 	{ PCI_PRODUCT_ATI_RAGE_LT_PRO, 230000 },
    188        1.1  junyoung 	{ PCI_PRODUCT_ATI_MACH64_VT, 170000 },
    189        1.1  junyoung 	{ PCI_PRODUCT_ATI_MACH64_VTB, 200000 },
    190        1.1  junyoung 	{ PCI_PRODUCT_ATI_MACH64_VT4, 230000 }
    191        1.1  junyoung };
    192        1.1  junyoung 
    193        1.1  junyoung static int mach64_chip_id, mach64_chip_rev;
    194       1.33  macallan static struct videomode default_mode = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    195        1.1  junyoung 
    196       1.27  christos static const char *mach64_memtype_names[] = {
    197        1.1  junyoung 	"(N/A)", "DRAM", "EDO DRAM", "EDO DRAM", "SDRAM", "SGRAM", "WRAM",
    198        1.1  junyoung 	"(unknown type)"
    199        1.1  junyoung };
    200        1.1  junyoung 
    201       1.30   thorpej static struct videomode mach64_modes[] = {
    202        1.1  junyoung 	/* 640x400 @ 70 Hz, 31.5 kHz */
    203        1.1  junyoung 	{ 25175, 640, 664, 760, 800, 400, 409, 411, 450, 0 },
    204        1.1  junyoung 	/* 640x480 @ 72 Hz, 36.5 kHz */
    205        1.1  junyoung 	{ 25175, 640, 664, 760, 800, 480, 491, 493, 525, 0 },
    206        1.1  junyoung 	/* 800x600 @ 72 Hz, 48.0 kHz */
    207        1.1  junyoung 	{ 50000, 800, 856, 976, 1040, 600, 637, 643, 666,
    208        1.1  junyoung 	  VID_PHSYNC | VID_PVSYNC },
    209        1.1  junyoung 	/* 1024x768 @ 70 Hz, 56.5 kHz */
    210        1.1  junyoung 	{ 75000, 1024, 1048, 1184, 1328, 768, 771, 777, 806,
    211        1.1  junyoung 	  VID_NHSYNC | VID_NVSYNC },
    212        1.1  junyoung 	/* 1152x864 @ 70 Hz, 62.4 kHz */
    213        1.1  junyoung 	{ 92000, 1152, 1208, 1368, 1474, 864, 865, 875, 895, 0 },
    214        1.1  junyoung 	/* 1280x1024 @ 70 Hz, 74.59 kHz */
    215        1.1  junyoung 	{ 126500, 1280, 1312, 1472, 1696, 1024, 1032, 1040, 1068,
    216        1.1  junyoung 	  VID_NHSYNC | VID_NVSYNC }
    217        1.1  junyoung };
    218        1.1  junyoung 
    219       1.19    martin extern const u_char rasops_cmap[768];
    220        1.1  junyoung 
    221       1.30   thorpej static int	mach64_match(struct device *, struct cfdata *, void *);
    222       1.30   thorpej static void	mach64_attach(struct device *, struct device *, void *);
    223        1.1  junyoung 
    224        1.1  junyoung CFATTACH_DECL(machfb, sizeof(struct mach64_softc), mach64_match, mach64_attach,
    225        1.1  junyoung     NULL, NULL);
    226        1.1  junyoung 
    227       1.30   thorpej static void	mach64_init(struct mach64_softc *);
    228       1.30   thorpej static int	mach64_get_memsize(struct mach64_softc *);
    229       1.30   thorpej static int	mach64_get_max_ramdac(struct mach64_softc *);
    230       1.35  macallan 
    231  1.38.10.1      elad #if defined(__sparc__) || defined(__powerpc__)
    232       1.30   thorpej static void	mach64_get_mode(struct mach64_softc *, struct videomode *);
    233       1.35  macallan #endif
    234       1.35  macallan 
    235       1.30   thorpej static int	mach64_calc_crtcregs(struct mach64_softc *,
    236       1.30   thorpej 				     struct mach64_crtcregs *,
    237       1.30   thorpej 				     struct videomode *);
    238       1.30   thorpej static void	mach64_set_crtcregs(struct mach64_softc *,
    239       1.30   thorpej 				    struct mach64_crtcregs *);
    240       1.33  macallan 
    241       1.30   thorpej static int	mach64_modeswitch(struct mach64_softc *, struct videomode *);
    242       1.30   thorpej static void	mach64_set_dsp(struct mach64_softc *);
    243       1.30   thorpej static void	mach64_set_pll(struct mach64_softc *, int);
    244       1.30   thorpej static void	mach64_reset_engine(struct mach64_softc *);
    245       1.30   thorpej static void	mach64_init_engine(struct mach64_softc *);
    246       1.30   thorpej #if 0
    247       1.30   thorpej static void	mach64_adjust_frame(struct mach64_softc *, int, int);
    248       1.30   thorpej #endif
    249       1.30   thorpej static void	mach64_init_lut(struct mach64_softc *);
    250  1.38.10.1      elad 
    251  1.38.10.1      elad static void	mach64_init_screen(void *, struct vcons_screen *, int, long *);
    252       1.30   thorpej static int 	mach64_set_screentype(struct mach64_softc *,
    253       1.30   thorpej 				      const struct wsscreen_descr *);
    254       1.30   thorpej static int	mach64_is_console(struct pci_attach_args *);
    255       1.30   thorpej 
    256       1.30   thorpej static void	mach64_cursor(void *, int, int, int);
    257       1.30   thorpej #if 0
    258       1.30   thorpej static int	mach64_mapchar(void *, int, u_int *);
    259       1.30   thorpej #endif
    260       1.30   thorpej static void	mach64_putchar(void *, int, int, u_int, long);
    261       1.30   thorpej static void	mach64_copycols(void *, int, int, int, int);
    262       1.30   thorpej static void	mach64_erasecols(void *, int, int, int, long);
    263       1.30   thorpej static void	mach64_copyrows(void *, int, int, int);
    264       1.30   thorpej static void	mach64_eraserows(void *, int, int, long);
    265       1.30   thorpej static int	mach64_allocattr(void *, int, int, int, long *);
    266       1.30   thorpej static void 	mach64_clearscreen(struct mach64_softc *);
    267       1.30   thorpej 
    268       1.30   thorpej static int	mach64_putcmap(struct mach64_softc *, struct wsdisplay_cmap *);
    269       1.30   thorpej static int	mach64_getcmap(struct mach64_softc *, struct wsdisplay_cmap *);
    270       1.30   thorpej static int	mach64_putpalreg(struct mach64_softc *, uint8_t, uint8_t,
    271       1.30   thorpej 				 uint8_t, uint8_t);
    272       1.30   thorpej static void	mach64_bitblt(struct mach64_softc *, int, int, int, int, int,
    273       1.30   thorpej 			      int, int, int) ;
    274       1.30   thorpej static void	mach64_rectfill(struct mach64_softc *, int, int, int, int, int);
    275       1.30   thorpej static void	mach64_setup_mono(struct mach64_softc *, int, int, int, int,
    276       1.30   thorpej 				  uint32_t, uint32_t);
    277       1.30   thorpej static void	mach64_feed_bytes(struct mach64_softc *, int, uint8_t *);
    278       1.30   thorpej #if 0
    279       1.30   thorpej static void	mach64_showpal(struct mach64_softc *);
    280       1.30   thorpej #endif
    281       1.21    martin 
    282  1.38.10.2      elad static void	set_address(struct rasops_info *, caddr_t);
    283       1.34  macallan static void	machfb_blank(struct mach64_softc *, int);
    284       1.19    martin 
    285        1.7    martin #if 0
    286       1.30   thorpej static const struct wsdisplay_emulops mach64_emulops = {
    287        1.1  junyoung 	mach64_cursor,
    288        1.1  junyoung 	mach64_mapchar,
    289        1.1  junyoung 	mach64_putchar,
    290        1.1  junyoung 	mach64_copycols,
    291        1.1  junyoung 	mach64_erasecols,
    292        1.1  junyoung 	mach64_copyrows,
    293        1.1  junyoung 	mach64_eraserows,
    294        1.1  junyoung 	mach64_allocattr,
    295        1.1  junyoung };
    296        1.7    martin #endif
    297        1.1  junyoung 
    298       1.30   thorpej static struct wsscreen_descr mach64_defaultscreen = {
    299        1.1  junyoung 	"default",
    300       1.33  macallan 	80, 30,
    301       1.33  macallan 	NULL,
    302        1.1  junyoung 	8, 16,
    303        1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    304        1.1  junyoung 	&default_mode
    305        1.1  junyoung }, mach64_80x25_screen = {
    306        1.1  junyoung 	"80x25", 80, 25,
    307       1.33  macallan 	NULL,
    308        1.1  junyoung 	8, 16,
    309        1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    310        1.1  junyoung 	&mach64_modes[0]
    311        1.1  junyoung }, mach64_80x30_screen = {
    312        1.1  junyoung 	"80x30", 80, 30,
    313       1.33  macallan 	NULL,
    314        1.1  junyoung 	8, 16,
    315        1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    316        1.1  junyoung 	&mach64_modes[1]
    317        1.1  junyoung }, mach64_80x40_screen = {
    318        1.1  junyoung 	"80x40", 80, 40,
    319       1.33  macallan 	NULL,
    320        1.1  junyoung 	8, 10,
    321        1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    322        1.1  junyoung 	&mach64_modes[0]
    323        1.1  junyoung }, mach64_80x50_screen = {
    324        1.1  junyoung 	"80x50", 80, 50,
    325       1.33  macallan 	NULL,
    326        1.1  junyoung 	8, 8,
    327        1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    328        1.1  junyoung 	&mach64_modes[0]
    329        1.1  junyoung }, mach64_100x37_screen = {
    330        1.1  junyoung 	"100x37", 100, 37,
    331       1.33  macallan 	NULL,
    332        1.1  junyoung 	8, 16,
    333        1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    334        1.1  junyoung 	&mach64_modes[2]
    335        1.1  junyoung }, mach64_128x48_screen = {
    336        1.1  junyoung 	"128x48", 128, 48,
    337       1.33  macallan 	NULL,
    338        1.1  junyoung 	8, 16,
    339        1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    340        1.1  junyoung 	&mach64_modes[3]
    341        1.1  junyoung }, mach64_144x54_screen = {
    342        1.1  junyoung 	"144x54", 144, 54,
    343       1.33  macallan 	NULL,
    344        1.1  junyoung 	8, 16,
    345        1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    346        1.1  junyoung 	&mach64_modes[4]
    347        1.1  junyoung }, mach64_160x64_screen = {
    348        1.1  junyoung 	"160x54", 160, 64,
    349       1.33  macallan 	NULL,
    350        1.1  junyoung 	8, 16,
    351        1.1  junyoung 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    352        1.1  junyoung 	&mach64_modes[5]
    353        1.1  junyoung };
    354        1.1  junyoung 
    355       1.30   thorpej static const struct wsscreen_descr *_mach64_scrlist[] = {
    356        1.1  junyoung 	&mach64_defaultscreen,
    357        1.1  junyoung 	&mach64_80x25_screen,
    358        1.1  junyoung 	&mach64_80x30_screen,
    359        1.1  junyoung 	&mach64_80x40_screen,
    360        1.1  junyoung 	&mach64_80x50_screen,
    361        1.1  junyoung 	&mach64_100x37_screen,
    362        1.1  junyoung 	&mach64_128x48_screen,
    363        1.1  junyoung 	&mach64_144x54_screen,
    364        1.1  junyoung 	&mach64_160x64_screen
    365        1.1  junyoung };
    366        1.1  junyoung 
    367       1.30   thorpej static struct wsscreen_list mach64_screenlist = {
    368        1.1  junyoung 	sizeof(_mach64_scrlist) / sizeof(struct wsscreen_descr *),
    369        1.1  junyoung 	_mach64_scrlist
    370        1.1  junyoung };
    371        1.1  junyoung 
    372  1.38.10.1      elad static int	mach64_ioctl(void *, void *, u_long, caddr_t, int,
    373  1.38.10.1      elad 		             struct lwp *);
    374  1.38.10.1      elad static paddr_t	mach64_mmap(void *, void *, off_t, int);
    375  1.38.10.1      elad 
    376       1.30   thorpej #if 0
    377       1.30   thorpej static int	mach64_load_font(void *, void *, struct wsdisplay_font *);
    378       1.30   thorpej #endif
    379        1.1  junyoung 
    380       1.30   thorpej static struct wsdisplay_accessops mach64_accessops = {
    381        1.1  junyoung 	mach64_ioctl,
    382        1.1  junyoung 	mach64_mmap,
    383  1.38.10.1      elad 	NULL,			/* vcons_alloc_screen */
    384  1.38.10.1      elad 	NULL,			/* vcons_free_screen */
    385  1.38.10.1      elad 	NULL,			/* vcons_show_screen */
    386       1.25  macallan 	NULL,			/* load_font */
    387       1.25  macallan 	NULL,			/* polls */
    388       1.25  macallan 	NULL,			/* scroll */
    389        1.1  junyoung };
    390        1.1  junyoung 
    391  1.38.10.1      elad static struct vcons_screen mach64_console_screen;
    392  1.38.10.1      elad 
    393  1.38.10.1      elad /* framebuffer device, SPARC-only so far */
    394  1.38.10.1      elad #ifdef __sparc__
    395  1.38.10.1      elad 
    396  1.38.10.1      elad static void	machfb_unblank(struct device *);
    397  1.38.10.1      elad static void	machfb_fbattach(struct mach64_softc *);
    398  1.38.10.1      elad 
    399  1.38.10.1      elad extern struct cfdriver machfb_cd;
    400  1.38.10.1      elad 
    401  1.38.10.1      elad dev_type_open(machfb_fbopen);
    402  1.38.10.1      elad dev_type_close(machfb_fbclose);
    403  1.38.10.1      elad dev_type_ioctl(machfb_fbioctl);
    404  1.38.10.1      elad dev_type_mmap(machfb_fbmmap);
    405  1.38.10.1      elad 
    406  1.38.10.1      elad /* frame buffer generic driver */
    407  1.38.10.1      elad static struct fbdriver machfb_fbdriver = {
    408  1.38.10.1      elad 	machfb_unblank, machfb_fbopen, machfb_fbclose, machfb_fbioctl, nopoll,
    409  1.38.10.1      elad 	machfb_fbmmap, nokqfilter
    410  1.38.10.1      elad };
    411  1.38.10.1      elad 
    412  1.38.10.1      elad #endif /* __sparc__ */
    413  1.38.10.1      elad 
    414        1.1  junyoung /*
    415        1.1  junyoung  * Inline functions for getting access to register aperture.
    416        1.1  junyoung  */
    417        1.1  junyoung 
    418  1.38.10.1      elad static inline uint32_t
    419  1.38.10.1      elad regr(struct mach64_softc *sc, uint32_t index)
    420        1.1  junyoung {
    421        1.4  junyoung 	return bus_space_read_4(sc->sc_regt, sc->sc_regh, index);
    422        1.1  junyoung }
    423        1.1  junyoung 
    424  1.38.10.1      elad static inline uint8_t
    425  1.38.10.1      elad regrb(struct mach64_softc *sc, uint32_t index)
    426        1.1  junyoung {
    427        1.4  junyoung 	return bus_space_read_1(sc->sc_regt, sc->sc_regh, index);
    428        1.1  junyoung }
    429        1.1  junyoung 
    430        1.1  junyoung static inline void
    431  1.38.10.1      elad regw(struct mach64_softc *sc, uint32_t index, uint32_t data)
    432        1.1  junyoung {
    433        1.4  junyoung 	bus_space_write_4(sc->sc_regt, sc->sc_regh, index, data);
    434       1.25  macallan 	bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 4,
    435       1.25  macallan 	    BUS_SPACE_BARRIER_WRITE);
    436        1.1  junyoung }
    437        1.1  junyoung 
    438        1.1  junyoung static inline void
    439  1.38.10.1      elad regwb(struct mach64_softc *sc, uint32_t index, uint8_t data)
    440        1.1  junyoung {
    441        1.4  junyoung 	bus_space_write_1(sc->sc_regt, sc->sc_regh, index, data);
    442       1.25  macallan 	bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 1,
    443       1.25  macallan 	    BUS_SPACE_BARRIER_WRITE);
    444        1.1  junyoung }
    445        1.1  junyoung 
    446        1.1  junyoung static inline void
    447  1.38.10.1      elad regwb_pll(struct mach64_softc *sc, uint32_t index, uint8_t data)
    448        1.1  junyoung {
    449        1.1  junyoung 	regwb(sc, CLOCK_CNTL + 1, (index << 2) | PLL_WR_EN);
    450        1.1  junyoung 	regwb(sc, CLOCK_CNTL + 2, data);
    451       1.22     perry 	regwb(sc, CLOCK_CNTL + 1, (index << 2) & ~PLL_WR_EN);
    452        1.1  junyoung }
    453        1.1  junyoung 
    454        1.1  junyoung static inline void
    455  1.38.10.1      elad wait_for_fifo(struct mach64_softc *sc, uint8_t v)
    456        1.1  junyoung {
    457        1.1  junyoung 	while ((regr(sc, FIFO_STAT) & 0xffff) > (0x8000 >> v))
    458       1.28  christos 		continue;
    459        1.1  junyoung }
    460        1.1  junyoung 
    461        1.1  junyoung static inline void
    462        1.1  junyoung wait_for_idle(struct mach64_softc *sc)
    463        1.1  junyoung {
    464        1.1  junyoung 	wait_for_fifo(sc, 16);
    465        1.1  junyoung 	while ((regr(sc, GUI_STAT) & 1) != 0)
    466       1.28  christos 		continue;
    467        1.1  junyoung }
    468        1.1  junyoung 
    469       1.30   thorpej static int
    470        1.1  junyoung mach64_match(struct device *parent, struct cfdata *match, void *aux)
    471        1.1  junyoung {
    472        1.1  junyoung 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
    473        1.1  junyoung 	int i;
    474        1.1  junyoung 
    475        1.1  junyoung 	if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
    476        1.1  junyoung 	    PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
    477        1.1  junyoung 		return 0;
    478        1.1  junyoung 
    479        1.1  junyoung 	for (i = 0; i < sizeof(mach64_info) / sizeof(mach64_info[0]); i++)
    480        1.1  junyoung 		if (PCI_PRODUCT(pa->pa_id) == mach64_info[i].chip_id) {
    481        1.1  junyoung 			mach64_chip_id = PCI_PRODUCT(pa->pa_id);
    482        1.1  junyoung 			mach64_chip_rev = PCI_REVISION(pa->pa_class);
    483       1.24  macallan 			return 100;
    484        1.1  junyoung 		}
    485       1.22     perry 
    486        1.1  junyoung 	return 0;
    487        1.1  junyoung }
    488        1.1  junyoung 
    489       1.30   thorpej static void
    490        1.1  junyoung mach64_attach(struct device *parent, struct device *self, void *aux)
    491        1.1  junyoung {
    492       1.22     perry 	struct mach64_softc *sc = (void *)self;
    493        1.1  junyoung 	struct pci_attach_args *pa = aux;
    494  1.38.10.1      elad 	struct rasops_info *ri;
    495        1.1  junyoung 	char devinfo[256];
    496        1.1  junyoung 	int bar, reg, id;
    497        1.1  junyoung 	struct wsemuldisplaydev_attach_args aa;
    498        1.1  junyoung 	long defattr;
    499  1.38.10.1      elad 	int setmode;
    500       1.21    martin 	pcireg_t screg;
    501        1.1  junyoung 
    502        1.1  junyoung 	sc->sc_pc = pa->pa_pc;
    503        1.1  junyoung 	sc->sc_pcitag = pa->pa_tag;
    504       1.26  macallan 	sc->sc_dacw = -1;
    505       1.26  macallan 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    506  1.38.10.1      elad 	sc->sc_nbus = pa->pa_bus;
    507  1.38.10.1      elad 	sc->sc_ndev = pa->pa_device;
    508  1.38.10.1      elad 	sc->sc_nfunc = pa->pa_function;
    509  1.38.10.1      elad 	sc->sc_locked = 0;
    510       1.24  macallan 
    511       1.18    itojun 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    512        1.1  junyoung 	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
    513       1.24  macallan 
    514       1.24  macallan 	/* enable memory and IO access */
    515       1.26  macallan 	screg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, PCI_COMMAND_STATUS_REG);
    516       1.26  macallan 	screg |= PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    517       1.21    martin 	pci_conf_write(sc->sc_pc, sc->sc_pcitag,PCI_COMMAND_STATUS_REG,screg);
    518       1.21    martin 
    519        1.1  junyoung 	for (bar = 0; bar < NBARS; bar++) {
    520        1.1  junyoung 		reg = PCI_MAPREG_START + (bar * 4);
    521        1.1  junyoung 		sc->sc_bars[bar].vb_type = pci_mapreg_type(sc->sc_pc,
    522        1.1  junyoung 		    sc->sc_pcitag, reg);
    523        1.1  junyoung 		(void)pci_mapreg_info(sc->sc_pc, sc->sc_pcitag, reg,
    524        1.1  junyoung 		    sc->sc_bars[bar].vb_type, &sc->sc_bars[bar].vb_base,
    525        1.1  junyoung 		    &sc->sc_bars[bar].vb_size, &sc->sc_bars[bar].vb_flags);
    526       1.26  macallan 		sc->sc_bars[bar].vb_busaddr = pci_conf_read(sc->sc_pc,
    527       1.25  macallan 		    sc->sc_pcitag, reg)&0xfffffff0;
    528        1.1  junyoung 	}
    529        1.3    martin 	sc->sc_memt = pa->pa_memt;
    530        1.1  junyoung 
    531        1.3    martin 	mach64_init(sc);
    532        1.1  junyoung 
    533        1.1  junyoung 	printf("%s: %d MB aperture at 0x%08x, %d KB registers at 0x%08x\n",
    534        1.4  junyoung 	    sc->sc_dev.dv_xname, (u_int)(sc->sc_apersize / (1024 * 1024)),
    535       1.22     perry 	    (u_int)sc->sc_aperphys, (u_int)(sc->sc_regsize / 1024),
    536       1.20    martin 	    (u_int)sc->sc_regphys);
    537        1.1  junyoung 
    538        1.1  junyoung 	if (mach64_chip_id == PCI_PRODUCT_ATI_MACH64_CT ||
    539       1.22     perry 	    ((mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||
    540       1.25  macallan 	    mach64_chip_id == PCI_PRODUCT_ATI_RAGE_II) &&
    541       1.25  macallan 	    (mach64_chip_rev & 0x07) == 0))
    542        1.1  junyoung 		sc->has_dsp = 0;
    543        1.1  junyoung 	else
    544        1.1  junyoung 		sc->has_dsp = 1;
    545        1.1  junyoung 
    546        1.1  junyoung 	sc->memsize = mach64_get_memsize(sc);
    547        1.1  junyoung 	if (sc->memsize == 8192)
    548        1.1  junyoung 		/* The last page is used as register aperture. */
    549        1.1  junyoung 		sc->memsize -= 4;
    550        1.1  junyoung 	sc->memtype = regr(sc, CONFIG_STAT0) & 0x07;
    551        1.1  junyoung 
    552        1.1  junyoung 	/* XXX is there any way to calculate reference frequency from
    553        1.1  junyoung 	   known values? */
    554       1.22     perry 	if ((mach64_chip_id == PCI_PRODUCT_ATI_RAGE_XL_PCI) ||
    555       1.26  macallan 	    ((mach64_chip_id >= PCI_PRODUCT_ATI_RAGE_LT_PRO_PCI) &&
    556       1.26  macallan 	    (mach64_chip_id <= PCI_PRODUCT_ATI_RAGE_LT_PRO))) {
    557       1.38  macallan 		printf("%s: ref_freq=29.498MHz\n", sc->sc_dev.dv_xname);
    558        1.1  junyoung 		sc->ref_freq = 29498;
    559       1.21    martin 	} else
    560        1.1  junyoung 		sc->ref_freq = 14318;
    561        1.1  junyoung 
    562        1.1  junyoung 	regwb(sc, CLOCK_CNTL + 1, PLL_REF_DIV << 2);
    563       1.22     perry 	sc->ref_div = regrb(sc, CLOCK_CNTL + 2);
    564        1.1  junyoung 	regwb(sc, CLOCK_CNTL + 1, MCLK_FB_DIV << 2);
    565        1.1  junyoung 	sc->mclk_fb_div = regrb(sc, CLOCK_CNTL + 2);
    566       1.22     perry 	sc->mem_freq = (2 * sc->ref_freq * sc->mclk_fb_div) /
    567        1.1  junyoung 	    (sc->ref_div * 2);
    568        1.1  junyoung 	sc->mclk_post_div = (sc->mclk_fb_div * 2 * sc->ref_freq) /
    569        1.1  junyoung 	    (sc->mem_freq * sc->ref_div);
    570        1.1  junyoung 	sc->ramdac_freq = mach64_get_max_ramdac(sc);
    571        1.2    martin 	printf("%s: %ld KB %s %d.%d MHz, maximum RAMDAC clock %d MHz\n",
    572       1.22     perry 	    sc->sc_dev.dv_xname, (u_long)sc->memsize,
    573        1.1  junyoung 	    mach64_memtype_names[sc->memtype],
    574        1.1  junyoung 	    sc->mem_freq / 1000, sc->mem_freq % 1000,
    575        1.1  junyoung 	    sc->ramdac_freq / 1000);
    576       1.22     perry 
    577        1.1  junyoung 	id = regr(sc, CONFIG_CHIP_ID) & 0xffff;
    578        1.1  junyoung 	if (id != mach64_chip_id) {
    579        1.1  junyoung 		printf("%s: chip ID mismatch, 0x%x != 0x%x\n",
    580        1.1  junyoung 		    sc->sc_dev.dv_xname, id, mach64_chip_id);
    581        1.1  junyoung 		return;
    582        1.1  junyoung 	}
    583        1.1  junyoung 
    584  1.38.10.1      elad 	sc->sc_console = mach64_is_console(pa);
    585       1.34  macallan #ifdef DIAGNOSTIC
    586       1.34  macallan 	printf("gen_cntl: %08x\n", regr(sc, CRTC_GEN_CNTL));
    587       1.34  macallan #endif
    588       1.20    martin #if defined(__sparc__) || defined(__powerpc__)
    589  1.38.10.1      elad 	if (sc->sc_console) {
    590        1.7    martin 		mach64_get_mode(sc, &default_mode);
    591        1.7    martin 		setmode = 0;
    592       1.33  macallan 		sc->sc_my_mode = &default_mode;
    593        1.7    martin 	} else {
    594       1.33  macallan 		/* fill in default_mode if it's empty */
    595  1.38.10.1      elad 		mach64_get_mode(sc, &default_mode);
    596       1.33  macallan 		if (default_mode.dot_clock == 0) {
    597       1.33  macallan 			memcpy(&default_mode, &mach64_modes[4],
    598       1.33  macallan 			    sizeof(default_mode));
    599       1.33  macallan 		}
    600       1.34  macallan 		sc->sc_my_mode = &default_mode;
    601        1.7    martin 		setmode = 1;
    602        1.7    martin 	}
    603        1.1  junyoung #else
    604       1.35  macallan 	if (default_mode.dot_clock == 0) {
    605       1.35  macallan 		memcpy(&default_mode, &mach64_modes[0],
    606       1.35  macallan 		    sizeof(default_mode));
    607       1.35  macallan 	}
    608       1.35  macallan 	sc->sc_my_mode = &mach64_modes[0];
    609       1.35  macallan 	setmode = 1;
    610        1.1  junyoung #endif
    611        1.1  junyoung 
    612        1.1  junyoung 	sc->bits_per_pixel = 8;
    613       1.33  macallan 	sc->virt_x = sc->sc_my_mode->hdisplay;
    614       1.33  macallan 	sc->virt_y = sc->sc_my_mode->vdisplay;
    615        1.1  junyoung 	sc->max_x = sc->virt_x - 1;
    616        1.1  junyoung 	sc->max_y = (sc->memsize * 1024) /
    617        1.1  junyoung 	    (sc->virt_x * (sc->bits_per_pixel / 8)) - 1;
    618       1.22     perry 
    619        1.1  junyoung 	sc->color_depth = CRTC_PIX_WIDTH_8BPP;
    620        1.1  junyoung 
    621        1.1  junyoung 	mach64_init_engine(sc);
    622        1.1  junyoung #if 0
    623        1.1  junyoung 	mach64_adjust_frame(0, 0);
    624        1.1  junyoung 	if (sc->bits_per_pixel == 8)
    625        1.1  junyoung 		mach64_init_lut(sc);
    626        1.1  junyoung #endif
    627        1.1  junyoung 
    628        1.1  junyoung 	printf("%s: initial resolution %dx%d at %d bpp\n", sc->sc_dev.dv_xname,
    629       1.33  macallan 	    sc->sc_my_mode->hdisplay, sc->sc_my_mode->vdisplay,
    630        1.1  junyoung 	    sc->bits_per_pixel);
    631        1.1  junyoung 
    632  1.38.10.1      elad #ifdef __sparc__
    633  1.38.10.1      elad 	machfb_fbattach(sc);
    634  1.38.10.1      elad #endif
    635       1.33  macallan 
    636  1.38.10.1      elad 	wsfont_init();
    637  1.38.10.1      elad 
    638  1.38.10.1      elad 	sc->sc_bg = WS_DEFAULT_BG;
    639  1.38.10.1      elad 	vcons_init(&sc->vd, sc, &mach64_defaultscreen, &mach64_accessops);
    640  1.38.10.1      elad 	sc->vd.init_screen = mach64_init_screen;
    641  1.38.10.1      elad 
    642  1.38.10.1      elad 	if (sc->sc_console) {
    643  1.38.10.1      elad 		vcons_init_screen(&sc->vd, &mach64_console_screen, 1,
    644  1.38.10.1      elad 		    &defattr);
    645  1.38.10.1      elad 		mach64_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    646  1.38.10.1      elad 
    647  1.38.10.1      elad 		ri = &mach64_console_screen.scr_ri;
    648  1.38.10.1      elad 		mach64_defaultscreen.textops = &ri->ri_ops;
    649  1.38.10.1      elad 		mach64_defaultscreen.capabilities = ri->ri_caps;
    650  1.38.10.1      elad 		mach64_defaultscreen.nrows = ri->ri_rows;
    651  1.38.10.1      elad 		mach64_defaultscreen.ncols = ri->ri_cols;
    652  1.38.10.1      elad 		wsdisplay_cnattach(&mach64_defaultscreen, ri, 0, 0, defattr);
    653       1.33  macallan 	} else {
    654       1.33  macallan 		/*
    655       1.33  macallan 		 * since we're not the console we can postpone the rest
    656       1.33  macallan 		 * until someone actually allocates a screen for us
    657       1.33  macallan 		 */
    658       1.34  macallan 		mach64_modeswitch(sc, sc->sc_my_mode);
    659        1.7    martin 	}
    660       1.33  macallan 
    661       1.19    martin 	mach64_init_lut(sc);
    662       1.21    martin 	mach64_clearscreen(sc);
    663       1.34  macallan 	machfb_blank(sc, 0);	/* unblank the screen */
    664       1.34  macallan 
    665  1.38.10.1      elad 	aa.console = sc->sc_console;
    666        1.1  junyoung 	aa.scrdata = &mach64_screenlist;
    667        1.1  junyoung 	aa.accessops = &mach64_accessops;
    668  1.38.10.1      elad 	aa.accesscookie = &sc->vd;
    669        1.1  junyoung 
    670        1.1  junyoung 	config_found(self, &aa, wsemuldisplaydevprint);
    671        1.1  junyoung }
    672        1.1  junyoung 
    673       1.30   thorpej static void
    674  1.38.10.1      elad mach64_init_screen(void *cookie, struct vcons_screen *scr, int existing,
    675  1.38.10.1      elad     long *defattr)
    676        1.1  junyoung {
    677  1.38.10.1      elad 	struct mach64_softc *sc = cookie;
    678  1.38.10.1      elad 	struct rasops_info *ri = &scr->scr_ri;
    679  1.38.10.1      elad 
    680  1.38.10.1      elad /* XXX for now */
    681  1.38.10.1      elad #define setmode 0
    682       1.26  macallan 
    683       1.21    martin 	ri->ri_depth = sc->bits_per_pixel;
    684       1.33  macallan 	ri->ri_width = sc->sc_my_mode->hdisplay;
    685       1.33  macallan 	ri->ri_height = sc->sc_my_mode->vdisplay;
    686       1.21    martin 	ri->ri_stride = ri->ri_width;
    687       1.21    martin 	ri->ri_flg = RI_CENTER;
    688  1.38.10.2      elad 	set_address(ri, sc->sc_aperture);
    689       1.21    martin 
    690        1.1  junyoung 	if (existing) {
    691       1.26  macallan 		ri->ri_flg |= RI_CLEAR;
    692  1.38.10.1      elad 		if (setmode && mach64_set_screentype(sc, scr->scr_type)) {
    693        1.1  junyoung 			panic("%s: failed to switch video mode",
    694        1.1  junyoung 			    sc->sc_dev.dv_xname);
    695        1.1  junyoung 		}
    696        1.1  junyoung 	}
    697  1.38.10.1      elad 
    698  1.38.10.1      elad 	rasops_init(ri, sc->sc_my_mode->vdisplay/8,
    699  1.38.10.1      elad 	    sc->sc_my_mode->hdisplay/8);
    700  1.38.10.1      elad 	ri->ri_caps = WSSCREEN_WSCOLORS;
    701        1.1  junyoung 
    702  1.38.10.1      elad 	rasops_reconfig(ri, sc->sc_my_mode->vdisplay / ri->ri_font->fontheight,
    703  1.38.10.1      elad 		    sc->sc_my_mode->hdisplay / ri->ri_font->fontwidth);
    704  1.38.10.1      elad 
    705  1.38.10.1      elad 	/* enable acceleration */
    706  1.38.10.1      elad 	ri->ri_hw = scr;
    707  1.38.10.1      elad 	ri->ri_ops.copyrows = mach64_copyrows;
    708  1.38.10.1      elad 	ri->ri_ops.copycols = mach64_copycols;
    709  1.38.10.1      elad 	ri->ri_ops.eraserows = mach64_eraserows;
    710  1.38.10.1      elad 	ri->ri_ops.erasecols = mach64_erasecols;
    711  1.38.10.1      elad 	ri->ri_ops.cursor = mach64_cursor;
    712  1.38.10.1      elad 	ri->ri_ops.putchar = mach64_putchar;
    713  1.38.10.1      elad 	ri->ri_ops.allocattr = mach64_allocattr;
    714        1.1  junyoung }
    715        1.1  junyoung 
    716       1.30   thorpej static void
    717        1.3    martin mach64_init(struct mach64_softc *sc)
    718        1.1  junyoung {
    719  1.38.10.1      elad 	uint32_t *p32, saved_value;
    720  1.38.10.1      elad 	uint8_t *p;
    721        1.9    martin 	int need_swap;
    722        1.4  junyoung 
    723        1.3    martin 	if (bus_space_map(sc->sc_memt, sc->sc_aperbase, sc->sc_apersize,
    724        1.1  junyoung 		BUS_SPACE_MAP_LINEAR, &sc->sc_memh)) {
    725        1.1  junyoung 		panic("%s: failed to map aperture", sc->sc_dev.dv_xname);
    726        1.1  junyoung 	}
    727  1.38.10.2      elad 	sc->sc_aperture = (caddr_t)bus_space_vaddr(sc->sc_memt, sc->sc_memh);
    728        1.4  junyoung 
    729        1.4  junyoung 	sc->sc_regt = sc->sc_memt;
    730        1.4  junyoung 	bus_space_subregion(sc->sc_regt, sc->sc_memh, MACH64_REG_OFF,
    731        1.4  junyoung 	    sc->sc_regsize, &sc->sc_regh);
    732  1.38.10.2      elad 	sc->sc_registers = sc->sc_aperture + 0x7ffc00;
    733        1.4  junyoung 
    734        1.9    martin 	/*
    735        1.9    martin 	 * Test wether the aperture is byte swapped or not
    736        1.9    martin 	 */
    737  1.38.10.2      elad 	p32 = (uint32_t*)sc->sc_aperture;
    738        1.9    martin 	saved_value = *p32;
    739  1.38.10.2      elad 	p = (uint8_t*)(u_long)sc->sc_aperture;
    740        1.9    martin 	*p32 = 0x12345678;
    741        1.9    martin 	if (p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78)
    742        1.9    martin 		need_swap = 0;
    743        1.9    martin 	else
    744        1.9    martin 		need_swap = 1;
    745        1.9    martin 	if (need_swap) {
    746  1.38.10.2      elad 		sc->sc_aperture += 0x800000;
    747        1.9    martin 		sc->sc_aperbase += 0x800000;
    748        1.9    martin 		sc->sc_apersize -= 0x800000;
    749        1.9    martin 	}
    750        1.9    martin 	*p32 = saved_value;
    751  1.38.10.1      elad 
    752  1.38.10.1      elad 	sc->sc_blanked = 0;
    753        1.1  junyoung }
    754        1.1  junyoung 
    755       1.30   thorpej static int
    756        1.1  junyoung mach64_get_memsize(struct mach64_softc *sc)
    757        1.1  junyoung {
    758        1.1  junyoung 	int tmp, memsize;
    759        1.1  junyoung 	int mem_tab[] = {
    760        1.1  junyoung 		512, 1024, 2048, 4096, 6144, 8192, 12288, 16384
    761        1.1  junyoung 	};
    762        1.1  junyoung 	tmp = regr(sc, MEM_CNTL);
    763  1.38.10.1      elad #ifdef DIAGNOSTIC
    764       1.38  macallan 	printf("%s: memctl %08x\n", sc->sc_dev.dv_xname, tmp);
    765  1.38.10.1      elad #endif
    766        1.1  junyoung 	if (sc->has_dsp) {
    767        1.1  junyoung 		tmp &= 0x0000000f;
    768        1.1  junyoung 		if (tmp < 8)
    769        1.1  junyoung 			memsize = (tmp + 1) * 512;
    770        1.1  junyoung 		else if (tmp < 12)
    771        1.1  junyoung 			memsize = (tmp - 3) * 1024;
    772        1.1  junyoung 		else
    773        1.1  junyoung 			memsize = (tmp - 7) * 2048;
    774        1.1  junyoung 	} else {
    775        1.1  junyoung 		memsize = mem_tab[tmp & 0x07];
    776        1.1  junyoung 	}
    777        1.1  junyoung 
    778        1.1  junyoung 	return memsize;
    779        1.1  junyoung }
    780        1.1  junyoung 
    781       1.30   thorpej static int
    782        1.1  junyoung mach64_get_max_ramdac(struct mach64_softc *sc)
    783        1.1  junyoung {
    784        1.1  junyoung 	int i;
    785        1.1  junyoung 
    786       1.22     perry 	if ((mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||
    787        1.1  junyoung 	     mach64_chip_id == PCI_PRODUCT_ATI_RAGE_II) &&
    788        1.1  junyoung 	     (mach64_chip_rev & 0x07))
    789        1.1  junyoung 		return 170000;
    790        1.1  junyoung 
    791        1.1  junyoung 	for (i = 0; i < sizeof(mach64_info) / sizeof(mach64_info[0]); i++)
    792        1.1  junyoung 		if (mach64_chip_id == mach64_info[i].chip_id)
    793        1.1  junyoung 			return mach64_info[i].ramdac_freq;
    794        1.1  junyoung 
    795        1.1  junyoung 	if (sc->bits_per_pixel == 8)
    796        1.1  junyoung 		return 135000;
    797        1.1  junyoung 	else
    798        1.1  junyoung 		return 80000;
    799        1.1  junyoung }
    800        1.1  junyoung 
    801  1.38.10.1      elad #if defined(__sparc__) || defined(__powerpc__)
    802       1.30   thorpej static void
    803        1.1  junyoung mach64_get_mode(struct mach64_softc *sc, struct videomode *mode)
    804        1.1  junyoung {
    805        1.1  junyoung 	struct mach64_crtcregs crtc;
    806       1.22     perry 
    807        1.1  junyoung 	crtc.h_total_disp = regr(sc, CRTC_H_TOTAL_DISP);
    808        1.1  junyoung 	crtc.h_sync_strt_wid = regr(sc, CRTC_H_SYNC_STRT_WID);
    809        1.1  junyoung 	crtc.v_total_disp = regr(sc, CRTC_V_TOTAL_DISP);
    810        1.1  junyoung 	crtc.v_sync_strt_wid = regr(sc, CRTC_V_SYNC_STRT_WID);
    811        1.1  junyoung 
    812        1.1  junyoung 	mode->htotal = ((crtc.h_total_disp & 0xffff) + 1) << 3;
    813        1.1  junyoung 	mode->hdisplay = ((crtc.h_total_disp >> 16) + 1) << 3;
    814        1.1  junyoung 	mode->hsync_start = ((crtc.h_sync_strt_wid & 0xffff) + 1) << 3;
    815        1.1  junyoung 	mode->hsync_end = ((crtc.h_sync_strt_wid >> 16) << 3) +
    816        1.1  junyoung 	    mode->hsync_start;
    817        1.1  junyoung 	mode->vtotal = (crtc.v_total_disp & 0xffff) + 1;
    818        1.1  junyoung 	mode->vdisplay = (crtc.v_total_disp >> 16) + 1;
    819        1.1  junyoung 	mode->vsync_start = (crtc.v_sync_strt_wid & 0xffff) + 1;
    820        1.1  junyoung 	mode->vsync_end = (crtc.v_sync_strt_wid >> 16) + mode->vsync_start;
    821        1.1  junyoung 
    822  1.38.10.1      elad #ifndef DEBUG_MACHFB
    823        1.1  junyoung 	printf("mach64_get_mode: %d %d %d %d %d %d %d %d\n",
    824        1.1  junyoung 	    mode->hdisplay, mode->hsync_start, mode->hsync_end, mode->htotal,
    825        1.1  junyoung 	    mode->vdisplay, mode->vsync_start, mode->vsync_end, mode->vtotal);
    826        1.1  junyoung #endif
    827        1.1  junyoung }
    828       1.35  macallan #endif
    829        1.1  junyoung 
    830       1.30   thorpej static int
    831        1.1  junyoung mach64_calc_crtcregs(struct mach64_softc *sc, struct mach64_crtcregs *crtc,
    832        1.1  junyoung     struct videomode *mode)
    833        1.1  junyoung {
    834        1.1  junyoung 
    835        1.1  junyoung 	if (mode->dot_clock > sc->ramdac_freq)
    836        1.1  junyoung 		/* Clock too high. */
    837        1.1  junyoung 		return 1;
    838        1.1  junyoung 
    839        1.1  junyoung 	crtc->h_total_disp = (((mode->hdisplay >> 3) - 1) << 16) |
    840        1.1  junyoung 	    ((mode->htotal >> 3) - 1);
    841       1.22     perry 	crtc->h_sync_strt_wid =
    842        1.1  junyoung 	    (((mode->hsync_end - mode->hsync_start) >> 3) << 16) |
    843        1.1  junyoung 	    ((mode->hsync_start >> 3) - 1);
    844        1.1  junyoung 
    845        1.1  junyoung 	crtc->v_total_disp = ((mode->vdisplay - 1) << 16) |
    846        1.1  junyoung 	    (mode->vtotal - 1);
    847        1.1  junyoung 	crtc->v_sync_strt_wid =
    848        1.1  junyoung 	    ((mode->vsync_end - mode->vsync_start) << 16) |
    849        1.1  junyoung 	    (mode->vsync_start - 1);
    850        1.1  junyoung 
    851        1.1  junyoung 	if (mode->flags & VID_NVSYNC)
    852        1.1  junyoung 		crtc->v_sync_strt_wid |= CRTC_VSYNC_NEG;
    853        1.1  junyoung 
    854        1.1  junyoung 	switch (sc->bits_per_pixel) {
    855        1.1  junyoung 	case 8:
    856        1.1  junyoung 		crtc->color_depth = CRTC_PIX_WIDTH_8BPP;
    857        1.1  junyoung 		break;
    858        1.1  junyoung 	case 16:
    859        1.1  junyoung 		crtc->color_depth = CRTC_PIX_WIDTH_16BPP;
    860       1.22     perry 		break;
    861        1.1  junyoung 	case 32:
    862        1.1  junyoung 		crtc->color_depth = CRTC_PIX_WIDTH_32BPP;
    863       1.22     perry 		break;
    864        1.1  junyoung 	}
    865       1.22     perry 
    866        1.1  junyoung 	crtc->gen_cntl = 0;
    867        1.1  junyoung 	if (mode->flags & VID_INTERLACE)
    868        1.1  junyoung 		crtc->gen_cntl |= CRTC_INTERLACE_EN;
    869  1.38.10.1      elad 
    870        1.1  junyoung 	if (mode->flags & VID_CSYNC)
    871        1.1  junyoung 		crtc->gen_cntl |= CRTC_CSYNC_EN;
    872       1.22     perry 
    873        1.1  junyoung 	crtc->dot_clock = mode->dot_clock;
    874        1.1  junyoung 
    875        1.1  junyoung 	return 0;
    876        1.1  junyoung }
    877        1.1  junyoung 
    878       1.30   thorpej static void
    879        1.1  junyoung mach64_set_crtcregs(struct mach64_softc *sc, struct mach64_crtcregs *crtc)
    880        1.1  junyoung {
    881        1.1  junyoung 
    882        1.1  junyoung 	mach64_set_pll(sc, crtc->dot_clock);
    883        1.1  junyoung 
    884        1.1  junyoung 	if (sc->has_dsp)
    885        1.1  junyoung 		mach64_set_dsp(sc);
    886        1.1  junyoung 
    887        1.1  junyoung 	regw(sc, CRTC_H_TOTAL_DISP, crtc->h_total_disp);
    888        1.1  junyoung 	regw(sc, CRTC_H_SYNC_STRT_WID, crtc->h_sync_strt_wid);
    889        1.1  junyoung 	regw(sc, CRTC_V_TOTAL_DISP, crtc->v_total_disp);
    890        1.1  junyoung 	regw(sc, CRTC_V_SYNC_STRT_WID, crtc->v_sync_strt_wid);
    891       1.22     perry 
    892        1.1  junyoung 	regw(sc, CRTC_VLINE_CRNT_VLINE, 0);
    893        1.1  junyoung 
    894        1.1  junyoung 	regw(sc, CRTC_OFF_PITCH, (sc->virt_x >> 3) << 22);
    895       1.22     perry 
    896        1.1  junyoung 	regw(sc, CRTC_GEN_CNTL, crtc->gen_cntl | crtc->color_depth |
    897  1.38.10.1      elad /* XXX this unconditionally enables composite sync on SPARC */
    898  1.38.10.1      elad #ifdef __sparc__
    899  1.38.10.1      elad 	    CRTC_CSYNC_EN |
    900  1.38.10.1      elad #endif
    901        1.1  junyoung 	    CRTC_EXT_DISP_EN | CRTC_EXT_EN);
    902        1.1  junyoung }
    903        1.1  junyoung 
    904       1.30   thorpej static int
    905        1.1  junyoung mach64_modeswitch(struct mach64_softc *sc, struct videomode *mode)
    906        1.1  junyoung {
    907        1.1  junyoung 	struct mach64_crtcregs crtc;
    908        1.1  junyoung 
    909  1.38.10.2      elad 	memset(&crtc, 0, sizeof crtc);	/* XXX gcc */
    910  1.38.10.2      elad 
    911        1.1  junyoung 	if (mach64_calc_crtcregs(sc, &crtc, mode))
    912        1.1  junyoung 		return 1;
    913        1.1  junyoung 
    914        1.1  junyoung 	mach64_set_crtcregs(sc, &crtc);
    915        1.1  junyoung 	return 0;
    916        1.1  junyoung }
    917        1.1  junyoung 
    918       1.30   thorpej static void
    919        1.1  junyoung mach64_reset_engine(struct mach64_softc *sc)
    920        1.1  junyoung {
    921        1.1  junyoung 
    922        1.1  junyoung 	/* Reset engine.*/
    923        1.1  junyoung 	regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) & ~GUI_ENGINE_ENABLE);
    924        1.1  junyoung 
    925        1.1  junyoung 	/* Enable engine. */
    926        1.1  junyoung 	regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) | GUI_ENGINE_ENABLE);
    927        1.1  junyoung 
    928        1.1  junyoung 	/* Ensure engine is not locked up by clearing any FIFO or
    929        1.1  junyoung 	   host errors. */
    930        1.1  junyoung 	regw(sc, BUS_CNTL, regr(sc, BUS_CNTL) | BUS_HOST_ERR_ACK |
    931        1.1  junyoung 	    BUS_FIFO_ERR_ACK);
    932        1.1  junyoung }
    933        1.1  junyoung 
    934       1.30   thorpej static void
    935        1.1  junyoung mach64_init_engine(struct mach64_softc *sc)
    936        1.1  junyoung {
    937  1.38.10.1      elad 	uint32_t pitch_value;
    938       1.22     perry 
    939        1.1  junyoung 	pitch_value = sc->virt_x;
    940        1.1  junyoung 
    941        1.1  junyoung 	if (sc->bits_per_pixel == 24)
    942        1.1  junyoung 		pitch_value *= 3;
    943        1.1  junyoung 
    944        1.1  junyoung 	mach64_reset_engine(sc);
    945       1.22     perry 
    946        1.1  junyoung 	wait_for_fifo(sc, 14);
    947       1.22     perry 
    948        1.1  junyoung 	regw(sc, CONTEXT_MASK, 0xffffffff);
    949        1.1  junyoung 
    950        1.1  junyoung 	regw(sc, DST_OFF_PITCH, (pitch_value / 8) << 22);
    951        1.1  junyoung 
    952        1.1  junyoung 	regw(sc, DST_Y_X, 0);
    953        1.1  junyoung 	regw(sc, DST_HEIGHT, 0);
    954        1.1  junyoung 	regw(sc, DST_BRES_ERR, 0);
    955        1.1  junyoung 	regw(sc, DST_BRES_INC, 0);
    956        1.1  junyoung 	regw(sc, DST_BRES_DEC, 0);
    957        1.1  junyoung 
    958        1.1  junyoung 	regw(sc, DST_CNTL, DST_LAST_PEL | DST_X_LEFT_TO_RIGHT |
    959        1.1  junyoung 	    DST_Y_TOP_TO_BOTTOM);
    960        1.1  junyoung 
    961        1.1  junyoung 	regw(sc, SRC_OFF_PITCH, (pitch_value / 8) << 22);
    962        1.1  junyoung 
    963        1.1  junyoung 	regw(sc, SRC_Y_X, 0);
    964        1.1  junyoung 	regw(sc, SRC_HEIGHT1_WIDTH1, 1);
    965        1.1  junyoung 	regw(sc, SRC_Y_X_START, 0);
    966        1.1  junyoung 	regw(sc, SRC_HEIGHT2_WIDTH2, 1);
    967        1.1  junyoung 
    968        1.1  junyoung 	regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
    969        1.1  junyoung 
    970        1.1  junyoung 	wait_for_fifo(sc, 13);
    971        1.1  junyoung 	regw(sc, HOST_CNTL, 0);
    972       1.22     perry 
    973        1.1  junyoung 	regw(sc, PAT_REG0, 0);
    974        1.1  junyoung 	regw(sc, PAT_REG1, 0);
    975        1.1  junyoung 	regw(sc, PAT_CNTL, 0);
    976        1.1  junyoung 
    977        1.1  junyoung 	regw(sc, SC_LEFT, 0);
    978        1.1  junyoung 	regw(sc, SC_TOP, 0);
    979       1.33  macallan 	regw(sc, SC_BOTTOM, sc->sc_my_mode->vdisplay - 1);
    980        1.1  junyoung 	regw(sc, SC_RIGHT, pitch_value - 1);
    981        1.1  junyoung 
    982        1.1  junyoung 	regw(sc, DP_BKGD_CLR, 0);
    983        1.1  junyoung 	regw(sc, DP_FRGD_CLR, 0xffffffff);
    984        1.1  junyoung 	regw(sc, DP_WRITE_MASK, 0xffffffff);
    985        1.1  junyoung 	regw(sc, DP_MIX, (MIX_SRC << 16) | MIX_DST);
    986        1.1  junyoung 
    987        1.1  junyoung 	regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR);
    988        1.1  junyoung 
    989        1.1  junyoung 	wait_for_fifo(sc, 3);
    990        1.1  junyoung 	regw(sc, CLR_CMP_CLR, 0);
    991        1.1  junyoung 	regw(sc, CLR_CMP_MASK, 0xffffffff);
    992        1.1  junyoung 	regw(sc, CLR_CMP_CNTL, 0);
    993        1.1  junyoung 
    994        1.1  junyoung 	wait_for_fifo(sc, 2);
    995        1.1  junyoung 	switch (sc->bits_per_pixel) {
    996        1.1  junyoung 	case 8:
    997        1.1  junyoung 		regw(sc, DP_PIX_WIDTH, HOST_8BPP | SRC_8BPP | DST_8BPP);
    998        1.1  junyoung 		regw(sc, DP_CHAIN_MASK, DP_CHAIN_8BPP);
    999       1.25  macallan 		/* We want 8 bit per channel */
   1000       1.19    martin 		regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
   1001        1.1  junyoung 		break;
   1002        1.1  junyoung #if 0
   1003        1.1  junyoung 	case 32:
   1004        1.1  junyoung 		regw(sc, DP_PIX_WIDTH, HOST_32BPP | SRC_32BPP | DST_32BPP);
   1005        1.1  junyoung 		regw(sc, DP_CHAIN_MASK, DP_CHAIN_32BPP);
   1006        1.1  junyoung 		regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
   1007        1.1  junyoung 		break;
   1008        1.1  junyoung #endif
   1009        1.1  junyoung 	}
   1010        1.1  junyoung 
   1011        1.1  junyoung 	wait_for_fifo(sc, 5);
   1012        1.1  junyoung 	regw(sc, CRTC_INT_CNTL, regr(sc, CRTC_INT_CNTL) & ~0x20);
   1013        1.1  junyoung 	regw(sc, GUI_TRAJ_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
   1014        1.1  junyoung 
   1015        1.1  junyoung 	wait_for_idle(sc);
   1016        1.1  junyoung }
   1017        1.1  junyoung 
   1018       1.30   thorpej #if 0
   1019       1.30   thorpej static void
   1020        1.1  junyoung mach64_adjust_frame(struct mach64_softc *sc, int x, int y)
   1021        1.1  junyoung {
   1022        1.1  junyoung 	int offset;
   1023        1.1  junyoung 
   1024        1.1  junyoung 	offset = ((x + y * sc->virt_x) * (sc->bits_per_pixel >> 3)) >> 3;
   1025       1.22     perry 
   1026        1.1  junyoung 	regw(sc, CRTC_OFF_PITCH, (regr(sc, CRTC_OFF_PITCH) & 0xfff00000) |
   1027        1.1  junyoung 	     offset);
   1028        1.1  junyoung }
   1029       1.30   thorpej #endif
   1030        1.1  junyoung 
   1031       1.30   thorpej static void
   1032        1.1  junyoung mach64_set_dsp(struct mach64_softc *sc)
   1033        1.1  junyoung {
   1034  1.38.10.1      elad 	uint32_t fifo_depth, page_size, dsp_precision, dsp_loop_latency;
   1035  1.38.10.1      elad 	uint32_t dsp_off, dsp_on, dsp_xclks_per_qw;
   1036  1.38.10.1      elad 	uint32_t xclks_per_qw, y;
   1037  1.38.10.1      elad 	uint32_t fifo_off, fifo_on;
   1038       1.22     perry 
   1039       1.38  macallan 	printf("%s: initializing the DSP\n", sc->sc_dev.dv_xname);
   1040        1.1  junyoung 	if (mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||
   1041        1.1  junyoung 	    mach64_chip_id == PCI_PRODUCT_ATI_RAGE_II ||
   1042        1.1  junyoung 	    mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIP ||
   1043        1.1  junyoung 	    mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIC_PCI ||
   1044        1.1  junyoung 	    mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIC_AGP_B ||
   1045        1.1  junyoung 	    mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIC_AGP_P) {
   1046        1.1  junyoung 		dsp_loop_latency = 0;
   1047        1.1  junyoung 		fifo_depth = 24;
   1048        1.1  junyoung 	} else {
   1049        1.1  junyoung 		dsp_loop_latency = 2;
   1050        1.1  junyoung 		fifo_depth = 32;
   1051        1.1  junyoung 	}
   1052        1.1  junyoung 
   1053        1.1  junyoung 	dsp_precision = 0;
   1054        1.1  junyoung 	xclks_per_qw = (sc->mclk_fb_div * sc->vclk_post_div * 64 << 11) /
   1055        1.1  junyoung 	    (sc->vclk_fb_div * sc->mclk_post_div * sc->bits_per_pixel);
   1056        1.1  junyoung 	y = (xclks_per_qw * fifo_depth) >> 11;
   1057        1.1  junyoung 	while (y) {
   1058        1.1  junyoung 		y >>= 1;
   1059        1.1  junyoung 		dsp_precision++;
   1060        1.1  junyoung 	}
   1061        1.1  junyoung 	dsp_precision -= 5;
   1062        1.1  junyoung 	fifo_off = ((xclks_per_qw * (fifo_depth - 1)) >> 5) + (3 << 6);
   1063       1.22     perry 
   1064        1.1  junyoung 	switch (sc->memtype) {
   1065        1.1  junyoung 	case DRAM:
   1066        1.1  junyoung 	case EDO_DRAM:
   1067        1.1  junyoung 	case PSEUDO_EDO:
   1068        1.1  junyoung 		if (sc->memsize > 1024) {
   1069        1.1  junyoung 			page_size = 9;
   1070        1.1  junyoung 			dsp_loop_latency += 6;
   1071        1.1  junyoung 		} else {
   1072        1.1  junyoung 			page_size = 10;
   1073        1.1  junyoung 			if (sc->memtype == DRAM)
   1074        1.1  junyoung 				dsp_loop_latency += 8;
   1075        1.1  junyoung 			else
   1076        1.1  junyoung 				dsp_loop_latency += 7;
   1077        1.1  junyoung 		}
   1078        1.1  junyoung 		break;
   1079        1.1  junyoung 	case SDRAM:
   1080        1.1  junyoung 	case SGRAM:
   1081        1.1  junyoung 		if (sc->memsize > 1024) {
   1082        1.1  junyoung 			page_size = 8;
   1083        1.1  junyoung 			dsp_loop_latency += 8;
   1084        1.1  junyoung 		} else {
   1085       1.22     perry 			page_size = 10;
   1086        1.1  junyoung 			dsp_loop_latency += 9;
   1087        1.1  junyoung 		}
   1088        1.1  junyoung 		break;
   1089        1.1  junyoung 	default:
   1090        1.1  junyoung 		page_size = 10;
   1091        1.1  junyoung 		dsp_loop_latency += 9;
   1092        1.1  junyoung 		break;
   1093        1.1  junyoung 	}
   1094        1.1  junyoung 
   1095        1.1  junyoung 	if (xclks_per_qw >= (page_size << 11))
   1096        1.1  junyoung 		fifo_on = ((2 * page_size + 1) << 6) + (xclks_per_qw >> 5);
   1097        1.1  junyoung 	else
   1098        1.1  junyoung 		fifo_on = (3 * page_size + 2) << 6;
   1099        1.1  junyoung 
   1100        1.1  junyoung 	dsp_xclks_per_qw = xclks_per_qw >> dsp_precision;
   1101        1.1  junyoung 	dsp_on = fifo_on >> dsp_precision;
   1102        1.1  junyoung 	dsp_off = fifo_off >> dsp_precision;
   1103        1.1  junyoung 
   1104       1.21    martin #ifdef DEBUG_MACHFB
   1105        1.1  junyoung 	printf("dsp_xclks_per_qw = %d, dsp_on = %d, dsp_off = %d,\n"
   1106        1.1  junyoung 	    "dsp_precision = %d, dsp_loop_latency = %d,\n"
   1107        1.1  junyoung 	    "mclk_fb_div = %d, vclk_fb_div = %d,\n"
   1108        1.1  junyoung 	    "mclk_post_div = %d, vclk_post_div = %d\n",
   1109        1.1  junyoung 	    dsp_xclks_per_qw, dsp_on, dsp_off, dsp_precision, dsp_loop_latency,
   1110        1.1  junyoung 	    sc->mclk_fb_div, sc->vclk_fb_div,
   1111        1.1  junyoung 	    sc->mclk_post_div, sc->vclk_post_div);
   1112       1.22     perry #endif
   1113        1.1  junyoung 
   1114        1.1  junyoung 	regw(sc, DSP_ON_OFF, ((dsp_on << 16) & DSP_ON) | (dsp_off & DSP_OFF));
   1115        1.1  junyoung 	regw(sc, DSP_CONFIG, ((dsp_precision << 20) & DSP_PRECISION) |
   1116       1.22     perry 	    ((dsp_loop_latency << 16) & DSP_LOOP_LATENCY) |
   1117        1.1  junyoung 	    (dsp_xclks_per_qw & DSP_XCLKS_PER_QW));
   1118        1.1  junyoung }
   1119        1.1  junyoung 
   1120       1.30   thorpej static void
   1121        1.1  junyoung mach64_set_pll(struct mach64_softc *sc, int clock)
   1122        1.1  junyoung {
   1123        1.1  junyoung 	int q;
   1124        1.1  junyoung 
   1125        1.1  junyoung 	q = (clock * sc->ref_div * 100) / (2 * sc->ref_freq);
   1126       1.21    martin #ifdef DEBUG_MACHFB
   1127        1.1  junyoung 	printf("q = %d\n", q);
   1128        1.1  junyoung #endif
   1129        1.1  junyoung 	if (q > 25500) {
   1130        1.1  junyoung 		printf("Warning: q > 25500\n");
   1131        1.1  junyoung 		q = 25500;
   1132        1.1  junyoung 		sc->vclk_post_div = 1;
   1133        1.1  junyoung 		sc->log2_vclk_post_div = 0;
   1134        1.1  junyoung 	} else if (q > 12750) {
   1135        1.1  junyoung 		sc->vclk_post_div = 1;
   1136        1.1  junyoung 		sc->log2_vclk_post_div = 0;
   1137        1.1  junyoung 	} else if (q > 6350) {
   1138        1.1  junyoung 		sc->vclk_post_div = 2;
   1139        1.1  junyoung 		sc->log2_vclk_post_div = 1;
   1140        1.1  junyoung 	} else if (q > 3150) {
   1141        1.1  junyoung 		sc->vclk_post_div = 4;
   1142        1.1  junyoung 		sc->log2_vclk_post_div = 2;
   1143        1.1  junyoung 	} else if (q >= 1600) {
   1144        1.1  junyoung 		sc->vclk_post_div = 8;
   1145        1.1  junyoung 		sc->log2_vclk_post_div = 3;
   1146        1.1  junyoung 	} else {
   1147       1.22     perry 		printf("Warning: q < 1600\n");
   1148        1.1  junyoung 		sc->vclk_post_div = 8;
   1149        1.1  junyoung 		sc->log2_vclk_post_div = 3;
   1150        1.1  junyoung 	}
   1151        1.1  junyoung 	sc->vclk_fb_div = q * sc->vclk_post_div / 100;
   1152        1.1  junyoung 
   1153        1.1  junyoung 	regwb_pll(sc, MCLK_FB_DIV, sc->mclk_fb_div);
   1154        1.1  junyoung 	regwb_pll(sc, VCLK_POST_DIV, sc->log2_vclk_post_div);
   1155        1.1  junyoung 	regwb_pll(sc, VCLK0_FB_DIV, sc->vclk_fb_div);
   1156       1.22     perry }
   1157        1.1  junyoung 
   1158       1.30   thorpej static void
   1159        1.1  junyoung mach64_init_lut(struct mach64_softc *sc)
   1160        1.1  junyoung {
   1161       1.28  christos 	int i, idx;
   1162       1.26  macallan 
   1163       1.26  macallan 	idx = 0;
   1164       1.26  macallan 	for (i = 0; i < 256; i++) {
   1165       1.26  macallan 		mach64_putpalreg(sc, i, rasops_cmap[idx], rasops_cmap[idx + 1],
   1166       1.26  macallan 		    rasops_cmap[idx + 2]);
   1167       1.26  macallan 		idx += 3;
   1168       1.19    martin 	}
   1169       1.24  macallan }
   1170        1.1  junyoung 
   1171       1.30   thorpej static int
   1172       1.26  macallan mach64_putpalreg(struct mach64_softc *sc, uint8_t index, uint8_t r, uint8_t g,
   1173       1.26  macallan     uint8_t b)
   1174       1.19    martin {
   1175       1.26  macallan 	sc->sc_cmap_red[index] = r;
   1176       1.26  macallan 	sc->sc_cmap_green[index] = g;
   1177       1.26  macallan 	sc->sc_cmap_blue[index] = b;
   1178       1.25  macallan 	/*
   1179       1.25  macallan 	 * writing the dac index takes a while, in theory we can poll some
   1180       1.25  macallan 	 * register to see when it's ready - but we better avoid writing it
   1181       1.25  macallan 	 * unnecessarily
   1182       1.25  macallan 	 */
   1183       1.28  christos 	if (index != sc->sc_dacw) {
   1184       1.19    martin 		regwb(sc, DAC_MASK, 0xff);
   1185       1.19    martin 		regwb(sc, DAC_WINDEX, index);
   1186       1.19    martin 	}
   1187       1.26  macallan 	sc->sc_dacw = index + 1;
   1188       1.19    martin 	regwb(sc, DAC_DATA, r);
   1189       1.19    martin 	regwb(sc, DAC_DATA, g);
   1190       1.19    martin 	regwb(sc, DAC_DATA, b);
   1191       1.19    martin 	return 0;
   1192       1.19    martin }
   1193        1.1  junyoung 
   1194       1.30   thorpej static int
   1195       1.21    martin mach64_putcmap(struct mach64_softc *sc, struct wsdisplay_cmap *cm)
   1196       1.19    martin {
   1197  1.38.10.1      elad 	uint index = cm->index;
   1198  1.38.10.1      elad 	uint count = cm->count;
   1199       1.19    martin 	int i, error;
   1200  1.38.10.1      elad 	uint8_t rbuf[256], gbuf[256], bbuf[256];
   1201  1.38.10.1      elad 	uint8_t *r, *g, *b;
   1202       1.19    martin 
   1203       1.19    martin 	if (cm->index >= 256 || cm->count > 256 ||
   1204       1.19    martin 	    (cm->index + cm->count) > 256)
   1205       1.19    martin 		return EINVAL;
   1206       1.19    martin 	error = copyin(cm->red, &rbuf[index], count);
   1207       1.19    martin 	if (error)
   1208       1.19    martin 		return error;
   1209       1.19    martin 	error = copyin(cm->green, &gbuf[index], count);
   1210       1.19    martin 	if (error)
   1211       1.19    martin 		return error;
   1212       1.19    martin 	error = copyin(cm->blue, &bbuf[index], count);
   1213       1.19    martin 	if (error)
   1214       1.19    martin 		return error;
   1215       1.19    martin 
   1216       1.19    martin 	memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
   1217       1.19    martin 	memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
   1218       1.19    martin 	memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
   1219       1.19    martin 
   1220       1.19    martin 	r = &sc->sc_cmap_red[index];
   1221       1.19    martin 	g = &sc->sc_cmap_green[index];
   1222       1.19    martin 	b = &sc->sc_cmap_blue[index];
   1223       1.22     perry 
   1224       1.19    martin 	for (i = 0; i < count; i++) {
   1225       1.26  macallan 		mach64_putpalreg(sc, index, *r, *g, *b);
   1226       1.19    martin 		index++;
   1227       1.19    martin 		r++, g++, b++;
   1228        1.1  junyoung 	}
   1229       1.19    martin 	return 0;
   1230       1.19    martin }
   1231       1.19    martin 
   1232       1.30   thorpej static int
   1233       1.21    martin mach64_getcmap(struct mach64_softc *sc, struct wsdisplay_cmap *cm)
   1234       1.19    martin {
   1235       1.19    martin 	u_int index = cm->index;
   1236       1.19    martin 	u_int count = cm->count;
   1237       1.19    martin 	int error;
   1238       1.19    martin 
   1239       1.19    martin 	if (index >= 255 || count > 256 || index + count > 256)
   1240       1.19    martin 		return EINVAL;
   1241       1.22     perry 
   1242       1.19    martin 	error = copyout(&sc->sc_cmap_red[index],   cm->red,   count);
   1243       1.19    martin 	if (error)
   1244       1.19    martin 		return error;
   1245       1.19    martin 	error = copyout(&sc->sc_cmap_green[index], cm->green, count);
   1246       1.19    martin 	if (error)
   1247       1.19    martin 		return error;
   1248       1.19    martin 	error = copyout(&sc->sc_cmap_blue[index],  cm->blue,  count);
   1249       1.19    martin 	if (error)
   1250       1.19    martin 		return error;
   1251       1.19    martin 
   1252       1.19    martin 	return 0;
   1253        1.1  junyoung }
   1254        1.1  junyoung 
   1255       1.30   thorpej static int
   1256        1.1  junyoung mach64_set_screentype(struct mach64_softc *sc, const struct wsscreen_descr *des)
   1257        1.1  junyoung {
   1258        1.6  junyoung 	struct mach64_crtcregs regs;
   1259        1.1  junyoung 
   1260        1.6  junyoung 	if (mach64_calc_crtcregs(sc, &regs,
   1261        1.6  junyoung 	    (struct videomode *)des->modecookie))
   1262        1.6  junyoung 		return 1;
   1263        1.6  junyoung 
   1264        1.6  junyoung 	mach64_set_crtcregs(sc, &regs);
   1265        1.6  junyoung 	return 0;
   1266        1.1  junyoung }
   1267        1.1  junyoung 
   1268       1.30   thorpej static int
   1269        1.5  junyoung mach64_is_console(struct pci_attach_args *pa)
   1270        1.5  junyoung {
   1271        1.5  junyoung #ifdef __sparc__
   1272        1.5  junyoung 	int node;
   1273        1.5  junyoung 
   1274        1.5  junyoung 	node = PCITAG_NODE(pa->pa_tag);
   1275        1.5  junyoung 	if (node == -1)
   1276        1.5  junyoung 		return 0;
   1277        1.5  junyoung 
   1278       1.17        pk 	return (node == prom_instance_to_package(prom_stdout()));
   1279       1.20    martin #elif defined(__powerpc__)
   1280       1.20    martin 	/* check if we're the /chosen console device */
   1281       1.20    martin 	int chosen, stdout, node, us;
   1282       1.26  macallan 
   1283       1.26  macallan 	us = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
   1284       1.20    martin 	chosen = OF_finddevice("/chosen");
   1285       1.20    martin 	OF_getprop(chosen, "stdout", &stdout, 4);
   1286       1.20    martin 	node = OF_instance_to_package(stdout);
   1287       1.26  macallan 	return (us == node);
   1288        1.5  junyoung #else
   1289        1.5  junyoung 	return 1;
   1290        1.5  junyoung #endif
   1291        1.5  junyoung }
   1292        1.5  junyoung 
   1293        1.1  junyoung /*
   1294        1.1  junyoung  * wsdisplay_emulops
   1295        1.1  junyoung  */
   1296        1.1  junyoung 
   1297       1.30   thorpej static void
   1298        1.1  junyoung mach64_cursor(void *cookie, int on, int row, int col)
   1299        1.1  junyoung {
   1300       1.28  christos 	struct rasops_info *ri = cookie;
   1301  1.38.10.1      elad 	struct vcons_screen *scr = ri->ri_hw;
   1302  1.38.10.1      elad 	struct mach64_softc *sc = scr->scr_cookie;
   1303  1.38.10.1      elad 	int x, y, wi, he;
   1304       1.26  macallan 
   1305       1.26  macallan 	wi = ri->ri_font->fontwidth;
   1306       1.26  macallan 	he = ri->ri_font->fontheight;
   1307       1.26  macallan 
   1308  1.38.10.1      elad 	if ((!sc->sc_locked) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
   1309  1.38.10.1      elad 		x = ri->ri_ccol * wi + ri->ri_xorigin;
   1310  1.38.10.1      elad 		y = ri->ri_crow * he + ri->ri_yorigin;
   1311  1.38.10.1      elad 		if (ri->ri_flg & RI_CURSOR) {
   1312       1.26  macallan 			mach64_bitblt(sc, x, y, x, y, wi, he, MIX_NOT_SRC,
   1313       1.26  macallan 			    0xff);
   1314  1.38.10.1      elad 			ri->ri_flg &= ~RI_CURSOR;
   1315       1.21    martin 		}
   1316  1.38.10.1      elad 		ri->ri_crow = row;
   1317  1.38.10.1      elad 		ri->ri_ccol = col;
   1318  1.38.10.1      elad 		if (on) {
   1319  1.38.10.1      elad 			x = ri->ri_ccol * wi + ri->ri_xorigin;
   1320  1.38.10.1      elad 			y = ri->ri_crow * he + ri->ri_yorigin;
   1321       1.26  macallan 			mach64_bitblt(sc, x, y, x, y, wi, he, MIX_NOT_SRC,
   1322       1.26  macallan 			    0xff);
   1323  1.38.10.1      elad 			ri->ri_flg |= RI_CURSOR;;
   1324       1.21    martin 		}
   1325       1.21    martin 	} else {
   1326  1.38.10.1      elad 		scr->scr_ri.ri_crow = row;
   1327  1.38.10.1      elad 		scr->scr_ri.ri_ccol = col;
   1328  1.38.10.1      elad 		scr->scr_ri.ri_flg &= ~RI_CURSOR;
   1329       1.21    martin 	}
   1330        1.1  junyoung }
   1331        1.1  junyoung 
   1332        1.7    martin #if 0
   1333       1.30   thorpej static int
   1334        1.1  junyoung mach64_mapchar(void *cookie, int uni, u_int *index)
   1335        1.1  junyoung {
   1336        1.1  junyoung 	return 0;
   1337        1.1  junyoung }
   1338       1.21    martin #endif
   1339        1.1  junyoung 
   1340       1.30   thorpej static void
   1341        1.1  junyoung mach64_putchar(void *cookie, int row, int col, u_int c, long attr)
   1342        1.1  junyoung {
   1343       1.28  christos 	struct rasops_info *ri = cookie;
   1344  1.38.10.1      elad 	struct vcons_screen *scr = ri->ri_hw;
   1345  1.38.10.1      elad 	struct mach64_softc *sc = scr->scr_cookie;
   1346  1.38.10.1      elad 
   1347  1.38.10.1      elad 	if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
   1348       1.26  macallan 		int fg, bg, uc;
   1349       1.21    martin 		uint8_t *data;
   1350       1.26  macallan 		int x, y, wi, he;
   1351       1.26  macallan 		wi = ri->ri_font->fontwidth;
   1352       1.26  macallan 		he = ri->ri_font->fontheight;
   1353       1.22     perry 
   1354       1.21    martin 		if (!CHAR_IN_FONT(c, ri->ri_font))
   1355       1.21    martin 			return;
   1356       1.21    martin 		bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xf];
   1357       1.21    martin 		fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xf];
   1358       1.26  macallan 		x = ri->ri_xorigin + col * wi;
   1359       1.26  macallan 		y = ri->ri_yorigin + row * he;
   1360       1.26  macallan 		if (c == 0x20) {
   1361       1.26  macallan 			mach64_rectfill(sc, x, y, wi, he, bg);
   1362       1.21    martin 		} else {
   1363       1.21    martin 			uc = c-ri->ri_font->firstchar;
   1364       1.25  macallan 			data = (uint8_t *)ri->ri_font->data + uc *
   1365       1.25  macallan 			    ri->ri_fontscale;
   1366        1.1  junyoung 
   1367       1.26  macallan 			mach64_setup_mono(sc, x, y, wi, he, fg, bg);
   1368       1.26  macallan 			mach64_feed_bytes(sc, ri->ri_fontscale, data);
   1369       1.21    martin 		}
   1370       1.21    martin 	}
   1371        1.1  junyoung }
   1372       1.21    martin 
   1373        1.1  junyoung 
   1374       1.30   thorpej static void
   1375        1.1  junyoung mach64_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
   1376        1.1  junyoung {
   1377  1.38.10.1      elad 	struct rasops_info *ri = cookie;
   1378  1.38.10.1      elad 	struct vcons_screen *scr = ri->ri_hw;
   1379  1.38.10.1      elad 	struct mach64_softc *sc = scr->scr_cookie;
   1380  1.38.10.1      elad 	int32_t xs, xd, y, width, height;
   1381       1.26  macallan 
   1382  1.38.10.1      elad 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
   1383       1.26  macallan 		xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
   1384       1.26  macallan 		xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
   1385       1.26  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1386       1.26  macallan 		width = ri->ri_font->fontwidth * ncols;
   1387       1.26  macallan 		height = ri->ri_font->fontheight;
   1388       1.26  macallan 		mach64_bitblt(sc, xs, y, xd, y, width, height, MIX_SRC, 0xff);
   1389       1.24  macallan 	}
   1390       1.21    martin }
   1391        1.1  junyoung 
   1392       1.30   thorpej static void
   1393        1.1  junyoung mach64_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
   1394        1.1  junyoung {
   1395  1.38.10.1      elad 	struct rasops_info *ri = cookie;
   1396  1.38.10.1      elad 	struct vcons_screen *scr = ri->ri_hw;
   1397  1.38.10.1      elad 	struct mach64_softc *sc = scr->scr_cookie;
   1398       1.26  macallan 	int32_t x, y, width, height, fg, bg, ul;
   1399       1.26  macallan 
   1400  1.38.10.1      elad 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
   1401       1.26  macallan 		x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
   1402       1.26  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1403       1.26  macallan 		width = ri->ri_font->fontwidth * ncols;
   1404       1.26  macallan 		height = ri->ri_font->fontheight;
   1405       1.26  macallan 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
   1406       1.22     perry 
   1407       1.26  macallan 		mach64_rectfill(sc, x, y, width, height, bg);
   1408       1.21    martin 	}
   1409        1.1  junyoung }
   1410        1.1  junyoung 
   1411       1.30   thorpej static void
   1412        1.1  junyoung mach64_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
   1413        1.1  junyoung {
   1414  1.38.10.1      elad 	struct rasops_info *ri = cookie;
   1415  1.38.10.1      elad 	struct vcons_screen *scr = ri->ri_hw;
   1416  1.38.10.1      elad 	struct mach64_softc *sc = scr->scr_cookie;
   1417       1.25  macallan 	int32_t x, ys, yd, width, height;
   1418       1.22     perry 
   1419  1.38.10.1      elad 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
   1420       1.26  macallan 		x = ri->ri_xorigin;
   1421       1.26  macallan 		ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
   1422       1.26  macallan 		yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
   1423       1.26  macallan 		width = ri->ri_emuwidth;
   1424       1.26  macallan 		height = ri->ri_font->fontheight*nrows;
   1425       1.26  macallan 		mach64_bitblt(sc, x, ys, x, yd, width, height, MIX_SRC, 0xff);
   1426       1.24  macallan 	}
   1427       1.21    martin }
   1428       1.19    martin 
   1429       1.30   thorpej static void
   1430       1.21    martin mach64_eraserows(void *cookie, int row, int nrows, long fillattr)
   1431       1.21    martin {
   1432  1.38.10.1      elad 	struct rasops_info *ri = cookie;
   1433  1.38.10.1      elad 	struct vcons_screen *scr = ri->ri_hw;
   1434  1.38.10.1      elad 	struct mach64_softc *sc = scr->scr_cookie;
   1435       1.34  macallan 	int32_t x, y, width, height, fg, bg, ul;
   1436       1.26  macallan 
   1437  1.38.10.1      elad 	if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
   1438       1.26  macallan 		x = ri->ri_xorigin;
   1439       1.26  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1440       1.26  macallan 		width = ri->ri_emuwidth;
   1441       1.26  macallan 		height = ri->ri_font->fontheight * nrows;
   1442       1.26  macallan 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
   1443       1.22     perry 
   1444       1.26  macallan 		mach64_rectfill(sc, x, y, width, height, bg);
   1445       1.21    martin 	}
   1446       1.21    martin }
   1447       1.21    martin 
   1448       1.30   thorpej static void
   1449       1.22     perry mach64_bitblt(struct mach64_softc *sc, int xs, int ys, int xd, int yd, int width, int height, int rop, int mask)
   1450       1.19    martin {
   1451       1.26  macallan 	uint32_t dest_ctl = 0;
   1452       1.26  macallan 
   1453       1.22     perry 	wait_for_idle(sc);
   1454       1.26  macallan 	regw(sc, DP_WRITE_MASK, mask);	/* XXX only good for 8 bit */
   1455       1.26  macallan 	regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_8BPP | HOST_8BPP);
   1456       1.26  macallan 	regw(sc, DP_SRC, FRGD_SRC_BLIT);
   1457       1.26  macallan 	regw(sc, DP_MIX, (rop & 0xffff) << 16);
   1458       1.26  macallan 	regw(sc, CLR_CMP_CNTL, 0);	/* no transparency */
   1459       1.26  macallan 	if (yd < ys) {
   1460       1.26  macallan 		dest_ctl = DST_Y_TOP_TO_BOTTOM;
   1461       1.19    martin 	} else {
   1462       1.26  macallan 		ys += height - 1;
   1463       1.26  macallan 		yd += height - 1;
   1464       1.26  macallan 		dest_ctl = DST_Y_BOTTOM_TO_TOP;
   1465       1.26  macallan 	}
   1466       1.26  macallan 	if (xd < xs) {
   1467       1.26  macallan 		dest_ctl |= DST_X_LEFT_TO_RIGHT;
   1468       1.26  macallan 		regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
   1469       1.19    martin 	} else {
   1470       1.26  macallan 		dest_ctl |= DST_X_RIGHT_TO_LEFT;
   1471       1.26  macallan 		xs += width - 1;
   1472       1.26  macallan 		xd += width - 1;
   1473       1.26  macallan 		regw(sc, SRC_CNTL, SRC_LINE_X_RIGHT_TO_LEFT);
   1474       1.26  macallan 	}
   1475       1.26  macallan 	regw(sc, DST_CNTL, dest_ctl);
   1476       1.26  macallan 
   1477       1.26  macallan 	regw(sc, SRC_Y_X, (xs << 16) | ys);
   1478       1.26  macallan 	regw(sc, SRC_WIDTH1, width);
   1479       1.26  macallan 	regw(sc, DST_Y_X, (xd << 16) | yd);
   1480       1.26  macallan 	regw(sc, DST_HEIGHT_WIDTH, (width << 16) | height);
   1481       1.19    martin }
   1482       1.22     perry 
   1483       1.30   thorpej static void
   1484       1.25  macallan mach64_setup_mono(struct mach64_softc *sc, int xd, int yd, int width,
   1485       1.25  macallan      int height, uint32_t fg, uint32_t bg)
   1486       1.21    martin {
   1487       1.22     perry 	wait_for_idle(sc);
   1488       1.26  macallan 	regw(sc, DP_WRITE_MASK, 0xff);	/* XXX only good for 8 bit */
   1489       1.26  macallan 	regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_1BPP | HOST_1BPP);
   1490       1.26  macallan 	regw(sc, DP_SRC, MONO_SRC_HOST | BKGD_SRC_BKGD_CLR | FRGD_SRC_FRGD_CLR);
   1491       1.26  macallan 	regw(sc, DP_MIX, ((MIX_SRC & 0xffff) << 16) | MIX_SRC);
   1492       1.26  macallan 	regw(sc, CLR_CMP_CNTL ,0);	/* no transparency */
   1493       1.26  macallan 	regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
   1494       1.26  macallan 	regw(sc, DST_CNTL, DST_Y_TOP_TO_BOTTOM | DST_X_LEFT_TO_RIGHT);
   1495       1.26  macallan 	regw(sc, HOST_CNTL, HOST_BYTE_ALIGN);
   1496       1.26  macallan 	regw(sc, DP_BKGD_CLR, bg);
   1497       1.26  macallan 	regw(sc, DP_FRGD_CLR, fg);
   1498       1.26  macallan 	regw(sc, SRC_Y_X, 0);
   1499       1.26  macallan 	regw(sc, SRC_WIDTH1, width);
   1500       1.26  macallan 	regw(sc, DST_Y_X, (xd << 16) | yd);
   1501       1.26  macallan 	regw(sc, DST_HEIGHT_WIDTH, (width << 16) | height);
   1502       1.21    martin 	/* now feed the data into the chip */
   1503       1.21    martin }
   1504       1.21    martin 
   1505       1.30   thorpej static void
   1506       1.21    martin mach64_feed_bytes(struct mach64_softc *sc, int count, uint8_t *data)
   1507       1.21    martin {
   1508       1.21    martin 	int i;
   1509       1.26  macallan 	uint32_t latch = 0, bork;
   1510       1.26  macallan 	int shift = 0;
   1511       1.26  macallan 	int reg = 0;
   1512       1.26  macallan 
   1513       1.26  macallan 	for (i=0;i<count;i++) {
   1514       1.26  macallan 		bork = data[i];
   1515       1.26  macallan 		latch |= (bork << shift);
   1516       1.26  macallan 		if (shift == 24) {
   1517       1.26  macallan 			regw(sc, HOST_DATA0 + reg, latch);
   1518       1.26  macallan 			latch = 0;
   1519       1.26  macallan 			shift = 0;
   1520       1.26  macallan 			reg = (reg + 4) & 0x3c;
   1521       1.21    martin 		} else
   1522       1.26  macallan 			shift += 8;
   1523       1.21    martin 	}
   1524       1.26  macallan 	if (shift != 0)	/* 24 */
   1525       1.26  macallan 		regw(sc, HOST_DATA0 + reg, latch);
   1526       1.22     perry }
   1527       1.21    martin 
   1528       1.22     perry 
   1529       1.30   thorpej static void
   1530       1.25  macallan mach64_rectfill(struct mach64_softc *sc, int x, int y, int width, int height,
   1531       1.25  macallan     int colour)
   1532       1.19    martin {
   1533       1.22     perry 	wait_for_idle(sc);
   1534       1.26  macallan 	regw(sc, DP_WRITE_MASK, 0xff);
   1535       1.26  macallan 	regw(sc, DP_FRGD_CLR, colour);
   1536       1.26  macallan 	regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_8BPP | HOST_8BPP);
   1537       1.26  macallan 	regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR);
   1538       1.26  macallan 	regw(sc, DP_MIX, MIX_SRC << 16);
   1539       1.26  macallan 	regw(sc, CLR_CMP_CNTL, 0);	/* no transparency */
   1540       1.26  macallan 	regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
   1541       1.26  macallan 	regw(sc, DST_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
   1542       1.26  macallan 
   1543       1.26  macallan 	regw(sc, SRC_Y_X, (x << 16) | y);
   1544       1.26  macallan 	regw(sc, SRC_WIDTH1, width);
   1545       1.26  macallan 	regw(sc, DST_Y_X, (x << 16) | y);
   1546       1.26  macallan 	regw(sc, DST_HEIGHT_WIDTH, (width << 16) | height);
   1547       1.19    martin }
   1548        1.1  junyoung 
   1549       1.30   thorpej static void
   1550       1.21    martin mach64_clearscreen(struct mach64_softc *sc)
   1551       1.21    martin {
   1552       1.26  macallan 	mach64_rectfill(sc, 0, 0, sc->virt_x, sc->virt_y, sc->sc_bg);
   1553       1.21    martin }
   1554       1.21    martin 
   1555       1.21    martin 
   1556       1.30   thorpej #if 0
   1557       1.30   thorpej static void
   1558       1.22     perry mach64_showpal(struct mach64_softc *sc)
   1559       1.19    martin {
   1560       1.26  macallan 	int i, x = 0;
   1561       1.26  macallan 
   1562       1.26  macallan 	for (i = 0; i < 16; i++) {
   1563       1.26  macallan 		mach64_rectfill(sc, x, 0, 64, 64, i);
   1564       1.26  macallan 		x += 64;
   1565       1.19    martin 	}
   1566        1.1  junyoung }
   1567       1.30   thorpej #endif
   1568       1.22     perry 
   1569       1.30   thorpej static int
   1570        1.7    martin mach64_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
   1571        1.1  junyoung {
   1572       1.26  macallan 	if ((fg == 0) && (bg == 0))
   1573       1.24  macallan 	{
   1574       1.26  macallan 		fg = WS_DEFAULT_FG;
   1575       1.26  macallan 		bg = WS_DEFAULT_BG;
   1576       1.21    martin 	}
   1577       1.26  macallan 	*attrp = (fg & 0xf) << 24 | (bg & 0xf) << 16 | (flags & 0xff) << 8;
   1578        1.7    martin 	return 0;
   1579        1.1  junyoung }
   1580        1.1  junyoung 
   1581        1.1  junyoung /*
   1582        1.1  junyoung  * wsdisplay_accessops
   1583        1.1  junyoung  */
   1584        1.1  junyoung 
   1585       1.30   thorpej static int
   1586  1.38.10.1      elad mach64_ioctl(void *v, void *vs, u_long cmd, caddr_t data, int flag,
   1587  1.38.10.1      elad 	struct lwp *l)
   1588        1.1  junyoung {
   1589  1.38.10.1      elad 	struct vcons_data *vd = v;
   1590  1.38.10.1      elad 	struct mach64_softc *sc = vd->cookie;
   1591       1.19    martin 	struct wsdisplay_fbinfo *wdf;
   1592  1.38.10.1      elad 	struct vcons_screen *ms = vd->active;
   1593       1.26  macallan 
   1594       1.19    martin 	switch (cmd) {
   1595       1.19    martin 		case WSDISPLAYIO_GTYPE:
   1596       1.25  macallan 			/* XXX is this the right type to return? */
   1597       1.25  macallan 			*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
   1598       1.19    martin 			return 0;
   1599       1.19    martin 
   1600       1.19    martin 		case WSDISPLAYIO_GINFO:
   1601       1.19    martin 			wdf = (void *)data;
   1602  1.38.10.1      elad 			wdf->height = sc->virt_y;
   1603  1.38.10.1      elad 			wdf->width = sc->virt_x;
   1604  1.38.10.1      elad 			wdf->depth = sc->color_depth;
   1605       1.19    martin 			wdf->cmsize = 256;
   1606       1.19    martin 			return 0;
   1607       1.26  macallan 
   1608       1.19    martin 		case WSDISPLAYIO_GETCMAP:
   1609       1.25  macallan 			return mach64_getcmap(sc,
   1610       1.25  macallan 			    (struct wsdisplay_cmap *)data);
   1611       1.19    martin 
   1612       1.19    martin 		case WSDISPLAYIO_PUTCMAP:
   1613       1.25  macallan 			return mach64_putcmap(sc,
   1614       1.25  macallan 			    (struct wsdisplay_cmap *)data);
   1615       1.26  macallan 
   1616       1.19    martin 		/* PCI config read/write passthrough. */
   1617       1.19    martin 		case PCI_IOC_CFGREAD:
   1618       1.19    martin 		case PCI_IOC_CFGWRITE:
   1619       1.19    martin 			return (pci_devioctl(sc->sc_pc, sc->sc_pcitag,
   1620       1.37  christos 			    cmd, data, flag, l));
   1621       1.26  macallan 
   1622       1.19    martin 		case WSDISPLAYIO_SMODE:
   1623       1.19    martin 			{
   1624       1.26  macallan 				int new_mode = *(int*)data;
   1625       1.26  macallan 
   1626       1.26  macallan 				if (new_mode != sc->sc_mode)
   1627       1.19    martin 				{
   1628       1.26  macallan 					sc->sc_mode = new_mode;
   1629  1.38.10.1      elad 					if ((new_mode == WSDISPLAYIO_MODE_EMUL)
   1630  1.38.10.1      elad 					    && (ms != NULL))
   1631       1.19    martin 					{
   1632  1.38.10.1      elad 						vcons_redraw_screen(ms);
   1633       1.19    martin 					}
   1634       1.19    martin 				}
   1635       1.19    martin 			}
   1636       1.21    martin 			return 0;
   1637       1.26  macallan 
   1638       1.19    martin 	}
   1639       1.19    martin 	return EPASSTHROUGH;
   1640        1.1  junyoung }
   1641        1.1  junyoung 
   1642       1.30   thorpej static paddr_t
   1643  1.38.10.1      elad mach64_mmap(void *v, void *vs, off_t offset, int prot)
   1644        1.1  junyoung {
   1645  1.38.10.1      elad 	struct vcons_data *vd = v;
   1646  1.38.10.1      elad 	struct mach64_softc *sc = vd->cookie;
   1647       1.19    martin 	paddr_t pa;
   1648       1.33  macallan 	pcireg_t reg;
   1649       1.26  macallan 
   1650       1.32  macallan #ifndef __sparc64__
   1651       1.31  macallan 	/*
   1652       1.31  macallan 	 *'regular' framebuffer mmap()ing
   1653       1.31  macallan 	 * disabled on sparc64 because some ATI firmware likes to map some PCI
   1654       1.31  macallan 	 * resources to addresses that would collide with this ( like some Rage
   1655       1.31  macallan 	 * IIc which uses 0x2000 for the 2nd register block )
   1656       1.31  macallan 	 * Other 64bit architectures might run into similar problems.
   1657       1.31  macallan 	 */
   1658       1.26  macallan 	if (offset<sc->sc_apersize) {
   1659  1.38.10.2      elad 		pa = bus_space_mmap(sc->sc_memt, sc->sc_aperbase, offset,
   1660       1.25  macallan 		    prot, BUS_SPACE_MAP_LINEAR);
   1661       1.19    martin 		return pa;
   1662       1.19    martin 	}
   1663       1.31  macallan #endif
   1664       1.33  macallan 	reg = (pci_conf_read(sc->sc_pc, sc->sc_pcitag, 0x18) & 0xffffff00);
   1665       1.33  macallan 	if (reg != sc->sc_regphys) {
   1666  1.38.10.1      elad #ifdef DIAGNOSTIC
   1667       1.33  macallan 		printf("%s: BAR 0x18 changed! (%x %x)\n",
   1668       1.33  macallan 		    sc->sc_dev.dv_xname, (uint32_t)sc->sc_regphys,
   1669       1.33  macallan 		    (uint32_t)reg);
   1670  1.38.10.1      elad #endif
   1671       1.33  macallan 		sc->sc_regphys = reg;
   1672       1.33  macallan 	}
   1673       1.33  macallan 
   1674       1.33  macallan 	reg = (pci_conf_read(sc->sc_pc, sc->sc_pcitag, 0x10) & 0xffffff00);
   1675       1.33  macallan 	if (reg != sc->sc_aperphys) {
   1676  1.38.10.1      elad #ifdef DIAGNOSTIC
   1677       1.33  macallan 		printf("%s: BAR 0x10 changed! (%x %x)\n",
   1678       1.33  macallan 		    sc->sc_dev.dv_xname, (uint32_t)sc->sc_aperphys,
   1679       1.33  macallan 		    (uint32_t)reg);
   1680  1.38.10.1      elad #endif
   1681       1.33  macallan 		sc->sc_aperphys = reg;
   1682       1.33  macallan 	}
   1683       1.31  macallan 
   1684       1.22     perry #if 0
   1685       1.25  macallan 	/* evil hack to allow mmap()ing other devices as well */
   1686       1.26  macallan 	if ((offset > 0x80000000) && (offset <= 0xffffffff)) {
   1687       1.25  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
   1688       1.25  macallan 		    BUS_SPACE_MAP_LINEAR);
   1689       1.19    martin 		return pa;
   1690       1.19    martin 	}
   1691       1.22     perry #endif
   1692       1.20    martin 
   1693       1.26  macallan 	if ((offset >= sc->sc_aperphys) &&
   1694       1.26  macallan 	    (offset < (sc->sc_aperphys + sc->sc_apersize))) {
   1695       1.25  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
   1696       1.25  macallan 		    BUS_SPACE_MAP_LINEAR);
   1697       1.20    martin 		return pa;
   1698       1.20    martin 	}
   1699       1.20    martin 
   1700       1.26  macallan 	if ((offset >= sc->sc_regphys) &&
   1701       1.26  macallan 	    (offset < (sc->sc_regphys + sc->sc_regsize))) {
   1702       1.25  macallan 		pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
   1703       1.25  macallan 		    BUS_SPACE_MAP_LINEAR);
   1704       1.20    martin 		return pa;
   1705       1.20    martin 	}
   1706       1.20    martin 
   1707        1.1  junyoung 	return -1;
   1708        1.1  junyoung }
   1709        1.1  junyoung 
   1710  1.38.10.1      elad /* set ri->ri_bits according to fb, ri_xorigin and ri_yorigin */
   1711  1.38.10.1      elad static void
   1712  1.38.10.2      elad set_address(struct rasops_info *ri, caddr_t fb)
   1713        1.1  junyoung {
   1714       1.28  christos #ifdef notdef
   1715  1.38.10.1      elad 	printf(" %d %d %d\n", ri->ri_xorigin, ri->ri_yorigin, ri->ri_stride);
   1716       1.28  christos #endif
   1717  1.38.10.2      elad 	ri->ri_bits = (void *)(fb + ri->ri_stride * ri->ri_yorigin +
   1718  1.38.10.1      elad 	    ri->ri_xorigin);
   1719        1.1  junyoung }
   1720        1.1  junyoung 
   1721       1.34  macallan #if 0
   1722       1.30   thorpej static int
   1723  1.38.10.1      elad mach64_load_font(void *v, void *cookie, struct wsdisplay_font *data)
   1724        1.1  junyoung {
   1725        1.1  junyoung 
   1726        1.1  junyoung 	return 0;
   1727        1.1  junyoung }
   1728       1.21    martin #endif
   1729       1.21    martin 
   1730  1.38.10.1      elad void
   1731  1.38.10.1      elad machfb_blank(struct mach64_softc *sc, int blank)
   1732  1.38.10.1      elad {
   1733  1.38.10.1      elad 	uint32_t reg;
   1734       1.21    martin 
   1735  1.38.10.1      elad #define MACH64_BLANK (CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS | CRTC_VSYNC_DIS)
   1736       1.21    martin 
   1737  1.38.10.1      elad 	switch (blank)
   1738  1.38.10.1      elad 	{
   1739  1.38.10.1      elad     		case 0:
   1740  1.38.10.1      elad 			reg = regr(sc, CRTC_GEN_CNTL);
   1741  1.38.10.1      elad 			regw(sc, CRTC_GEN_CNTL, reg & ~(MACH64_BLANK));
   1742  1.38.10.1      elad 			sc->sc_blanked = 0;
   1743  1.38.10.1      elad 			break;
   1744  1.38.10.1      elad 		case 1:
   1745  1.38.10.1      elad 			reg = regr(sc, CRTC_GEN_CNTL);
   1746  1.38.10.1      elad 			regw(sc, CRTC_GEN_CNTL, reg | (MACH64_BLANK));
   1747  1.38.10.1      elad 			sc->sc_blanked = 1;
   1748  1.38.10.1      elad 			break;
   1749  1.38.10.1      elad 		default:
   1750  1.38.10.1      elad         		break;
   1751       1.21    martin 	}
   1752  1.38.10.1      elad }
   1753       1.21    martin 
   1754  1.38.10.1      elad /* framebuffer device support */
   1755  1.38.10.1      elad #ifdef __sparc__
   1756       1.21    martin 
   1757  1.38.10.1      elad static void
   1758  1.38.10.1      elad machfb_unblank(struct device *dev)
   1759  1.38.10.1      elad {
   1760  1.38.10.1      elad 	struct mach64_softc *sc = (struct mach64_softc *)dev;
   1761  1.38.10.1      elad 
   1762  1.38.10.1      elad 	machfb_blank(sc, 0);
   1763       1.21    martin }
   1764       1.21    martin 
   1765       1.30   thorpej static void
   1766  1.38.10.1      elad machfb_fbattach(struct mach64_softc *sc)
   1767       1.21    martin {
   1768  1.38.10.1      elad 	struct fbdevice *fb = &sc->sc_fb;
   1769       1.26  macallan 
   1770  1.38.10.1      elad 	fb->fb_device = &sc->sc_dev;
   1771  1.38.10.1      elad 	fb->fb_driver = &machfb_fbdriver;
   1772  1.38.10.1      elad 
   1773  1.38.10.1      elad 	fb->fb_type.fb_cmsize = 256;
   1774  1.38.10.1      elad 	fb->fb_type.fb_size = sc->memsize;
   1775  1.38.10.1      elad 
   1776  1.38.10.1      elad 	fb->fb_type.fb_type = FBTYPE_GENERIC_PCI;
   1777  1.38.10.1      elad 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
   1778  1.38.10.1      elad 	fb->fb_type.fb_depth = sc->bits_per_pixel;
   1779  1.38.10.1      elad 	fb->fb_type.fb_width = sc->virt_x;
   1780  1.38.10.1      elad 	fb->fb_type.fb_height = sc->virt_y;
   1781  1.38.10.1      elad 
   1782  1.38.10.2      elad 	fb->fb_pixels = sc->sc_aperture;
   1783  1.38.10.1      elad 	fb_attach(fb, sc->sc_console);
   1784       1.21    martin }
   1785       1.21    martin 
   1786  1.38.10.1      elad int
   1787  1.38.10.1      elad machfb_fbopen(dev_t dev, int flags, int mode, struct lwp *l)
   1788       1.21    martin {
   1789  1.38.10.1      elad 	struct mach64_softc *sc;
   1790  1.38.10.1      elad 	int unit = minor(dev);
   1791  1.38.10.1      elad 
   1792  1.38.10.1      elad 	sc = machfb_cd.cd_devs[unit];
   1793  1.38.10.1      elad 	sc->sc_locked = 1;
   1794  1.38.10.1      elad 
   1795  1.38.10.1      elad #ifdef DEBUG_MACHFB
   1796  1.38.10.1      elad 	printf("machfb_fbopen(%d)\n", unit);
   1797       1.28  christos #endif
   1798  1.38.10.1      elad 	if (unit > machfb_cd.cd_ndevs || machfb_cd.cd_devs[unit] == NULL)
   1799  1.38.10.1      elad 		return ENXIO;
   1800  1.38.10.1      elad 	return 0;
   1801       1.21    martin }
   1802       1.21    martin 
   1803  1.38.10.1      elad int
   1804  1.38.10.1      elad machfb_fbclose(dev_t dev, int flags, int mode, struct lwp *l)
   1805       1.21    martin {
   1806  1.38.10.1      elad 	struct mach64_softc *sc = machfb_cd.cd_devs[minor(dev)];
   1807       1.26  macallan 
   1808  1.38.10.1      elad #ifdef DEBUG_MACHFB
   1809  1.38.10.1      elad 	printf("machfb_fbclose()\n");
   1810  1.38.10.1      elad #endif
   1811  1.38.10.1      elad 	mach64_init_engine(sc);
   1812  1.38.10.1      elad 	mach64_init_lut(sc);
   1813  1.38.10.1      elad 	sc->sc_locked = 0;
   1814  1.38.10.1      elad 	return 0;
   1815       1.21    martin }
   1816       1.21    martin 
   1817  1.38.10.1      elad int
   1818  1.38.10.1      elad machfb_fbioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct lwp *l)
   1819       1.21    martin {
   1820  1.38.10.1      elad 	struct mach64_softc *sc = machfb_cd.cd_devs[minor(dev)];
   1821       1.21    martin 
   1822  1.38.10.1      elad #ifdef DEBUG_MACHFB
   1823  1.38.10.1      elad 	printf("machfb_fbioctl(%d, %lx)\n", minor(dev), cmd);
   1824  1.38.10.1      elad #endif
   1825  1.38.10.1      elad 	switch (cmd) {
   1826  1.38.10.1      elad 		case FBIOGTYPE:
   1827  1.38.10.1      elad 			*(struct fbtype *)data = sc->sc_fb.fb_type;
   1828  1.38.10.1      elad 			break;
   1829        1.1  junyoung 
   1830  1.38.10.1      elad 		case FBIOGATTR:
   1831  1.38.10.1      elad #define fba ((struct fbgattr *)data)
   1832  1.38.10.1      elad 			fba->real_type = sc->sc_fb.fb_type.fb_type;
   1833  1.38.10.1      elad 			fba->owner = 0;		/* XXX ??? */
   1834  1.38.10.1      elad 			fba->fbtype = sc->sc_fb.fb_type;
   1835  1.38.10.1      elad 			fba->sattr.flags = 0;
   1836  1.38.10.1      elad 			fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
   1837  1.38.10.1      elad 			fba->sattr.dev_specific[0] = sc->sc_nbus;
   1838  1.38.10.1      elad 			fba->sattr.dev_specific[1] = sc->sc_ndev;
   1839  1.38.10.1      elad 			fba->sattr.dev_specific[2] = sc->sc_nfunc;
   1840  1.38.10.1      elad 			fba->sattr.dev_specific[3] = -1;
   1841  1.38.10.1      elad 			fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
   1842  1.38.10.1      elad 			fba->emu_types[1] = -1;
   1843  1.38.10.1      elad #undef fba
   1844  1.38.10.1      elad 			break;
   1845  1.38.10.1      elad 
   1846  1.38.10.1      elad #if 0
   1847  1.38.10.1      elad 		case FBIOGETCMAP:
   1848  1.38.10.1      elad #define	p ((struct fbcmap *)data)
   1849  1.38.10.1      elad 			return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
   1850  1.38.10.1      elad 
   1851  1.38.10.1      elad 		case FBIOPUTCMAP:
   1852  1.38.10.1      elad 			/* copy to software map */
   1853  1.38.10.1      elad 			error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
   1854  1.38.10.1      elad 			if (error)
   1855  1.38.10.1      elad 				return error;
   1856  1.38.10.1      elad 			/* now blast them into the chip */
   1857  1.38.10.1      elad 			/* XXX should use retrace interrupt */
   1858  1.38.10.1      elad 			cg6_loadcmap(sc, p->index, p->count);
   1859  1.38.10.1      elad #undef p
   1860  1.38.10.1      elad 			break;
   1861        1.7    martin #endif
   1862  1.38.10.1      elad 		case FBIOGVIDEO:
   1863  1.38.10.1      elad 			*(int *)data = sc->sc_blanked;
   1864  1.38.10.1      elad 			break;
   1865       1.34  macallan 
   1866  1.38.10.1      elad 		case FBIOSVIDEO:
   1867  1.38.10.1      elad 			machfb_blank(sc, *(int *)data);
   1868  1.38.10.1      elad 			break;
   1869       1.34  macallan 
   1870  1.38.10.1      elad #if 0
   1871  1.38.10.1      elad 		case FBIOGCURSOR:
   1872  1.38.10.1      elad 			break;
   1873  1.38.10.1      elad 
   1874  1.38.10.1      elad 		case FBIOSCURSOR:
   1875  1.38.10.1      elad 			break;
   1876       1.34  macallan 
   1877  1.38.10.1      elad 		case FBIOGCURPOS:
   1878  1.38.10.1      elad 			*(struct fbcurpos *)data = sc->sc_cursor.cc_pos;
   1879       1.34  macallan 			break;
   1880  1.38.10.1      elad 
   1881  1.38.10.1      elad 		case FBIOSCURPOS:
   1882  1.38.10.1      elad 			sc->sc_cursor.cc_pos = *(struct fbcurpos *)data;
   1883       1.34  macallan 			break;
   1884  1.38.10.1      elad 
   1885  1.38.10.1      elad 		case FBIOGCURMAX:
   1886  1.38.10.1      elad 			/* max cursor size is 32x32 */
   1887  1.38.10.1      elad 			((struct fbcurpos *)data)->x = 32;
   1888  1.38.10.1      elad 			((struct fbcurpos *)data)->y = 32;
   1889  1.38.10.1      elad 			break;
   1890  1.38.10.1      elad #endif
   1891  1.38.10.1      elad 		case PCI_IOC_CFGREAD:
   1892  1.38.10.1      elad 		case PCI_IOC_CFGWRITE:
   1893  1.38.10.1      elad 		{
   1894  1.38.10.1      elad 			int ret;
   1895  1.38.10.1      elad 
   1896  1.38.10.1      elad 			ret = pci_devioctl(sc->sc_pc, sc->sc_pcitag,
   1897  1.38.10.1      elad 			    cmd, data, flags, l);
   1898  1.38.10.1      elad 
   1899  1.38.10.1      elad #ifdef DEBUG_MACHFB
   1900  1.38.10.1      elad 			printf("pci_devioctl: %d\n", ret);
   1901  1.38.10.1      elad #endif
   1902  1.38.10.1      elad 			return ret;
   1903  1.38.10.1      elad 		}
   1904       1.34  macallan 		default:
   1905  1.38.10.1      elad #ifdef DEBUG_MACHFB
   1906  1.38.10.1      elad 			log(LOG_NOTICE, "machfb_fbioctl(0x%lx) (%s[%d])\n", cmd,
   1907  1.38.10.1      elad 			    p->p_comm, p->p_pid);
   1908  1.38.10.1      elad #endif
   1909  1.38.10.1      elad 			return ENOTTY;
   1910       1.34  macallan 	}
   1911  1.38.10.1      elad #ifdef DEBUG_MACHFB
   1912  1.38.10.1      elad 	printf("machfb_fbioctl done\n");
   1913  1.38.10.1      elad #endif
   1914  1.38.10.1      elad 	return 0;
   1915       1.34  macallan }
   1916  1.38.10.1      elad 
   1917  1.38.10.1      elad paddr_t
   1918  1.38.10.1      elad machfb_fbmmap(dev_t dev, off_t off, int prot)
   1919  1.38.10.1      elad {
   1920  1.38.10.1      elad 	struct mach64_softc *sc = machfb_cd.cd_devs[minor(dev)];
   1921  1.38.10.1      elad 
   1922  1.38.10.1      elad 	if (sc != NULL)
   1923  1.38.10.1      elad 		return mach64_mmap(&sc->vd, NULL, off, prot);
   1924  1.38.10.1      elad 
   1925  1.38.10.1      elad 	return 0;
   1926  1.38.10.1      elad }
   1927  1.38.10.1      elad 
   1928  1.38.10.1      elad #endif /* __sparc__ */
   1929