pxa_space.c revision 227293
1220496Smarkm/* $NetBSD: obio_space.c,v 1.6 2003/07/15 00:25:05 lukem Exp $ */ 2220496Smarkm 3220496Smarkm/*- 4220496Smarkm * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc. 5220496Smarkm * All rights reserved. 6220496Smarkm * 7220496Smarkm * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8220496Smarkm * 9220496Smarkm * Redistribution and use in source and binary forms, with or without 10220496Smarkm * modification, are permitted provided that the following conditions 11220496Smarkm * are met: 12263955Sgjb * 1. Redistributions of source code must retain the above copyright 13220496Smarkm * notice, this list of conditions and the following disclaimer. 14220496Smarkm * 2. Redistributions in binary form must reproduce the above copyright 15220496Smarkm * notice, this list of conditions and the following disclaimer in the 16220496Smarkm * documentation and/or other materials provided with the distribution. 17220496Smarkm * 3. All advertising materials mentioning features or use of this software 18220496Smarkm * must display the following acknowledgement: 19220496Smarkm * This product includes software developed for the NetBSD Project by 20220496Smarkm * Wasabi Systems, Inc. 21220496Smarkm * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22220496Smarkm * or promote products derived from this software without specific prior 23220496Smarkm * written permission. 24220496Smarkm * 25220496Smarkm * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26220496Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27220496Smarkm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28220496Smarkm * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29220496Smarkm * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30220496Smarkm * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31220496Smarkm * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32220496Smarkm * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33220496Smarkm * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34220496Smarkm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35220496Smarkm * POSSIBILITY OF SUCH DAMAGE. 36220496Smarkm */ 37220496Smarkm 38220496Smarkm/* 39220496Smarkm * bus_space functions for PXA devices 40220496Smarkm */ 41220496Smarkm 42220496Smarkm#include <sys/cdefs.h> 43220496Smarkm__FBSDID("$FreeBSD: head/sys/arm/xscale/pxa/pxa_space.c 227293 2011-11-07 06:44:47Z ed $"); 44220496Smarkm 45220496Smarkm#include <sys/param.h> 46220496Smarkm#include <sys/systm.h> 47220496Smarkm#include <sys/bus.h> 48220496Smarkm#include <sys/kernel.h> 49220496Smarkm#include <sys/malloc.h> 50220496Smarkm 51220496Smarkm#include <machine/bus.h> 52220496Smarkm 53220496Smarkm#include <arm/xscale/pxa/pxareg.h> 54220496Smarkm#include <arm/xscale/pxa/pxavar.h> 55220496Smarkm 56220496Smarkmstatic MALLOC_DEFINE(M_PXATAG, "PXA bus_space tags", "Bus_space tags for PXA"); 57220496Smarkm 58220496Smarkm/* Prototypes for all the bus_space structure functions */ 59220496Smarkmbs_protos(generic); 60220496Smarkmbs_protos(generic_armv4); 61220496Smarkmbs_protos(pxa); 62220496Smarkm 63220496Smarkm/* 64220496Smarkm * The obio bus space tag. This is constant for all instances, so 65220496Smarkm * we never have to explicitly "create" it. 66220496Smarkm */ 67220496Smarkmstruct bus_space _base_tag = { 68220496Smarkm /* cookie */ 69220496Smarkm (void *) 0, 70220496Smarkm 71220496Smarkm /* mapping/unmapping */ 72220496Smarkm generic_bs_map, 73220496Smarkm generic_bs_unmap, 74220496Smarkm generic_bs_subregion, 75220496Smarkm 76220496Smarkm /* allocation/deallocation */ 77220496Smarkm generic_bs_alloc, 78220496Smarkm generic_bs_free, 79220496Smarkm 80220496Smarkm /* barrier */ 81220496Smarkm generic_bs_barrier, 82220496Smarkm 83220496Smarkm /* read (single) */ 84220496Smarkm pxa_bs_r_1, 85220496Smarkm pxa_bs_r_2, 86220496Smarkm pxa_bs_r_4, 87220496Smarkm NULL, 88220496Smarkm 89220496Smarkm /* read multiple */ 90220496Smarkm pxa_bs_rm_1, 91220496Smarkm pxa_bs_rm_2, 92220496Smarkm NULL, 93220496Smarkm NULL, 94220496Smarkm 95220496Smarkm /* read region */ 96220496Smarkm pxa_bs_rr_1, 97220496Smarkm NULL, 98220496Smarkm NULL, 99220496Smarkm NULL, 100220496Smarkm 101220496Smarkm /* write (single) */ 102220496Smarkm pxa_bs_w_1, 103220496Smarkm pxa_bs_w_2, 104220496Smarkm pxa_bs_w_4, 105220496Smarkm NULL, 106220496Smarkm 107220496Smarkm /* write multiple */ 108220496Smarkm pxa_bs_wm_1, 109220496Smarkm pxa_bs_wm_2, 110220496Smarkm NULL, 111220496Smarkm NULL, 112220496Smarkm 113220496Smarkm /* write region */ 114220496Smarkm NULL, 115220496Smarkm NULL, 116220496Smarkm NULL, 117220496Smarkm NULL, 118220496Smarkm 119220496Smarkm /* set multiple */ 120220496Smarkm NULL, 121220496Smarkm NULL, 122220496Smarkm NULL, 123220496Smarkm NULL, 124220496Smarkm 125220496Smarkm /* set region */ 126220496Smarkm NULL, 127220496Smarkm NULL, 128220496Smarkm NULL, 129223582Scperciva NULL, 130220496Smarkm 131220496Smarkm /* copy */ 132220496Smarkm NULL, 133220496Smarkm NULL, 134220496Smarkm NULL, 135220496Smarkm NULL, 136220496Smarkm}; 137220496Smarkm 138220496Smarkmstatic struct bus_space _obio_tag; 139 140bus_space_tag_t base_tag = &_base_tag; 141bus_space_tag_t obio_tag = NULL; 142 143void 144pxa_obio_tag_init() 145{ 146 147 bcopy(&_base_tag, &_obio_tag, sizeof(struct bus_space)); 148 _obio_tag.bs_cookie = (void *)PXA2X0_PERIPH_OFFSET; 149 obio_tag = &_obio_tag; 150} 151 152bus_space_tag_t 153pxa_bus_tag_alloc(bus_addr_t offset) 154{ 155 struct bus_space *tag; 156 157 tag = (struct bus_space *)malloc(sizeof(struct bus_space), M_PXATAG, 158 M_WAITOK); 159 if (tag == NULL) { 160 return (NULL); 161 } 162 163 bcopy(&_base_tag, tag, sizeof(struct bus_space)); 164 tag->bs_cookie = (void *)offset; 165 166 return ((bus_space_tag_t)tag); 167} 168 169 170#define READ_SINGLE(type, proto, base) \ 171 type \ 172 proto(void *cookie, bus_space_handle_t bsh, bus_size_t offset) \ 173 { \ 174 bus_addr_t tag_offset; \ 175 type value; \ 176 tag_offset = (bus_addr_t)cookie; \ 177 value = base(NULL, bsh + tag_offset, offset); \ 178 return (value); \ 179 } 180 181READ_SINGLE(u_int8_t, pxa_bs_r_1, generic_bs_r_1) 182READ_SINGLE(u_int16_t, pxa_bs_r_2, generic_armv4_bs_r_2) 183READ_SINGLE(u_int32_t, pxa_bs_r_4, generic_bs_r_4) 184 185#undef READ_SINGLE 186 187#define WRITE_SINGLE(type, proto, base) \ 188 void \ 189 proto(void *cookie, bus_space_handle_t bsh, bus_size_t offset, \ 190 type value) \ 191 { \ 192 bus_addr_t tag_offset; \ 193 tag_offset = (bus_addr_t)cookie; \ 194 base(NULL, bsh + tag_offset, offset, value); \ 195 } 196 197WRITE_SINGLE(u_int8_t, pxa_bs_w_1, generic_bs_w_1) 198WRITE_SINGLE(u_int16_t, pxa_bs_w_2, generic_armv4_bs_w_2) 199WRITE_SINGLE(u_int32_t, pxa_bs_w_4, generic_bs_w_4) 200 201#undef WRITE_SINGLE 202 203#define READ_MULTI(type, proto, base) \ 204 void \ 205 proto(void *cookie, bus_space_handle_t bsh, bus_size_t offset, \ 206 type *dest, bus_size_t count) \ 207 { \ 208 bus_addr_t tag_offset; \ 209 tag_offset = (bus_addr_t)cookie; \ 210 base(NULL, bsh + tag_offset, offset, dest, count); \ 211 } 212 213READ_MULTI(u_int8_t, pxa_bs_rm_1, generic_bs_rm_1) 214READ_MULTI(u_int16_t, pxa_bs_rm_2, generic_armv4_bs_rm_2) 215 216READ_MULTI(u_int8_t, pxa_bs_rr_1, generic_bs_rr_1) 217 218#undef READ_MULTI 219 220#define WRITE_MULTI(type, proto, base) \ 221 void \ 222 proto(void *cookie, bus_space_handle_t bsh, bus_size_t offset, \ 223 const type *src, bus_size_t count) \ 224 { \ 225 bus_addr_t tag_offset; \ 226 tag_offset = (bus_addr_t)cookie; \ 227 base(NULL, bsh + tag_offset, offset, src, count); \ 228 } 229 230WRITE_MULTI(u_int8_t, pxa_bs_wm_1, generic_bs_wm_1) 231WRITE_MULTI(u_int16_t, pxa_bs_wm_2, generic_armv4_bs_wm_2) 232 233#undef WRITE_MULTI 234