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