xref: /netbsd/sys/arch/mipsco/obio/obio.c (revision bf9ec67e)
1 /*	$NetBSD: obio.c,v 1.2 2000/08/15 04:56:46 wdk Exp $	*/
2 
3 /*-
4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Wayne Knowles
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 
43 #include <machine/autoconf.h>
44 #include <machine/mainboard.h>
45 #include <machine/bus.h>
46 #include <machine/sysconf.h>
47 
48 static int	obio_match __P((struct device *, struct cfdata *, void *));
49 static void	obio_attach __P((struct device *, struct device *, void *));
50 static int	obio_search __P((struct device *, struct cfdata *, void *));
51 static int	obio_print __P((void *, const char *));
52 static void	obio_intr_establish  __P((bus_space_tag_t, int, int, int,
53 					  int (*)(void *), void *));
54 
55 struct cfattach obio_ca = {
56 	sizeof(struct device), obio_match, obio_attach
57 };
58 
59 extern struct cfdriver obio_cd;
60 
61 struct mipsco_bus_space obio_bustag;
62 struct mipsco_bus_dma_tag obio_dmatag;
63 
64 static int
65 obio_match(parent, cf, aux)
66 	struct device *parent;
67 	struct cfdata *cf;
68 	void *aux;
69 {
70 	struct confargs *ca = aux;
71 
72 	if (strcmp(ca->ca_name, obio_cd.cd_name) != 0)
73 		return 0;
74 
75 	return 1;
76 }
77 
78 static void
79 obio_attach(parent, self, aux)
80 	struct device *parent;
81 	struct device *self;
82 	void *aux;
83 {
84 	struct confargs *ca = aux;
85 
86 	/* PIZAZZ (Mips 3000 Magnum)  Address Map */
87 	mipsco_bus_space_init(&obio_bustag, "obio",
88 			      0x18000000, 0xb8000000,
89 			      0xb8000000, 0x08000000);
90 
91 	_bus_dma_tag_init(&obio_dmatag);
92 	obio_bustag.bs_intr_establish = obio_intr_establish; /* XXX */
93 
94 	ca->ca_bustag = &obio_bustag;
95 	ca->ca_dmatag = &obio_dmatag;
96 
97 	printf("\n");
98 	config_search(obio_search, self, ca);
99 }
100 
101 static int
102 obio_search(parent, cf, aux)
103 	struct device *parent;
104 	struct cfdata *cf;
105 	void *aux;
106 {
107 	struct confargs *ca = aux;
108 
109 	ca->ca_addr = cf->cf_addr;
110 	ca->ca_name = cf->cf_driver->cd_name;
111 
112 	if ((*cf->cf_attach->ca_match)(parent, cf, ca) != 0)
113 		config_attach(parent, cf, ca, obio_print);
114 
115 	return 0;
116 }
117 
118 /*
119  * Print out the confargs.  The (parent) name is non-NULL
120  * when there was no match found by config_found().
121  */
122 static int
123 obio_print(args, name)
124 	void *args;
125 	const char *name;
126 {
127 	struct confargs *ca = args;
128 
129 	if (name)
130 		return(QUIET);
131 
132 	if (ca->ca_addr != -1)
133 		printf(" addr 0x%x", ca->ca_addr);
134 
135 	return(UNCONF);
136 }
137 
138 void
139 obio_intr_establish(bst, level, pri, flags, func, arg)
140 	bus_space_tag_t bst;
141 	int level;
142 	int pri;
143 	int flags;
144 	int (*func) __P((void *));
145 	void *arg;
146 {
147 	(*platform.intr_establish)(level, func, arg);
148 }
149