xref: /netbsd/sys/arch/sandpoint/sandpoint/mainbus.c (revision c4a72b64)
1 /*	$NetBSD: mainbus.c,v 1.11 2002/10/02 15:52:31 thorpej 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/param.h>
34 #include <sys/extent.h>
35 #include <sys/device.h>
36 #include <sys/malloc.h>
37 #include <sys/systm.h>
38 
39 #include <machine/bus.h>
40 
41 #include "mainbus.h"
42 #include "pci.h"
43 #include "opt_pci.h"
44 #include <dev/pci/pcivar.h>
45 #include <dev/pci/pciconf.h>
46 
47 #if NCPU == 0
48 #error	A cpu device is now required
49 #endif
50 
51 int	mainbus_match __P((struct device *, void *, void *));
52 void	mainbus_attach __P((struct device *, struct device *, void *));
53 
54 CFATTACH_DECL(mainbus, sizeof(struct device),
55     (cfmatch_t)mainbus_match, mainbus_attach, NULL, NULL);
56 
57 int	mainbus_print __P((void *, const char *));
58 
59 union mainbus_attach_args {
60 	const char *mba_busname;		/* first elem of all */
61 	struct pcibus_attach_args mba_pba;
62 };
63 
64 /*
65  * Probe for the mainbus; always succeeds.
66  */
67 int
68 mainbus_match(parent, match, aux)
69 	struct device *parent;
70 	void *match, *aux;
71 {
72 
73 	return 1;
74 }
75 
76 /*
77  * Attach the mainbus.
78  */
79 void
80 mainbus_attach(parent, self, aux)
81 	struct device *parent, *self;
82 	void *aux;
83 {
84 	union mainbus_attach_args mba;
85 #if defined(PCI_NETBSD_CONFIGURE)
86 	struct extent *ioext, *memext;
87 #endif
88 
89 	printf("\n");
90 
91 	/*
92 	 * Always find the CPU
93 	 */
94 	mba.mba_busname = "cpu";
95 	config_found(self, &mba, mainbus_print);
96 
97 	/*
98 	 * XXX Note also that the presence of a PCI bus should
99 	 * XXX _always_ be checked, and if present the bus should be
100 	 * XXX 'found'.  However, because of the structure of the code,
101 	 * XXX that's not currently possible.
102 	 */
103 #if NPCI > 0
104 #if !defined(PCI_NETBSD_CONFIGURE)
105 /* #error Sandpoint needs PCI_NETBSD_CONFIGURE if PCI busses are defined. */
106 #else
107 	ioext  = extent_create("pciio",  0x00000600, 0x0000ffff, M_DEVBUF,
108 	    NULL, 0, EX_NOWAIT);
109 	memext = extent_create("pcimem", 0x80000000, 0x8fffffff, M_DEVBUF,
110 	    NULL, 0, EX_NOWAIT);
111 
112 	pci_configure_bus(0, ioext, memext, NULL, 0, 32);
113 
114 	extent_destroy(ioext);
115 	extent_destroy(memext);
116 #endif
117 
118 	mba.mba_pba.pba_busname = "pci";
119 	mba.mba_pba.pba_iot = &sandpoint_io_bs_tag;
120 	mba.mba_pba.pba_memt = &sandpoint_mem_bs_tag;
121 	mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
122 	mba.mba_pba.pba_bus = 0;
123 	mba.mba_pba.pba_pc = 0;
124 	mba.mba_pba.pba_bridgetag = NULL;
125 	mba.mba_pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
126 
127 	config_found(self, &mba.mba_pba, mainbus_print);
128 #endif
129 }
130 
131 static int	cpu_match(struct device *, struct cfdata *, void *);
132 static void	cpu_attach(struct device *, struct device *, void *);
133 
134 CFATTACH_DECL(cpu, sizeof(struct device),
135     cpu_match, cpu_attach, NULL, NULL);
136 
137 extern struct cfdriver cpu_cd;
138 
139 int
140 cpu_match(struct device *parent, struct cfdata *cf, void *aux)
141 {
142 	union mainbus_attach_args *mba = aux;
143 
144 	if (strcmp(mba->mba_busname, cpu_cd.cd_name) != 0)
145 		return 0;
146 
147 	if (cpu_info_store.ci_dev != NULL)
148 		return 0;
149 
150 	return 1;
151 }
152 
153 void
154 cpu_attach(struct device *parent, struct device *self, void *aux)
155 {
156 	(void) cpu_attach_common(self, 0);
157 }
158 
159 int
160 mainbus_print(aux, pnp)
161 	void *aux;
162 	const char *pnp;
163 {
164 	union mainbus_attach_args *mba = aux;
165 
166 	if (pnp)
167 		printf("%s at %s", mba->mba_busname, pnp);
168 	if (!strcmp(mba->mba_busname, "pci"))
169 		printf(" bus %d", mba->mba_pba.pba_bus);
170 	return (UNCONF);
171 }
172