1*23fc84bdSjoerg /* $NetBSD: amiga_bus_simple_1word.c,v 1.9 2014/08/06 14:23:53 joerg Exp $ */
23a54b5a8Saymeric
33a54b5a8Saymeric /*-
43a54b5a8Saymeric * Copyright (c) 1999 The NetBSD Foundation, Inc.
53a54b5a8Saymeric * All rights reserved.
63a54b5a8Saymeric *
73a54b5a8Saymeric * This code is derived from software contributed to The NetBSD Foundation
83a54b5a8Saymeric * by Ignatios Souvatzis.
93a54b5a8Saymeric *
103a54b5a8Saymeric * Redistribution and use in source and binary forms, with or without
113a54b5a8Saymeric * modification, are permitted provided that the following conditions
123a54b5a8Saymeric * are met:
133a54b5a8Saymeric * 1. Redistributions of source code must retain the above copyright
143a54b5a8Saymeric * notice, this list of conditions and the following disclaimer.
153a54b5a8Saymeric * 2. Redistributions in binary form must reproduce the above copyright
163a54b5a8Saymeric * notice, this list of conditions and the following disclaimer in the
173a54b5a8Saymeric * documentation and/or other materials provided with the distribution.
183a54b5a8Saymeric *
193a54b5a8Saymeric * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
203a54b5a8Saymeric * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
213a54b5a8Saymeric * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223a54b5a8Saymeric * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
233a54b5a8Saymeric * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
243a54b5a8Saymeric * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
253a54b5a8Saymeric * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
263a54b5a8Saymeric * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
273a54b5a8Saymeric * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
283a54b5a8Saymeric * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
293a54b5a8Saymeric * POSSIBILITY OF SUCH DAMAGE.
303a54b5a8Saymeric */
31dd5ab79cSrkujawa #include <sys/param.h>
32dd5ab79cSrkujawa #include <sys/device.h>
33dd5ab79cSrkujawa #include <sys/systm.h>
34dd5ab79cSrkujawa
35dd5ab79cSrkujawa #include <machine/cpu.h>
36dd5ab79cSrkujawa #include <machine/pte.h>
373a54b5a8Saymeric
381ea4df81Saymeric #include <sys/cdefs.h>
39*23fc84bdSjoerg __KERNEL_RCSID(1, "$NetBSD: amiga_bus_simple_1word.c,v 1.9 2014/08/06 14:23:53 joerg Exp $");
401ea4df81Saymeric
41dd5ab79cSrkujawa #define AMIGA_SIMPLE_BUS_STRIDE 1 /* 1 byte per byte */
423a54b5a8Saymeric #define AMIGA_SIMPLE_BUS_WORD_METHODS
43dd5ab79cSrkujawa #define AMIGA_SIMPLE_BUS_LONGWORD_METHODS
443a54b5a8Saymeric
453a54b5a8Saymeric #include "simple_busfuncs.c"
46dd5ab79cSrkujawa
47efb0a9dcSrkujawa bsr(oabs(bsr2_swap_), u_int16_t);
48efb0a9dcSrkujawa bsw(oabs(bsw2_swap_), u_int16_t);
49dd5ab79cSrkujawa bsr(oabs(bsr4_swap_), u_int32_t);
50dd5ab79cSrkujawa bsw(oabs(bsw4_swap_), u_int32_t);
51dd5ab79cSrkujawa
52dd5ab79cSrkujawa bsrm(oabs(bsrm2_swap_), u_int16_t);
53dd5ab79cSrkujawa bswm(oabs(bswm2_swap_), u_int16_t);
54dd5ab79cSrkujawa
55dd5ab79cSrkujawa int oabs(bsm_absolute_)(bus_space_tag_t, bus_addr_t, bus_size_t, int,
56dd5ab79cSrkujawa bus_space_handle_t *);
57dd5ab79cSrkujawa
58dd5ab79cSrkujawa /* ARGSUSED */
59dd5ab79cSrkujawa int
oabs(bsm_absolute_)6041ba3596Smatt oabs(bsm_absolute_)(bus_space_tag_t tag, bus_addr_t address,
6141ba3596Smatt bus_size_t size, int flags, bus_space_handle_t *handlep)
62dd5ab79cSrkujawa {
63dd5ab79cSrkujawa uint32_t pa = kvtop((void*) tag->base);
64dd5ab79cSrkujawa *handlep = tag->base + (address - pa) * AMIGA_SIMPLE_BUS_STRIDE;
65dd5ab79cSrkujawa return 0;
66dd5ab79cSrkujawa }
67dd5ab79cSrkujawa
68dd5ab79cSrkujawa /* ARGSUSED */
69efb0a9dcSrkujawa u_int16_t
oabs(bsr2_swap_)70efb0a9dcSrkujawa oabs(bsr2_swap_)(bus_space_handle_t handle, bus_size_t offset)
71efb0a9dcSrkujawa {
72efb0a9dcSrkujawa volatile u_int16_t *p;
73efb0a9dcSrkujawa u_int16_t x;
74efb0a9dcSrkujawa
75efb0a9dcSrkujawa p = (volatile u_int16_t *)(handle + offset * AMIGA_SIMPLE_BUS_STRIDE);
76efb0a9dcSrkujawa x = *p;
77efb0a9dcSrkujawa amiga_bus_reorder_protect();
78efb0a9dcSrkujawa return bswap16(x);
79efb0a9dcSrkujawa }
80efb0a9dcSrkujawa
81efb0a9dcSrkujawa /* ARGSUSED */
82efb0a9dcSrkujawa void
oabs(bsw2_swap_)83efb0a9dcSrkujawa oabs(bsw2_swap_)(bus_space_handle_t handle, bus_size_t offset, unsigned value)
84efb0a9dcSrkujawa {
85efb0a9dcSrkujawa volatile u_int16_t *p;
86efb0a9dcSrkujawa
87efb0a9dcSrkujawa p = (volatile u_int16_t *)(handle + offset * AMIGA_SIMPLE_BUS_STRIDE);
88efb0a9dcSrkujawa *p = bswap16( (u_int16_t)value );
89efb0a9dcSrkujawa amiga_bus_reorder_protect();
90efb0a9dcSrkujawa }
91efb0a9dcSrkujawa
92efb0a9dcSrkujawa /* ARGSUSED */
93dd5ab79cSrkujawa u_int32_t
oabs(bsr4_swap_)9441ba3596Smatt oabs(bsr4_swap_)(bus_space_handle_t handle, bus_size_t offset)
95dd5ab79cSrkujawa {
96dd5ab79cSrkujawa volatile u_int32_t *p;
97dd5ab79cSrkujawa u_int32_t x;
98dd5ab79cSrkujawa
99dd5ab79cSrkujawa p = (volatile u_int32_t *)(handle + offset * AMIGA_SIMPLE_BUS_STRIDE);
100dd5ab79cSrkujawa x = *p;
101dd5ab79cSrkujawa amiga_bus_reorder_protect();
102dd5ab79cSrkujawa return bswap32(x);
103dd5ab79cSrkujawa }
104dd5ab79cSrkujawa
105dd5ab79cSrkujawa /* ARGSUSED */
106dd5ab79cSrkujawa void
oabs(bsw4_swap_)10741ba3596Smatt oabs(bsw4_swap_)(bus_space_handle_t handle, bus_size_t offset, unsigned value)
108dd5ab79cSrkujawa {
109dd5ab79cSrkujawa volatile u_int32_t *p;
110dd5ab79cSrkujawa
111dd5ab79cSrkujawa p = (volatile u_int32_t *)(handle + offset * AMIGA_SIMPLE_BUS_STRIDE);
112dd5ab79cSrkujawa *p = bswap32( (u_int32_t)value );
113dd5ab79cSrkujawa amiga_bus_reorder_protect();
114dd5ab79cSrkujawa }
115dd5ab79cSrkujawa
116dd5ab79cSrkujawa /* ARGSUSED */
117dd5ab79cSrkujawa void
oabs(bsrm2_swap_)118dd5ab79cSrkujawa oabs(bsrm2_swap_)(bus_space_handle_t handle, bus_size_t offset,
119dd5ab79cSrkujawa u_int16_t *pointer, bus_size_t count)
120dd5ab79cSrkujawa {
121dd5ab79cSrkujawa volatile u_int16_t *p;
122dd5ab79cSrkujawa
123dd5ab79cSrkujawa p = (volatile u_int16_t *)(handle + offset * AMIGA_SIMPLE_BUS_STRIDE);
124dd5ab79cSrkujawa
125dd5ab79cSrkujawa while (count > 0) {
126dd5ab79cSrkujawa *pointer++ = bswap16(*p);
127dd5ab79cSrkujawa amiga_bus_reorder_protect();
128dd5ab79cSrkujawa --count;
129dd5ab79cSrkujawa }
130dd5ab79cSrkujawa }
131dd5ab79cSrkujawa
132dd5ab79cSrkujawa /* ARGSUSED */
133dd5ab79cSrkujawa void
oabs(bswm2_swap_)134dd5ab79cSrkujawa oabs(bswm2_swap_)(bus_space_handle_t handle, bus_size_t offset,
135dd5ab79cSrkujawa const u_int16_t *pointer, bus_size_t count)
136dd5ab79cSrkujawa {
137dd5ab79cSrkujawa volatile u_int16_t *p;
138dd5ab79cSrkujawa
139dd5ab79cSrkujawa p = (volatile u_int16_t *)(handle + offset * AMIGA_SIMPLE_BUS_STRIDE);
140dd5ab79cSrkujawa
141dd5ab79cSrkujawa while (count > 0) {
142dd5ab79cSrkujawa *p = bswap16(*pointer);
143dd5ab79cSrkujawa amiga_bus_reorder_protect();
144dd5ab79cSrkujawa ++pointer;
145dd5ab79cSrkujawa --count;
146dd5ab79cSrkujawa }
147dd5ab79cSrkujawa }
148dd5ab79cSrkujawa
149dd5ab79cSrkujawa const struct amiga_bus_space_methods amiga_bus_stride_1swap_abs = {
150dd5ab79cSrkujawa
1518e72f003Schristos .bsm = oabs(bsm_absolute_),
1528e72f003Schristos .bsms = oabs(bsms_),
1538e72f003Schristos .bsu = oabs(bsu_),
1548e72f003Schristos .bsa = NULL,
1558e72f003Schristos .bsf = NULL,
156dd5ab79cSrkujawa
1578e72f003Schristos .bsr1 = oabs(bsr1_),
1588e72f003Schristos .bsw1 = oabs(bsw1_),
1598e72f003Schristos .bsrm1 = oabs(bsrm1_),
1608e72f003Schristos .bswm1 = oabs(bswm1_),
1618e72f003Schristos .bsrr1 = oabs(bsrr1_),
1628e72f003Schristos .bswr1 = oabs(bswr1_),
1638e72f003Schristos .bssr1 = oabs(bssr1_),
1648e72f003Schristos .bscr1 = oabs(bscr1_),
165dd5ab79cSrkujawa
1668e72f003Schristos .bsr2 = oabs(bsr2_), /* XXX swap? */
1678e72f003Schristos .bsw2 = oabs(bsw2_), /* XXX swap? */
1688e72f003Schristos .bsrs2 = oabs(bsr2_),
1698e72f003Schristos .bsws2 = oabs(bsw2_),
1708e72f003Schristos .bsrm2 = oabs(bsrm2_swap_),
1718e72f003Schristos .bswm2 = oabs(bswm2_swap_),
1728e72f003Schristos .bsrms2 = oabs(bsrm2_),
1738e72f003Schristos .bswms2 = oabs(bswm2_),
1748e72f003Schristos .bsrr2 = oabs(bsrr2_), /* XXX swap? */
1758e72f003Schristos .bswr2 = oabs(bswr2_), /* XXX swap? */
1768e72f003Schristos .bssr2 = oabs(bssr2_), /* XXX swap? */
1778e72f003Schristos .bscr2 = oabs(bscr2_), /* XXX swap? */
178dd5ab79cSrkujawa
1798e72f003Schristos .bsr4 = oabs(bsr4_swap_),
1808e72f003Schristos .bsw4 = oabs(bsw4_swap_),
1818e72f003Schristos .bsrs4 = oabs(bsr4_),
1828e72f003Schristos .bsws4 = oabs(bsw4_),
1838e72f003Schristos .bsrm4 = oabs(bsrm4_), /* XXX swap? */
1848e72f003Schristos .bswm4 = oabs(bswm4_), /* XXX swap? */
1858e72f003Schristos .bsrms4 = oabs(bsrm4_),
1868e72f003Schristos .bswms4 = oabs(bswm4_),
1878e72f003Schristos .bsrr4 = oabs(bsrr4_), /* XXX swap? */
1888e72f003Schristos .bswr4 = oabs(bswr4_), /* XXX swap? */
1898e72f003Schristos .bsrrs4 = oabs(bsrr4_),
1908e72f003Schristos .bswrs4 = oabs(bswr4_),
1918e72f003Schristos .bssr4 = oabs(bssr4_), /* XXX swap? */
1928e72f003Schristos .bscr4 = oabs(bscr4_) /* XXX swap? */
193dd5ab79cSrkujawa };
194dd5ab79cSrkujawa
195dd5ab79cSrkujawa const struct amiga_bus_space_methods amiga_bus_stride_1swap = {
196dd5ab79cSrkujawa
1978e72f003Schristos .bsm = oabs(bsm_),
1988e72f003Schristos .bsms = oabs(bsms_),
1998e72f003Schristos .bsu = oabs(bsu_),
2008e72f003Schristos .bsa = NULL,
2018e72f003Schristos .bsf = NULL,
202dd5ab79cSrkujawa
2038e72f003Schristos .bsr1 = oabs(bsr1_),
2048e72f003Schristos .bsw1 = oabs(bsw1_),
2058e72f003Schristos .bsrm1 = oabs(bsrm1_),
2068e72f003Schristos .bswm1 = oabs(bswm1_),
2078e72f003Schristos .bsrr1 = oabs(bsrr1_),
20811db23feSrkujawa .bswr1 = oabs(bswr1_),
2098e72f003Schristos .bssr1 = oabs(bssr1_),
2108e72f003Schristos .bscr1 = oabs(bscr1_),
211dd5ab79cSrkujawa
212efb0a9dcSrkujawa .bsr2 = oabs(bsr2_swap_),
213efb0a9dcSrkujawa .bsw2 = oabs(bsw2_swap_),
2148e72f003Schristos .bsrs2 = oabs(bsr2_),
2158e72f003Schristos .bsws2 = oabs(bsw2_),
2168e72f003Schristos .bsrm2 = oabs(bsrm2_swap_),
2178e72f003Schristos .bswm2 = oabs(bswm2_swap_),
2188e72f003Schristos .bsrms2 = oabs(bsrm2_),
2198e72f003Schristos .bswms2 = oabs(bswm2_),
2208e72f003Schristos .bsrr2 = oabs(bsrr2_), /* XXX swap? */
2218e72f003Schristos .bswr2 = oabs(bswr2_), /* XXX swap? */
2228e72f003Schristos .bsrrs2 = oabs(bsrr2_),
2238e72f003Schristos .bswrs2 = oabs(bswr2_),
2248e72f003Schristos .bssr2 = oabs(bssr2_), /* XXX swap? */
22511db23feSrkujawa .bscr2 = oabs(bscr2_), /* XXX swap? */
226dd5ab79cSrkujawa
2278e72f003Schristos .bsr4 = oabs(bsr4_swap_),
2288e72f003Schristos .bsw4 = oabs(bsw4_swap_),
2298e72f003Schristos .bsrs4 = oabs(bsr4_),
2308e72f003Schristos .bsws4 = oabs(bsw4_),
2318e72f003Schristos .bsrm4 = oabs(bsrm4_), /* XXX swap? */
2328e72f003Schristos .bswm4 = oabs(bswm4_), /* XXX swap? */
2338e72f003Schristos .bsrms4 = oabs(bsrm4_),
2348e72f003Schristos .bswms4 = oabs(bswm4_),
2358e72f003Schristos .bsrr4 = oabs(bsrr4_), /* XXX swap? */
2368e72f003Schristos .bswr4 = oabs(bswr4_), /* XXX swap? */
2378e72f003Schristos .bsrrs4 = oabs(bsrr4_),
2388e72f003Schristos .bswrs4 = oabs(bswr4_),
2398e72f003Schristos .bssr4 = oabs(bssr4_), /* XXX swap? */
2408e72f003Schristos .bscr4 = oabs(bscr4_) /* XXX swap? */
241dd5ab79cSrkujawa };
242