Home | History | Annotate | Line # | Download | only in dev
sti_sgc.c revision 1.4
      1  1.4  tsutsui /*	$NetBSD: sti_sgc.c,v 1.4 2020/12/23 08:36:47 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.4  tsutsui __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.4 2020/12/23 08:36:47 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 };
     53  1.3  tsutsui 
     54  1.3  tsutsui /*
     55  1.3  tsutsui  * 425e EVRX specific hardware
     56  1.3  tsutsui  */
     57  1.4  tsutsui /*
     58  1.4  tsutsui  * EVRX RAMDAC (Bt458) is found at offset 0x060000 from SGC bus PA and
     59  1.4  tsutsui  * offset 0x040000 length 0x1c0000 is mapped in MI sti via ROM region 2
     60  1.4  tsutsui  */
     61  1.4  tsutsui #define STI_EVRX_REGNO2OFFSET	0x020000
     62  1.3  tsutsui #define STI_EVRX_FBOFFSET	0x200000
     63  1.3  tsutsui 
     64  1.4  tsutsui #define EVRX_BT458_ADDR		(STI_EVRX_REGNO2OFFSET + 0x200 + 2)
     65  1.4  tsutsui #define EVRX_BT458_CMAP		(STI_EVRX_REGNO2OFFSET + 0x204 + 2)
     66  1.4  tsutsui #define EVRX_BT458_CTRL		(STI_EVRX_REGNO2OFFSET + 0x208 + 2)
     67  1.4  tsutsui #define EVRX_BT458_OMAP		(STI_EVRX_REGNO2OFFSET + 0x20C + 2)
     68  1.3  tsutsui 
     69  1.3  tsutsui /* from HP-UX /usr/lib/libddevrx.a */
     70  1.4  tsutsui #define EVRX_MAGIC00		(STI_EVRX_REGNO2OFFSET + 0x600)
     71  1.4  tsutsui #define EVRX_MAGIC04		(STI_EVRX_REGNO2OFFSET + 0x604)
     72  1.4  tsutsui #define EVRX_MAGIC08		(STI_EVRX_REGNO2OFFSET + 0x608)
     73  1.4  tsutsui #define EVRX_MAGIC0C		(STI_EVRX_REGNO2OFFSET + 0x60c)
     74  1.4  tsutsui #define EVRX_MAGIC10		(STI_EVRX_REGNO2OFFSET + 0x610)
     75  1.3  tsutsui #define EVRX_MAGIC10_BSY	0x00010000
     76  1.4  tsutsui #define EVRX_MAGIC18		(STI_EVRX_REGNO2OFFSET + 0x618)
     77  1.4  tsutsui #define EVRX_MAGIC1C		(STI_EVRX_REGNO2OFFSET + 0x61c)
     78  1.4  tsutsui 
     79  1.4  tsutsui /*
     80  1.4  tsutsui  * HP A1659A CRX specific hardware
     81  1.4  tsutsui  */
     82  1.4  tsutsui #define STI_CRX_FBOFFSET	0x01000000
     83  1.3  tsutsui 
     84  1.2  tsutsui static int sticonslot = -1;
     85  1.4  tsutsui 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.3  tsutsui 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.4  tsutsui /* 425e EVRX/CRX specific access functions */
     99  1.4  tsutsui static int sti_evrx_putcmap(struct sti_screen *, u_int, u_int);
    100  1.4  tsutsui static void sti_evrx_resetramdac(struct sti_screen *);
    101  1.4  tsutsui static void sti_evrx_resetcmap(struct sti_screen *);
    102  1.4  tsutsui static void sti_evrx_setupfb(struct sti_screen *);
    103  1.4  tsutsui static paddr_t sti_m68k_mmap(void *, void *, off_t, int);
    104  1.4  tsutsui 
    105  1.4  tsutsui static const struct wsdisplay_accessops sti_m68k_accessops = {
    106  1.4  tsutsui 	sti_ioctl,
    107  1.4  tsutsui 	sti_m68k_mmap,
    108  1.3  tsutsui 	sti_alloc_screen,
    109  1.3  tsutsui 	sti_free_screen,
    110  1.3  tsutsui 	sti_show_screen,
    111  1.3  tsutsui 	sti_load_font
    112  1.3  tsutsui };
    113  1.3  tsutsui 
    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.3  tsutsui 	struct sti_sgc_softc *sc = device_private(self);
    133  1.3  tsutsui 	struct sti_softc *ssc = &sc->sc_sti;
    134  1.1  tsutsui 	struct sgc_attach_args *saa = aux;
    135  1.3  tsutsui 	struct sti_screen *scr;
    136  1.4  tsutsui 	bus_space_tag_t bst;
    137  1.2  tsutsui 	bus_space_handle_t romh;
    138  1.2  tsutsui 	bus_addr_t base;
    139  1.3  tsutsui 	struct wsemuldisplaydev_attach_args waa;
    140  1.1  tsutsui 	u_int romend;
    141  1.3  tsutsui 	struct sti_dd *rom_dd;
    142  1.3  tsutsui 	uint32_t grid0;
    143  1.1  tsutsui 	int i;
    144  1.1  tsutsui 
    145  1.3  tsutsui 	ssc->sc_dev = self;
    146  1.4  tsutsui 	bst = saa->saa_iot;
    147  1.3  tsutsui 	base = (bus_addr_t)sgc_slottopa(saa->saa_slot);
    148  1.2  tsutsui 
    149  1.2  tsutsui 	if (saa->saa_slot == sticonslot) {
    150  1.3  tsutsui 		ssc->sc_flags |= STI_CONSOLE | STI_ATTACHED;
    151  1.3  tsutsui 		ssc->sc_rom = &sticn_rom;
    152  1.3  tsutsui 		ssc->sc_rom->rom_softc = ssc;
    153  1.3  tsutsui 		ssc->sc_scr = &sticn_scr;
    154  1.3  tsutsui 		ssc->sc_scr->scr_rom = ssc->sc_rom;
    155  1.3  tsutsui 		memcpy(ssc->bases, sticn_bases, sizeof(ssc->bases));
    156  1.2  tsutsui 
    157  1.3  tsutsui 		sti_describe(ssc);
    158  1.2  tsutsui 	} else {
    159  1.4  tsutsui 		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.4  tsutsui 		romend = sti_rom_size(bst, romh);
    167  1.2  tsutsui 
    168  1.4  tsutsui 		bus_space_unmap(bst, romh, PAGE_SIZE);
    169  1.2  tsutsui 
    170  1.4  tsutsui 		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.3  tsutsui 		ssc->bases[0] = romh;
    176  1.2  tsutsui 		for (i = 0; i < STI_REGION_MAX; i++)
    177  1.3  tsutsui 			ssc->bases[i] = base;
    178  1.2  tsutsui 
    179  1.4  tsutsui 		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.3  tsutsui 	/* Identify the board model by dd_grid */
    185  1.3  tsutsui 	rom_dd = &ssc->sc_rom->rom_dd;
    186  1.3  tsutsui 	grid0 = rom_dd->dd_grid[0];
    187  1.3  tsutsui 	scr = ssc->sc_scr;
    188  1.3  tsutsui 
    189  1.3  tsutsui 	switch (grid0) {
    190  1.3  tsutsui 	case STI_DD_EVRX:
    191  1.3  tsutsui 		/*
    192  1.3  tsutsui 		 * 425e on-board EVRX framebuffer.
    193  1.3  tsutsui 		 * bitmap memory can be accessed at offset +0x200000.
    194  1.3  tsutsui 		 */
    195  1.3  tsutsui 		sc->sc_bitmap = base + STI_EVRX_FBOFFSET;
    196  1.3  tsutsui 
    197  1.3  tsutsui 		aprint_normal_dev(self, "Enable mmap support\n");
    198  1.3  tsutsui 
    199  1.3  tsutsui 		/*
    200  1.3  tsutsui 		 * initialize Bt458 RAMDAC and preserve initial color map
    201  1.3  tsutsui 		 */
    202  1.4  tsutsui 		sti_evrx_resetramdac(scr);
    203  1.4  tsutsui 		sti_evrx_resetcmap(scr);
    204  1.4  tsutsui 
    205  1.4  tsutsui 		scr->setupfb = sti_evrx_setupfb;
    206  1.4  tsutsui 		scr->putcmap = sti_evrx_putcmap;
    207  1.3  tsutsui 
    208  1.3  tsutsui 		scr->scr_wsmode = WSDISPLAYIO_MODE_EMUL;
    209  1.3  tsutsui 		waa.console = ssc->sc_flags & STI_CONSOLE ? 1 : 0;
    210  1.3  tsutsui 		waa.scrdata = &scr->scr_screenlist;
    211  1.4  tsutsui 		waa.accessops = &sti_m68k_accessops;
    212  1.3  tsutsui 		waa.accesscookie = scr;
    213  1.3  tsutsui 
    214  1.3  tsutsui 		config_found(ssc->sc_dev, &waa, wsemuldisplaydevprint);
    215  1.3  tsutsui 		break;
    216  1.1  tsutsui 
    217  1.3  tsutsui 	case STI_DD_CRX:
    218  1.3  tsutsui 		/*
    219  1.3  tsutsui 		 * HP A1659A CRX on some 425t variants.
    220  1.4  tsutsui 		 * bitmap memory can be accessed at offset +0x1000000.
    221  1.3  tsutsui 		 */
    222  1.4  tsutsui 		sc->sc_bitmap = base + STI_CRX_FBOFFSET;
    223  1.4  tsutsui 
    224  1.4  tsutsui 		aprint_normal_dev(self, "Enable mmap support\n");
    225  1.4  tsutsui 
    226  1.4  tsutsui 		scr->scr_wsmode = WSDISPLAYIO_MODE_EMUL;
    227  1.4  tsutsui 		waa.console = ssc->sc_flags & STI_CONSOLE ? 1 : 0;
    228  1.4  tsutsui 		waa.scrdata = &scr->scr_screenlist;
    229  1.4  tsutsui 		waa.accessops = &sti_m68k_accessops;
    230  1.4  tsutsui 		waa.accesscookie = scr;
    231  1.4  tsutsui 
    232  1.4  tsutsui 		config_found(ssc->sc_dev, &waa, wsemuldisplaydevprint);
    233  1.4  tsutsui 		break;
    234  1.3  tsutsui 	default:
    235  1.3  tsutsui 		/*
    236  1.3  tsutsui 		 * Unsupported variants.
    237  1.3  tsutsui 		 * Use default common sti(4) attachment (no bitmap support).
    238  1.3  tsutsui 		 */
    239  1.3  tsutsui 		sti_end_attach(ssc);
    240  1.3  tsutsui 		break;
    241  1.3  tsutsui 	}
    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.3  tsutsui static int
    271  1.4  tsutsui sti_evrx_putcmap(struct sti_screen *scr, u_int index, u_int count)
    272  1.3  tsutsui {
    273  1.4  tsutsui 	struct sti_rom *rom = scr->scr_rom;
    274  1.4  tsutsui 	bus_space_tag_t bst = rom->memt;
    275  1.4  tsutsui 	bus_space_handle_t bsh = rom->regh[2];
    276  1.4  tsutsui 	int i;
    277  1.3  tsutsui 
    278  1.3  tsutsui 	/* magic setup from HP-UX */
    279  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
    280  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
    281  1.3  tsutsui 	for (i = index; i < index + count; i++) {
    282  1.3  tsutsui 		/* this is what HP-UX woodDownloadCmap() does */
    283  1.3  tsutsui 		while ((bus_space_read_4(bst, bsh, EVRX_MAGIC10) &
    284  1.3  tsutsui 		    EVRX_MAGIC10_BSY) != 0)
    285  1.3  tsutsui 			continue;
    286  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, i);
    287  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_CMAP, scr->scr_rcmap[i]);
    288  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_CMAP, scr->scr_gcmap[i]);
    289  1.3  tsutsui 		bus_space_write_4(bst, bsh, EVRX_MAGIC10,   scr->scr_bcmap[i]);
    290  1.3  tsutsui 	}
    291  1.3  tsutsui 	return 0;
    292  1.3  tsutsui }
    293  1.3  tsutsui 
    294  1.3  tsutsui static void
    295  1.4  tsutsui sti_evrx_resetramdac(struct sti_screen *scr)
    296  1.3  tsutsui {
    297  1.4  tsutsui 	struct sti_rom *rom = scr->scr_rom;
    298  1.4  tsutsui 	bus_space_tag_t bst = rom->memt;
    299  1.4  tsutsui 	bus_space_handle_t bsh = rom->regh[2];
    300  1.3  tsutsui #if 0
    301  1.3  tsutsui 	int i;
    302  1.3  tsutsui #endif
    303  1.3  tsutsui 
    304  1.3  tsutsui 	/*
    305  1.3  tsutsui 	 * Initialize the Bt458.  When we write to control registers,
    306  1.3  tsutsui 	 * the address is not incremented automatically. So we specify
    307  1.3  tsutsui 	 * it ourselves for each control register.
    308  1.3  tsutsui 	 */
    309  1.3  tsutsui 
    310  1.3  tsutsui 	/* all planes will be read */
    311  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x04);
    312  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0xff);
    313  1.3  tsutsui 
    314  1.3  tsutsui 	/* all planes have non-blink */
    315  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x05);
    316  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x00);
    317  1.3  tsutsui 
    318  1.3  tsutsui 	/* pallete enabled, ovly plane disabled */
    319  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x06);
    320  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x40);
    321  1.3  tsutsui 
    322  1.3  tsutsui 	/* no test mode */
    323  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x07);
    324  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_CTRL, 0x00);
    325  1.3  tsutsui 
    326  1.3  tsutsui 	/* magic initialization from HP-UX woodInitializeHardware() */
    327  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
    328  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC04, 0x00000001);
    329  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
    330  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC0C, 0x00000001);
    331  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC18, 0xFFFFFFFF);
    332  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC1C, 0x00000000);
    333  1.3  tsutsui 
    334  1.3  tsutsui #if 0
    335  1.3  tsutsui 	bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, 0x00);
    336  1.3  tsutsui 	for (i = 0; i < 4; i++) {
    337  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
    338  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
    339  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_OMAP, 0x00);
    340  1.3  tsutsui 	}
    341  1.3  tsutsui #endif
    342  1.3  tsutsui }
    343  1.3  tsutsui 
    344  1.3  tsutsui static void
    345  1.4  tsutsui sti_evrx_resetcmap(struct sti_screen *scr)
    346  1.3  tsutsui {
    347  1.4  tsutsui 	struct sti_rom *rom = scr->scr_rom;
    348  1.4  tsutsui 	bus_space_tag_t bst = rom->memt;
    349  1.4  tsutsui 	bus_space_handle_t bsh = rom->regh[2];
    350  1.3  tsutsui 	int i;
    351  1.3  tsutsui 
    352  1.3  tsutsui 	/* magic setup from HP-UX */
    353  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC08, 0x00000001);
    354  1.3  tsutsui 	bus_space_write_4(bst, bsh, EVRX_MAGIC00, 0x00000001);
    355  1.3  tsutsui 
    356  1.3  tsutsui 	/* preserve palette values initialized by STI firmware */
    357  1.3  tsutsui 	for (i = 0; i < STI_NCMAP; i++) {
    358  1.3  tsutsui 		/* this is what HP-UX woodUploadCmap() does */
    359  1.3  tsutsui 		while ((bus_space_read_4(bst, bsh, EVRX_MAGIC10) &
    360  1.3  tsutsui 		    EVRX_MAGIC10_BSY) != 0)
    361  1.3  tsutsui 			continue;
    362  1.3  tsutsui 		bus_space_write_1(bst, bsh, EVRX_BT458_ADDR, i);
    363  1.3  tsutsui 		scr->scr_rcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
    364  1.3  tsutsui 		scr->scr_gcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
    365  1.3  tsutsui 		scr->scr_bcmap[i] = bus_space_read_1(bst, bsh, EVRX_BT458_CMAP);
    366  1.3  tsutsui 	}
    367  1.3  tsutsui }
    368  1.3  tsutsui 
    369  1.4  tsutsui static void
    370  1.4  tsutsui sti_evrx_setupfb(struct sti_screen *scr)
    371  1.3  tsutsui {
    372  1.3  tsutsui 
    373  1.4  tsutsui 	sti_init(scr, 0);
    374  1.4  tsutsui 	sti_evrx_resetramdac(scr);
    375  1.3  tsutsui }
    376  1.3  tsutsui 
    377  1.3  tsutsui static paddr_t
    378  1.4  tsutsui sti_m68k_mmap(void *v, void *vs, off_t offset, int prot)
    379  1.3  tsutsui {
    380  1.3  tsutsui 	struct sti_screen *scr = (struct sti_screen *)v;
    381  1.3  tsutsui 	struct sti_rom *rom = scr->scr_rom;
    382  1.3  tsutsui 	struct sti_softc *ssc = rom->rom_softc;
    383  1.3  tsutsui 	struct sti_sgc_softc *sc = device_private(ssc->sc_dev);
    384  1.3  tsutsui 	paddr_t cookie = -1;
    385  1.3  tsutsui 
    386  1.3  tsutsui 	if ((offset & PAGE_MASK) != 0)
    387  1.3  tsutsui 		return -1;
    388  1.3  tsutsui 
    389  1.3  tsutsui 	switch (scr->scr_wsmode) {
    390  1.3  tsutsui 	case WSDISPLAYIO_MODE_MAPPED:
    391  1.3  tsutsui 		/* not implemented yet; what should be shown? */
    392  1.3  tsutsui 		break;
    393  1.3  tsutsui 	case WSDISPLAYIO_MODE_DUMBFB:
    394  1.3  tsutsui 		if (offset >= 0 && offset < (scr->fbwidth * scr->fbheight))
    395  1.3  tsutsui 			cookie = m68k_btop(sc->sc_bitmap + offset);
    396  1.3  tsutsui 		break;
    397  1.3  tsutsui 	default:
    398  1.3  tsutsui 		break;
    399  1.3  tsutsui 	}
    400  1.3  tsutsui 
    401  1.3  tsutsui 	return cookie;
    402  1.3  tsutsui }
    403  1.3  tsutsui 
    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.4  tsutsui 	sticn_tag = *bst;
    433  1.4  tsutsui 
    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.4  tsutsui 	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