Home | History | Annotate | Line # | Download | only in dev
ffb_mainbus.c revision 1.9
      1  1.9  macallan /*	$NetBSD: ffb_mainbus.c,v 1.9 2010/09/21 03:31:04 macallan Exp $	*/
      2  1.1    petrov /*	$OpenBSD: creator_mainbus.c,v 1.4 2002/07/26 16:39:04 jason Exp $	*/
      3  1.1    petrov 
      4  1.1    petrov /*
      5  1.1    petrov  * Copyright (c) 2002 Jason L. Wright (jason (at) thought.net),
      6  1.1    petrov  *  Federico G. Schwindt (fgsch (at) openbsd.org)
      7  1.1    petrov  * All rights reserved.
      8  1.1    petrov  *
      9  1.1    petrov  * Redistribution and use in source and binary forms, with or without
     10  1.1    petrov  * modification, are permitted provided that the following conditions
     11  1.1    petrov  * are met:
     12  1.1    petrov  * 1. Redistributions of source code must retain the above copyright
     13  1.1    petrov  *    notice, this list of conditions and the following disclaimer.
     14  1.1    petrov  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1    petrov  *    notice, this list of conditions and the following disclaimer in the
     16  1.1    petrov  *    documentation and/or other materials provided with the distribution.
     17  1.1    petrov  * 3. All advertising materials mentioning features or use of this software
     18  1.1    petrov  *    must display the following acknowledgement:
     19  1.1    petrov  *	This product includes software developed by Jason L. Wright
     20  1.1    petrov  * 4. The name of the author may not be used to endorse or promote products
     21  1.1    petrov  *    derived from this software without specific prior written permission.
     22  1.1    petrov  *
     23  1.1    petrov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  1.1    petrov  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     25  1.1    petrov  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     26  1.1    petrov  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     27  1.1    petrov  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     28  1.1    petrov  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     29  1.1    petrov  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1    petrov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     31  1.1    petrov  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     32  1.1    petrov  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  1.1    petrov  * POSSIBILITY OF SUCH DAMAGE.
     34  1.1    petrov  */
     35  1.2     lukem 
     36  1.2     lukem #include <sys/cdefs.h>
     37  1.9  macallan __KERNEL_RCSID(0, "$NetBSD: ffb_mainbus.c,v 1.9 2010/09/21 03:31:04 macallan Exp $");
     38  1.1    petrov 
     39  1.1    petrov #include <sys/types.h>
     40  1.1    petrov #include <sys/param.h>
     41  1.1    petrov #include <sys/systm.h>
     42  1.1    petrov #include <sys/kernel.h>
     43  1.1    petrov #include <sys/device.h>
     44  1.1    petrov 
     45  1.1    petrov #include <machine/bus.h>
     46  1.1    petrov #include <machine/autoconf.h>
     47  1.1    petrov #include <machine/openfirm.h>
     48  1.1    petrov 
     49  1.1    petrov #include <dev/wscons/wsconsio.h>
     50  1.7    martin #include <dev/sun/fbio.h>
     51  1.7    martin #include <dev/sun/fbvar.h>
     52  1.1    petrov 
     53  1.1    petrov #include <sparc64/dev/ffbreg.h>
     54  1.1    petrov #include <sparc64/dev/ffbvar.h>
     55  1.1    petrov 
     56  1.3    petrov extern int prom_stdout_node;
     57  1.3    petrov 
     58  1.1    petrov int	ffb_mainbus_match(struct device *, struct cfdata *, void *);
     59  1.1    petrov void	ffb_mainbus_attach(struct device *, struct device *, void *);
     60  1.1    petrov 
     61  1.1    petrov CFATTACH_DECL(ffb_mainbus, sizeof(struct ffb_softc),
     62  1.1    petrov 	      ffb_mainbus_match, ffb_mainbus_attach, NULL, NULL);
     63  1.1    petrov 
     64  1.1    petrov int
     65  1.6    martin ffb_mainbus_match(struct device *parent, struct cfdata *match, void *aux)
     66  1.1    petrov {
     67  1.1    petrov 	struct mainbus_attach_args *ma = aux;
     68  1.1    petrov 
     69  1.1    petrov 	if (strcmp(ma->ma_name, "SUNW,ffb") == 0 ||
     70  1.1    petrov 	    strcmp(ma->ma_name, "SUNW,afb") == 0)
     71  1.1    petrov 		return (1);
     72  1.1    petrov 	return (0);
     73  1.1    petrov }
     74  1.1    petrov 
     75  1.1    petrov void
     76  1.6    martin ffb_mainbus_attach(struct device *parent, struct device *self, void *aux)
     77  1.1    petrov {
     78  1.1    petrov 	struct ffb_softc *sc = (struct ffb_softc *)self;
     79  1.1    petrov 	struct mainbus_attach_args *ma = aux;
     80  1.1    petrov 	int i, nregs;
     81  1.1    petrov 
     82  1.1    petrov 	sc->sc_bt = ma->ma_bustag;
     83  1.1    petrov 
     84  1.1    petrov 	nregs = min(ma->ma_nreg, FFB_NREGS);
     85  1.1    petrov 
     86  1.1    petrov 	if (nregs < FFB_REG_DFB24) {
     87  1.1    petrov 		printf(": no dfb24 regs found\n");
     88  1.1    petrov 		goto fail1;
     89  1.1    petrov 	}
     90  1.1    petrov 
     91  1.1    petrov 
     92  1.1    petrov 	if (bus_space_map(sc->sc_bt, ma->ma_reg[FFB_REG_FBC].ur_paddr,
     93  1.1    petrov 	    ma->ma_reg[FFB_REG_FBC].ur_len, 0, &sc->sc_fbc_h)) {
     94  1.1    petrov 		printf(": failed to map fbc\n");
     95  1.9  macallan 		goto fail1;
     96  1.4      heas 	}
     97  1.4      heas 
     98  1.4      heas 	if (bus_space_map(sc->sc_bt, ma->ma_reg[FFB_REG_DAC].ur_paddr,
     99  1.5      heas 	    ma->ma_reg[FFB_REG_DAC].ur_len, 0, &sc->sc_dac_h)) {
    100  1.4      heas 		printf(": failed to map dac\n");
    101  1.4      heas 		goto unmap_fbc;
    102  1.1    petrov 	}
    103  1.1    petrov 
    104  1.1    petrov 	for (i = 0; i < nregs; i++) {
    105  1.1    petrov 		sc->sc_addrs[i] = ma->ma_reg[i].ur_paddr;
    106  1.1    petrov 		sc->sc_sizes[i] = ma->ma_reg[i].ur_len;
    107  1.1    petrov 	}
    108  1.1    petrov 	sc->sc_nreg = nregs;
    109  1.1    petrov 
    110  1.3    petrov 	sc->sc_console = (prom_stdout_node == ma->ma_node);
    111  1.1    petrov 	sc->sc_node = ma->ma_node;
    112  1.1    petrov 
    113  1.1    petrov 	if (strcmp(ma->ma_name, "SUNW,afb") == 0)
    114  1.1    petrov 		sc->sc_type = FFB_AFB;
    115  1.1    petrov 
    116  1.1    petrov 	ffb_attach(sc);
    117  1.1    petrov 
    118  1.1    petrov 	return;
    119  1.1    petrov 
    120  1.4      heas #if notyet
    121  1.4      heas unmap_dac:
    122  1.4      heas 	bus_space_unmap(sc->sc_bt, sc->sc_dac_h,
    123  1.4      heas 		    ma->ma_reg[FFB_REG_DAC].ur_len);
    124  1.4      heas #endif
    125  1.4      heas unmap_fbc:
    126  1.4      heas 	bus_space_unmap(sc->sc_bt, sc->sc_fbc_h,
    127  1.1    petrov 		    ma->ma_reg[FFB_REG_FBC].ur_len);
    128  1.1    petrov fail1:
    129  1.1    petrov 	return;
    130  1.1    petrov }
    131