octeon_bus_space.c revision 1.1
1/* $OpenBSD: octeon_bus_space.c,v 1.1 2010/10/28 22:52:10 syuu Exp $ */ 2 3/* 4 * Copyright (c) 2001-2003 Opsycon AB (www.opsycon.se / www.opsycon.com) 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 */ 28 29/* 30 * Simple generic bus access primitives. 31 */ 32 33#include <sys/param.h> 34#include <sys/systm.h> 35 36#include <machine/bus.h> 37 38uint8_t 39generic_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) 40{ 41 return *(volatile uint8_t *)(h + o); 42} 43 44uint16_t 45generic_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) 46{ 47 return *(volatile uint16_t *)(h + o); 48} 49 50uint32_t 51generic_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) 52{ 53 return *(volatile uint32_t *)(h + o); 54} 55 56uint64_t 57generic_space_read_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) 58{ 59 return *(volatile uint64_t *)(h + o); 60} 61 62void 63generic_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 64 uint8_t v) 65{ 66 *(volatile uint8_t *)(h + o) = v; 67} 68 69void 70generic_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 71 uint16_t v) 72{ 73 *(volatile uint16_t *)(h + o) = v; 74} 75 76void 77generic_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 78 uint32_t v) 79{ 80 *(volatile uint32_t *)(h + o) = v; 81} 82 83void 84generic_space_write_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 85 uint64_t v) 86{ 87 *(volatile uint64_t *)(h + o) = v; 88} 89 90void 91generic_space_read_raw_2(bus_space_tag_t t, bus_space_handle_t h, bus_addr_t o, 92 uint8_t *buf, bus_size_t len) 93{ 94 volatile uint16_t *addr = (volatile uint16_t *)(h + o); 95 len >>= 1; 96 while (len-- != 0) { 97 *(uint16_t *)buf = *addr; 98 buf += 2; 99 } 100} 101 102void 103generic_space_write_raw_2(bus_space_tag_t t, bus_space_handle_t h, bus_addr_t o, 104 const uint8_t *buf, bus_size_t len) 105{ 106 volatile uint16_t *addr = (volatile uint16_t *)(h + o); 107 len >>= 1; 108 while (len-- != 0) { 109 *addr = *(uint16_t *)buf; 110 buf += 2; 111 } 112} 113 114void 115generic_space_read_raw_4(bus_space_tag_t t, bus_space_handle_t h, bus_addr_t o, 116 uint8_t *buf, bus_size_t len) 117{ 118 volatile uint32_t *addr = (volatile uint32_t *)(h + o); 119 len >>= 2; 120 while (len-- != 0) { 121 *(uint32_t *)buf = *addr; 122 buf += 4; 123 } 124} 125 126void 127generic_space_write_raw_4(bus_space_tag_t t, bus_space_handle_t h, bus_addr_t o, 128 const uint8_t *buf, bus_size_t len) 129{ 130 volatile uint32_t *addr = (volatile uint32_t *)(h + o); 131 len >>= 2; 132 while (len-- != 0) { 133 *addr = *(uint32_t *)buf; 134 buf += 4; 135 } 136} 137 138void 139generic_space_read_raw_8(bus_space_tag_t t, bus_space_handle_t h, bus_addr_t o, 140 uint8_t *buf, bus_size_t len) 141{ 142 volatile uint64_t *addr = (volatile uint64_t *)(h + o); 143 len >>= 3; 144 while (len-- != 0) { 145 *(uint64_t *)buf = *addr; 146 buf += 8; 147 } 148} 149 150void 151generic_space_write_raw_8(bus_space_tag_t t, bus_space_handle_t h, bus_addr_t o, 152 const uint8_t *buf, bus_size_t len) 153{ 154 volatile uint64_t *addr = (volatile uint64_t *)(h + o); 155 len >>= 3; 156 while (len-- != 0) { 157 *addr = *(uint64_t *)buf; 158 buf += 8; 159 } 160} 161 162int 163generic_space_map(bus_space_tag_t t, bus_addr_t offs, bus_size_t size, 164 int flags, bus_space_handle_t *bshp) 165{ 166 *bshp = t->bus_base + offs; 167 return 0; 168} 169 170void 171generic_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size) 172{ 173} 174 175int 176generic_space_region(bus_space_tag_t t, bus_space_handle_t bsh, 177 bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp) 178{ 179 *nbshp = bsh + offset; 180 return 0; 181} 182 183void * 184generic_space_vaddr(bus_space_tag_t t, bus_space_handle_t h) 185{ 186 return (void *)h; 187} 188