lca.c revision 1.55 1 /* $NetBSD: lca.c,v 1.55 2021/07/04 22:42:36 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
34 * All rights reserved.
35 *
36 * Authors: Jeffrey Hsu and Chris G. Demetriou
37 *
38 * Permission to use, copy, modify and distribute this software and
39 * its documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
43 *
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
46 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47 *
48 * Carnegie Mellon requests users of this software to return to
49 *
50 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie the
56 * rights to redistribute these changes.
57 */
58
59 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
60
61 __KERNEL_RCSID(0, "$NetBSD: lca.c,v 1.55 2021/07/04 22:42:36 thorpej Exp $");
62
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/kernel.h>
66 #include <sys/device.h>
67
68 #include <machine/autoconf.h>
69 #include <machine/rpb.h>
70 #include <machine/sysarch.h>
71
72 #include <dev/isa/isareg.h>
73 #include <dev/isa/isavar.h>
74
75 #include <dev/pci/pcireg.h>
76 #include <dev/pci/pcivar.h>
77 #include <alpha/pci/lcareg.h>
78 #include <alpha/pci/lcavar.h>
79
80 static int lcamatch(device_t, cfdata_t, void *);
81 static void lcaattach(device_t, device_t, void *);
82
83 CFATTACH_DECL_NEW(lca, sizeof(struct lca_softc),
84 lcamatch, lcaattach, NULL, NULL);
85
86 extern struct cfdriver lca_cd;
87
88 static int lca_bus_get_window(int, int,
89 struct alpha_bus_space_translation *);
90
91 /* There can be only one. */
92 struct lca_config lca_configuration;
93 static int lcafound;
94
95 static int
96 lcamatch(device_t parent, cfdata_t match, void *aux)
97 {
98 struct mainbus_attach_args *ma = aux;
99
100 /* Make sure that we're looking for a LCA. */
101 if (strcmp(ma->ma_name, lca_cd.cd_name) != 0)
102 return (0);
103
104 if (lcafound)
105 return (0);
106
107 return (1);
108 }
109
110 /*
111 * Set up the chipset's function pointers.
112 */
113 void
114 lca_init(struct lca_config *lcp, int mallocsafe)
115 {
116
117 /*
118 * The LCA HAE register is WRITE-ONLY, so we can't tell where
119 * the second sparse window is actually mapped. Therefore,
120 * we have to guess where it is. This seems to be the normal
121 * address.
122 */
123 lcp->lc_s_mem_w2_masked_base = 0x80000000;
124
125 if (!lcp->lc_initted) {
126 /* don't do these twice since they set up extents */
127 lca_bus_io_init(&lcp->lc_iot, lcp);
128 lca_bus_mem_init(&lcp->lc_memt, lcp);
129
130 /*
131 * We have 1 I/O window and 3 MEM windows.
132 */
133 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
134 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 3;
135 alpha_bus_get_window = lca_bus_get_window;
136 }
137 lcp->lc_mallocsafe = mallocsafe;
138
139 lca_pci_init(&lcp->lc_pc, lcp);
140 alpha_pci_chipset = &lcp->lc_pc;
141
142 /*
143 * Refer to ``DECchip 21066 and DECchip 21068 Alpha AXP Microprocessors
144 * Hardware Reference Manual''.
145 * ...
146 */
147
148 /*
149 * According to section 6.4.1, all bits of the IOC_HAE register are
150 * undefined after reset. Bits <31:27> are write-only. However, we
151 * cannot blindly set it to zero. The serial ROM code that initializes
152 * the PCI devices' address spaces, allocates sparse memory blocks in
153 * the range that must use the IOC_HAE register for address translation,
154 * and sets this register accordingly (see section 6.4.14).
155 *
156 * IOC_HAE left AS IS.
157 */
158
159 /* According to section 6.4.2, all bits of the IOC_CONF register are
160 * undefined after reset. Bits <1:0> are write-only. Set them to
161 * 0x00 for PCI Type 0 configuration access.
162 *
163 * IOC_CONF set to ZERO.
164 */
165 REGVAL64(LCA_IOC_CONF) = 0;
166
167 lcp->lc_initted = 1;
168 }
169
170 static void
171 lcaattach(device_t parent, device_t self, void *aux)
172 {
173 struct lca_softc *sc = device_private(self);
174 struct lca_config *lcp;
175 struct pcibus_attach_args pba;
176
177 /* note that we've attached the chipset; can't have 2 LCAs. */
178 lcafound = 1;
179 sc->sc_dev = self;
180
181 /*
182 * set up the chipset's info; done once at console init time
183 * (maybe), but we must do it twice to take care of things
184 * that need to use memory allocation.
185 */
186 lcp = sc->sc_lcp = &lca_configuration;
187 lca_init(lcp, 1);
188
189 /* XXX print chipset information */
190 aprint_normal("\n");
191
192 lca_dma_init(lcp);
193
194 alpha_pci_intr_init(lcp, &lcp->lc_iot, &lcp->lc_memt, &lcp->lc_pc);
195
196 pba.pba_iot = &lcp->lc_iot;
197 pba.pba_memt = &lcp->lc_memt;
198 pba.pba_dmat =
199 alphabus_dma_get_tag(&lcp->lc_dmat_direct, ALPHA_BUS_PCI);
200 pba.pba_dmat64 = NULL;
201 pba.pba_pc = &lcp->lc_pc;
202 pba.pba_bus = 0;
203 pba.pba_bridgetag = NULL;
204 pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
205 PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
206 config_found(self, &pba, pcibusprint, CFARG_EOL);
207 }
208
209 static int
210 lca_bus_get_window(int type, int window,
211 struct alpha_bus_space_translation *abst)
212 {
213 struct lca_config *lcp = &lca_configuration;
214 bus_space_tag_t st;
215
216 switch (type) {
217 case ALPHA_BUS_TYPE_PCI_IO:
218 st = &lcp->lc_iot;
219 break;
220
221 case ALPHA_BUS_TYPE_PCI_MEM:
222 st = &lcp->lc_memt;
223 break;
224
225 default:
226 panic("lca_bus_get_window");
227 }
228
229 return (alpha_bus_space_get_window(st, window, abst));
230 }
231