Home | History | Annotate | Line # | Download | only in mca
mca.c revision 1.28
      1 /*	$NetBSD: mca.c,v 1.28 2009/03/14 21:04:21 dsl 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 (at) 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.28 2009/03/14 21:04:21 dsl 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(void *aux, const char *pnp)
     77 {
     78 	register struct mca_attach_args *ma = aux;
     79 	char devinfo[256];
     80 
     81 	if (pnp) {
     82 		mca_devinfo(ma->ma_id, devinfo, sizeof(devinfo));
     83 		aprint_normal("%s slot %d: %s", pnp, ma->ma_slot + 1, devinfo);
     84 	}
     85 
     86 	/*
     87 	 * Print "configured" for Memory Extension boards - there is no
     88 	 * meaningfull driver for them, they "just work".
     89 	 */
     90 	switch(ma->ma_id) {
     91 	case MCA_PRODUCT_HRAM: case MCA_PRODUCT_IQRAM: case MCA_PRODUCT_MICRAM:
     92 	case MCA_PRODUCT_ASTRAM: case MCA_PRODUCT_KINGRAM:
     93 	case MCA_PRODUCT_KINGRAM8: case MCA_PRODUCT_KINGRAM16:
     94 	case MCA_PRODUCT_KINGRAM609: case MCA_PRODUCT_HYPRAM:
     95 	case MCA_PRODUCT_QRAM1: case MCA_PRODUCT_QRAM2: case MCA_PRODUCT_EVERAM:
     96 	case MCA_PRODUCT_BOCARAM: case MCA_PRODUCT_IBMRAM1:
     97 	case MCA_PRODUCT_IBMRAM2: case MCA_PRODUCT_IBMRAM3:
     98 	case MCA_PRODUCT_IBMRAM4: case MCA_PRODUCT_IBMRAM5:
     99 	case MCA_PRODUCT_IBMRAM6: case MCA_PRODUCT_IBMRAM7:
    100 		aprint_normal(": memory configured\n");
    101 		return (QUIET);
    102 	default:
    103 		return (UNCONF);
    104 	}
    105 }
    106 
    107 void
    108 mca_attach(struct device *parent, struct device *self, void *aux)
    109 {
    110 	struct mcabus_attach_args *mba = aux;
    111 	bus_space_tag_t iot, memt;
    112 	bus_dma_tag_t dmat;
    113 	mca_chipset_tag_t mc;
    114 	int slot;
    115 
    116 	mca_attach_hook(parent, self, mba);
    117 	printf("\n");
    118 
    119 	iot = mba->mba_iot;
    120 	memt = mba->mba_memt;
    121 	mc = mba->mba_mc;
    122 	dmat = mba->mba_dmat;
    123 
    124 	/*
    125 	 * Search for and attach subdevices.
    126 	 *
    127 	 * NB: In the adapter setup register, slots are numbered from 0,
    128 	 * but officially they are numbered from 1.
    129 	 * We use the former convention internally and the latter for text
    130 	 * messages and in config files.
    131 	 */
    132 
    133 	for (slot = 0; slot < MCA_MAX_SLOTS; slot++) {
    134 		struct mca_attach_args ma;
    135 		int reg;
    136 		int locs[MCACF_NLOCS];
    137 
    138 		ma.ma_iot = iot;
    139 		ma.ma_memt = memt;
    140 		ma.ma_dmat = dmat;
    141 		ma.ma_mc = mc;
    142 		ma.ma_slot = slot;
    143 
    144 		for(reg = 0; reg < 8; reg++)
    145 			ma.ma_pos[reg]=mca_conf_read(mc, slot, reg);
    146 
    147 		ma.ma_id = ma.ma_pos[0] + (ma.ma_pos[1] << 8);
    148 		if (ma.ma_id == 0xffff)	/* no adapter here */
    149 			continue;
    150 
    151 		locs[MCACF_SLOT] = slot;
    152 
    153 		if (ma.ma_pos[2] & MCA_POS2_ENABLE
    154 		    || mca_match_disabled(ma.ma_id))
    155 			config_found_sm_loc(self, "mca", locs, &ma,
    156 					    mca_print, config_stdsubmatch);
    157 		else {
    158 			mca_print(&ma, device_xname(self));
    159 			printf(" disabled\n");
    160 		}
    161 	}
    162 }
    163