Home | History | Annotate | Line # | Download | only in dev
sti_sgc.c revision 1.3
      1  1.3  tsutsui /*	$NetBSD: sti_sgc.c,v 1.3 2020/05/04 06:52:53 tsutsui 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.3  tsutsui __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.3 2020/05/04 06:52:53 tsutsui 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.3  tsutsui #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.3  tsutsui struct sti_sgc_softc {
     49  1.3  tsutsui 	struct sti_softc sc_sti;
     50  1.3  tsutsui 
     51  1.3  tsutsui 	paddr_t sc_bitmap;
     52  1.3  tsutsui 	bus_space_tag_t sc_bst;
     53  1.3  tsutsui 	bus_space_handle_t sc_ramdach;
     54  1.3  tsutsui };
     55  1.3  tsutsui 
     56  1.3  tsutsui /*
     57  1.3  tsutsui  * 425e EVRX specific hardware
     58  1.3  tsutsui  */
     59  1.3  tsutsui #define STI_EVRX_RAMDACOFFSET	0x060000
     60  1.3  tsutsui #define STI_EVRX_RAMDACSIZE	0x000800
     61  1.3  tsutsui #define STI_EVRX_FBOFFSET	0x200000
     62  1.3  tsutsui 
     63  1.3  tsutsui #define EVRX_BT458_ADDR		(0x200 + 2)
     64  1.3  tsutsui #define EVRX_BT458_CMAP		(0x204 + 2)
     65  1.3  tsutsui #define EVRX_BT458_CTRL		(0x208 + 2)
     66  1.3  tsutsui #define EVRX_BT458_OMAP		(0x20C + 2)
     67  1.3  tsutsui 
     68  1.3  tsutsui /* from HP-UX /usr/lib/libddevrx.a */
     69  1.3  tsutsui #define EVRX_MAGIC00		0x600
     70  1.3  tsutsui #define EVRX_MAGIC04		0x604
     71  1.3  tsutsui #define EVRX_MAGIC08		0x608
     72  1.3  tsutsui #define EVRX_MAGIC0C		0x60c
     73  1.3  tsutsui #define EVRX_MAGIC10		0x610
     74  1.3  tsutsui #define EVRX_MAGIC10_BSY	0x00010000
     75  1.3  tsutsui #define EVRX_MAGIC18		0x618
     76  1.3  tsutsui #define EVRX_MAGIC1C		0x61c
     77  1.3  tsutsui 
     78  1.2  tsutsui static int sticonslot = -1;
     79  1.2  tsutsui static struct sti_rom sticn_rom;
     80  1.2  tsutsui static struct sti_screen sticn_scr;
     81  1.2  tsutsui static bus_addr_t sticn_bases[STI_REGION_MAX];
     82  1.1  tsutsui 
     83  1.1  tsutsui static int sti_sgc_match(device_t, struct cfdata *, void *);
     84  1.1  tsutsui static void sti_sgc_attach(device_t, device_t, void *);
     85  1.1  tsutsui 
     86  1.1  tsutsui static int sti_sgc_probe(bus_space_tag_t, int);
     87  1.1  tsutsui 
     88  1.3  tsutsui CFATTACH_DECL_NEW(sti_sgc, sizeof(struct sti_sgc_softc),
     89  1.1  tsutsui     sti_sgc_match, sti_sgc_attach, NULL, NULL);
     90  1.1  tsutsui 
     91  1.3  tsutsui /* 425e EVRX specific access functions */
     92  1.3  tsutsui static int sti_evrx_setcmap(struct sti_sgc_softc *, struct wsdisplay_cmap *);
     93  1.3  tsutsui static void sti_evrx_resetramdac(struct sti_sgc_softc *);
     94  1.3  tsutsui static void sti_evrx_resetcmap(struct sti_sgc_softc *);
     95  1.3  tsutsui static int sti_evrx_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     96  1.3  tsutsui static paddr_t sti_evrx_mmap(void *, void *, off_t, int);
     97  1.3  tsutsui 
     98  1.3  tsutsui static const struct wsdisplay_accessops sti_evrx_accessops = {
     99  1.3  tsutsui 	sti_evrx_ioctl,
    100  1.3  tsutsui 	sti_evrx_mmap,
    101  1.3  tsutsui 	sti_alloc_screen,
    102  1.3  tsutsui 	sti_free_screen,
    103  1.3  tsutsui 	sti_show_screen,
    104  1.3  tsutsui 	sti_load_font
    105  1.3  tsutsui };
    106  1.3  tsutsui 
    107  1.1  tsutsui static int
    108  1.1  tsutsui sti_sgc_match(device_t parent, struct cfdata *cf, void *aux)
    109  1.1  tsutsui {
    110  1.1  tsutsui 	struct sgc_attach_args *saa = aux;
    111  1.1  tsutsui 
    112  1.1  tsutsui 	/*
    113  1.1  tsutsui 	 * If we already probed it successfully as a console device, go ahead,
    114  1.1  tsutsui 	 * since we will not be able to bus_space_map() again.
    115  1.1  tsutsui 	 */
    116  1.1  tsutsui 	if (saa->saa_slot == sticonslot)
    117  1.1  tsutsui 		return 1;
    118  1.1  tsutsui 
    119  1.1  tsutsui 	return sti_sgc_probe(saa->saa_iot, saa->saa_slot);
    120  1.1  tsutsui }
    121  1.1  tsutsui 
    122  1.1  tsutsui static void
    123  1.1  tsutsui sti_sgc_attach(device_t parent, device_t self, void *aux)
    124  1.1  tsutsui {
    125  1.3  tsutsui 	struct sti_sgc_softc *sc = device_private(self);
    126  1.3  tsutsui 	struct sti_softc *ssc = &sc->sc_sti;
    127  1.1  tsutsui 	struct sgc_attach_args *saa = aux;
    128  1.3  tsutsui 	struct sti_screen *scr;
    129  1.2  tsutsui 	bus_space_handle_t romh;
    130  1.2  tsutsui 	bus_addr_t base;
    131  1.3  tsutsui 	struct wsemuldisplaydev_attach_args waa;
    132  1.1  tsutsui 	u_int romend;
    133  1.3  tsutsui 	struct sti_dd *rom_dd;
    134  1.3  tsutsui 	uint32_t grid0;
    135  1.1  tsutsui 	int i;
    136  1.1  tsutsui 
    137  1.3  tsutsui 	ssc->sc_dev = self;
    138  1.3  tsutsui 	base = (bus_addr_t)sgc_slottopa(saa->saa_slot);
    139  1.2  tsutsui 
    140  1.2  tsutsui 	if (saa->saa_slot == sticonslot) {
    141  1.3  tsutsui 		ssc->sc_flags |= STI_CONSOLE | STI_ATTACHED;
    142  1.3  tsutsui 		ssc->sc_rom = &sticn_rom;
    143  1.3  tsutsui 		ssc->sc_rom->rom_softc = ssc;
    144  1.3  tsutsui 		ssc->sc_scr = &sticn_scr;
    145  1.3  tsutsui 		ssc->sc_scr->scr_rom = ssc->sc_rom;
    146  1.3  tsutsui 		memcpy(ssc->bases, sticn_bases, sizeof(ssc->bases));
    147  1.2  tsutsui 
    148  1.3  tsutsui 		sti_describe(ssc);
    149  1.2  tsutsui 	} else {
    150  1.2  tsutsui 		if (bus_space_map(saa->saa_iot, base, PAGE_SIZE, 0, &romh)) {
    151  1.2  tsutsui 			aprint_error(": can't map ROM");
    152  1.2  tsutsui 			return;
    153  1.2  tsutsui 		}
    154  1.2  tsutsui 		/*
    155  1.2  tsutsui 		 * Compute real PROM size
    156  1.2  tsutsui 		 */
    157  1.2  tsutsui 		romend = sti_rom_size(saa->saa_iot, romh);
    158  1.2  tsutsui 
    159  1.2  tsutsui 		bus_space_unmap(saa->saa_iot, romh, PAGE_SIZE);
    160  1.2  tsutsui 
    161  1.2  tsutsui 		if (bus_space_map(saa->saa_iot, base, romend, 0, &romh)) {
    162  1.2  tsutsui 			aprint_error(": can't map frame buffer");
    163  1.2  tsutsui 			return;
    164  1.2  tsutsui 		}
    165  1.2  tsutsui 
    166  1.3  tsutsui 		ssc->bases[0] = romh;
    167  1.2  tsutsui 		for (i = 0; i < STI_REGION_MAX; i++)
    168  1.3  tsutsui 			ssc->bases[i] = base;
    169  1.2  tsutsui 
    170  1.3  tsutsui 		if (sti_attach_common(ssc, saa->saa_iot, saa->saa_iot, romh,
    171  1.2  tsutsui 		    STI_CODEBASE_ALT) != 0)
    172  1.2  tsutsui 			return;
    173  1.1  tsutsui 	}
    174  1.1  tsutsui 
    175  1.3  tsutsui 	/* Identify the board model by dd_grid */
    176  1.3  tsutsui 	rom_dd = &ssc->sc_rom->rom_dd;
    177  1.3  tsutsui 	grid0 = rom_dd->dd_grid[0];
    178  1.3  tsutsui 	scr = ssc->sc_scr;
    179  1.3  tsutsui 
    180  1.3  tsutsui 	switch (grid0) {
    181  1.3  tsutsui 	case STI_DD_EVRX:
    182  1.3  tsutsui 		/*
    183  1.3  tsutsui 		 * 425e on-board EVRX framebuffer.
    184  1.3  tsutsui 		 * bitmap memory can be accessed at offset +0x200000.
    185  1.3  tsutsui 		 */
    186  1.3  tsutsui 		sc->sc_bitmap = base + STI_EVRX_FBOFFSET;
    187  1.3  tsutsui 
    188  1.3  tsutsui 		/*
    189  1.3  tsutsui 		 * Bt458 RAMDAC can be accessed at offset +0x60200 and
    190  1.3  tsutsui 		 * unknown control registers are around +0x60600.
    191  1.3  tsutsui 		 */
    192  1.3  tsutsui 		sc->sc_bst = saa->saa_iot;
    193  1.3  tsutsui 		if (bus_space_map(sc->sc_bst, base + STI_EVRX_RAMDACOFFSET,
    194  1.3  tsutsui 		    STI_EVRX_RAMDACSIZE, 0, &sc->sc_ramdach)) {
    195  1.3  tsutsui 			aprint_error_dev(self, "can't map RAMDAC\n");
    196  1.3  tsutsui 			return;
    197  1.3  tsutsui 		}
    198  1.3  tsutsui 
    199  1.3  tsutsui 		aprint_normal_dev(self, "Enable mmap support\n");
    200  1.3  tsutsui 
    201  1.3  tsutsui 		/*
    202  1.3  tsutsui 		 * initialize Bt458 RAMDAC and preserve initial color map
    203  1.3  tsutsui 		 */
    204  1.3  tsutsui 		sti_evrx_resetramdac(sc);
    205  1.3  tsutsui 		sti_evrx_resetcmap(sc);
    206  1.3  tsutsui 
    207  1.3  tsutsui 		scr->scr_wsmode = WSDISPLAYIO_MODE_EMUL;
    208  1.3  tsutsui 		waa.console = ssc->sc_flags & STI_CONSOLE ? 1 : 0;
    209  1.3  tsutsui 		waa.scrdata = &scr->scr_screenlist;
    210  1.3  tsutsui 		waa.accessops = &sti_evrx_accessops;
    211  1.3  tsutsui 		waa.accesscookie = scr;
    212  1.3  tsutsui 
    213  1.3  tsutsui 		config_found(ssc->sc_dev, &waa, wsemuldisplaydevprint);
    214  1.3  tsutsui 		break;
    215  1.1  tsutsui 
    216  1.3  tsutsui 	case STI_DD_CRX:
    217  1.3  tsutsui 		/*
    218  1.3  tsutsui 		 * HP A1659A CRX on some 425t variants.
    219  1.3  tsutsui 		 * Not investigated yet; needs to check HP-UX libddgcrx.a etc.
    220  1.3  tsutsui 		 */
    221  1.3  tsutsui 		/* FALLTHROUGH */
    222  1.3  tsutsui 	default:
    223  1.3  tsutsui 		/*
    224  1.3  tsutsui 		 * Unsupported variants.
    225  1.3  tsutsui 		 * Use default common sti(4) attachment (no bitmap support).
    226  1.3  tsutsui 		 */
    227  1.3  tsutsui 		sti_end_attach(ssc);
    228  1.3  tsutsui 		break;
    229  1.3  tsutsui 	}
    230  1.1  tsutsui }
    231  1.1  tsutsui 
    232  1.1  tsutsui static int
    233  1.1  tsutsui sti_sgc_probe(bus_space_tag_t iot, int slot)
    234  1.1  tsutsui {
    235  1.1  tsutsui 	bus_space_handle_t ioh;
    236  1.1  tsutsui 	int devtype;
    237  1.1  tsutsui 
    238  1.2  tsutsui 	if (bus_space_map(iot, (bus_addr_t)sgc_slottopa(slot),
    239  1.2  tsutsui 	    PAGE_SIZE, 0, &ioh))
    240  1.1  tsutsui 		return 0;
    241  1.2  tsutsui 
    242  1.1  tsutsui 	devtype = bus_space_read_1(iot, ioh, 3);
    243  1.2  tsutsui 
    244  1.1  tsutsui 	bus_space_unmap(iot, ioh, PAGE_SIZE);
    245  1.1  tsutsui 
    246  1.1  tsutsui 	/*
    247  1.1  tsutsui 	 * This might not be reliable enough. On the other hand, non-STI
    248  1.1  tsutsui 	 * SGC cards will apparently not initialize in an hp300, to the
    249  1.1  tsutsui 	 * point of not even answering bus probes (checked with an
    250  1.1  tsutsui 	 * Harmony/FDDI SGC card).
    251  1.1  tsutsui 	 */
    252  1.2  tsutsui 	if (devtype != STI_DEVTYPE1 && devtype != STI_DEVTYPE4)
    253  1.1  tsutsui 		return 0;
    254  1.2  tsutsui 
    255  1.1  tsutsui 	return 1;
    256  1.1  tsutsui }
    257  1.1  tsutsui 
    258  1.3  tsutsui static int
    259  1.3  tsutsui sti_evrx_setcmap(struct sti_sgc_softc *sc, struct wsdisplay_cmap *p)
    260  1.3  tsutsui {
    261  1.3  tsutsui 	struct sti_softc *ssc = &sc->sc_sti;
    262  1.3  tsutsui 	struct sti_screen *scr = ssc->sc_scr;
    263  1.3  tsutsui 	bus_space_tag_t bst = sc->sc_bst;
    264  1.3  tsutsui 	bus_space_handle_t bsh = sc->sc_ramdach;
    265  1.3  tsutsui 	uint8_t r[STI_NCMAP], g[STI_NCMAP], b[STI_NCMAP];
    266  1.3  tsutsui 	u_int index, count;
    267  1.3  tsutsui 	int i, error;
    268  1.3  tsutsui 
    269  1.3  tsutsui 	index = p->index;
    270  1.3  tsutsui 	count = p->count;
    271  1.3  tsutsui 	if (index >= STI_NCMAP || count > STI_NCMAP - index)
    272  1.3  tsutsui 		return EINVAL;
    273  1.3  tsutsui 
    274  1.3  tsutsui 	error = copyin(p->red, &r[index], count);
    275  1.3  tsutsui 	if (error)
    276  1.3  tsutsui 		return error;
    277  1.3  tsutsui 	error = copyin(p->green, &g[index], count);
    278  1.3  tsutsui 	if (error)
    279  1.3  tsutsui 		return error;
    280  1.3  tsutsui 	error = copyin(p->blue, &b[index], count);
    281  1.3  tsutsui 	if (error)
    282  1.3  tsutsui 		return error;
    283  1.3  tsutsui 
    284  1.3  tsutsui 	memcpy(&scr->scr_rcmap[index], &r[index], count);
    285  1.3  tsutsui 	memcpy(&scr->scr_gcmap[index], &g[index], count);
    286  1.3  tsutsui 	memcpy(&scr->scr_bcmap[index], &b[index], count);
    287  1.3  tsutsui 
    288  1.3  tsutsui 	/* magic setup from HP-UX */
    289  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
    290  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
    291  1.3  tsutsui 	for (i = index; i < index + count; i++) {
    292  1.3  tsutsui 		/* this is what HP-UX woodDownloadCmap() does */
    293  1.3  tsutsui 		while ((bus_space_read_4(bst, bsh, EVRX_MAGIC10) &
    294  1.3  tsutsui 		    EVRX_MAGIC10_BSY) != 0)
    295  1.3  tsutsui 			continue;
    296  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, i);
    297  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_CMAP, scr->scr_rcmap[i]);
    298  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_CMAP, scr->scr_gcmap[i]);
    299  1.3  tsutsui 		bus_space_write_4(bst, bsh, EVRX_MAGIC10,   scr->scr_bcmap[i]);
    300  1.3  tsutsui 	}
    301  1.3  tsutsui 	return 0;
    302  1.3  tsutsui }
    303  1.3  tsutsui 
    304  1.3  tsutsui static void
    305  1.3  tsutsui sti_evrx_resetramdac(struct sti_sgc_softc *sc)
    306  1.3  tsutsui {
    307  1.3  tsutsui 	bus_space_tag_t bst = sc->sc_bst;
    308  1.3  tsutsui 	bus_space_handle_t bsh = sc->sc_ramdach;
    309  1.3  tsutsui #if 0
    310  1.3  tsutsui 	int i;
    311  1.3  tsutsui #endif
    312  1.3  tsutsui 
    313  1.3  tsutsui 	/*
    314  1.3  tsutsui 	 * Initialize the Bt458.  When we write to control registers,
    315  1.3  tsutsui 	 * the address is not incremented automatically. So we specify
    316  1.3  tsutsui 	 * it ourselves for each control register.
    317  1.3  tsutsui 	 */
    318  1.3  tsutsui 
    319  1.3  tsutsui 	/* all planes will be read */
    320  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x04);
    321  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0xff);
    322  1.3  tsutsui 
    323  1.3  tsutsui 	/* all planes have non-blink */
    324  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x05);
    325  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x00);
    326  1.3  tsutsui 
    327  1.3  tsutsui 	/* pallete enabled, ovly plane disabled */
    328  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x06);
    329  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x40);
    330  1.3  tsutsui 
    331  1.3  tsutsui 	/* no test mode */
    332  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x07);
    333  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x00);
    334  1.3  tsutsui 
    335  1.3  tsutsui 	/* magic initialization from HP-UX woodInitializeHardware() */
    336  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
    337  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC04, 0x00000001);
    338  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
    339  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC0C, 0x00000001);
    340  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC18, 0xFFFFFFFF);
    341  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC1C, 0x00000000);
    342  1.3  tsutsui 
    343  1.3  tsutsui #if 0
    344  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x00);
    345  1.3  tsutsui 	for (i = 0; i < 4; i++) {
    346  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
    347  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
    348  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
    349  1.3  tsutsui 	}
    350  1.3  tsutsui #endif
    351  1.3  tsutsui }
    352  1.3  tsutsui 
    353  1.3  tsutsui static void
    354  1.3  tsutsui sti_evrx_resetcmap(struct sti_sgc_softc *sc)
    355  1.3  tsutsui {
    356  1.3  tsutsui 	struct sti_softc *ssc = &sc->sc_sti;
    357  1.3  tsutsui 	struct sti_screen *scr = ssc->sc_scr;
    358  1.3  tsutsui 	bus_space_tag_t bst = sc->sc_bst;
    359  1.3  tsutsui 	bus_space_handle_t bsh = sc->sc_ramdach;
    360  1.3  tsutsui 	int i;
    361  1.3  tsutsui 
    362  1.3  tsutsui 	/* magic setup from HP-UX */
    363  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
    364  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
    365  1.3  tsutsui 
    366  1.3  tsutsui 	/* preserve palette values initialized by STI firmware */
    367  1.3  tsutsui 	for (i = 0; i < STI_NCMAP; i++) {
    368  1.3  tsutsui 		/* this is what HP-UX woodUploadCmap() does */
    369  1.3  tsutsui 		while ((bus_space_read_4(bst, bsh, EVRX_MAGIC10) &
    370  1.3  tsutsui 		    EVRX_MAGIC10_BSY) != 0)
    371  1.3  tsutsui 			continue;
    372  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, i);
    373  1.3  tsutsui 		scr->scr_rcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
    374  1.3  tsutsui 		scr->scr_gcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
    375  1.3  tsutsui 		scr->scr_bcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
    376  1.3  tsutsui 	}
    377  1.3  tsutsui }
    378  1.3  tsutsui 
    379  1.3  tsutsui static int
    380  1.3  tsutsui sti_evrx_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    381  1.3  tsutsui     struct lwp *l)
    382  1.3  tsutsui {
    383  1.3  tsutsui 	struct sti_screen *scr = (struct sti_screen *)v;
    384  1.3  tsutsui 	struct sti_rom *rom = scr->scr_rom;
    385  1.3  tsutsui 	struct sti_softc *ssc = rom->rom_softc;
    386  1.3  tsutsui 	struct sti_sgc_softc *sc = device_private(ssc->sc_dev);
    387  1.3  tsutsui 	struct wsdisplay_fbinfo *wdf;
    388  1.3  tsutsui 	struct wsdisplay_cmap *cmapp;
    389  1.3  tsutsui 	u_int idx, count;
    390  1.3  tsutsui 	int error, new_mode;
    391  1.3  tsutsui 
    392  1.3  tsutsui 	switch (cmd) {
    393  1.3  tsutsui 	case WSDISPLAYIO_GINFO:
    394  1.3  tsutsui 		wdf = (struct wsdisplay_fbinfo *)data;
    395  1.3  tsutsui 		wdf->height = scr->scr_cfg.scr_height;
    396  1.3  tsutsui 		wdf->width  = scr->scr_cfg.scr_width;
    397  1.3  tsutsui 		wdf->depth  = scr->scr_bpp;
    398  1.3  tsutsui 		wdf->cmsize = STI_NCMAP;
    399  1.3  tsutsui 		return 0;
    400  1.3  tsutsui 
    401  1.3  tsutsui 	case WSDISPLAYIO_GETCMAP:
    402  1.3  tsutsui 		cmapp = (struct wsdisplay_cmap *)data;
    403  1.3  tsutsui 		idx = cmapp->index;
    404  1.3  tsutsui 		count = cmapp->count;
    405  1.3  tsutsui 		if (idx >= STI_NCMAP || count > STI_NCMAP - idx)
    406  1.3  tsutsui 			return EINVAL;
    407  1.3  tsutsui 		error = copyout(&scr->scr_rcmap[idx], cmapp->red, count);
    408  1.3  tsutsui 		if (error != 0)
    409  1.3  tsutsui 			return error;
    410  1.3  tsutsui 		error = copyout(&scr->scr_gcmap[idx], cmapp->green, count);
    411  1.3  tsutsui 		if (error != 0)
    412  1.3  tsutsui 			return error;
    413  1.3  tsutsui 		error = copyout(&scr->scr_bcmap[idx], cmapp->blue, count);
    414  1.3  tsutsui 		if (error != 0)
    415  1.3  tsutsui 			return error;
    416  1.3  tsutsui 		return 0;
    417  1.3  tsutsui 
    418  1.3  tsutsui 	case WSDISPLAYIO_PUTCMAP:
    419  1.3  tsutsui 		cmapp = (struct wsdisplay_cmap *)data;
    420  1.3  tsutsui 		return sti_evrx_setcmap(sc, cmapp);
    421  1.3  tsutsui 
    422  1.3  tsutsui 	case WSDISPLAYIO_SMODE:
    423  1.3  tsutsui 		new_mode = *(int *)data;
    424  1.3  tsutsui 		if (new_mode != scr->scr_wsmode) {
    425  1.3  tsutsui 			scr->scr_wsmode = new_mode;
    426  1.3  tsutsui 			if (new_mode == WSDISPLAYIO_MODE_EMUL) {
    427  1.3  tsutsui 				sti_init(scr, STI_TEXTMODE);
    428  1.3  tsutsui 			} else if (new_mode == WSDISPLAYIO_MODE_DUMBFB) {
    429  1.3  tsutsui 				sti_init(scr, 0);
    430  1.3  tsutsui 				sti_evrx_resetramdac(sc);
    431  1.3  tsutsui 			}
    432  1.3  tsutsui 		}
    433  1.3  tsutsui 		return 0;
    434  1.3  tsutsui 
    435  1.3  tsutsui 	}
    436  1.3  tsutsui 	return sti_ioctl(v, vs, cmd, data, flag, l);
    437  1.3  tsutsui }
    438  1.3  tsutsui 
    439  1.3  tsutsui static paddr_t
    440  1.3  tsutsui sti_evrx_mmap(void *v, void *vs, off_t offset, int prot)
    441  1.3  tsutsui {
    442  1.3  tsutsui 	struct sti_screen *scr = (struct sti_screen *)v;
    443  1.3  tsutsui 	struct sti_rom *rom = scr->scr_rom;
    444  1.3  tsutsui 	struct sti_softc *ssc = rom->rom_softc;
    445  1.3  tsutsui 	struct sti_sgc_softc *sc = device_private(ssc->sc_dev);
    446  1.3  tsutsui 	paddr_t cookie = -1;
    447  1.3  tsutsui 
    448  1.3  tsutsui 	if ((offset & PAGE_MASK) != 0)
    449  1.3  tsutsui 		return -1;
    450  1.3  tsutsui 
    451  1.3  tsutsui 	switch (scr->scr_wsmode) {
    452  1.3  tsutsui 	case WSDISPLAYIO_MODE_MAPPED:
    453  1.3  tsutsui 		/* not implemented yet; what should be shown? */
    454  1.3  tsutsui 		break;
    455  1.3  tsutsui 	case WSDISPLAYIO_MODE_DUMBFB:
    456  1.3  tsutsui 		if (offset >= 0 && offset < (scr->fbwidth * scr->fbheight))
    457  1.3  tsutsui 			cookie = m68k_btop(sc->sc_bitmap + offset);
    458  1.3  tsutsui 		break;
    459  1.3  tsutsui 	default:
    460  1.3  tsutsui 		break;
    461  1.3  tsutsui 	}
    462  1.3  tsutsui 
    463  1.3  tsutsui 	return cookie;
    464  1.3  tsutsui }
    465  1.3  tsutsui 
    466  1.2  tsutsui int
    467  1.2  tsutsui sti_sgc_cnprobe(bus_space_tag_t bst, bus_addr_t addr, int slot)
    468  1.2  tsutsui {
    469  1.2  tsutsui 	void *va;
    470  1.2  tsutsui 	bus_space_handle_t romh;
    471  1.2  tsutsui 	int devtype, rv = 0;
    472  1.2  tsutsui 
    473  1.2  tsutsui 	if (bus_space_map(bst, addr, PAGE_SIZE, 0, &romh))
    474  1.2  tsutsui 		return 0;
    475  1.2  tsutsui 
    476  1.2  tsutsui 	va = bus_space_vaddr(bst, romh);
    477  1.2  tsutsui 	if (badaddr(va))
    478  1.2  tsutsui 		goto out;
    479  1.2  tsutsui 
    480  1.2  tsutsui 	devtype = bus_space_read_1(bst, romh, 3);
    481  1.2  tsutsui 	if (devtype == STI_DEVTYPE1 || devtype == STI_DEVTYPE4)
    482  1.2  tsutsui 		rv = 1;
    483  1.2  tsutsui 
    484  1.2  tsutsui  out:
    485  1.2  tsutsui 	bus_space_unmap(bst, romh, PAGE_SIZE);
    486  1.2  tsutsui 	return rv;
    487  1.2  tsutsui }
    488  1.2  tsutsui 
    489  1.2  tsutsui void
    490  1.2  tsutsui sti_sgc_cnattach(bus_space_tag_t bst, bus_addr_t addr, int slot)
    491  1.1  tsutsui {
    492  1.2  tsutsui 	int i;
    493  1.2  tsutsui 
    494  1.2  tsutsui 	/* sticn_bases[0] will be fixed in sti_cnattach() */
    495  1.2  tsutsui 	for (i = 0; i < STI_REGION_MAX; i++)
    496  1.2  tsutsui 		sticn_bases[i] = addr;
    497  1.2  tsutsui 
    498  1.2  tsutsui 	sti_cnattach(&sticn_rom, &sticn_scr, bst, sticn_bases,
    499  1.2  tsutsui 	    STI_CODEBASE_ALT);
    500  1.1  tsutsui 
    501  1.2  tsutsui 	sticonslot = slot;
    502  1.1  tsutsui }
    503