1 1.3 mrg /* $NetBSD: fhc_central.c,v 1.3 2012/03/18 05:26:58 mrg Exp $ */ 2 1.1 mrg /* $OpenBSD: fhc_central.c,v 1.5 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.3 mrg #include <sys/cdefs.h> 31 1.3 mrg __KERNEL_RCSID(0, "$NetBSD: fhc_central.c,v 1.3 2012/03/18 05:26:58 mrg Exp $"); 32 1.3 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/centralvar.h> 45 1.1 mrg #include <sparc64/dev/fhcreg.h> 46 1.1 mrg #include <sparc64/dev/fhcvar.h> 47 1.1 mrg 48 1.1 mrg int fhc_central_match(device_t, cfdata_t, void *); 49 1.1 mrg void fhc_central_attach(device_t, device_t, void *); 50 1.1 mrg 51 1.1 mrg CFATTACH_DECL_NEW(fhc_central, sizeof(struct fhc_softc), 52 1.1 mrg fhc_central_match, fhc_central_attach, NULL, NULL); 53 1.1 mrg 54 1.1 mrg int 55 1.1 mrg fhc_central_match(device_t parent, cfdata_t match, void *aux) 56 1.1 mrg { 57 1.1 mrg struct central_attach_args *ca = aux; 58 1.1 mrg 59 1.1 mrg if (strcmp(ca->ca_name, "fhc") == 0) 60 1.1 mrg return (1); 61 1.1 mrg return (0); 62 1.1 mrg } 63 1.1 mrg 64 1.1 mrg void 65 1.1 mrg fhc_central_attach(device_t parent, device_t self, void *aux) 66 1.1 mrg { 67 1.2 mrg struct fhc_softc *sc = device_private(self); 68 1.1 mrg struct central_attach_args *ca = aux; 69 1.1 mrg u_int32_t board; 70 1.1 mrg 71 1.1 mrg sc->sc_node = ca->ca_node; 72 1.1 mrg sc->sc_bt = ca->ca_bustag; 73 1.1 mrg sc->sc_is_central = 1; 74 1.1 mrg 75 1.1 mrg if (central_bus_map(sc->sc_bt, ca->ca_reg[0].cbr_slot, 76 1.1 mrg ca->ca_reg[0].cbr_offset, ca->ca_reg[0].cbr_size, 0, 77 1.1 mrg &sc->sc_preg)) { 78 1.1 mrg printf(": failed to map preg\n"); 79 1.1 mrg return; 80 1.1 mrg } 81 1.1 mrg 82 1.1 mrg if (central_bus_map(sc->sc_bt, ca->ca_reg[1].cbr_slot, 83 1.1 mrg ca->ca_reg[1].cbr_offset, ca->ca_reg[1].cbr_size, 0, 84 1.1 mrg &sc->sc_ireg)) { 85 1.1 mrg printf(": failed to map ireg\n"); 86 1.1 mrg return; 87 1.1 mrg } 88 1.1 mrg 89 1.1 mrg if (central_bus_map(sc->sc_bt, ca->ca_reg[2].cbr_slot, 90 1.1 mrg ca->ca_reg[2].cbr_offset, ca->ca_reg[2].cbr_size, 91 1.1 mrg BUS_SPACE_MAP_LINEAR, &sc->sc_freg)) { 92 1.1 mrg printf(": failed to map freg\n"); 93 1.1 mrg return; 94 1.1 mrg } 95 1.1 mrg 96 1.1 mrg if (central_bus_map(sc->sc_bt, ca->ca_reg[3].cbr_slot, 97 1.1 mrg ca->ca_reg[3].cbr_offset, ca->ca_reg[3].cbr_size, 98 1.1 mrg BUS_SPACE_MAP_LINEAR, &sc->sc_sreg)) { 99 1.1 mrg printf(": failed to map sreg\n"); 100 1.1 mrg return; 101 1.1 mrg } 102 1.1 mrg 103 1.1 mrg if (central_bus_map(sc->sc_bt, ca->ca_reg[4].cbr_slot, 104 1.1 mrg ca->ca_reg[4].cbr_offset, ca->ca_reg[4].cbr_size, 105 1.1 mrg BUS_SPACE_MAP_LINEAR, &sc->sc_ureg)) { 106 1.1 mrg printf(": failed to map ureg\n"); 107 1.1 mrg return; 108 1.1 mrg } 109 1.1 mrg 110 1.1 mrg if (central_bus_map(sc->sc_bt, ca->ca_reg[5].cbr_slot, 111 1.1 mrg ca->ca_reg[5].cbr_offset, ca->ca_reg[5].cbr_size, 112 1.1 mrg BUS_SPACE_MAP_LINEAR, &sc->sc_treg)) { 113 1.1 mrg printf(": failed to map treg\n"); 114 1.1 mrg return; 115 1.1 mrg } 116 1.1 mrg 117 1.1 mrg board = bus_space_read_4(sc->sc_bt, sc->sc_preg, FHC_P_BSR); 118 1.1 mrg sc->sc_board = ((board >> 16) & 0x1) | ((board >> 12) & 0xe); 119 1.1 mrg sc->sc_dev = self; 120 1.1 mrg 121 1.1 mrg fhc_attach(sc); 122 1.1 mrg return; 123 1.1 mrg } 124