Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9025d688 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Ruchi Kandoi
Browse files

cpu: add generic support for CPU feature based module autoloading



This patch adds support for advertising optional CPU features over udev
using the modalias, and for declaring compatibility with/dependency upon
such a feature in a module.

The mapping between feature numbers and actual features should be provided
by the architecture in a file called <asm/cpufeature.h> which exports the
following functions/macros:
- cpu_feature(FEAT), a preprocessor macro that maps token FEAT to a
  numeric index;
- bool cpu_have_feature(n), returning whether this CPU has support for
  feature #n;
- MAX_CPU_FEATURES, an upper bound for 'n' in the previous function.

The feature can then be enabled by setting CONFIG_GENERIC_CPU_AUTOPROBE
for the architecture.

For instance, a module that registers its module init function using

  module_cpu_feature_match(FEAT_X, module_init_function)

will be probed automatically when the CPU's support for the 'FEAT_X'
feature is advertised over udev, and will only allow the module to be
loaded by hand if the 'FEAT_X' feature is supported.

Change-Id: Icae8e3ff347235fc72a5b41279f0afdb34fb161a
Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 83d452a0
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -220,8 +220,13 @@ config GENERIC_CPU_DEVICES
	bool
	default n

config HAVE_CPU_AUTOPROBE
	def_bool ARCH_HAS_CPU_AUTOPROBE

config GENERIC_CPU_AUTOPROBE
	bool
	depends on !ARCH_HAS_CPU_AUTOPROBE
	select HAVE_CPU_AUTOPROBE

config SOC_BUS
	bool
+7 −3
Original line number Diff line number Diff line
@@ -287,6 +287,7 @@ static void cpu_device_release(struct device *dev)
	 */
}

#ifdef CONFIG_HAVE_CPU_AUTOPROBE
#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
static ssize_t print_cpu_modalias(struct device *dev,
				  struct device_attribute *attr,
@@ -309,6 +310,9 @@ static ssize_t print_cpu_modalias(struct device *dev,
	buf[n++] = '\n';
	return n;
}
#else
#define print_cpu_modalias	arch_print_cpu_modalias
#endif

static int cpu_uevent(struct device *dev, struct kobj_uevent_env *env)
{
@@ -342,7 +346,7 @@ int register_cpu(struct cpu *cpu, int num)
	cpu->dev.offline_disabled = !cpu->hotpluggable;
	cpu->dev.offline = !cpu_online(num);
	cpu->dev.of_node = of_get_cpu_node(num, NULL);
#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
#ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
	cpu->dev.bus->uevent = cpu_uevent;
#endif
	cpu->dev.groups = common_cpu_attr_groups;
@@ -366,7 +370,7 @@ struct device *get_cpu_device(unsigned cpu)
}
EXPORT_SYMBOL_GPL(get_cpu_device);

#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
#ifdef CONFIG_HAVE_CPU_AUTOPROBE
static DEVICE_ATTR(modalias, 0444, print_cpu_modalias, NULL);
#endif

@@ -380,7 +384,7 @@ static struct attribute *cpu_root_attrs[] = {
	&cpu_attrs[2].attr.attr,
	&dev_attr_kernel_max.attr,
	&dev_attr_offline.attr,
#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
#ifdef CONFIG_HAVE_CPU_AUTOPROBE
	&dev_attr_modalias.attr,
#endif
	NULL