xref: /netbsd/sys/arch/x68k/dev/neptune.c (revision beecddb6)
1 /*	$NetBSD: neptune.c,v 1.23 2021/08/07 16:19:07 thorpej Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Minoura Makoto.
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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Neptune-X -- X68k-ISA Bus Bridge
34  */
35 
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: neptune.c,v 1.23 2021/08/07 16:19:07 thorpej Exp $");
38 
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
43 
44 #include <machine/bus.h>
45 #include <machine/cpu.h>
46 #include <machine/frame.h>
47 
48 #include <arch/x68k/dev/intiovar.h>
49 #include <arch/x68k/dev/neptunevar.h>
50 
51 /* bus_space stuff */
52 static int neptune_bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
53 	int, bus_space_handle_t *);
54 static void neptune_bus_space_unmap(bus_space_tag_t, bus_space_handle_t,
55 	bus_size_t);
56 static int neptune_bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
57 	bus_size_t, bus_size_t, bus_space_handle_t *);
58 
59 static struct x68k_bus_space neptune_bus = {
60 #if 0
61 	X68K_NEPUTUNE_BUS,
62 #endif
63 	neptune_bus_space_map, neptune_bus_space_unmap,
64 	neptune_bus_space_subregion,
65 	x68k_bus_space_alloc, x68k_bus_space_free,
66 };
67 
68 
69 static int neptune_match(device_t, cfdata_t, void *);
70 static void neptune_attach(device_t, device_t, void *);
71 static int neptune_search(device_t, cfdata_t, const int *, void *);
72 static int neptune_print(void *, const char *);
73 
74 CFATTACH_DECL_NEW(neptune, sizeof(struct neptune_softc),
75     neptune_match, neptune_attach, NULL, NULL);
76 
77 static int
neptune_match(device_t parent,cfdata_t cf,void * aux)78 neptune_match(device_t parent, cfdata_t cf, void *aux)
79 {
80 	struct intio_attach_args *ia = aux;
81 
82 	if (strcmp(ia->ia_name, "neptune") != 0)
83 		return 0;
84 
85 	ia->ia_size = 0x400;
86 	if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY))
87 		return 0;
88 
89 	/* Neptune is a virtual device.  Always there. */
90 
91 	return (1);
92 }
93 
94 
95 static void
neptune_attach(device_t parent,device_t self,void * aux)96 neptune_attach(device_t parent, device_t self, void *aux)
97 {
98 	struct neptune_softc *sc = device_private(self);
99 	struct intio_attach_args *ia = aux;
100 	struct neptune_attach_args na;
101 	int r __diagused;
102 	cfdata_t cf;
103 
104 	ia->ia_size = 0x400;
105 	r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
106 #ifdef DIAGNOSTIC
107 	if (r)
108 		panic("IO map for Neptune corruption??");
109 #endif
110 
111 	sc->sc_bst = malloc(sizeof(struct x68k_bus_space), M_DEVBUF, M_WAITOK);
112 	*sc->sc_bst = neptune_bus;
113 	sc->sc_bst->x68k_bus_device = self;
114 
115 	sc->sc_addr = (vaddr_t)IIOV(ia->ia_addr);
116 
117 	na.na_bst = sc->sc_bst;
118 	na.na_intr = ia->ia_intr;
119 
120 	cf = config_search(self, &na,
121 	    CFARGS(.submatch = neptune_search));
122 	if (cf) {
123 		aprint_normal(": Neptune-X ISA bridge\n");
124 		config_attach(self, cf, &na, neptune_print, CFARGS_NONE);
125 	} else {
126 		aprint_normal(": no device found.\n");
127 		intio_map_free_region(parent, ia);
128 	}
129 }
130 
131 static int
neptune_search(device_t parent,cfdata_t cf,const int * ldesc,void * aux)132 neptune_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
133 {
134 	struct neptune_attach_args *na = aux;
135 
136 	na->na_addr = cf->neptune_cf_addr;
137 
138 	return config_match(parent, cf, na);
139 }
140 
141 static int
neptune_print(void * aux,const char * name)142 neptune_print(void *aux, const char *name)
143 {
144 	struct neptune_attach_args *na = aux;
145 
146 /*	if (na->na_addr > 0)	*/
147 		aprint_normal(" addr 0x%06x", na->na_addr);
148 
149 	return (QUIET);
150 }
151 
152 
153 /*
154  * neptune bus space stuff.
155  */
156 static int
neptune_bus_space_map(bus_space_tag_t t,bus_addr_t bpa,bus_size_t size,int flags,bus_space_handle_t * bshp)157 neptune_bus_space_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size,
158     int flags, bus_space_handle_t *bshp)
159 {
160 	struct neptune_softc *sc = device_private(t->x68k_bus_device);
161 	vaddr_t start = sc->sc_addr;
162 
163 	/*
164 	 * Neptune bus is mapped permanently.
165 	 */
166 	*bshp = (bus_space_handle_t) ((u_int)start + ((u_int)bpa - 0x200) * 2);
167 
168 	if (badaddr((void *)*bshp)) {
169 		return 1;
170 	}
171 
172 	*bshp |= 0x80000000;	/* higher byte (= even address) only */
173 
174 	return (0);
175 }
176 
177 static void
neptune_bus_space_unmap(bus_space_tag_t t,bus_space_handle_t bsh,bus_size_t size)178 neptune_bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
179     bus_size_t size)
180 {
181 	return;
182 }
183 
184 static int
neptune_bus_space_subregion(bus_space_tag_t t,bus_space_handle_t bsh,bus_size_t offset,bus_size_t size,bus_space_handle_t * nbshp)185 neptune_bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
186     bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
187 {
188 
189 	*nbshp = bsh + offset*2;
190 	return (0);
191 }
192