Release 4.14 arch/x86/kernel/cpuid.c
/* ----------------------------------------------------------------------- *
*
* Copyright 2000-2008 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
* USA; either version 2 of the License, or (at your option) any later
* version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* x86 CPUID access device
*
* This device is accessed by lseek() to the appropriate CPUID level
* and then read in chunks of 16 bytes. A larger size means multiple
* reads of consecutive levels.
*
* The lower 32 bits of the file position is used as the incoming %eax,
* and the upper 32 bits of the file position as the incoming %ecx,
* the latter intended for "counting" eax levels like eax=4.
*
* This driver uses /dev/cpu/%d/cpuid where %d is the minor number, and on
* an SMP box will direct the access to CPU %d.
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/fcntl.h>
#include <linux/init.h>
#include <linux/poll.h>
#include <linux/smp.h>
#include <linux/major.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/cpu.h>
#include <linux/notifier.h>
#include <linux/uaccess.h>
#include <linux/gfp.h>
#include <asm/processor.h>
#include <asm/msr.h>
static struct class *cpuid_class;
static enum cpuhp_state cpuhp_cpuid_state;
static void cpuid_smp_cpuid(void *cmd_block)
{
struct cpuid_regs *cmd = (struct cpuid_regs *)cmd_block;
cpuid_count(cmd->eax, cmd->ecx,
&cmd->eax, &cmd->ebx, &cmd->ecx, &cmd->edx);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 39 | 73.58% | 2 | 66.67% |
H. Peter Anvin | 14 | 26.42% | 1 | 33.33% |
Total | 53 | 100.00% | 3 | 100.00% |
static ssize_t cpuid_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
char __user *tmp = buf;
struct cpuid_regs cmd;
int cpu = iminor(file_inode(file));
u64 pos = *ppos;
ssize_t bytes = 0;
int err = 0;
if (count % 16)
return -EINVAL; /* Invalid chunk size */
for (; count; count -= 16) {
cmd.eax = pos;
cmd.ecx = pos >> 32;
err = smp_call_function_single(cpu, cpuid_smp_cpuid, &cmd, 1);
if (err)
break;
if (copy_to_user(tmp, &cmd, 16)) {
err = -EFAULT;
break;
}
tmp += 16;
bytes += 16;
*ppos = ++pos;
}
return bytes ? bytes : err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 86 | 54.78% | 1 | 14.29% |
H. Peter Anvin | 63 | 40.13% | 3 | 42.86% |
Al Viro | 8 | 5.10% | 3 | 42.86% |
Total | 157 | 100.00% | 7 | 100.00% |
static int cpuid_open(struct inode *inode, struct file *file)
{
unsigned int cpu;
struct cpuinfo_x86 *c;
cpu = iminor(file_inode(file));
if (cpu >= nr_cpu_ids || !cpu_online(cpu))
return -ENXIO; /* No such CPU */
c = &cpu_data(cpu);
if (c->cpuid_level < 0)
return -EIO; /* CPUID not supported */
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 42 | 55.26% | 2 | 22.22% |
Jonathan Corbet | 17 | 22.37% | 1 | 11.11% |
Andrew Morton | 7 | 9.21% | 2 | 22.22% |
John Kacur | 5 | 6.58% | 1 | 11.11% |
Al Viro | 4 | 5.26% | 2 | 22.22% |
Mike Travis | 1 | 1.32% | 1 | 11.11% |
Total | 76 | 100.00% | 9 | 100.00% |
/*
* File operations we support
*/
static const struct file_operations cpuid_fops = {
.owner = THIS_MODULE,
.llseek = no_seek_end_llseek,
.read = cpuid_read,
.open = cpuid_open,
};
static int cpuid_device_create(unsigned int cpu)
{
struct device *dev;
dev = device_create(cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu), NULL,
"cpu%d", cpu);
return PTR_ERR_OR_ZERO(dev);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hanna V. Linder | 26 | 60.47% | 2 | 22.22% |
Greg Kroah-Hartman | 10 | 23.26% | 4 | 44.44% |
Akinobu Mita | 5 | 11.63% | 1 | 11.11% |
Fabian Frederick | 1 | 2.33% | 1 | 11.11% |
Sebastian Andrzej Siewior | 1 | 2.33% | 1 | 11.11% |
Total | 43 | 100.00% | 9 | 100.00% |
static int cpuid_device_destroy(unsigned int cpu)
{
device_destroy(cpuid_class, MKDEV(CPUID_MAJOR, cpu));
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Akinobu Mita | 19 | 76.00% | 1 | 33.33% |
Hanna V. Linder | 3 | 12.00% | 1 | 33.33% |
Sebastian Andrzej Siewior | 3 | 12.00% | 1 | 33.33% |
Total | 25 | 100.00% | 3 | 100.00% |
static char *cpuid_devnode(struct device *dev, umode_t *mode)
{
return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt));
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Kay Sievers | 30 | 96.77% | 2 | 66.67% |
Al Viro | 1 | 3.23% | 1 | 33.33% |
Total | 31 | 100.00% | 3 | 100.00% |
static int __init cpuid_init(void)
{
int err;
if (__register_chrdev(CPUID_MAJOR, 0, NR_CPUS,
"cpu/cpuid", &cpuid_fops)) {
printk(KERN_ERR "cpuid: unable to get major %d for cpuid\n",
CPUID_MAJOR);
return -EBUSY;
}
cpuid_class = class_create(THIS_MODULE, "cpuid");
if (IS_ERR(cpuid_class)) {
err = PTR_ERR(cpuid_class);
goto out_chrdev;
}
cpuid_class->devnode = cpuid_devnode;
err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/cpuid:online",
cpuid_device_create, cpuid_device_destroy);
if (err < 0)
goto out_class;
cpuhp_cpuid_state = err;
return 0;
out_class:
class_destroy(cpuid_class);
out_chrdev:
__unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid");
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hanna V. Linder | 68 | 53.12% | 2 | 20.00% |
Linus Torvalds (pre-git) | 26 | 20.31% | 1 | 10.00% |
Sebastian Andrzej Siewior | 10 | 7.81% | 1 | 10.00% |
H. Peter Anvin | 10 | 7.81% | 1 | 10.00% |
Kay Sievers | 6 | 4.69% | 2 | 20.00% |
Thomas Gleixner | 5 | 3.91% | 1 | 10.00% |
Greg Kroah-Hartman | 2 | 1.56% | 1 | 10.00% |
Adrian Bunk | 1 | 0.78% | 1 | 10.00% |
Total | 128 | 100.00% | 10 | 100.00% |
module_init(cpuid_init);
static void __exit cpuid_exit(void)
{
cpuhp_remove_state(cpuhp_cpuid_state);
class_destroy(cpuid_class);
__unregister_chrdev(CPUID_MAJOR, 0, NR_CPUS, "cpu/cpuid");
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 14 | 46.67% | 2 | 22.22% |
Russ Anderson | 5 | 16.67% | 1 | 11.11% |
Hanna V. Linder | 5 | 16.67% | 1 | 11.11% |
Greg Kroah-Hartman | 3 | 10.00% | 2 | 22.22% |
Thomas Gleixner | 1 | 3.33% | 1 | 11.11% |
Adrian Bunk | 1 | 3.33% | 1 | 11.11% |
Sebastian Andrzej Siewior | 1 | 3.33% | 1 | 11.11% |
Total | 30 | 100.00% | 9 | 100.00% |
module_exit(cpuid_exit);
MODULE_AUTHOR("H. Peter Anvin <hpa@zytor.com>");
MODULE_DESCRIPTION("x86 generic CPUID driver");
MODULE_LICENSE("GPL");
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 269 | 40.88% | 3 | 7.50% |
Hanna V. Linder | 116 | 17.63% | 2 | 5.00% |
H. Peter Anvin | 89 | 13.53% | 4 | 10.00% |
Kay Sievers | 36 | 5.47% | 2 | 5.00% |
Akinobu Mita | 24 | 3.65% | 1 | 2.50% |
Jonathan Corbet | 17 | 2.58% | 1 | 2.50% |
Greg Kroah-Hartman | 16 | 2.43% | 6 | 15.00% |
Thomas Gleixner | 16 | 2.43% | 1 | 2.50% |
Sebastian Andrzej Siewior | 15 | 2.28% | 1 | 2.50% |
Al Viro | 14 | 2.13% | 5 | 12.50% |
Andrew Morton | 9 | 1.37% | 3 | 7.50% |
Rusty Russell | 8 | 1.22% | 1 | 2.50% |
Linus Torvalds | 5 | 0.76% | 1 | 2.50% |
John Kacur | 5 | 0.76% | 1 | 2.50% |
Russ Anderson | 5 | 0.76% | 1 | 2.50% |
Tejun Heo | 3 | 0.46% | 1 | 2.50% |
Dave Jones | 3 | 0.46% | 1 | 2.50% |
Jaswinder Singh Rajput | 3 | 0.46% | 1 | 2.50% |
Adrian Bunk | 2 | 0.30% | 1 | 2.50% |
Arjan van de Ven | 1 | 0.15% | 1 | 2.50% |
Mike Travis | 1 | 0.15% | 1 | 2.50% |
Fabian Frederick | 1 | 0.15% | 1 | 2.50% |
Total | 658 | 100.00% | 40 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.