Home | History | Annotate | Line # | Download | only in dev
sti_sgc.c revision 1.1.14.1
      1  1.1.14.1      tls /*	$NetBSD: sti_sgc.c,v 1.1.14.1 2014/08/10 06:53:57 tls 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.1.14.1      tls __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.1.14.1 2014/08/10 06:53:57 tls 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.1.14.1      tls #include <hp300/dev/sti_sgcvar.h>
     45  1.1.14.1      tls #include <machine/autoconf.h>
     46       1.1  tsutsui 
     47  1.1.14.1      tls static int sticonslot = -1;
     48  1.1.14.1      tls static struct sti_rom sticn_rom;
     49  1.1.14.1      tls static struct sti_screen sticn_scr;
     50  1.1.14.1      tls 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.1.14.1      tls 	bus_space_handle_t romh;
     81  1.1.14.1      tls 	bus_addr_t base;
     82       1.1  tsutsui 	u_int romend;
     83       1.1  tsutsui 	int i;
     84       1.1  tsutsui 
     85       1.1  tsutsui 	sc->sc_dev = self;
     86       1.1  tsutsui 
     87  1.1.14.1      tls 	if (saa->saa_slot == sticonslot) {
     88  1.1.14.1      tls 		sc->sc_flags |= STI_CONSOLE | STI_ATTACHED;
     89  1.1.14.1      tls 		sc->sc_rom = &sticn_rom;
     90  1.1.14.1      tls 		sc->sc_scr = &sticn_scr;
     91  1.1.14.1      tls 		memcpy(sc->bases, sticn_bases, sizeof(sc->bases));
     92  1.1.14.1      tls 
     93  1.1.14.1      tls 		sti_describe(sc);
     94  1.1.14.1      tls 	} else {
     95  1.1.14.1      tls 		base = (bus_addr_t)sgc_slottopa(saa->saa_slot);
     96  1.1.14.1      tls 		if (bus_space_map(saa->saa_iot, base, PAGE_SIZE, 0, &romh)) {
     97  1.1.14.1      tls 			aprint_error(": can't map ROM");
     98  1.1.14.1      tls 			return;
     99  1.1.14.1      tls 		}
    100  1.1.14.1      tls 		/*
    101  1.1.14.1      tls 		 * Compute real PROM size
    102  1.1.14.1      tls 		 */
    103  1.1.14.1      tls 		romend = sti_rom_size(saa->saa_iot, romh);
    104  1.1.14.1      tls 
    105  1.1.14.1      tls 		bus_space_unmap(saa->saa_iot, romh, PAGE_SIZE);
    106  1.1.14.1      tls 
    107  1.1.14.1      tls 		if (bus_space_map(saa->saa_iot, base, romend, 0, &romh)) {
    108  1.1.14.1      tls 			aprint_error(": can't map frame buffer");
    109  1.1.14.1      tls 			return;
    110  1.1.14.1      tls 		}
    111  1.1.14.1      tls 
    112  1.1.14.1      tls 		sc->bases[0] = romh;
    113  1.1.14.1      tls 		for (i = 0; i < STI_REGION_MAX; i++)
    114  1.1.14.1      tls 			sc->bases[i] = base;
    115  1.1.14.1      tls 
    116  1.1.14.1      tls 		if (sti_attach_common(sc, saa->saa_iot, saa->saa_iot, romh,
    117  1.1.14.1      tls 		    STI_CODEBASE_ALT) != 0)
    118  1.1.14.1      tls 			return;
    119       1.1  tsutsui 	}
    120  1.1.14.1      tls 
    121  1.1.14.1      tls 	/*
    122  1.1.14.1      tls 	 * Note on 425e sti(4) framebuffer bitmap memory can be accessed at
    123  1.1.14.1      tls 	 * (sgc_slottopa(saa->saa_slot) + 0x200000)
    124  1.1.14.1      tls 	 * but the mmap function to map bitmap display is not provided yet.
    125  1.1.14.1      tls 	 */
    126  1.1.14.1      tls 
    127  1.1.14.1      tls 	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.1.14.1      tls 	if (bus_space_map(iot, (bus_addr_t)sgc_slottopa(slot),
    137  1.1.14.1      tls 	    PAGE_SIZE, 0, &ioh))
    138       1.1  tsutsui 		return 0;
    139  1.1.14.1      tls 
    140       1.1  tsutsui 	devtype = bus_space_read_1(iot, ioh, 3);
    141  1.1.14.1      tls 
    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.1.14.1      tls 	if (devtype != STI_DEVTYPE1 && devtype != STI_DEVTYPE4)
    151       1.1  tsutsui 		return 0;
    152  1.1.14.1      tls 
    153       1.1  tsutsui 	return 1;
    154       1.1  tsutsui }
    155       1.1  tsutsui 
    156  1.1.14.1      tls int
    157  1.1.14.1      tls sti_sgc_cnprobe(bus_space_tag_t bst, bus_addr_t addr, int slot)
    158       1.1  tsutsui {
    159  1.1.14.1      tls 	void *va;
    160  1.1.14.1      tls 	bus_space_handle_t romh;
    161  1.1.14.1      tls 	int devtype, rv = 0;
    162       1.1  tsutsui 
    163  1.1.14.1      tls 	if (bus_space_map(bst, addr, PAGE_SIZE, 0, &romh))
    164  1.1.14.1      tls 		return 0;
    165  1.1.14.1      tls 
    166  1.1.14.1      tls 	va = bus_space_vaddr(bst, romh);
    167  1.1.14.1      tls 	if (badaddr(va))
    168  1.1.14.1      tls 		goto out;
    169  1.1.14.1      tls 
    170  1.1.14.1      tls 	devtype = bus_space_read_1(bst, romh, 3);
    171  1.1.14.1      tls 	if (devtype == STI_DEVTYPE1 || devtype == STI_DEVTYPE4)
    172  1.1.14.1      tls 		rv = 1;
    173  1.1.14.1      tls 
    174  1.1.14.1      tls  out:
    175  1.1.14.1      tls 	bus_space_unmap(bst, romh, PAGE_SIZE);
    176  1.1.14.1      tls 	return rv;
    177  1.1.14.1      tls }
    178  1.1.14.1      tls 
    179  1.1.14.1      tls void
    180  1.1.14.1      tls sti_sgc_cnattach(bus_space_tag_t bst, bus_addr_t addr, int slot)
    181  1.1.14.1      tls {
    182  1.1.14.1      tls 	int i;
    183  1.1.14.1      tls 
    184  1.1.14.1      tls 	/* sticn_bases[0] will be fixed in sti_cnattach() */
    185  1.1.14.1      tls 	for (i = 0; i < STI_REGION_MAX; i++)
    186  1.1.14.1      tls 		sticn_bases[i] = addr;
    187  1.1.14.1      tls 
    188  1.1.14.1      tls 	sti_cnattach(&sticn_rom, &sticn_scr, bst, sticn_bases,
    189  1.1.14.1      tls 	    STI_CODEBASE_ALT);
    190  1.1.14.1      tls 
    191  1.1.14.1      tls 	sticonslot = slot;
    192       1.1  tsutsui }
    193