1179595Sbenno/* $NetBSD: obio_space.c,v 1.6 2003/07/15 00:25:05 lukem Exp $ */ 2179595Sbenno 3179595Sbenno/*- 4179595Sbenno * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc. 5179595Sbenno * All rights reserved. 6179595Sbenno * 7179595Sbenno * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8179595Sbenno * 9179595Sbenno * Redistribution and use in source and binary forms, with or without 10179595Sbenno * modification, are permitted provided that the following conditions 11179595Sbenno * are met: 12179595Sbenno * 1. Redistributions of source code must retain the above copyright 13179595Sbenno * notice, this list of conditions and the following disclaimer. 14179595Sbenno * 2. Redistributions in binary form must reproduce the above copyright 15179595Sbenno * notice, this list of conditions and the following disclaimer in the 16179595Sbenno * documentation and/or other materials provided with the distribution. 17179595Sbenno * 3. All advertising materials mentioning features or use of this software 18179595Sbenno * must display the following acknowledgement: 19179595Sbenno * This product includes software developed for the NetBSD Project by 20179595Sbenno * Wasabi Systems, Inc. 21179595Sbenno * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22179595Sbenno * or promote products derived from this software without specific prior 23179595Sbenno * written permission. 24179595Sbenno * 25179595Sbenno * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26179595Sbenno * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27179595Sbenno * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28179595Sbenno * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29179595Sbenno * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30179595Sbenno * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31179595Sbenno * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32179595Sbenno * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33179595Sbenno * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34179595Sbenno * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35179595Sbenno * POSSIBILITY OF SUCH DAMAGE. 36179595Sbenno */ 37179595Sbenno 38179595Sbenno/* 39179595Sbenno * bus_space functions for PXA devices 40179595Sbenno */ 41179595Sbenno 42179595Sbenno#include <sys/cdefs.h> 43179595Sbenno__FBSDID("$FreeBSD$"); 44179595Sbenno 45179595Sbenno#include <sys/param.h> 46179595Sbenno#include <sys/systm.h> 47179595Sbenno#include <sys/bus.h> 48179595Sbenno#include <sys/kernel.h> 49179595Sbenno#include <sys/malloc.h> 50179595Sbenno 51179595Sbenno#include <machine/bus.h> 52179595Sbenno 53179595Sbenno#include <arm/xscale/pxa/pxareg.h> 54179595Sbenno#include <arm/xscale/pxa/pxavar.h> 55179595Sbenno 56227293Sedstatic MALLOC_DEFINE(M_PXATAG, "PXA bus_space tags", "Bus_space tags for PXA"); 57179595Sbenno 58179595Sbenno/* Prototypes for all the bus_space structure functions */ 59179595Sbennobs_protos(generic); 60179595Sbennobs_protos(generic_armv4); 61179595Sbennobs_protos(pxa); 62179595Sbenno 63179595Sbenno/* 64179595Sbenno * The obio bus space tag. This is constant for all instances, so 65179595Sbenno * we never have to explicitly "create" it. 66179595Sbenno */ 67179595Sbennostruct bus_space _base_tag = { 68179595Sbenno /* cookie */ 69179595Sbenno (void *) 0, 70179595Sbenno 71179595Sbenno /* mapping/unmapping */ 72179700Skevlo generic_bs_map, 73179700Skevlo generic_bs_unmap, 74179700Skevlo generic_bs_subregion, 75179595Sbenno 76179595Sbenno /* allocation/deallocation */ 77179700Skevlo generic_bs_alloc, 78179700Skevlo generic_bs_free, 79179595Sbenno 80179595Sbenno /* barrier */ 81179700Skevlo generic_bs_barrier, 82179595Sbenno 83179595Sbenno /* read (single) */ 84179595Sbenno pxa_bs_r_1, 85179595Sbenno pxa_bs_r_2, 86179595Sbenno pxa_bs_r_4, 87179595Sbenno NULL, 88179595Sbenno 89179595Sbenno /* read multiple */ 90179595Sbenno pxa_bs_rm_1, 91179595Sbenno pxa_bs_rm_2, 92179595Sbenno NULL, 93179595Sbenno NULL, 94179595Sbenno 95179595Sbenno /* read region */ 96179595Sbenno pxa_bs_rr_1, 97179595Sbenno NULL, 98179595Sbenno NULL, 99179595Sbenno NULL, 100179595Sbenno 101179595Sbenno /* write (single) */ 102179595Sbenno pxa_bs_w_1, 103179595Sbenno pxa_bs_w_2, 104179595Sbenno pxa_bs_w_4, 105179595Sbenno NULL, 106179595Sbenno 107179595Sbenno /* write multiple */ 108179595Sbenno pxa_bs_wm_1, 109179595Sbenno pxa_bs_wm_2, 110179595Sbenno NULL, 111179595Sbenno NULL, 112179595Sbenno 113179595Sbenno /* write region */ 114179595Sbenno NULL, 115179595Sbenno NULL, 116179595Sbenno NULL, 117179595Sbenno NULL, 118179595Sbenno 119179595Sbenno /* set multiple */ 120179595Sbenno NULL, 121179595Sbenno NULL, 122179595Sbenno NULL, 123179595Sbenno NULL, 124179595Sbenno 125179595Sbenno /* set region */ 126179595Sbenno NULL, 127179595Sbenno NULL, 128179595Sbenno NULL, 129179595Sbenno NULL, 130179595Sbenno 131179595Sbenno /* copy */ 132179595Sbenno NULL, 133179595Sbenno NULL, 134179595Sbenno NULL, 135179595Sbenno NULL, 136179595Sbenno}; 137179595Sbenno 138179595Sbennostatic struct bus_space _obio_tag; 139179595Sbenno 140179595Sbennobus_space_tag_t base_tag = &_base_tag; 141179595Sbennobus_space_tag_t obio_tag = NULL; 142179595Sbenno 143179595Sbennovoid 144179595Sbennopxa_obio_tag_init() 145179595Sbenno{ 146179595Sbenno 147179595Sbenno bcopy(&_base_tag, &_obio_tag, sizeof(struct bus_space)); 148179595Sbenno _obio_tag.bs_cookie = (void *)PXA2X0_PERIPH_OFFSET; 149179595Sbenno obio_tag = &_obio_tag; 150179595Sbenno} 151179595Sbenno 152179595Sbennobus_space_tag_t 153179595Sbennopxa_bus_tag_alloc(bus_addr_t offset) 154179595Sbenno{ 155179595Sbenno struct bus_space *tag; 156179595Sbenno 157179595Sbenno tag = (struct bus_space *)malloc(sizeof(struct bus_space), M_PXATAG, 158179595Sbenno M_WAITOK); 159179595Sbenno if (tag == NULL) { 160179595Sbenno return (NULL); 161179595Sbenno } 162179595Sbenno 163179595Sbenno bcopy(&_base_tag, tag, sizeof(struct bus_space)); 164179595Sbenno tag->bs_cookie = (void *)offset; 165179595Sbenno 166179595Sbenno return ((bus_space_tag_t)tag); 167179595Sbenno} 168179595Sbenno 169179595Sbenno 170179595Sbenno#define READ_SINGLE(type, proto, base) \ 171179595Sbenno type \ 172179595Sbenno proto(void *cookie, bus_space_handle_t bsh, bus_size_t offset) \ 173179595Sbenno { \ 174179595Sbenno bus_addr_t tag_offset; \ 175179595Sbenno type value; \ 176179595Sbenno tag_offset = (bus_addr_t)cookie; \ 177179595Sbenno value = base(NULL, bsh + tag_offset, offset); \ 178179595Sbenno return (value); \ 179179595Sbenno } 180179595Sbenno 181179595SbennoREAD_SINGLE(u_int8_t, pxa_bs_r_1, generic_bs_r_1) 182179595SbennoREAD_SINGLE(u_int16_t, pxa_bs_r_2, generic_armv4_bs_r_2) 183179595SbennoREAD_SINGLE(u_int32_t, pxa_bs_r_4, generic_bs_r_4) 184179595Sbenno 185179595Sbenno#undef READ_SINGLE 186179595Sbenno 187179595Sbenno#define WRITE_SINGLE(type, proto, base) \ 188179595Sbenno void \ 189179595Sbenno proto(void *cookie, bus_space_handle_t bsh, bus_size_t offset, \ 190179595Sbenno type value) \ 191179595Sbenno { \ 192179595Sbenno bus_addr_t tag_offset; \ 193179595Sbenno tag_offset = (bus_addr_t)cookie; \ 194179595Sbenno base(NULL, bsh + tag_offset, offset, value); \ 195179595Sbenno } 196179595Sbenno 197179595SbennoWRITE_SINGLE(u_int8_t, pxa_bs_w_1, generic_bs_w_1) 198179595SbennoWRITE_SINGLE(u_int16_t, pxa_bs_w_2, generic_armv4_bs_w_2) 199179595SbennoWRITE_SINGLE(u_int32_t, pxa_bs_w_4, generic_bs_w_4) 200179595Sbenno 201179595Sbenno#undef WRITE_SINGLE 202179595Sbenno 203179595Sbenno#define READ_MULTI(type, proto, base) \ 204179595Sbenno void \ 205179595Sbenno proto(void *cookie, bus_space_handle_t bsh, bus_size_t offset, \ 206179595Sbenno type *dest, bus_size_t count) \ 207179595Sbenno { \ 208179595Sbenno bus_addr_t tag_offset; \ 209179595Sbenno tag_offset = (bus_addr_t)cookie; \ 210179595Sbenno base(NULL, bsh + tag_offset, offset, dest, count); \ 211179595Sbenno } 212179595Sbenno 213179595SbennoREAD_MULTI(u_int8_t, pxa_bs_rm_1, generic_bs_rm_1) 214179595SbennoREAD_MULTI(u_int16_t, pxa_bs_rm_2, generic_armv4_bs_rm_2) 215179595Sbenno 216179595SbennoREAD_MULTI(u_int8_t, pxa_bs_rr_1, generic_bs_rr_1) 217179595Sbenno 218179595Sbenno#undef READ_MULTI 219179595Sbenno 220179595Sbenno#define WRITE_MULTI(type, proto, base) \ 221179595Sbenno void \ 222179595Sbenno proto(void *cookie, bus_space_handle_t bsh, bus_size_t offset, \ 223179595Sbenno const type *src, bus_size_t count) \ 224179595Sbenno { \ 225179595Sbenno bus_addr_t tag_offset; \ 226179595Sbenno tag_offset = (bus_addr_t)cookie; \ 227179595Sbenno base(NULL, bsh + tag_offset, offset, src, count); \ 228179595Sbenno } 229179595Sbenno 230179595SbennoWRITE_MULTI(u_int8_t, pxa_bs_wm_1, generic_bs_wm_1) 231179595SbennoWRITE_MULTI(u_int16_t, pxa_bs_wm_2, generic_armv4_bs_wm_2) 232179595Sbenno 233179595Sbenno#undef WRITE_MULTI 234