xref: /optee_os/core/include/io.h (revision b01047730e77127c23a36591643eeb8bb0487d68)
1*b0104773SPascal Brand /*
2*b0104773SPascal Brand  * Copyright (c) 2014, Linaro Limited
3*b0104773SPascal Brand  * All rights reserved.
4*b0104773SPascal Brand  *
5*b0104773SPascal Brand  * Redistribution and use in source and binary forms, with or without
6*b0104773SPascal Brand  * modification, are permitted provided that the following conditions are met:
7*b0104773SPascal Brand  *
8*b0104773SPascal Brand  * 1. Redistributions of source code must retain the above copyright notice,
9*b0104773SPascal Brand  * this list of conditions and the following disclaimer.
10*b0104773SPascal Brand  *
11*b0104773SPascal Brand  * 2. Redistributions in binary form must reproduce the above copyright notice,
12*b0104773SPascal Brand  * this list of conditions and the following disclaimer in the documentation
13*b0104773SPascal Brand  * and/or other materials provided with the distribution.
14*b0104773SPascal Brand  *
15*b0104773SPascal Brand  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16*b0104773SPascal Brand  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*b0104773SPascal Brand  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*b0104773SPascal Brand  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19*b0104773SPascal Brand  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20*b0104773SPascal Brand  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21*b0104773SPascal Brand  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22*b0104773SPascal Brand  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23*b0104773SPascal Brand  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24*b0104773SPascal Brand  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25*b0104773SPascal Brand  * POSSIBILITY OF SUCH DAMAGE.
26*b0104773SPascal Brand  */
27*b0104773SPascal Brand #ifndef IO_H
28*b0104773SPascal Brand #define IO_H
29*b0104773SPascal Brand 
30*b0104773SPascal Brand static inline void write8(uint8_t val, vaddr_t addr)
31*b0104773SPascal Brand {
32*b0104773SPascal Brand 	*(volatile uint8_t *)addr = val;
33*b0104773SPascal Brand }
34*b0104773SPascal Brand 
35*b0104773SPascal Brand static inline void write16(uint16_t val, vaddr_t addr)
36*b0104773SPascal Brand {
37*b0104773SPascal Brand 	*(volatile uint16_t *)addr = val;
38*b0104773SPascal Brand }
39*b0104773SPascal Brand 
40*b0104773SPascal Brand static inline void write32(uint32_t val, vaddr_t addr)
41*b0104773SPascal Brand {
42*b0104773SPascal Brand 	*(volatile uint32_t *)addr = val;
43*b0104773SPascal Brand }
44*b0104773SPascal Brand 
45*b0104773SPascal Brand static inline uint8_t read8(vaddr_t addr)
46*b0104773SPascal Brand {
47*b0104773SPascal Brand 	return *(volatile uint8_t *)addr;
48*b0104773SPascal Brand }
49*b0104773SPascal Brand 
50*b0104773SPascal Brand static inline uint16_t read16(vaddr_t addr)
51*b0104773SPascal Brand {
52*b0104773SPascal Brand 	return *(volatile uint16_t *)addr;
53*b0104773SPascal Brand }
54*b0104773SPascal Brand 
55*b0104773SPascal Brand static inline uint32_t read32(vaddr_t addr)
56*b0104773SPascal Brand {
57*b0104773SPascal Brand 	return *(volatile uint32_t *)addr;
58*b0104773SPascal Brand }
59*b0104773SPascal Brand 
60*b0104773SPascal Brand #endif /*IO_H*/
61