Home | History | Annotate | Line # | Download | only in dev
sti_sgc.c revision 1.2
      1  1.2  tsutsui /*	$NetBSD: sti_sgc.c,v 1.2 2014/04/20 04:12:54 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.2  tsutsui __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.2 2014/04/20 04:12:54 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.1  tsutsui #include <dev/wscons/wsdisplayvar.h>
     39  1.1  tsutsui 
     40  1.1  tsutsui #include <dev/ic/stireg.h>
     41  1.1  tsutsui #include <dev/ic/stivar.h>
     42  1.1  tsutsui 
     43  1.1  tsutsui #include <hp300/dev/sgcvar.h>
     44  1.2  tsutsui #include <hp300/dev/sti_sgcvar.h>
     45  1.2  tsutsui #include <machine/autoconf.h>
     46  1.1  tsutsui 
     47  1.2  tsutsui static int sticonslot = -1;
     48  1.2  tsutsui static struct sti_rom sticn_rom;
     49  1.2  tsutsui static struct sti_screen sticn_scr;
     50  1.2  tsutsui static bus_addr_t sticn_bases[STI_REGION_MAX];
     51  1.1  tsutsui 
     52  1.1  tsutsui static int sti_sgc_match(device_t, struct cfdata *, void *);
     53  1.1  tsutsui static void sti_sgc_attach(device_t, device_t, void *);
     54  1.1  tsutsui 
     55  1.1  tsutsui static int sti_sgc_probe(bus_space_tag_t, int);
     56  1.1  tsutsui 
     57  1.1  tsutsui CFATTACH_DECL_NEW(sti_sgc, sizeof(struct sti_softc),
     58  1.1  tsutsui     sti_sgc_match, sti_sgc_attach, NULL, NULL);
     59  1.1  tsutsui 
     60  1.1  tsutsui static int
     61  1.1  tsutsui sti_sgc_match(device_t parent, struct cfdata *cf, void *aux)
     62  1.1  tsutsui {
     63  1.1  tsutsui 	struct sgc_attach_args *saa = aux;
     64  1.1  tsutsui 
     65  1.1  tsutsui 	/*
     66  1.1  tsutsui 	 * If we already probed it successfully as a console device, go ahead,
     67  1.1  tsutsui 	 * since we will not be able to bus_space_map() again.
     68  1.1  tsutsui 	 */
     69  1.1  tsutsui 	if (saa->saa_slot == sticonslot)
     70  1.1  tsutsui 		return 1;
     71  1.1  tsutsui 
     72  1.1  tsutsui 	return sti_sgc_probe(saa->saa_iot, saa->saa_slot);
     73  1.1  tsutsui }
     74  1.1  tsutsui 
     75  1.1  tsutsui static void
     76  1.1  tsutsui sti_sgc_attach(device_t parent, device_t self, void *aux)
     77  1.1  tsutsui {
     78  1.1  tsutsui 	struct sti_softc *sc = device_private(self);
     79  1.1  tsutsui 	struct sgc_attach_args *saa = aux;
     80  1.2  tsutsui 	bus_space_handle_t romh;
     81  1.2  tsutsui 	bus_addr_t base;
     82  1.1  tsutsui 	u_int romend;
     83  1.1  tsutsui 	int i;
     84  1.1  tsutsui 
     85  1.2  tsutsui 	sc->sc_dev = self;
     86  1.2  tsutsui 
     87  1.2  tsutsui 	if (saa->saa_slot == sticonslot) {
     88  1.2  tsutsui 		sc->sc_flags |= STI_CONSOLE | STI_ATTACHED;
     89  1.2  tsutsui 		sc->sc_rom = &sticn_rom;
     90  1.2  tsutsui 		sc->sc_scr = &sticn_scr;
     91  1.2  tsutsui 		memcpy(sc->bases, sticn_bases, sizeof(sc->bases));
     92  1.2  tsutsui 
     93  1.2  tsutsui 		sti_describe(sc);
     94  1.2  tsutsui 	} else {
     95  1.2  tsutsui 		base = (bus_addr_t)sgc_slottopa(saa->saa_slot);
     96  1.2  tsutsui 		if (bus_space_map(saa->saa_iot, base, PAGE_SIZE, 0, &romh)) {
     97  1.2  tsutsui 			aprint_error(": can't map ROM");
     98  1.2  tsutsui 			return;
     99  1.2  tsutsui 		}
    100  1.2  tsutsui 		/*
    101  1.2  tsutsui 		 * Compute real PROM size
    102  1.2  tsutsui 		 */
    103  1.2  tsutsui 		romend = sti_rom_size(saa->saa_iot, romh);
    104  1.2  tsutsui 
    105  1.2  tsutsui 		bus_space_unmap(saa->saa_iot, romh, PAGE_SIZE);
    106  1.2  tsutsui 
    107  1.2  tsutsui 		if (bus_space_map(saa->saa_iot, base, romend, 0, &romh)) {
    108  1.2  tsutsui 			aprint_error(": can't map frame buffer");
    109  1.2  tsutsui 			return;
    110  1.2  tsutsui 		}
    111  1.2  tsutsui 
    112  1.2  tsutsui 		sc->bases[0] = romh;
    113  1.2  tsutsui 		for (i = 0; i < STI_REGION_MAX; i++)
    114  1.2  tsutsui 			sc->bases[i] = base;
    115  1.2  tsutsui 
    116  1.2  tsutsui 		if (sti_attach_common(sc, saa->saa_iot, saa->saa_iot, romh,
    117  1.2  tsutsui 		    STI_CODEBASE_ALT) != 0)
    118  1.2  tsutsui 			return;
    119  1.1  tsutsui 	}
    120  1.1  tsutsui 
    121  1.2  tsutsui 	/*
    122  1.2  tsutsui 	 * Note on 425e sti(4) framebuffer bitmap memory can be accessed at
    123  1.2  tsutsui 	 * (sgc_slottopa(saa->saa_slot) + 0x200000)
    124  1.2  tsutsui 	 * but the mmap function to map bitmap display is not provided yet.
    125  1.2  tsutsui 	 */
    126  1.1  tsutsui 
    127  1.2  tsutsui 	sti_end_attach(sc);
    128  1.1  tsutsui }
    129  1.1  tsutsui 
    130  1.1  tsutsui static int
    131  1.1  tsutsui sti_sgc_probe(bus_space_tag_t iot, int slot)
    132  1.1  tsutsui {
    133  1.1  tsutsui 	bus_space_handle_t ioh;
    134  1.1  tsutsui 	int devtype;
    135  1.1  tsutsui 
    136  1.2  tsutsui 	if (bus_space_map(iot, (bus_addr_t)sgc_slottopa(slot),
    137  1.2  tsutsui 	    PAGE_SIZE, 0, &ioh))
    138  1.1  tsutsui 		return 0;
    139  1.2  tsutsui 
    140  1.1  tsutsui 	devtype = bus_space_read_1(iot, ioh, 3);
    141  1.2  tsutsui 
    142  1.1  tsutsui 	bus_space_unmap(iot, ioh, PAGE_SIZE);
    143  1.1  tsutsui 
    144  1.1  tsutsui 	/*
    145  1.1  tsutsui 	 * This might not be reliable enough. On the other hand, non-STI
    146  1.1  tsutsui 	 * SGC cards will apparently not initialize in an hp300, to the
    147  1.1  tsutsui 	 * point of not even answering bus probes (checked with an
    148  1.1  tsutsui 	 * Harmony/FDDI SGC card).
    149  1.1  tsutsui 	 */
    150  1.2  tsutsui 	if (devtype != STI_DEVTYPE1 && devtype != STI_DEVTYPE4)
    151  1.1  tsutsui 		return 0;
    152  1.2  tsutsui 
    153  1.1  tsutsui 	return 1;
    154  1.1  tsutsui }
    155  1.1  tsutsui 
    156  1.2  tsutsui int
    157  1.2  tsutsui sti_sgc_cnprobe(bus_space_tag_t bst, bus_addr_t addr, int slot)
    158  1.2  tsutsui {
    159  1.2  tsutsui 	void *va;
    160  1.2  tsutsui 	bus_space_handle_t romh;
    161  1.2  tsutsui 	int devtype, rv = 0;
    162  1.2  tsutsui 
    163  1.2  tsutsui 	if (bus_space_map(bst, addr, PAGE_SIZE, 0, &romh))
    164  1.2  tsutsui 		return 0;
    165  1.2  tsutsui 
    166  1.2  tsutsui 	va = bus_space_vaddr(bst, romh);
    167  1.2  tsutsui 	if (badaddr(va))
    168  1.2  tsutsui 		goto out;
    169  1.2  tsutsui 
    170  1.2  tsutsui 	devtype = bus_space_read_1(bst, romh, 3);
    171  1.2  tsutsui 	if (devtype == STI_DEVTYPE1 || devtype == STI_DEVTYPE4)
    172  1.2  tsutsui 		rv = 1;
    173  1.2  tsutsui 
    174  1.2  tsutsui  out:
    175  1.2  tsutsui 	bus_space_unmap(bst, romh, PAGE_SIZE);
    176  1.2  tsutsui 	return rv;
    177  1.2  tsutsui }
    178  1.2  tsutsui 
    179  1.2  tsutsui void
    180  1.2  tsutsui sti_sgc_cnattach(bus_space_tag_t bst, bus_addr_t addr, int slot)
    181  1.1  tsutsui {
    182  1.2  tsutsui 	int i;
    183  1.2  tsutsui 
    184  1.2  tsutsui 	/* sticn_bases[0] will be fixed in sti_cnattach() */
    185  1.2  tsutsui 	for (i = 0; i < STI_REGION_MAX; i++)
    186  1.2  tsutsui 		sticn_bases[i] = addr;
    187  1.2  tsutsui 
    188  1.2  tsutsui 	sti_cnattach(&sticn_rom, &sticn_scr, bst, sticn_bases,
    189  1.2  tsutsui 	    STI_CODEBASE_ALT);
    190  1.1  tsutsui 
    191  1.2  tsutsui 	sticonslot = slot;
    192  1.1  tsutsui }
    193