Home | History | Annotate | Line # | Download | only in mca
      1 /*	$NetBSD: mca.c,v 1.34 2021/08/07 16:19:13 thorpej 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.34 2021/08/07 16:19:13 thorpej 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(device_t, cfdata_t, void *);
     54 void	mca_attach(device_t, device_t, void *);
     55 
     56 CFATTACH_DECL_NEW(mca, 0,
     57     mca_match, mca_attach, NULL, NULL);
     58 
     59 int	mca_print(void *, const char *);
     60 
     61 int
     62 mca_match(device_t parent, cfdata_t 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(device_t parent, device_t 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 	aprint_naive("\n");
    118 	aprint_normal("\n");
    119 
    120 	iot = mba->mba_iot;
    121 	memt = mba->mba_memt;
    122 	mc = mba->mba_mc;
    123 	dmat = mba->mba_dmat;
    124 
    125 	/*
    126 	 * Search for and attach subdevices.
    127 	 *
    128 	 * NB: In the adapter setup register, slots are numbered from 0,
    129 	 * but officially they are numbered from 1.
    130 	 * We use the former convention internally and the latter for text
    131 	 * messages and in config files.
    132 	 */
    133 
    134 	for (slot = 0; slot < MCA_MAX_SLOTS; slot++) {
    135 		struct mca_attach_args ma;
    136 		int reg;
    137 		int locs[MCACF_NLOCS];
    138 
    139 		ma.ma_iot = iot;
    140 		ma.ma_memt = memt;
    141 		ma.ma_dmat = dmat;
    142 		ma.ma_mc = mc;
    143 		ma.ma_slot = slot;
    144 
    145 		for(reg = 0; reg < 8; reg++)
    146 			ma.ma_pos[reg]=mca_conf_read(mc, slot, reg);
    147 
    148 		ma.ma_id = ma.ma_pos[0] + (ma.ma_pos[1] << 8);
    149 		if (ma.ma_id == 0xffff)	/* no adapter here */
    150 			continue;
    151 
    152 		locs[MCACF_SLOT] = slot;
    153 
    154 		if (ma.ma_pos[2] & MCA_POS2_ENABLE
    155 		    || mca_match_disabled(ma.ma_id))
    156 			config_found(self, &ma, mca_print,
    157 				     CFARGS(.submatch = config_stdsubmatch,
    158 					    .locators = locs));
    159 		else {
    160 			mca_print(&ma, device_xname(self));
    161 			aprint_normal(" disabled\n");
    162 		}
    163 	}
    164 }
    165