pchb.c revision 1.1 1 1.1 shige /* $NetBSD: pchb.c,v 1.1 2003/09/23 15:30:22 shige Exp $ */
2 1.1 shige
3 1.1 shige /*-
4 1.1 shige * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1 shige * All rights reserved.
6 1.1 shige *
7 1.1 shige * This code is derived from software contributed to The NetBSD Foundation
8 1.1 shige * by Jason R. Thorpe.
9 1.1 shige *
10 1.1 shige * Redistribution and use in source and binary forms, with or without
11 1.1 shige * modification, are permitted provided that the following conditions
12 1.1 shige * are met:
13 1.1 shige * 1. Redistributions of source code must retain the above copyright
14 1.1 shige * notice, this list of conditions and the following disclaimer.
15 1.1 shige * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 shige * notice, this list of conditions and the following disclaimer in the
17 1.1 shige * documentation and/or other materials provided with the distribution.
18 1.1 shige * 3. All advertising materials mentioning features or use of this software
19 1.1 shige * must display the following acknowledgement:
20 1.1 shige * This product includes software developed by the NetBSD
21 1.1 shige * Foundation, Inc. and its contributors.
22 1.1 shige * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 shige * contributors may be used to endorse or promote products derived
24 1.1 shige * from this software without specific prior written permission.
25 1.1 shige *
26 1.1 shige * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 shige * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 shige * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 shige * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
30 1.1 shige * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 shige * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 shige * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 shige * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 shige * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 shige * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 shige * POSSIBILITY OF SUCH DAMAGE.
37 1.1 shige */
38 1.1 shige #include <sys/cdefs.h>
39 1.1 shige __KERNEL_RCSID(0, "$NetBSD: pchb.c,v 1.1 2003/09/23 15:30:22 shige Exp $");
40 1.1 shige
41 1.1 shige #include "pci.h"
42 1.1 shige #include "opt_pci.h"
43 1.1 shige
44 1.1 shige #include <sys/types.h>
45 1.1 shige #include <sys/param.h>
46 1.1 shige #include <sys/systm.h>
47 1.1 shige #include <sys/device.h>
48 1.1 shige #include <sys/extent.h>
49 1.1 shige #include <sys/malloc.h>
50 1.1 shige
51 1.1 shige #define _IBM4XX_BUS_DMA_PRIVATE
52 1.1 shige
53 1.1 shige #include <powerpc/ibm4xx/ibm405gp.h>
54 1.1 shige #include <powerpc/ibm4xx/dev/plbvar.h>
55 1.1 shige
56 1.1 shige #include <dev/pci/pcivar.h>
57 1.1 shige #include <dev/pci/pcireg.h>
58 1.1 shige #include <dev/pci/pcidevs.h>
59 1.1 shige #include <dev/pci/pciconf.h>
60 1.1 shige
61 1.1 shige static int pchbmatch(struct device *, struct cfdata *, void *);
62 1.1 shige static void pchbattach(struct device *, struct device *, void *);
63 1.1 shige static int pchbprint(void *, const char *);
64 1.1 shige
65 1.1 shige CFATTACH_DECL(pchb, sizeof(struct device),
66 1.1 shige pchbmatch, pchbattach, NULL, NULL);
67 1.1 shige
68 1.1 shige static int pcifound = 0;
69 1.1 shige
70 1.1 shige /* IO window located @ e8000000 and maps to 0-0xffff */
71 1.1 shige static struct powerpc_bus_space pchb_io_tag = {
72 1.1 shige _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_IO_TYPE,
73 1.1 shige IBM405GP_PLB_PCI_IO_START, /* offset */
74 1.1 shige IBM405GP_PCI_PCI_IO_START, /* extent base */
75 1.1 shige IBM405GP_PCI_PCI_IO_START + 0xffff, /* extent limit */
76 1.1 shige };
77 1.1 shige
78 1.1 shige /* PCI memory window is directly mapped */
79 1.1 shige static struct powerpc_bus_space pchb_mem_tag = {
80 1.1 shige _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE,
81 1.1 shige 0x00000000, /* offset */
82 1.1 shige IBM405GP_PCI_MEM_START, /* extent base */
83 1.1 shige IBM405GP_PCI_MEM_START + 0x1fffffff, /* extent limit */
84 1.1 shige };
85 1.1 shige
86 1.1 shige
87 1.1 shige static int
88 1.1 shige pchbmatch(struct device *parent, struct cfdata *cf, void *aux)
89 1.1 shige {
90 1.1 shige struct plb_attach_args *paa = aux;
91 1.1 shige /* XXX chipset tag unused by walnut, so just pass 0 */
92 1.1 shige pci_chipset_tag_t pc = 0;
93 1.1 shige pcitag_t tag;
94 1.1 shige int class, id;
95 1.1 shige
96 1.1 shige /* match only pchb devices */
97 1.1 shige if (strcmp(paa->plb_name, cf->cf_name) != 0)
98 1.1 shige return 0;
99 1.1 shige
100 1.1 shige pci_machdep_init();
101 1.1 shige tag = pci_make_tag(pc, 0, 0, 0);
102 1.1 shige
103 1.1 shige class = pci_conf_read(pc, tag, PCI_CLASS_REG);
104 1.1 shige id = pci_conf_read(pc, tag, PCI_ID_REG);
105 1.1 shige
106 1.1 shige /*
107 1.1 shige * Match all known PCI host chipsets.
108 1.1 shige */
109 1.1 shige if (PCI_CLASS(class) == PCI_CLASS_BRIDGE &&
110 1.1 shige PCI_SUBCLASS(class) == PCI_SUBCLASS_BRIDGE_HOST) {
111 1.1 shige switch (PCI_VENDOR(id)) {
112 1.1 shige case PCI_VENDOR_IBM:
113 1.1 shige switch (PCI_PRODUCT(id)) {
114 1.1 shige case PCI_PRODUCT_IBM_405GP:
115 1.1 shige return (!pcifound);
116 1.1 shige }
117 1.1 shige break;
118 1.1 shige }
119 1.1 shige }
120 1.1 shige return (0);
121 1.1 shige }
122 1.1 shige
123 1.1 shige static void
124 1.1 shige pchbattach(struct device *parent, struct device *self, void *aux)
125 1.1 shige {
126 1.1 shige struct plb_attach_args *paa = aux;
127 1.1 shige struct pcibus_attach_args pba;
128 1.1 shige char devinfo[256];
129 1.1 shige #ifdef PCI_NETBSD_CONFIGURE
130 1.1 shige struct extent *ioext, *memext;
131 1.1 shige #ifdef PCI_CONFIGURE_VERBOSE
132 1.1 shige extern int pci_conf_debug;
133 1.1 shige
134 1.1 shige pci_conf_debug = 1;
135 1.1 shige #endif
136 1.1 shige #endif
137 1.1 shige pci_chipset_tag_t pc = 0;
138 1.1 shige pcitag_t tag;
139 1.1 shige int class, id;
140 1.1 shige
141 1.1 shige pci_machdep_init();
142 1.1 shige tag = pci_make_tag(pc, 0, 0, 0);
143 1.1 shige
144 1.1 shige class = pci_conf_read(pc, tag, PCI_CLASS_REG);
145 1.1 shige id = pci_conf_read(pc, tag, PCI_ID_REG);
146 1.1 shige
147 1.1 shige printf("\n");
148 1.1 shige pcifound++;
149 1.1 shige /*
150 1.1 shige * All we do is print out a description. Eventually, we
151 1.1 shige * might want to add code that does something that's
152 1.1 shige * possibly chipset-specific.
153 1.1 shige */
154 1.1 shige
155 1.1 shige pci_devinfo(id, class, 0, devinfo);
156 1.1 shige printf("%s: %s (rev. 0x%02x)\n", self->dv_xname, devinfo,
157 1.1 shige PCI_REVISION(class));
158 1.1 shige
159 1.1 shige pci_machdep_init(); /* Redundant... */
160 1.1 shige ibm4xx_setup_pci();
161 1.1 shige #ifdef PCI_CONFIGURE_VERBOSE
162 1.1 shige ibm4xx_show_pci_map();
163 1.1 shige #endif
164 1.1 shige
165 1.1 shige if (bus_space_init(&pchb_io_tag, "pchbio", NULL, 0))
166 1.1 shige panic("pchbattach: can't init IO tag");
167 1.1 shige if (bus_space_init(&pchb_mem_tag, "pchbmem", NULL, 0))
168 1.1 shige panic("pchbattach: can't init MEM tag");
169 1.1 shige
170 1.1 shige #ifdef PCI_NETBSD_CONFIGURE
171 1.1 shige memext = extent_create("pcimem", IBM405GP_PCI_MEM_START,
172 1.1 shige IBM405GP_PCI_MEM_START + 0x1fffffff, M_DEVBUF, NULL, 0,
173 1.1 shige EX_NOWAIT);
174 1.1 shige ioext = extent_create("pciio", IBM405GP_PCI_PCI_IO_START,
175 1.1 shige IBM405GP_PCI_PCI_IO_START + 0xffff, M_DEVBUF, NULL, 0, EX_NOWAIT);
176 1.1 shige pci_configure_bus(0, ioext, memext, NULL, 0, 32);
177 1.1 shige extent_destroy(memext);
178 1.1 shige extent_destroy(ioext);
179 1.1 shige #endif /* PCI_NETBSD_CONFIGURE */
180 1.1 shige
181 1.1 shige #ifdef PCI_CONFIGURE_VERBOSE
182 1.1 shige printf("running config_found PCI\n");
183 1.1 shige #endif
184 1.1 shige pba.pba_busname = "pci";
185 1.1 shige /* IO window located @ e8000000 and maps to 0-0xffff */
186 1.1 shige pba.pba_iot = &pchb_io_tag;
187 1.1 shige /* PCI memory window is directly mapped */
188 1.1 shige pba.pba_memt = &pchb_mem_tag;
189 1.1 shige pba.pba_dmat = paa->plb_dmat;
190 1.1 shige pba.pba_dmat64 = NULL;
191 1.1 shige pba.pba_bus = 0;
192 1.1 shige pba.pba_bridgetag = NULL;
193 1.1 shige pba.pba_flags = PCI_FLAGS_MEM_ENABLED | PCI_FLAGS_IO_ENABLED;
194 1.1 shige config_found(self, &pba, pchbprint);
195 1.1 shige }
196 1.1 shige
197 1.1 shige
198 1.1 shige static int
199 1.1 shige pchbprint(void *aux, const char *p)
200 1.1 shige {
201 1.1 shige
202 1.1 shige if (p == NULL)
203 1.1 shige return (UNCONF);
204 1.1 shige return (QUIET);
205 1.1 shige }
206 1.1 shige
207 1.1 shige #if 0
208 1.1 shige static void
209 1.1 shige scan_pci_bus(void)
210 1.1 shige {
211 1.1 shige pcitag_t tag;
212 1.1 shige int i, x;
213 1.1 shige
214 1.1 shige for (i=0;i<32;i++){
215 1.1 shige tag = pci_make_tag(0, 0, i, 0);
216 1.1 shige x = pci_conf_read(0, tag, 0);
217 1.1 shige printf("%d tag=%08x : %08x\n", i, tag, x);
218 1.1 shige #if 0
219 1.1 shige if (PCI_VENDOR(x) == PCI_VENDOR_INTEL
220 1.1 shige && PCI_PRODUCT(x) == PCI_PRODUCT_INTEL_80960_RP) {
221 1.1 shige /* Do not configure PCI bus analyzer */
222 1.1 shige continue;
223 1.1 shige }
224 1.1 shige x = pci_conf_read(0, tag, PCI_COMMAND_STATUS_REG);
225 1.1 shige x |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE;
226 1.1 shige pci_conf_write(0, tag, PCI_COMMAND_STATUS_REG, x);
227 1.1 shige #endif
228 1.1 shige }
229 1.1 shige }
230 1.1 shige #endif
231