1 1.5 ryo /* $NetBSD: rsbus_io.c,v 1.5 2018/03/16 17:56:31 ryo Exp $ */ 2 1.1 chris 3 1.1 chris /* 4 1.1 chris * Copyright (c) 1997 Mark Brinicombe. 5 1.1 chris * All rights reserved. 6 1.1 chris * 7 1.1 chris * Redistribution and use in source and binary forms, with or without 8 1.1 chris * modification, are permitted provided that the following conditions 9 1.1 chris * are met: 10 1.1 chris * 1. Redistributions of source code must retain the above copyright 11 1.1 chris * notice, this list of conditions and the following disclaimer. 12 1.1 chris * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 chris * notice, this list of conditions and the following disclaimer in the 14 1.1 chris * documentation and/or other materials provided with the distribution. 15 1.1 chris * 3. All advertising materials mentioning features or use of this software 16 1.1 chris * must display the following acknowledgement: 17 1.1 chris * This product includes software developed by Mark Brinicombe. 18 1.1 chris * 4. The name of the company nor the name of the author may be used to 19 1.1 chris * endorse or promote products derived from this software without specific 20 1.1 chris * prior written permission. 21 1.1 chris * 22 1.1 chris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 1.1 chris * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 1.1 chris * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 1.1 chris * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 26 1.1 chris * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 1.1 chris * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 1.1 chris * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 1.1 chris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 1.1 chris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 1.1 chris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 1.1 chris * SUCH DAMAGE. 33 1.1 chris */ 34 1.1 chris 35 1.1 chris /* 36 1.1 chris * bus_space I/O functions for rsbus 37 1.1 chris */ 38 1.1 chris 39 1.1 chris #include <sys/cdefs.h> 40 1.5 ryo __KERNEL_RCSID(0, "$NetBSD: rsbus_io.c,v 1.5 2018/03/16 17:56:31 ryo Exp $"); 41 1.1 chris 42 1.1 chris #include <sys/param.h> 43 1.1 chris #include <sys/systm.h> 44 1.3 dyoung #include <sys/bus.h> 45 1.1 chris 46 1.1 chris /* Proto types for all the bus_space structure functions */ 47 1.1 chris 48 1.1 chris bs_protos(rsbus); 49 1.1 chris bs_protos(bs_notimpl); 50 1.1 chris bs_protos(mainbus); 51 1.1 chris 52 1.1 chris /* Declare the rsbus bus space tag */ 53 1.1 chris struct bus_space rsbus_bs_tag = { 54 1.1 chris /* cookie */ 55 1.5 ryo .bs_cookie = (void *) 2, /* Shift to apply to registers */ 56 1.1 chris 57 1.1 chris /* mapping/unmapping */ 58 1.5 ryo .bs_map = mainbus_bs_map, 59 1.5 ryo .bs_unmap = mainbus_bs_unmap, 60 1.5 ryo .bs_subregion = mainbus_bs_subregion, 61 1.1 chris 62 1.1 chris /* allocation/deallocation */ 63 1.5 ryo .bs_alloc = mainbus_bs_alloc, 64 1.5 ryo .bs_free = mainbus_bs_free, 65 1.1 chris 66 1.1 chris /* get kernel virtual address */ 67 1.5 ryo .bs_vaddr = 0, /* there is no linear mapping */ 68 1.1 chris 69 1.1 chris /* mmap bus space for userland */ 70 1.5 ryo .bs_mmap = mainbus_bs_mmap, 71 1.1 chris 72 1.1 chris /* barrier */ 73 1.5 ryo .bs_barrier = mainbus_bs_barrier, 74 1.1 chris 75 1.1 chris /* read (single) */ 76 1.5 ryo .bs_r_1 = rsbus_bs_r_1, 77 1.5 ryo .bs_r_2 = rsbus_bs_r_2, 78 1.5 ryo .bs_r_4 = rsbus_bs_r_4, 79 1.5 ryo .bs_r_8 = bs_notimpl_bs_r_8, 80 1.1 chris 81 1.1 chris /* read multiple */ 82 1.5 ryo .bs_rm_1 = rsbus_bs_rm_1, 83 1.5 ryo .bs_rm_2 = rsbus_bs_rm_2, 84 1.5 ryo .bs_rm_4 = bs_notimpl_bs_rm_4, 85 1.5 ryo .bs_rm_8 = bs_notimpl_bs_rm_8, 86 1.1 chris 87 1.1 chris /* read region */ 88 1.5 ryo .bs_rr_1 = rsbus_bs_rr_1, 89 1.5 ryo .bs_rr_2 = rsbus_bs_rr_2, 90 1.5 ryo .bs_rr_4 = bs_notimpl_bs_rr_4, 91 1.5 ryo .bs_rr_8 = bs_notimpl_bs_rr_8, 92 1.1 chris 93 1.1 chris /* write (single) */ 94 1.5 ryo .bs_w_1 = rsbus_bs_w_1, 95 1.5 ryo .bs_w_2 = rsbus_bs_w_2, 96 1.5 ryo .bs_w_4 = rsbus_bs_w_4, 97 1.5 ryo .bs_w_8 = bs_notimpl_bs_w_8, 98 1.1 chris 99 1.1 chris /* write multiple */ 100 1.5 ryo .bs_wm_1 = rsbus_bs_wm_1, 101 1.5 ryo .bs_wm_2 = rsbus_bs_wm_2, 102 1.5 ryo .bs_wm_4 = bs_notimpl_bs_wm_4, 103 1.5 ryo .bs_wm_8 = bs_notimpl_bs_wm_8, 104 1.1 chris 105 1.1 chris /* write region */ 106 1.5 ryo .bs_wr_1 = rsbus_bs_wr_1, 107 1.5 ryo .bs_wr_2 = rsbus_bs_wr_2, 108 1.5 ryo .bs_wr_4 = bs_notimpl_bs_wr_4, 109 1.5 ryo .bs_wr_8 = bs_notimpl_bs_wr_8, 110 1.1 chris 111 1.1 chris /* set multiple */ 112 1.5 ryo .bs_sm_1 = bs_notimpl_bs_sm_1, 113 1.5 ryo .bs_sm_2 = bs_notimpl_bs_sm_2, 114 1.5 ryo .bs_sm_4 = bs_notimpl_bs_sm_4, 115 1.5 ryo .bs_sm_8 = bs_notimpl_bs_sm_8, 116 1.1 chris 117 1.1 chris /* set region */ 118 1.5 ryo .bs_sr_1 = rsbus_bs_sr_1, 119 1.5 ryo .bs_sr_2 = rsbus_bs_sr_2, 120 1.5 ryo .bs_sr_4 = bs_notimpl_bs_sr_4, 121 1.5 ryo .bs_sr_8 = bs_notimpl_bs_sr_8, 122 1.1 chris 123 1.1 chris /* copy */ 124 1.5 ryo .bs_c_1 = bs_notimpl_bs_c_1, 125 1.5 ryo .bs_c_2 = bs_notimpl_bs_c_2, 126 1.5 ryo .bs_c_4 = bs_notimpl_bs_c_4, 127 1.5 ryo .bs_c_8 = bs_notimpl_bs_c_8, 128 1.1 chris }; 129 1.1 chris 130 1.1 chris /* bus space functions */ 131 1.1 chris 132 1.1 chris /* Rough-and-ready implementations from arm26 */ 133 1.1 chris void 134 1.1 chris rsbus_bs_rr_1(void *cookie, bus_space_handle_t bsh, 135 1.4 skrll bus_size_t offset, uint8_t *datap, bus_size_t count) 136 1.1 chris { 137 1.1 chris int i; 138 1.1 chris 139 1.1 chris for (i = 0; i < count; i++) 140 1.1 chris datap[i] = rsbus_bs_r_1(cookie, bsh, offset + i); 141 1.1 chris } 142 1.1 chris 143 1.1 chris void 144 1.1 chris rsbus_bs_rr_2(void *cookie, bus_space_handle_t bsh, 145 1.4 skrll bus_size_t offset, uint16_t *datap, bus_size_t count) 146 1.1 chris { 147 1.1 chris int i; 148 1.1 chris 149 1.1 chris for (i = 0; i < count; i++) 150 1.1 chris datap[i] = rsbus_bs_r_2(cookie, bsh, offset + i); 151 1.1 chris } 152 1.1 chris 153 1.1 chris void 154 1.1 chris rsbus_bs_wr_1(void *cookie, bus_space_handle_t bsh, 155 1.4 skrll bus_size_t offset, uint8_t const *datap, 156 1.1 chris bus_size_t count) 157 1.1 chris { 158 1.1 chris int i; 159 1.1 chris 160 1.1 chris for (i = 0; i < count; i++) 161 1.1 chris rsbus_bs_w_1(cookie, bsh, offset + i, datap[i]); 162 1.1 chris } 163 1.1 chris 164 1.1 chris void 165 1.1 chris rsbus_bs_wr_2(void *cookie, bus_space_handle_t bsh, 166 1.4 skrll bus_size_t offset, uint16_t const *datap, 167 1.1 chris bus_size_t count) 168 1.1 chris { 169 1.1 chris int i; 170 1.1 chris 171 1.1 chris for (i = 0; i < count; i++) 172 1.1 chris rsbus_bs_w_2(cookie, bsh, offset + i, datap[i]); 173 1.1 chris } 174 1.1 chris 175 1.1 chris void 176 1.1 chris rsbus_bs_sr_1(void *cookie, bus_space_handle_t bsh, 177 1.4 skrll bus_size_t offset, uint8_t value, bus_size_t count) 178 1.1 chris { 179 1.1 chris int i; 180 1.1 chris 181 1.1 chris for (i = 0; i < count; i++) 182 1.1 chris rsbus_bs_w_1(cookie, bsh, offset + i, value); 183 1.1 chris } 184 1.1 chris 185 1.1 chris void 186 1.1 chris rsbus_bs_sr_2(void *cookie, bus_space_handle_t bsh, 187 1.4 skrll bus_size_t offset, uint16_t value, bus_size_t count) 188 1.1 chris { 189 1.1 chris int i; 190 1.1 chris 191 1.1 chris for (i = 0; i < count; i++) 192 1.1 chris rsbus_bs_w_2(cookie, bsh, offset + i, value); 193 1.1 chris } 194