xref: /netbsd/sys/arch/mvmeppc/mvmeppc/mainbus.c (revision c4a72b64)
1 /*	$NetBSD: mainbus.c,v 1.4 2002/10/02 04:49:11 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/systm.h>
36 #include <sys/device.h>
37 #include <sys/malloc.h>
38 
39 #include <machine/autoconf.h>
40 #include <machine/bus.h>
41 
42 #include "pci.h"
43 #include "opt_pci.h"
44 #include <dev/pci/pcivar.h>
45 #include <dev/pci/pciconf.h>
46 
47 int	mainbus_match(struct device *, struct cfdata *, void *);
48 void	mainbus_attach(struct device *, struct device *, void *);
49 
50 CFATTACH_DECL(mainbus, sizeof(struct device),
51     mainbus_match, mainbus_attach, NULL, NULL);
52 
53 int	mainbus_print(void *, const char *);
54 
55 union mainbus_attach_args {
56 	const char *mba_busname;		/* first elem of all */
57 	struct pcibus_attach_args mba_pba;
58 };
59 
60 /* There can be only one */
61 static int mainbus_found;
62 
63 /*
64  * Probe for the mainbus; always succeeds.
65  */
66 int
67 mainbus_match(parent, match, aux)
68 	struct device *parent;
69 	struct cfdata *match;
70 	void *aux;
71 {
72 
73 	if (mainbus_found)
74 		return 0;
75 	return 1;
76 }
77 
78 /*
79  * Attach the mainbus.
80  */
81 void
82 mainbus_attach(parent, self, aux)
83 	struct device *parent;
84 	struct device *self;
85 	void *aux;
86 {
87 	union mainbus_attach_args mba;
88 	struct confargs ca;
89 #ifdef PCI_NETBSD_CONFIGURE
90 	struct extent *ioext, *memext;
91 #endif
92 
93 	mainbus_found = 1;
94 
95 	printf("\n");
96 
97 	ca.ca_name = "cpu";
98 	ca.ca_node = 0;
99 	config_found(self, &ca, mainbus_print);
100 
101 	/*
102 	 * XXX Note also that the presence of a PCI bus should
103 	 * XXX _always_ be checked, and if present the bus should be
104 	 * XXX 'found'.  However, because of the structure of the code,
105 	 * XXX that's not currently possible.
106 	 */
107 #if NPCI > 0
108 #ifdef PCI_NETBSD_CONFIGURE
109 	ioext  = extent_create("pciio",  0x00008000, 0x0000ffff, M_DEVBUF,
110 	    NULL, 0, EX_NOWAIT);
111 	memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF,
112 	    NULL, 0, EX_NOWAIT);
113 
114 	pci_configure_bus(0, ioext, memext, NULL, 0, 32);
115 
116 	extent_destroy(ioext);
117 	extent_destroy(memext);
118 #endif
119 
120 	mba.mba_pba.pba_busname = "pci";
121 	mba.mba_pba.pba_iot = &mvmeppc_pci_io_bs_tag;
122 	mba.mba_pba.pba_memt = &mvmeppc_pci_mem_bs_tag;
123 	mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
124 	mba.mba_pba.pba_bus = 0;
125 	mba.mba_pba.pba_bridgetag = NULL;
126 	mba.mba_pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
127 	config_found(self, &mba.mba_pba, mainbus_print);
128 #endif
129 }
130 
131 int
132 mainbus_print(aux, pnp)
133 	void *aux;
134 	const char *pnp;
135 {
136 	union mainbus_attach_args *mba = aux;
137 
138 	if (pnp)
139 		printf("%s at %s", mba->mba_busname, pnp);
140 	if (!strcmp(mba->mba_busname, "pci"))
141 		printf(" bus %d", mba->mba_pba.pba_bus);
142 
143 	return (UNCONF);
144 }
145