lca.c revision 1.13 1 /* $NetBSD: lca.c,v 1.13 1996/11/25 03:56:49 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Authors: Jeffrey Hsu and Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/malloc.h>
34 #include <sys/device.h>
35 #include <vm/vm.h>
36
37 #include <machine/autoconf.h>
38 #include <machine/rpb.h>
39
40 #include <dev/isa/isareg.h>
41 #include <dev/isa/isavar.h>
42
43 #include <dev/pci/pcireg.h>
44 #include <dev/pci/pcivar.h>
45 #include <alpha/pci/lcareg.h>
46 #include <alpha/pci/lcavar.h>
47 #if defined(DEC_AXPPCI_33)
48 #include <alpha/pci/pci_axppci_33.h>
49 #endif
50
51 int lcamatch __P((struct device *, void *, void *));
52 void lcaattach __P((struct device *, struct device *, void *));
53
54 struct cfattach lca_ca = {
55 sizeof(struct lca_softc), lcamatch, lcaattach,
56 };
57
58 struct cfdriver lca_cd = {
59 NULL, "lca", DV_DULL,
60 };
61
62 static int lcaprint __P((void *, const char *pnp));
63
64 /* There can be only one. */
65 int lcafound;
66 struct lca_config lca_configuration;
67
68 int
69 lcamatch(parent, match, aux)
70 struct device *parent;
71 void *match, *aux;
72 {
73 struct confargs *ca = aux;
74
75 /* Make sure that we're looking for a LCA. */
76 if (strcmp(ca->ca_name, lca_cd.cd_name) != 0)
77 return (0);
78
79 if (lcafound)
80 return (0);
81
82 return (1);
83 }
84
85 /*
86 * Set up the chipset's function pointers.
87 */
88 void
89 lca_init(lcp, mallocsafe)
90 struct lca_config *lcp;
91 int mallocsafe;
92 {
93
94 /*
95 * Can't set up SGMAP data here; can be called before malloc().
96 */
97
98 /*
99 * The LCA HAE register is WRITE-ONLY, so we can't tell where
100 * the second sparse window is actually mapped. Therefore,
101 * we have to guess where it is. This seems to be the normal
102 * address.
103 */
104 lcp->lc_s_mem_w2_masked_base = 0x80000000;
105
106 if (!lcp->lc_initted) {
107 /* don't do these twice since they set up extents */
108 lcp->lc_iot = lca_bus_io_init(lcp);
109 lcp->lc_memt = lca_bus_mem_init(lcp);
110 }
111 lcp->lc_mallocsafe = mallocsafe;
112
113 lca_pci_init(&lcp->lc_pc, lcp);
114
115 /*
116 * Refer to ``DECchip 21066 and DECchip 21068 Alpha AXP Microprocessors
117 * Hardware Reference Manual''.
118 * ...
119 */
120
121 /*
122 * According to section 6.4.1, all bits of the IOC_HAE register are
123 * undefined after reset. Bits <31:27> are write-only. However, we
124 * cannot blindly set it to zero. The serial ROM code that initializes
125 * the PCI devices' address spaces, allocates sparse memory blocks in
126 * the range that must use the IOC_HAE register for address translation,
127 * and sets this register accordingly (see section 6.4.14).
128 *
129 * IOC_HAE left AS IS.
130 */
131
132 /* According to section 6.4.2, all bits of the IOC_CONF register are
133 * undefined after reset. Bits <1:0> are write-only. Set them to
134 * 0x00 for PCI Type 0 configuration access.
135 *
136 * IOC_CONF set to ZERO.
137 */
138 REGVAL(LCA_IOC_CONF) = 0;
139
140 /* Turn off DMA window enables in Window Base Registers */
141 /* REGVAL(LCA_IOC_W_BASE0) = 0;
142 REGVAL(LCA_IOC_W_BASE1) = 0; */
143 alpha_mb();
144
145 /* XXX XXX BEGIN XXX XXX */
146 { /* XXX */
147 extern vm_offset_t alpha_XXX_dmamap_or; /* XXX */
148 alpha_XXX_dmamap_or = 0x40000000; /* XXX */
149 } /* XXX */
150 /* XXX XXX END XXX XXX */
151
152 lcp->lc_initted = 1;
153 }
154
155 #ifdef notdef
156 void
157 lca_init_sgmap(lcp)
158 struct lca_config *lcp;
159 {
160
161 /* XXX */
162 lcp->lc_sgmap = malloc(1024 * 8, M_DEVBUF, M_WAITOK);
163 bzero(lcp->lc_sgmap, 1024 * 8); /* clear all entries. */
164
165 REGVAL(LCA_IOC_W_BASE0) = 0;
166 alpha_mb();
167
168 /* Set up Translated Base Register 1; translate to sybBus addr 0. */
169 /* check size against APEC XXX JH */
170 REGVAL(LCA_IOC_T_BASE_0) = vtophys(lcp->lc_sgmap) >> 1;
171
172 /* Set up PCI mask register 1; map 8MB space. */
173 REGVAL(LCA_IOC_W_MASK0) = 0x00700000;
174
175 /* Enable window 1; from PCI address 8MB, direct mapped. */
176 REGVAL(LCA_IOC_W_BASE0) = 0x300800000;
177 alpha_mb();
178 }
179 #endif
180
181 void
182 lcaattach(parent, self, aux)
183 struct device *parent, *self;
184 void *aux;
185 {
186 struct lca_softc *sc = (struct lca_softc *)self;
187 struct lca_config *lcp;
188 struct pcibus_attach_args pba;
189
190 /* note that we've attached the chipset; can't have 2 LCAs. */
191 /* Um, not sure about this. XXX JH */
192 lcafound = 1;
193
194 /*
195 * set up the chipset's info; done once at console init time
196 * (maybe), but doesn't hurt to do twice.
197 */
198 lcp = sc->sc_lcp = &lca_configuration;
199 lca_init(lcp, 1);
200 #ifdef notdef
201 lca_init_sgmap(lcp);
202 #endif
203
204 /* XXX print chipset information */
205 printf("\n");
206
207 switch (hwrpb->rpb_type) {
208 #if defined(DEC_AXPPCI_33)
209 case ST_DEC_AXPPCI_33:
210 pci_axppci_33_pickintr(lcp);
211 break;
212 #endif
213
214 default:
215 panic("lcaattach: shouldn't be here, really...");
216 }
217
218 pba.pba_busname = "pci";
219 pba.pba_iot = lcp->lc_iot;
220 pba.pba_memt = lcp->lc_memt;
221 pba.pba_pc = &lcp->lc_pc;
222 pba.pba_bus = 0;
223 config_found(self, &pba, lcaprint);
224 }
225
226 static int
227 lcaprint(aux, pnp)
228 void *aux;
229 const char *pnp;
230 {
231 register struct pcibus_attach_args *pba = aux;
232
233 /* only PCIs can attach to LCAes; easy. */
234 if (pnp)
235 printf("%s at %s", pba->pba_busname, pnp);
236 printf(" bus %d", pba->pba_bus);
237 return (UNCONF);
238 }
239