0402125bba76e67736e0a1a1a11da8c402e9a06c
[deb_dpdk.git] / lib / librte_eal / common / include / arch / arm / rte_io_64.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium networks Ltd. 2016.
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  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium networks nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _RTE_IO_ARM64_H_
34 #define _RTE_IO_ARM64_H_
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 #include <stdint.h>
41
42 #define RTE_OVERRIDE_IO_H
43
44 #include "generic/rte_io.h"
45 #include "rte_atomic_64.h"
46
47 static inline uint8_t __attribute__((always_inline))
48 rte_read8_relaxed(const volatile void *addr)
49 {
50         uint8_t val;
51
52         asm volatile(
53                     "ldrb %w[val], [%x[addr]]"
54                     : [val] "=r" (val)
55                     : [addr] "r" (addr));
56         return val;
57 }
58
59 static inline uint16_t __attribute__((always_inline))
60 rte_read16_relaxed(const volatile void *addr)
61 {
62         uint16_t val;
63
64         asm volatile(
65                     "ldrh %w[val], [%x[addr]]"
66                     : [val] "=r" (val)
67                     : [addr] "r" (addr));
68         return val;
69 }
70
71 static inline uint32_t __attribute__((always_inline))
72 rte_read32_relaxed(const volatile void *addr)
73 {
74         uint32_t val;
75
76         asm volatile(
77                     "ldr %w[val], [%x[addr]]"
78                     : [val] "=r" (val)
79                     : [addr] "r" (addr));
80         return val;
81 }
82
83 static inline uint64_t __attribute__((always_inline))
84 rte_read64_relaxed(const volatile void *addr)
85 {
86         uint64_t val;
87
88         asm volatile(
89                     "ldr %x[val], [%x[addr]]"
90                     : [val] "=r" (val)
91                     : [addr] "r" (addr));
92         return val;
93 }
94
95 static inline void __attribute__((always_inline))
96 rte_write8_relaxed(uint8_t val, volatile void *addr)
97 {
98         asm volatile(
99                     "strb %w[val], [%x[addr]]"
100                     :
101                     : [val] "r" (val), [addr] "r" (addr));
102 }
103
104 static inline void __attribute__((always_inline))
105 rte_write16_relaxed(uint16_t val, volatile void *addr)
106 {
107         asm volatile(
108                     "strh %w[val], [%x[addr]]"
109                     :
110                     : [val] "r" (val), [addr] "r" (addr));
111 }
112
113 static inline void __attribute__((always_inline))
114 rte_write32_relaxed(uint32_t val, volatile void *addr)
115 {
116         asm volatile(
117                     "str %w[val], [%x[addr]]"
118                     :
119                     : [val] "r" (val), [addr] "r" (addr));
120 }
121
122 static inline void __attribute__((always_inline))
123 rte_write64_relaxed(uint64_t val, volatile void *addr)
124 {
125         asm volatile(
126                     "str %x[val], [%x[addr]]"
127                     :
128                     : [val] "r" (val), [addr] "r" (addr));
129 }
130
131 static inline uint8_t __attribute__((always_inline))
132 rte_read8(const volatile void *addr)
133 {
134         uint8_t val;
135         val = rte_read8_relaxed(addr);
136         rte_io_rmb();
137         return val;
138 }
139
140 static inline uint16_t __attribute__((always_inline))
141 rte_read16(const volatile void *addr)
142 {
143         uint16_t val;
144         val = rte_read16_relaxed(addr);
145         rte_io_rmb();
146         return val;
147 }
148
149 static inline uint32_t  __attribute__((always_inline))
150 rte_read32(const volatile void *addr)
151 {
152         uint32_t val;
153         val = rte_read32_relaxed(addr);
154         rte_io_rmb();
155         return val;
156 }
157
158 static inline uint64_t __attribute__((always_inline))
159 rte_read64(const volatile void *addr)
160 {
161         uint64_t val;
162         val = rte_read64_relaxed(addr);
163         rte_io_rmb();
164         return val;
165 }
166
167 static inline void __attribute__((always_inline))
168 rte_write8(uint8_t value, volatile void *addr)
169 {
170         rte_io_wmb();
171         rte_write8_relaxed(value, addr);
172 }
173
174 static inline void __attribute__((always_inline))
175 rte_write16(uint16_t value, volatile void *addr)
176 {
177         rte_io_wmb();
178         rte_write16_relaxed(value, addr);
179 }
180
181 static inline void __attribute__((always_inline))
182 rte_write32(uint32_t value, volatile void *addr)
183 {
184         rte_io_wmb();
185         rte_write32_relaxed(value, addr);
186 }
187
188 static inline void __attribute__((always_inline))
189 rte_write64(uint64_t value, volatile void *addr)
190 {
191         rte_io_wmb();
192         rte_write64_relaxed(value, addr);
193 }
194
195 #ifdef __cplusplus
196 }
197 #endif
198
199 #endif /* _RTE_IO_ARM64_H_ */