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