xref: /netbsd/sys/arch/bebox/bebox/mainbus.c (revision 6550d01e)
1 /*	$NetBSD: mainbus.c,v 1.24 2009/03/18 16:00:10 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 <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.24 2009/03/18 16:00:10 cegger Exp $");
35 
36 #include <sys/param.h>
37 #include <sys/extent.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 #include <sys/malloc.h>
41 
42 #include <machine/autoconf.h>
43 #include <machine/bus.h>
44 
45 #include "pci.h"
46 #include "opt_pci.h"
47 #include <dev/pci/pcivar.h>
48 #include <dev/pci/pciconf.h>
49 #include <machine/pci_machdep.h>
50 #include <machine/isa_machdep.h>
51 
52 int	mainbus_match(struct device *, struct cfdata *, void *);
53 void	mainbus_attach(struct device *, struct device *, void *);
54 
55 CFATTACH_DECL(mainbus, sizeof(struct device),
56     mainbus_match, mainbus_attach, NULL, NULL);
57 
58 int	mainbus_print (void *, const char *);
59 
60 union mainbus_attach_args {
61 	const char *mba_busname;		/* first elem of all */
62 	struct pcibus_attach_args mba_pba;
63 };
64 
65 
66 /* There can be only one */
67 int mainbus_found = 0;
68 struct powerpc_isa_chipset genppc_ict;
69 struct genppc_pci_chipset *genppc_pct;
70 
71 /*
72  * Probe for the mainbus; always succeeds.
73  */
74 int
75 mainbus_match(struct device *parent, struct cfdata *match, void *aux)
76 {
77 	return 1;
78 }
79 
80 /*
81  * Attach the mainbus.
82  */
83 void
84 mainbus_attach(struct device *parent, struct device *self, void *aux)
85 {
86 	union mainbus_attach_args mba;
87 	struct confargs ca;
88 
89 #if NPCI > 0
90 	struct genppc_pci_chipset_businfo *pbi;
91 #ifdef PCI_NETBSD_CONFIGURE
92 	struct extent *ioext, *memext;
93 #endif
94 #endif
95 
96 	mainbus_found = 1;
97 
98 	aprint_normal("\n");
99 
100 
101 #if defined(RESIDUAL_DATA_DUMP)
102 	print_residual_device_info();
103 #endif
104 
105 	/*
106 	 * Always find the CPU
107 	 */
108 	ca.ca_name = "cpu";
109 	ca.ca_node = 0;
110 	config_found_ia(self, "mainbus", &ca, mainbus_print);
111 
112 	/*
113 	 * XXX Note also that the presence of a PCI bus should
114 	 * XXX _always_ be checked, and if present the bus should be
115 	 * XXX 'found'.  However, because of the structure of the code,
116 	 * XXX that's not currently possible.
117 	 */
118 
119 #if NPCI > 0
120 	genppc_pct = malloc(sizeof(struct genppc_pci_chipset), M_DEVBUF,
121 	    M_NOWAIT);
122 	KASSERT(genppc_pct != NULL);
123 	bebox_pci_get_chipset_tag(genppc_pct);
124 
125 	pbi = malloc(sizeof(struct genppc_pci_chipset_businfo),
126 	    M_DEVBUF, M_NOWAIT);
127 	KASSERT(pbi != NULL);
128 	pbi->pbi_properties = prop_dictionary_create();
129         KASSERT(pbi->pbi_properties != NULL);
130 
131 	SIMPLEQ_INIT(&genppc_pct->pc_pbi);
132 	SIMPLEQ_INSERT_TAIL(&genppc_pct->pc_pbi, pbi, next);
133 
134 #ifdef PCI_NETBSD_CONFIGURE
135 	ioext  = extent_create("pciio",  0x00008000, 0x0000ffff, M_DEVBUF,
136 	    NULL, 0, EX_NOWAIT);
137 	memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF,
138 	    NULL, 0, EX_NOWAIT);
139 
140 	pci_configure_bus(genppc_pct, ioext, memext, NULL, 0, CACHELINESIZE);
141 
142 	extent_destroy(ioext);
143 	extent_destroy(memext);
144 #endif /* PCI_NETBSD_CONFIGURE */
145 #endif /* NPCI */
146 
147 #if NPCI > 0
148 	memset(&mba, 0, sizeof(mba));
149 	mba.mba_pba.pba_iot = &prep_io_space_tag;
150 	mba.mba_pba.pba_memt = &prep_mem_space_tag;
151 	mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
152 	mba.mba_pba.pba_dmat64 = NULL;
153 	mba.mba_pba.pba_pc = genppc_pct;
154 	mba.mba_pba.pba_bus = 0;
155 	mba.mba_pba.pba_bridgetag = NULL;
156 	mba.mba_pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
157 	config_found_ia(self, "pcibus", &mba.mba_pba, pcibusprint);
158 #endif /* NPCI */
159 
160 #ifdef RESIDUAL_DATA_DUMP
161 	SIMPLEQ_FOREACH(pbi, &genppc_pct->pc_pbi, next)
162 	    printf("%s\n", prop_dictionary_externalize(pbi->pbi_properties));
163 #endif
164 
165 }
166 
167 int
168 mainbus_print(void *aux, const char *pnp)
169 {
170 
171 	if (pnp)
172 		aprint_normal("cpu at %s", pnp);
173 	return (UNCONF);
174 }
175