1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef NORTHBRIDGE_INTEL_COMMON_FIXED_BARS_H
4 #define NORTHBRIDGE_INTEL_COMMON_FIXED_BARS_H
6 #include <device/mmio.h>
9 _Static_assert(CONFIG_FIXED_MCHBAR_MMIO_BASE
!= 0, "MCHBAR base address is zero");
11 static __always_inline
uint8_t mchbar_read8(const uintptr_t offset
)
13 return read8p(CONFIG_FIXED_MCHBAR_MMIO_BASE
+ offset
);
16 static __always_inline
uint16_t mchbar_read16(const uintptr_t offset
)
18 return read16p(CONFIG_FIXED_MCHBAR_MMIO_BASE
+ offset
);
21 static __always_inline
uint32_t mchbar_read32(const uintptr_t offset
)
23 return read32p(CONFIG_FIXED_MCHBAR_MMIO_BASE
+ offset
);
26 static __always_inline
void mchbar_write8(const uintptr_t offset
, const uint8_t value
)
28 write8p(CONFIG_FIXED_MCHBAR_MMIO_BASE
+ offset
, value
);
31 static __always_inline
void mchbar_write16(const uintptr_t offset
, const uint16_t value
)
33 write16p(CONFIG_FIXED_MCHBAR_MMIO_BASE
+ offset
, value
);
36 static __always_inline
void mchbar_write32(const uintptr_t offset
, const uint32_t value
)
38 write32p(CONFIG_FIXED_MCHBAR_MMIO_BASE
+ offset
, value
);
41 static __always_inline
void mchbar_clrsetbits8(uintptr_t offset
, uint8_t clear
, uint8_t set
)
43 clrsetbits8((void *)((uintptr_t)CONFIG_FIXED_MCHBAR_MMIO_BASE
+ offset
), clear
, set
);
46 static __always_inline
void mchbar_clrsetbits16(uintptr_t offset
, uint16_t clear
, uint16_t set
)
48 clrsetbits16((void *)((uintptr_t)CONFIG_FIXED_MCHBAR_MMIO_BASE
+ offset
), clear
, set
);
51 static __always_inline
void mchbar_clrsetbits32(uintptr_t offset
, uint32_t clear
, uint32_t set
)
53 clrsetbits32((void *)((uintptr_t)CONFIG_FIXED_MCHBAR_MMIO_BASE
+ offset
), clear
, set
);
56 #define mchbar_setbits8(addr, set) mchbar_clrsetbits8(addr, 0, set)
57 #define mchbar_setbits16(addr, set) mchbar_clrsetbits16(addr, 0, set)
58 #define mchbar_setbits32(addr, set) mchbar_clrsetbits32(addr, 0, set)
60 #define mchbar_clrbits8(addr, clear) mchbar_clrsetbits8(addr, clear, 0)
61 #define mchbar_clrbits16(addr, clear) mchbar_clrsetbits16(addr, clear, 0)
62 #define mchbar_clrbits32(addr, clear) mchbar_clrsetbits32(addr, clear, 0)
64 _Static_assert(CONFIG_FIXED_DMIBAR_MMIO_BASE
!= 0, "DMIBAR base address is zero");
66 static __always_inline
uint8_t dmibar_read8(const uintptr_t offset
)
68 return read8p(CONFIG_FIXED_DMIBAR_MMIO_BASE
+ offset
);
71 static __always_inline
uint16_t dmibar_read16(const uintptr_t offset
)
73 return read16p(CONFIG_FIXED_DMIBAR_MMIO_BASE
+ offset
);
76 static __always_inline
uint32_t dmibar_read32(const uintptr_t offset
)
78 return read32p(CONFIG_FIXED_DMIBAR_MMIO_BASE
+ offset
);
81 static __always_inline
void dmibar_write8(const uintptr_t offset
, const uint8_t value
)
83 write8p(CONFIG_FIXED_DMIBAR_MMIO_BASE
+ offset
, value
);
86 static __always_inline
void dmibar_write16(const uintptr_t offset
, const uint16_t value
)
88 write16p(CONFIG_FIXED_DMIBAR_MMIO_BASE
+ offset
, value
);
91 static __always_inline
void dmibar_write32(const uintptr_t offset
, const uint32_t value
)
93 write32p(CONFIG_FIXED_DMIBAR_MMIO_BASE
+ offset
, value
);
96 static __always_inline
void dmibar_clrsetbits8(uintptr_t offset
, uint8_t clear
, uint8_t set
)
98 clrsetbits8((void *)((uintptr_t)CONFIG_FIXED_DMIBAR_MMIO_BASE
+ offset
), clear
, set
);
101 static __always_inline
void dmibar_clrsetbits16(uintptr_t offset
, uint16_t clear
, uint16_t set
)
103 clrsetbits16((void *)((uintptr_t)CONFIG_FIXED_DMIBAR_MMIO_BASE
+ offset
), clear
, set
);
106 static __always_inline
void dmibar_clrsetbits32(uintptr_t offset
, uint32_t clear
, uint32_t set
)
108 clrsetbits32((void *)((uintptr_t)CONFIG_FIXED_DMIBAR_MMIO_BASE
+ offset
), clear
, set
);
111 #define dmibar_setbits8(addr, set) dmibar_clrsetbits8(addr, 0, set)
112 #define dmibar_setbits16(addr, set) dmibar_clrsetbits16(addr, 0, set)
113 #define dmibar_setbits32(addr, set) dmibar_clrsetbits32(addr, 0, set)
115 #define dmibar_clrbits8(addr, clear) dmibar_clrsetbits8(addr, clear, 0)
116 #define dmibar_clrbits16(addr, clear) dmibar_clrsetbits16(addr, clear, 0)
117 #define dmibar_clrbits32(addr, clear) dmibar_clrsetbits32(addr, clear, 0)
119 _Static_assert(CONFIG_FIXED_EPBAR_MMIO_BASE
!= 0, "EPBAR base address is zero");
121 static __always_inline
uint8_t epbar_read8(const uintptr_t offset
)
123 return read8p(CONFIG_FIXED_EPBAR_MMIO_BASE
+ offset
);
126 static __always_inline
uint16_t epbar_read16(const uintptr_t offset
)
128 return read16p(CONFIG_FIXED_EPBAR_MMIO_BASE
+ offset
);
131 static __always_inline
uint32_t epbar_read32(const uintptr_t offset
)
133 return read32p(CONFIG_FIXED_EPBAR_MMIO_BASE
+ offset
);
136 static __always_inline
void epbar_write8(const uintptr_t offset
, const uint8_t value
)
138 write8p(CONFIG_FIXED_EPBAR_MMIO_BASE
+ offset
, value
);
141 static __always_inline
void epbar_write16(const uintptr_t offset
, const uint16_t value
)
143 write16p(CONFIG_FIXED_EPBAR_MMIO_BASE
+ offset
, value
);
146 static __always_inline
void epbar_write32(const uintptr_t offset
, const uint32_t value
)
148 write32p(CONFIG_FIXED_EPBAR_MMIO_BASE
+ offset
, value
);
151 static __always_inline
void epbar_clrsetbits8(uintptr_t offset
, uint8_t clear
, uint8_t set
)
153 clrsetbits8((void *)((uintptr_t)CONFIG_FIXED_EPBAR_MMIO_BASE
+ offset
), clear
, set
);
156 static __always_inline
void epbar_clrsetbits16(uintptr_t offset
, uint16_t clear
, uint16_t set
)
158 clrsetbits16((void *)((uintptr_t)CONFIG_FIXED_EPBAR_MMIO_BASE
+ offset
), clear
, set
);
161 static __always_inline
void epbar_clrsetbits32(uintptr_t offset
, uint32_t clear
, uint32_t set
)
163 clrsetbits32((void *)((uintptr_t)CONFIG_FIXED_EPBAR_MMIO_BASE
+ offset
), clear
, set
);
166 #define epbar_setbits8(addr, set) epbar_clrsetbits8(addr, 0, set)
167 #define epbar_setbits16(addr, set) epbar_clrsetbits16(addr, 0, set)
168 #define epbar_setbits32(addr, set) epbar_clrsetbits32(addr, 0, set)
170 #define epbar_clrbits8(addr, clear) epbar_clrsetbits8(addr, clear, 0)
171 #define epbar_clrbits16(addr, clear) epbar_clrsetbits16(addr, clear, 0)
172 #define epbar_clrbits32(addr, clear) epbar_clrsetbits32(addr, clear, 0)
174 #endif /* ! NORTHBRIDGE_INTEL_COMMON_FIXED_BARS_H */