blob: d80e0e34a53bb7b8e4d146daa134f54977de8ba4 [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
Thomas Heijligencce1e5b2021-11-02 20:33:35 +010023void mmio_writeb(uint8_t val, void *addr);
24void mmio_writew(uint16_t val, void *addr);
25void mmio_writel(uint32_t val, void *addr);
26uint8_t mmio_readb(const void *addr);
27uint16_t mmio_readw(const void *addr);
28uint32_t mmio_readl(const void *addr);
29void mmio_readn(const void *addr, uint8_t *buf, size_t len);
30void mmio_le_writeb(uint8_t val, void *addr);
31void mmio_le_writew(uint16_t val, void *addr);
32void mmio_le_writel(uint32_t val, void *addr);
33uint8_t mmio_le_readb(const void *addr);
34uint16_t mmio_le_readw(const void *addr);
35uint32_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
42void rmmio_writeb(uint8_t val, void *addr);
43void rmmio_writew(uint16_t val, void *addr);
44void rmmio_writel(uint32_t val, void *addr);
45void rmmio_le_writeb(uint8_t val, void *addr);
46void rmmio_le_writew(uint16_t val, void *addr);
47void 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
51void rmmio_valb(void *addr);
52void rmmio_valw(void *addr);
53void rmmio_vall(void *addr);
54
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +000055#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) \
81static inline uint##bits##_t cpu_to_le##bits(uint##bits##_t val) \
82{ \
83 return ___constant_swab##bits(val); \
84}
85
86cpu_to_le(8)
87cpu_to_le(16)
88cpu_to_le(32)
89cpu_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) \
99static inline uint##bits##_t cpu_to_be##bits(uint##bits##_t val) \
100{ \
101 return ___constant_swab##bits(val); \
102}
103
104cpu_to_be(8)
105cpu_to_be(16)
106cpu_to_be(32)
107cpu_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 Taunerb0eee9b2015-01-10 09:32:50 +0000114#endif /* __FLASHROM_BIG_ENDIAN__ / __FLASHROM_LITTLE_ENDIAN__ */
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +0000115
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 Hailfinger5d5c0722009-12-14 03:32:24 +0000125#endif /* !__HWACCESS_H__ */