1 /* $OpenBSD: fhc_mainbus.c,v 1.7 2022/10/16 01:22:39 jsg Exp $ */ 2 3 /* 4 * Copyright (c) 2004 Jason L. Wright (jason@thought.net). 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/param.h> 30 #include <sys/systm.h> 31 #include <sys/kernel.h> 32 #include <sys/device.h> 33 #include <sys/conf.h> 34 #include <sys/timeout.h> 35 36 #include <machine/bus.h> 37 #include <machine/autoconf.h> 38 #include <machine/openfirm.h> 39 40 #include <sparc64/dev/fhcvar.h> 41 42 int fhc_mainbus_match(struct device *, void *, void *); 43 void fhc_mainbus_attach(struct device *, struct device *, void *); 44 45 const struct cfattach fhc_mainbus_ca = { 46 sizeof(struct fhc_softc), fhc_mainbus_match, fhc_mainbus_attach 47 }; 48 49 int 50 fhc_mainbus_match(struct device *parent, void *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(struct device *parent, struct device *self, void *aux) 61 { 62 struct fhc_softc *sc = (struct fhc_softc *)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 = getpropint(sc->sc_node, "board#", -1); 106 107 fhc_attach(sc); 108 109 return; 110 } 111