1e085f869SStanislav Sedov.\" Copyright (c) 2006-2008 Stanislav Sedov <stas@FreeBSD.org> 2e085f869SStanislav Sedov.\" All rights reserved. 3e085f869SStanislav Sedov.\" 4e085f869SStanislav Sedov.\" Redistribution and use in source and binary forms, with or without 5e085f869SStanislav Sedov.\" modification, are permitted provided that the following conditions 6e085f869SStanislav Sedov.\" are met: 7e085f869SStanislav Sedov.\" 1. Redistributions of source code must retain the above copyright 8e085f869SStanislav Sedov.\" notice, this list of conditions and the following disclaimer. 9e085f869SStanislav Sedov.\" 2. Redistributions in binary form must reproduce the above copyright 10e085f869SStanislav Sedov.\" notice, this list of conditions and the following disclaimer in the 11e085f869SStanislav Sedov.\" documentation and/or other materials provided with the distribution. 12e085f869SStanislav Sedov.\" 13e085f869SStanislav Sedov.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14e085f869SStanislav Sedov.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15e085f869SStanislav Sedov.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16e085f869SStanislav Sedov.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17e085f869SStanislav Sedov.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18e085f869SStanislav Sedov.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19e085f869SStanislav Sedov.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20e085f869SStanislav Sedov.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21e085f869SStanislav Sedov.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22e085f869SStanislav Sedov.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23e085f869SStanislav Sedov.\" SUCH DAMAGE. 24e085f869SStanislav Sedov.\" 25cef789cdSKonstantin Belousov.Dd June 20, 2014 26e085f869SStanislav Sedov.Dt CPUCTL 4 27e085f869SStanislav Sedov.Os 28e085f869SStanislav Sedov.Sh NAME 29e085f869SStanislav Sedov.Nm cpuctl 30e085f869SStanislav Sedov.Nd cpuctl pseudo device 31e085f869SStanislav Sedov.Sh SYNOPSIS 32e085f869SStanislav SedovTo compile this driver into the kernel, 33e085f869SStanislav Sedovplace the following lines in your kernel 34e085f869SStanislav Sedovconfiguration file: 35e085f869SStanislav Sedov.Bd -ragged -offset indent 36e085f869SStanislav Sedov.Cd "device cpuctl" 37e085f869SStanislav Sedov.Ed 38e085f869SStanislav Sedov.Pp 39e085f869SStanislav SedovAlternatively, to load the driver as a module 40e085f869SStanislav Sedovat boot time, place the following in 41e085f869SStanislav Sedov.Xr loader.conf 5 : 42e085f869SStanislav Sedov.Bd -literal -offset indent 43e085f869SStanislav Sedovcpuctl_load="YES" 44e085f869SStanislav Sedov.Ed 45e085f869SStanislav Sedov.Sh DESCRIPTION 46d0bc5026SChristian BruefferThe special device 47e085f869SStanislav Sedov.Pa /dev/cpuctl 485256765fSChristian Bruefferpresents interface to the system CPU. 495256765fSChristian BruefferIt provides functionality to retrieve 50e085f869SStanislav SedovCPUID information, read/write machine specific registers (MSR) and perform 515256765fSChristian BruefferCPU firmware updates. 52e085f869SStanislav Sedov.Pp 53d0bc5026SChristian BruefferFor each CPU present in the system, the special device 54e085f869SStanislav Sedov.Pa /dev/cpuctl%d 555256765fSChristian Bruefferwith the appropriate index will be created. 56d0bc5026SChristian BruefferFor multicore CPUs such a 57d0bc5026SChristian Bruefferspecial device will be created for each core. 58e085f869SStanislav Sedov.Pp 59e085f869SStanislav SedovCurrently, only i386 and amd64 processors are 60e085f869SStanislav Sedovsupported. 61e085f869SStanislav Sedov.Sh IOCTL INTERFACE 62e085f869SStanislav SedovAll of the supported operations are invoked using the 635256765fSChristian Brueffer.Xr ioctl 2 645256765fSChristian Brueffersystem call. 655256765fSChristian BruefferCurrently, the following ioctls are defined: 66cef789cdSKonstantin Belousov.Bl -tag -width CPUCTL_CPUID_COUNT 67e085f869SStanislav Sedov.It Dv CPUCTL_RDMSR Fa cpuctl_msr_args_t *args 68e085f869SStanislav Sedov.It Dv CPUCTL_WRMSR Fa cpuctl_msr_args_t *args 695256765fSChristian BruefferRead/write CPU machine specific register. 705256765fSChristian BruefferThe 71e085f869SStanislav Sedov.Vt cpuctl_msr_args_t 725256765fSChristian Bruefferstructure is defined in 73e085f869SStanislav Sedov.In sys/cpuctl.h 74e085f869SStanislav Sedovas: 75e085f869SStanislav Sedov.Bd -literal 76e085f869SStanislav Sedovtypedef struct { 77e085f869SStanislav Sedov int msr; /* MSR to read */ 78e085f869SStanislav Sedov uint64_t data; 79e085f869SStanislav Sedov} cpuctl_msr_args_t; 80e085f869SStanislav Sedov.Ed 81b2d75854SStanislav Sedov.It Dv CPUCTL_MSRSBIT Fa cpuctl_msr_args_t *args 82b2d75854SStanislav Sedov.It Dv CPUCTL_MSRCBIT Fa cpuctl_msr_args_t *args 83b2d75854SStanislav SedovSet/clear MSR bits according to the mask given in the 84b2d75854SStanislav Sedov.Va data 85b2d75854SStanislav Sedovfield. 86e085f869SStanislav Sedov.It Dv CPUCTL_CPUID Fa cpuctl_cpuid_args_t *args 875256765fSChristian BruefferRetrieve CPUID information. 88cef789cdSKonstantin BelousovArguments are supplied in the following structure: 89cef789cdSKonstantin Belousov.Bd -literal 90cef789cdSKonstantin Belousovtypedef struct { 91cef789cdSKonstantin Belousov int level; /* CPUID level */ 92cef789cdSKonstantin Belousov uint32_t data[4]; 93cef789cdSKonstantin Belousov} cpuctl_cpuid_args_t; 94cef789cdSKonstantin Belousov.Ed 95cef789cdSKonstantin BelousovIt is equivalent to the 96cef789cdSKonstantin Belousov.Dv CPUCTL_CPUID_COUNT 97cef789cdSKonstantin Belousovrequest with 98cef789cdSKonstantin Belousov.Va level_type 99cef789cdSKonstantin Belousovset to 0. 100cef789cdSKonstantin Belousov.It Dv CPUCTL_CPUID_COUNT Fa cpuctl_cpuid_count_args_t *args 101cef789cdSKonstantin BelousovRetrieve CPUID information. 102cef789cdSKonstantin BelousovArguments are supplied in the following structure: 103e085f869SStanislav Sedov.Bd -literal 104e085f869SStanislav Sedovtypedef struct { 105e085f869SStanislav Sedov int level; /* CPUID level */ 106aa1cb750SAttilio Rao int level_type; /* CPUID level type */ 107e085f869SStanislav Sedov uint32_t data[4]; 108cef789cdSKonstantin Belousov} cpuctl_cpuid_count_args_t; 109e085f869SStanislav Sedov.Ed 110e085f869SStanislav SedovThe 111e085f869SStanislav Sedov.Va level 112cef789cdSKonstantin Belousovfield indicates the CPUID level to retrieve, 113cef789cdSKonstantin Belousovit is loaded into the 114cef789cdSKonstantin Belousov.Va %eax 115cef789cdSKonstantin Belousovregister before the CPUID instruction is executed, 116aa1cb750SAttilio RaoThe 117aa1cb750SAttilio Rao.Va level_type 118cef789cdSKonstantin Belousovfield indicates the CPUID level type to retrieve, 119cef789cdSKonstantin Belousovit is loaded into the 120cef789cdSKonstantin Belousov.Va %ecx 121cef789cdSKonstantin Belousovregister. 122cef789cdSKonstantin Belousov.Pp 123cef789cdSKonstantin BelousovThe 124e085f869SStanislav Sedov.Va data 1255256765fSChristian Bruefferfield is used to store the received CPUID data. 126cef789cdSKonstantin BelousovThat is, 127cef789cdSKonstantin Belousov.Va data[0] 128cef789cdSKonstantin Belousovcontains the value of 129cef789cdSKonstantin Belousov.Va %eax 130cef789cdSKonstantin Belousovregister after the CPUID instruction is executed, 131cef789cdSKonstantin Belousov.Va data[1] 132cef789cdSKonstantin Belousovis for 133cef789cdSKonstantin Belousov.Va %ebx , 134cef789cdSKonstantin Belousov.Va data[2] 135cef789cdSKonstantin Belousovfor 136cef789cdSKonstantin Belousov.Va %ecx , 137cef789cdSKonstantin Belousovand 138cef789cdSKonstantin Belousov.Va data[3] 139cef789cdSKonstantin Belousovfor 140cef789cdSKonstantin Belousov.Va %edx . 141e085f869SStanislav Sedov.It Dv CPUCTL_UPDATE cpuctl_update_args_t *args 1425256765fSChristian BruefferUpdate CPU firmware (microcode). 1435256765fSChristian BruefferThe structure is defined in 144e085f869SStanislav Sedov.In sys/cpuctl.h 145e085f869SStanislav Sedovas: 146e085f869SStanislav Sedov.Bd -literal 147e085f869SStanislav Sedovtypedef struct { 148e085f869SStanislav Sedov void *data; 149e085f869SStanislav Sedov size_t size; 150e085f869SStanislav Sedov} cpuctl_update_args_t; 151e085f869SStanislav Sedov.Ed 152e085f869SStanislav Sedov.Pp 153e085f869SStanislav SedovThe 154e085f869SStanislav Sedov.Va data 155e085f869SStanislav Sedovfield should point to the firmware image of size 156e085f869SStanislav Sedov.Va size . 157e085f869SStanislav Sedov.El 158e085f869SStanislav Sedov.Pp 159e085f869SStanislav SedovFor additional information refer to 160e085f869SStanislav Sedov.Pa cpuctl.h . 161*c6209be8SXin LI.Sh FILES 162*c6209be8SXin LI.Bl -tag -width /dev/cpuctl -compact 163*c6209be8SXin LI.It Pa /dev/cpuctl 164*c6209be8SXin LI.El 165*c6209be8SXin LI.Sh ERRORS 166e085f869SStanislav Sedov.Bl -tag -width Er 167e085f869SStanislav Sedov.It Bq Er ENXIO 16850d922a0SGlen BarberThe operation requested is not supported by the device (e.g., unsupported 16950d922a0SGlen Barberarchitecture or the CPU is disabled). 170e085f869SStanislav Sedov.It Bq Er EINVAL 171e085f869SStanislav SedovIncorrect request was supplied, or microcode image is not correct. 172e085f869SStanislav Sedov.It Bq Er ENOMEM 173e085f869SStanislav SedovNo physical memory was available to complete the request. 174e085f869SStanislav Sedov.It Bq Er EFAULT 1755256765fSChristian BruefferThe firmware image address points outside the process address space. 176e085f869SStanislav Sedov.El 177e085f869SStanislav Sedov.Sh SEE ALSO 178d0e00c8bSChristian Brueffer.Xr hwpmc 4 , 1795256765fSChristian Brueffer.Xr cpucontrol 8 180e085f869SStanislav Sedov.Sh HISTORY 181e085f869SStanislav SedovThe 182e085f869SStanislav Sedov.Nm 183e085f869SStanislav Sedovdriver first appeared in 1842a72feb4SChristian Brueffer.Fx 7.2 . 185e085f869SStanislav Sedov.Sh AUTHORS 186e085f869SStanislav SedovThe 187e085f869SStanislav Sedov.Nm 1885256765fSChristian Brueffermodule and this manual page were written by 1896c899950SBaptiste Daroussin.An Stanislav Sedov Aq Mt stas@FreeBSD.org . 1900afc94c1SUlrich Spörlein.Sh BUGS 1910afc94c1SUlrich SpörleinYes, probably, report if any. 192