No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / evbppc / walnut / pci / pchb.c
blob906d69d8e5f31cb1462c9ed467e017cd386e4a79
1 /* $NetBSD: pchb.c,v 1.7 2005/12/11 12:17:13 christos Exp $ */
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
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.
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.
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: pchb.c,v 1.7 2005/12/11 12:17:13 christos Exp $");
34 #include "pci.h"
35 #include "opt_pci.h"
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/device.h>
41 #include <sys/extent.h>
42 #include <sys/malloc.h>
44 #define _IBM4XX_BUS_DMA_PRIVATE
45 #include <machine/walnut.h>
47 #include <powerpc/ibm4xx/ibm405gp.h>
48 #include <powerpc/ibm4xx/dev/plbvar.h>
50 #include <dev/pci/pcivar.h>
51 #include <dev/pci/pcireg.h>
52 #include <dev/pci/pcidevs.h>
53 #include <dev/pci/pciconf.h>
55 static int pchbmatch(struct device *, struct cfdata *, void *);
56 static void pchbattach(struct device *, struct device *, void *);
57 static int pchbprint(void *, const char *);
59 CFATTACH_DECL(pchb, sizeof(struct device),
60 pchbmatch, pchbattach, NULL, NULL);
62 static int pcifound = 0;
64 /* IO window located @ e8000000 and maps to 0-0xffff */
65 static struct powerpc_bus_space pchb_io_tag = {
66 _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_IO_TYPE,
67 MIN_PLB_PCI_IOADDR, /* offset */
68 MIN_PCI_PCI_IOADDR, /* extent base */
69 MIN_PCI_PCI_IOADDR + 0xffff, /* extent limit */
72 /* PCI memory window is directly mapped */
73 static struct powerpc_bus_space pchb_mem_tag = {
74 _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE,
75 0x00000000, /* offset */
76 MIN_PCI_MEMADDR_NOPREFETCH, /* extent base */
77 MIN_PCI_MEMADDR_NOPREFETCH + 0x1fffffff, /* extent limit */
81 static int
82 pchbmatch(struct device *parent, struct cfdata *cf, void *aux)
84 struct plb_attach_args *paa = aux;
85 /* XXX chipset tag unused by walnut, so just pass 0 */
86 pci_chipset_tag_t pc = 0;
87 pcitag_t tag;
88 int class, id;
90 /* match only pchb devices */
91 if (strcmp(paa->plb_name, cf->cf_name) != 0)
92 return 0;
94 pci_machdep_init();
95 tag = pci_make_tag(pc, 0, 0, 0);
97 class = pci_conf_read(pc, tag, PCI_CLASS_REG);
98 id = pci_conf_read(pc, tag, PCI_ID_REG);
101 * Match all known PCI host chipsets.
103 if (PCI_CLASS(class) == PCI_CLASS_BRIDGE &&
104 PCI_SUBCLASS(class) == PCI_SUBCLASS_BRIDGE_HOST) {
105 switch (PCI_VENDOR(id)) {
106 case PCI_VENDOR_IBM:
107 switch (PCI_PRODUCT(id)) {
108 case PCI_PRODUCT_IBM_405GP:
109 return (!pcifound);
111 break;
114 return (0);
117 static void
118 pchbattach(struct device *parent, struct device *self, void *aux)
120 struct plb_attach_args *paa = aux;
121 struct pcibus_attach_args pba;
122 char devinfo[256];
123 #ifdef PCI_NETBSD_CONFIGURE
124 struct extent *ioext, *memext;
125 #ifdef PCI_CONFIGURE_VERBOSE
126 extern int pci_conf_debug;
128 pci_conf_debug = 1;
129 #endif
130 #endif
131 pci_chipset_tag_t pc = 0;
132 pcitag_t tag;
133 int class, id;
135 pci_machdep_init();
136 tag = pci_make_tag(pc, 0, 0, 0);
138 class = pci_conf_read(pc, tag, PCI_CLASS_REG);
139 id = pci_conf_read(pc, tag, PCI_ID_REG);
141 printf("\n");
142 pcifound++;
144 * All we do is print out a description. Eventually, we
145 * might want to add code that does something that's
146 * possibly chipset-specific.
149 pci_devinfo(id, class, 0, devinfo, sizeof(devinfo));
150 printf("%s: %s (rev. 0x%02x)\n", self->dv_xname, devinfo,
151 PCI_REVISION(class));
153 pci_machdep_init(); /* Redundant... */
154 ibm4xx_setup_pci();
155 #ifdef PCI_CONFIGURE_VERBOSE
156 ibm4xx_show_pci_map();
157 #endif
159 if (bus_space_init(&pchb_io_tag, "pchbio", NULL, 0))
160 panic("pchbattach: can't init IO tag");
161 if (bus_space_init(&pchb_mem_tag, "pchbmem", NULL, 0))
162 panic("pchbattach: can't init MEM tag");
164 #ifdef PCI_NETBSD_CONFIGURE
165 memext = extent_create("pcimem", MIN_PCI_MEMADDR_NOPREFETCH,
166 MIN_PCI_MEMADDR_NOPREFETCH + 0x1fffffff, M_DEVBUF, NULL, 0,
167 EX_NOWAIT);
168 ioext = extent_create("pciio", MIN_PCI_PCI_IOADDR,
169 MIN_PCI_PCI_IOADDR + 0xffff, M_DEVBUF, NULL, 0, EX_NOWAIT);
170 pci_configure_bus(0, ioext, memext, NULL, 0, 32);
171 extent_destroy(memext);
172 extent_destroy(ioext);
173 #endif /* PCI_NETBSD_CONFIGURE */
175 #ifdef PCI_CONFIGURE_VERBOSE
176 printf("running config_found PCI\n");
177 #endif
178 /* IO window located @ e8000000 and maps to 0-0xffff */
179 pba.pba_iot = &pchb_io_tag;
180 /* PCI memory window is directly mapped */
181 pba.pba_memt = &pchb_mem_tag;
182 pba.pba_dmat = paa->plb_dmat;
183 pba.pba_dmat64 = NULL;
184 pba.pba_bus = 0;
185 pba.pba_bridgetag = NULL;
186 pba.pba_flags = PCI_FLAGS_MEM_ENABLED | PCI_FLAGS_IO_ENABLED;
187 config_found_ia(self, "pcibus", &pba, pchbprint);
191 static int
192 pchbprint(void *aux, const char *p)
195 if (p == NULL)
196 return (UNCONF);
197 return (QUIET);
200 #if 0
201 static void
202 scan_pci_bus(void)
204 pcitag_t tag;
205 int i, x;
207 for (i=0;i<32;i++){
208 tag = pci_make_tag(0, 0, i, 0);
209 x = pci_conf_read(0, tag, 0);
210 printf("%d tag=%08x : %08x\n", i, tag, x);
211 #if 0
212 if (PCI_VENDOR(x) == PCI_VENDOR_INTEL
213 && PCI_PRODUCT(x) == PCI_PRODUCT_INTEL_80960_RP) {
214 /* Do not configure PCI bus analyzer */
215 continue;
217 x = pci_conf_read(0, tag, PCI_COMMAND_STATUS_REG);
218 x |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE;
219 pci_conf_write(0, tag, PCI_COMMAND_STATUS_REG, x);
220 #endif
223 #endif