tegra: Move pinmux enum constants from tegra/pinmux.h to soc-specific pinmux.h
[coreboot.git] / src / include / endian.h
blobd9199b4f95dbfb79e882e7ee71b1ac6032e610a0
1 /*
2 * Copyright (C) 2013 The Chromium OS Authors. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but without any warranty; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc.
19 #ifndef _ENDIAN_H_
20 #define _ENDIAN_H_
22 #include <arch/byteorder.h>
23 #include <stdint.h>
24 #include <swab.h>
26 #if defined(__LITTLE_ENDIAN)
27 #define cpu_to_le64(x) ((uint64_t)(x))
28 #define le64_to_cpu(x) ((uint64_t)(x))
29 #define cpu_to_le32(x) ((uint32_t)(x))
30 #define le32_to_cpu(x) ((uint32_t)(x))
31 #define cpu_to_le16(x) ((uint16_t)(x))
32 #define le16_to_cpu(x) ((uint16_t)(x))
33 #define cpu_to_be64(x) swab64(x)
34 #define be64_to_cpu(x) swab64(x)
35 #define cpu_to_be32(x) swab32(x)
36 #define be32_to_cpu(x) swab32(x)
37 #define cpu_to_be16(x) swab16(x)
38 #define be16_to_cpu(x) swab16(x)
39 #elif defined(__BIG_ENDIAN)
40 #define cpu_to_le64(x) swab64(x)
41 #define le64_to_cpu(x) swab64(x)
42 #define cpu_to_le32(x) swab32(x)
43 #define le32_to_cpu(x) swab32(x)
44 #define cpu_to_le16(x) swab16(x)
45 #define le16_to_cpu(x) swab16(x)
46 #define cpu_to_be64(x) ((uint64_t)(x))
47 #define be64_to_cpu(x) ((uint64_t)(x))
48 #define cpu_to_be32(x) ((uint32_t)(x))
49 #define be32_to_cpu(x) ((uint32_t)(x))
50 #define cpu_to_be16(x) ((uint16_t)(x))
51 #define be16_to_cpu(x) ((uint16_t)(x))
52 #else
53 #error "<arch/byteorder.h> must #define __LITTLE_ENDIAN or __BIG_ENDIAN"
54 #endif
56 #define ntohll(x) be64_to_cpu(x)
57 #define htonll(x) cpu_to_be64(x)
58 #define ntohl(x) be32_to_cpu(x)
59 #define htonl(x) cpu_to_be32(x)
61 #define __clrsetbits(endian, bits, addr, clear, set) \
62 write##bits(addr, cpu_to_##endian##bits((endian##bits##_to_cpu( \
63 read##bits(addr)) & ~((uint##bits##_t)(clear))) | (set)))
65 #define clrbits_le64(addr, clear) __clrsetbits(le, 64, addr, clear, 0)
66 #define clrbits_be64(addr, clear) __clrsetbits(be, 64, addr, clear, 0)
67 #define clrbits_le32(addr, clear) __clrsetbits(le, 32, addr, clear, 0)
68 #define clrbits_be32(addr, clear) __clrsetbits(be, 32, addr, clear, 0)
69 #define clrbits_le16(addr, clear) __clrsetbits(le, 16, addr, clear, 0)
70 #define clrbits_be16(addr, clear) __clrsetbits(be, 16, addr, clear, 0)
72 #define setbits_le64(addr, set) __clrsetbits(le, 64, addr, 0, set)
73 #define setbits_be64(addr, set) __clrsetbits(be, 64, addr, 0, set)
74 #define setbits_le32(addr, set) __clrsetbits(le, 32, addr, 0, set)
75 #define setbits_be32(addr, set) __clrsetbits(be, 32, addr, 0, set)
76 #define setbits_le16(addr, set) __clrsetbits(le, 16, addr, 0, set)
77 #define setbits_be16(addr, set) __clrsetbits(be, 16, addr, 0, set)
79 #define clrsetbits_le64(addr, clear, set) __clrsetbits(le, 64, addr, clear, set)
80 #define clrsetbits_be64(addr, clear, set) __clrsetbits(be, 64, addr, clear, set)
81 #define clrsetbits_le32(addr, clear, set) __clrsetbits(le, 32, addr, clear, set)
82 #define clrsetbits_be32(addr, clear, set) __clrsetbits(be, 32, addr, clear, set)
83 #define clrsetbits_le16(addr, clear, set) __clrsetbits(le, 16, addr, clear, set)
84 #define clrsetbits_be16(addr, clear, set) __clrsetbits(be, 16, addr, clear, set)
86 #define clrsetbits_8(addr, clear, set) \
87 write8(addr, (read8(addr) & ~(clear)) | (set))
88 #define clrbits_8(addr, clear) clrsetbits_8(addr, clear, 0)
89 #define setbits_8(addr, set) setbits_8(addr, 0, set)
91 #endif