Home | History | Annotate | Line # | Download | only in mca
mca.c revision 1.20.20.1
      1  1.20.20.1        ad /*	$NetBSD: mca.c,v 1.20.20.1 2006/11/18 21:34:26 ad Exp $	*/
      2        1.1  jdolecek 
      3        1.1  jdolecek /*-
      4        1.4  jdolecek  * 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.6     lukem 
     44        1.6     lukem #include <sys/cdefs.h>
     45  1.20.20.1        ad __KERNEL_RCSID(0, "$NetBSD: mca.c,v 1.20.20.1 2006/11/18 21:34:26 ad Exp $");
     46        1.1  jdolecek 
     47        1.1  jdolecek #include <sys/param.h>
     48        1.1  jdolecek #include <sys/systm.h>
     49        1.1  jdolecek #include <sys/device.h>
     50        1.1  jdolecek 
     51        1.1  jdolecek #include <machine/bus.h>
     52        1.1  jdolecek 
     53        1.1  jdolecek #include <dev/mca/mcareg.h>
     54        1.1  jdolecek #include <dev/mca/mcavar.h>
     55        1.3  jdolecek #include <dev/mca/mcadevs.h>
     56        1.1  jdolecek 
     57       1.16  drochner #include "locators.h"
     58       1.16  drochner 
     59       1.17     perry int	mca_match(struct device *, struct cfdata *, void *);
     60       1.17     perry void	mca_attach(struct device *, struct device *, void *);
     61        1.1  jdolecek 
     62       1.11   thorpej CFATTACH_DECL(mca, sizeof(struct device),
     63       1.12   thorpej     mca_match, mca_attach, NULL, NULL);
     64        1.1  jdolecek 
     65       1.17     perry int	mca_print(void *, const char *);
     66        1.1  jdolecek 
     67        1.1  jdolecek int
     68  1.20.20.1        ad mca_match(struct device *parent, struct cfdata *cf, void *aux)
     69        1.1  jdolecek {
     70        1.1  jdolecek 	struct mcabus_attach_args *mba = aux;
     71        1.1  jdolecek 
     72        1.1  jdolecek 	/* sanity (only mca0 supported currently) */
     73        1.1  jdolecek 	if (mba->mba_bus < 0 || mba->mba_bus > 0)
     74        1.1  jdolecek 		return (0);
     75        1.1  jdolecek 
     76        1.1  jdolecek 	/* XXX check other indicators? */
     77        1.1  jdolecek 
     78        1.1  jdolecek 	return (1);
     79        1.1  jdolecek }
     80        1.1  jdolecek 
     81        1.1  jdolecek int
     82        1.1  jdolecek mca_print(aux, pnp)
     83        1.1  jdolecek 	void *aux;
     84        1.1  jdolecek 	const char *pnp;
     85        1.1  jdolecek {
     86        1.1  jdolecek 	register struct mca_attach_args *ma = aux;
     87        1.1  jdolecek 	char devinfo[256];
     88        1.1  jdolecek 
     89        1.1  jdolecek 	if (pnp) {
     90       1.14    itojun 		mca_devinfo(ma->ma_id, devinfo, sizeof(devinfo));
     91       1.13   thorpej 		aprint_normal("%s slot %d: %s", pnp, ma->ma_slot + 1, devinfo);
     92        1.1  jdolecek 	}
     93        1.1  jdolecek 
     94        1.3  jdolecek 	/*
     95        1.3  jdolecek 	 * Print "configured" for Memory Extension boards - there is no
     96        1.3  jdolecek 	 * meaningfull driver for them, they "just work".
     97        1.3  jdolecek 	 */
     98        1.3  jdolecek 	switch(ma->ma_id) {
     99        1.3  jdolecek 	case MCA_PRODUCT_HRAM: case MCA_PRODUCT_IQRAM: case MCA_PRODUCT_MICRAM:
    100        1.3  jdolecek 	case MCA_PRODUCT_ASTRAM: case MCA_PRODUCT_KINGRAM:
    101        1.3  jdolecek 	case MCA_PRODUCT_KINGRAM8: case MCA_PRODUCT_KINGRAM16:
    102        1.3  jdolecek 	case MCA_PRODUCT_KINGRAM609: case MCA_PRODUCT_HYPRAM:
    103        1.3  jdolecek 	case MCA_PRODUCT_QRAM1: case MCA_PRODUCT_QRAM2: case MCA_PRODUCT_EVERAM:
    104        1.3  jdolecek 	case MCA_PRODUCT_BOCARAM: case MCA_PRODUCT_IBMRAM1:
    105        1.3  jdolecek 	case MCA_PRODUCT_IBMRAM2: case MCA_PRODUCT_IBMRAM3:
    106        1.3  jdolecek 	case MCA_PRODUCT_IBMRAM4: case MCA_PRODUCT_IBMRAM5:
    107        1.3  jdolecek 	case MCA_PRODUCT_IBMRAM6: case MCA_PRODUCT_IBMRAM7:
    108       1.13   thorpej 		aprint_normal(": memory configured\n");
    109        1.3  jdolecek 		return (QUIET);
    110        1.3  jdolecek 	default:
    111        1.3  jdolecek 		return (UNCONF);
    112        1.3  jdolecek 	}
    113        1.1  jdolecek }
    114        1.1  jdolecek 
    115        1.1  jdolecek void
    116        1.1  jdolecek mca_attach(parent, self, aux)
    117        1.1  jdolecek 	struct device *parent, *self;
    118        1.1  jdolecek 	void *aux;
    119        1.1  jdolecek {
    120        1.1  jdolecek 	struct mcabus_attach_args *mba = aux;
    121        1.1  jdolecek 	bus_space_tag_t iot, memt;
    122        1.1  jdolecek 	bus_dma_tag_t dmat;
    123        1.1  jdolecek 	mca_chipset_tag_t mc;
    124        1.1  jdolecek 	int slot;
    125        1.1  jdolecek 
    126        1.1  jdolecek 	mca_attach_hook(parent, self, mba);
    127        1.1  jdolecek 	printf("\n");
    128        1.1  jdolecek 
    129        1.1  jdolecek 	iot = mba->mba_iot;
    130        1.1  jdolecek 	memt = mba->mba_memt;
    131        1.1  jdolecek 	mc = mba->mba_mc;
    132        1.1  jdolecek 	dmat = mba->mba_dmat;
    133        1.1  jdolecek 
    134        1.1  jdolecek 	/*
    135        1.1  jdolecek 	 * Search for and attach subdevices.
    136        1.1  jdolecek 	 *
    137        1.1  jdolecek 	 * NB: In the adapter setup register, slots are numbered from 0,
    138        1.1  jdolecek 	 * but officially they are numbered from 1.
    139        1.1  jdolecek 	 * We use the former convention internally and the latter for text
    140        1.1  jdolecek 	 * messages and in config files.
    141        1.1  jdolecek 	 */
    142        1.1  jdolecek 
    143        1.1  jdolecek 	for (slot = 0; slot < MCA_MAX_SLOTS; slot++) {
    144        1.1  jdolecek 		struct mca_attach_args ma;
    145        1.1  jdolecek 		int reg;
    146       1.18  drochner 		int locs[MCACF_NLOCS];
    147        1.1  jdolecek 
    148        1.1  jdolecek 		ma.ma_iot = iot;
    149        1.1  jdolecek 		ma.ma_memt = memt;
    150        1.1  jdolecek 		ma.ma_dmat = dmat;
    151        1.1  jdolecek 		ma.ma_mc = mc;
    152        1.1  jdolecek 		ma.ma_slot = slot;
    153        1.1  jdolecek 
    154        1.1  jdolecek 		for(reg = 0; reg < 8; reg++)
    155        1.1  jdolecek 			ma.ma_pos[reg]=mca_conf_read(mc, slot, reg);
    156        1.1  jdolecek 
    157        1.1  jdolecek 		ma.ma_id = ma.ma_pos[0] + (ma.ma_pos[1] << 8);
    158        1.1  jdolecek 		if (ma.ma_id == 0xffff)	/* no adapter here */
    159        1.1  jdolecek 			continue;
    160        1.1  jdolecek 
    161       1.18  drochner 		locs[MCACF_SLOT] = slot;
    162       1.16  drochner 
    163        1.5  jdolecek 		if (ma.ma_pos[2] & MCA_POS2_ENABLE
    164        1.5  jdolecek 		    || mca_match_disabled(ma.ma_id))
    165       1.18  drochner 			config_found_sm_loc(self, "mca", locs, &ma,
    166       1.19  drochner 					    mca_print, config_stdsubmatch);
    167        1.1  jdolecek 		else {
    168        1.1  jdolecek 			mca_print(&ma, self->dv_xname);
    169        1.1  jdolecek 			printf(" disabled\n");
    170        1.1  jdolecek 		}
    171        1.1  jdolecek 	}
    172        1.1  jdolecek }
    173