Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kernel: add platform_has() infrastructure

Add a simple infrastructure for setting, resetting and querying
platform feature flags.

Flags can be either global or architecture specific.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Tested-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> # Arm64 only
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Juergen Gross <jgross@suse.com>

+60 -1
+8
MAINTAINERS
··· 15824 15824 F: Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.yaml 15825 15825 F: drivers/iio/chemical/pms7003.c 15826 15826 15827 + PLATFORM FEATURE INFRASTRUCTURE 15828 + M: Juergen Gross <jgross@suse.com> 15829 + S: Maintained 15830 + F: arch/*/include/asm/platform-feature.h 15831 + F: include/asm-generic/platform-feature.h 15832 + F: include/linux/platform-feature.h 15833 + F: kernel/platform-feature.c 15834 + 15827 15835 PLDMFW LIBRARY 15828 15836 M: Jacob Keller <jacob.e.keller@intel.com> 15829 15837 S: Maintained
+1
include/asm-generic/Kbuild
··· 44 44 mandatory-y += pci.h 45 45 mandatory-y += percpu.h 46 46 mandatory-y += pgalloc.h 47 + mandatory-y += platform-feature.h 47 48 mandatory-y += preempt.h 48 49 mandatory-y += rwonce.h 49 50 mandatory-y += sections.h
+8
include/asm-generic/platform-feature.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _ASM_GENERIC_PLATFORM_FEATURE_H 3 + #define _ASM_GENERIC_PLATFORM_FEATURE_H 4 + 5 + /* Number of arch specific feature flags. */ 6 + #define PLATFORM_ARCH_FEAT_N 0 7 + 8 + #endif /* _ASM_GENERIC_PLATFORM_FEATURE_H */
+15
include/linux/platform-feature.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _PLATFORM_FEATURE_H 3 + #define _PLATFORM_FEATURE_H 4 + 5 + #include <linux/bitops.h> 6 + #include <asm/platform-feature.h> 7 + 8 + /* The platform features are starting with the architecture specific ones. */ 9 + #define PLATFORM_FEAT_N (0 + PLATFORM_ARCH_FEAT_N) 10 + 11 + void platform_set(unsigned int feature); 12 + void platform_clear(unsigned int feature); 13 + bool platform_has(unsigned int feature); 14 + 15 + #endif /* _PLATFORM_FEATURE_H */
+1 -1
kernel/Makefile
··· 7 7 cpu.o exit.o softirq.o resource.o \ 8 8 sysctl.o capability.o ptrace.o user.o \ 9 9 signal.o sys.o umh.o workqueue.o pid.o task_work.o \ 10 - extable.o params.o \ 10 + extable.o params.o platform-feature.o \ 11 11 kthread.o sys_ni.o nsproxy.o \ 12 12 notifier.o ksysfs.o cred.o reboot.o \ 13 13 async.o range.o smpboot.o ucount.o regset.o
+27
kernel/platform-feature.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/bitops.h> 4 + #include <linux/cache.h> 5 + #include <linux/export.h> 6 + #include <linux/platform-feature.h> 7 + 8 + #define PLATFORM_FEAT_ARRAY_SZ BITS_TO_LONGS(PLATFORM_FEAT_N) 9 + static unsigned long __read_mostly platform_features[PLATFORM_FEAT_ARRAY_SZ]; 10 + 11 + void platform_set(unsigned int feature) 12 + { 13 + set_bit(feature, platform_features); 14 + } 15 + EXPORT_SYMBOL_GPL(platform_set); 16 + 17 + void platform_clear(unsigned int feature) 18 + { 19 + clear_bit(feature, platform_features); 20 + } 21 + EXPORT_SYMBOL_GPL(platform_clear); 22 + 23 + bool platform_has(unsigned int feature) 24 + { 25 + return test_bit(feature, platform_features); 26 + } 27 + EXPORT_SYMBOL_GPL(platform_has);