xref: /netbsd-src/sys/arch/mips/alchemy/aubus.c (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 /* $NetBSD: aubus.c,v 1.24 2021/04/24 23:36:42 thorpej Exp $ */
2 
3 /*-
4  * Copyright (c) 2006 Itronix Inc.
5  * All rights reserved.
6  *
7  * Portions written by Garrett D'Amore for Itronix Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. The name of Itronix Inc. may not be used to endorse
18  *    or promote products derived from this software without specific
19  *    prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Copyright 2001 Wasabi Systems, Inc.
36  * All rights reserved.
37  *
38  * Written by Simon Burge for Wasabi Systems, Inc.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  * 1. Redistributions of source code must retain the above copyright
44  *    notice, this list of conditions and the following disclaimer.
45  * 2. Redistributions in binary form must reproduce the above copyright
46  *    notice, this list of conditions and the following disclaimer in the
47  *    documentation and/or other materials provided with the distribution.
48  * 3. All advertising materials mentioning features or use of this software
49  *    must display the following acknowledgement:
50  *      This product includes software developed for the NetBSD Project by
51  *      Wasabi Systems, Inc.
52  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
53  *    or promote products derived from this software without specific prior
54  *    written permission.
55  *
56  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
57  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
58  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
60  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
66  * POSSIBILITY OF SUCH DAMAGE.
67  */
68 
69 /*
70  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
71  *
72  * Redistribution and use in source and binary forms, with or without
73  * modification, are permitted provided that the following conditions
74  * are met:
75  * 1. Redistributions of source code must retain the above copyright
76  *    notice, this list of conditions and the following disclaimer.
77  * 2. Redistributions in binary form must reproduce the above copyright
78  *    notice, this list of conditions and the following disclaimer in the
79  *    documentation and/or other materials provided with the distribution.
80  * 3. All advertising materials mentioning features or use of this software
81  *    must display the following acknowledgement:
82  *      This product includes software developed by Christopher G. Demetriou
83  *	for the NetBSD Project.
84  * 4. The name of the author may not be used to endorse or promote products
85  *    derived from this software without specific prior written permission
86  *
87  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
88  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
90  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
91  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
92  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
93  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
94  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
95  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
96  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97  */
98 
99 #include <sys/cdefs.h>
100 __KERNEL_RCSID(0, "$NetBSD: aubus.c,v 1.24 2021/04/24 23:36:42 thorpej Exp $");
101 
102 #include "locators.h"
103 #define _MIPS_BUS_DMA_PRIVATE
104 
105 #include <sys/param.h>
106 #include <sys/bus.h>
107 #include <sys/device.h>
108 #include <sys/extent.h>
109 #include <sys/malloc.h>
110 #include <sys/systm.h>
111 
112 #include <mips/locore.h>
113 #include <mips/alchemy/include/aureg.h>
114 #include <mips/alchemy/include/auvar.h>
115 #include <mips/alchemy/include/aubusvar.h>
116 
117 static int	aubus_match(device_t, cfdata_t, void *);
118 static void	aubus_attach(device_t, device_t, void *);
119 static int	aubus_print(void *, const char *);
120 
121 CFATTACH_DECL_NEW(aubus, 0,
122     aubus_match, aubus_attach, NULL, NULL);
123 
124 bus_space_tag_t	aubus_st;		/* XXX */
125 struct mips_bus_dma_tag aubus_mdt = {
126 	._dmamap_ops = _BUS_DMAMAP_OPS_INITIALIZER,
127 	._dmamem_ops = _BUS_DMAMEM_OPS_INITIALIZER,
128 	._dmatag_ops = _BUS_DMATAG_OPS_INITIALIZER,
129 };
130 
131 /*
132  * Probe for the aubus; always succeeds.
133  */
134 static int
135 aubus_match(device_t parent, cfdata_t match, void *aux)
136 {
137 
138 	return 1;
139 }
140 
141 /*
142  * Attach the aubus.
143  */
144 static void
145 aubus_attach(device_t parent, device_t self, void *aux)
146 {
147 	struct aubus_attach_args aa;
148 	device_t sc = self;
149 	struct au_chipdep *chip;
150 	const struct au_dev *ad;
151 	int locs[AUBUSCF_NLOCS];
152 
153 	printf("\n");
154 
155 	chip = au_chipdep();
156 	KASSERT(chip != NULL);
157 
158 	aubus_mdt._cookie = sc;
159 
160 	for (ad = chip->devices; ad->name != NULL; ad++) {
161 		aa.aa_name = ad->name;
162 		aa.aa_st = aubus_st;
163 		aa.aa_dt = &aubus_mdt;
164 		aa.aa_addrs[0] = ad->addr[0];
165 		aa.aa_addrs[1] = ad->addr[1];
166 		aa.aa_addrs[2] = ad->addr[2];
167 		aa.aa_irq[0] = ad->irq[0];
168 		aa.aa_irq[1] = ad->irq[1];
169 
170 		locs[AUBUSCF_ADDR] = ad->addr[0];
171 
172 		config_found(self, &aa, aubus_print,
173 		    CFARG_SUBMATCH, config_stdsubmatch,
174 		    CFARG_LOCATORS, locs,
175 		    CFARG_EOL);
176 	}
177 }
178 
179 static int
180 aubus_print(void *aux, const char *pnp)
181 {
182 	struct aubus_attach_args *aa = aux;
183 
184 	if (pnp)
185 		aprint_normal("%s at %s", aa->aa_name, pnp);
186 
187 	if (aa->aa_addr != AUBUSCF_ADDR_DEFAULT)
188 		aprint_normal(" addr 0x%"PRIxBUSADDR, aa->aa_addr);
189 	if (aa->aa_irq[0] >= 0)
190 		aprint_normal(" irq %d", aa->aa_irq[0]);
191 	if (aa->aa_irq[1] >= 0)
192 		aprint_normal(",%d", aa->aa_irq[1]);
193 	return (UNCONF);
194 }
195 
196 #if 0
197 void
198 aubus_alloc_dma_tag(device_t sc, bus_dma_tag_t pdt)
199 {
200 	bus_dma_tag_t	t;
201 
202 	t = pdt;
203 	t->_cookie = sc;
204 	t->_wbase = 0;	/* XXX */
205 	t->_physbase = 0;	/* XXX */
206 	t->_wsize = MIPS_KSEG1_START - MIPS_KSEG0_START;
207 	t->_dmamap_create = _bus_dmamap_create;
208 	t->_dmamap_destroy = _bus_dmamap_destroy;
209 	t->_dmamap_load = _bus_dmamap_load;
210 	t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf;
211 	t->_dmamap_load_uio = _bus_dmamap_load_uio;
212 	t->_dmamap_load_raw = _bus_dmamap_load_raw;
213 	t->_dmamap_unload = _bus_dmamap_unload;
214 	t->_dmamap_sync = _bus_dmamap_sync;
215 	t->_dmamem_alloc = _bus_dmamem_alloc;
216 	t->_dmamem_free = _bus_dmamem_free;
217 	t->_dmamem_map = _bus_dmamem_map;
218 	t->_dmamem_unmap = _bus_dmamem_unmap;
219 	t->_dmamem_mmap = _bus_dmamem_mmap;
220 }
221 #endif
222