1 /* $NetBSD: mca.c,v 1.6 2001/11/13 07:46:26 lukem Exp $ */ 2 3 /*- 4 * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. 5 * Copyright (c) 1996-1999 Scott D. Telford. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Scott Telford <s.telford@ed.ac.uk>. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 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 /* 41 * MCA Bus device 42 */ 43 44 #include <sys/cdefs.h> 45 __KERNEL_RCSID(0, "$NetBSD: mca.c,v 1.6 2001/11/13 07:46:26 lukem Exp $"); 46 47 #include "opt_mcaverbose.h" 48 49 #include <sys/param.h> 50 #include <sys/systm.h> 51 #include <sys/device.h> 52 53 #include <machine/bus.h> 54 55 #include <dev/mca/mcareg.h> 56 #include <dev/mca/mcavar.h> 57 #include <dev/mca/mcadevs.h> 58 59 int mca_match __P((struct device *, struct cfdata *, void *)); 60 void mca_attach __P((struct device *, struct device *, void *)); 61 62 struct cfattach mca_ca = { 63 sizeof(struct device), mca_match, mca_attach 64 }; 65 66 int mca_submatch __P((struct device *, struct cfdata *, void *)); 67 int mca_print __P((void *, const char *)); 68 69 int 70 mca_match(parent, cf, aux) 71 struct device *parent; 72 struct cfdata *cf; 73 void *aux; 74 { 75 struct mcabus_attach_args *mba = aux; 76 77 if (strcmp(mba->mba_busname, cf->cf_driver->cd_name)) 78 return (0); 79 80 /* sanity (only mca0 supported currently) */ 81 if (mba->mba_bus < 0 || mba->mba_bus > 0) 82 return (0); 83 84 /* XXX check other indicators? */ 85 86 return (1); 87 } 88 89 int 90 mca_print(aux, pnp) 91 void *aux; 92 const char *pnp; 93 { 94 register struct mca_attach_args *ma = aux; 95 char devinfo[256]; 96 97 if (pnp) { 98 mca_devinfo(ma->ma_id, devinfo); 99 printf("%s slot %d: %s", pnp, ma->ma_slot + 1, devinfo); 100 } 101 102 /* 103 * Print "configured" for Memory Extension boards - there is no 104 * meaningfull driver for them, they "just work". 105 */ 106 switch(ma->ma_id) { 107 case MCA_PRODUCT_HRAM: case MCA_PRODUCT_IQRAM: case MCA_PRODUCT_MICRAM: 108 case MCA_PRODUCT_ASTRAM: case MCA_PRODUCT_KINGRAM: 109 case MCA_PRODUCT_KINGRAM8: case MCA_PRODUCT_KINGRAM16: 110 case MCA_PRODUCT_KINGRAM609: case MCA_PRODUCT_HYPRAM: 111 case MCA_PRODUCT_QRAM1: case MCA_PRODUCT_QRAM2: case MCA_PRODUCT_EVERAM: 112 case MCA_PRODUCT_BOCARAM: case MCA_PRODUCT_IBMRAM1: 113 case MCA_PRODUCT_IBMRAM2: case MCA_PRODUCT_IBMRAM3: 114 case MCA_PRODUCT_IBMRAM4: case MCA_PRODUCT_IBMRAM5: 115 case MCA_PRODUCT_IBMRAM6: case MCA_PRODUCT_IBMRAM7: 116 printf(": configured\n"); 117 return (QUIET); 118 default: 119 return (UNCONF); 120 } 121 } 122 123 int 124 mca_submatch(parent, cf, aux) 125 struct device *parent; 126 struct cfdata *cf; 127 void *aux; 128 { 129 struct mca_attach_args *ma = aux; 130 131 if (cf->mcacf_slot != MCA_UNKNOWN_SLOT && 132 cf->mcacf_slot != ma->ma_slot) 133 return 0; 134 return ((*cf->cf_attach->ca_match)(parent, cf, aux)); 135 } 136 137 void 138 mca_attach(parent, self, aux) 139 struct device *parent, *self; 140 void *aux; 141 { 142 struct mcabus_attach_args *mba = aux; 143 bus_space_tag_t iot, memt; 144 bus_dma_tag_t dmat; 145 mca_chipset_tag_t mc; 146 int slot; 147 148 mca_attach_hook(parent, self, mba); 149 printf("\n"); 150 151 iot = mba->mba_iot; 152 memt = mba->mba_memt; 153 mc = mba->mba_mc; 154 dmat = mba->mba_dmat; 155 156 /* 157 * Search for and attach subdevices. 158 * 159 * NB: In the adapter setup register, slots are numbered from 0, 160 * but officially they are numbered from 1. 161 * We use the former convention internally and the latter for text 162 * messages and in config files. 163 */ 164 165 for (slot = 0; slot < MCA_MAX_SLOTS; slot++) { 166 struct mca_attach_args ma; 167 int reg; 168 169 ma.ma_iot = iot; 170 ma.ma_memt = memt; 171 ma.ma_dmat = dmat; 172 ma.ma_mc = mc; 173 ma.ma_slot = slot; 174 175 for(reg = 0; reg < 8; reg++) 176 ma.ma_pos[reg]=mca_conf_read(mc, slot, reg); 177 178 ma.ma_id = ma.ma_pos[0] + (ma.ma_pos[1] << 8); 179 if (ma.ma_id == 0xffff) /* no adapter here */ 180 continue; 181 182 if (ma.ma_pos[2] & MCA_POS2_ENABLE 183 || mca_match_disabled(ma.ma_id)) 184 config_found_sm(self, &ma, mca_print, mca_submatch); 185 else { 186 mca_print(&ma, self->dv_xname); 187 printf(" disabled\n"); 188 } 189 } 190 } 191