13004Salanb/*- 23004Salanb * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org> 33004Salanb * All rights reserved. 43004Salanb * 53004Salanb * Redistribution and use in source and binary forms, with or without 63004Salanb * modification, are permitted provided that the following conditions 73004Salanb * are met: 83004Salanb * 1. Redistributions of source code must retain the above copyright 93004Salanb * notice unmodified, this list of conditions, and the following 103004Salanb * disclaimer. 113004Salanb * 2. Redistributions in binary form must reproduce the above copyright 123004Salanb * notice, this list of conditions and the following disclaimer in the 133004Salanb * documentation and/or other materials provided with the distribution. 143004Salanb * 153004Salanb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 163004Salanb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 173004Salanb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 183004Salanb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 193004Salanb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 203004Salanb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 213004Salanb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 223004Salanb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 233004Salanb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 243004Salanb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 253004Salanb * SUCH DAMAGE. 263004Salanb */ 273004Salanb#include <sys/cdefs.h> 283004Salanb__FBSDID("$FreeBSD$"); 293004Salanb 303004Salanb#include <sys/param.h> 313004Salanb#include <sys/systm.h> 323004Salanb#include <sys/bus.h> 333004Salanb 343004Salanb#include <machine/bus.h> 353004Salanb#include <mips/atheros/ar71xx_bus_space_reversed.h> 363004Salanb 373004Salanbstatic bs_r_1_proto(reversed); 383004Salanbstatic bs_r_2_proto(reversed); 393004Salanbstatic bs_w_1_proto(reversed); 403004Salanbstatic bs_w_2_proto(reversed); 413004Salanb 423004Salanb/* 433004Salanb * Bus space that handles offsets in word for 1/2 bytes read/write access. 443004Salanb * Byte order of values is handled by device drivers itself. 453004Salanb */ 463004Salanbstatic struct bus_space bus_space_reversed = { 473004Salanb /* cookie */ 483004Salanb (void *) 0, 493004Salanb 503004Salanb /* mapping/unmapping */ 513004Salanb generic_bs_map, 523004Salanb generic_bs_unmap, 533004Salanb generic_bs_subregion, 543004Salanb 553004Salanb /* allocation/deallocation */ 563004Salanb NULL, 573004Salanb NULL, 583004Salanb 593004Salanb /* barrier */ 603004Salanb generic_bs_barrier, 613004Salanb 623004Salanb /* read (single) */ 633004Salanb reversed_bs_r_1, 643004Salanb reversed_bs_r_2, 653004Salanb generic_bs_r_4, 663004Salanb NULL, 673004Salanb 683004Salanb /* read multiple */ 693004Salanb generic_bs_rm_1, 703004Salanb generic_bs_rm_2, 713004Salanb generic_bs_rm_4, 723004Salanb NULL, 733004Salanb 743004Salanb /* read region */ 753004Salanb generic_bs_rr_1, 763004Salanb generic_bs_rr_2, 773004Salanb generic_bs_rr_4, 783004Salanb NULL, 793004Salanb 803004Salanb /* write (single) */ 813004Salanb reversed_bs_w_1, 82 reversed_bs_w_2, 83 generic_bs_w_4, 84 NULL, 85 86 /* write multiple */ 87 generic_bs_wm_1, 88 generic_bs_wm_2, 89 generic_bs_wm_4, 90 NULL, 91 92 /* write region */ 93 NULL, 94 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