cpuid.c (19c22c34dcbecb50c24548aa2ff2b07039c26c14) cpuid.c (644e9cbbe3fc032cc92d0936057e166a994dc246)
1/* ----------------------------------------------------------------------- *
2 *
3 * Copyright 2000-2008 H. Peter Anvin - All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
8 * USA; either version 2 of the License, or (at your option) any later

--- 26 unchanged lines hidden (view full) ---

35#include <linux/smp.h>
36#include <linux/major.h>
37#include <linux/fs.h>
38#include <linux/device.h>
39#include <linux/cpu.h>
40#include <linux/notifier.h>
41#include <linux/uaccess.h>
42#include <linux/gfp.h>
1/* ----------------------------------------------------------------------- *
2 *
3 * Copyright 2000-2008 H. Peter Anvin - All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
8 * USA; either version 2 of the License, or (at your option) any later

--- 26 unchanged lines hidden (view full) ---

35#include <linux/smp.h>
36#include <linux/major.h>
37#include <linux/fs.h>
38#include <linux/device.h>
39#include <linux/cpu.h>
40#include <linux/notifier.h>
41#include <linux/uaccess.h>
42#include <linux/gfp.h>
43#include <linux/slab.h>
43
44#include <asm/processor.h>
45#include <asm/msr.h>
46#include <asm/system.h>
47
48static struct class *cpuid_class;
49
50struct cpuid_regs {

--- 82 unchanged lines hidden (view full) ---

133 */
134static const struct file_operations cpuid_fops = {
135 .owner = THIS_MODULE,
136 .llseek = cpuid_seek,
137 .read = cpuid_read,
138 .open = cpuid_open,
139};
140
44
45#include <asm/processor.h>
46#include <asm/msr.h>
47#include <asm/system.h>
48
49static struct class *cpuid_class;
50
51struct cpuid_regs {

--- 82 unchanged lines hidden (view full) ---

134 */
135static const struct file_operations cpuid_fops = {
136 .owner = THIS_MODULE,
137 .llseek = cpuid_seek,
138 .read = cpuid_read,
139 .open = cpuid_open,
140};
141
142static ssize_t print_cpu_modalias(struct device *dev,
143 struct device_attribute *attr,
144 char *bufptr)
145{
146 int size = PAGE_SIZE;
147 int i, n;
148 char *buf = bufptr;
149
150 n = snprintf(buf, size, "x86cpu:vendor:%04X:family:"
151 "%04X:model:%04X:feature:",
152 boot_cpu_data.x86_vendor,
153 boot_cpu_data.x86,
154 boot_cpu_data.x86_model);
155 size -= n;
156 buf += n;
157 size -= 2;
158 for (i = 0; i < NCAPINTS*32; i++) {
159 if (boot_cpu_has(i)) {
160 n = snprintf(buf, size, ",%04X", i);
161 if (n < 0) {
162 WARN(1, "x86 features overflow page\n");
163 break;
164 }
165 size -= n;
166 buf += n;
167 }
168 }
169 *buf++ = ',';
170 *buf++ = '\n';
171 return buf - bufptr;
172}
173
174static DEVICE_ATTR(modalias, 0444, print_cpu_modalias, NULL);
175
141static __cpuinit int cpuid_device_create(int cpu)
142{
143 struct device *dev;
176static __cpuinit int cpuid_device_create(int cpu)
177{
178 struct device *dev;
179 int err;
144
145 dev = device_create(cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu), NULL,
146 "cpu%d", cpu);
180
181 dev = device_create(cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu), NULL,
182 "cpu%d", cpu);
147 return IS_ERR(dev) ? PTR_ERR(dev) : 0;
183 if (IS_ERR(dev))
184 return PTR_ERR(dev);
185
186 err = device_create_file(dev, &dev_attr_modalias);
187 if (err) {
188 /* keep device around on error. attribute is optional. */
189 err = 0;
190 }
191
192 return 0;
148}
149
150static void cpuid_device_destroy(int cpu)
151{
152 device_destroy(cpuid_class, MKDEV(CPUID_MAJOR, cpu));
153}
154
155static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,

--- 21 unchanged lines hidden (view full) ---

177 .notifier_call = cpuid_class_cpu_callback,
178};
179
180static char *cpuid_devnode(struct device *dev, umode_t *mode)
181{
182 return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt));
183}
184
193}
194
195static void cpuid_device_destroy(int cpu)
196{
197 device_destroy(cpuid_class, MKDEV(CPUID_MAJOR, cpu));
198}
199
200static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,

--- 21 unchanged lines hidden (view full) ---

222 .notifier_call = cpuid_class_cpu_callback,
223};
224
225static char *cpuid_devnode(struct device *dev, umode_t *mode)
226{
227 return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt));
228}
229
230static int cpuid_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
231{
232 char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
233 if (buf) {
234 print_cpu_modalias(NULL, NULL, buf);
235 add_uevent_var(env, "MODALIAS=%s", buf);
236 kfree(buf);
237 }
238 return 0;
239}
240
185static int __init cpuid_init(void)
186{
187 int i, err = 0;
188 i = 0;
189
190 if (__register_chrdev(CPUID_MAJOR, 0, NR_CPUS,
191 "cpu/cpuid", &cpuid_fops)) {
192 printk(KERN_ERR "cpuid: unable to get major %d for cpuid\n",
193 CPUID_MAJOR);
194 err = -EBUSY;
195 goto out;
196 }
197 cpuid_class = class_create(THIS_MODULE, "cpuid");
198 if (IS_ERR(cpuid_class)) {
199 err = PTR_ERR(cpuid_class);
200 goto out_chrdev;
201 }
202 cpuid_class->devnode = cpuid_devnode;
241static int __init cpuid_init(void)
242{
243 int i, err = 0;
244 i = 0;
245
246 if (__register_chrdev(CPUID_MAJOR, 0, NR_CPUS,
247 "cpu/cpuid", &cpuid_fops)) {
248 printk(KERN_ERR "cpuid: unable to get major %d for cpuid\n",
249 CPUID_MAJOR);
250 err = -EBUSY;
251 goto out;
252 }
253 cpuid_class = class_create(THIS_MODULE, "cpuid");
254 if (IS_ERR(cpuid_class)) {
255 err = PTR_ERR(cpuid_class);
256 goto out_chrdev;
257 }
258 cpuid_class->devnode = cpuid_devnode;
259 cpuid_class->dev_uevent = cpuid_dev_uevent;
203 for_each_online_cpu(i) {
204 err = cpuid_device_create(i);
205 if (err != 0)
206 goto out_class;
207 }
208 register_hotcpu_notifier(&cpuid_class_cpu_notifier);
209
210 err = 0;

--- 31 unchanged lines hidden ---
260 for_each_online_cpu(i) {
261 err = cpuid_device_create(i);
262 if (err != 0)
263 goto out_class;
264 }
265 register_hotcpu_notifier(&cpuid_class_cpu_notifier);
266
267 err = 0;

--- 31 unchanged lines hidden ---