~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/skiboot/include/io.h

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2013-2014 IBM Corp.
 
2
 *
 
3
 * Licensed under the Apache License, Version 2.0 (the "License");
 
4
 * you may not use this file except in compliance with the License.
 
5
 * You may obtain a copy of the License at
 
6
 *
 
7
 *      http://www.apache.org/licenses/LICENSE-2.0
 
8
 *
 
9
 * Unless required by applicable law or agreed to in writing, software
 
10
 * distributed under the License is distributed on an "AS IS" BASIS,
 
11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 
12
 * implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#ifndef __IO_H
 
18
#define __IO_H
 
19
 
 
20
#ifndef __ASSEMBLY__
 
21
 
 
22
#include <compiler.h>
 
23
#include <stdint.h>
 
24
#include <processor.h>
 
25
#include <ccan/endian/endian.h>
 
26
 
 
27
/*
 
28
 * IO access functions
 
29
 *
 
30
 * __in_beXX() / __out_beXX() : non-byteswap, no barrier
 
31
 * in_beXX() / out_beXX()     : non-byteswap, barrier
 
32
 * in_leXX() / out_leXX()     : byteswap, barrier
 
33
 */
 
34
 
 
35
static inline uint8_t __in_8(const volatile uint8_t *addr)
 
36
{
 
37
        uint8_t val;
 
38
        asm volatile("lbzcix %0,0,%1" :
 
39
                     "=r"(val) : "r"(addr), "m"(*addr) : "memory");
 
40
        return val;
 
41
}
 
42
 
 
43
static inline uint8_t in_8(const volatile uint8_t *addr)
 
44
{
 
45
        sync();
 
46
        return __in_8(addr);
 
47
}
 
48
 
 
49
static inline uint16_t __in_be16(const volatile uint16_t *addr)
 
50
{
 
51
        uint16_t val;
 
52
        asm volatile("lhzcix %0,0,%1" :
 
53
                     "=r"(val) : "r"(addr), "m"(*addr) : "memory");
 
54
        return val;
 
55
}
 
56
 
 
57
static inline uint16_t in_be16(const volatile uint16_t *addr)
 
58
{
 
59
        sync();
 
60
        return __in_be16(addr);
 
61
}
 
62
 
 
63
static inline uint16_t in_le16(const volatile uint16_t *addr)
 
64
{
 
65
        return bswap_16(in_be16(addr));
 
66
}
 
67
 
 
68
static inline uint32_t __in_be32(const volatile uint32_t *addr)
 
69
{
 
70
        uint32_t val;
 
71
        asm volatile("lwzcix %0,0,%1" :
 
72
                     "=r"(val) : "r"(addr), "m"(*addr) : "memory");
 
73
        return val;
 
74
}
 
75
 
 
76
static inline uint32_t in_be32(const volatile uint32_t *addr)
 
77
{
 
78
        sync();
 
79
        return __in_be32(addr);
 
80
}
 
81
 
 
82
static inline uint32_t in_le32(const volatile uint32_t *addr)
 
83
{
 
84
        return bswap_32(in_be32(addr));
 
85
}
 
86
 
 
87
static inline uint64_t __in_be64(const volatile uint64_t *addr)
 
88
{
 
89
        uint64_t val;
 
90
        asm volatile("ldcix %0,0,%1" :
 
91
                     "=r"(val) : "r"(addr), "m"(*addr) : "memory");
 
92
        return val;
 
93
}
 
94
 
 
95
static inline uint64_t in_be64(const volatile uint64_t *addr)
 
96
{
 
97
        sync();
 
98
        return __in_be64(addr);
 
99
}
 
100
 
 
101
static inline uint64_t in_le64(const volatile uint64_t *addr)
 
102
{
 
103
        return bswap_64(in_be64(addr));
 
104
}
 
105
 
 
106
static inline void __out_8(volatile uint8_t *addr, uint8_t val)
 
107
{
 
108
        asm volatile("stbcix %0,0,%1"
 
109
                     : : "r"(val), "r"(addr), "m"(*addr) : "memory");
 
110
}
 
111
 
 
112
static inline void out_8(volatile uint8_t *addr, uint8_t val)
 
113
{
 
114
        sync();
 
115
        return __out_8(addr, val);
 
116
}
 
117
 
 
118
static inline void __out_be16(volatile uint16_t *addr, uint16_t val)
 
119
{
 
120
        asm volatile("sthcix %0,0,%1"
 
121
                     : : "r"(val), "r"(addr), "m"(*addr) : "memory");
 
122
}
 
123
 
 
124
static inline void out_be16(volatile uint16_t *addr, uint16_t val)
 
125
{
 
126
        sync();
 
127
        return __out_be16(addr, val);
 
128
}
 
129
 
 
130
static inline void out_le16(volatile uint16_t *addr, uint16_t val)
 
131
{
 
132
        out_be16(addr, bswap_16(val));
 
133
}
 
134
 
 
135
static inline void __out_be32(volatile uint32_t *addr, uint32_t val)
 
136
{
 
137
        asm volatile("stwcix %0,0,%1"
 
138
                     : : "r"(val), "r"(addr), "m"(*addr) : "memory");
 
139
}
 
140
 
 
141
static inline void out_be32(volatile uint32_t *addr, uint32_t val)
 
142
{
 
143
        sync();
 
144
        return __out_be32(addr, val);
 
145
}
 
146
 
 
147
static inline void out_le32(volatile uint32_t *addr, uint32_t val)
 
148
{
 
149
        out_be32(addr, bswap_32(val));
 
150
}
 
151
 
 
152
static inline void __out_be64(volatile uint64_t *addr, uint64_t val)
 
153
{
 
154
        asm volatile("stdcix %0,0,%1"
 
155
                     : : "r"(val), "r"(addr), "m"(*addr) : "memory");
 
156
}
 
157
 
 
158
static inline void out_be64(volatile uint64_t *addr, uint64_t val)
 
159
{
 
160
        sync();
 
161
        return __out_be64(addr, val);
 
162
}
 
163
 
 
164
static inline void out_le64(volatile uint64_t *addr, uint64_t val)
 
165
{
 
166
        out_be64(addr, bswap_64(val));
 
167
}
 
168
 
 
169
/* Assistant to macros used to access PCI config space */
 
170
#define in_le8  in_8
 
171
#define out_le8 out_8
 
172
 
 
173
#endif /* __ASSEMBLY__ */
 
174
 
 
175
#endif /* __IO_H */