cpuctl.c (263080) | cpuctl.c (267651) |
---|---|
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: head/sys/dev/cpuctl/cpuctl.c 263080 2014-03-12 10:25:26Z kib $"); | 29__FBSDID("$FreeBSD: head/sys/dev/cpuctl/cpuctl.c 267651 2014-06-19 21:54:41Z attilio $"); |
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> --- 26 unchanged lines hidden (view full) --- 64#endif 65 66#define UCODE_SIZE_MAX (16 * 1024) 67 68static int cpuctl_do_msr(int cpu, cpuctl_msr_args_t *data, u_long cmd, 69 struct thread *td); 70static int cpuctl_do_cpuid(int cpu, cpuctl_cpuid_args_t *data, 71 struct thread *td); | 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> --- 26 unchanged lines hidden (view full) --- 64#endif 65 66#define UCODE_SIZE_MAX (16 * 1024) 67 68static int cpuctl_do_msr(int cpu, cpuctl_msr_args_t *data, u_long cmd, 69 struct thread *td); 70static int cpuctl_do_cpuid(int cpu, cpuctl_cpuid_args_t *data, 71 struct thread *td); |
72static int cpuctl_do_cpuid_count(int cpu, cpuctl_cpuid_args_t *data, 73 struct thread *td); |
|
72static int cpuctl_do_update(int cpu, cpuctl_update_args_t *data, 73 struct thread *td); 74static int update_intel(int cpu, cpuctl_update_args_t *args, 75 struct thread *td); 76static int update_amd(int cpu, cpuctl_update_args_t *args, struct thread *td); 77static int update_via(int cpu, cpuctl_update_args_t *args, 78 struct thread *td); 79 --- 92 unchanged lines hidden (view full) --- 172 ret = cpuctl_do_cpuid(cpu, (cpuctl_cpuid_args_t *)data, td); 173 break; 174 case CPUCTL_UPDATE: 175 ret = priv_check(td, PRIV_CPUCTL_UPDATE); 176 if (ret != 0) 177 goto fail; 178 ret = cpuctl_do_update(cpu, (cpuctl_update_args_t *)data, td); 179 break; | 74static int cpuctl_do_update(int cpu, cpuctl_update_args_t *data, 75 struct thread *td); 76static int update_intel(int cpu, cpuctl_update_args_t *args, 77 struct thread *td); 78static int update_amd(int cpu, cpuctl_update_args_t *args, struct thread *td); 79static int update_via(int cpu, cpuctl_update_args_t *args, 80 struct thread *td); 81 --- 92 unchanged lines hidden (view full) --- 174 ret = cpuctl_do_cpuid(cpu, (cpuctl_cpuid_args_t *)data, td); 175 break; 176 case CPUCTL_UPDATE: 177 ret = priv_check(td, PRIV_CPUCTL_UPDATE); 178 if (ret != 0) 179 goto fail; 180 ret = cpuctl_do_update(cpu, (cpuctl_update_args_t *)data, td); 181 break; |
182 case CPUCTL_CPUID_COUNT: 183 ret = cpuctl_do_cpuid_count(cpu, (cpuctl_cpuid_args_t *)data, 184 td); 185 break; |
|
180 default: 181 ret = EINVAL; 182 break; 183 } 184fail: 185 return (ret); 186} 187 188/* 189 * Actually perform cpuid operation. 190 */ 191static int | 186 default: 187 ret = EINVAL; 188 break; 189 } 190fail: 191 return (ret); 192} 193 194/* 195 * Actually perform cpuid operation. 196 */ 197static int |
192cpuctl_do_cpuid(int cpu, cpuctl_cpuid_args_t *data, struct thread *td) | 198cpuctl_do_cpuid_count(int cpu, cpuctl_cpuid_args_t *data, struct thread *td) |
193{ 194 int is_bound = 0; 195 int oldcpu; 196 197 KASSERT(cpu >= 0 && cpu < mp_ncpus, 198 ("[cpuctl,%d]: bad cpu number %d", __LINE__, cpu)); 199 200 /* Explicitly clear cpuid data to avoid returning stale info. */ 201 bzero(data->data, sizeof(data->data)); | 199{ 200 int is_bound = 0; 201 int oldcpu; 202 203 KASSERT(cpu >= 0 && cpu < mp_ncpus, 204 ("[cpuctl,%d]: bad cpu number %d", __LINE__, cpu)); 205 206 /* Explicitly clear cpuid data to avoid returning stale info. */ 207 bzero(data->data, sizeof(data->data)); |
202 DPRINTF("[cpuctl,%d]: retriving cpuid level %#0x for %d cpu\n", 203 __LINE__, data->level, cpu); | 208 DPRINTF("[cpuctl,%d]: retrieving cpuid lev %#0x type %#0x for %d cpu\n", 209 __LINE__, data->level, data->level_type, cpu); |
204 oldcpu = td->td_oncpu; 205 is_bound = cpu_sched_is_bound(td); 206 set_cpu(cpu, td); | 210 oldcpu = td->td_oncpu; 211 is_bound = cpu_sched_is_bound(td); 212 set_cpu(cpu, td); |
207 cpuid_count(data->level, 0, data->data); | 213 cpuid_count(data->level, data->level_type, data->data); |
208 restore_cpu(oldcpu, is_bound, td); 209 return (0); 210} 211 | 214 restore_cpu(oldcpu, is_bound, td); 215 return (0); 216} 217 |
218static int 219cpuctl_do_cpuid(int cpu, cpuctl_cpuid_args_t *data, struct thread *td) 220{ 221 222 /* Override the level type. */ 223 data->level_type = 0; 224 return (cpuctl_do_cpuid_count(cpu, data, td)); 225} 226 |
|
212/* 213 * Actually perform MSR operations. 214 */ 215static int 216cpuctl_do_msr(int cpu, cpuctl_msr_args_t *data, u_long cmd, struct thread *td) 217{ 218 uint64_t reg; 219 int is_bound = 0; --- 317 unchanged lines hidden --- | 227/* 228 * Actually perform MSR operations. 229 */ 230static int 231cpuctl_do_msr(int cpu, cpuctl_msr_args_t *data, u_long cmd, struct thread *td) 232{ 233 uint64_t reg; 234 int is_bound = 0; --- 317 unchanged lines hidden --- |