Home | History | Annotate | Line # | Download | only in dev
fhc_mainbus.c revision 1.2.6.1
      1  1.2.6.1  mrg /*	$NetBSD: fhc_mainbus.c,v 1.2.6.1 2012/04/05 21:33:19 mrg Exp $	*/
      2      1.1  mrg /*	$OpenBSD: fhc_mainbus.c,v 1.4 2004/09/27 18:32:35 jason Exp $	*/
      3      1.1  mrg 
      4      1.1  mrg /*
      5      1.1  mrg  * Copyright (c) 2004 Jason L. Wright (jason (at) thought.net).
      6      1.1  mrg  * All rights reserved.
      7      1.1  mrg  *
      8      1.1  mrg  * Redistribution and use in source and binary forms, with or without
      9      1.1  mrg  * modification, are permitted provided that the following conditions
     10      1.1  mrg  * are met:
     11      1.1  mrg  * 1. Redistributions of source code must retain the above copyright
     12      1.1  mrg  *    notice, this list of conditions and the following disclaimer.
     13      1.1  mrg  * 2. Redistributions in binary form must reproduce the above copyright
     14      1.1  mrg  *    notice, this list of conditions and the following disclaimer in the
     15      1.1  mrg  *    documentation and/or other materials provided with the distribution.
     16      1.1  mrg  *
     17      1.1  mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18      1.1  mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     19      1.1  mrg  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     20      1.1  mrg  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     21      1.1  mrg  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     22      1.1  mrg  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     23      1.1  mrg  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24      1.1  mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     25      1.1  mrg  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     26      1.1  mrg  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27      1.1  mrg  * POSSIBILITY OF SUCH DAMAGE.
     28      1.1  mrg  */
     29      1.1  mrg 
     30  1.2.6.1  mrg #include <sys/cdefs.h>
     31  1.2.6.1  mrg __KERNEL_RCSID(0, "$NetBSD: fhc_mainbus.c,v 1.2.6.1 2012/04/05 21:33:19 mrg Exp $");
     32  1.2.6.1  mrg 
     33      1.1  mrg #include <sys/types.h>
     34      1.1  mrg #include <sys/param.h>
     35      1.1  mrg #include <sys/systm.h>
     36      1.1  mrg #include <sys/kernel.h>
     37      1.1  mrg #include <sys/device.h>
     38      1.1  mrg #include <sys/conf.h>
     39      1.1  mrg #include <sys/bus.h>
     40      1.1  mrg 
     41      1.1  mrg #include <machine/autoconf.h>
     42      1.1  mrg #include <machine/openfirm.h>
     43      1.1  mrg 
     44      1.1  mrg #include <sparc64/dev/fhcvar.h>
     45      1.1  mrg 
     46      1.1  mrg int	fhc_mainbus_match(device_t, cfdata_t, void *);
     47      1.1  mrg void	fhc_mainbus_attach(device_t, device_t, void *);
     48      1.1  mrg 
     49      1.1  mrg CFATTACH_DECL_NEW(fhc_mainbus, sizeof(struct fhc_softc),
     50      1.1  mrg     fhc_mainbus_match, fhc_mainbus_attach, NULL, NULL);
     51      1.1  mrg 
     52      1.1  mrg int
     53      1.1  mrg fhc_mainbus_match(device_t parent, cfdata_t match, void *aux)
     54      1.1  mrg {
     55      1.1  mrg 	struct mainbus_attach_args *ma = aux;
     56      1.1  mrg 
     57      1.1  mrg 	if (strcmp(ma->ma_name, "fhc") == 0)
     58      1.1  mrg 		return (1);
     59      1.1  mrg 	return (0);
     60      1.1  mrg }
     61      1.1  mrg 
     62      1.1  mrg void
     63      1.1  mrg fhc_mainbus_attach(device_t parent, device_t self, void *aux)
     64      1.1  mrg {
     65      1.2  mrg 	struct fhc_softc *sc = device_private(self);
     66      1.1  mrg 	struct mainbus_attach_args *ma = aux;
     67      1.1  mrg 
     68      1.1  mrg 	sc->sc_node = ma->ma_node;
     69      1.1  mrg 	sc->sc_bt = ma->ma_bustag;
     70      1.1  mrg 	sc->sc_is_central = 0;
     71      1.1  mrg 
     72      1.1  mrg 	if (bus_space_map(sc->sc_bt, ma->ma_reg[0].ur_paddr,
     73      1.1  mrg 	    ma->ma_reg[0].ur_len, 0, &sc->sc_preg)) {
     74      1.1  mrg 		printf(": failed to map preg\n");
     75      1.1  mrg 		return;
     76      1.1  mrg 	}
     77      1.1  mrg 
     78      1.1  mrg 	if (bus_space_map(sc->sc_bt, ma->ma_reg[1].ur_paddr,
     79      1.1  mrg 	    ma->ma_reg[1].ur_len, 0, &sc->sc_ireg)) {
     80      1.1  mrg 		printf(": failed to map ireg\n");
     81      1.1  mrg 		return;
     82      1.1  mrg 	}
     83      1.1  mrg 
     84      1.1  mrg 	if (bus_space_map(sc->sc_bt, ma->ma_reg[2].ur_paddr,
     85      1.1  mrg 	    ma->ma_reg[2].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_freg)) {
     86      1.1  mrg 		printf(": failed to map freg\n");
     87      1.1  mrg 		return;
     88      1.1  mrg 	}
     89      1.1  mrg 
     90      1.1  mrg 	if (bus_space_map(sc->sc_bt, ma->ma_reg[3].ur_paddr,
     91      1.1  mrg 	    ma->ma_reg[3].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_sreg)) {
     92      1.1  mrg 		printf(": failed to map sreg\n");
     93      1.1  mrg 		return;
     94      1.1  mrg 	}
     95      1.1  mrg 
     96      1.1  mrg 	if (bus_space_map(sc->sc_bt, ma->ma_reg[4].ur_paddr,
     97      1.1  mrg 	    ma->ma_reg[4].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_ureg)) {
     98      1.1  mrg 		printf(": failed to map ureg\n");
     99      1.1  mrg 		return;
    100      1.1  mrg 	}
    101      1.1  mrg 
    102      1.1  mrg 	if (bus_space_map(sc->sc_bt, ma->ma_reg[5].ur_paddr,
    103      1.1  mrg 	    ma->ma_reg[5].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_treg)) {
    104      1.1  mrg 		printf(": failed to map treg\n");
    105      1.1  mrg 		return;
    106      1.1  mrg 	}
    107      1.1  mrg 
    108      1.1  mrg 	sc->sc_board = prom_getpropint(sc->sc_node, "board#", -1);
    109      1.1  mrg 	sc->sc_dev = self;
    110      1.1  mrg 
    111      1.1  mrg 	fhc_attach(sc);
    112      1.1  mrg 
    113      1.1  mrg 	return;
    114      1.1  mrg }
    115