Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 288847
b: refs/heads/master
c: 644e9cb
h: refs/heads/master
i:
  288845: 176e5ee
  288843: efeeb69
  288839: f807b9b
  288831: 085c8b6
v: v3
  • Loading branch information
Andi Kleen authored and Greg Kroah-Hartman committed Jan 27, 2012
1 parent 64555ba commit 283d281
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d6e486868cde585842d55ba3b6ec57af090fc343
refs/heads/master: 644e9cbbe3fc032cc92d0936057e166a994dc246
13 changes: 13 additions & 0 deletions trunk/arch/x86/include/asm/cpu_device_id.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _CPU_DEVICE_ID
#define _CPU_DEVICE_ID 1

/*
* Declare drivers belonging to specific x86 CPUs
* Similar in spirit to pci_device_id and related PCI functions
*/

#include <linux/mod_devicetable.h>

extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);

#endif
1 change: 1 addition & 0 deletions trunk/arch/x86/kernel/cpu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ obj-y := intel_cacheinfo.o scattered.o topology.o
obj-y += proc.o capflags.o powerflags.o common.o
obj-y += vmware.o hypervisor.o sched.o mshyperv.o
obj-y += rdrand.o
obj-y += match.o

obj-$(CONFIG_X86_32) += bugs.o
obj-$(CONFIG_X86_64) += bugs_64.o
Expand Down
48 changes: 48 additions & 0 deletions trunk/arch/x86/kernel/cpu/match.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <asm/cpu_device_id.h>
#include <asm/processor.h>
#include <linux/cpu.h>
#include <linux/module.h>

/**
* x86_match_cpu - match current CPU again an array of x86_cpu_ids
* @match: Pointer to array of x86_cpu_ids. Last entry terminated with
* {}.
*
* Return the entry if the current CPU matches the entries in the
* passed x86_cpu_id match table. Otherwise NULL. The match table
* contains vendor (X86_VENDOR_*), family, model and feature bits or
* respective wildcard entries.
*
* A typical table entry would be to match a specific CPU
* { X86_VENDOR_INTEL, 6, 0x12 }
* or to match a specific CPU feature
* { X86_FEATURE_MATCH(X86_FEATURE_FOOBAR) }
*
* Fields can be wildcarded with %X86_VENDOR_ANY, %X86_FAMILY_ANY,
* %X86_MODEL_ANY, %X86_FEATURE_ANY or 0 (except for vendor)
*
* Arrays used to match for this should also be declared using
* MODULE_DEVICE_TABLE(x86_cpu, ...)
*
* This always matches against the boot cpu, assuming models and features are
* consistent over all CPUs.
*/
const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)
{
const struct x86_cpu_id *m;
struct cpuinfo_x86 *c = &boot_cpu_data;

for (m = match; m->vendor | m->family | m->model | m->feature; m++) {
if (m->vendor != X86_VENDOR_ANY && c->x86_vendor != m->vendor)
continue;
if (m->family != X86_FAMILY_ANY && c->x86 != m->family)
continue;
if (m->model != X86_MODEL_ANY && c->x86_model != m->model)
continue;
if (m->feature != X86_FEATURE_ANY && !cpu_has(c, m->feature))
continue;
return m;
}
return NULL;
}
EXPORT_SYMBOL(x86_match_cpu);
59 changes: 58 additions & 1 deletion trunk/arch/x86/kernel/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <linux/notifier.h>
#include <linux/uaccess.h>
#include <linux/gfp.h>
#include <linux/slab.h>

#include <asm/processor.h>
#include <asm/msr.h>
Expand Down Expand Up @@ -138,13 +139,57 @@ static const struct file_operations cpuid_fops = {
.open = cpuid_open,
};

static ssize_t print_cpu_modalias(struct device *dev,
struct device_attribute *attr,
char *bufptr)
{
int size = PAGE_SIZE;
int i, n;
char *buf = bufptr;

n = snprintf(buf, size, "x86cpu:vendor:%04X:family:"
"%04X:model:%04X:feature:",
boot_cpu_data.x86_vendor,
boot_cpu_data.x86,
boot_cpu_data.x86_model);
size -= n;
buf += n;
size -= 2;
for (i = 0; i < NCAPINTS*32; i++) {
if (boot_cpu_has(i)) {
n = snprintf(buf, size, ",%04X", i);
if (n < 0) {
WARN(1, "x86 features overflow page\n");
break;
}
size -= n;
buf += n;
}
}
*buf++ = ',';
*buf++ = '\n';
return buf - bufptr;
}

static DEVICE_ATTR(modalias, 0444, print_cpu_modalias, NULL);

static __cpuinit int cpuid_device_create(int cpu)
{
struct device *dev;
int err;

dev = device_create(cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu), NULL,
"cpu%d", cpu);
return IS_ERR(dev) ? PTR_ERR(dev) : 0;
if (IS_ERR(dev))
return PTR_ERR(dev);

err = device_create_file(dev, &dev_attr_modalias);
if (err) {
/* keep device around on error. attribute is optional. */
err = 0;
}

return 0;
}

static void cpuid_device_destroy(int cpu)
Expand Down Expand Up @@ -182,6 +227,17 @@ static char *cpuid_devnode(struct device *dev, umode_t *mode)
return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt));
}

static int cpuid_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
{
char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (buf) {
print_cpu_modalias(NULL, NULL, buf);
add_uevent_var(env, "MODALIAS=%s", buf);
kfree(buf);
}
return 0;
}

static int __init cpuid_init(void)
{
int i, err = 0;
Expand All @@ -200,6 +256,7 @@ static int __init cpuid_init(void)
goto out_chrdev;
}
cpuid_class->devnode = cpuid_devnode;
cpuid_class->dev_uevent = cpuid_dev_uevent;
for_each_online_cpu(i) {
err = cpuid_device_create(i);
if (err != 0)
Expand Down
21 changes: 21 additions & 0 deletions trunk/include/linux/mod_devicetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,25 @@ struct amba_id {
#endif
};

/*
* Match x86 CPUs for CPU specific drivers.
* See documentation of "x86_match_cpu" for details.
*/

struct x86_cpu_id {
__u16 vendor;
__u16 family;
__u16 model;
__u16 feature; /* bit index */
kernel_ulong_t driver_data;
};

#define X86_FEATURE_MATCH(x) \
{ X86_VENDOR_ANY, X86_FAMILY_ANY, X86_MODEL_ANY, x }

#define X86_VENDOR_ANY 0xffff
#define X86_FAMILY_ANY 0
#define X86_MODEL_ANY 0
#define X86_FEATURE_ANY 0 /* Same as FPU, you can't test for that */

#endif /* LINUX_MOD_DEVICETABLE_H */
24 changes: 24 additions & 0 deletions trunk/scripts/mod/file2alias.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,30 @@ static int do_amba_entry(const char *filename,
}
ADD_TO_DEVTABLE("amba", struct amba_id, do_amba_entry);

/* LOOKS like x86cpu:vendor:VVVV:family:FFFF:model:MMMM:feature:*,FEAT,*
* All fields are numbers. It would be nicer to use strings for vendor
* and feature, but getting those out of the build system here is too
* complicated.
*/

static int do_x86cpu_entry(const char *filename, struct x86_cpu_id *id,
char *alias)
{
id->feature = TO_NATIVE(id->feature);
id->family = TO_NATIVE(id->family);
id->model = TO_NATIVE(id->model);
id->vendor = TO_NATIVE(id->vendor);

strcpy(alias, "x86cpu:");
ADD(alias, "vendor:", id->vendor != X86_VENDOR_ANY, id->vendor);
ADD(alias, ":family:", id->family != X86_FAMILY_ANY, id->family);
ADD(alias, ":model:", id->model != X86_MODEL_ANY, id->model);
ADD(alias, ":feature:*,", id->feature != X86_FEATURE_ANY, id->feature);
strcat(alias, ",*");
return 1;
}
ADD_TO_DEVTABLE("x86cpu", struct x86_cpu_id, do_x86cpu_entry);

/* Does namelen bytes of name exactly match the symbol? */
static bool sym_is(const char *name, unsigned namelen, const char *symbol)
{
Expand Down

0 comments on commit 283d281

Please sign in to comment.