1 /* $NetBSD: mca.c,v 1.26 2008/04/28 20:23:53 martin 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 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * MCA Bus device 35 */ 36 37 #include <sys/cdefs.h> 38 __KERNEL_RCSID(0, "$NetBSD: mca.c,v 1.26 2008/04/28 20:23:53 martin Exp $"); 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/device.h> 43 44 #include <sys/bus.h> 45 #include <machine/mca_machdep.h> 46 47 #include <dev/mca/mcareg.h> 48 #include <dev/mca/mcavar.h> 49 #include <dev/mca/mcadevs.h> 50 51 #include "locators.h" 52 53 int mca_match(struct device *, struct cfdata *, void *); 54 void mca_attach(struct device *, struct device *, void *); 55 56 CFATTACH_DECL(mca, sizeof(struct device), 57 mca_match, mca_attach, NULL, NULL); 58 59 int mca_print(void *, const char *); 60 61 int 62 mca_match(struct device *parent, struct cfdata *cf, void *aux) 63 { 64 struct mcabus_attach_args *mba = aux; 65 66 /* sanity (only mca0 supported currently) */ 67 if (mba->mba_bus < 0 || mba->mba_bus > 0) 68 return (0); 69 70 /* XXX check other indicators? */ 71 72 return (1); 73 } 74 75 int 76 mca_print(aux, pnp) 77 void *aux; 78 const char *pnp; 79 { 80 register struct mca_attach_args *ma = aux; 81 char devinfo[256]; 82 83 if (pnp) { 84 mca_devinfo(ma->ma_id, devinfo, sizeof(devinfo)); 85 aprint_normal("%s slot %d: %s", pnp, ma->ma_slot + 1, devinfo); 86 } 87 88 /* 89 * Print "configured" for Memory Extension boards - there is no 90 * meaningfull driver for them, they "just work". 91 */ 92 switch(ma->ma_id) { 93 case MCA_PRODUCT_HRAM: case MCA_PRODUCT_IQRAM: case MCA_PRODUCT_MICRAM: 94 case MCA_PRODUCT_ASTRAM: case MCA_PRODUCT_KINGRAM: 95 case MCA_PRODUCT_KINGRAM8: case MCA_PRODUCT_KINGRAM16: 96 case MCA_PRODUCT_KINGRAM609: case MCA_PRODUCT_HYPRAM: 97 case MCA_PRODUCT_QRAM1: case MCA_PRODUCT_QRAM2: case MCA_PRODUCT_EVERAM: 98 case MCA_PRODUCT_BOCARAM: case MCA_PRODUCT_IBMRAM1: 99 case MCA_PRODUCT_IBMRAM2: case MCA_PRODUCT_IBMRAM3: 100 case MCA_PRODUCT_IBMRAM4: case MCA_PRODUCT_IBMRAM5: 101 case MCA_PRODUCT_IBMRAM6: case MCA_PRODUCT_IBMRAM7: 102 aprint_normal(": memory configured\n"); 103 return (QUIET); 104 default: 105 return (UNCONF); 106 } 107 } 108 109 void 110 mca_attach(parent, self, aux) 111 struct device *parent, *self; 112 void *aux; 113 { 114 struct mcabus_attach_args *mba = aux; 115 bus_space_tag_t iot, memt; 116 bus_dma_tag_t dmat; 117 mca_chipset_tag_t mc; 118 int slot; 119 120 mca_attach_hook(parent, self, mba); 121 printf("\n"); 122 123 iot = mba->mba_iot; 124 memt = mba->mba_memt; 125 mc = mba->mba_mc; 126 dmat = mba->mba_dmat; 127 128 /* 129 * Search for and attach subdevices. 130 * 131 * NB: In the adapter setup register, slots are numbered from 0, 132 * but officially they are numbered from 1. 133 * We use the former convention internally and the latter for text 134 * messages and in config files. 135 */ 136 137 for (slot = 0; slot < MCA_MAX_SLOTS; slot++) { 138 struct mca_attach_args ma; 139 int reg; 140 int locs[MCACF_NLOCS]; 141 142 ma.ma_iot = iot; 143 ma.ma_memt = memt; 144 ma.ma_dmat = dmat; 145 ma.ma_mc = mc; 146 ma.ma_slot = slot; 147 148 for(reg = 0; reg < 8; reg++) 149 ma.ma_pos[reg]=mca_conf_read(mc, slot, reg); 150 151 ma.ma_id = ma.ma_pos[0] + (ma.ma_pos[1] << 8); 152 if (ma.ma_id == 0xffff) /* no adapter here */ 153 continue; 154 155 locs[MCACF_SLOT] = slot; 156 157 if (ma.ma_pos[2] & MCA_POS2_ENABLE 158 || mca_match_disabled(ma.ma_id)) 159 config_found_sm_loc(self, "mca", locs, &ma, 160 mca_print, config_stdsubmatch); 161 else { 162 mca_print(&ma, device_xname(self)); 163 printf(" disabled\n"); 164 } 165 } 166 } 167