Lines Matching +full:8 +full:- +full:cpu
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* ----------------------------------------------------------------------- *
4 * Copyright 2000-2008 H. Peter Anvin - All Rights Reserved
7 * ----------------------------------------------------------------------- */
13 * and then read/write in chunks of 8 bytes. A larger size means multiple
16 * This driver uses /dev/cpu/%d/msr where %d is the minor number, and on
17 * an SMP box will direct the access to CPU %d.
33 #include <linux/cpu.h>
58 int cpu = iminor(file_inode(file)); in msr_read() local
62 if (count % 8) in msr_read()
63 return -EINVAL; /* Invalid chunk size */ in msr_read()
65 for (; count; count -= 8) { in msr_read()
66 err = rdmsr_safe_on_cpu(cpu, reg, &data[0], &data[1]); in msr_read()
69 if (copy_to_user(tmp, &data, 8)) { in msr_read()
70 err = -EFAULT; in msr_read()
74 bytes += 8; in msr_read()
86 * It's possible to be smarter here and do it (for example) per-MSR, but in filter_write()
94 case MSR_WRITES_OFF: return -EPERM; in filter_write()
102 reg, current->comm, current->pid); in filter_write()
114 int cpu = iminor(file_inode(file)); in msr_write() local
126 if (count % 8) in msr_write()
127 return -EINVAL; /* Invalid chunk size */ in msr_write()
129 for (; count; count -= 8) { in msr_write()
130 if (copy_from_user(&data, tmp, 8)) { in msr_write()
131 err = -EFAULT; in msr_write()
137 err = wrmsr_safe_on_cpu(cpu, reg, data[0], data[1]); in msr_write()
142 bytes += 8; in msr_write()
151 u32 regs[8]; in msr_ioctl()
152 int cpu = iminor(file_inode(file)); in msr_ioctl() local
157 if (!(file->f_mode & FMODE_READ)) { in msr_ioctl()
158 err = -EBADF; in msr_ioctl()
162 err = -EFAULT; in msr_ioctl()
165 err = rdmsr_safe_regs_on_cpu(cpu, regs); in msr_ioctl()
169 err = -EFAULT; in msr_ioctl()
173 if (!(file->f_mode & FMODE_WRITE)) { in msr_ioctl()
174 err = -EBADF; in msr_ioctl()
178 err = -EFAULT; in msr_ioctl()
191 err = wrmsr_safe_regs_on_cpu(cpu, regs); in msr_ioctl()
195 err = -EFAULT; in msr_ioctl()
199 err = -ENOTTY; in msr_ioctl()
208 unsigned int cpu = iminor(file_inode(file)); in msr_open() local
212 return -EPERM; in msr_open()
214 if (cpu >= nr_cpu_ids || !cpu_online(cpu)) in msr_open()
215 return -ENXIO; /* No such CPU */ in msr_open()
217 c = &cpu_data(cpu); in msr_open()
219 return -EIO; /* MSR not supported */ in msr_open()
239 return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt)); in msr_devnode()
247 static int msr_device_create(unsigned int cpu) in msr_device_create() argument
251 dev = device_create(&msr_class, NULL, MKDEV(MSR_MAJOR, cpu), NULL, in msr_device_create()
252 "msr%d", cpu); in msr_device_create()
256 static int msr_device_destroy(unsigned int cpu) in msr_device_destroy() argument
258 device_destroy(&msr_class, MKDEV(MSR_MAJOR, cpu)); in msr_device_destroy()
266 if (__register_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr", &msr_fops)) { in msr_init()
268 return -EBUSY; in msr_init()
284 __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); in msr_init()
293 __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); in msr_exit()
299 /* val is NUL-terminated, see kernfs_fop_write() */ in module_exit()