18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _PPC_BOOT_SWAB_H_
38c2ecf20Sopenharmony_ci#define _PPC_BOOT_SWAB_H_
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_cistatic inline u16 swab16(u16 x)
68c2ecf20Sopenharmony_ci{
78c2ecf20Sopenharmony_ci	return  ((x & (u16)0x00ffU) << 8) |
88c2ecf20Sopenharmony_ci		((x & (u16)0xff00U) >> 8);
98c2ecf20Sopenharmony_ci}
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistatic inline u32 swab32(u32 x)
128c2ecf20Sopenharmony_ci{
138c2ecf20Sopenharmony_ci	return  ((x & (u32)0x000000ffUL) << 24) |
148c2ecf20Sopenharmony_ci		((x & (u32)0x0000ff00UL) <<  8) |
158c2ecf20Sopenharmony_ci		((x & (u32)0x00ff0000UL) >>  8) |
168c2ecf20Sopenharmony_ci		((x & (u32)0xff000000UL) >> 24);
178c2ecf20Sopenharmony_ci}
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistatic inline u64 swab64(u64 x)
208c2ecf20Sopenharmony_ci{
218c2ecf20Sopenharmony_ci	return  (u64)((x & (u64)0x00000000000000ffULL) << 56) |
228c2ecf20Sopenharmony_ci		(u64)((x & (u64)0x000000000000ff00ULL) << 40) |
238c2ecf20Sopenharmony_ci		(u64)((x & (u64)0x0000000000ff0000ULL) << 24) |
248c2ecf20Sopenharmony_ci		(u64)((x & (u64)0x00000000ff000000ULL) <<  8) |
258c2ecf20Sopenharmony_ci		(u64)((x & (u64)0x000000ff00000000ULL) >>  8) |
268c2ecf20Sopenharmony_ci		(u64)((x & (u64)0x0000ff0000000000ULL) >> 24) |
278c2ecf20Sopenharmony_ci		(u64)((x & (u64)0x00ff000000000000ULL) >> 40) |
288c2ecf20Sopenharmony_ci		(u64)((x & (u64)0xff00000000000000ULL) >> 56);
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ci#endif /* _PPC_BOOT_SWAB_H_ */
31