Carl-Daniel Hailfinger | 5d5c072 | 2009-12-14 03:32:24 +0000 | [diff] [blame] | 1 | /* |
| 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 Hermann | 4395970 | 2010-03-13 17:28:29 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* |
Carl-Daniel Hailfinger | 5d5c072 | 2009-12-14 03:32:24 +0000 | [diff] [blame] | 17 | * 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 Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 23 | #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) \ |
| 49 | static inline uint##bits##_t cpu_to_le##bits(uint##bits##_t val) \ |
| 50 | { \ |
| 51 | return ___constant_swab##bits(val); \ |
| 52 | } |
| 53 | |
| 54 | cpu_to_le(8) |
| 55 | cpu_to_le(16) |
| 56 | cpu_to_le(32) |
| 57 | cpu_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) \ |
| 67 | static inline uint##bits##_t cpu_to_be##bits(uint##bits##_t val) \ |
| 68 | { \ |
| 69 | return ___constant_swab##bits(val); \ |
| 70 | } |
| 71 | |
| 72 | cpu_to_be(8) |
| 73 | cpu_to_be(16) |
| 74 | cpu_to_be(32) |
| 75 | cpu_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 Tauner | b0eee9b | 2015-01-10 09:32:50 +0000 | [diff] [blame] | 82 | #endif /* __FLASHROM_BIG_ENDIAN__ / __FLASHROM_LITTLE_ENDIAN__ */ |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 83 | |
| 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 Hailfinger | 5d5c072 | 2009-12-14 03:32:24 +0000 | [diff] [blame] | 93 | #endif /* !__HWACCESS_H__ */ |