Merge commit 'b31320a79e2054c6739b5229259dbf98f3afc547' into merges
[unleashed.git] / share / man / man7d / cpuid.7d
blob5ac3eafc6d9d3977dc9de2869bd7201442eb4a6c
1 '\" te
2 .\" Copyright (c) 2004, Sun Microsystems, Inc.  All Rights Reserved
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH CPUID 7D "April 9, 2016"
7 .SH NAME
8 cpuid \- CPU identification driver
9 .SH SYNOPSIS
10 .LP
11 .nf
12 \fB/dev/cpu/self/cpuid\fR
13 .fi
15 .SH DESCRIPTION
16 .SS "SPARC and x86 system"
17 .LP
18 This device provides implementation-private information via ioctls about
19 various aspects of the implementation to Solaris libraries and utilities.
20 .SS "x86 systems only"
21 .LP
22 This device also provides a file-like view of the namespace and return values
23 of the x86 cpuid instruction. The cpuid instruction takes a single 32-bit
24 integer function code, and returns four 32-bit integer values corresponding to
25 the input value that describe various aspects of the capabilities and
26 configuration of the processor.
27 .LP
28 The API for the character device consists of using the seek offset to set the
29 function code value, and using a \fBread\fR(2) or \fBpread\fR(2) of 16 bytes to
30 fetch the four 32-bit return values of the instruction in the order %\fBeax\fR,
31 %\fBebx\fR, %\fBecx\fR and %\fBedx\fR.
32 .LP
33 No data can be written to the device. Like the \fBcpuid\fR instruction, no
34 special privileges are required to use the device.
35 .LP
36 The device is useful to enable low-level configuration information to be
37 extracted from the CPU without having to write any assembler code to invoke the
38 \fBcpuid\fR instruction directly. It also allows the kernel to attempt to
39 correct any erroneous data returned by the instruction (prompted by occasional
40 errors in the information exported by various processor implementations over
41 the years).
42 .LP
43 See the processor manufacturers documentation for further information about the
44 syntax and semantics of the wide variety of information available from this
45 instruction.
46 .SH EXAMPLE
47 .LP
48 This example allows you to determine if the current x86 processor supports
49 "long mode," which is a necessary (but not sufficient) condition for running
50 the 64-bit Solaris kernel on the processor.
51 .sp
52 .in +2
53 .nf
56 #include <sys/types.h>
57 #include <sys/stat.h>
58 #include <fcntl.h>
59 #include <unistd.h>
60 #include <string.h>
61 #include <errno.h>
62 #include <stdio.h>
64 static const char devname[] = "/dev/cpu/self/cpuid";
66 /*ARGSUSED*/
67 int
68 main(int argc, char *argv[])
70         struct {
71                 uint32_t r_eax, r_ebx, r_ecx, r_edx;
72         } _r, *rp = &_r;
73         int d;
74         char *s;
76         if ((d = open(devname, O_RDONLY)) == -1) {
77                 perror(devname);
78                 return (1);
79         }
81         if (pread(d, rp, sizeof (*rp), 0) != sizeof (*rp)) {
82                 perror(devname);
83                 goto fail;
84         }
86         s = (char *)&rp->r_ebx;
87         if (strncmp(s, "Auth" "cAMD" "enti", 12) != 0 &&
88             strncmp(s, "Genu" "ntel" "ineI", 12) != 0)
89                 goto fail;
91         if (pread(d, rp, sizeof (*rp), 0x80000001) == sizeof (*rp)) {
92                 /*
93                  * Read extended feature word; check bit 29
94                  */
95                 (void) close(d);
96                 if ((rp->r_edx >> 29) & 1) {
97                         (void) printf("processor supports long mode\en");
98                         return (0);
99                 }
100         }
101 fail:
102         (void) close(d);
103         return (1);
106 .in -2
108 .SH ERRORS
109 .ne 2
111 \fBENXIO\fR
113 .RS 10n
114 Results from attempting to read data from the device on a system that does not
115 support the CPU identification interfaces
119 .ne 2
121 \fBEINVAL\fR
123 .RS 10n
124 Results from reading from an offset larger than UINT_MAX, or attempting to read
125 with a size that is not multiple of 16 bytes.
128 .SH FILES
129 .ne 2
131 \fB\fB/dev/cpu/self/cpuid\fR\fR
133 .RS 23n
134 Provides access to CPU identification data.
137 .SH ATTRIBUTES
139 See \fBattributes\fR(5) for descriptions of the following attributes:
144 box;
145 c | c
146 l | l .
147 ATTRIBUTE TYPE  ATTRIBUTE VALUE
149 Interface Stability     Evolving
152 .SH SEE ALSO
154 \fBpsrinfo\fR(8), \fBprtconf\fR(8), \fBpread\fR(2), \fBread\fR(2),
155 \fBattributes\fR(5)