xref: /freebsd/share/man/man4/cpuctl.4 (revision a90b9d0159070121c221b966469c3e36d912bf82)
1.\" Copyright (c) 2006-2008 Stanislav Sedov <stas@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd June 20, 2014
26.Dt CPUCTL 4
27.Os
28.Sh NAME
29.Nm cpuctl
30.Nd cpuctl pseudo device
31.Sh SYNOPSIS
32To compile this driver into the kernel,
33place the following lines in your kernel
34configuration file:
35.Bd -ragged -offset indent
36.Cd "device cpuctl"
37.Ed
38.Pp
39Alternatively, to load the driver as a module
40at boot time, place the following in
41.Xr loader.conf 5 :
42.Bd -literal -offset indent
43cpuctl_load="YES"
44.Ed
45.Sh DESCRIPTION
46The special device
47.Pa /dev/cpuctl
48presents interface to the system CPU.
49It provides functionality to retrieve
50CPUID information, read/write machine specific registers (MSR) and perform
51CPU firmware updates.
52.Pp
53For each CPU present in the system, the special device
54.Pa /dev/cpuctl%d
55with the appropriate index will be created.
56For multicore CPUs such a
57special device will be created for each core.
58.Pp
59Currently, only i386 and amd64 processors are
60supported.
61.Sh IOCTL INTERFACE
62All of the supported operations are invoked using the
63.Xr ioctl 2
64system call.
65Currently, the following ioctls are defined:
66.Bl -tag -width CPUCTL_CPUID_COUNT
67.It Dv CPUCTL_RDMSR Fa cpuctl_msr_args_t *args
68.It Dv CPUCTL_WRMSR Fa cpuctl_msr_args_t *args
69Read/write CPU machine specific register.
70The
71.Vt cpuctl_msr_args_t
72structure is defined in
73.In sys/cpuctl.h
74as:
75.Bd -literal
76typedef struct {
77	int		msr;	/* MSR to read */
78	uint64_t	data;
79} cpuctl_msr_args_t;
80.Ed
81.It Dv CPUCTL_MSRSBIT Fa cpuctl_msr_args_t *args
82.It Dv CPUCTL_MSRCBIT Fa cpuctl_msr_args_t *args
83Set/clear MSR bits according to the mask given in the
84.Va data
85field.
86.It Dv CPUCTL_CPUID Fa cpuctl_cpuid_args_t *args
87Retrieve CPUID information.
88Arguments are supplied in the following structure:
89.Bd -literal
90typedef struct {
91	int		level;		/* CPUID level */
92	uint32_t	data[4];
93} cpuctl_cpuid_args_t;
94.Ed
95It is equivalent to the
96.Dv CPUCTL_CPUID_COUNT
97request with
98.Va level_type
99set to 0.
100.It Dv CPUCTL_CPUID_COUNT Fa cpuctl_cpuid_count_args_t *args
101Retrieve CPUID information.
102Arguments are supplied in the following structure:
103.Bd -literal
104typedef struct {
105	int		level;		/* CPUID level */
106	int		level_type;	/* CPUID level type */
107	uint32_t	data[4];
108} cpuctl_cpuid_count_args_t;
109.Ed
110The
111.Va level
112field indicates the CPUID level to retrieve,
113it is loaded into the
114.Va %eax
115register before the CPUID instruction is executed,
116The
117.Va level_type
118field indicates the CPUID level type to retrieve,
119it is loaded into the
120.Va %ecx
121register.
122.Pp
123The
124.Va data
125field is used to store the received CPUID data.
126That is,
127.Va data[0]
128contains the value of
129.Va %eax
130register after the CPUID instruction is executed,
131.Va data[1]
132is for
133.Va %ebx ,
134.Va data[2]
135for
136.Va %ecx ,
137and
138.Va data[3]
139for
140.Va %edx .
141.It Dv CPUCTL_UPDATE cpuctl_update_args_t *args
142Update CPU firmware (microcode).
143The structure is defined in
144.In sys/cpuctl.h
145as:
146.Bd -literal
147typedef struct {
148	void	*data;
149	size_t	size;
150} cpuctl_update_args_t;
151.Ed
152.Pp
153The
154.Va data
155field should point to the firmware image of size
156.Va size .
157.El
158.Pp
159For additional information refer to
160.Pa cpuctl.h .
161.Sh FILES
162.Bl -tag -width /dev/cpuctl -compact
163.It Pa /dev/cpuctl
164.El
165.Sh ERRORS
166.Bl -tag -width Er
167.It Bq Er ENXIO
168The operation requested is not supported by the device (e.g., unsupported
169architecture or the CPU is disabled).
170.It Bq Er EINVAL
171Incorrect request was supplied, or microcode image is not correct.
172.It Bq Er ENOMEM
173No physical memory was available to complete the request.
174.It Bq Er EFAULT
175The firmware image address points outside the process address space.
176.El
177.Sh SEE ALSO
178.Xr hwpmc 4 ,
179.Xr cpucontrol 8
180.Sh HISTORY
181The
182.Nm
183driver first appeared in
184.Fx 7.2 .
185.Sh AUTHORS
186The
187.Nm
188module and this manual page were written by
189.An Stanislav Sedov Aq Mt stas@FreeBSD.org .
190.Sh BUGS
191Yes, probably, report if any.
192