irongate.c revision 1.22 1 1.22 thorpej /* $NetBSD: irongate.c,v 1.22 2023/12/04 00:32:10 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.4 thorpej * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.4 thorpej * by Jason R. Thorpe of Wasabi Systems, Inc.
9 1.1 thorpej *
10 1.1 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1 thorpej * modification, are permitted provided that the following conditions
12 1.1 thorpej * are met:
13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1 thorpej * documentation and/or other materials provided with the distribution.
18 1.1 thorpej *
19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
30 1.1 thorpej */
31 1.1 thorpej
32 1.1 thorpej #include <sys/cdefs.h>
33 1.1 thorpej
34 1.22 thorpej __KERNEL_RCSID(0, "$NetBSD: irongate.c,v 1.22 2023/12/04 00:32:10 thorpej Exp $");
35 1.1 thorpej
36 1.1 thorpej #include <sys/param.h>
37 1.1 thorpej #include <sys/systm.h>
38 1.1 thorpej #include <sys/device.h>
39 1.1 thorpej
40 1.1 thorpej #include <machine/autoconf.h>
41 1.1 thorpej #include <machine/rpb.h>
42 1.1 thorpej #include <machine/sysarch.h>
43 1.1 thorpej
44 1.1 thorpej #include <dev/isa/isareg.h>
45 1.1 thorpej #include <dev/isa/isavar.h>
46 1.1 thorpej #include <dev/pci/pcireg.h>
47 1.1 thorpej #include <dev/pci/pcivar.h>
48 1.4 thorpej #include <dev/pci/agpvar.h>
49 1.1 thorpej
50 1.1 thorpej #include <alpha/pci/irongatereg.h>
51 1.1 thorpej #include <alpha/pci/irongatevar.h>
52 1.1 thorpej
53 1.18 thorpej static int irongate_match(device_t, cfdata_t, void *);
54 1.18 thorpej static void irongate_attach(device_t, device_t, void *);
55 1.1 thorpej
56 1.16 matt CFATTACH_DECL_NEW(irongate, sizeof(struct irongate_softc),
57 1.9 thorpej irongate_match, irongate_attach, NULL, NULL);
58 1.1 thorpej
59 1.1 thorpej extern struct cfdriver irongate_cd;
60 1.1 thorpej
61 1.1 thorpej /* There can be only one. */
62 1.1 thorpej struct irongate_config irongate_configuration;
63 1.18 thorpej static int irongate_found;
64 1.1 thorpej
65 1.18 thorpej static int irongate_bus_get_window(int, int,
66 1.18 thorpej struct alpha_bus_space_translation *);
67 1.1 thorpej
68 1.1 thorpej /*
69 1.1 thorpej * Set up the chipset's function pointers.
70 1.1 thorpej */
71 1.1 thorpej void
72 1.22 thorpej irongate_init(struct irongate_config *icp)
73 1.1 thorpej {
74 1.1 thorpej pcitag_t tag;
75 1.1 thorpej pcireg_t reg;
76 1.1 thorpej
77 1.1 thorpej /*
78 1.1 thorpej * Set up PCI configuration space; we can only read the
79 1.1 thorpej * revision info through configuration space.
80 1.1 thorpej */
81 1.1 thorpej irongate_pci_init(&icp->ic_pc, icp);
82 1.1 thorpej alpha_pci_chipset = &icp->ic_pc;
83 1.1 thorpej
84 1.1 thorpej tag = pci_make_tag(&icp->ic_pc, 0, IRONGATE_PCIHOST_DEV, 0);
85 1.1 thorpej
86 1.1 thorpej /* Read the revision. */
87 1.1 thorpej reg = irongate_conf_read0(icp, tag, PCI_CLASS_REG);
88 1.1 thorpej icp->ic_rev = PCI_REVISION(reg);
89 1.1 thorpej
90 1.1 thorpej if (icp->ic_initted == 0) {
91 1.1 thorpej /* Don't do these twice, since they set up extents. */
92 1.1 thorpej irongate_bus_io_init(&icp->ic_iot, icp);
93 1.1 thorpej irongate_bus_mem_init(&icp->ic_memt, icp);
94 1.1 thorpej
95 1.1 thorpej /* Only one each PCI I/O and MEM window. */
96 1.1 thorpej alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
97 1.1 thorpej alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
98 1.1 thorpej
99 1.1 thorpej alpha_bus_get_window = irongate_bus_get_window;
100 1.1 thorpej }
101 1.1 thorpej
102 1.1 thorpej icp->ic_initted = 1;
103 1.1 thorpej }
104 1.1 thorpej
105 1.18 thorpej static int
106 1.16 matt irongate_match(device_t parent, cfdata_t match, void *aux)
107 1.1 thorpej {
108 1.1 thorpej struct mainbus_attach_args *ma = aux;
109 1.1 thorpej
110 1.1 thorpej /* Make sure we're looking for an Irongate. */
111 1.1 thorpej if (strcmp(ma->ma_name, irongate_cd.cd_name) != 0)
112 1.1 thorpej return (0);
113 1.1 thorpej
114 1.1 thorpej if (irongate_found)
115 1.1 thorpej return (0);
116 1.1 thorpej
117 1.1 thorpej return (1);
118 1.1 thorpej }
119 1.1 thorpej
120 1.18 thorpej static void
121 1.16 matt irongate_attach(device_t parent, device_t self, void *aux)
122 1.1 thorpej {
123 1.16 matt struct irongate_softc *sc = device_private(self);
124 1.1 thorpej struct irongate_config *icp;
125 1.1 thorpej struct pcibus_attach_args pba;
126 1.4 thorpej struct agpbus_attach_args apa;
127 1.4 thorpej pcitag_t tag;
128 1.1 thorpej
129 1.1 thorpej /* Note that we've attached the chipset; can't have 2 Irongates. */
130 1.1 thorpej irongate_found = 1;
131 1.16 matt sc->sc_dev = self;
132 1.1 thorpej
133 1.1 thorpej /*
134 1.1 thorpej * Set up the chipset's info; done once at console init time
135 1.1 thorpej * (maybe), but we must do it here as well to take care of things
136 1.1 thorpej * that need to use memory allocation.
137 1.1 thorpej */
138 1.1 thorpej icp = sc->sc_icp = &irongate_configuration;
139 1.22 thorpej irongate_init(icp);
140 1.1 thorpej
141 1.1 thorpej printf(": AMD 751 Core Logic + AGP Chipset, rev. %d\n", icp->ic_rev);
142 1.1 thorpej
143 1.1 thorpej irongate_dma_init(icp);
144 1.3 thorpej
145 1.3 thorpej /*
146 1.3 thorpej * Do PCI memory initialization that needs to be deferred until
147 1.3 thorpej * malloc is safe.
148 1.3 thorpej */
149 1.3 thorpej irongate_bus_mem_init2(&icp->ic_memt, icp);
150 1.1 thorpej
151 1.19 thorpej alpha_pci_intr_init(icp, &icp->ic_iot, &icp->ic_memt, &icp->ic_pc);
152 1.1 thorpej
153 1.4 thorpej tag = pci_make_tag(&icp->ic_pc, 0, IRONGATE_PCIHOST_DEV, 0);
154 1.4 thorpej
155 1.4 thorpej pba.pba_iot = &icp->ic_iot;
156 1.4 thorpej pba.pba_memt = &icp->ic_memt;
157 1.4 thorpej pba.pba_dmat =
158 1.4 thorpej alphabus_dma_get_tag(&icp->ic_dmat_pci, ALPHA_BUS_PCI);
159 1.11 fvdl pba.pba_dmat64 = NULL;
160 1.4 thorpej pba.pba_pc = &icp->ic_pc;
161 1.4 thorpej pba.pba_bus = 0;
162 1.7 thorpej pba.pba_bridgetag = NULL;
163 1.15 dyoung pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
164 1.4 thorpej PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
165 1.4 thorpej
166 1.4 thorpej if (pci_get_capability(&icp->ic_pc, tag, PCI_CAP_AGP,
167 1.4 thorpej NULL, NULL) != 0) {
168 1.4 thorpej apa.apa_pci_args.pa_iot = pba.pba_iot;
169 1.4 thorpej apa.apa_pci_args.pa_memt = pba.pba_memt;
170 1.6 thorpej apa.apa_pci_args.pa_dmat = pba.pba_dmat;
171 1.4 thorpej apa.apa_pci_args.pa_pc = pba.pba_pc;
172 1.4 thorpej apa.apa_pci_args.pa_bus = pba.pba_bus;
173 1.4 thorpej apa.apa_pci_args.pa_device = IRONGATE_PCIHOST_DEV;
174 1.4 thorpej apa.apa_pci_args.pa_function = 0;
175 1.4 thorpej apa.apa_pci_args.pa_tag = tag;
176 1.4 thorpej apa.apa_pci_args.pa_id =
177 1.4 thorpej irongate_conf_read0(icp, tag, PCI_ID_REG);
178 1.4 thorpej apa.apa_pci_args.pa_class =
179 1.4 thorpej irongate_conf_read0(icp, tag, PCI_CLASS_REG);
180 1.4 thorpej apa.apa_pci_args.pa_flags = pba.pba_flags;
181 1.4 thorpej
182 1.17 thorpej config_found(self, &apa, agpbusprint,
183 1.21 thorpej CFARGS(.iattr = "agpbus"));
184 1.4 thorpej }
185 1.4 thorpej
186 1.17 thorpej config_found(self, &pba, pcibusprint,
187 1.21 thorpej CFARGS(.iattr = "pcibus"));
188 1.1 thorpej }
189 1.1 thorpej
190 1.18 thorpej static int
191 1.1 thorpej irongate_bus_get_window(int type, int window,
192 1.1 thorpej struct alpha_bus_space_translation *abst)
193 1.1 thorpej {
194 1.1 thorpej struct irongate_config *icp = &irongate_configuration;
195 1.1 thorpej bus_space_tag_t st;
196 1.2 thorpej int error;
197 1.1 thorpej
198 1.1 thorpej switch (type) {
199 1.1 thorpej case ALPHA_BUS_TYPE_PCI_IO:
200 1.1 thorpej st = &icp->ic_iot;
201 1.1 thorpej break;
202 1.1 thorpej
203 1.1 thorpej case ALPHA_BUS_TYPE_PCI_MEM:
204 1.1 thorpej st = &icp->ic_memt;
205 1.1 thorpej break;
206 1.1 thorpej
207 1.1 thorpej default:
208 1.1 thorpej panic("irongate_bus_get_window");
209 1.1 thorpej }
210 1.1 thorpej
211 1.2 thorpej error = alpha_bus_space_get_window(st, window, abst);
212 1.2 thorpej if (error)
213 1.2 thorpej return (error);
214 1.2 thorpej
215 1.2 thorpej abst->abst_sys_start = IRONGATE_PHYSADDR(abst->abst_sys_start);
216 1.2 thorpej abst->abst_sys_end = IRONGATE_PHYSADDR(abst->abst_sys_end);
217 1.2 thorpej
218 1.2 thorpej return (0);
219 1.1 thorpej }
220