xref: /netbsd/sys/arch/ibmnws/ibmnws/mainbus.c (revision 6550d01e)
1 /*	$NetBSD: mainbus.c,v 1.8 2009/03/18 16:00:13 cegger Exp $	*/
2 
3 /*
4  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Christopher G. Demetriou
17  *	for the NetBSD Project.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include "opt_pci.h"
34 
35 /* #include "obio.h" */
36 #include "pci.h"
37 #include "isa.h"
38 
39 #include <sys/param.h>
40 #include <sys/extent.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 #include <sys/malloc.h>
44 
45 #include <machine/autoconf.h>
46 #include <machine/bus.h>
47 #include <machine/isa_machdep.h>
48 
49 #include <dev/pci/pcivar.h>
50 #include <dev/pci/pciconf.h>
51 
52 int	mainbus_match(device_t, cfdata_t, void *);
53 void	mainbus_attach(device_t, device_t, void *);
54 
55 struct mainbus_softc {
56 	device_t sc_dev;		/* device tree glue */
57 };
58 
59 CFATTACH_DECL_NEW(mainbus, sizeof(struct mainbus_softc),
60     mainbus_match, mainbus_attach, NULL, NULL);
61 
62 int	mainbus_print(void *, const char *);
63 
64 union mainbus_attach_args {
65 	const char *mba_busname;		/* first elem of all */
66 	struct pcibus_attach_args mba_pba;
67 };
68 
69 /* There can be only one. */
70 int mainbus_found = 0;
71 struct powerpc_isa_chipset genppc_ict;
72 struct genppc_pci_chipset *genppc_pct;
73 
74 /*
75  * Probe for the mainbus; always succeeds.
76  */
77 int
78 mainbus_match(device_t parent, cfdata_t match, void *aux)
79 {
80 
81 	if (mainbus_found)
82 		return 0;
83 	return 1;
84 }
85 
86 /*
87  * Attach the mainbus.
88  */
89 void
90 mainbus_attach(device_t parent, device_t self, void *aux)
91 {
92 	struct mainbus_softc *sc = device_private(self);
93 	union mainbus_attach_args mba;
94 	struct confargs ca;
95 #if NPCI > 0
96 #ifdef PCI_NETBSD_CONFIGURE
97 	struct extent *ioext, *memext;
98 #endif
99 #endif
100 
101 	mainbus_found = 1;
102 
103 	aprint_normal("\n");
104 
105 	sc->sc_dev = self;
106 	ca.ca_name = "cpu";
107 	ca.ca_node = 0;
108 	config_found_ia(self, "mainbus", &ca, mainbus_print);
109 
110 #if NOBIO > 0
111 	obio_reserve_resource_map();
112 #endif
113 
114 	/*
115 	 * XXX Note also that the presence of a PCI bus should
116 	 * XXX _always_ be checked, and if present the bus should be
117 	 * XXX 'found'.  However, because of the structure of the code,
118 	 * XXX that's not currently possible.
119 	 */
120 #if NPCI > 0
121 	genppc_pct = malloc(sizeof(struct genppc_pci_chipset), M_DEVBUF,
122 	    M_NOWAIT);
123 	KASSERT(genppc_pct != NULL);
124 	ibmnws_pci_get_chipset_tag_indirect (genppc_pct);
125 
126 #ifdef PCI_NETBSD_CONFIGURE
127 	ioext  = extent_create("pciio",  0x00008000, 0x0000ffff, M_DEVBUF,
128 	    NULL, 0, EX_NOWAIT);
129 	memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF,
130 	    NULL, 0, EX_NOWAIT);
131 
132 	pci_configure_bus(genppc_pct, ioext, memext, NULL, 0, CACHELINESIZE);
133 
134 	extent_destroy(ioext);
135 	extent_destroy(memext);
136 #endif
137 
138 	memset(&mba, 0, sizeof(mba));
139 	mba.mba_pba.pba_iot = &prep_io_space_tag;
140 	mba.mba_pba.pba_memt = &prep_mem_space_tag;
141 	mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
142 	mba.mba_pba.pba_dmat64 = NULL;
143 	mba.mba_pba.pba_pc = genppc_pct;
144 	mba.mba_pba.pba_bus = 0;
145 	mba.mba_pba.pba_bridgetag = NULL;
146 	mba.mba_pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
147 	config_found_ia(self, "pcibus", &mba.mba_pba, pcibusprint);
148 #endif
149 
150 #if NOBIO > 0
151 #if 0
152 	obio_reserve_resource_unmap();
153 
154 	if (platform->obiodevs != obiodevs_nodev) {
155 		memset(&mba, 0, sizeof(mba));
156 		mba.mba_busname = "obio"; /* XXX needs placeholder in pba */
157 		mba.mba_pba.pba_iot = &isa_io_space_tag;
158 		mba.mba_pba.pba_memt = &isa_mem_space_tag;
159 		config_found_ia(self, "mainbus", &mba.mba_pba, mainbus_print);
160 	}
161 #endif
162 #endif
163 }
164 
165 int
166 mainbus_print(void *aux, const char *pnp)
167 {
168 	union mainbus_attach_args *mba = aux;
169 
170 	if (pnp)
171 		aprint_normal("%s at %s", mba->mba_busname, pnp);
172 
173 	return (UNCONF);
174 }
175