xref: /netbsd/sys/arch/bebox/bebox/mainbus.c (revision bf9ec67e)
1 /*	$NetBSD: mainbus.c,v 1.11 2002/05/16 01:01:34 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/device.h>
35 #include <sys/extent.h>
36 #include <sys/malloc.h>
37 #include <sys/systm.h>
38 
39 #include <machine/bus.h>
40 
41 #include "opt_pci.h"
42 #include "mainbus.h"
43 #include "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 static int	mainbus_match (struct device *, struct cfdata *, void *);
52 static void	mainbus_attach (struct device *, struct device *, void *);
53 
54 struct cfattach mainbus_ca = {
55 	sizeof(struct device), mainbus_match, mainbus_attach
56 };
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  * Probe for the mainbus; always succeeds.
67  */
68 int
69 mainbus_match(struct device *parent, struct cfdata *match, void *aux)
70 {
71 	return 1;
72 }
73 
74 /*
75  * Attach the mainbus.
76  */
77 void
78 mainbus_attach(struct device *parent, struct device *self, void *aux)
79 {
80 	union mainbus_attach_args mba;
81 #if defined(PCI_NETBSD_CONFIGURE)
82 	struct extent *ioext, *memext;
83 #endif
84 
85 	printf("\n");
86 
87 	/*
88 	 * Always find the CPU
89 	 */
90 	mba.mba_busname = "cpu";
91 	config_found(self, &mba, mainbus_print);
92 
93 	/*
94 	 * XXX Note also that the presence of a PCI bus should
95 	 * XXX _always_ be checked, and if present the bus should be
96 	 * XXX 'found'.  However, because of the structure of the code,
97 	 * XXX that's not currently possible.
98 	 */
99 #if NPCI > 0
100 #if defined(PCI_NETBSD_CONFIGURE)
101 	ioext  = extent_create("pciio",  0x00008000, 0x0000ffff, M_DEVBUF,
102 	    NULL, 0, EX_NOWAIT);
103 	memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF,
104 	    NULL, 0, EX_NOWAIT);
105 	pci_configure_bus(0, ioext, memext, NULL, 0, 32);
106 	extent_destroy(ioext);
107 	extent_destroy(memext);
108 #endif
109 	mba.mba_pba.pba_busname = "pci";
110 	mba.mba_pba.pba_iot = &bebox_io_bs_tag;
111 	mba.mba_pba.pba_memt = &bebox_mem_bs_tag;
112 	mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
113 	mba.mba_pba.pba_bus = 0;
114 	mba.mba_pba.pba_bridgetag = NULL;
115 	mba.mba_pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
116 	config_found(self, &mba.mba_pba, mainbus_print);
117 #endif
118 }
119 
120 static int	cpu_match(struct device *, struct cfdata *, void *);
121 static void	cpu_attach(struct device *, struct device *, void *);
122 
123 struct cfattach cpu_ca = {
124 	sizeof(struct device), cpu_match, cpu_attach
125 };
126 
127 extern struct cfdriver cpu_cd;
128 
129 int
130 cpu_match(struct device *parent, struct cfdata *cf, void *aux)
131 {
132 	union mainbus_attach_args *mba = aux;
133 
134 	if (strcmp(mba->mba_busname, cpu_cd.cd_name) != 0)
135 		return 0;
136 
137 	if (cpu_info_store.ci_dev != NULL)
138 		return 0;
139 
140 	return 1;
141 }
142 
143 void
144 cpu_attach(struct device *parent, struct device *self, void *aux)
145 {
146 	(void) cpu_attach_common(self, 0);
147 }
148 
149 int
150 mainbus_print(void *aux, const char *pnp)
151 {
152 	union mainbus_attach_args *mba = aux;
153 
154 	if (pnp)
155 		printf("%s at %s", mba->mba_busname, pnp);
156 	if (!strcmp(mba->mba_busname, "pci"))
157 		printf(" bus %d", mba->mba_pba.pba_bus);
158 	return (UNCONF);
159 }
160