blob: 98ca08e86189235caf06b47c3db7b19ed08eaa9d [file] [log] [blame]
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2009 Carl-Daniel Hailfinger
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Uwe Hermann43959702010-03-13 17:28:29 +000014 */
15
16/*
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +000017 * Header file for hardware access and OS abstraction. Included from flash.h.
18 */
19
20#ifndef __HWACCESS_H__
21#define __HWACCESS_H__ 1
22
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +000023#define ___constant_swab8(x) ((uint8_t) ( \
24 (((uint8_t)(x) & (uint8_t)0xffU))))
25
26#define ___constant_swab16(x) ((uint16_t) ( \
27 (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \
28 (((uint16_t)(x) & (uint16_t)0xff00U) >> 8)))
29
30#define ___constant_swab32(x) ((uint32_t) ( \
31 (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
32 (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
33 (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
34 (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
35
36#define ___constant_swab64(x) ((uint64_t) ( \
37 (((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \
38 (((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
39 (((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
40 (((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
41 (((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
42 (((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
43 (((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
44 (((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56)))
45
46#if defined (__FLASHROM_BIG_ENDIAN__)
47
48#define cpu_to_le(bits) \
49static inline uint##bits##_t cpu_to_le##bits(uint##bits##_t val) \
50{ \
51 return ___constant_swab##bits(val); \
52}
53
54cpu_to_le(8)
55cpu_to_le(16)
56cpu_to_le(32)
57cpu_to_le(64)
58
59#define cpu_to_be8
60#define cpu_to_be16
61#define cpu_to_be32
62#define cpu_to_be64
63
64#elif defined (__FLASHROM_LITTLE_ENDIAN__)
65
66#define cpu_to_be(bits) \
67static inline uint##bits##_t cpu_to_be##bits(uint##bits##_t val) \
68{ \
69 return ___constant_swab##bits(val); \
70}
71
72cpu_to_be(8)
73cpu_to_be(16)
74cpu_to_be(32)
75cpu_to_be(64)
76
77#define cpu_to_le8
78#define cpu_to_le16
79#define cpu_to_le32
80#define cpu_to_le64
81
Stefan Taunerb0eee9b2015-01-10 09:32:50 +000082#endif /* __FLASHROM_BIG_ENDIAN__ / __FLASHROM_LITTLE_ENDIAN__ */
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +000083
84#define be_to_cpu8 cpu_to_be8
85#define be_to_cpu16 cpu_to_be16
86#define be_to_cpu32 cpu_to_be32
87#define be_to_cpu64 cpu_to_be64
88#define le_to_cpu8 cpu_to_le8
89#define le_to_cpu16 cpu_to_le16
90#define le_to_cpu32 cpu_to_le32
91#define le_to_cpu64 cpu_to_le64
92
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +000093#endif /* !__HWACCESS_H__ */