Deleted Added
sdiff udiff text old ( 263080 ) new ( 267651 )
full compact
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 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);
72static int cpuctl_do_cpuid_count(int cpu, cpuctl_cpuid_args_t *data,
73 struct thread *td);
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;
186 default:
187 ret = EINVAL;
188 break;
189 }
190fail:
191 return (ret);
192}
193
194/*
195 * Actually perform cpuid operation.
196 */
197static int
198cpuctl_do_cpuid_count(int cpu, cpuctl_cpuid_args_t *data, struct thread *td)
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));
208 DPRINTF("[cpuctl,%d]: retrieving cpuid lev %#0x type %#0x for %d cpu\n",
209 __LINE__, data->level, data->level_type, cpu);
210 oldcpu = td->td_oncpu;
211 is_bound = cpu_sched_is_bound(td);
212 set_cpu(cpu, td);
213 cpuid_count(data->level, data->level_type, data->data);
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
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 ---