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/cdefs.h> 31__KERNEL_RCSID(0, "$NetBSD$"); 32 33#include <sys/types.h> 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/kernel.h> 37#include <sys/device.h> 38#include <sys/conf.h> 39#include <sys/bus.h> 40 41#include <machine/autoconf.h> 42#include <machine/openfirm.h> 43 44#include <sparc64/dev/fhcvar.h> 45 46int fhc_mainbus_match(device_t, cfdata_t, void *); 47void fhc_mainbus_attach(device_t, device_t, void *); 48 49CFATTACH_DECL_NEW(fhc_mainbus, sizeof(struct fhc_softc), 50 fhc_mainbus_match, fhc_mainbus_attach, NULL, NULL); 51 52int 53fhc_mainbus_match(device_t parent, cfdata_t match, void *aux) 54{ 55 struct mainbus_attach_args *ma = aux; 56 57 if (strcmp(ma->ma_name, "fhc") == 0) 58 return (1); 59 return (0); 60} 61 62void 63fhc_mainbus_attach(device_t parent, device_t self, void *aux) 64{ 65 struct fhc_softc *sc = device_private(self); 66 struct mainbus_attach_args *ma = aux; 67 68 sc->sc_node = ma->ma_node; 69 sc->sc_bt = ma->ma_bustag; 70 sc->sc_is_central = 0; 71 72 if (bus_space_map(sc->sc_bt, ma->ma_reg[0].ur_paddr, 73 ma->ma_reg[0].ur_len, 0, &sc->sc_preg)) { 74 printf(": failed to map preg\n"); 75 return; 76 } 77 78 if (bus_space_map(sc->sc_bt, ma->ma_reg[1].ur_paddr, 79 ma->ma_reg[1].ur_len, 0, &sc->sc_ireg)) { 80 printf(": failed to map ireg\n"); 81 return; 82 } 83 84 if (bus_space_map(sc->sc_bt, ma->ma_reg[2].ur_paddr, 85 ma->ma_reg[2].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_freg)) { 86 printf(": failed to map freg\n"); 87 return; 88 } 89 90 if (bus_space_map(sc->sc_bt, ma->ma_reg[3].ur_paddr, 91 ma->ma_reg[3].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_sreg)) { 92 printf(": failed to map sreg\n"); 93 return; 94 } 95 96 if (bus_space_map(sc->sc_bt, ma->ma_reg[4].ur_paddr, 97 ma->ma_reg[4].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_ureg)) { 98 printf(": failed to map ureg\n"); 99 return; 100 } 101 102 if (bus_space_map(sc->sc_bt, ma->ma_reg[5].ur_paddr, 103 ma->ma_reg[5].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_treg)) { 104 printf(": failed to map treg\n"); 105 return; 106 } 107 108 sc->sc_board = prom_getpropint(sc->sc_node, "board#", -1); 109 sc->sc_dev = self; 110 111 fhc_attach(sc); 112 113 return; 114} 115