Deleted Added
full compact
cpuctl.c (308801) cpuctl.c (315969)
1/*-
2 * Copyright (c) 2006-2008 Stanislav Sedov <stas@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006-2008 Stanislav Sedov <stas@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: stable/11/sys/dev/cpuctl/cpuctl.c 308801 2016-11-18 09:01:44Z kib $");
29__FBSDID("$FreeBSD: stable/11/sys/dev/cpuctl/cpuctl.c 315969 2017-03-26 00:53:34Z kib $");
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/conf.h>
34#include <sys/fcntl.h>
35#include <sys/ioccom.h>
36#include <sys/malloc.h>
37#include <sys/module.h>

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

121{
122
123 KASSERT(cpu >= 0 && cpu <= mp_maxid && cpu_enabled(cpu),
124 ("[cpuctl,%d]: bad cpu number %d", __LINE__, cpu));
125 thread_lock(td);
126 sched_bind(td, cpu);
127 thread_unlock(td);
128 KASSERT(td->td_oncpu == cpu,
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/conf.h>
34#include <sys/fcntl.h>
35#include <sys/ioccom.h>
36#include <sys/malloc.h>
37#include <sys/module.h>

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

121{
122
123 KASSERT(cpu >= 0 && cpu <= mp_maxid && cpu_enabled(cpu),
124 ("[cpuctl,%d]: bad cpu number %d", __LINE__, cpu));
125 thread_lock(td);
126 sched_bind(td, cpu);
127 thread_unlock(td);
128 KASSERT(td->td_oncpu == cpu,
129 ("[cpuctl,%d]: cannot bind to target cpu %d on cpu %d", __LINE__, cpu, td->td_oncpu));
129 ("[cpuctl,%d]: cannot bind to target cpu %d on cpu %d", __LINE__,
130 cpu, td->td_oncpu));
130}
131
132static void
133restore_cpu(int oldcpu, int is_bound, struct thread *td)
134{
135
136 KASSERT(oldcpu >= 0 && oldcpu <= mp_maxid && cpu_enabled(oldcpu),
137 ("[cpuctl,%d]: bad cpu number %d", __LINE__, oldcpu));
138 thread_lock(td);
139 if (is_bound == 0)
140 sched_unbind(td);
141 else
142 sched_bind(td, oldcpu);
143 thread_unlock(td);
144}
145
146int
147cpuctl_ioctl(struct cdev *dev, u_long cmd, caddr_t data,
131}
132
133static void
134restore_cpu(int oldcpu, int is_bound, struct thread *td)
135{
136
137 KASSERT(oldcpu >= 0 && oldcpu <= mp_maxid && cpu_enabled(oldcpu),
138 ("[cpuctl,%d]: bad cpu number %d", __LINE__, oldcpu));
139 thread_lock(td);
140 if (is_bound == 0)
141 sched_unbind(td);
142 else
143 sched_bind(td, oldcpu);
144 thread_unlock(td);
145}
146
147int
148cpuctl_ioctl(struct cdev *dev, u_long cmd, caddr_t data,
148 int flags, struct thread *td)
149 int flags, struct thread *td)
149{
150{
150 int ret;
151 int cpu = dev2unit(dev);
151 int cpu, ret;
152
152
153 cpu = dev2unit(dev);
153 if (cpu > mp_maxid || !cpu_enabled(cpu)) {
154 DPRINTF("[cpuctl,%d]: bad cpu number %d\n", __LINE__, cpu);
155 return (ENXIO);
156 }
157 /* Require write flag for "write" requests. */
158 if ((cmd == CPUCTL_WRMSR || cmd == CPUCTL_UPDATE) &&
159 ((flags & FWRITE) == 0))
160 return (EPERM);

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

274 critical_exit();
275 } else if (cmd == CPUCTL_MSRCBIT) {
276 critical_enter();
277 ret = rdmsr_safe(data->msr, &reg);
278 if (ret == 0)
279 ret = wrmsr_safe(data->msr, reg & ~data->data);
280 critical_exit();
281 } else
154 if (cpu > mp_maxid || !cpu_enabled(cpu)) {
155 DPRINTF("[cpuctl,%d]: bad cpu number %d\n", __LINE__, cpu);
156 return (ENXIO);
157 }
158 /* Require write flag for "write" requests. */
159 if ((cmd == CPUCTL_WRMSR || cmd == CPUCTL_UPDATE) &&
160 ((flags & FWRITE) == 0))
161 return (EPERM);

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

275 critical_exit();
276 } else if (cmd == CPUCTL_MSRCBIT) {
277 critical_enter();
278 ret = rdmsr_safe(data->msr, &reg);
279 if (ret == 0)
280 ret = wrmsr_safe(data->msr, reg & ~data->data);
281 critical_exit();
282 } else
282 panic("[cpuctl,%d]: unknown operation requested: %lu", __LINE__, cmd);
283 panic("[cpuctl,%d]: unknown operation requested: %lu",
284 __LINE__, cmd);
283 restore_cpu(oldcpu, is_bound, td);
284 return (ret);
285}
286
287/*
288 * Actually perform microcode update.
289 */
290static int

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

306 ((uint32_t *)vendor)[0] = args.data[1];
307 ((uint32_t *)vendor)[1] = args.data[3];
308 ((uint32_t *)vendor)[2] = args.data[2];
309 vendor[12] = '\0';
310 if (strncmp(vendor, INTEL_VENDOR_ID, sizeof(INTEL_VENDOR_ID)) == 0)
311 ret = update_intel(cpu, data, td);
312 else if(strncmp(vendor, AMD_VENDOR_ID, sizeof(AMD_VENDOR_ID)) == 0)
313 ret = update_amd(cpu, data, td);
285 restore_cpu(oldcpu, is_bound, td);
286 return (ret);
287}
288
289/*
290 * Actually perform microcode update.
291 */
292static int

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

308 ((uint32_t *)vendor)[0] = args.data[1];
309 ((uint32_t *)vendor)[1] = args.data[3];
310 ((uint32_t *)vendor)[2] = args.data[2];
311 vendor[12] = '\0';
312 if (strncmp(vendor, INTEL_VENDOR_ID, sizeof(INTEL_VENDOR_ID)) == 0)
313 ret = update_intel(cpu, data, td);
314 else if(strncmp(vendor, AMD_VENDOR_ID, sizeof(AMD_VENDOR_ID)) == 0)
315 ret = update_amd(cpu, data, td);
314 else if(strncmp(vendor, CENTAUR_VENDOR_ID, sizeof(CENTAUR_VENDOR_ID)) == 0)
316 else if(strncmp(vendor, CENTAUR_VENDOR_ID, sizeof(CENTAUR_VENDOR_ID))
317 == 0)
315 ret = update_via(cpu, data, td);
316 else
317 ret = ENXIO;
318 return (ret);
319}
320
321static int
322update_intel(int cpu, cpuctl_update_args_t *args, struct thread *td)

--- 228 unchanged lines hidden ---
318 ret = update_via(cpu, data, td);
319 else
320 ret = ENXIO;
321 return (ret);
322}
323
324static int
325update_intel(int cpu, cpuctl_update_args_t *args, struct thread *td)

--- 228 unchanged lines hidden ---