xref: /netbsd-src/sys/arch/news68k/news68k/bus_space.c (revision d6e282afbaca1ba49e1ab5f732f3bf668a8c38f2)
1 /*	$NetBSD: bus_space.c,v 1.14 2023/04/22 10:09:12 tsutsui 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 Jason R. Thorpe.
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  * Implementation of bus_space mapping for the news68k.
34  * Just taken from hp300.
35  */
36 
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: bus_space.c,v 1.14 2023/04/22 10:09:12 tsutsui Exp $");
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 
43 #include <machine/bus.h>
44 
45 #include <uvm/uvm_extern.h>
46 
47 extern int *nofault;
48 
49 int
bus_space_map(bus_space_tag_t t,bus_addr_t bpa,bus_size_t size,int flags,bus_space_handle_t * bshp)50 bus_space_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size, int flags,
51     bus_space_handle_t *bshp)
52 {
53 
54 	if (t == NEWS68K_BUS_SPACE_INTIO) {
55 		/*
56 		 * Intio space is direct-mapped in pmap_bootstrap(); just
57 		 * do the translation.
58 		 */
59 		*bshp = (bus_space_handle_t)bpa;
60 		return 0;
61 	}
62 
63 	if (t == NEWS68K_BUS_SPACE_EIO) {
64 		*bshp = (bus_space_handle_t)bpa; /* XXX use tt0 mapping */
65 		return 0;
66 	}
67 
68 	return 1;
69 }
70 
71 int
bus_space_alloc(bus_space_tag_t t,bus_addr_t rstart,bus_addr_t rend,bus_size_t size,bus_size_t alignment,bus_size_t boundary,int flags,bus_addr_t * bpap,bus_space_handle_t * bshp)72 bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart, bus_addr_t rend,
73     bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
74     bus_addr_t *bpap, bus_space_handle_t *bshp)
75 {
76 
77 	/*
78 	 * Not meaningful on any currently-supported news68k bus.
79 	 */
80 	return EINVAL;
81 }
82 
83 void
bus_space_free(bus_space_tag_t t,bus_space_handle_t bsh,bus_size_t size)84 bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size)
85 {
86 
87 	/*
88 	 * Not meaningful on any currently-supported news68k bus.
89 	 */
90 	panic("bus_space_free: shouldn't be here");
91 }
92 
93 void
bus_space_unmap(bus_space_tag_t t,bus_space_handle_t bsh,bus_size_t size)94 bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size)
95 {
96 
97 	if (t == NEWS68K_BUS_SPACE_INTIO) {
98 		/*
99 		 * Intio space is direct-mapped in pmap_bootstrap(); nothing
100 		 * to do
101 		 */
102 		return;
103 	}
104 
105 	if (t != NEWS68K_BUS_SPACE_EIO)
106 		panic("bus_space_map: bad space tag");
107 
108 	return;
109 }
110 
111 int
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)112 bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
113     bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
114 {
115 
116 	*nbshp = bsh + offset;
117 	return 0;
118 }
119 
120 int
news68k_bus_space_probe(bus_space_tag_t t,bus_space_handle_t bsh,bus_size_t offset,int sz)121 news68k_bus_space_probe(bus_space_tag_t t, bus_space_handle_t bsh,
122     bus_size_t offset, int sz)
123 {
124 	label_t faultbuf;
125 	int i;
126 
127 	nofault = (int *)&faultbuf;
128 	if (setjmp((label_t *)nofault)) {
129 		nofault = NULL;
130 		return 0;
131 	}
132 
133 	switch (sz) {
134 	case 1:
135 		i = bus_space_read_1(t, bsh, offset);
136 		break;
137 
138 	case 2:
139 		i = bus_space_read_2(t, bsh, offset);
140 		break;
141 
142 	case 4:
143 		i = bus_space_read_4(t, bsh, offset);
144 		break;
145 
146 	default:
147 		panic("bus_space_probe: unupported data size %d", sz);
148 		/* NOTREACHED */
149 	}
150 	__USE(i);
151 	nofault = NULL;
152 	return 1;
153 }
154