09
     ˆ0_’I|¥‰ÓMjqØ‚¦ð¬÷ÅÄ     ˆÀÂƒsÅÄ     # SPDX-License-Identifier: GPL-2.0
HOSTARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
                                  -e s/sun4u/sparc/ -e s/sparc64/sparc/ \
                                  -e /arm64/!s/arm.*/arm/ -e s/sa110/arm/ \
                                  -e s/s390x/s390/ -e s/parisc64/parisc/ \
                                  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
                                  -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )

ifndef ARCH
ARCH := $(HOSTARCH)
endif

SRCARCH := $(ARCH)

# Additional ARCH settings for x86
ifeq ($(ARCH),i386)
        SRCARCH := x86
endif
ifeq ($(ARCH),x86_64)
        SRCARCH := x86
endif

# Additional ARCH settings for sparc
ifeq ($(ARCH),sparc32)
       SRCARCH := sparc
endif
ifeq ($(ARCH),sparc64)
       SRCARCH := sparc
endif

# Additional ARCH settings for sh
ifeq ($(ARCH),sh64)
       SRCARCH := sh
endif

LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
ifeq ($(LP64), 1)
  IS_64_BIT := 1
else
  IS_64_BIT := 0
endif
     ˆÀÂ„Œ¼×ÁÅÄ ?÷     /* SPDX-License-Identifier: BSD-3-Clause
 * Copyright 2016-2018 NXP
 * Copyright (c) 2018-2019, Vladimir Oltean <olteanv@gmail.com>
 */
#ifndef _LINUX_PACKING_H
#define _LINUX_PACKING_H

#include <linux/types.h>
#include <linux/bitops.h>

#define GEN_PACKED_FIELD_STRUCT(__type) \
	struct packed_field_ ## __type { \
		__type startbit; \
		__type endbit; \
		__type offset; \
		__type size; \
	}

/* struct packed_field_u8. Use with bit offsets < 256, buffers < 32B and
 * unpacked structures < 256B.
 */
GEN_PACKED_FIELD_STRUCT(u8);

/* struct packed_field_u16. Use with bit offsets < 65536, buffers < 8KB and
 * unpacked structures < 64KB.
 */
GEN_PACKED_FIELD_STRUCT(u16);

#define PACKED_FIELD(start, end, struct_name, struct_field) \
{ \
	(start), \
	(end), \
	offsetof(struct_name, struct_field), \
	sizeof_field(struct_name, struct_field), \
}

#define CHECK_PACKED_FIELD_OVERLAP(fields, index1, index2) ({ \
	typeof(&(fields)[0]) __f = (fields); \
	typeof(__f[0]) _f1 = __f[index1]; typeof(__f[0]) _f2 = __f[index2]; \
	const bool _ascending = __f[0].startbit < __f[1].startbit; \
	BUILD_BUG_ON_MSG(_ascending && _f1.startbit >= _f2.startbit, \
			 __stringify(fields) " field " __stringify(index2) \
			 " breaks ascending order"); \
	BUILD_BUG_ON_MSG(!_ascending && _f1.startbit <= _f2.startbit, \
			 __stringify(fields) " field " __stringify(index2) \
			 " breaks descending order"); \
	BUILD_BUG_ON_MSG(max(_f1.endbit, _f2.endbit) <= \
			 min(_f1.startbit, _f2.startbit), \
			 __stringify(fields) " field " __stringify(index2) \
			 " overlaps with previous field"); \
})

#define CHECK_PACKED_FIELD(fields, index) ({ \
	typeof(&(fields)[0]) _f = (fields); \
	typeof(_f[0]) __f = _f[index]; \
	BUILD_BUG_ON_MSG(__f.startbit < __f.endbit, \
			 __stringify(fields) " field " __stringify(index) \
			 " start bit must not be smaller than end bit"); \
	BUILD_BUG_ON_MSG(__f.size != 1 && __f.size != 2 && \
			 __f.size != 4 && __f.size != 8, \
			 __stringify(fields) " field " __stringify(index) \
			" has unsupported unpacked storage size"); \
	BUILD_BUG_ON_MSG(__f.startbit - __f.endbit >= BITS_PER_BYTE * __f.size, \
			 __stringify(fields) " field " __stringify(index) \
			 " exceeds unpacked storage size"); \
	__builtin_choose_expr(index != 0, \
			      CHECK_PACKED_FIELD_OVERLAP(fields, index - 1, index), \
			      1); \
})

/* Note that the packed fields may be either in ascending or descending order.
 * Thus, we must check that both the first and last field wit within the
 * packed buffer size.
 */
#define CHECK_PACKED_FIELDS_SIZE(fields, pbuflen) ({ \
	typeof(&(fields)[0]) _f = (fields); \
	typeof(pbuflen) _len = (pbuflen); \
	const size_t num_fields = ARRAY_SIZE(fields); \
	BUILD_BUG_ON_MSG(!__builtin_constant_p(_len), \
			 __stringify(fields) " pbuflen " __stringify(pbuflen) \
			 " must be a compile time constant"); \
	BUILD_BUG_ON_MSG(_f[0].startbit >= BITS_PER_BYTE * _len, \
			 __stringify(fields) " first field e