irongate.c revision 1.3 1 /* $NetBSD: irongate.c,v 1.3 2000/11/29 06:29:10 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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include "opt_api_up1000.h"
40
41 #include <sys/cdefs.h>
42
43 __KERNEL_RCSID(0, "$NetBSD: irongate.c,v 1.3 2000/11/29 06:29:10 thorpej Exp $");
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/device.h>
48 #include <sys/malloc.h>
49
50 #include <machine/autoconf.h>
51 #include <machine/rpb.h>
52 #include <machine/sysarch.h>
53
54 #include <dev/isa/isareg.h>
55 #include <dev/isa/isavar.h>
56 #include <dev/pci/pcireg.h>
57 #include <dev/pci/pcivar.h>
58
59 #include <alpha/pci/irongatereg.h>
60 #include <alpha/pci/irongatevar.h>
61
62 #ifdef API_UP1000
63 #include <alpha/pci/pci_up1000.h>
64 #endif
65
66 int irongate_match(struct device *, struct cfdata *, void *);
67 void irongate_attach(struct device *, struct device *, void *);
68
69 struct cfattach irongate_ca = {
70 sizeof(struct irongate_softc), irongate_match, irongate_attach,
71 };
72
73 int irongate_print(void *, const char *pnp);
74
75 extern struct cfdriver irongate_cd;
76
77 /* There can be only one. */
78 struct irongate_config irongate_configuration;
79 int irongate_found;
80
81 int irongate_bus_get_window(int, int,
82 struct alpha_bus_space_translation *);
83
84 /*
85 * Set up the chipset's function pointers.
86 */
87 void
88 irongate_init(struct irongate_config *icp, int mallocsafe)
89 {
90 pcitag_t tag;
91 pcireg_t reg;
92
93 icp->ic_mallocsafe = mallocsafe;
94
95 /*
96 * Set up PCI configuration space; we can only read the
97 * revision info through configuration space.
98 */
99 irongate_pci_init(&icp->ic_pc, icp);
100 alpha_pci_chipset = &icp->ic_pc;
101
102 tag = pci_make_tag(&icp->ic_pc, 0, IRONGATE_PCIHOST_DEV, 0);
103
104 /* Read the revision. */
105 reg = irongate_conf_read0(icp, tag, PCI_CLASS_REG);
106 icp->ic_rev = PCI_REVISION(reg);
107
108 if (icp->ic_initted == 0) {
109 /* Don't do these twice, since they set up extents. */
110 irongate_bus_io_init(&icp->ic_iot, icp);
111 irongate_bus_mem_init(&icp->ic_memt, icp);
112
113 /* Only one each PCI I/O and MEM window. */
114 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
115 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
116
117 alpha_bus_get_window = irongate_bus_get_window;
118 }
119
120 icp->ic_initted = 1;
121 }
122
123 int
124 irongate_match(struct device *parent, struct cfdata *match, void *aux)
125 {
126 struct mainbus_attach_args *ma = aux;
127
128 /* Make sure we're looking for an Irongate. */
129 if (strcmp(ma->ma_name, irongate_cd.cd_name) != 0)
130 return (0);
131
132 if (irongate_found)
133 return (0);
134
135 return (1);
136 }
137
138 void
139 irongate_attach(struct device *parent, struct device *self, void *aux)
140 {
141 struct irongate_softc *sc = (void *) self;
142 struct irongate_config *icp;
143 struct pcibus_attach_args pba;
144
145 /* Note that we've attached the chipset; can't have 2 Irongates. */
146 irongate_found = 1;
147
148 /*
149 * Set up the chipset's info; done once at console init time
150 * (maybe), but we must do it here as well to take care of things
151 * that need to use memory allocation.
152 */
153 icp = sc->sc_icp = &irongate_configuration;
154 irongate_init(icp, 1);
155
156 printf(": AMD 751 Core Logic + AGP Chipset, rev. %d\n", icp->ic_rev);
157
158 irongate_dma_init(icp);
159
160 /*
161 * Do PCI memory initialization that needs to be deferred until
162 * malloc is safe.
163 */
164 irongate_bus_mem_init2(&icp->ic_memt, icp);
165
166 switch (cputype) {
167 #ifdef API_UP1000
168 case ST_API_NAUTILUS:
169 pci_up1000_pickintr(icp);
170 break;
171 #endif
172
173 default:
174 panic("irongate_attach: shouldn't be here, really...");
175 }
176
177 pba.pba_busname = "pci";
178 pba.pba_iot = &icp->ic_iot;
179 pba.pba_memt = &icp->ic_memt;
180 pba.pba_dmat =
181 alphabus_dma_get_tag(&icp->ic_dmat_pci, ALPHA_BUS_PCI);
182 pba.pba_pc = &icp->ic_pc;
183 pba.pba_bus = 0;
184 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
185 PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
186 (void) config_found(self, &pba, irongate_print);
187 }
188
189 int
190 irongate_print(void *aux, const char *pnp)
191 {
192 struct pcibus_attach_args *pba = aux;
193
194 /* Only PCIs can attach to Irongates; easy. */
195 if (pnp != NULL)
196 printf("%s at %s", pba->pba_busname, pnp);
197 printf(" bus %d", pba->pba_bus);
198 return (UNCONF);
199 }
200
201 int
202 irongate_bus_get_window(int type, int window,
203 struct alpha_bus_space_translation *abst)
204 {
205 struct irongate_config *icp = &irongate_configuration;
206 bus_space_tag_t st;
207 int error;
208
209 switch (type) {
210 case ALPHA_BUS_TYPE_PCI_IO:
211 st = &icp->ic_iot;
212 break;
213
214 case ALPHA_BUS_TYPE_PCI_MEM:
215 st = &icp->ic_memt;
216 break;
217
218 default:
219 panic("irongate_bus_get_window");
220 }
221
222 error = alpha_bus_space_get_window(st, window, abst);
223 if (error)
224 return (error);
225
226 abst->abst_sys_start = IRONGATE_PHYSADDR(abst->abst_sys_start);
227 abst->abst_sys_end = IRONGATE_PHYSADDR(abst->abst_sys_end);
228
229 return (0);
230 }
231