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