]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOReportTypes.h
xnu-4903.270.47.tar.gz
[apple/xnu.git] / iokit / IOKit / IOReportTypes.h
CommitLineData
39236c6e 1/*
fe8ab488 2 * Copyright (c) 2012-2014 Apple Computer, Inc. All Rights Reserved.
5ba3f43e 3 *
39236c6e 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5ba3f43e 5 *
39236c6e
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
5ba3f43e 14 *
39236c6e
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
5ba3f43e 17 *
39236c6e
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
5ba3f43e 25 *
39236c6e
A
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _IOREPORT_TYPES_H_
30#define _IOREPORT_TYPES_H_
31
32#include <stdint.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
fe8ab488
A
38#define IOR_VALUES_PER_ELEMENT 4
39
39236c6e 40/*! @const kIOReportInvalidValue
0a7de745
A
41 * @const kIOReportInvalidIntValue
42 * @abstract cardinal value used to indicate data errors
43 *
44 * @discussion
45 * kIOReportInvalidValue and kIOReportInvalidIntValue have the
46 * same bit pattern so that clients checking for one or the other
47 * don't have to worry about getting the signedness right.
48 */
fe8ab488
A
49#define kIOReportInvalidIntValue INT64_MIN
50#define kIOReportInvalidValue (uint64_t)kIOReportInvalidIntValue
51
52/*! @typedef IOReportCategories
0a7de745
A
53 * @abstract encapsulate important, multi-purpose "tags" for channels
54 *
55 * @discussion
56 * IOReportCategories is the type for the .categories field of
57 * IOReportChanelType. These categories are inteded to empower a
58 * limited number of clients to retrieve a broad range of channels
59 * without knowing much about them. They can be OR'd together as
60 * needed. Groups and subgroups are a more extensible mechanism
61 * for aggregating channels produced by different drivers.
62 */
5ba3f43e 63typedef uint16_t IOReportCategories;
39236c6e 64#define kIOReportCategoryPower (1 << 1) // and energy
fe8ab488
A
65#define kIOReportCategoryTraffic (1 << 2) // I/O at any level
66#define kIOReportCategoryPerformance (1 << 3) // e.g. cycles/byte
67#define kIOReportCategoryPeripheral (1 << 4) // not built-in
68
69#define kIOReportCategoryField (1 << 8) // consider logging
70
39236c6e
A
71// future categories TBD
72#define kIOReportCategoryDebug (1 << 15)
5ba3f43e 73#define kIOReportInvalidCategory UINT16_MAX
39236c6e
A
74
75
76// IOReportChannelType.report_format
77typedef uint8_t IOReportFormat;
78enum {
0a7de745
A
79 kIOReportInvalidFormat = 0,
80 kIOReportFormatSimple = 1,
81 kIOReportFormatState = 2,
82 kIOReportFormatHistogram = 3,
83 kIOReportFormatSimpleArray = 4
39236c6e
A
84};
85
86// simple report values
87typedef struct {
0a7de745
A
88 int64_t simple_value;
89 uint64_t reserved1;
90 uint64_t reserved2;
91 uint64_t reserved3;
39236c6e
A
92} __attribute((packed)) IOSimpleReportValues;
93
fe8ab488
A
94// simple value array
95typedef struct {
0a7de745 96 int64_t simple_values[IOR_VALUES_PER_ELEMENT];
fe8ab488
A
97} __attribute((packed)) IOSimpleArrayReportValues;
98
39236c6e
A
99// state report values
100typedef struct {
0a7de745
A
101 uint64_t state_id; // 0..N-1 or 8-char code (see MAKEID())
102 uint64_t intransitions; // number of transitions into this state
103 uint64_t upticks; // ticks spent in state (local timebase)
104 uint64_t last_intransition;// ticks at last in-transition
39236c6e
A
105} __attribute((packed)) IOStateReportValues;
106
fe8ab488 107// histogram report values
39236c6e 108typedef struct {
0a7de745
A
109 uint64_t bucket_hits;
110 int64_t bucket_min;
111 int64_t bucket_max;
112 int64_t bucket_sum;
39236c6e
A
113} __attribute((packed)) IOHistogramReportValues;
114
fe8ab488
A
115
116
39236c6e
A
117// configuration actions generally change future behavior
118typedef uint32_t IOReportConfigureAction;
119enum {
0a7de745
A
120 // basics (in common operational order)
121 kIOReportEnable = 0x01,
122 kIOReportGetDimensions = 0x02,
123 kIOReportDisable = 0x00,
39236c6e 124
0a7de745
A
125 // Enable/disable modifiers
126 kIOReportNotifyHubOnChange = 0x10, // triggered polling
39236c6e 127
0a7de745 128 kIOReportTraceOnChange = 0x20 // kdebug.h tracing
39236c6e
A
129};
130
131// update actions should not have observable side effects
132typedef uint32_t IOReportUpdateAction;
133enum {
0a7de745
A
134 kIOReportCopyChannelData = 1,
135 kIOReportTraceChannelData = 2
39236c6e
A
136};
137
138typedef struct {
0a7de745
A
139 uint8_t report_format; // Histogram, StateResidency, etc.
140 uint8_t reserved; // must be zero
141 uint16_t categories; // power, traffic, etc (omnibus obs.)
142 uint16_t nelements; // internal size of channel
143
144 // only meaningful in the data pipeline
145 int16_t element_idx; // 0..nelements-1
146 // -1..-(nelements) = invalid (13127884)
39236c6e
A
147} __attribute((packed)) IOReportChannelType;
148
149/*!
0a7de745
A
150 * @define IOREPORT_MAKECHID
151 * @abstract convert up to 8 printable characters into a 64-bit channel ID
152 * @param <char0..char7> - printable chars to be packed into a channel ID
153 * @result a 64-bit channel ID with an implicit ASCII name
154 * @discussion A simple example:
155 * IOREPORT_MAKECHID('H', 'i', ' ', 'w', 'o', 'r', 'l', 'd');
156 * will evaluate to 0x686920776f726c64. Any NUL bytes are
157 * ignored (by libIOReport) for naming purposes, but will
158 * appear in the channel ID. Using a non-NUL non-printable
159 * character will disable the implicit name. Putting NUL
160 * bytes first eliminates trailing zeros when the channel
161 * ID is printed as hex. For example:
162 * IORERPORT_MAKECHID('\0','\0','n','x','f','e','r','s');
163 * To see the text, use xxd -r -p # not -rp; see 12976241
164 */
39236c6e
A
165#define __IOR_lshiftchr(c, chshift) ((uint64_t)(c) << (8*(chshift)))
166#define IOREPORT_MAKEID(A, B, C, D, E, F, G, H) \
167 (__IOR_lshiftchr(A, 7) | __IOR_lshiftchr(B, 6) | __IOR_lshiftchr(C, 5) \
168 | __IOR_lshiftchr(D, 4) | __IOR_lshiftchr(E, 3) | __IOR_lshiftchr(F, 2) \
169 | __IOR_lshiftchr(G, 1) | __IOR_lshiftchr(H, 0))
170
171typedef struct {
0a7de745
A
172 uint64_t channel_id;
173 IOReportChannelType channel_type;
39236c6e
A
174} IOReportChannel;
175
176typedef struct {
0a7de745
A
177 uint32_t nchannels;
178 IOReportChannel channels[];
39236c6e
A
179} IOReportChannelList;
180
181typedef struct {
0a7de745
A
182 uint64_t provider_id;
183 IOReportChannel channel;
39236c6e
A
184} IOReportInterest;
185
186typedef struct {
0a7de745
A
187 uint32_t ninterests;
188 IOReportInterest interests[];
39236c6e
A
189} IOReportInterestList;
190
191typedef struct {
0a7de745 192 uint64_t v[IOR_VALUES_PER_ELEMENT];
39236c6e
A
193} __attribute((packed)) IOReportElementValues;
194
195typedef struct {
0a7de745
A
196 uint64_t provider_id;
197 uint64_t channel_id;
198 IOReportChannelType channel_type;
199 uint64_t timestamp;// mach_absolute_time()
200 IOReportElementValues values;
39236c6e
A
201} __attribute((packed)) IOReportElement;
202
5ba3f43e
A
203
204
205/*
0a7de745
A
206 * IOReporting unit type and constants
207 */
5ba3f43e
A
208
209// 1. Mechanism
210
211// Assume encoded units could be stored in binary format: don't
212// change existing values.
213
214typedef uint64_t IOReportUnit;
215typedef uint64_t IOReportUnits; // deprecated typo, please switch
216#define __IOR_MAKEUNIT(quantity, scale) \
0a7de745 217 (((IOReportUnit)quantity << 56) | (uint64_t)scale)
5ba3f43e 218#define IOREPORT_GETUNIT_QUANTITY(unit) \
0a7de745 219 ((IOReportQuantity)((uint64_t)unit >> 56) & 0xff)
5ba3f43e 220#define IOREPORT_GETUNIT_SCALE(unit) \
0a7de745 221 ((IOReportScaleFactor)unit & 0x00ffffffffffffff)
5ba3f43e
A
222
223// 8b quantity ID | 32b const val + 8b*2^10 + 8b*2^n | 8b cardinal | 8b unused
224typedef uint8_t IOReportQuantity; // SI "quantity" is what's measured
225typedef uint64_t IOReportScaleFactor;
226
227// See <http://en.wikipedia.org/wiki/SI_base_unit> for a list
228// of quantities and their symbols.
229enum {
0a7de745
A
230 // used by state reports, etc
231 kIOReportQuantityUndefined = 0,
232
233 kIOReportQuantityTime = 1,// Seconds
234 kIOReportQuantityPower = 2,// Watts
235 kIOReportQuantityEnergy = 3,// Joules
236 kIOReportQuantityCurrent = 4,// Amperes
237 kIOReportQuantityVoltage = 5,// Volts
238 kIOReportQuantityCapacitance = 6,// Farad
239 kIOReportQuantityInductance = 7,// Henry
240 kIOReportQuantityFrequency = 8,// Hertz
241 kIOReportQuantityData = 9,// bits/bytes (see scale)
242 kIOReportQuantityTemperature = 10,// Celsius (not Kelvin :)
243
244 kIOReportQuantityEventCount = 100,
245 kIOReportQuantityPacketCount = 101,
246 kIOReportQuantityCPUInstrs = 102
5ba3f43e
A
247};
248
249
250/* A number of units end up with both IEC (2^n) and SI (10^n) scale factors.
0a7de745
A
251 * For example, the "MB" of a 1.44 MB floppy or a 1024MHz clock. We
252 * thus support separate 2^n and 10^n factors. The exponent encoding
253 * scheme is modeled loosely on single-precision IEEE 754.
5ba3f43e
A
254 */
255#define kIOReportScaleConstMask 0x000000007fffffff // constant ("uint31")
256#define kIOReportScaleOneOver (1LL << 31) // 1/constant
257#define kIOReportExpBase (-127) // support base^(-n)
258#define kIOReportExpZeroOffset -(kIOReportExpBase) // max exponent = 128
259#define kIOReportScaleSIShift 32 // * 10^n
260#define kIOReportScaleSIMask 0x000000ff00000000
261#define kIOReportScaleIECShift 40 // * 2^n
262#define kIOReportScaleIECMask 0x0000ff0000000000
263#define kIOReportCardinalShift 48 // placeholders
264#define kIOReportCardinalMask 0x00ff000000000000
265
266
267/*
0a7de745
A
268 * Scales are described as a factor times unity:
269 * 1ms = kIOReportScaleMilli * s
270 *
271 * A value expressed in a scaled unit can be scaled to unity via
272 * multiplication by the constant:
273 * 100ms * kIOReportScaleMilli [1e-3] = 0.1s.
274 */
5ba3f43e
A
275
276// SI / decimal
277#define kIOReportScalePico ((-12LL + kIOReportExpZeroOffset) \
0a7de745 278 << kIOReportScaleSIShift)
5ba3f43e 279#define kIOReportScaleNano ((-9LL + kIOReportExpZeroOffset) \
0a7de745 280 << kIOReportScaleSIShift)
5ba3f43e 281#define kIOReportScaleMicro ((-6LL + kIOReportExpZeroOffset) \
0a7de745 282 << kIOReportScaleSIShift)
5ba3f43e 283#define kIOReportScaleMilli ((-3LL + kIOReportExpZeroOffset) \
0a7de745 284 << kIOReportScaleSIShift)
5ba3f43e
A
285#define kIOReportScaleUnity 0 // 10^0 = 2^0 = 1
286// unity = 0 is a special case for which we give up exp = -127
287#define kIOReportScaleKilo ((3LL + kIOReportExpZeroOffset) \
0a7de745 288 << kIOReportScaleSIShift)
5ba3f43e 289#define kIOReportScaleMega ((6LL + kIOReportExpZeroOffset) \
0a7de745 290 << kIOReportScaleSIShift)
5ba3f43e 291#define kIOReportScaleGiga ((9LL + kIOReportExpZeroOffset) \
0a7de745 292 << kIOReportScaleSIShift)
5ba3f43e 293#define kIOReportScaleTera ((12LL + kIOReportExpZeroOffset) \
0a7de745 294 << kIOReportScaleSIShift)
5ba3f43e
A
295
296// IEC / computer / binary
297// It's not clear we'll ever use 2^(-n), but 1..2^~120 should suffice.
298#define kIOReportScaleBits kIOReportScaleUnity
299#define kIOReportScaleBytes ((3LL + kIOReportExpZeroOffset) \
0a7de745 300 << kIOReportScaleIECShift)
5ba3f43e
A
301// (bytes have to be added to the exponents up front, can't just OR in)
302#define kIOReportScaleKibi ((10LL + kIOReportExpZeroOffset) \
0a7de745 303 << kIOReportScaleIECShift)
5ba3f43e 304#define kIOReportScaleKiBytes ((13LL + kIOReportExpZeroOffset) \
0a7de745 305 << kIOReportScaleIECShift)
5ba3f43e 306#define kIOReportScaleMebi ((20LL + kIOReportExpZeroOffset) \
0a7de745 307 << kIOReportScaleIECShift)
5ba3f43e 308#define kIOReportScaleMiBytes ((23LL + kIOReportExpZeroOffset) \
0a7de745 309 << kIOReportScaleIECShift)
5ba3f43e 310#define kIOReportScaleGibi ((30LL + kIOReportExpZeroOffset) \
0a7de745 311 << kIOReportScaleIECShift)
5ba3f43e 312#define kIOReportScaleGiBytes ((33LL + kIOReportExpZeroOffset) \
0a7de745 313 << kIOReportScaleIECShift)
5ba3f43e 314#define kIOReportScaleTebi ((40LL + kIOReportExpZeroOffset) \
0a7de745 315 << kIOReportScaleIECShift)
5ba3f43e 316#define kIOReportScaleTiBytes ((43LL + kIOReportExpZeroOffset) \
0a7de745 317 << kIOReportScaleIECShift)
5ba3f43e
A
318// can't encode more than 2^125 (keeping bits & bytes inside -126..128)
319// Also, IOReportScaleValue() is currently limited internally by uint64_t.
320
321
322// Cardinal values, to be filled in appropriately.
323// Add values in increasing order.
324#define kIOReportScaleMachHWTicks (1LL << kIOReportCardinalShift)
325#define kIOReportScaleHWPageSize (2LL << kIOReportCardinalShift)
326
327// page scales: 2 pages * 4ikB/page = 8096 bytes
328#define kIOReportScale4KiB (4 | kIOReportScaleKiBytes)
329#define kIOReportScale8KiB (8 | kIOReportScaleKiBytes)
330#define kIOReportScale16KiB (16 | kIOReportScaleKiBytes)
331
332// Clock frequency scales (units add seconds).
333// 1 GHz ticks are 1 ns: 1000 ticks * 1e-6 = 1e-3s
334// This '1' is a no-op for scaling, but allows a custom label.
335#define kIOReportScale1GHz (1 | kIOReportScaleNano)
336// 24MHz ticks are 1/24 of a microsecond: (1/24 * kIOReportScaleMicro [1e-6])s
337// So for example, 240 24Mticks * 1/24 * 1e-6 = .00001s [1e-5]s
338#define kIOReportScale24MHz (kIOReportScaleOneOver|24 |kIOReportScaleMicro)
339
340// --- END: units mechanism
341
342
343// 2. Unit constants
344#define kIOReportUnitNone __IOR_MAKEUNIT(kIOReportQuantityUndefined, \
0a7de745 345 kIOReportScaleUnity)
5ba3f43e
A
346
347#define kIOReportUnit_s __IOR_MAKEUNIT(kIOReportQuantityTime, \
0a7de745 348 kIOReportScaleUnity)
5ba3f43e 349#define kIOReportUnit_ms __IOR_MAKEUNIT(kIOReportQuantityTime, \
0a7de745 350 kIOReportScaleMilli)
5ba3f43e 351#define kIOReportUnit_us __IOR_MAKEUNIT(kIOReportQuantityTime, \
0a7de745 352 kIOReportScaleMicro)
5ba3f43e 353#define kIOReportUnit_ns __IOR_MAKEUNIT(kIOReportQuantityTime, \
0a7de745 354 kIOReportScaleNano)
5ba3f43e
A
355
356#define kIOReportUnit_J __IOR_MAKEUNIT(kIOReportQuantityEnergy, \
0a7de745 357 kIOReportScaleUnity)
5ba3f43e 358#define kIOReportUnit_mJ __IOR_MAKEUNIT(kIOReportQuantityEnergy, \
0a7de745 359 kIOReportScaleMilli)
5ba3f43e 360#define kIOReportUnit_uJ __IOR_MAKEUNIT(kIOReportQuantityEnergy, \
0a7de745 361 kIOReportScaleMicro)
5ba3f43e 362#define kIOReportUnit_nJ __IOR_MAKEUNIT(kIOReportQuantityEnergy, \
0a7de745 363 kIOReportScaleNano)
5ba3f43e 364#define kIOReportUnit_pJ __IOR_MAKEUNIT(kIOReportQuantityEnergy, \
0a7de745 365 kIOReportScalePico)
5ba3f43e
A
366
367#define kIOReportUnitHWTicks __IOR_MAKEUNIT(kIOReportQuantityTime, \
0a7de745 368 kIOReportScaleMachHWTicks)
5ba3f43e 369#define kIOReportUnit24MHzTicks __IOR_MAKEUNIT(kIOReportQuantityTime, \
0a7de745 370 kIOReportScale24MHz)
5ba3f43e 371#define kIOReportUnit1GHzTicks __IOR_MAKEUNIT(kIOReportQuantityTime, \
0a7de745 372 kIOReportScale1GHz)
5ba3f43e
A
373
374#define kIOReportUnitBits __IOR_MAKEUNIT(kIOReportQuantityData, \
0a7de745 375 kIOReportScaleBits)
5ba3f43e 376#define kIOReportUnitBytes __IOR_MAKEUNIT(kIOReportQuantityData, \
0a7de745 377 kIOReportScaleBytes)
5ba3f43e 378#define kIOReportUnit_KiB __IOR_MAKEUNIT(kIOReportQuantityData, \
0a7de745 379 kIOReportScaleKiBytes)
5ba3f43e 380#define kIOReportUnit_MiB __IOR_MAKEUNIT(kIOReportQuantityData, \
0a7de745 381 kIOReportScaleMiBytes)
5ba3f43e 382#define kIOReportUnit_GiB __IOR_MAKEUNIT(kIOReportQuantityData, \
0a7de745 383 kIOReportScaleGiBytes)
5ba3f43e 384#define kIOReportUnit_TiB __IOR_MAKEUNIT(kIOReportQuantityData, \
0a7de745 385 kIOReportScaleTiBytes)
5ba3f43e
A
386
387#define kIOReportUnitEvents __IOR_MAKEUNIT(kIOReportQuantityEventCount, \
0a7de745 388 kIOReportScaleUnity)
5ba3f43e
A
389
390#define kIOReportUnitPackets __IOR_MAKEUNIT(kIOReportQuantityPacketCount, \
0a7de745 391 kIOReportScaleUnity)
5ba3f43e
A
392
393#define kIOReportUnitInstrs __IOR_MAKEUNIT(kIOReportQuantityCPUInstrs, \
0a7de745 394 kIOReportScaleUnity)
5ba3f43e 395#define kIOReportUnit_KI __IOR_MAKEUNIT(kIOReportQuantityCPUInstrs, \
0a7de745 396 kIOReportScaleKilo)
5ba3f43e 397#define kIOReportUnit_MI __IOR_MAKEUNIT(kIOReportQuantityCPUInstrs, \
0a7de745 398 kIOReportScaleMega)
5ba3f43e 399#define kIOReportUnit_GI __IOR_MAKEUNIT(kIOReportQuantityCPUInstrs, \
0a7de745 400 kIOReportScaleGiga)
5ba3f43e
A
401
402// Please file bugs (xnu | IOReporting) for additional units.
403
404// --- END: unit constants
405
406
39236c6e
A
407#ifdef __cplusplus
408}
409#endif
410
411#endif // _IOREPORT_TYPES_H_