lca.c revision 1.33 1 /* $NetBSD: lca.c,v 1.33 1999/04/10 01:21:38 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 "opt_dec_axppci_33.h"
31 #include "opt_dec_alphabook1.h"
32 #include "opt_dec_eb66.h"
33
34 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
35
36 __KERNEL_RCSID(0, "$NetBSD: lca.c,v 1.33 1999/04/10 01:21:38 cgd Exp $");
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/malloc.h>
42 #include <sys/device.h>
43 #include <vm/vm.h>
44
45 #include <machine/autoconf.h>
46 #include <machine/rpb.h>
47
48 #include <dev/isa/isareg.h>
49 #include <dev/isa/isavar.h>
50
51 #include <dev/pci/pcireg.h>
52 #include <dev/pci/pcivar.h>
53 #include <alpha/pci/lcareg.h>
54 #include <alpha/pci/lcavar.h>
55 #ifdef DEC_AXPPCI_33
56 #include <alpha/pci/pci_axppci_33.h>
57 #endif
58 #ifdef DEC_ALPHABOOK1
59 #include <alpha/pci/pci_alphabook1.h>
60 #endif
61 #ifdef DEC_EB66
62 #include <alpha/pci/pci_eb66.h>
63 #endif
64
65 int lcamatch __P((struct device *, struct cfdata *, void *));
66 void lcaattach __P((struct device *, struct device *, void *));
67
68 struct cfattach lca_ca = {
69 sizeof(struct lca_softc), lcamatch, lcaattach,
70 };
71
72 extern struct cfdriver lca_cd;
73
74 static int lcaprint __P((void *, const char *pnp));
75
76 /* There can be only one. */
77 int lcafound;
78 struct lca_config lca_configuration;
79
80 int
81 lcamatch(parent, match, aux)
82 struct device *parent;
83 struct cfdata *match;
84 void *aux;
85 {
86 struct mainbus_attach_args *ma = aux;
87
88 /* Make sure that we're looking for a LCA. */
89 if (strcmp(ma->ma_name, lca_cd.cd_name) != 0)
90 return (0);
91
92 if (lcafound)
93 return (0);
94
95 return (1);
96 }
97
98 /*
99 * Set up the chipset's function pointers.
100 */
101 void
102 lca_init(lcp, mallocsafe)
103 struct lca_config *lcp;
104 int mallocsafe;
105 {
106
107 /*
108 * The LCA HAE register is WRITE-ONLY, so we can't tell where
109 * the second sparse window is actually mapped. Therefore,
110 * we have to guess where it is. This seems to be the normal
111 * address.
112 */
113 lcp->lc_s_mem_w2_masked_base = 0x80000000;
114
115 if (!lcp->lc_initted) {
116 /* don't do these twice since they set up extents */
117 lca_bus_io_init(&lcp->lc_iot, lcp);
118 lca_bus_mem_init(&lcp->lc_memt, lcp);
119 }
120 lcp->lc_mallocsafe = mallocsafe;
121
122 lca_pci_init(&lcp->lc_pc, lcp);
123
124 /*
125 * Refer to ``DECchip 21066 and DECchip 21068 Alpha AXP Microprocessors
126 * Hardware Reference Manual''.
127 * ...
128 */
129
130 /*
131 * According to section 6.4.1, all bits of the IOC_HAE register are
132 * undefined after reset. Bits <31:27> are write-only. However, we
133 * cannot blindly set it to zero. The serial ROM code that initializes
134 * the PCI devices' address spaces, allocates sparse memory blocks in
135 * the range that must use the IOC_HAE register for address translation,
136 * and sets this register accordingly (see section 6.4.14).
137 *
138 * IOC_HAE left AS IS.
139 */
140
141 /* According to section 6.4.2, all bits of the IOC_CONF register are
142 * undefined after reset. Bits <1:0> are write-only. Set them to
143 * 0x00 for PCI Type 0 configuration access.
144 *
145 * IOC_CONF set to ZERO.
146 */
147 REGVAL64(LCA_IOC_CONF) = 0;
148
149 lcp->lc_initted = 1;
150 }
151
152 void
153 lcaattach(parent, self, aux)
154 struct device *parent, *self;
155 void *aux;
156 {
157 struct lca_softc *sc = (struct lca_softc *)self;
158 struct lca_config *lcp;
159 struct pcibus_attach_args pba;
160
161 /* note that we've attached the chipset; can't have 2 LCAs. */
162 /* Um, not sure about this. XXX JH */
163 lcafound = 1;
164
165 /*
166 * set up the chipset's info; done once at console init time
167 * (maybe), but we must do it twice to take care of things
168 * that need to use memory allocation.
169 */
170 lcp = sc->sc_lcp = &lca_configuration;
171 lca_init(lcp, 1);
172
173 /* XXX print chipset information */
174 printf("\n");
175
176 lca_dma_init(lcp);
177
178 switch (cputype) {
179 #ifdef DEC_AXPPCI_33
180 case ST_DEC_AXPPCI_33:
181 pci_axppci_33_pickintr(lcp);
182 break;
183 #endif
184 #ifdef DEC_ALPHABOOK1
185 case ST_ALPHABOOK1:
186 pci_alphabook1_pickintr(lcp);
187 break;
188 #endif
189 #ifdef DEC_EB66
190 case ST_EB66:
191 pci_eb66_pickintr(lcp);
192 break;
193 #endif
194
195 default:
196 panic("lcaattach: shouldn't be here, really...");
197 }
198
199 pba.pba_busname = "pci";
200 pba.pba_iot = &lcp->lc_iot;
201 pba.pba_memt = &lcp->lc_memt;
202 pba.pba_dmat =
203 alphabus_dma_get_tag(&lcp->lc_dmat_direct, ALPHA_BUS_PCI);
204 pba.pba_pc = &lcp->lc_pc;
205 pba.pba_bus = 0;
206 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
207 config_found(self, &pba, lcaprint);
208 }
209
210 static int
211 lcaprint(aux, pnp)
212 void *aux;
213 const char *pnp;
214 {
215 register struct pcibus_attach_args *pba = aux;
216
217 /* only PCIs can attach to LCAes; easy. */
218 if (pnp)
219 printf("%s at %s", pba->pba_busname, pnp);
220 printf(" bus %d", pba->pba_bus);
221 return (UNCONF);
222 }
223