Home | History | Annotate | Line # | Download | only in mca
mca.c revision 1.16
      1  1.16  drochner /*	$NetBSD: mca.c,v 1.16 2004/08/30 18:27:21 drochner 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.16  drochner __KERNEL_RCSID(0, "$NetBSD: mca.c,v 1.16 2004/08/30 18:27:21 drochner 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.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.11   thorpej CFATTACH_DECL(mca, sizeof(struct device),
     63  1.12   thorpej     mca_match, mca_attach, NULL, NULL);
     64   1.1  jdolecek 
     65  1.16  drochner int	mca_submatch __P((struct device *, struct cfdata *,
     66  1.16  drochner 			  const locdesc_t *, 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 	/* sanity (only mca0 supported currently) */
     78   1.1  jdolecek 	if (mba->mba_bus < 0 || mba->mba_bus > 0)
     79   1.1  jdolecek 		return (0);
     80   1.1  jdolecek 
     81   1.1  jdolecek 	/* XXX check other indicators? */
     82   1.1  jdolecek 
     83   1.1  jdolecek 	return (1);
     84   1.1  jdolecek }
     85   1.1  jdolecek 
     86   1.1  jdolecek int
     87   1.1  jdolecek mca_print(aux, pnp)
     88   1.1  jdolecek 	void *aux;
     89   1.1  jdolecek 	const char *pnp;
     90   1.1  jdolecek {
     91   1.1  jdolecek 	register struct mca_attach_args *ma = aux;
     92   1.1  jdolecek 	char devinfo[256];
     93   1.1  jdolecek 
     94   1.1  jdolecek 	if (pnp) {
     95  1.14    itojun 		mca_devinfo(ma->ma_id, devinfo, sizeof(devinfo));
     96  1.13   thorpej 		aprint_normal("%s slot %d: %s", pnp, ma->ma_slot + 1, devinfo);
     97   1.1  jdolecek 	}
     98   1.1  jdolecek 
     99   1.3  jdolecek 	/*
    100   1.3  jdolecek 	 * Print "configured" for Memory Extension boards - there is no
    101   1.3  jdolecek 	 * meaningfull driver for them, they "just work".
    102   1.3  jdolecek 	 */
    103   1.3  jdolecek 	switch(ma->ma_id) {
    104   1.3  jdolecek 	case MCA_PRODUCT_HRAM: case MCA_PRODUCT_IQRAM: case MCA_PRODUCT_MICRAM:
    105   1.3  jdolecek 	case MCA_PRODUCT_ASTRAM: case MCA_PRODUCT_KINGRAM:
    106   1.3  jdolecek 	case MCA_PRODUCT_KINGRAM8: case MCA_PRODUCT_KINGRAM16:
    107   1.3  jdolecek 	case MCA_PRODUCT_KINGRAM609: case MCA_PRODUCT_HYPRAM:
    108   1.3  jdolecek 	case MCA_PRODUCT_QRAM1: case MCA_PRODUCT_QRAM2: case MCA_PRODUCT_EVERAM:
    109   1.3  jdolecek 	case MCA_PRODUCT_BOCARAM: case MCA_PRODUCT_IBMRAM1:
    110   1.3  jdolecek 	case MCA_PRODUCT_IBMRAM2: case MCA_PRODUCT_IBMRAM3:
    111   1.3  jdolecek 	case MCA_PRODUCT_IBMRAM4: case MCA_PRODUCT_IBMRAM5:
    112   1.3  jdolecek 	case MCA_PRODUCT_IBMRAM6: case MCA_PRODUCT_IBMRAM7:
    113  1.13   thorpej 		aprint_normal(": memory configured\n");
    114   1.3  jdolecek 		return (QUIET);
    115   1.3  jdolecek 	default:
    116   1.3  jdolecek 		return (UNCONF);
    117   1.3  jdolecek 	}
    118   1.1  jdolecek }
    119   1.1  jdolecek 
    120   1.1  jdolecek int
    121  1.16  drochner mca_submatch(parent, cf, ldesc, aux)
    122   1.1  jdolecek 	struct device *parent;
    123   1.1  jdolecek 	struct cfdata *cf;
    124  1.16  drochner 	const locdesc_t *ldesc;
    125   1.1  jdolecek 	void *aux;
    126   1.1  jdolecek {
    127   1.1  jdolecek 
    128  1.16  drochner 	if (cf->cf_loc[MCACF_SLOT] != MCACF_SLOT_DEFAULT &&
    129  1.16  drochner 	    cf->cf_loc[MCACF_SLOT] != ldesc->locs[MCACF_SLOT])
    130   1.1  jdolecek 		return 0;
    131   1.9   thorpej 	return (config_match(parent, cf, aux));
    132   1.1  jdolecek }
    133   1.1  jdolecek 
    134   1.1  jdolecek void
    135   1.1  jdolecek mca_attach(parent, self, aux)
    136   1.1  jdolecek 	struct device *parent, *self;
    137   1.1  jdolecek 	void *aux;
    138   1.1  jdolecek {
    139   1.1  jdolecek 	struct mcabus_attach_args *mba = aux;
    140   1.1  jdolecek 	bus_space_tag_t iot, memt;
    141   1.1  jdolecek 	bus_dma_tag_t dmat;
    142   1.1  jdolecek 	mca_chipset_tag_t mc;
    143   1.1  jdolecek 	int slot;
    144   1.1  jdolecek 
    145   1.1  jdolecek 	mca_attach_hook(parent, self, mba);
    146   1.1  jdolecek 	printf("\n");
    147   1.1  jdolecek 
    148   1.1  jdolecek 	iot = mba->mba_iot;
    149   1.1  jdolecek 	memt = mba->mba_memt;
    150   1.1  jdolecek 	mc = mba->mba_mc;
    151   1.1  jdolecek 	dmat = mba->mba_dmat;
    152   1.1  jdolecek 
    153   1.1  jdolecek 	/*
    154   1.1  jdolecek 	 * Search for and attach subdevices.
    155   1.1  jdolecek 	 *
    156   1.1  jdolecek 	 * NB: In the adapter setup register, slots are numbered from 0,
    157   1.1  jdolecek 	 * but officially they are numbered from 1.
    158   1.1  jdolecek 	 * We use the former convention internally and the latter for text
    159   1.1  jdolecek 	 * messages and in config files.
    160   1.1  jdolecek 	 */
    161   1.1  jdolecek 
    162   1.1  jdolecek 	for (slot = 0; slot < MCA_MAX_SLOTS; slot++) {
    163   1.1  jdolecek 		struct mca_attach_args ma;
    164   1.1  jdolecek 		int reg;
    165  1.16  drochner 		int help[2];
    166  1.16  drochner 		locdesc_t *ldesc = (void *)help; /* XXX */
    167   1.1  jdolecek 
    168   1.1  jdolecek 		ma.ma_iot = iot;
    169   1.1  jdolecek 		ma.ma_memt = memt;
    170   1.1  jdolecek 		ma.ma_dmat = dmat;
    171   1.1  jdolecek 		ma.ma_mc = mc;
    172   1.1  jdolecek 		ma.ma_slot = slot;
    173   1.1  jdolecek 
    174   1.1  jdolecek 		for(reg = 0; reg < 8; reg++)
    175   1.1  jdolecek 			ma.ma_pos[reg]=mca_conf_read(mc, slot, reg);
    176   1.1  jdolecek 
    177   1.1  jdolecek 		ma.ma_id = ma.ma_pos[0] + (ma.ma_pos[1] << 8);
    178   1.1  jdolecek 		if (ma.ma_id == 0xffff)	/* no adapter here */
    179   1.1  jdolecek 			continue;
    180   1.1  jdolecek 
    181  1.16  drochner 		ldesc->len = 1;
    182  1.16  drochner 		ldesc->locs[MCACF_SLOT] = slot;
    183  1.16  drochner 
    184   1.5  jdolecek 		if (ma.ma_pos[2] & MCA_POS2_ENABLE
    185   1.5  jdolecek 		    || mca_match_disabled(ma.ma_id))
    186  1.16  drochner 			config_found_sm_loc(self, "mca", ldesc, &ma,
    187  1.16  drochner 					    mca_print, mca_submatch);
    188   1.1  jdolecek 		else {
    189   1.1  jdolecek 			mca_print(&ma, self->dv_xname);
    190   1.1  jdolecek 			printf(" disabled\n");
    191   1.1  jdolecek 		}
    192   1.1  jdolecek 	}
    193   1.1  jdolecek }
    194