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 | |
Thomas Heijligen | cce1e5b | 2021-11-02 20:33:35 +0100 | [diff] [blame] | 23 | void mmio_writeb(uint8_t val, void *addr); |
| 24 | void mmio_writew(uint16_t val, void *addr); |
| 25 | void mmio_writel(uint32_t val, void *addr); |
| 26 | uint8_t mmio_readb(const void *addr); |
| 27 | uint16_t mmio_readw(const void *addr); |
| 28 | uint32_t mmio_readl(const void *addr); |
| 29 | void mmio_readn(const void *addr, uint8_t *buf, size_t len); |
| 30 | void mmio_le_writeb(uint8_t val, void *addr); |
| 31 | void mmio_le_writew(uint16_t val, void *addr); |
| 32 | void mmio_le_writel(uint32_t val, void *addr); |
| 33 | uint8_t mmio_le_readb(const void *addr); |
| 34 | uint16_t mmio_le_readw(const void *addr); |
| 35 | uint32_t mmio_le_readl(const void *addr); |
| 36 | #define pci_mmio_writeb mmio_le_writeb |
| 37 | #define pci_mmio_writew mmio_le_writew |
| 38 | #define pci_mmio_writel mmio_le_writel |
| 39 | #define pci_mmio_readb mmio_le_readb |
| 40 | #define pci_mmio_readw mmio_le_readw |
| 41 | #define pci_mmio_readl mmio_le_readl |
| 42 | void rmmio_writeb(uint8_t val, void *addr); |
| 43 | void rmmio_writew(uint16_t val, void *addr); |
| 44 | void rmmio_writel(uint32_t val, void *addr); |
| 45 | void rmmio_le_writeb(uint8_t val, void *addr); |
| 46 | void rmmio_le_writew(uint16_t val, void *addr); |
| 47 | void rmmio_le_writel(uint32_t val, void *addr); |
| 48 | #define pci_rmmio_writeb rmmio_le_writeb |
| 49 | #define pci_rmmio_writew rmmio_le_writew |
| 50 | #define pci_rmmio_writel rmmio_le_writel |
| 51 | void rmmio_valb(void *addr); |
| 52 | void rmmio_valw(void *addr); |
| 53 | void rmmio_vall(void *addr); |
| 54 | |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 55 | #define ___constant_swab8(x) ((uint8_t) ( \ |
| 56 | (((uint8_t)(x) & (uint8_t)0xffU)))) |
| 57 | |
| 58 | #define ___constant_swab16(x) ((uint16_t) ( \ |
| 59 | (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \ |
| 60 | (((uint16_t)(x) & (uint16_t)0xff00U) >> 8))) |
| 61 | |
| 62 | #define ___constant_swab32(x) ((uint32_t) ( \ |
| 63 | (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \ |
| 64 | (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \ |
| 65 | (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \ |
| 66 | (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24))) |
| 67 | |
| 68 | #define ___constant_swab64(x) ((uint64_t) ( \ |
| 69 | (((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \ |
| 70 | (((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ |
| 71 | (((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ |
| 72 | (((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ |
| 73 | (((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ |
| 74 | (((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ |
| 75 | (((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ |
| 76 | (((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56))) |
| 77 | |
| 78 | #if defined (__FLASHROM_BIG_ENDIAN__) |
| 79 | |
| 80 | #define cpu_to_le(bits) \ |
| 81 | static inline uint##bits##_t cpu_to_le##bits(uint##bits##_t val) \ |
| 82 | { \ |
| 83 | return ___constant_swab##bits(val); \ |
| 84 | } |
| 85 | |
| 86 | cpu_to_le(8) |
| 87 | cpu_to_le(16) |
| 88 | cpu_to_le(32) |
| 89 | cpu_to_le(64) |
| 90 | |
| 91 | #define cpu_to_be8 |
| 92 | #define cpu_to_be16 |
| 93 | #define cpu_to_be32 |
| 94 | #define cpu_to_be64 |
| 95 | |
| 96 | #elif defined (__FLASHROM_LITTLE_ENDIAN__) |
| 97 | |
| 98 | #define cpu_to_be(bits) \ |
| 99 | static inline uint##bits##_t cpu_to_be##bits(uint##bits##_t val) \ |
| 100 | { \ |
| 101 | return ___constant_swab##bits(val); \ |
| 102 | } |
| 103 | |
| 104 | cpu_to_be(8) |
| 105 | cpu_to_be(16) |
| 106 | cpu_to_be(32) |
| 107 | cpu_to_be(64) |
| 108 | |
| 109 | #define cpu_to_le8 |
| 110 | #define cpu_to_le16 |
| 111 | #define cpu_to_le32 |
| 112 | #define cpu_to_le64 |
| 113 | |
Stefan Tauner | b0eee9b | 2015-01-10 09:32:50 +0000 | [diff] [blame] | 114 | #endif /* __FLASHROM_BIG_ENDIAN__ / __FLASHROM_LITTLE_ENDIAN__ */ |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 115 | |
| 116 | #define be_to_cpu8 cpu_to_be8 |
| 117 | #define be_to_cpu16 cpu_to_be16 |
| 118 | #define be_to_cpu32 cpu_to_be32 |
| 119 | #define be_to_cpu64 cpu_to_be64 |
| 120 | #define le_to_cpu8 cpu_to_le8 |
| 121 | #define le_to_cpu16 cpu_to_le16 |
| 122 | #define le_to_cpu32 cpu_to_le32 |
| 123 | #define le_to_cpu64 cpu_to_le64 |
| 124 | |
Carl-Daniel Hailfinger | 5d5c072 | 2009-12-14 03:32:24 +0000 | [diff] [blame] | 125 | #endif /* !__HWACCESS_H__ */ |