Home | History | Annotate | Line # | Download | only in dev
sti_sgc.c revision 1.2.34.2
      1  1.2.34.2   martin /*	$NetBSD: sti_sgc.c,v 1.2.34.2 2020/12/28 20:10:04 martin Exp $	*/
      2       1.1  tsutsui /*	$OpenBSD: sti_sgc.c,v 1.14 2007/05/26 00:36:03 krw Exp $	*/
      3       1.1  tsutsui 
      4       1.1  tsutsui /*
      5       1.1  tsutsui  * Copyright (c) 2005, Miodrag Vallat
      6       1.1  tsutsui  *
      7       1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
      8       1.1  tsutsui  * modification, are permitted provided that the following conditions
      9       1.1  tsutsui  * are met:
     10       1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     11       1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     12       1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     14       1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     15       1.1  tsutsui  *
     16       1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17       1.1  tsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18       1.1  tsutsui  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     19       1.1  tsutsui  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     20       1.1  tsutsui  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21       1.1  tsutsui  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22       1.1  tsutsui  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23       1.1  tsutsui  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     24       1.1  tsutsui  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     25       1.1  tsutsui  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26       1.1  tsutsui  * POSSIBILITY OF SUCH DAMAGE.
     27       1.1  tsutsui  *
     28       1.1  tsutsui  */
     29       1.1  tsutsui #include <sys/cdefs.h>
     30  1.2.34.2   martin __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.2.34.2 2020/12/28 20:10:04 martin Exp $");
     31       1.1  tsutsui 
     32       1.1  tsutsui #include <sys/param.h>
     33       1.1  tsutsui #include <sys/device.h>
     34       1.1  tsutsui #include <sys/bus.h>
     35       1.1  tsutsui 
     36       1.1  tsutsui #include <uvm/uvm_extern.h>
     37       1.1  tsutsui 
     38  1.2.34.1   martin #include <dev/wscons/wsconsio.h>
     39       1.1  tsutsui #include <dev/wscons/wsdisplayvar.h>
     40       1.1  tsutsui 
     41       1.1  tsutsui #include <dev/ic/stireg.h>
     42       1.1  tsutsui #include <dev/ic/stivar.h>
     43       1.1  tsutsui 
     44       1.1  tsutsui #include <hp300/dev/sgcvar.h>
     45       1.2  tsutsui #include <hp300/dev/sti_sgcvar.h>
     46       1.2  tsutsui #include <machine/autoconf.h>
     47       1.1  tsutsui 
     48  1.2.34.1   martin struct sti_sgc_softc {
     49  1.2.34.1   martin 	struct sti_softc sc_sti;
     50  1.2.34.1   martin 
     51  1.2.34.1   martin 	paddr_t sc_bitmap;
     52  1.2.34.1   martin };
     53  1.2.34.1   martin 
     54  1.2.34.1   martin /*
     55  1.2.34.1   martin  * 425e EVRX specific hardware
     56  1.2.34.1   martin  */
     57  1.2.34.2   martin /*
     58  1.2.34.2   martin  * EVRX RAMDAC (Bt458) is found at offset 0x060000 from SGC bus PA and
     59  1.2.34.2   martin  * offset 0x040000 length 0x1c0000 is mapped in MI sti via ROM region 2
     60  1.2.34.2   martin  */
     61  1.2.34.2   martin #define STI_EVRX_REGNO2OFFSET	0x020000
     62  1.2.34.1   martin #define STI_EVRX_FBOFFSET	0x200000
     63  1.2.34.1   martin 
     64  1.2.34.2   martin #define EVRX_BT458_ADDR		(STI_EVRX_REGNO2OFFSET + 0x200 + 2)
     65  1.2.34.2   martin #define EVRX_BT458_CMAP		(STI_EVRX_REGNO2OFFSET + 0x204 + 2)
     66  1.2.34.2   martin #define EVRX_BT458_CTRL		(STI_EVRX_REGNO2OFFSET + 0x208 + 2)
     67  1.2.34.2   martin #define EVRX_BT458_OMAP		(STI_EVRX_REGNO2OFFSET + 0x20C + 2)
     68  1.2.34.1   martin 
     69  1.2.34.1   martin /* from HP-UX /usr/lib/libddevrx.a */
     70  1.2.34.2   martin #define EVRX_MAGIC00		(STI_EVRX_REGNO2OFFSET + 0x600)
     71  1.2.34.2   martin #define EVRX_MAGIC04		(STI_EVRX_REGNO2OFFSET + 0x604)
     72  1.2.34.2   martin #define EVRX_MAGIC08		(STI_EVRX_REGNO2OFFSET + 0x608)
     73  1.2.34.2   martin #define EVRX_MAGIC0C		(STI_EVRX_REGNO2OFFSET + 0x60c)
     74  1.2.34.2   martin #define EVRX_MAGIC10		(STI_EVRX_REGNO2OFFSET + 0x610)
     75  1.2.34.1   martin #define EVRX_MAGIC10_BSY	0x00010000
     76  1.2.34.2   martin #define EVRX_MAGIC18		(STI_EVRX_REGNO2OFFSET + 0x618)
     77  1.2.34.2   martin #define EVRX_MAGIC1C		(STI_EVRX_REGNO2OFFSET + 0x61c)
     78  1.2.34.2   martin 
     79  1.2.34.2   martin /*
     80  1.2.34.2   martin  * HP A1659A CRX specific hardware
     81  1.2.34.2   martin  */
     82  1.2.34.2   martin #define STI_CRX_FBOFFSET	0x01000000
     83  1.2.34.1   martin 
     84       1.2  tsutsui static int sticonslot = -1;
     85  1.2.34.2   martin static struct bus_space_tag sticn_tag;
     86       1.2  tsutsui static struct sti_rom sticn_rom;
     87       1.2  tsutsui static struct sti_screen sticn_scr;
     88       1.2  tsutsui static bus_addr_t sticn_bases[STI_REGION_MAX];
     89       1.1  tsutsui 
     90       1.1  tsutsui static int sti_sgc_match(device_t, struct cfdata *, void *);
     91       1.1  tsutsui static void sti_sgc_attach(device_t, device_t, void *);
     92       1.1  tsutsui 
     93       1.1  tsutsui static int sti_sgc_probe(bus_space_tag_t, int);
     94       1.1  tsutsui 
     95  1.2.34.1   martin CFATTACH_DECL_NEW(sti_sgc, sizeof(struct sti_sgc_softc),
     96       1.1  tsutsui     sti_sgc_match, sti_sgc_attach, NULL, NULL);
     97       1.1  tsutsui 
     98  1.2.34.2   martin /* 425e EVRX/CRX specific access functions */
     99  1.2.34.2   martin static int sti_evrx_putcmap(struct sti_screen *, u_int, u_int);
    100  1.2.34.2   martin static void sti_evrx_resetramdac(struct sti_screen *);
    101  1.2.34.2   martin static void sti_evrx_resetcmap(struct sti_screen *);
    102  1.2.34.2   martin static void sti_evrx_setupfb(struct sti_screen *);
    103  1.2.34.2   martin static paddr_t sti_m68k_mmap(void *, void *, off_t, int);
    104  1.2.34.2   martin 
    105  1.2.34.2   martin static const struct wsdisplay_accessops sti_m68k_accessops = {
    106  1.2.34.2   martin 	sti_ioctl,
    107  1.2.34.2   martin 	sti_m68k_mmap,
    108  1.2.34.1   martin 	sti_alloc_screen,
    109  1.2.34.1   martin 	sti_free_screen,
    110  1.2.34.1   martin 	sti_show_screen,
    111  1.2.34.1   martin 	sti_load_font
    112  1.2.34.1   martin };
    113  1.2.34.1   martin 
    114       1.1  tsutsui static int
    115       1.1  tsutsui sti_sgc_match(device_t parent, struct cfdata *cf, void *aux)
    116       1.1  tsutsui {
    117       1.1  tsutsui 	struct sgc_attach_args *saa = aux;
    118       1.1  tsutsui 
    119       1.1  tsutsui 	/*
    120       1.1  tsutsui 	 * If we already probed it successfully as a console device, go ahead,
    121       1.1  tsutsui 	 * since we will not be able to bus_space_map() again.
    122       1.1  tsutsui 	 */
    123       1.1  tsutsui 	if (saa->saa_slot == sticonslot)
    124       1.1  tsutsui 		return 1;
    125       1.1  tsutsui 
    126       1.1  tsutsui 	return sti_sgc_probe(saa->saa_iot, saa->saa_slot);
    127       1.1  tsutsui }
    128       1.1  tsutsui 
    129       1.1  tsutsui static void
    130       1.1  tsutsui sti_sgc_attach(device_t parent, device_t self, void *aux)
    131       1.1  tsutsui {
    132  1.2.34.1   martin 	struct sti_sgc_softc *sc = device_private(self);
    133  1.2.34.1   martin 	struct sti_softc *ssc = &sc->sc_sti;
    134       1.1  tsutsui 	struct sgc_attach_args *saa = aux;
    135  1.2.34.1   martin 	struct sti_screen *scr;
    136  1.2.34.2   martin 	bus_space_tag_t bst;
    137       1.2  tsutsui 	bus_space_handle_t romh;
    138       1.2  tsutsui 	bus_addr_t base;
    139  1.2.34.1   martin 	struct wsemuldisplaydev_attach_args waa;
    140       1.1  tsutsui 	u_int romend;
    141  1.2.34.1   martin 	struct sti_dd *rom_dd;
    142  1.2.34.1   martin 	uint32_t grid0;
    143       1.1  tsutsui 	int i;
    144       1.1  tsutsui 
    145  1.2.34.1   martin 	ssc->sc_dev = self;
    146  1.2.34.2   martin 	bst = saa->saa_iot;
    147  1.2.34.1   martin 	base = (bus_addr_t)sgc_slottopa(saa->saa_slot);
    148       1.2  tsutsui 
    149       1.2  tsutsui 	if (saa->saa_slot == sticonslot) {
    150  1.2.34.1   martin 		ssc->sc_flags |= STI_CONSOLE | STI_ATTACHED;
    151  1.2.34.1   martin 		ssc->sc_rom = &sticn_rom;
    152  1.2.34.1   martin 		ssc->sc_rom->rom_softc = ssc;
    153  1.2.34.1   martin 		ssc->sc_scr = &sticn_scr;
    154  1.2.34.1   martin 		ssc->sc_scr->scr_rom = ssc->sc_rom;
    155  1.2.34.1   martin 		memcpy(ssc->bases, sticn_bases, sizeof(ssc->bases));
    156       1.2  tsutsui 
    157  1.2.34.1   martin 		sti_describe(ssc);
    158       1.2  tsutsui 	} else {
    159  1.2.34.2   martin 		if (bus_space_map(bst, base, PAGE_SIZE, 0, &romh)) {
    160       1.2  tsutsui 			aprint_error(": can't map ROM");
    161       1.2  tsutsui 			return;
    162       1.2  tsutsui 		}
    163       1.2  tsutsui 		/*
    164       1.2  tsutsui 		 * Compute real PROM size
    165       1.2  tsutsui 		 */
    166  1.2.34.2   martin 		romend = sti_rom_size(bst, romh);
    167       1.2  tsutsui 
    168  1.2.34.2   martin 		bus_space_unmap(bst, romh, PAGE_SIZE);
    169       1.2  tsutsui 
    170  1.2.34.2   martin 		if (bus_space_map(bst, base, romend, 0, &romh)) {
    171       1.2  tsutsui 			aprint_error(": can't map frame buffer");
    172       1.2  tsutsui 			return;
    173       1.2  tsutsui 		}
    174       1.2  tsutsui 
    175  1.2.34.1   martin 		ssc->bases[0] = romh;
    176       1.2  tsutsui 		for (i = 0; i < STI_REGION_MAX; i++)
    177  1.2.34.1   martin 			ssc->bases[i] = base;
    178       1.2  tsutsui 
    179  1.2.34.2   martin 		if (sti_attach_common(ssc, bst, bst, romh,
    180       1.2  tsutsui 		    STI_CODEBASE_ALT) != 0)
    181       1.2  tsutsui 			return;
    182       1.1  tsutsui 	}
    183       1.1  tsutsui 
    184  1.2.34.1   martin 	/* Identify the board model by dd_grid */
    185  1.2.34.1   martin 	rom_dd = &ssc->sc_rom->rom_dd;
    186  1.2.34.1   martin 	grid0 = rom_dd->dd_grid[0];
    187  1.2.34.1   martin 	scr = ssc->sc_scr;
    188  1.2.34.1   martin 
    189  1.2.34.1   martin 	switch (grid0) {
    190  1.2.34.1   martin 	case STI_DD_EVRX:
    191  1.2.34.1   martin 		/*
    192  1.2.34.1   martin 		 * 425e on-board EVRX framebuffer.
    193  1.2.34.1   martin 		 * bitmap memory can be accessed at offset +0x200000.
    194  1.2.34.1   martin 		 */
    195  1.2.34.1   martin 		sc->sc_bitmap = base + STI_EVRX_FBOFFSET;
    196  1.2.34.1   martin 
    197  1.2.34.1   martin 		aprint_normal_dev(self, "Enable mmap support\n");
    198       1.1  tsutsui 
    199  1.2.34.1   martin 		/*
    200  1.2.34.1   martin 		 * initialize Bt458 RAMDAC and preserve initial color map
    201  1.2.34.1   martin 		 */
    202  1.2.34.2   martin 		sti_evrx_resetramdac(scr);
    203  1.2.34.2   martin 		sti_evrx_resetcmap(scr);
    204  1.2.34.2   martin 
    205  1.2.34.2   martin 		scr->setupfb = sti_evrx_setupfb;
    206  1.2.34.2   martin 		scr->putcmap = sti_evrx_putcmap;
    207  1.2.34.1   martin 
    208  1.2.34.1   martin 		scr->scr_wsmode = WSDISPLAYIO_MODE_EMUL;
    209  1.2.34.1   martin 		waa.console = ssc->sc_flags & STI_CONSOLE ? 1 : 0;
    210  1.2.34.1   martin 		waa.scrdata = &scr->scr_screenlist;
    211  1.2.34.2   martin 		waa.accessops = &sti_m68k_accessops;
    212  1.2.34.1   martin 		waa.accesscookie = scr;
    213  1.2.34.1   martin 
    214  1.2.34.1   martin 		config_found(ssc->sc_dev, &waa, wsemuldisplaydevprint);
    215  1.2.34.1   martin 		break;
    216  1.2.34.1   martin 
    217  1.2.34.1   martin 	case STI_DD_CRX:
    218  1.2.34.1   martin 		/*
    219  1.2.34.1   martin 		 * HP A1659A CRX on some 425t variants.
    220  1.2.34.2   martin 		 * bitmap memory can be accessed at offset +0x1000000.
    221  1.2.34.1   martin 		 */
    222  1.2.34.2   martin 		sc->sc_bitmap = base + STI_CRX_FBOFFSET;
    223  1.2.34.2   martin 
    224  1.2.34.2   martin 		aprint_normal_dev(self, "Enable mmap support\n");
    225  1.2.34.2   martin 
    226  1.2.34.2   martin 		scr->scr_wsmode = WSDISPLAYIO_MODE_EMUL;
    227  1.2.34.2   martin 		waa.console = ssc->sc_flags & STI_CONSOLE ? 1 : 0;
    228  1.2.34.2   martin 		waa.scrdata = &scr->scr_screenlist;
    229  1.2.34.2   martin 		waa.accessops = &sti_m68k_accessops;
    230  1.2.34.2   martin 		waa.accesscookie = scr;
    231  1.2.34.2   martin 
    232  1.2.34.2   martin 		config_found(ssc->sc_dev, &waa, wsemuldisplaydevprint);
    233  1.2.34.2   martin 		break;
    234  1.2.34.1   martin 	default:
    235  1.2.34.1   martin 		/*
    236  1.2.34.1   martin 		 * Unsupported variants.
    237  1.2.34.1   martin 		 * Use default common sti(4) attachment (no bitmap support).
    238  1.2.34.1   martin 		 */
    239  1.2.34.1   martin 		sti_end_attach(ssc);
    240  1.2.34.1   martin 		break;
    241  1.2.34.1   martin 	}
    242       1.1  tsutsui }
    243       1.1  tsutsui 
    244       1.1  tsutsui static int
    245       1.1  tsutsui sti_sgc_probe(bus_space_tag_t iot, int slot)
    246       1.1  tsutsui {
    247       1.1  tsutsui 	bus_space_handle_t ioh;
    248       1.1  tsutsui 	int devtype;
    249       1.1  tsutsui 
    250       1.2  tsutsui 	if (bus_space_map(iot, (bus_addr_t)sgc_slottopa(slot),
    251       1.2  tsutsui 	    PAGE_SIZE, 0, &ioh))
    252       1.1  tsutsui 		return 0;
    253       1.2  tsutsui 
    254       1.1  tsutsui 	devtype = bus_space_read_1(iot, ioh, 3);
    255       1.2  tsutsui 
    256       1.1  tsutsui 	bus_space_unmap(iot, ioh, PAGE_SIZE);
    257       1.1  tsutsui 
    258       1.1  tsutsui 	/*
    259       1.1  tsutsui 	 * This might not be reliable enough. On the other hand, non-STI
    260       1.1  tsutsui 	 * SGC cards will apparently not initialize in an hp300, to the
    261       1.1  tsutsui 	 * point of not even answering bus probes (checked with an
    262       1.1  tsutsui 	 * Harmony/FDDI SGC card).
    263       1.1  tsutsui 	 */
    264       1.2  tsutsui 	if (devtype != STI_DEVTYPE1 && devtype != STI_DEVTYPE4)
    265       1.1  tsutsui 		return 0;
    266       1.2  tsutsui 
    267       1.1  tsutsui 	return 1;
    268       1.1  tsutsui }
    269       1.1  tsutsui 
    270  1.2.34.1   martin static int
    271  1.2.34.2   martin sti_evrx_putcmap(struct sti_screen *scr, u_int index, u_int count)
    272  1.2.34.1   martin {
    273  1.2.34.2   martin 	struct sti_rom *rom = scr->scr_rom;
    274  1.2.34.2   martin 	bus_space_tag_t bst = rom->memt;
    275  1.2.34.2   martin 	bus_space_handle_t bsh = rom->regh[2];
    276  1.2.34.2   martin 	int i;
    277  1.2.34.1   martin 
    278  1.2.34.1   martin 	/* magic setup from HP-UX */
    279  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
    280  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
    281  1.2.34.1   martin 	for (i = index; i < index + count; i++) {
    282  1.2.34.1   martin 		/* this is what HP-UX woodDownloadCmap() does */
    283  1.2.34.1   martin 		while ((bus_space_read_4(bst, bsh, EVRX_MAGIC10) &
    284  1.2.34.1   martin 		    EVRX_MAGIC10_BSY) != 0)
    285  1.2.34.1   martin 			continue;
    286  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, i);
    287  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_CMAP, scr->scr_rcmap[i]);
    288  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_CMAP, scr->scr_gcmap[i]);
    289  1.2.34.1   martin 		bus_space_write_4(bst, bsh, EVRX_MAGIC10,   scr->scr_bcmap[i]);
    290  1.2.34.1   martin 	}
    291  1.2.34.1   martin 	return 0;
    292  1.2.34.1   martin }
    293  1.2.34.1   martin 
    294  1.2.34.1   martin static void
    295  1.2.34.2   martin sti_evrx_resetramdac(struct sti_screen *scr)
    296  1.2.34.1   martin {
    297  1.2.34.2   martin 	struct sti_rom *rom = scr->scr_rom;
    298  1.2.34.2   martin 	bus_space_tag_t bst = rom->memt;
    299  1.2.34.2   martin 	bus_space_handle_t bsh = rom->regh[2];
    300  1.2.34.1   martin #if 0
    301  1.2.34.1   martin 	int i;
    302  1.2.34.1   martin #endif
    303  1.2.34.1   martin 
    304  1.2.34.1   martin 	/*
    305  1.2.34.1   martin 	 * Initialize the Bt458.  When we write to control registers,
    306  1.2.34.1   martin 	 * the address is not incremented automatically. So we specify
    307  1.2.34.1   martin 	 * it ourselves for each control register.
    308  1.2.34.1   martin 	 */
    309  1.2.34.1   martin 
    310  1.2.34.1   martin 	/* all planes will be read */
    311  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x04);
    312  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0xff);
    313  1.2.34.1   martin 
    314  1.2.34.1   martin 	/* all planes have non-blink */
    315  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x05);
    316  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x00);
    317  1.2.34.1   martin 
    318  1.2.34.1   martin 	/* pallete enabled, ovly plane disabled */
    319  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x06);
    320  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x40);
    321  1.2.34.1   martin 
    322  1.2.34.1   martin 	/* no test mode */
    323  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x07);
    324  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x00);
    325  1.2.34.1   martin 
    326  1.2.34.1   martin 	/* magic initialization from HP-UX woodInitializeHardware() */
    327  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
    328  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC04, 0x00000001);
    329  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
    330  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC0C, 0x00000001);
    331  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC18, 0xFFFFFFFF);
    332  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC1C, 0x00000000);
    333  1.2.34.1   martin 
    334  1.2.34.1   martin #if 0
    335  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x00);
    336  1.2.34.1   martin 	for (i = 0; i < 4; i++) {
    337  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
    338  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
    339  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
    340  1.2.34.1   martin 	}
    341  1.2.34.1   martin #endif
    342  1.2.34.1   martin }
    343  1.2.34.1   martin 
    344  1.2.34.1   martin static void
    345  1.2.34.2   martin sti_evrx_resetcmap(struct sti_screen *scr)
    346  1.2.34.1   martin {
    347  1.2.34.2   martin 	struct sti_rom *rom = scr->scr_rom;
    348  1.2.34.2   martin 	bus_space_tag_t bst = rom->memt;
    349  1.2.34.2   martin 	bus_space_handle_t bsh = rom->regh[2];
    350  1.2.34.1   martin 	int i;
    351  1.2.34.1   martin 
    352  1.2.34.1   martin 	/* magic setup from HP-UX */
    353  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
    354  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
    355  1.2.34.1   martin 
    356  1.2.34.1   martin 	/* preserve palette values initialized by STI firmware */
    357  1.2.34.1   martin 	for (i = 0; i < STI_NCMAP; i++) {
    358  1.2.34.1   martin 		/* this is what HP-UX woodUploadCmap() does */
    359  1.2.34.1   martin 		while ((bus_space_read_4(bst, bsh, EVRX_MAGIC10) &
    360  1.2.34.1   martin 		    EVRX_MAGIC10_BSY) != 0)
    361  1.2.34.1   martin 			continue;
    362  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, i);
    363  1.2.34.1   martin 		scr->scr_rcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
    364  1.2.34.1   martin 		scr->scr_gcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
    365  1.2.34.1   martin 		scr->scr_bcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
    366  1.2.34.1   martin 	}
    367  1.2.34.1   martin }
    368  1.2.34.1   martin 
    369  1.2.34.2   martin static void
    370  1.2.34.2   martin sti_evrx_setupfb(struct sti_screen *scr)
    371  1.2.34.1   martin {
    372  1.2.34.1   martin 
    373  1.2.34.2   martin 	sti_init(scr, 0);
    374  1.2.34.2   martin 	sti_evrx_resetramdac(scr);
    375  1.2.34.1   martin }
    376  1.2.34.1   martin 
    377  1.2.34.1   martin static paddr_t
    378  1.2.34.2   martin sti_m68k_mmap(void *v, void *vs, off_t offset, int prot)
    379  1.2.34.1   martin {
    380  1.2.34.1   martin 	struct sti_screen *scr = (struct sti_screen *)v;
    381  1.2.34.1   martin 	struct sti_rom *rom = scr->scr_rom;
    382  1.2.34.1   martin 	struct sti_softc *ssc = rom->rom_softc;
    383  1.2.34.1   martin 	struct sti_sgc_softc *sc = device_private(ssc->sc_dev);
    384  1.2.34.1   martin 	paddr_t cookie = -1;
    385  1.2.34.1   martin 
    386  1.2.34.1   martin 	if ((offset & PAGE_MASK) != 0)
    387  1.2.34.1   martin 		return -1;
    388  1.2.34.1   martin 
    389  1.2.34.1   martin 	switch (scr->scr_wsmode) {
    390  1.2.34.1   martin 	case WSDISPLAYIO_MODE_MAPPED:
    391  1.2.34.1   martin 		/* not implemented yet; what should be shown? */
    392  1.2.34.1   martin 		break;
    393  1.2.34.1   martin 	case WSDISPLAYIO_MODE_DUMBFB:
    394  1.2.34.1   martin 		if (offset >= 0 && offset < (scr->fbwidth * scr->fbheight))
    395  1.2.34.1   martin 			cookie = m68k_btop(sc->sc_bitmap + offset);
    396  1.2.34.1   martin 		break;
    397  1.2.34.1   martin 	default:
    398  1.2.34.1   martin 		break;
    399  1.2.34.1   martin 	}
    400  1.2.34.1   martin 
    401  1.2.34.1   martin 	return cookie;
    402  1.2.34.1   martin }
    403  1.2.34.1   martin 
    404       1.2  tsutsui int
    405       1.2  tsutsui sti_sgc_cnprobe(bus_space_tag_t bst, bus_addr_t addr, int slot)
    406       1.2  tsutsui {
    407       1.2  tsutsui 	void *va;
    408       1.2  tsutsui 	bus_space_handle_t romh;
    409       1.2  tsutsui 	int devtype, rv = 0;
    410       1.2  tsutsui 
    411       1.2  tsutsui 	if (bus_space_map(bst, addr, PAGE_SIZE, 0, &romh))
    412       1.2  tsutsui 		return 0;
    413       1.2  tsutsui 
    414       1.2  tsutsui 	va = bus_space_vaddr(bst, romh);
    415       1.2  tsutsui 	if (badaddr(va))
    416       1.2  tsutsui 		goto out;
    417       1.2  tsutsui 
    418       1.2  tsutsui 	devtype = bus_space_read_1(bst, romh, 3);
    419       1.2  tsutsui 	if (devtype == STI_DEVTYPE1 || devtype == STI_DEVTYPE4)
    420       1.2  tsutsui 		rv = 1;
    421       1.2  tsutsui 
    422       1.2  tsutsui  out:
    423       1.2  tsutsui 	bus_space_unmap(bst, romh, PAGE_SIZE);
    424       1.2  tsutsui 	return rv;
    425       1.2  tsutsui }
    426       1.2  tsutsui 
    427       1.2  tsutsui void
    428       1.2  tsutsui sti_sgc_cnattach(bus_space_tag_t bst, bus_addr_t addr, int slot)
    429       1.1  tsutsui {
    430       1.2  tsutsui 	int i;
    431       1.2  tsutsui 
    432  1.2.34.2   martin 	sticn_tag = *bst;
    433  1.2.34.2   martin 
    434       1.2  tsutsui 	/* sticn_bases[0] will be fixed in sti_cnattach() */
    435       1.2  tsutsui 	for (i = 0; i < STI_REGION_MAX; i++)
    436       1.2  tsutsui 		sticn_bases[i] = addr;
    437       1.2  tsutsui 
    438  1.2.34.2   martin 	sti_cnattach(&sticn_rom, &sticn_scr, &sticn_tag, sticn_bases,
    439       1.2  tsutsui 	    STI_CODEBASE_ALT);
    440       1.1  tsutsui 
    441       1.2  tsutsui 	sticonslot = slot;
    442       1.1  tsutsui }
    443