1 '\" te
   2 .\" Copyright (c) 2004, Sun Microsystems, Inc.  All Rights Reserved
   3 .\" Copyright 2015, Joyent, Inc.
   4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
   5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
   6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
   7 .TH CPUID 7D "April 9, 2016"
   8 .SH NAME
   9 cpuid \- CPU identification driver
  10 .SH SYNOPSIS
  11 .LP
  12 .nf
  13 \fB/dev/cpu/self/cpuid\fR
  14 .fi
  15 
  16 .SH DESCRIPTION
  17 .SS "SPARC and x86 system"
  18 .LP
  19 This device provides implementation-private information via ioctls about
  20 various aspects of the implementation to Solaris libraries and utilities.
  21 .SS "x86 systems only"
  22 .LP
  23 This device also provides a file-like view of the namespace and return values
  24 of the x86 cpuid instruction. The cpuid instruction takes a single 32-bit
  25 integer function code, and returns four 32-bit integer values corresponding to
  26 the input value that describe various aspects of the capabilities and
  27 configuration of the processor.
  28 .LP
  29 The API for the character device consists of using the seek offset to set the
  30 function code value, and using a \fBread\fR(2) or \fBpread\fR(2) of 16 bytes to
  31 fetch the four 32-bit return values of the instruction in the order %\fBeax\fR,
  32 %\fBebx\fR, %\fBecx\fR and %\fBedx\fR.
  33 .LP
  34 No data can be written to the device. Like the \fBcpuid\fR instruction, no
  35 special privileges are required to use the device.
  36 .LP
  37 The device is useful to enable low-level configuration information to be
  38 extracted from the CPU without having to write any assembler code to invoke the
  39 \fBcpuid\fR instruction directly. It also allows the kernel to attempt to
  40 correct any erroneous data returned by the instruction (prompted by occasional
  41 errors in the information exported by various processor implementations over
  42 the years).
  43 .LP
  44 See the processor manufacturers documentation for further information about the
  45 syntax and semantics of the wide variety of information available from this
  46 instruction.
  47 .LP
  48 Some systems can be configured to limit the cpuid opcodes which are accessible.
  49 While illumos handles this condition, other software may malfunction when such
  50 limits are enabled.  Those settings are typically manipulated in the BIOS.
  51 .SH EXAMPLE
  52 .LP
  53 This example allows you to determine if the current x86 processor supports
  54 "long mode," which is a necessary (but not sufficient) condition for running
  55 the 64-bit Solaris kernel on the processor.
  56 .sp
  57 .in +2
  58 .nf
  59 /*
  60 
  61 #include <sys/types.h>
  62 #include <sys/stat.h>
  63 #include <fcntl.h>
  64 #include <unistd.h>
  65 #include <string.h>
  66 #include <errno.h>
  67 #include <stdio.h>
  68 
  69 static const char devname[] = "/dev/cpu/self/cpuid";
  70 
  71 /*ARGSUSED*/
  72 int
  73 main(int argc, char *argv[])
  74 {
  75         struct {
  76                 uint32_t r_eax, r_ebx, r_ecx, r_edx;
  77         } _r, *rp = &_r;
  78         int d;
  79         char *s;
  80 
  81         if ((d = open(devname, O_RDONLY)) == -1) {
  82                 perror(devname);
  83                 return (1);
  84         }
  85 
  86         if (pread(d, rp, sizeof (*rp), 0) != sizeof (*rp)) {
  87                 perror(devname);
  88                 goto fail;
  89         }
  90 
  91         s = (char *)&rp->r_ebx;
  92         if (strncmp(s, "Auth" "cAMD" "enti", 12) != 0 &&
  93             strncmp(s, "Genu" "ntel" "ineI", 12) != 0)
  94                 goto fail;
  95 
  96         if (pread(d, rp, sizeof (*rp), 0x80000001) == sizeof (*rp)) {
  97                 /*
  98                  * Read extended feature word; check bit 29
  99                  */
 100                 (void) close(d);
 101                 if ((rp->r_edx >> 29) & 1) {
 102                         (void) printf("processor supports long mode\en");
 103                         return (0);
 104                 }
 105         }
 106 fail:
 107         (void) close(d);
 108         return (1);
 109 }
 110 .fi
 111 .in -2
 112 
 113 .SH ERRORS
 114 .ne 2
 115 .na
 116 \fBENXIO\fR
 117 .ad
 118 .RS 10n
 119 Results from attempting to read data from the device on a system that does not
 120 support the CPU identification interfaces
 121 .RE
 122 
 123 .sp
 124 .ne 2
 125 .na
 126 \fBEINVAL\fR
 127 .ad
 128 .RS 10n
 129 Results from reading from an offset larger than UINT_MAX, or attempting to read
 130 with a size that is not multiple of 16 bytes.
 131 .RE
 132 
 133 .SH FILES
 134 .ne 2
 135 .na
 136 \fB\fB/dev/cpu/self/cpuid\fR\fR
 137 .ad
 138 .RS 23n
 139 Provides access to CPU identification data.
 140 .RE
 141 
 142 .SH ATTRIBUTES
 143 .LP
 144 See \fBattributes\fR(5) for descriptions of the following attributes:
 145 .sp
 146 
 147 .sp
 148 .TS
 149 box;
 150 c | c
 151 l | l .
 152 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 153 _
 154 Interface Stability     Evolving
 155 .TE
 156 
 157 .SH SEE ALSO
 158 .LP
 159 \fBpsrinfo\fR(1M), \fBprtconf\fR(1M), \fBpread\fR(2), \fBread\fR(2),
 160 \fBattributes\fR(5)