pxa_space.c revision 277467
1132718Skan/*	$NetBSD: obio_space.c,v 1.6 2003/07/15 00:25:05 lukem Exp $	*/
2161651Skan
3132718Skan/*-
4132718Skan * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5132718Skan * All rights reserved.
6132718Skan *
7132718Skan * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8132718Skan *
9132718Skan * Redistribution and use in source and binary forms, with or without
10132718Skan * modification, are permitted provided that the following conditions
11132718Skan * are met:
12132718Skan * 1. Redistributions of source code must retain the above copyright
13132718Skan *    notice, this list of conditions and the following disclaimer.
14132718Skan * 2. Redistributions in binary form must reproduce the above copyright
15132718Skan *    notice, this list of conditions and the following disclaimer in the
16132718Skan *    documentation and/or other materials provided with the distribution.
17132718Skan * 3. All advertising materials mentioning features or use of this software
18132718Skan *    must display the following acknowledgement:
19132718Skan *	This product includes software developed for the NetBSD Project by
20132718Skan *	Wasabi Systems, Inc.
21132718Skan * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22132718Skan *    or promote products derived from this software without specific prior
23132718Skan *    written permission.
24132718Skan *
25132718Skan * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26132718Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27132718Skan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28132718Skan * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29132718Skan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30132718Skan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31132718Skan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32132718Skan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33132718Skan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34132718Skan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35132718Skan * POSSIBILITY OF SUCH DAMAGE.
36132718Skan */
37132718Skan
38132718Skan/*
39132718Skan * bus_space functions for PXA devices
40132718Skan */
41132718Skan
42132718Skan#include <sys/cdefs.h>
43132718Skan__FBSDID("$FreeBSD: head/sys/arm/xscale/pxa/pxa_space.c 277467 2015-01-21 02:56:13Z ian $");
44132718Skan
45132718Skan#include <sys/param.h>
46132718Skan#include <sys/systm.h>
47132718Skan#include <sys/bus.h>
48132718Skan#include <sys/kernel.h>
49132718Skan#include <sys/malloc.h>
50132718Skan
51132718Skan#include <machine/bus.h>
52132718Skan
53132718Skan#include <arm/xscale/pxa/pxareg.h>
54132718Skan#include <arm/xscale/pxa/pxavar.h>
55132718Skan
56132718Skanstatic MALLOC_DEFINE(M_PXATAG, "PXA bus_space tags", "Bus_space tags for PXA");
57132718Skan
58132718Skan/* Prototypes for all the bus_space structure functions */
59132718Skanbs_protos(generic);
60132718Skanbs_protos(pxa);
61132718Skan
62132718Skan/*
63132718Skan * The obio bus space tag.  This is constant for all instances, so
64132718Skan * we never have to explicitly "create" it.
65132718Skan */
66132718Skanstruct bus_space _base_tag = {
67132718Skan	/* cookie */
68132718Skan	(void *) 0,
69132718Skan
70132718Skan	/* mapping/unmapping */
71132718Skan	generic_bs_map,
72132718Skan	generic_bs_unmap,
73132718Skan	generic_bs_subregion,
74132718Skan
75132718Skan	/* allocation/deallocation */
76132718Skan	generic_bs_alloc,
77132718Skan	generic_bs_free,
78132718Skan
79132718Skan	/* barrier */
80132718Skan	generic_bs_barrier,
81132718Skan
82132718Skan	/* read (single) */
83132718Skan	pxa_bs_r_1,
84132718Skan	pxa_bs_r_2,
85132718Skan	pxa_bs_r_4,
86132718Skan	NULL,
87132718Skan
88132718Skan	/* read multiple */
89132718Skan	pxa_bs_rm_1,
90132718Skan	pxa_bs_rm_2,
91132718Skan	NULL,
92132718Skan	NULL,
93132718Skan
94132718Skan	/* read region */
95132718Skan	pxa_bs_rr_1,
96132718Skan	NULL,
97132718Skan	NULL,
98132718Skan	NULL,
99132718Skan
100132718Skan	/* write (single) */
101132718Skan	pxa_bs_w_1,
102132718Skan	pxa_bs_w_2,
103132718Skan	pxa_bs_w_4,
104132718Skan	NULL,
105132718Skan
106132718Skan	/* write multiple */
107132718Skan	pxa_bs_wm_1,
108132718Skan	pxa_bs_wm_2,
109132718Skan	NULL,
110132718Skan	NULL,
111132718Skan
112132718Skan	/* write region */
113132718Skan	NULL,
114132718Skan	NULL,
115132718Skan	NULL,
116132718Skan	NULL,
117132718Skan
118132718Skan	/* set multiple */
119132718Skan	NULL,
120132718Skan	NULL,
121161651Skan	NULL,
122132718Skan	NULL,
123132718Skan
124132718Skan	/* set region */
125132718Skan	NULL,
126132718Skan	NULL,
127132718Skan	NULL,
128132718Skan	NULL,
129132718Skan
130132718Skan	/* copy */
131132718Skan	NULL,
132132718Skan	NULL,
133132718Skan	NULL,
134132718Skan	NULL,
135132718Skan};
136132718Skan
137132718Skanstatic struct bus_space	_obio_tag;
138132718Skan
139132718Skanbus_space_tag_t		base_tag = &_base_tag;
140132718Skanbus_space_tag_t		obio_tag = NULL;
141132718Skan
142132718Skanvoid
143132718Skanpxa_obio_tag_init()
144132718Skan{
145132718Skan
146132718Skan	bcopy(&_base_tag, &_obio_tag, sizeof(struct bus_space));
147132718Skan	_obio_tag.bs_privdata = (void *)PXA2X0_PERIPH_OFFSET;
148132718Skan	obio_tag = &_obio_tag;
149132718Skan}
150132718Skan
151132718Skanbus_space_tag_t
152132718Skanpxa_bus_tag_alloc(bus_addr_t offset)
153132718Skan{
154132718Skan	struct	bus_space *tag;
155132718Skan
156132718Skan	tag = (struct bus_space *)malloc(sizeof(struct bus_space), M_PXATAG,
157132718Skan	    M_WAITOK);
158132718Skan	if (tag == NULL) {
159132718Skan		return (NULL);
160132718Skan	}
161132718Skan
162132718Skan	bcopy(&_base_tag, tag, sizeof(struct bus_space));
163132718Skan	tag->bs_privdata = (void *)offset;
164132718Skan
165132718Skan	return ((bus_space_tag_t)tag);
166132718Skan}
167132718Skan
168132718Skan
169132718Skan#define	READ_SINGLE(type, proto, base)					\
170132718Skan	type								\
171132718Skan	proto(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset)	\
172132718Skan	{								\
173132718Skan		bus_addr_t	tag_offset;				\
174132718Skan		type		value;					\
175132718Skan		tag_offset = (bus_addr_t)tag->bs_privdata;		\
176132718Skan		value = base(NULL, bsh + tag_offset, offset);		\
177132718Skan		return (value);						\
178132718Skan	}
179132718Skan
180132718SkanREAD_SINGLE(u_int8_t,  pxa_bs_r_1, generic_bs_r_1)
181132718SkanREAD_SINGLE(u_int16_t, pxa_bs_r_2, generic_bs_r_2)
182132718SkanREAD_SINGLE(u_int32_t, pxa_bs_r_4, generic_bs_r_4)
183132718Skan
184132718Skan#undef READ_SINGLE
185132718Skan
186132718Skan#define	WRITE_SINGLE(type, proto, base)					\
187132718Skan	void								\
188132718Skan	proto(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset,	\
189132718Skan	    type value)							\
190132718Skan	{								\
191132718Skan		bus_addr_t	tag_offset;				\
192132718Skan		tag_offset = (bus_addr_t)tag->bs_privdata;		\
193132718Skan		base(NULL, bsh + tag_offset, offset, value);		\
194132718Skan	}
195132718Skan
196132718SkanWRITE_SINGLE(u_int8_t,  pxa_bs_w_1, generic_bs_w_1)
197132718SkanWRITE_SINGLE(u_int16_t, pxa_bs_w_2, generic_bs_w_2)
198132718SkanWRITE_SINGLE(u_int32_t, pxa_bs_w_4, generic_bs_w_4)
199132718Skan
200132718Skan#undef WRITE_SINGLE
201132718Skan
202132718Skan#define	READ_MULTI(type, proto, base)					\
203132718Skan	void								\
204132718Skan	proto(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset,	\
205132718Skan	    type *dest, bus_size_t count)				\
206132718Skan	{								\
207132718Skan		bus_addr_t	tag_offset;				\
208132718Skan		tag_offset = (bus_addr_t)tag->bs_privdata;		\
209132718Skan		base(NULL, bsh + tag_offset, offset, dest, count);	\
210132718Skan	}
211132718Skan
212132718SkanREAD_MULTI(u_int8_t,  pxa_bs_rm_1, generic_bs_rm_1)
213132718SkanREAD_MULTI(u_int16_t, pxa_bs_rm_2, generic_bs_rm_2)
214132718Skan
215132718SkanREAD_MULTI(u_int8_t,  pxa_bs_rr_1, generic_bs_rr_1)
216132718Skan
217132718Skan#undef READ_MULTI
218132718Skan
219132718Skan#define	WRITE_MULTI(type, proto, base)					\
220132718Skan	void								\
221132718Skan	proto(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset,	\
222132718Skan	    const type *src, bus_size_t count)				\
223132718Skan	{								\
224132718Skan		bus_addr_t	tag_offset;				\
225132718Skan		tag_offset = (bus_addr_t)tag->bs_privdata;		\
226132718Skan		base(NULL, bsh + tag_offset, offset, src, count);	\
227132718Skan	}
228132718Skan
229132718SkanWRITE_MULTI(u_int8_t,  pxa_bs_wm_1, generic_bs_wm_1)
230132718SkanWRITE_MULTI(u_int16_t, pxa_bs_wm_2, generic_bs_wm_2)
231132718Skan
232132718Skan#undef WRITE_MULTI
233132718Skan