mca.c revision 1.1.6.2 1 1.1.6.2 bouyer /* $NetBSD: mca.c,v 1.1.6.2 2000/11/20 11:41:30 bouyer Exp $ */
2 1.1.6.2 bouyer
3 1.1.6.2 bouyer /*-
4 1.1.6.2 bouyer * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1.6.2 bouyer * Copyright (c) 1996-1999 Scott D. Telford.
6 1.1.6.2 bouyer * All rights reserved.
7 1.1.6.2 bouyer *
8 1.1.6.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
9 1.1.6.2 bouyer * by Scott Telford <s.telford (at) ed.ac.uk>.
10 1.1.6.2 bouyer *
11 1.1.6.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.6.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.6.2 bouyer * are met:
14 1.1.6.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.6.2 bouyer * notice, this list of conditions and the following disclaimer.
16 1.1.6.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.6.2 bouyer * notice, this list of conditions and the following disclaimer in the
18 1.1.6.2 bouyer * documentation and/or other materials provided with the distribution.
19 1.1.6.2 bouyer * 3. All advertising materials mentioning features or use of this software
20 1.1.6.2 bouyer * must display the following acknowledgement:
21 1.1.6.2 bouyer * This product includes software developed by the NetBSD
22 1.1.6.2 bouyer * Foundation, Inc. and its contributors.
23 1.1.6.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1.6.2 bouyer * contributors may be used to endorse or promote products derived
25 1.1.6.2 bouyer * from this software without specific prior written permission.
26 1.1.6.2 bouyer *
27 1.1.6.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1.6.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1.6.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1.6.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1.6.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1.6.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1.6.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1.6.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1.6.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1.6.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1.6.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
38 1.1.6.2 bouyer */
39 1.1.6.2 bouyer
40 1.1.6.2 bouyer /*
41 1.1.6.2 bouyer * MCA Bus device
42 1.1.6.2 bouyer */
43 1.1.6.2 bouyer
44 1.1.6.2 bouyer #include "opt_mcaverbose.h"
45 1.1.6.2 bouyer
46 1.1.6.2 bouyer #include <sys/param.h>
47 1.1.6.2 bouyer #include <sys/systm.h>
48 1.1.6.2 bouyer #include <sys/device.h>
49 1.1.6.2 bouyer
50 1.1.6.2 bouyer #include <machine/bus.h>
51 1.1.6.2 bouyer
52 1.1.6.2 bouyer #include <dev/mca/mcareg.h>
53 1.1.6.2 bouyer #include <dev/mca/mcavar.h>
54 1.1.6.2 bouyer
55 1.1.6.2 bouyer
56 1.1.6.2 bouyer int mca_match __P((struct device *, struct cfdata *, void *));
57 1.1.6.2 bouyer void mca_attach __P((struct device *, struct device *, void *));
58 1.1.6.2 bouyer
59 1.1.6.2 bouyer struct cfattach mca_ca = {
60 1.1.6.2 bouyer sizeof(struct device), mca_match, mca_attach
61 1.1.6.2 bouyer };
62 1.1.6.2 bouyer
63 1.1.6.2 bouyer int mca_submatch __P((struct device *, struct cfdata *, void *));
64 1.1.6.2 bouyer int mca_print __P((void *, const char *));
65 1.1.6.2 bouyer
66 1.1.6.2 bouyer int
67 1.1.6.2 bouyer mca_match(parent, cf, aux)
68 1.1.6.2 bouyer struct device *parent;
69 1.1.6.2 bouyer struct cfdata *cf;
70 1.1.6.2 bouyer void *aux;
71 1.1.6.2 bouyer {
72 1.1.6.2 bouyer struct mcabus_attach_args *mba = aux;
73 1.1.6.2 bouyer
74 1.1.6.2 bouyer if (strcmp(mba->mba_busname, cf->cf_driver->cd_name))
75 1.1.6.2 bouyer return (0);
76 1.1.6.2 bouyer
77 1.1.6.2 bouyer /* sanity (only mca0 supported currently) */
78 1.1.6.2 bouyer if (mba->mba_bus < 0 || mba->mba_bus > 0)
79 1.1.6.2 bouyer return (0);
80 1.1.6.2 bouyer
81 1.1.6.2 bouyer /* XXX check other indicators? */
82 1.1.6.2 bouyer
83 1.1.6.2 bouyer return (1);
84 1.1.6.2 bouyer }
85 1.1.6.2 bouyer
86 1.1.6.2 bouyer int
87 1.1.6.2 bouyer mca_print(aux, pnp)
88 1.1.6.2 bouyer void *aux;
89 1.1.6.2 bouyer const char *pnp;
90 1.1.6.2 bouyer {
91 1.1.6.2 bouyer register struct mca_attach_args *ma = aux;
92 1.1.6.2 bouyer char devinfo[256];
93 1.1.6.2 bouyer
94 1.1.6.2 bouyer if (pnp) {
95 1.1.6.2 bouyer mca_devinfo(ma->ma_id, devinfo);
96 1.1.6.2 bouyer printf("%s slot %d: %s", pnp, ma->ma_slot + 1, devinfo);
97 1.1.6.2 bouyer }
98 1.1.6.2 bouyer
99 1.1.6.2 bouyer return (mca_issupp(ma->ma_id)) ? UNCONF : UNSUPP;
100 1.1.6.2 bouyer }
101 1.1.6.2 bouyer
102 1.1.6.2 bouyer int
103 1.1.6.2 bouyer mca_submatch(parent, cf, aux)
104 1.1.6.2 bouyer struct device *parent;
105 1.1.6.2 bouyer struct cfdata *cf;
106 1.1.6.2 bouyer void *aux;
107 1.1.6.2 bouyer {
108 1.1.6.2 bouyer struct mca_attach_args *ma = aux;
109 1.1.6.2 bouyer
110 1.1.6.2 bouyer if (cf->mcacf_slot != MCA_UNKNOWN_SLOT &&
111 1.1.6.2 bouyer cf->mcacf_slot != ma->ma_slot)
112 1.1.6.2 bouyer return 0;
113 1.1.6.2 bouyer return ((*cf->cf_attach->ca_match)(parent, cf, aux));
114 1.1.6.2 bouyer }
115 1.1.6.2 bouyer
116 1.1.6.2 bouyer void
117 1.1.6.2 bouyer mca_attach(parent, self, aux)
118 1.1.6.2 bouyer struct device *parent, *self;
119 1.1.6.2 bouyer void *aux;
120 1.1.6.2 bouyer {
121 1.1.6.2 bouyer struct mcabus_attach_args *mba = aux;
122 1.1.6.2 bouyer bus_space_tag_t iot, memt;
123 1.1.6.2 bouyer bus_dma_tag_t dmat;
124 1.1.6.2 bouyer mca_chipset_tag_t mc;
125 1.1.6.2 bouyer int slot;
126 1.1.6.2 bouyer
127 1.1.6.2 bouyer mca_attach_hook(parent, self, mba);
128 1.1.6.2 bouyer printf("\n");
129 1.1.6.2 bouyer
130 1.1.6.2 bouyer iot = mba->mba_iot;
131 1.1.6.2 bouyer memt = mba->mba_memt;
132 1.1.6.2 bouyer mc = mba->mba_mc;
133 1.1.6.2 bouyer dmat = mba->mba_dmat;
134 1.1.6.2 bouyer
135 1.1.6.2 bouyer /*
136 1.1.6.2 bouyer * Search for and attach subdevices.
137 1.1.6.2 bouyer *
138 1.1.6.2 bouyer * NB: In the adapter setup register, slots are numbered from 0,
139 1.1.6.2 bouyer * but officially they are numbered from 1.
140 1.1.6.2 bouyer * We use the former convention internally and the latter for text
141 1.1.6.2 bouyer * messages and in config files.
142 1.1.6.2 bouyer */
143 1.1.6.2 bouyer
144 1.1.6.2 bouyer for (slot = 0; slot < MCA_MAX_SLOTS; slot++) {
145 1.1.6.2 bouyer struct mca_attach_args ma;
146 1.1.6.2 bouyer int reg;
147 1.1.6.2 bouyer
148 1.1.6.2 bouyer ma.ma_iot = iot;
149 1.1.6.2 bouyer ma.ma_memt = memt;
150 1.1.6.2 bouyer ma.ma_dmat = dmat;
151 1.1.6.2 bouyer ma.ma_mc = mc;
152 1.1.6.2 bouyer ma.ma_slot = slot;
153 1.1.6.2 bouyer
154 1.1.6.2 bouyer for(reg = 0; reg < 8; reg++)
155 1.1.6.2 bouyer ma.ma_pos[reg]=mca_conf_read(mc, slot, reg);
156 1.1.6.2 bouyer
157 1.1.6.2 bouyer ma.ma_id = ma.ma_pos[0] + (ma.ma_pos[1] << 8);
158 1.1.6.2 bouyer if (ma.ma_id == 0xffff) /* no adapter here */
159 1.1.6.2 bouyer continue;
160 1.1.6.2 bouyer
161 1.1.6.2 bouyer if (ma.ma_pos[2] & MCA_POS2_ENABLE)
162 1.1.6.2 bouyer config_found_sm(self, &ma, mca_print, mca_submatch);
163 1.1.6.2 bouyer else {
164 1.1.6.2 bouyer mca_print(&ma, self->dv_xname);
165 1.1.6.2 bouyer printf(" disabled\n");
166 1.1.6.2 bouyer }
167 1.1.6.2 bouyer }
168 1.1.6.2 bouyer }
169