Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / lib / libusb / tools.h
1 /*****************************************************************************
2  * Copyright (c) 2013 IBM Corporation
3  * All rights reserved.
4  * This program and the accompanying materials
5  * are made available under the terms of the BSD License
6  * which accompanies this distribution, and is available at
7  * http://www.opensource.org/licenses/bsd-license.php
8  *
9  * Contributors:
10  *     IBM Corporation - initial implementation
11  *****************************************************************************/
12
13 #ifndef __TOOLS_H
14 #define __TOOLS_H
15
16 #include <stdint.h>
17 #include <byteorder.h>
18 #include <cache.h>
19
20 #define PTR_U32(x)  ((uint32_t) (uint64_t) (x))
21
22 static inline uint32_t read_reg32(uint32_t *reg)
23 {
24         return bswap_32(ci_read_32(reg));
25 }
26
27 static inline void write_reg32(uint32_t *reg, uint32_t value)
28 {
29         mb();
30         ci_write_32(reg, bswap_32(value));
31 }
32
33 static inline uint8_t read_reg8(uint8_t *reg)
34 {
35         return ci_read_8(reg);
36 }
37
38 static inline void write_reg8(uint8_t *reg, uint8_t value)
39 {
40         mb();
41         ci_write_8(reg, value);
42 }
43
44 static inline uint16_t read_reg16(uint16_t *reg)
45 {
46         return bswap_16(ci_read_16(reg));
47 }
48
49 static inline void write_reg16(uint16_t *reg, uint16_t value)
50 {
51         mb();
52         ci_write_16(reg, bswap_16(value));
53 }
54
55 static inline uint64_t read_reg64(uint64_t *reg)
56 {
57         return bswap_64(ci_read_64(reg));
58 }
59
60 static inline void write_reg64(uint64_t *reg, uint64_t value)
61 {
62         mb();
63         ci_write_64(reg, bswap_64(value));
64 }
65
66 static inline uint32_t ci_read_reg(uint32_t *reg)
67 {
68         return bswap_32(ci_read_32(reg));
69 }
70
71 static inline void ci_write_reg(uint32_t *reg, uint32_t value)
72 {
73         mb();
74         ci_write_32(reg, bswap_32(value));
75 }
76
77 #endif