^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __XZ_CONFIG_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __XZ_CONFIG_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * most of this is copied from lib/xz/xz_private.h, we can't use their defines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * since the boot wrapper is not built in the same environment as the rest of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "types.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "swab.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) static inline uint32_t swab32p(void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) uint32_t *q = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) return swab32(*q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #ifdef __LITTLE_ENDIAN__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define get_le32(p) (*((uint32_t *) (p)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define cpu_to_be32(x) swab32(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static inline u32 be32_to_cpup(const u32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return swab32p((u32 *)p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define get_le32(p) swab32p(p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define cpu_to_be32(x) (x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static inline u32 be32_to_cpup(const u32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) return *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static inline uint32_t get_unaligned_be32(const void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return be32_to_cpup(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static inline void put_unaligned_be32(u32 val, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *((u32 *)p) = cpu_to_be32(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define memeq(a, b, size) (memcmp(a, b, size) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define memzero(buf, size) memset(buf, 0, size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* prevent the inclusion of the xz-preboot MM headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define DECOMPR_MM_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define memmove memmove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define XZ_EXTERN static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* xz.h needs to be included directly since we need enum xz_mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include "../../../include/linux/xz.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #undef XZ_EXTERN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #endif