1123256Sscottl/*-
2123256Sscottl * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org>
3123256Sscottl * All rights reserved.
4123256Sscottl *
5123256Sscottl * Redistribution and use in source and binary forms, with or without
6123256Sscottl * modification, are permitted provided that the following conditions
7123256Sscottl * are met:
8123256Sscottl * 1. Redistributions of source code must retain the above copyright
9123256Sscottl *    notice unmodified, this list of conditions, and the following
10123256Sscottl *    disclaimer.
11123256Sscottl * 2. Redistributions in binary form must reproduce the above copyright
12123256Sscottl *    notice, this list of conditions and the following disclaimer in the
13123256Sscottl *    documentation and/or other materials provided with the distribution.
14123256Sscottl *
15123256Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16123256Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17123256Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18123256Sscottl * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19123256Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20123256Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21123256Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22123256Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23123256Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24123256Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25123256Sscottl * SUCH DAMAGE.
26123256Sscottl */
27123256Sscottl#include <sys/cdefs.h>
28123256Sscottl__FBSDID("$FreeBSD: releng/10.3/sys/mips/atheros/ar71xx_bus_space_reversed.c 202175 2010-01-12 21:36:08Z imp $");
29123256Sscottl
30123256Sscottl#include <sys/param.h>
31123256Sscottl#include <sys/systm.h>
32206622Suqs#include <sys/bus.h>
33123256Sscottl
34123256Sscottl#include <machine/bus.h>
35123256Sscottl#include <mips/atheros/ar71xx_bus_space_reversed.h>
36131736Sru
37123256Sscottlstatic bs_r_1_proto(reversed);
38123256Sscottlstatic bs_r_2_proto(reversed);
39123256Sscottlstatic bs_w_1_proto(reversed);
40123256Sscottlstatic bs_w_2_proto(reversed);
41123256Sscottl
42131736Sru/*
43131736Sru * Bus space that handles offsets in word for 1/2 bytes read/write access.
44131736Sru * Byte order of values is handled by device drivers itself.
45131736Sru */
46131736Srustatic struct bus_space bus_space_reversed = {
47131736Sru	/* cookie */
48128951Shmp	(void *) 0,
49123492Sroam
50131736Sru	/* mapping/unmapping */
51131736Sru	generic_bs_map,
52131736Sru	generic_bs_unmap,
53131736Sru	generic_bs_subregion,
54123256Sscottl
55128951Shmp	/* allocation/deallocation */
56131736Sru	NULL,
57131736Sru	NULL,
58131736Sru
59123256Sscottl	/* barrier */
60131736Sru	generic_bs_barrier,
61123256Sscottl
62131736Sru	/* read (single) */
63131736Sru	reversed_bs_r_1,
64131736Sru	reversed_bs_r_2,
65128951Shmp	generic_bs_r_4,
66131736Sru	NULL,
67131736Sru
68131736Sru	/* read multiple */
69123256Sscottl	generic_bs_rm_1,
70131736Sru	generic_bs_rm_2,
71131736Sru	generic_bs_rm_4,
72131736Sru	NULL,
73128951Shmp
74128951Shmp	/* read region */
75131736Sru	generic_bs_rr_1,
76131736Sru	generic_bs_rr_2,
77131736Sru	generic_bs_rr_4,
78131736Sru	NULL,
79131736Sru
80131736Sru	/* write (single) */
81131736Sru	reversed_bs_w_1,
82131736Sru	reversed_bs_w_2,
83131736Sru	generic_bs_w_4,
84131736Sru	NULL,
85131736Sru
86131736Sru	/* write multiple */
87131736Sru	generic_bs_wm_1,
88123256Sscottl	generic_bs_wm_2,
89123256Sscottl	generic_bs_wm_4,
90123256Sscottl	NULL,
91123256Sscottl
92123256Sscottl	/* write region */
93147647Shmp	NULL,
94123256Sscottl	generic_bs_wr_2,
95	generic_bs_wr_4,
96	NULL,
97
98	/* set multiple */
99	NULL,
100	NULL,
101	NULL,
102	NULL,
103
104	/* set region */
105	NULL,
106	generic_bs_sr_2,
107	generic_bs_sr_4,
108	NULL,
109
110	/* copy */
111	NULL,
112	generic_bs_c_2,
113	NULL,
114	NULL,
115
116	/* read (single) stream */
117	generic_bs_r_1,
118	generic_bs_r_2,
119	generic_bs_r_4,
120	NULL,
121
122	/* read multiple stream */
123	generic_bs_rm_1,
124	generic_bs_rm_2,
125	generic_bs_rm_4,
126	NULL,
127
128	/* read region stream */
129	generic_bs_rr_1,
130	generic_bs_rr_2,
131	generic_bs_rr_4,
132	NULL,
133
134	/* write (single) stream */
135	generic_bs_w_1,
136	generic_bs_w_2,
137	generic_bs_w_4,
138	NULL,
139
140	/* write multiple stream */
141	generic_bs_wm_1,
142	generic_bs_wm_2,
143	generic_bs_wm_4,
144	NULL,
145
146	/* write region stream */
147	NULL,
148	generic_bs_wr_2,
149	generic_bs_wr_4,
150	NULL,
151};
152
153bus_space_tag_t ar71xx_bus_space_reversed = &bus_space_reversed;
154
155static uint8_t
156reversed_bs_r_1(void *t, bus_space_handle_t h, bus_size_t o)
157{
158
159	return readb(h + (o &~ 3) + (3 - (o & 3)));
160}
161
162static void
163reversed_bs_w_1(void *t, bus_space_handle_t h, bus_size_t o, u_int8_t v)
164{
165
166	writeb(h + (o &~ 3) + (3 - (o & 3)), v);
167}
168
169static uint16_t
170reversed_bs_r_2(void *t, bus_space_handle_t h, bus_size_t o)
171{
172
173	return readw(h + (o &~ 3) + (2 - (o & 3)));
174}
175
176static void
177reversed_bs_w_2(void *t, bus_space_handle_t h, bus_size_t o, uint16_t v)
178{
179
180	writew(h + (o &~ 3) + (2 - (o & 3)), v);
181}
182