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