Home | History | Annotate | Line # | Download | only in dev
sti_sgc.c revision 1.2.34.1
      1  1.2.34.1   martin /*	$NetBSD: sti_sgc.c,v 1.2.34.1 2020/05/18 17:52:22 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.1   martin __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.2.34.1 2020/05/18 17:52:22 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 	bus_space_tag_t sc_bst;
     53  1.2.34.1   martin 	bus_space_handle_t sc_ramdach;
     54  1.2.34.1   martin };
     55  1.2.34.1   martin 
     56  1.2.34.1   martin /*
     57  1.2.34.1   martin  * 425e EVRX specific hardware
     58  1.2.34.1   martin  */
     59  1.2.34.1   martin #define STI_EVRX_RAMDACOFFSET	0x060000
     60  1.2.34.1   martin #define STI_EVRX_RAMDACSIZE	0x000800
     61  1.2.34.1   martin #define STI_EVRX_FBOFFSET	0x200000
     62  1.2.34.1   martin 
     63  1.2.34.1   martin #define EVRX_BT458_ADDR		(0x200 + 2)
     64  1.2.34.1   martin #define EVRX_BT458_CMAP		(0x204 + 2)
     65  1.2.34.1   martin #define EVRX_BT458_CTRL		(0x208 + 2)
     66  1.2.34.1   martin #define EVRX_BT458_OMAP		(0x20C + 2)
     67  1.2.34.1   martin 
     68  1.2.34.1   martin /* from HP-UX /usr/lib/libddevrx.a */
     69  1.2.34.1   martin #define EVRX_MAGIC00		0x600
     70  1.2.34.1   martin #define EVRX_MAGIC04		0x604
     71  1.2.34.1   martin #define EVRX_MAGIC08		0x608
     72  1.2.34.1   martin #define EVRX_MAGIC0C		0x60c
     73  1.2.34.1   martin #define EVRX_MAGIC10		0x610
     74  1.2.34.1   martin #define EVRX_MAGIC10_BSY	0x00010000
     75  1.2.34.1   martin #define EVRX_MAGIC18		0x618
     76  1.2.34.1   martin #define EVRX_MAGIC1C		0x61c
     77  1.2.34.1   martin 
     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.2.34.1   martin 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.2.34.1   martin /* 425e EVRX specific access functions */
     92  1.2.34.1   martin static int sti_evrx_setcmap(struct sti_sgc_softc *, struct wsdisplay_cmap *);
     93  1.2.34.1   martin static void sti_evrx_resetramdac(struct sti_sgc_softc *);
     94  1.2.34.1   martin static void sti_evrx_resetcmap(struct sti_sgc_softc *);
     95  1.2.34.1   martin static int sti_evrx_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     96  1.2.34.1   martin static paddr_t sti_evrx_mmap(void *, void *, off_t, int);
     97  1.2.34.1   martin 
     98  1.2.34.1   martin static const struct wsdisplay_accessops sti_evrx_accessops = {
     99  1.2.34.1   martin 	sti_evrx_ioctl,
    100  1.2.34.1   martin 	sti_evrx_mmap,
    101  1.2.34.1   martin 	sti_alloc_screen,
    102  1.2.34.1   martin 	sti_free_screen,
    103  1.2.34.1   martin 	sti_show_screen,
    104  1.2.34.1   martin 	sti_load_font
    105  1.2.34.1   martin };
    106  1.2.34.1   martin 
    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.2.34.1   martin 	struct sti_sgc_softc *sc = device_private(self);
    126  1.2.34.1   martin 	struct sti_softc *ssc = &sc->sc_sti;
    127       1.1  tsutsui 	struct sgc_attach_args *saa = aux;
    128  1.2.34.1   martin 	struct sti_screen *scr;
    129       1.2  tsutsui 	bus_space_handle_t romh;
    130       1.2  tsutsui 	bus_addr_t base;
    131  1.2.34.1   martin 	struct wsemuldisplaydev_attach_args waa;
    132       1.1  tsutsui 	u_int romend;
    133  1.2.34.1   martin 	struct sti_dd *rom_dd;
    134  1.2.34.1   martin 	uint32_t grid0;
    135       1.1  tsutsui 	int i;
    136       1.1  tsutsui 
    137  1.2.34.1   martin 	ssc->sc_dev = self;
    138  1.2.34.1   martin 	base = (bus_addr_t)sgc_slottopa(saa->saa_slot);
    139       1.2  tsutsui 
    140       1.2  tsutsui 	if (saa->saa_slot == sticonslot) {
    141  1.2.34.1   martin 		ssc->sc_flags |= STI_CONSOLE | STI_ATTACHED;
    142  1.2.34.1   martin 		ssc->sc_rom = &sticn_rom;
    143  1.2.34.1   martin 		ssc->sc_rom->rom_softc = ssc;
    144  1.2.34.1   martin 		ssc->sc_scr = &sticn_scr;
    145  1.2.34.1   martin 		ssc->sc_scr->scr_rom = ssc->sc_rom;
    146  1.2.34.1   martin 		memcpy(ssc->bases, sticn_bases, sizeof(ssc->bases));
    147       1.2  tsutsui 
    148  1.2.34.1   martin 		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.2.34.1   martin 		ssc->bases[0] = romh;
    167       1.2  tsutsui 		for (i = 0; i < STI_REGION_MAX; i++)
    168  1.2.34.1   martin 			ssc->bases[i] = base;
    169       1.2  tsutsui 
    170  1.2.34.1   martin 		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.2.34.1   martin 	/* Identify the board model by dd_grid */
    176  1.2.34.1   martin 	rom_dd = &ssc->sc_rom->rom_dd;
    177  1.2.34.1   martin 	grid0 = rom_dd->dd_grid[0];
    178  1.2.34.1   martin 	scr = ssc->sc_scr;
    179  1.2.34.1   martin 
    180  1.2.34.1   martin 	switch (grid0) {
    181  1.2.34.1   martin 	case STI_DD_EVRX:
    182  1.2.34.1   martin 		/*
    183  1.2.34.1   martin 		 * 425e on-board EVRX framebuffer.
    184  1.2.34.1   martin 		 * bitmap memory can be accessed at offset +0x200000.
    185  1.2.34.1   martin 		 */
    186  1.2.34.1   martin 		sc->sc_bitmap = base + STI_EVRX_FBOFFSET;
    187  1.2.34.1   martin 
    188  1.2.34.1   martin 		/*
    189  1.2.34.1   martin 		 * Bt458 RAMDAC can be accessed at offset +0x60200 and
    190  1.2.34.1   martin 		 * unknown control registers are around +0x60600.
    191  1.2.34.1   martin 		 */
    192  1.2.34.1   martin 		sc->sc_bst = saa->saa_iot;
    193  1.2.34.1   martin 		if (bus_space_map(sc->sc_bst, base + STI_EVRX_RAMDACOFFSET,
    194  1.2.34.1   martin 		    STI_EVRX_RAMDACSIZE, 0, &sc->sc_ramdach)) {
    195  1.2.34.1   martin 			aprint_error_dev(self, "can't map RAMDAC\n");
    196  1.2.34.1   martin 			return;
    197  1.2.34.1   martin 		}
    198  1.2.34.1   martin 
    199  1.2.34.1   martin 		aprint_normal_dev(self, "Enable mmap support\n");
    200       1.1  tsutsui 
    201  1.2.34.1   martin 		/*
    202  1.2.34.1   martin 		 * initialize Bt458 RAMDAC and preserve initial color map
    203  1.2.34.1   martin 		 */
    204  1.2.34.1   martin 		sti_evrx_resetramdac(sc);
    205  1.2.34.1   martin 		sti_evrx_resetcmap(sc);
    206  1.2.34.1   martin 
    207  1.2.34.1   martin 		scr->scr_wsmode = WSDISPLAYIO_MODE_EMUL;
    208  1.2.34.1   martin 		waa.console = ssc->sc_flags & STI_CONSOLE ? 1 : 0;
    209  1.2.34.1   martin 		waa.scrdata = &scr->scr_screenlist;
    210  1.2.34.1   martin 		waa.accessops = &sti_evrx_accessops;
    211  1.2.34.1   martin 		waa.accesscookie = scr;
    212  1.2.34.1   martin 
    213  1.2.34.1   martin 		config_found(ssc->sc_dev, &waa, wsemuldisplaydevprint);
    214  1.2.34.1   martin 		break;
    215  1.2.34.1   martin 
    216  1.2.34.1   martin 	case STI_DD_CRX:
    217  1.2.34.1   martin 		/*
    218  1.2.34.1   martin 		 * HP A1659A CRX on some 425t variants.
    219  1.2.34.1   martin 		 * Not investigated yet; needs to check HP-UX libddgcrx.a etc.
    220  1.2.34.1   martin 		 */
    221  1.2.34.1   martin 		/* FALLTHROUGH */
    222  1.2.34.1   martin 	default:
    223  1.2.34.1   martin 		/*
    224  1.2.34.1   martin 		 * Unsupported variants.
    225  1.2.34.1   martin 		 * Use default common sti(4) attachment (no bitmap support).
    226  1.2.34.1   martin 		 */
    227  1.2.34.1   martin 		sti_end_attach(ssc);
    228  1.2.34.1   martin 		break;
    229  1.2.34.1   martin 	}
    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.2.34.1   martin static int
    259  1.2.34.1   martin sti_evrx_setcmap(struct sti_sgc_softc *sc, struct wsdisplay_cmap *p)
    260  1.2.34.1   martin {
    261  1.2.34.1   martin 	struct sti_softc *ssc = &sc->sc_sti;
    262  1.2.34.1   martin 	struct sti_screen *scr = ssc->sc_scr;
    263  1.2.34.1   martin 	bus_space_tag_t bst = sc->sc_bst;
    264  1.2.34.1   martin 	bus_space_handle_t bsh = sc->sc_ramdach;
    265  1.2.34.1   martin 	uint8_t r[STI_NCMAP], g[STI_NCMAP], b[STI_NCMAP];
    266  1.2.34.1   martin 	u_int index, count;
    267  1.2.34.1   martin 	int i, error;
    268  1.2.34.1   martin 
    269  1.2.34.1   martin 	index = p->index;
    270  1.2.34.1   martin 	count = p->count;
    271  1.2.34.1   martin 	if (index >= STI_NCMAP || count > STI_NCMAP - index)
    272  1.2.34.1   martin 		return EINVAL;
    273  1.2.34.1   martin 
    274  1.2.34.1   martin 	error = copyin(p->red, &r[index], count);
    275  1.2.34.1   martin 	if (error)
    276  1.2.34.1   martin 		return error;
    277  1.2.34.1   martin 	error = copyin(p->green, &g[index], count);
    278  1.2.34.1   martin 	if (error)
    279  1.2.34.1   martin 		return error;
    280  1.2.34.1   martin 	error = copyin(p->blue, &b[index], count);
    281  1.2.34.1   martin 	if (error)
    282  1.2.34.1   martin 		return error;
    283  1.2.34.1   martin 
    284  1.2.34.1   martin 	memcpy(&scr->scr_rcmap[index], &r[index], count);
    285  1.2.34.1   martin 	memcpy(&scr->scr_gcmap[index], &g[index], count);
    286  1.2.34.1   martin 	memcpy(&scr->scr_bcmap[index], &b[index], count);
    287  1.2.34.1   martin 
    288  1.2.34.1   martin 	/* magic setup from HP-UX */
    289  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
    290  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
    291  1.2.34.1   martin 	for (i = index; i < index + count; i++) {
    292  1.2.34.1   martin 		/* this is what HP-UX woodDownloadCmap() does */
    293  1.2.34.1   martin 		while ((bus_space_read_4(bst, bsh, EVRX_MAGIC10) &
    294  1.2.34.1   martin 		    EVRX_MAGIC10_BSY) != 0)
    295  1.2.34.1   martin 			continue;
    296  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, i);
    297  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_CMAP, scr->scr_rcmap[i]);
    298  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_CMAP, scr->scr_gcmap[i]);
    299  1.2.34.1   martin 		bus_space_write_4(bst, bsh, EVRX_MAGIC10,   scr->scr_bcmap[i]);
    300  1.2.34.1   martin 	}
    301  1.2.34.1   martin 	return 0;
    302  1.2.34.1   martin }
    303  1.2.34.1   martin 
    304  1.2.34.1   martin static void
    305  1.2.34.1   martin sti_evrx_resetramdac(struct sti_sgc_softc *sc)
    306  1.2.34.1   martin {
    307  1.2.34.1   martin 	bus_space_tag_t bst = sc->sc_bst;
    308  1.2.34.1   martin 	bus_space_handle_t bsh = sc->sc_ramdach;
    309  1.2.34.1   martin #if 0
    310  1.2.34.1   martin 	int i;
    311  1.2.34.1   martin #endif
    312  1.2.34.1   martin 
    313  1.2.34.1   martin 	/*
    314  1.2.34.1   martin 	 * Initialize the Bt458.  When we write to control registers,
    315  1.2.34.1   martin 	 * the address is not incremented automatically. So we specify
    316  1.2.34.1   martin 	 * it ourselves for each control register.
    317  1.2.34.1   martin 	 */
    318  1.2.34.1   martin 
    319  1.2.34.1   martin 	/* all planes will be read */
    320  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x04);
    321  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0xff);
    322  1.2.34.1   martin 
    323  1.2.34.1   martin 	/* all planes have non-blink */
    324  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x05);
    325  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x00);
    326  1.2.34.1   martin 
    327  1.2.34.1   martin 	/* pallete enabled, ovly plane disabled */
    328  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x06);
    329  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x40);
    330  1.2.34.1   martin 
    331  1.2.34.1   martin 	/* no test mode */
    332  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x07);
    333  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x00);
    334  1.2.34.1   martin 
    335  1.2.34.1   martin 	/* magic initialization from HP-UX woodInitializeHardware() */
    336  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
    337  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC04, 0x00000001);
    338  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
    339  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC0C, 0x00000001);
    340  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC18, 0xFFFFFFFF);
    341  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC1C, 0x00000000);
    342  1.2.34.1   martin 
    343  1.2.34.1   martin #if 0
    344  1.2.34.1   martin 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x00);
    345  1.2.34.1   martin 	for (i = 0; i < 4; i++) {
    346  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
    347  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
    348  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
    349  1.2.34.1   martin 	}
    350  1.2.34.1   martin #endif
    351  1.2.34.1   martin }
    352  1.2.34.1   martin 
    353  1.2.34.1   martin static void
    354  1.2.34.1   martin sti_evrx_resetcmap(struct sti_sgc_softc *sc)
    355  1.2.34.1   martin {
    356  1.2.34.1   martin 	struct sti_softc *ssc = &sc->sc_sti;
    357  1.2.34.1   martin 	struct sti_screen *scr = ssc->sc_scr;
    358  1.2.34.1   martin 	bus_space_tag_t bst = sc->sc_bst;
    359  1.2.34.1   martin 	bus_space_handle_t bsh = sc->sc_ramdach;
    360  1.2.34.1   martin 	int i;
    361  1.2.34.1   martin 
    362  1.2.34.1   martin 	/* magic setup from HP-UX */
    363  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
    364  1.2.34.1   martin 	bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
    365  1.2.34.1   martin 
    366  1.2.34.1   martin 	/* preserve palette values initialized by STI firmware */
    367  1.2.34.1   martin 	for (i = 0; i < STI_NCMAP; i++) {
    368  1.2.34.1   martin 		/* this is what HP-UX woodUploadCmap() does */
    369  1.2.34.1   martin 		while ((bus_space_read_4(bst, bsh, EVRX_MAGIC10) &
    370  1.2.34.1   martin 		    EVRX_MAGIC10_BSY) != 0)
    371  1.2.34.1   martin 			continue;
    372  1.2.34.1   martin 		bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, i);
    373  1.2.34.1   martin 		scr->scr_rcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
    374  1.2.34.1   martin 		scr->scr_gcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
    375  1.2.34.1   martin 		scr->scr_bcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
    376  1.2.34.1   martin 	}
    377  1.2.34.1   martin }
    378  1.2.34.1   martin 
    379  1.2.34.1   martin static int
    380  1.2.34.1   martin sti_evrx_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    381  1.2.34.1   martin     struct lwp *l)
    382  1.2.34.1   martin {
    383  1.2.34.1   martin 	struct sti_screen *scr = (struct sti_screen *)v;
    384  1.2.34.1   martin 	struct sti_rom *rom = scr->scr_rom;
    385  1.2.34.1   martin 	struct sti_softc *ssc = rom->rom_softc;
    386  1.2.34.1   martin 	struct sti_sgc_softc *sc = device_private(ssc->sc_dev);
    387  1.2.34.1   martin 	struct wsdisplay_fbinfo *wdf;
    388  1.2.34.1   martin 	struct wsdisplay_cmap *cmapp;
    389  1.2.34.1   martin 	u_int idx, count;
    390  1.2.34.1   martin 	int error, new_mode;
    391  1.2.34.1   martin 
    392  1.2.34.1   martin 	switch (cmd) {
    393  1.2.34.1   martin 	case WSDISPLAYIO_GINFO:
    394  1.2.34.1   martin 		wdf = (struct wsdisplay_fbinfo *)data;
    395  1.2.34.1   martin 		wdf->height = scr->scr_cfg.scr_height;
    396  1.2.34.1   martin 		wdf->width  = scr->scr_cfg.scr_width;
    397  1.2.34.1   martin 		wdf->depth  = scr->scr_bpp;
    398  1.2.34.1   martin 		wdf->cmsize = STI_NCMAP;
    399  1.2.34.1   martin 		return 0;
    400  1.2.34.1   martin 
    401  1.2.34.1   martin 	case WSDISPLAYIO_GETCMAP:
    402  1.2.34.1   martin 		cmapp = (struct wsdisplay_cmap *)data;
    403  1.2.34.1   martin 		idx = cmapp->index;
    404  1.2.34.1   martin 		count = cmapp->count;
    405  1.2.34.1   martin 		if (idx >= STI_NCMAP || count > STI_NCMAP - idx)
    406  1.2.34.1   martin 			return EINVAL;
    407  1.2.34.1   martin 		error = copyout(&scr->scr_rcmap[idx], cmapp->red, count);
    408  1.2.34.1   martin 		if (error != 0)
    409  1.2.34.1   martin 			return error;
    410  1.2.34.1   martin 		error = copyout(&scr->scr_gcmap[idx], cmapp->green, count);
    411  1.2.34.1   martin 		if (error != 0)
    412  1.2.34.1   martin 			return error;
    413  1.2.34.1   martin 		error = copyout(&scr->scr_bcmap[idx], cmapp->blue, count);
    414  1.2.34.1   martin 		if (error != 0)
    415  1.2.34.1   martin 			return error;
    416  1.2.34.1   martin 		return 0;
    417  1.2.34.1   martin 
    418  1.2.34.1   martin 	case WSDISPLAYIO_PUTCMAP:
    419  1.2.34.1   martin 		cmapp = (struct wsdisplay_cmap *)data;
    420  1.2.34.1   martin 		return sti_evrx_setcmap(sc, cmapp);
    421  1.2.34.1   martin 
    422  1.2.34.1   martin 	case WSDISPLAYIO_SMODE:
    423  1.2.34.1   martin 		new_mode = *(int *)data;
    424  1.2.34.1   martin 		if (new_mode != scr->scr_wsmode) {
    425  1.2.34.1   martin 			scr->scr_wsmode = new_mode;
    426  1.2.34.1   martin 			if (new_mode == WSDISPLAYIO_MODE_EMUL) {
    427  1.2.34.1   martin 				sti_init(scr, STI_TEXTMODE);
    428  1.2.34.1   martin 			} else if (new_mode == WSDISPLAYIO_MODE_DUMBFB) {
    429  1.2.34.1   martin 				sti_init(scr, 0);
    430  1.2.34.1   martin 				sti_evrx_resetramdac(sc);
    431  1.2.34.1   martin 			}
    432  1.2.34.1   martin 		}
    433  1.2.34.1   martin 		return 0;
    434  1.2.34.1   martin 
    435  1.2.34.1   martin 	}
    436  1.2.34.1   martin 	return sti_ioctl(v, vs, cmd, data, flag, l);
    437  1.2.34.1   martin }
    438  1.2.34.1   martin 
    439  1.2.34.1   martin static paddr_t
    440  1.2.34.1   martin sti_evrx_mmap(void *v, void *vs, off_t offset, int prot)
    441  1.2.34.1   martin {
    442  1.2.34.1   martin 	struct sti_screen *scr = (struct sti_screen *)v;
    443  1.2.34.1   martin 	struct sti_rom *rom = scr->scr_rom;
    444  1.2.34.1   martin 	struct sti_softc *ssc = rom->rom_softc;
    445  1.2.34.1   martin 	struct sti_sgc_softc *sc = device_private(ssc->sc_dev);
    446  1.2.34.1   martin 	paddr_t cookie = -1;
    447  1.2.34.1   martin 
    448  1.2.34.1   martin 	if ((offset & PAGE_MASK) != 0)
    449  1.2.34.1   martin 		return -1;
    450  1.2.34.1   martin 
    451  1.2.34.1   martin 	switch (scr->scr_wsmode) {
    452  1.2.34.1   martin 	case WSDISPLAYIO_MODE_MAPPED:
    453  1.2.34.1   martin 		/* not implemented yet; what should be shown? */
    454  1.2.34.1   martin 		break;
    455  1.2.34.1   martin 	case WSDISPLAYIO_MODE_DUMBFB:
    456  1.2.34.1   martin 		if (offset >= 0 && offset < (scr->fbwidth * scr->fbheight))
    457  1.2.34.1   martin 			cookie = m68k_btop(sc->sc_bitmap + offset);
    458  1.2.34.1   martin 		break;
    459  1.2.34.1   martin 	default:
    460  1.2.34.1   martin 		break;
    461  1.2.34.1   martin 	}
    462  1.2.34.1   martin 
    463  1.2.34.1   martin 	return cookie;
    464  1.2.34.1   martin }
    465  1.2.34.1   martin 
    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