No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / powerpc / ibm4xx / pci / pchb.c
blob13c5b85e45477331632c9f76fd63434565976a46
1 /* $NetBSD: pchb.c,v 1.5 2005/12/11 12:18:43 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.5 2005/12/11 12:18:43 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
46 #include <powerpc/ibm4xx/ibm405gp.h>
47 #include <powerpc/ibm4xx/dev/plbvar.h>
49 #include <dev/pci/pcivar.h>
50 #include <dev/pci/pcireg.h>
51 #include <dev/pci/pcidevs.h>
52 #include <dev/pci/pciconf.h>
54 static int pchbmatch(struct device *, struct cfdata *, void *);
55 static void pchbattach(struct device *, struct device *, void *);
56 static int pchbprint(void *, const char *);
57 static pci_chipset_tag_t alloc_chipset_tag(int);
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 IBM405GP_PLB_PCI_IO_START, /* offset */
68 IBM405GP_PCI_PCI_IO_START, /* extent base */
69 IBM405GP_PCI_PCI_IO_START + 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 IBM405GP_PCI_MEM_START, /* extent base */
77 IBM405GP_PCI_MEM_START + 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 = alloc_chipset_tag(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_CONFIGURE_VERBOSE
124 extern int pci_conf_debug;
126 pci_conf_debug = 1;
127 #endif
128 pci_chipset_tag_t pc = alloc_chipset_tag(0);
129 pcitag_t tag;
130 int class, id;
132 pci_machdep_init();
133 tag = pci_make_tag(pc, 0, 0, 0);
135 class = pci_conf_read(pc, tag, PCI_CLASS_REG);
136 id = pci_conf_read(pc, tag, PCI_ID_REG);
138 printf("\n");
139 pcifound++;
141 * All we do is print out a description. Eventually, we
142 * might want to add code that does something that's
143 * possibly chipset-specific.
146 pci_devinfo(id, class, 0, devinfo, sizeof(devinfo));
147 printf("%s: %s (rev. 0x%02x)\n", self->dv_xname, devinfo,
148 PCI_REVISION(class));
150 pci_machdep_init(); /* Redundant... */
151 ibm4xx_setup_pci();
152 #ifdef PCI_CONFIGURE_VERBOSE
153 ibm4xx_show_pci_map();
154 #endif
156 if (bus_space_init(&pchb_io_tag, "pchbio", NULL, 0))
157 panic("pchbattach: can't init IO tag");
158 if (bus_space_init(&pchb_mem_tag, "pchbmem", NULL, 0))
159 panic("pchbattach: can't init MEM tag");
161 #ifdef PCI_NETBSD_CONFIGURE
162 pc->memext = extent_create("pcimem", IBM405GP_PCI_MEM_START,
163 IBM405GP_PCI_MEM_START + 0x1fffffff, M_DEVBUF, NULL, 0,
164 EX_NOWAIT);
165 pc->ioext = extent_create("pciio", IBM405GP_PCI_PCI_IO_START,
166 IBM405GP_PCI_PCI_IO_START + 0xffff, M_DEVBUF, NULL, 0, EX_NOWAIT);
167 pci_configure_bus(pc, pc->ioext, pc->memext, NULL, 0, 32);
168 #endif /* PCI_NETBSD_CONFIGURE */
170 #ifdef PCI_CONFIGURE_VERBOSE
171 printf("running config_found PCI\n");
172 #endif
173 /* IO window located @ e8000000 and maps to 0-0xffff */
174 pba.pba_iot = &pchb_io_tag;
175 /* PCI memory window is directly mapped */
176 pba.pba_memt = &pchb_mem_tag;
177 pba.pba_dmat = paa->plb_dmat;
178 pba.pba_dmat64 = NULL;
179 pba.pba_pc = pc;
180 pba.pba_bus = 0;
181 pba.pba_bridgetag = NULL;
182 pba.pba_flags = PCI_FLAGS_MEM_ENABLED | PCI_FLAGS_IO_ENABLED;
183 config_found_ia(self, "pcibus", &pba, pchbprint);
187 static int
188 pchbprint(void *aux, const char *p)
191 if (p == NULL)
192 return (UNCONF);
193 return (QUIET);
196 #if 0
197 static void
198 scan_pci_bus(void)
200 pcitag_t tag;
201 int i, x;
203 for (i=0;i<32;i++){
204 tag = pci_make_tag(0, 0, i, 0);
205 x = pci_conf_read(0, tag, 0);
206 printf("%d tag=%08x : %08x\n", i, tag, x);
207 #if 0
208 if (PCI_VENDOR(x) == PCI_VENDOR_INTEL
209 && PCI_PRODUCT(x) == PCI_PRODUCT_INTEL_80960_RP) {
210 /* Do not configure PCI bus analyzer */
211 continue;
213 x = pci_conf_read(0, tag, PCI_COMMAND_STATUS_REG);
214 x |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE;
215 pci_conf_write(0, tag, PCI_COMMAND_STATUS_REG, x);
216 #endif
219 #endif
221 static pci_chipset_tag_t
222 alloc_chipset_tag(int node)
224 pci_chipset_tag_t npc;
226 npc = malloc(sizeof *npc, M_DEVBUF, M_NOWAIT);
227 if (npc == NULL)
228 panic("could not allocate pci_chipset_tag_t");
229 npc->rootnode = node;
231 return (npc);