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