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