1 /* $NetBSD: obio.c,v 1.13 2010/04/28 13:51:56 kiyohara Exp $ */ 2 3 /* 4 * Copyright (c) 2002 Allegro Networks, Inc., Wasabi Systems, Inc. 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 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed for the NetBSD Project by 18 * Allegro Networks, Inc., and Wasabi Systems, Inc. 19 * 4. The name of Allegro Networks, Inc. may not be used to endorse 20 * or promote products derived from this software without specific prior 21 * written permission. 22 * 5. The name of Wasabi Systems, Inc. may not be used to endorse 23 * or promote products derived from this software without specific prior 24 * written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY ALLEGRO NETWORKS, INC. AND 27 * WASABI SYSTEMS, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 28 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 29 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 30 * IN NO EVENT SHALL EITHER ALLEGRO NETWORKS, INC. OR WASABI SYSTEMS, INC. 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40 #include <sys/cdefs.h> 41 __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.13 2010/04/28 13:51:56 kiyohara Exp $"); 42 43 #include "opt_marvell.h" 44 45 #include <sys/param.h> 46 #include <sys/types.h> 47 #include <sys/extent.h> 48 #include <sys/device.h> 49 #include <sys/kernel.h> 50 #include <sys/malloc.h> 51 52 #include <dev/pci/pcivar.h> 53 #include <dev/marvell/gtreg.h> 54 #include <dev/marvell/gtvar.h> 55 #include <dev/marvell/gtdevbusvar.h> 56 #include <dev/marvell/marvellvar.h> 57 58 #include <prop/proplib.h> 59 60 #ifdef DEBUG 61 #include <sys/systm.h> /* for Debugger() */ 62 #endif 63 64 #include "locators.h" 65 66 67 static int obio_match(device_t, cfdata_t, void *); 68 static void obio_attach(device_t, device_t, void *); 69 70 static int obio_cfprint(void *, const char *); 71 static int obio_cfsearch(device_t, cfdata_t, const int *, void *); 72 73 74 struct obio_softc { 75 device_t sc_dev; 76 bus_space_tag_t sc_iot; 77 }; 78 79 CFATTACH_DECL_NEW(obio, sizeof(struct obio_softc), 80 obio_match, obio_attach, NULL, NULL); 81 82 83 /* ARGSUSED */ 84 int 85 obio_match(device_t parent, cfdata_t cf, void *aux) 86 { 87 struct marvell_attach_args *mva = aux; 88 89 if (strcmp(mva->mva_name, cf->cf_name) != 0) 90 return 0; 91 92 #define NUM_OBIO 5 93 if (mva->mva_unit == GTCF_UNIT_DEFAULT || 94 mva->mva_unit > NUM_OBIO) 95 return 0; 96 97 return 1; 98 } 99 100 /* ARGSUSED */ 101 void 102 obio_attach(device_t parent, device_t self, void *aux) 103 { 104 struct obio_softc *sc = device_private(self); 105 struct marvell_attach_args *mva = aux; 106 prop_data_t bst; 107 uint32_t datal, datah; 108 109 aprint_naive("\n"); 110 aprint_normal(": Device Bus\n"); 111 112 sc->sc_dev = self; 113 114 if (gt_devbus_addr(parent, mva->mva_unit, &datal, &datah)) { 115 aprint_error_dev(self, "unknown unit number %d\n", 116 mva->mva_unit); 117 return; 118 } 119 120 if (GT_LowAddr_GET(datal) > GT_HighAddr_GET(datah)) { 121 aprint_normal_dev(self, "disabled\n"); 122 return; 123 } 124 125 bst = prop_dictionary_get(device_properties(sc->sc_dev), "bus-tag"); 126 if (bst != NULL) { 127 KASSERT(prop_object_type(bst) == PROP_TYPE_DATA); 128 KASSERT(prop_data_size(bst) == sizeof(bus_space_tag_t)); 129 memcpy(&sc->sc_iot, prop_data_data_nocopy(bst), 130 sizeof(bus_space_tag_t)); 131 } else 132 sc->sc_iot = mva->mva_iot; 133 if (sc->sc_iot == NULL) { 134 aprint_normal_dev(self, "unused\n"); 135 return; 136 } 137 138 aprint_normal_dev(self, "addr %#x-%#x\n", 139 GT_LowAddr_GET(datal), GT_HighAddr_GET(datah)); 140 141 config_search_ia(obio_cfsearch, self, "obio", NULL); 142 } 143 144 145 int 146 obio_cfprint(void *aux, const char *pnp) 147 { 148 struct obio_attach_args *oa = aux; 149 150 if (pnp) 151 aprint_normal("%s at %s", oa->oa_name, pnp); 152 aprint_normal(" addr %#x size %#x", oa->oa_offset, oa->oa_size); 153 if (oa->oa_irq != OBIOCF_IRQ_DEFAULT) 154 aprint_normal(" irq %d", oa->oa_irq); 155 156 return UNCONF; 157 } 158 159 160 /* ARGSUSED */ 161 int 162 obio_cfsearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux) 163 { 164 struct obio_softc *sc = device_private(parent); 165 struct obio_attach_args oa; 166 167 oa.oa_name = cf->cf_name; 168 oa.oa_memt = sc->sc_iot; 169 oa.oa_offset = cf->cf_loc[OBIOCF_OFFSET]; 170 oa.oa_size = cf->cf_loc[OBIOCF_SIZE]; 171 oa.oa_irq = cf->cf_loc[OBIOCF_IRQ]; 172 173 if (config_match(parent, cf, &oa) > 0) 174 config_attach(parent, cf, &oa, obio_cfprint); 175 176 return 0; 177 } 178