VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/DevSmc.cpp@ 86173

Last change on this file since 86173 was 85197, checked in by vboxsync, 4 years ago

DevSmc.cpp: Missing DECLCALLBACK on definitions. bugref:9794

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 56.3 KB
Line 
1/* $Id: DevSmc.cpp 85197 2020-07-10 15:13:25Z vboxsync $ */
2/** @file
3 * DevSmc - Apple System Management Controller.
4 *
5 * The SMC is controlling power, fans, take measurements (voltage, temperature,
6 * fan speed, ++), and lock Mac OS X to Apple hardware. For more details see:
7 * - http://en.wikipedia.org/wiki/System_Management_Controller
8 * - http://www.parhelia.ch/blog/statics/k3_keys.html
9 * - http://www.nosuchcon.org/talks/D1_02_Alex_Ninjas_and_Harry_Potter.pdf
10 */
11
12/*
13 * Copyright (C) 2013-2020 Oracle Corporation
14 *
15 * This file is part of VirtualBox Open Source Edition (OSE), as
16 * available from http://www.virtualbox.org. This file is free software;
17 * you can redistribute it and/or modify it under the terms of the GNU
18 * General Public License (GPL) as published by the Free Software
19 * Foundation, in version 2 as it comes in the "COPYING" file of the
20 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
21 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
22 */
23
24
25/*********************************************************************************************************************************
26* Header Files *
27*********************************************************************************************************************************/
28#define LOG_GROUP LOG_GROUP_DEV_SMC
29#include <VBox/vmm/pdmdev.h>
30#include <VBox/log.h>
31#include <VBox/err.h>
32#include <iprt/assert.h>
33#include <iprt/string.h>
34#ifdef IN_RING0
35# include <iprt/asm-amd64-x86.h>
36# include <iprt/once.h>
37#endif
38#if defined(RT_OS_DARWIN) && defined(IN_RING3)
39# include "IOKit/IOKitLib.h"
40#endif
41
42#include "VBoxDD.h"
43
44
45/*********************************************************************************************************************************
46* Defined Constants And Macros *
47*********************************************************************************************************************************/
48/** The current version of the saved state. */
49#define SMC_SAVED_STATE_VERSION 1 /** @todo later 2 */
50/** Empty saved state version. */
51#define SMC_SAVED_STATE_VERSION_BAKA 1
52
53/** The ring-0 operation number that attempts to get OSK0 and OSK1 from the real
54 * SMC. */
55#define SMC_CALLR0_READ_OSK 1
56
57
58/** @name Apple SMC port and register definitions.
59 * @{ */
60
61/** The first Apple SMC port. */
62#define SMC_PORT_FIRST 0x0300
63/** The number of registers (also ports). */
64#define SMC_REG_COUNT 0x0020
65
66/** The data register. */
67#define SMC_REG_DATA 0x00
68#define SMC_PORT_DATA (SMC_PORT_FIRST + SMC_REG_DATA)
69
70/** The command register. */
71#define SMC_REG_CMD 0x04
72#define SMC_PORT_CMD (SMC_PORT_FIRST + SMC_REG_CMD)
73
74/** Status code register. */
75#define SMC_REG_STATUS_CODE 0x1e
76#define SMC_PORT_STATUS_CODE (SMC_PORT_FIRST + SMC_REG_STATUS_CODE)
77/** @} */
78
79/** @name Apple SMC Commands.
80 * @{ */
81#define SMC_CMD_GET_KEY_VALUE 0x10
82#define SMC_CMD_PUT_KEY 0x11
83#define SMC_CMD_GET_KEY_BY_INDEX 0x12
84#define SMC_CMD_GET_KEY_INFO 0x13
85/** @} */
86
87/** @name Apple SMC Status Codes.
88 * @{ */
89#define SMC_STATUS_CD_SUCCESS UINT8_C(0x00)
90#define SMC_STATUS_CD_COMM_COLLISION UINT8_C(0x80)
91#define SMC_STATUS_CD_SPURIOUS_DATA UINT8_C(0x81)
92#define SMC_STATUS_CD_BAD_COMMAND UINT8_C(0x82)
93#define SMC_STATUS_CD_BAD_PARAMETER UINT8_C(0x83)
94#define SMC_STATUS_CD_KEY_NOT_FOUND UINT8_C(0x84)
95#define SMC_STATUS_CD_KEY_NOT_READABLE UINT8_C(0x85)
96#define SMC_STATUS_CD_KEY_NOT_WRITABLE UINT8_C(0x86)
97#define SMC_STATUS_CD_KEY_SIZE_MISMATCH UINT8_C(0x87)
98#define SMC_STATUS_CD_FRAMING_ERROR UINT8_C(0x88)
99#define SMC_STATUS_CD_BAD_ARGUMENT_ERROR UINT8_C(0x89)
100#define SMC_STATUS_CD_TIMEOUT_ERROR UINT8_C(0xb7)
101#define SMC_STATUS_CD_KEY_INDEX_RANGE_ERROR UINT8_C(0xb8)
102#define SMC_STATUS_CD_BAD_FUNC_PARAMETER UINT8_C(0xc0)
103#define SMC_STATUS_CD_EVENT_BUFF_WRONG_ORDER UINT8_C(0x??)
104#define SMC_STATUS_CD_EVENT_BUFF_READ_ERROR UINT8_C(0x??)
105#define SMC_STATUS_CD_DEVICE_ACCESS_ERROR UINT8_C(0xc7)
106#define SMC_STATUS_CD_UNSUPPORTED_FEATURE UINT8_C(0xcb)
107#define SMC_STATUS_CD_SMB_ACCESS_ERROR UINT8_C(0xcc)
108/** @} */
109
110/** @name Apple SMC Key Attributes.
111 * @{ */
112#define SMC_KEY_ATTR_PRIVATE UINT8_C(0x01)
113#define SMC_KEY_ATTR_UKN_0x02 UINT8_C(0x02)
114#define SMC_KEY_ATTR_UKN_0x04 UINT8_C(0x04)
115#define SMC_KEY_ATTR_CONST UINT8_C(0x08)
116#define SMC_KEY_ATTR_FUNCTION UINT8_C(0x10)
117#define SMC_KEY_ATTR_UKN_0x20 UINT8_C(0x20)
118#define SMC_KEY_ATTR_WRITE UINT8_C(0x40)
119#define SMC_KEY_ATTR_READ UINT8_C(0x80)
120/** @} */
121
122
123/** The index of the first enumerable key in g_aSmcKeys. */
124#define SMC_KEYIDX_FIRST_ENUM 2
125
126/** Macro for emitting a static DEVSMC4CHID initializer. */
127#define SMC4CH(ch1, ch2, ch3, ch4) { { ch1, ch2, ch3, ch4 } }
128
129/**
130 * Macro for comparing DEVSMC4CHID with a string value.
131 * @returns true if equal, false if not.
132 */
133#define SMC4CH_EQ(a_pSmcKey, a_sz4) ( (a_pSmcKey)->u32 == RT_MAKE_U32_FROM_U8(a_sz4[0], a_sz4[1], a_sz4[2], a_sz4[3]) )
134
135/** Indicates the we want a 2.x SMC. */
136#define VBOX_WITH_SMC_2_x
137
138
139/*********************************************************************************************************************************
140* Structures and Typedefs *
141*********************************************************************************************************************************/
142
143/**
144 * 4 char identifier
145 */
146typedef union DEVSMC4CHID
147{
148 /** Byte view. */
149 uint8_t ab[4];
150 /** 32-bit unsigned integer view. */
151 uint32_t u32;
152} DEVSMC4CHID;
153
154
155/**
156 * Current key data area for communicating with the guest.
157 */
158typedef struct DEVSMCCURKEY
159{
160 /** The key. */
161 DEVSMC4CHID Key;
162 /** The data type. */
163 DEVSMC4CHID Type;
164 /** Key attributes. */
165 uint8_t fAttr;
166 /** The value length. */
167 uint8_t cbValue;
168 uint8_t abAlignment[2];
169 /**
170 * The value union. 32 bytes is probably sufficient here, but we provide a
171 * little more room since it doesn't cost us anything. */
172 union
173 {
174 /** Byte view. */
175 uint8_t ab[128];
176 /** 16-bit view. */
177 uint16_t u16;
178 /** 32-bit view. */
179 uint32_t u32;
180 } Value;
181} DEVSMCCURKEY;
182AssertCompileSize(DEVSMCCURKEY, 128+12);
183/** Pointer to the current key buffer. */
184typedef DEVSMCCURKEY *PDEVSMCCURKEY;
185/** Const pointer to the current key buffer. */
186typedef DEVSMCCURKEY const *PCDEVSMCCURKEY;
187
188
189/**
190 * The device
191 */
192typedef struct DEVSMC
193{
194 /** The current command (SMC_PORT_CMD write). */
195 uint8_t bCmd;
196 /** Current key offset. */
197 uint8_t offKey;
198 /** Current value offset. */
199 uint8_t offValue;
200 /** Number of keys in the aKeys array. */
201 uint8_t cKeys;
202
203 /** The current key data the user is accessing. */
204 DEVSMCCURKEY CurKey;
205
206 /**
207 * Generic read/write register values.
208 *
209 * The DATA register entry is not used at all. The CMD register entry contains
210 * the state value.
211 */
212 union
213 {
214 /** Index register view. */
215 uint8_t abRegsRW[SMC_REG_COUNT];
216 /** Named register view. */
217 struct
218 {
219 uint8_t abUnknown0[0x04];
220 /** The current state (SMC_PORT_CMD read). */
221 uint8_t bState;
222 uint8_t abUnknown1[0x1e - 0x05];
223 /** The current status code (SMC_PORT_STATUS_CODE). */
224 uint8_t bStatusCode;
225 uint8_t abUnknown2[1];
226 } s;
227 } u;
228
229 /** @name Key data.
230 * @{ */
231 /** OSK0 and OSK1. */
232 char szOsk0And1[64+1];
233 /** $Num - unknown function. */
234 uint8_t bDollaryNumber;
235 /** MSSD - shutdown reason. */
236 uint8_t bShutdownReason;
237 /** NATJ - Ninja action timer job. */
238 uint8_t bNinjaActionTimerJob;
239 /** @} */
240
241 /** The I/O port registration handle. */
242 IOMIOPORTHANDLE hIoPorts;
243} DEVSMC;
244#ifndef _MSC_VER
245AssertCompileMembersAtSameOffset(DEVSMC, u.abRegsRW[SMC_REG_CMD], DEVSMC, u.s.bState);
246AssertCompileMembersAtSameOffset(DEVSMC, u.abRegsRW[SMC_REG_STATUS_CODE], DEVSMC, u.s.bStatusCode);
247#endif
248
249/** Pointer to the SMC state. */
250typedef DEVSMC *PDEVSMC;
251
252#ifndef VBOX_DEVICE_STRUCT_TESTCASE
253
254
255/**
256 * Method for retriving the key value and/or optionally also attributes.
257 *
258 * @returns Apple SMC Status Code.
259 * @param pThis The SMC instance data.
260 * @param pCurKey The current key structure (input / output).
261 * @param bCmd The current command (mostly for getters that also
262 * provides attributes or type info).
263 * @param pKeyDesc Pointer to the key descriptor so that the getter can
264 * service more than once key.
265 */
266typedef DECLCALLBACKTYPE(uint8_t, FNDEVSMCKEYGETTER,(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd,
267 struct DEVSMCKEYDESC const *pKeyDesc));
268
269/**
270 * Method for setting the key value.
271 *
272 * @returns Apple SMC Status Code.
273 * @param pThis The SMC instance data.
274 * @param pCurKey The current key structure (input / output).
275 * @param bCmd The current command (currently not relevant).
276 * @param pKeyDesc Pointer to the key descriptor so that the getter can
277 * service more than once key.
278 */
279typedef DECLCALLBACKTYPE(uint8_t, FNDEVSMCKEYPUTTER,(PDEVSMC pThis, PCDEVSMCCURKEY pCurKey, uint8_t bCmd,
280 struct DEVSMCKEYDESC const *pKeyDesc));
281
282/**
283 * Key descriptor.
284 */
285typedef struct DEVSMCKEYDESC
286{
287 /** The key 4 character identifier. */
288 DEVSMC4CHID Key;
289 /** Type 4 character identifier. 0 means the getter will set it dynamically. */
290 DEVSMC4CHID Type;
291 /** Getter method, see FNDEVSMCKEYGETTER. */
292 FNDEVSMCKEYGETTER *pfnGet;
293 /** Putter method, see FNDEVSMCKEYPUTTER. */
294 FNDEVSMCKEYPUTTER *pfnPut;
295 /** The keyvalue size. If 0 the pfnGet/pfnPut will define/check the size. */
296 uint8_t cbValue;
297 /** Attributes. 0 means the getter will set it dynamically. */
298 uint8_t fAttr;
299} DEVSMCKEYDESC;
300/** Pointer to a constant SMC key descriptor. */
301typedef DEVSMCKEYDESC const *PCDEVSMCKEYDESC;
302
303
304/*********************************************************************************************************************************
305* Internal Functions *
306*********************************************************************************************************************************/
307static FNDEVSMCKEYGETTER scmKeyGetOSKs;
308static FNDEVSMCKEYGETTER scmKeyGetKeyCount;
309static FNDEVSMCKEYGETTER scmKeyGetRevision;
310#ifdef VBOX_WITH_SMC_2_x
311static FNDEVSMCKEYGETTER scmKeyGetDollarAddress;
312static FNDEVSMCKEYGETTER scmKeyGetDollarNumber;
313static FNDEVSMCKEYPUTTER scmKeyPutDollarNumber;
314#endif
315static FNDEVSMCKEYGETTER scmKeyGetShutdownReason;
316static FNDEVSMCKEYPUTTER scmKeyPutShutdownReason;
317static FNDEVSMCKEYGETTER scmKeyGetNinjaTimerAction;
318static FNDEVSMCKEYPUTTER scmKeyPutNinjaTimerAction;
319static FNDEVSMCKEYGETTER scmKeyGetOne;
320static FNDEVSMCKEYGETTER scmKeyGetZero;
321
322
323/*********************************************************************************************************************************
324* Global Variables *
325*********************************************************************************************************************************/
326/**
327 * Apple SMC key descriptor table.
328 */
329static const DEVSMCKEYDESC g_aSmcKeys[] =
330{
331 /* Non-enum keys first. */
332 { SMC4CH('O','S','K','0'), SMC4CH('c','h','8','*'), scmKeyGetOSKs, NULL, 32, SMC_KEY_ATTR_READ | SMC_KEY_ATTR_FUNCTION },
333 { SMC4CH('O','S','K','1'), SMC4CH('c','h','8','*'), scmKeyGetOSKs, NULL, 32, SMC_KEY_ATTR_READ | SMC_KEY_ATTR_FUNCTION },
334
335 /* The first enum key is the #KEY value. */
336 { SMC4CH('#','K','E','Y'), SMC4CH('u','i','3','2'), scmKeyGetKeyCount, NULL, 4, SMC_KEY_ATTR_READ },
337# ifdef VBOX_WITH_SMC_2_x
338 { SMC4CH('$','A','d','r'), SMC4CH('u','i','3','2'), scmKeyGetDollarAddress, NULL, 4, SMC_KEY_ATTR_READ },
339 { SMC4CH('$','N','u','m'), SMC4CH('u','i','8',' '), scmKeyGetDollarNumber, scmKeyPutDollarNumber, 1, SMC_KEY_ATTR_READ | SMC_KEY_ATTR_WRITE | SMC_KEY_ATTR_PRIVATE },
340 { SMC4CH('B','E','M','B'), SMC4CH('f','l','a','g'), scmKeyGetOne, NULL, 1, SMC_KEY_ATTR_READ },
341# else
342 { SMC4CH('L','S','O','F'), SMC4CH('f','l','a','g'), scmKeyGetZero, NULL, 1, SMC_KEY_ATTR_READ },
343# endif
344 { SMC4CH('M','S','S','D'), SMC4CH('s','i','8',' '), scmKeyGetShutdownReason, scmKeyPutShutdownReason, 1, SMC_KEY_ATTR_READ | SMC_KEY_ATTR_WRITE | SMC_KEY_ATTR_PRIVATE },
345 /* MSDS is not present on MacPro3,1 nor MacBookPro10,1, so returning not found is fine. */
346# ifdef VBOX_WITH_SMC_2_x
347 { SMC4CH('M','S','T','f'), SMC4CH('u','i','8',' '), scmKeyGetZero, NULL, 1, SMC_KEY_ATTR_READ },
348# endif
349 { SMC4CH('N','A','T','J'), SMC4CH('u','i','8',' '), scmKeyGetNinjaTimerAction, scmKeyPutNinjaTimerAction, 1, SMC_KEY_ATTR_READ | SMC_KEY_ATTR_WRITE | SMC_KEY_ATTR_PRIVATE },
350 { SMC4CH('R','E','V',' '), SMC4CH('{','r','e','v'), scmKeyGetRevision, NULL, 6, SMC_KEY_ATTR_READ },
351/** @todo MSSP, NTOK and more. */
352};
353
354#ifdef IN_RING0
355/** Do once for the SMC ring-0 static data (g_abOsk0And1, g_fHaveOsk). */
356static RTONCE g_SmcR0Once = RTONCE_INITIALIZER;
357/** Indicates whether we've successfully queried the OSK* keys. */
358static bool g_fHaveOsk = false;
359/** The OSK0 and OSK1 values. */
360static uint8_t g_abOsk0And1[32+32];
361
362
363/**
364 * Waits for the specified state on the host SMC.
365 *
366 * @returns success indicator.
367 * @param bState The desired state.
368 * @param pszWhat What we're currently doing. For the log.
369 */
370static bool devR0SmcWaitHostState(uint8_t bState, const char *pszWhat)
371{
372 uint8_t bCurState = 0; /* (MSC is potentially uninitialized) */
373 for (uint32_t cMsSleep = 1; cMsSleep <= 64; cMsSleep <<= 1)
374 {
375 RTThreadSleep(cMsSleep);
376 bCurState = ASMInU16(SMC_PORT_CMD);
377 if ((bCurState & 0xf) == bState)
378 return true;
379 }
380
381 LogRel(("devR0Smc: %s: bCurState=%#x, wanted %#x.\n", pszWhat, bCurState, bState));
382#if 0
383 uint8_t bCurStatus2 = ASMInU8(SMC_PORT_STATUS_CODE);
384 uint8_t bCurStatus3 = ASMInU8(SMC_PORT_STATUS_CODE);
385 uint16_t wCurStatus3 = ASMInU16(SMC_PORT_STATUS_CODE);
386 uint32_t dwCurStatus3 = ASMInU32(SMC_PORT_STATUS_CODE);
387 LogRel(("SMC: status2=%#x status3=%#x w=%#x dw=%#x\n", bCurStatus2, bCurStatus3, wCurStatus3, dwCurStatus3));
388#endif
389 return false;
390}
391
392
393/**
394 * Reads a key by name from the host SMC.
395 *
396 * @returns success indicator.
397 * @param pszName The key name, must be exactly 4 chars long.
398 * @param pbBuf The output buffer.
399 * @param cbBuf The buffer size. Max 32 bytes.
400 */
401static bool devR0SmcQueryHostKey(const char *pszName, uint8_t *pbBuf, size_t cbBuf)
402{
403 Assert(strlen(pszName) == 4);
404 Assert(cbBuf <= 32);
405 Assert(cbBuf > 0);
406
407 /*
408 * Issue the READ command.
409 */
410 uint32_t cMsSleep = 1;
411 for (;;)
412 {
413 ASMOutU32(SMC_PORT_CMD, SMC_CMD_GET_KEY_VALUE);
414 RTThreadSleep(cMsSleep);
415 uint8_t bCurState = ASMInU8(SMC_PORT_CMD);
416 if ((bCurState & 0xf) == 0xc)
417 break;
418 cMsSleep <<= 1;
419 if (cMsSleep > 64)
420 {
421 LogRel(("devR0Smc: %s: bCurState=%#x, wanted %#x.\n", "cmd", bCurState, 0xc));
422 return false;
423 }
424 }
425
426 /*
427 * Send it the key.
428 */
429 for (unsigned off = 0; off < 4; off++)
430 {
431 ASMOutU8(SMC_PORT_DATA, pszName[off]);
432 if (!devR0SmcWaitHostState(4, "key"))
433 return false;
434 }
435
436 /*
437 * The desired amount of output.
438 */
439 ASMOutU8(SMC_PORT_DATA, (uint8_t)cbBuf);
440
441 /*
442 * Read the output.
443 */
444 for (size_t off = 0; off < cbBuf; off++)
445 {
446 if (!devR0SmcWaitHostState(5, off ? "data" : "len"))
447 return false;
448 pbBuf[off] = ASMInU8(SMC_PORT_DATA);
449 }
450
451 LogRel(("SMC: pbBuf=%.*s\n", cbBuf, pbBuf));
452 return true;
453}
454
455
456/**
457 * RTOnce callback that initializes g_fHaveOsk and g_abOsk0And1.
458 *
459 * @returns VINF_SUCCESS.
460 * @param pvUserIgnored Ignored.
461 */
462static DECLCALLBACK(int) devR0SmcInitOnce(void *pvUserIgnored)
463{
464 g_fHaveOsk = devR0SmcQueryHostKey("OSK0", &g_abOsk0And1[0], 32)
465 && devR0SmcQueryHostKey("OSK1", &g_abOsk0And1[32], 32);
466
467#if 0
468 /*
469 * Dump the device registers.
470 */
471 for (uint16_t uPort = 0x300; uPort < 0x320; uPort ++)
472 LogRel(("SMC: %#06x=%#010x w={%#06x, %#06x}, b={%#04x %#04x %#04x %#04x}\n", uPort,
473 ASMInU32(uPort), ASMInU16(uPort), ASMInU16(uPort + 2),
474 ASMInU8(uPort), ASMInU8(uPort + 1), ASMInU8(uPort +2), ASMInU8(uPort + 3) ));
475#endif
476
477 NOREF(pvUserIgnored);
478 return VINF_SUCCESS;
479}
480
481
482/**
483 * @interface_method_impl{PDMDEVREGR0,pfnRequest}
484 */
485static DECLCALLBACK(int) devR0SmcReqHandler(PPDMDEVINS pDevIns, uint32_t uReq, uint64_t uArg)
486{
487 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
488 int rc = VERR_INVALID_FUNCTION;
489 RT_NOREF_PV(uArg);
490
491 if (uReq == SMC_CALLR0_READ_OSK)
492 {
493 rc = RTOnce(&g_SmcR0Once, devR0SmcInitOnce, NULL);
494 if ( RT_SUCCESS(rc)
495 && g_fHaveOsk)
496 {
497 AssertCompile(sizeof(g_abOsk0And1) + 1 == sizeof(pThis->szOsk0And1));
498 memcpy(pThis->szOsk0And1, g_abOsk0And1, sizeof(pThis->szOsk0And1) - 1);
499 pThis->szOsk0And1[sizeof(pThis->szOsk0And1) - 1] = '\0';
500 }
501 }
502 return rc;
503}
504
505#endif /* IN_RING0 */
506
507#if defined(IN_RING3) && defined(RT_OS_DARWIN)
508
509/**
510 * Preferred method to retrieve the SMC key.
511 *
512 * @param pabKey where to store the key.
513 * @param cbKey size of the buffer.
514 */
515static int getSmcKeyOs(char *pabKey, uint32_t cbKey)
516{
517 /*
518 * Method as described in Amit Singh's article:
519 * http://osxbook.com/book/bonus/chapter7/tpmdrmmyth/
520 */
521 typedef struct
522 {
523 uint32_t key;
524 uint8_t pad0[22];
525 uint32_t datasize;
526 uint8_t pad1[10];
527 uint8_t cmd;
528 uint32_t pad2;
529 uint8_t data[32];
530 } AppleSMCBuffer;
531
532 AssertReturn(cbKey >= 65, VERR_INTERNAL_ERROR);
533
534 io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
535 IOServiceMatching("AppleSMC"));
536 if (!service)
537 return VERR_NOT_FOUND;
538
539 io_connect_t port = (io_connect_t)0;
540 kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &port);
541 IOObjectRelease(service);
542
543 if (kr != kIOReturnSuccess)
544 return RTErrConvertFromDarwin(kr);
545
546 AppleSMCBuffer inputStruct = { 0, {0}, 32, {0}, 5, };
547 AppleSMCBuffer outputStruct;
548 size_t cbOutputStruct = sizeof(outputStruct);
549
550 for (int i = 0; i < 2; i++)
551 {
552 inputStruct.key = (uint32_t)(i == 0 ? 'OSK0' : 'OSK1');
553 kr = IOConnectCallStructMethod((mach_port_t)port,
554 (uint32_t)2,
555 (const void *)&inputStruct,
556 sizeof(inputStruct),
557 (void *)&outputStruct,
558 &cbOutputStruct);
559 if (kr != kIOReturnSuccess)
560 {
561 IOServiceClose(port);
562 return RTErrConvertFromDarwin(kr);
563 }
564
565 for (int j = 0; j < 32; j++)
566 pabKey[j + i*32] = outputStruct.data[j];
567 }
568
569 IOServiceClose(port);
570
571 pabKey[64] = 0;
572
573 return VINF_SUCCESS;
574}
575
576#endif /* IN_RING3 && RT_OS_DARWIN */
577
578
579/** @callback_method_impl{FNDEVSMCKEYGETTER, OSK0 and OSK1} */
580static DECLCALLBACK(uint8_t) scmKeyGetOSKs(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
581{
582 RT_NOREF1(bCmd);
583 Assert(SMC4CH_EQ(&pKeyDesc->Key, "OSK0") || SMC4CH_EQ(&pKeyDesc->Key, "OSK1"));
584 const char *pszSrc = pThis->szOsk0And1;
585 if (SMC4CH_EQ(&pKeyDesc->Key, "OSK1"))
586 pszSrc += 32;
587 memcpy(pCurKey->Value.ab, pszSrc, 32);
588 return SMC_STATUS_CD_SUCCESS;
589}
590
591
592/** @callback_method_impl{FNDEVSMCKEYGETTER, \#KEY} */
593static DECLCALLBACK(uint8_t) scmKeyGetKeyCount(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
594{
595 RT_NOREF3(pThis, bCmd, pKeyDesc);
596 Assert(pKeyDesc == &g_aSmcKeys[SMC_KEYIDX_FIRST_ENUM]);
597 uint32_t cKeys = RT_ELEMENTS(g_aSmcKeys) - SMC_KEYIDX_FIRST_ENUM;
598 pCurKey->Value.u32 = RT_H2BE_U32(cKeys);
599 return SMC_STATUS_CD_SUCCESS;
600}
601
602
603/** @callback_method_impl{FNDEVSMCKEYGETTER, REV - Source revision.} */
604static DECLCALLBACK(uint8_t) scmKeyGetRevision(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
605{
606 RT_NOREF3(pThis, bCmd, pKeyDesc);
607#ifdef VBOX_WITH_SMC_2_x
608 pCurKey->Value.ab[0] = 0x02;
609 pCurKey->Value.ab[1] = 0x03;
610 pCurKey->Value.ab[2] = 0x0f;
611 pCurKey->Value.ab[3] = 0x00;
612 pCurKey->Value.ab[4] = 0x00;
613 pCurKey->Value.ab[5] = 0x35;
614#else
615 pCurKey->Value.ab[0] = 0x01;
616 pCurKey->Value.ab[1] = 0x25;
617 pCurKey->Value.ab[2] = 0x0f;
618 pCurKey->Value.ab[3] = 0x00;
619 pCurKey->Value.ab[4] = 0x00;
620 pCurKey->Value.ab[5] = 0x04;
621#endif
622 return SMC_STATUS_CD_SUCCESS;
623}
624
625#ifdef VBOX_WITH_SMC_2_x
626
627/** @callback_method_impl{FNDEVSMCKEYGETTER, $Adr - SMC address.} */
628static DECLCALLBACK(uint8_t) scmKeyGetDollarAddress(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
629{
630 RT_NOREF3(pThis, bCmd, pKeyDesc);
631 pCurKey->Value.u32 = RT_H2BE_U32(SMC_PORT_FIRST);
632 return VINF_SUCCESS;
633}
634
635
636/** @callback_method_impl{FNDEVSMCKEYGETTER, $Num - Some kind of number.} */
637static DECLCALLBACK(uint8_t) scmKeyGetDollarNumber(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
638{
639 RT_NOREF2(bCmd, pKeyDesc);
640 pCurKey->Value.ab[0] = pThis->bDollaryNumber;
641 return VINF_SUCCESS;
642}
643
644/** @callback_method_impl{FNDEVSMCKEYPUTTER, $Num - Some kind of number.} */
645static DECLCALLBACK(uint8_t) scmKeyPutDollarNumber(PDEVSMC pThis, PCDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
646{
647 RT_NOREF2(bCmd, pKeyDesc);
648 Log(("scmKeyPutDollarNumber: %#x -> %#x\n", pThis->bDollaryNumber, pCurKey->Value.ab[0]));
649 pThis->bDollaryNumber = pCurKey->Value.ab[0];
650 return VINF_SUCCESS;
651}
652
653#endif /* VBOX_WITH_SMC_2_x */
654
655/** @callback_method_impl{FNDEVSMCKEYGETTER, MSSD - Machine Shutdown reason.} */
656static DECLCALLBACK(uint8_t) scmKeyGetShutdownReason(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
657{
658 RT_NOREF2(bCmd, pKeyDesc);
659 pCurKey->Value.ab[0] = pThis->bShutdownReason;
660 return SMC_STATUS_CD_SUCCESS;
661}
662
663
664/** @callback_method_impl{FNDEVSMCKEYPUTTER, MSSD - Machine Shutdown reason.} */
665static DECLCALLBACK(uint8_t) scmKeyPutShutdownReason(PDEVSMC pThis, PCDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
666{
667 RT_NOREF2(bCmd, pKeyDesc);
668 Log(("scmKeyPutShutdownReason: %#x -> %#x\n", pThis->bShutdownReason, pCurKey->Value.ab[0]));
669 pThis->bShutdownReason = pCurKey->Value.ab[0];
670 return SMC_STATUS_CD_SUCCESS;
671}
672
673
674/** @callback_method_impl{FNDEVSMCKEYGETTER, MSSD - Ninja timer action job.} */
675static DECLCALLBACK(uint8_t)
676scmKeyGetNinjaTimerAction(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
677{
678 RT_NOREF2(bCmd, pKeyDesc);
679 pCurKey->Value.ab[0] = pThis->bNinjaActionTimerJob;
680 return SMC_STATUS_CD_SUCCESS;
681}
682
683
684/** @callback_method_impl{FNDEVSMCKEYPUTTER, NATJ - Ninja timer action job.} */
685static DECLCALLBACK(uint8_t)
686scmKeyPutNinjaTimerAction(PDEVSMC pThis, PCDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
687{
688 RT_NOREF2(bCmd, pKeyDesc);
689 Log(("scmKeyPutNinjaTimerAction: %#x -> %#x\n", pThis->bNinjaActionTimerJob, pCurKey->Value.ab[0]));
690 pThis->bNinjaActionTimerJob = pCurKey->Value.ab[0];
691 return SMC_STATUS_CD_SUCCESS;
692}
693
694#ifdef VBOX_WITH_SMC_2_x
695
696/** @callback_method_impl{FNDEVSMCKEYGETTER, Generic one getter.} */
697static DECLCALLBACK(uint8_t) scmKeyGetOne(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
698{
699 RT_NOREF2(pThis, bCmd);
700 memset(&pCurKey->Value.ab[0], 0, pKeyDesc->cbValue);
701 pCurKey->Value.ab[pKeyDesc->cbValue - 1] = 1;
702 return SMC_STATUS_CD_SUCCESS;
703}
704
705#endif /* VBOX_WITH_SMC_2_x */
706
707/** @callback_method_impl{FNDEVSMCKEYGETTER, Generic zero getter.} */
708static DECLCALLBACK(uint8_t) scmKeyGetZero(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
709{
710 RT_NOREF2(pThis, bCmd);
711 memset(&pCurKey->Value.ab[0], 0, pKeyDesc->cbValue);
712 return SMC_STATUS_CD_SUCCESS;
713}
714
715
716/**
717 * Looks up a key and copies its value and attributes into the CurKey.
718 *
719 * @returns Key index on success, UINT32_MAX on failure.
720 * @param uKeyValue The key value (DEVSMC4CHID.u32).
721 */
722static uint32_t smcKeyLookup(uint32_t uKeyValue)
723{
724 uint32_t iKey = RT_ELEMENTS(g_aSmcKeys);
725 while (iKey-- > 0)
726 if (g_aSmcKeys[iKey].Key.u32 == uKeyValue)
727 return iKey;
728 return UINT32_MAX;
729}
730
731
732/**
733 * Looks up a key and copies its value and attributes into the CurKey.
734 *
735 * @returns Apple SMC Status Code.
736 * @param pThis The SMC instance data.
737 */
738static uint8_t smcKeyGetByName(PDEVSMC pThis)
739{
740 uint8_t bRc;
741#ifdef LOG_ENABLED
742 uint32_t const uKeyValueLog = RT_H2LE_U32(pThis->CurKey.Key.u32);
743#endif
744 uint32_t iKey = smcKeyLookup(pThis->CurKey.Key.u32);
745 if (iKey != UINT32_MAX)
746 {
747 if ( g_aSmcKeys[iKey].cbValue == pThis->CurKey.cbValue
748 || !g_aSmcKeys[iKey].cbValue)
749 {
750 pThis->CurKey.Type = g_aSmcKeys[iKey].Type;
751 pThis->CurKey.fAttr = g_aSmcKeys[iKey].fAttr;
752 RT_ZERO(pThis->CurKey.Value);
753 if (g_aSmcKeys[iKey].pfnGet)
754 {
755 bRc = g_aSmcKeys[iKey].pfnGet(pThis, &pThis->CurKey, pThis->bCmd, &g_aSmcKeys[iKey]);
756 if (bRc == SMC_STATUS_CD_SUCCESS)
757 {
758 LogFlow(("smcKeyGetByName: key=%4.4s value=%.*Rhxs\n",
759 &uKeyValueLog, pThis->CurKey.cbValue, &pThis->CurKey.Value));
760 return SMC_STATUS_CD_SUCCESS;
761 }
762
763 Log(("smcKeyGetByName: key=%4.4s getter failed! bRc=%#x\n", &uKeyValueLog, bRc));
764 }
765 else
766 {
767 Log(("smcKeyGetByName: key=%4.4s is not readable!\n", &uKeyValueLog));
768 bRc = SMC_STATUS_CD_KEY_NOT_READABLE;
769 }
770 }
771 else
772 {
773 Log(("smcKeyGetByName: Wrong value size; user=%#x smc=%#x key=%4.4s !\n",
774 pThis->CurKey.cbValue, g_aSmcKeys[iKey].cbValue, &uKeyValueLog));
775 bRc = SMC_STATUS_CD_KEY_SIZE_MISMATCH;
776 }
777 }
778 else
779 {
780 Log(("smcKeyGetByName: Key not found! key=%4.4s size=%#x\n", &uKeyValueLog, pThis->CurKey.cbValue));
781 bRc = SMC_STATUS_CD_KEY_NOT_FOUND;
782 }
783
784 RT_ZERO(pThis->CurKey);
785 return bRc;
786}
787
788
789/**
790 * Looks up a key by index and copies its name (and attributes) into the CurKey.
791 *
792 * @returns Apple SMC Status Code.
793 * @param pThis The SMC instance data.
794 */
795static uint8_t smcKeyGetByIndex(PDEVSMC pThis)
796{
797 uint8_t bRc;
798 uint32_t iKey = RT_BE2H_U32(pThis->CurKey.Key.u32);
799 if (iKey < RT_ELEMENTS(g_aSmcKeys) - SMC_KEYIDX_FIRST_ENUM)
800 {
801 pThis->CurKey.Key = g_aSmcKeys[iKey].Key;
802 pThis->CurKey.Type = g_aSmcKeys[iKey].Type;
803 pThis->CurKey.fAttr = g_aSmcKeys[iKey].fAttr;
804 pThis->CurKey.cbValue = g_aSmcKeys[iKey].cbValue;
805 RT_ZERO(pThis->CurKey.Value);
806 Log(("smcKeyGetByIndex: %#x -> %c%c%c%c\n", iKey,
807 pThis->CurKey.Key.ab[3], pThis->CurKey.Key.ab[2], pThis->CurKey.Key.ab[1], pThis->CurKey.Key.ab[0]));
808 bRc = SMC_STATUS_CD_SUCCESS;
809 }
810 else
811 {
812 Log(("smcKeyGetByIndex: Key out or range: %#x, max %#x\n", iKey, RT_ELEMENTS(g_aSmcKeys) - SMC_KEYIDX_FIRST_ENUM));
813 bRc = SMC_STATUS_CD_KEY_NOT_FOUND;
814 }
815 return bRc;
816}
817
818
819/**
820 * Looks up a key by index and copies its attributes into the CurKey.
821 *
822 * @returns Apple SMC Status Code.
823 * @param pThis The SMC instance data.
824 */
825static uint8_t smcKeyGetAttrByName(PDEVSMC pThis)
826{
827 uint8_t bRc;
828#ifdef LOG_ENABLED
829 uint32_t const uKeyValueLog = RT_H2LE_U32(pThis->CurKey.Key.u32);
830#endif
831 uint32_t iKey = smcKeyLookup(pThis->CurKey.Key.u32);
832 if (iKey != UINT32_MAX)
833 {
834 pThis->CurKey.Type = g_aSmcKeys[iKey].Type;
835 pThis->CurKey.fAttr = g_aSmcKeys[iKey].fAttr;
836 pThis->CurKey.cbValue = g_aSmcKeys[iKey].cbValue;
837 RT_ZERO(pThis->CurKey.Value);
838 if (g_aSmcKeys[iKey].cbValue)
839 bRc = SMC_STATUS_CD_SUCCESS;
840 else
841 bRc = g_aSmcKeys[iKey].pfnGet(pThis, &pThis->CurKey, pThis->bCmd, &g_aSmcKeys[iKey]);
842 if (bRc == SMC_STATUS_CD_SUCCESS)
843 {
844 LogFlow(("smcKeyGetAttrByName: key=%4.4s value=%.*Rhxs\n",
845 &uKeyValueLog, pThis->CurKey.cbValue, &pThis->CurKey.Value));
846 return SMC_STATUS_CD_SUCCESS;
847 }
848
849 Log(("smcKeyGetAttrByName: key=%4.4s getter failed! bRc=%#x\n", &uKeyValueLog, bRc));
850 }
851 else
852 {
853 Log(("smcKeyGetAttrByName: Key not found! key=%4.4s size=%#x\n", &uKeyValueLog, pThis->CurKey.cbValue));
854 bRc = SMC_STATUS_CD_KEY_NOT_FOUND;
855 }
856
857 RT_ZERO(pThis->CurKey);
858 return bRc;
859}
860
861
862static uint8_t smcKeyPutPrepare(PDEVSMC pThis)
863{
864 RT_NOREF1(pThis);
865 return 0;
866}
867
868static uint8_t smcKeyPutValue(PDEVSMC pThis)
869{
870 RT_NOREF1(pThis);
871 return 0;
872}
873
874
875/**
876 * Data register read.
877 *
878 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
879 * @param uReg The register number.
880 * @param pbValue Where to return the value.
881 */
882static VBOXSTRICTRC smcRegData_r(PDEVSMC pThis, uint8_t uReg, uint8_t *pbValue)
883{
884 RT_NOREF1(uReg);
885 switch (pThis->bCmd)
886 {
887 case SMC_CMD_GET_KEY_VALUE:
888 if ( pThis->u.s.bState == 0x05
889 && pThis->offValue < pThis->CurKey.cbValue)
890 {
891 *pbValue = pThis->CurKey.Value.ab[pThis->offValue];
892 if (++pThis->offValue >= pThis->CurKey.cbValue)
893 pThis->u.s.bState = 0x00;
894 pThis->u.s.bStatusCode = SMC_STATUS_CD_SUCCESS;
895 }
896 else
897 {
898 Log(("smcRegData_r: Reading too much or at wrong time during SMC_CMD_GET_KEY_INFO! bState=%#x offValue=%#x\n",
899 pThis->u.s.bState, pThis->offValue));
900 pThis->u.s.bState = 0x00;
901 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA; /** @todo check status code */
902 }
903 break;
904
905 case SMC_CMD_GET_KEY_INFO:
906 if ( pThis->u.s.bState == 0x05
907 && pThis->offValue < 6)
908 {
909 if (pThis->offValue == 0)
910 *pbValue = pThis->CurKey.cbValue;
911 else if (pThis->offValue < 1 + 4)
912 *pbValue = pThis->CurKey.Type.ab[pThis->offValue - 1];
913 else
914 *pbValue = pThis->CurKey.fAttr;
915 if (++pThis->offValue >= 6)
916 pThis->u.s.bState = 0x00;
917 pThis->u.s.bStatusCode = SMC_STATUS_CD_SUCCESS;
918 }
919 else
920 {
921 Log(("smcRegData_r: Reading too much or at wrong time during SMC_CMD_GET_KEY_INFO! bState=%#x offValue=%#x\n",
922 pThis->u.s.bState, pThis->offValue));
923 pThis->u.s.bState = 0x00;
924 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA; /** @todo check status code */
925 }
926 break;
927
928 case SMC_CMD_GET_KEY_BY_INDEX:
929 if ( pThis->u.s.bState == 0x05
930 && pThis->offValue < sizeof(pThis->CurKey.Key))
931 {
932 *pbValue = pThis->CurKey.Key.ab[pThis->offValue];
933 if (++pThis->offValue >= sizeof(pThis->CurKey.Key))
934 pThis->u.s.bState = 0x00;
935 pThis->u.s.bStatusCode = SMC_STATUS_CD_SUCCESS;
936 }
937 else
938 {
939 Log(("smcRegData_r: Reading too much or at wrong time during GET_KEY_BY_INDEX! bState=%#x offValue=%#x\n",
940 pThis->u.s.bState, pThis->offValue));
941 pThis->u.s.bState = 0x00;
942 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA; /** @todo check status code */
943 }
944 break;
945
946 case SMC_CMD_PUT_KEY:
947 Log(("smcRegData_r: Attempting to read data during PUT_KEY!\n"));
948 *pbValue = 0xff;
949 pThis->u.s.bState = 0;
950 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA;
951 break;
952
953 default:
954 Log(("smcRegData_r: Unknown command attempts reading data\n"));
955 *pbValue = 0xff;
956 pThis->u.s.bState = 0;
957 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA;
958 break;
959 }
960
961 return VINF_SUCCESS;
962}
963
964
965/**
966 * Data register write.
967 *
968 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
969 * @param uReg The register number.
970 * @param bValue The value being written.
971 */
972static VBOXSTRICTRC smcRegData_w(PDEVSMC pThis, uint8_t uReg, uint8_t bValue)
973{
974 RT_NOREF1(uReg);
975 switch (pThis->bCmd)
976 {
977 /*
978 * Get or put key value.
979 *
980 * 5 bytes written, first 4 is the key the 5th is the value size. In
981 * the case of a put the value bytes are then written, while a get will
982 * read the value bytes.
983 */
984 case SMC_CMD_GET_KEY_VALUE:
985 case SMC_CMD_PUT_KEY:
986 if (pThis->offKey < 4)
987 {
988 /* Key byte. */
989 pThis->CurKey.Key.ab[pThis->offKey++] = bValue;
990 pThis->u.s.bState = 0x04;
991 pThis->u.s.bStatusCode = SMC_STATUS_CD_SUCCESS;
992 }
993 else if (pThis->offKey == 4)
994 {
995 /* Data length. */
996 pThis->u.s.bState = 0;
997 if (bValue <= sizeof(pThis->CurKey.Value))
998 {
999 pThis->CurKey.cbValue = bValue;
1000 pThis->offKey = 5;
1001 Assert(pThis->offValue == 0);
1002
1003 if (pThis->bCmd == SMC_CMD_GET_KEY_VALUE)
1004 pThis->u.s.bStatusCode = smcKeyGetByName(pThis);
1005 else
1006 pThis->u.s.bStatusCode = smcKeyPutPrepare(pThis);
1007 if (pThis->u.s.bStatusCode == SMC_STATUS_CD_SUCCESS)
1008 pThis->u.s.bState = 0x05;
1009 }
1010 else
1011 {
1012 Log(("smcRegData_w: Guest attempts to get/put too many value bytes: %#x (max %#x)!\n",
1013 bValue, sizeof(pThis->CurKey.Value)));
1014 pThis->u.s.bStatusCode = SMC_STATUS_CD_KEY_SIZE_MISMATCH; /** @todo check this case! */
1015 }
1016 }
1017 else if ( pThis->bCmd == SMC_CMD_PUT_KEY
1018 && pThis->offValue < pThis->CurKey.cbValue)
1019 {
1020 /* More value bytes for put key action. */
1021 pThis->CurKey.Value.ab[pThis->offValue++] = bValue;
1022 if (pThis->offValue != pThis->CurKey.cbValue)
1023 pThis->u.s.bState = 0x05;
1024 else
1025 {
1026 pThis->u.s.bState = 0x00;
1027 pThis->u.s.bStatusCode = smcKeyPutValue(pThis);
1028 }
1029 }
1030 else
1031 {
1032 Log(("smcRegData_w: Writing too much data on %s command!\n", pThis->bCmd == SMC_CMD_PUT_KEY ? "put" : "get"));
1033 pThis->u.s.bState = 0x00;
1034 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA;
1035 }
1036 break;
1037
1038 /*
1039 * Get key info and key by index seems to take action after the last
1040 * key char is written. They then both go into a data reading phase.
1041 */
1042 case SMC_CMD_GET_KEY_INFO:
1043 case SMC_CMD_GET_KEY_BY_INDEX:
1044 if (pThis->offKey < 4)
1045 {
1046 pThis->CurKey.Key.ab[pThis->offKey] = bValue;
1047 if (++pThis->offKey == 4)
1048 {
1049 if (pThis->bCmd == SMC_CMD_GET_KEY_BY_INDEX)
1050 pThis->u.s.bStatusCode = smcKeyGetByIndex(pThis);
1051 else
1052 pThis->u.s.bStatusCode = smcKeyGetAttrByName(pThis);
1053 pThis->u.s.bState = pThis->u.s.bStatusCode == SMC_STATUS_CD_SUCCESS ? 0x05 : 0x00;
1054 }
1055 else
1056 {
1057 pThis->u.s.bState = 0x04;
1058 pThis->u.s.bStatusCode = SMC_STATUS_CD_SUCCESS;
1059 }
1060 }
1061 else
1062 {
1063 Log(("smcRegData_w: Writing data beyond 5th byte on get %s command!\n",
1064 pThis->bCmd == SMC_CMD_GET_KEY_INFO ? "info" : "by index"));
1065 pThis->u.s.bState = 0x00;
1066 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA;
1067 }
1068 break;
1069
1070 default:
1071 Log(("smcRegData_w: Unknown command %#x!\n", bValue));
1072 pThis->u.s.bState = 0x00; /** @todo Check statuses with real HW. */
1073 pThis->u.s.bStatusCode = SMC_STATUS_CD_BAD_COMMAND;
1074 break;
1075 }
1076 return VINF_SUCCESS;
1077}
1078
1079
1080/**
1081 * Command register write.
1082 *
1083 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
1084 * @param uReg The register number.
1085 * @param bValue The value being written.
1086 */
1087static VBOXSTRICTRC smcRegCmd_w(PDEVSMC pThis, uint8_t uReg, uint8_t bValue)
1088{
1089 LogFlow(("smcRegCmd_w: New command: %#x (old=%#x)\n", bValue, pThis->bCmd)); NOREF(uReg);
1090
1091 pThis->bCmd = bValue;
1092
1093 /* Validate the command. */
1094 switch (bValue)
1095 {
1096 case SMC_CMD_GET_KEY_VALUE:
1097 case SMC_CMD_PUT_KEY:
1098 case SMC_CMD_GET_KEY_BY_INDEX:
1099 case SMC_CMD_GET_KEY_INFO:
1100 pThis->u.s.bState = 0x0c;
1101 pThis->u.s.bStatusCode = SMC_STATUS_CD_SUCCESS;
1102 break;
1103
1104 default:
1105 Log(("SMC: Unknown command %#x!\n", bValue));
1106 pThis->u.s.bState = 0x00; /** @todo Check state with real HW. */
1107 pThis->u.s.bStatusCode = SMC_STATUS_CD_BAD_COMMAND;
1108 break;
1109 }
1110
1111 /* Reset the value/key related state. */
1112 pThis->offKey = 0;
1113 pThis->offValue = 0;
1114 pThis->CurKey.Key.u32 = 0;
1115 pThis->CurKey.cbValue = 0;
1116
1117 return VINF_SUCCESS;
1118}
1119
1120
1121/**
1122 * Generic register write.
1123 *
1124 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
1125 * @param uReg The register number.
1126 * @param bValue The value being written.
1127 */
1128static VBOXSTRICTRC smcRegGen_w(PDEVSMC pThis, uint8_t uReg, uint8_t bValue)
1129{
1130 Log(("smcRegGen_w: %#04x: %#x -> %#x (write)\n", uReg, pThis->u.abRegsRW[uReg], bValue));
1131 pThis->u.abRegsRW[uReg] = bValue;
1132 return VINF_SUCCESS;
1133}
1134
1135
1136/**
1137 * Read from register that isn't writable and reads as 0xFF.
1138 *
1139 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
1140 * @param uReg The register number.
1141 * @param pbValue Where to return the value.
1142 */
1143static VBOXSTRICTRC smcRegGen_r(PDEVSMC pThis, uint8_t uReg, uint8_t *pbValue)
1144{
1145 Log(("smcRegGen_r: %#04x: %#x (read)\n", uReg, pThis->u.abRegsRW[uReg]));
1146 *pbValue = pThis->u.abRegsRW[uReg];
1147 return VINF_SUCCESS;
1148}
1149
1150
1151/**
1152 * Write to register that isn't writable and reads as 0xFF.
1153 *
1154 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
1155 * @param uReg The register number.
1156 * @param bValue The value being written.
1157 */
1158static VBOXSTRICTRC smcRegFF_w(PDEVSMC pThis, uint8_t uReg, uint8_t bValue)
1159{
1160 RT_NOREF3(pThis, uReg, bValue);
1161 Log(("SMC: %#04x: Writing %#x to unknown register!\n", uReg, bValue));
1162 return VINF_SUCCESS;
1163}
1164
1165
1166/**
1167 * Read from register that isn't writable and reads as 0xFF.
1168 *
1169 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
1170 * @param uReg The register number.
1171 * @param pbValue Where to return the value.
1172 */
1173static VBOXSTRICTRC smcRegFF_r(PDEVSMC pThis, uint8_t uReg, uint8_t *pbValue)
1174{
1175 RT_NOREF2(pThis, uReg);
1176 Log(("SMC: %#04x: Reading from unknown register!\n", uReg));
1177 *pbValue = 0xff;
1178 return VINF_SUCCESS;
1179}
1180
1181
1182
1183/**
1184 * SMC register handlers (indexed by relative I/O port).
1185 *
1186 * The device seems to be all byte registers and will split wider
1187 * accesses between registers like if it was MMIO. To better illustrate it
1188 * here is the output of the code in devR0SmcInitOnce on a MacPro3,1:
1189 * @verbatim
1190 * SMC: 0x0300=0xffffff63 w={0xff63, 0xffff}, b={0x63 0xff 0xff 0xff}
1191 * SMC: 0x0301=0x0cffffff w={0xffff, 0x0cff}, b={0xff 0xff 0xff 0x0c}
1192 * SMC: 0x0302=0xff0cffff w={0xffff, 0xff0c}, b={0xff 0xff 0x0c 0xff}
1193 * SMC: 0x0303=0xffff0cff w={0x0cff, 0xffff}, b={0xff 0x0c 0xff 0xff}
1194 * SMC: 0x0304=0xffffff0c w={0xff0c, 0xffff}, b={0x0c 0xff 0xff 0xff}
1195 * SMC: 0x0305=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1196 * SMC: 0x0306=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1197 * SMC: 0x0307=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1198 * SMC: 0x0308=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1199 * SMC: 0x0309=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1200 * SMC: 0x030a=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1201 * SMC: 0x030b=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1202 * SMC: 0x030c=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1203 * SMC: 0x030d=0x00ffffff w={0xffff, 0x00ff}, b={0xff 0xff 0xff 0x00}
1204 * SMC: 0x030e=0x0000ffff w={0xffff, 0x0000}, b={0xff 0xff 0x00 0x00}
1205 * SMC: 0x030f=0x000000ff w={0x00ff, 0x0000}, b={0xff 0x00 0x00 0x00}
1206 * SMC: 0x0310=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1207 * SMC: 0x0311=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1208 * SMC: 0x0312=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1209 * SMC: 0x0313=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1210 * SMC: 0x0314=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1211 * SMC: 0x0315=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1212 * SMC: 0x0316=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1213 * SMC: 0x0317=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1214 * SMC: 0x0318=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1215 * SMC: 0x0319=0xbe000000 w={0x0000, 0xbe00}, b={0x00 0x00 0x00 0xbe}
1216 * SMC: 0x031a=0xbabe0000 w={0x0000, 0xbabe}, b={0x00 0x00 0xbe 0xba}
1217 * SMC: 0x031b=0x00babe00 w={0xbe00, 0x00ba}, b={0x00 0xbe 0xba 0x00}
1218 * SMC: 0x031c=0xbe00babe w={0xbabe, 0xbe00}, b={0xbe 0xba 0x00 0xbe}
1219 * SMC: 0x031d=0xffbe00ba w={0x00ba, 0xffbe}, b={0xba 0x00 0xbe 0xff}
1220 * SMC: 0x031e=0xffffbe00 w={0xbe00, 0xffff}, b={0x00 0xbe 0xff 0xff}
1221 * SMC: 0x031f=0xffffffbe w={0xffbe, 0xffff}, b={0xbe 0xff 0xff 0xff}
1222 * @endverbatim
1223 *
1224 * The last dword is writable (0xbeXXbabe) where in the register at 0x1e is some
1225 * kind of status register for qualifying search failures and the like and will
1226 * be cleared under certain conditions. The whole dword can be written and read
1227 * back unchanged, according to my experiments. The 0x00 and 0x04 registers
1228 * does not read back what is written.
1229 *
1230 * My guess is that the 0xff values indicates ports that are not writable and
1231 * hardwired to 0xff, while the other values indicates ports that can be written
1232 * to and normally read back as written. I'm not going to push my luck too far
1233 * wrt to exact behavior until I see the guest using the registers.
1234 */
1235static const struct
1236{
1237 VBOXSTRICTRC (*pfnWrite)(PDEVSMC pThis, uint8_t uReg, uint8_t bValue);
1238 VBOXSTRICTRC (*pfnRead)(PDEVSMC pThis, uint8_t uReg, uint8_t *pbValue);
1239} g_aSmcRegs[SMC_REG_COUNT] =
1240{
1241 /* [0x00] = */ { smcRegData_w, smcRegData_r },
1242 /* [0x01] = */ { smcRegFF_w, smcRegFF_r },
1243 /* [0x02] = */ { smcRegFF_w, smcRegFF_r },
1244 /* [0x03] = */ { smcRegFF_w, smcRegFF_r },
1245 /* [0x04] = */ { smcRegCmd_w, smcRegGen_r },
1246 /* [0x05] = */ { smcRegFF_w, smcRegFF_r },
1247 /* [0x06] = */ { smcRegFF_w, smcRegFF_r },
1248 /* [0x07] = */ { smcRegFF_w, smcRegFF_r },
1249 /* [0x08] = */ { smcRegFF_w, smcRegFF_r },
1250 /* [0x09] = */ { smcRegFF_w, smcRegFF_r },
1251 /* [0x0a] = */ { smcRegFF_w, smcRegFF_r },
1252 /* [0x0b] = */ { smcRegFF_w, smcRegFF_r },
1253 /* [0x0c] = */ { smcRegFF_w, smcRegFF_r },
1254 /* [0x0d] = */ { smcRegFF_w, smcRegFF_r },
1255 /* [0x0e] = */ { smcRegFF_w, smcRegFF_r },
1256 /* [0x0f] = */ { smcRegFF_w, smcRegFF_r },
1257 /* [0x10] = */ { smcRegGen_w, smcRegGen_r },
1258 /* [0x11] = */ { smcRegGen_w, smcRegGen_r },
1259 /* [0x12] = */ { smcRegGen_w, smcRegGen_r },
1260 /* [0x13] = */ { smcRegGen_w, smcRegGen_r },
1261 /* [0x14] = */ { smcRegGen_w, smcRegGen_r },
1262 /* [0x15] = */ { smcRegGen_w, smcRegGen_r },
1263 /* [0x16] = */ { smcRegGen_w, smcRegGen_r },
1264 /* [0x17] = */ { smcRegGen_w, smcRegGen_r },
1265 /* [0x18] = */ { smcRegGen_w, smcRegGen_r },
1266 /* [0x19] = */ { smcRegGen_w, smcRegGen_r },
1267 /* [0x1a] = */ { smcRegGen_w, smcRegGen_r },
1268 /* [0x1b] = */ { smcRegGen_w, smcRegGen_r },
1269 /* [0x1c] = */ { smcRegGen_w, smcRegGen_r },
1270 /* [0x1d] = */ { smcRegGen_w, smcRegGen_r },
1271 /* [0x1e] = */ { smcRegGen_w, smcRegGen_r },
1272 /* [0x1f] = */ { smcRegGen_w, smcRegGen_r },
1273};
1274
1275
1276/**
1277 * @callback_method_impl{FNIOMIOPORTNEWOUT}
1278 */
1279static DECLCALLBACK(VBOXSTRICTRC) smcIoPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
1280{
1281 RT_NOREF1(pvUser);
1282#ifndef IN_RING3
1283 if (cb > 1)
1284 {
1285 Log3(("smcIoPortWrite: %#04x write access: %#x (LB %u) -> ring-3\n", offPort, u32, cb));
1286 return VINF_IOM_R3_IOPORT_WRITE;
1287 }
1288#endif
1289#ifdef LOG_ENABLED
1290 RTIOPORT const offPortLog = offPort;
1291 unsigned const cbLog = cb;
1292#endif
1293
1294 /*
1295 * The first register, usually only one is accessed.
1296 */
1297 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
1298 AssertReturn(offPort < RT_ELEMENTS(g_aSmcRegs), VERR_INTERNAL_ERROR_3); /* impossible*/
1299 VBOXSTRICTRC rc = g_aSmcRegs[offPort].pfnWrite(pThis, offPort, u32);
1300
1301 /*
1302 * On the off chance that multiple registers are being read.
1303 */
1304 if (cb > 1)
1305 {
1306 while (cb > 1 && offPort < SMC_REG_COUNT - 1)
1307 {
1308 cb--;
1309 offPort++;
1310 u32 >>= 8;
1311 VBOXSTRICTRC rc2 = g_aSmcRegs[offPort].pfnWrite(pThis, offPort, u32);
1312 if (rc2 != VINF_SUCCESS)
1313 {
1314 if ( rc == VINF_SUCCESS
1315 || (RT_FAILURE(rc2) && RT_SUCCESS(rc))
1316 || (rc2 < rc && RT_SUCCESS(rc2) && RT_SUCCESS(rc)))
1317 rc = rc2;
1318 }
1319 }
1320 }
1321
1322 LogFlow(("smcIoPortWrite: %#04x write access: %#x (LB %u) rc=%Rrc\n", offPortLog, u32, cbLog, VBOXSTRICTRC_VAL(rc) ));
1323 return rc;
1324}
1325
1326
1327/**
1328 * @callback_method_impl{FNIOMIOPORTNEWIN}
1329 */
1330static DECLCALLBACK(VBOXSTRICTRC) smcIoPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
1331{
1332 RT_NOREF1(pvUser);
1333#ifndef IN_RING3
1334 if (cb > 1)
1335 return VINF_IOM_R3_IOPORT_READ;
1336#endif
1337
1338 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
1339#ifdef LOG_ENABLED
1340 RTIOPORT const offPortLog = offPort;
1341 unsigned const cbLog = cb;
1342#endif
1343
1344 /*
1345 * The first register, usually only one is accessed.
1346 */
1347 AssertReturn(offPort < RT_ELEMENTS(g_aSmcRegs), VERR_INTERNAL_ERROR_3); /* impossible*/
1348 Log2(("smcIoPortRead: %#04x read access: LB %u\n", offPort, cb));
1349 uint8_t bValue = 0xff;
1350 VBOXSTRICTRC rc = g_aSmcRegs[offPort].pfnRead(pThis, offPort, &bValue);
1351 *pu32 = bValue;
1352
1353 /*
1354 * On the off chance that multiple registers are being read.
1355 */
1356 if (cb > 1)
1357 {
1358 do
1359 {
1360 cb--;
1361 offPort++;
1362 bValue = 0xff;
1363 if (offPort < SMC_REG_COUNT)
1364 {
1365 VBOXSTRICTRC rc2 = g_aSmcRegs[offPort].pfnRead(pThis, offPort, &bValue);
1366 if (rc2 != VINF_SUCCESS)
1367 {
1368 if ( rc == VINF_SUCCESS
1369 || (RT_FAILURE(rc2) && RT_SUCCESS(rc))
1370 || (rc2 < rc && RT_SUCCESS(rc2) && RT_SUCCESS(rc)))
1371 rc = rc2;
1372 }
1373 }
1374 *pu32 |= (uint32_t)bValue << ((4 - cb) * 8);
1375 } while (cb > 1);
1376 }
1377 LogFlow(("smcIoPortRead: %#04x read access: %#x (LB %u) rc=%Rrc\n", offPortLog, *pu32, cbLog, VBOXSTRICTRC_VAL(rc)));
1378 return rc;
1379}
1380
1381#ifdef IN_RING3
1382
1383/** @callback_method_impl{FNSSMDEVSAVEEXEC} */
1384static DECLCALLBACK(int) smcR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
1385{
1386 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
1387 RT_NOREF2(pSSM, pThis);
1388
1389 /** @todo */
1390
1391 return VINF_SUCCESS;
1392}
1393
1394
1395/** @callback_method_impl{FNSSMDEVLOADEXEC} */
1396static DECLCALLBACK(int) smcR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
1397{
1398 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
1399 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
1400 RT_NOREF2(pSSM, pThis);
1401
1402 /* Fend off unsupported versions. */
1403 if ( uVersion != SMC_SAVED_STATE_VERSION
1404#if SMC_SAVED_STATE_VERSION != SMC_SAVED_STATE_VERSION_BAKA
1405 && uVersion != SMC_SAVED_STATE_VERSION_BAKA
1406#endif
1407 && uVersion != SMC_SAVED_STATE_VERSION_BAKA + 1)
1408 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
1409
1410 /*
1411 * Do the actual restoring.
1412 */
1413 if (uVersion == SMC_SAVED_STATE_VERSION)
1414 {
1415 /** @todo */
1416 }
1417
1418 return VINF_SUCCESS;
1419}
1420
1421
1422/**
1423 * @interface_method_impl{PDMDEVREG,pfnConstruct}
1424 */
1425static DECLCALLBACK(int) smcR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
1426{
1427 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
1428 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
1429 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
1430
1431 Assert(iInstance == 0); RT_NOREF1(iInstance);
1432
1433 /*
1434 * Init the data.
1435 */
1436 pThis->bDollaryNumber = 1;
1437 pThis->bShutdownReason = 3; /* STOP_CAUSE_POWERKEY_GOOD_CODE */
1438
1439 /*
1440 * Validate configuration.
1441 */
1442 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "DeviceKey|GetKeyFromRealSMC", "");
1443
1444 /*
1445 * Read configuration.
1446 */
1447
1448 /* The DeviceKey sets OSK0 and OSK1. */
1449 int rc = pHlp->pfnCFGMQueryStringDef(pCfg, "DeviceKey", pThis->szOsk0And1, sizeof(pThis->szOsk0And1), "");
1450 if (RT_FAILURE(rc))
1451 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
1452 N_("Configuration error: Querying \"DeviceKey\" as a string failed"));
1453
1454 /* Query the key from the OS / real hardware if asked to do so. */
1455 bool fGetKeyFromRealSMC;
1456 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "GetKeyFromRealSMC", &fGetKeyFromRealSMC, false);
1457 if (RT_FAILURE(rc))
1458 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
1459 N_("Configuration error: Querying \"GetKeyFromRealSMC\" as a boolean failed"));
1460 if (fGetKeyFromRealSMC)
1461 {
1462# ifdef RT_OS_DARWIN
1463 rc = getSmcKeyOs(pThis->szOsk0And1, sizeof(pThis->szOsk0And1));
1464 if (RT_FAILURE(rc))
1465 {
1466 LogRel(("SMC: Retrieving the SMC key from the OS failed (%Rrc), trying to read it from hardware\n", rc));
1467# endif
1468 rc = PDMDevHlpCallR0(pDevIns, SMC_CALLR0_READ_OSK, 0 /*uArg*/);
1469 if (RT_SUCCESS(rc))
1470 LogRel(("SMC: Successfully retrieved the SMC key from hardware\n"));
1471 else
1472 LogRel(("SMC: Retrieving the SMC key from hardware failed(%Rrc)\n", rc));
1473# ifdef RT_OS_DARWIN
1474 }
1475 else
1476 LogRel(("SMC: Successfully retrieved the SMC key from the OS\n"));
1477# endif
1478 if (RT_FAILURE(rc))
1479 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
1480 N_("Failed to query SMC value from the host"));
1481 }
1482
1483 /*
1484 * Register I/O Ports
1485 */
1486 rc = PDMDevHlpIoPortCreateAndMap(pDevIns, SMC_PORT_FIRST, SMC_REG_COUNT, smcIoPortWrite, smcIoPortRead,
1487 "SMC data port", NULL, &pThis->hIoPorts);
1488 AssertRCReturn(rc, rc);
1489
1490 /** @todo Newer versions (2.03) have an MMIO mapping as well (ACPI). */
1491
1492
1493 /*
1494 * Saved state.
1495 */
1496 rc = PDMDevHlpSSMRegister(pDevIns, SMC_SAVED_STATE_VERSION, sizeof(*pThis), smcR3SaveExec, smcR3LoadExec);
1497 if (RT_FAILURE(rc))
1498 return rc;
1499
1500 return VINF_SUCCESS;
1501}
1502
1503#else /* !IN_RING3 */
1504
1505/**
1506 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
1507 */
1508static DECLCALLBACK(int) smcRZConstruct(PPDMDEVINS pDevIns)
1509{
1510 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
1511 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
1512
1513 int rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPorts, smcIoPortWrite, smcIoPortRead, NULL /*pvUser*/);
1514 AssertRCReturn(rc, rc);
1515 RT_NOREF(pThis);
1516
1517 return VINF_SUCCESS;
1518}
1519
1520#endif /* !IN_RING3 */
1521
1522
1523/**
1524 * The device registration structure.
1525 */
1526const PDMDEVREG g_DeviceSmc =
1527{
1528 /* .u32Version = */ PDM_DEVREG_VERSION,
1529 /* .uReserved0 = */ 0,
1530 /* .szName = */ "smc",
1531 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ | PDM_DEVREG_FLAGS_NEW_STYLE,
1532 /* .fClass = */ PDM_DEVREG_CLASS_ARCH,
1533 /* .cMaxInstances = */ 1,
1534 /* .uSharedVersion = */ 42,
1535 /* .cbInstanceShared = */ sizeof(DEVSMC),
1536 /* .cbInstanceCC = */ 0,
1537 /* .cbInstanceRC = */ 0,
1538 /* .cMaxPciDevices = */ 0,
1539 /* .cMaxMsixVectors = */ 0,
1540 /* .pszDescription = */ "Apple System Management Controller",
1541#if defined(IN_RING3)
1542 /* .pszRCMod = */ "VBoxDDRC.rc",
1543 /* .pszR0Mod = */ "VBoxDDR0.r0",
1544 /* .pfnConstruct = */ smcR3Construct,
1545 /* .pfnDestruct = */ NULL,
1546 /* .pfnRelocate = */ NULL,
1547 /* .pfnMemSetup = */ NULL,
1548 /* .pfnPowerOn = */ NULL,
1549 /* .pfnReset = */ NULL,
1550 /* .pfnSuspend = */ NULL,
1551 /* .pfnResume = */ NULL,
1552 /* .pfnAttach = */ NULL,
1553 /* .pfnDetach = */ NULL,
1554 /* .pfnQueryInterface = */ NULL,
1555 /* .pfnInitComplete = */ NULL,
1556 /* .pfnPowerOff = */ NULL,
1557 /* .pfnSoftReset = */ NULL,
1558 /* .pfnReserved0 = */ NULL,
1559 /* .pfnReserved1 = */ NULL,
1560 /* .pfnReserved2 = */ NULL,
1561 /* .pfnReserved3 = */ NULL,
1562 /* .pfnReserved4 = */ NULL,
1563 /* .pfnReserved5 = */ NULL,
1564 /* .pfnReserved6 = */ NULL,
1565 /* .pfnReserved7 = */ NULL,
1566#elif defined(IN_RING0)
1567 /* .pfnEarlyConstruct = */ NULL,
1568 /* .pfnConstruct = */ smcRZConstruct,
1569 /* .pfnDestruct = */ NULL,
1570 /* .pfnFinalDestruct = */ NULL,
1571 /* .pfnRequest = */ devR0SmcReqHandler,
1572 /* .pfnReserved0 = */ NULL,
1573 /* .pfnReserved1 = */ NULL,
1574 /* .pfnReserved2 = */ NULL,
1575 /* .pfnReserved3 = */ NULL,
1576 /* .pfnReserved4 = */ NULL,
1577 /* .pfnReserved5 = */ NULL,
1578 /* .pfnReserved6 = */ NULL,
1579 /* .pfnReserved7 = */ NULL,
1580#elif defined(IN_RC)
1581 /* .pfnConstruct = */ smcRZConstruct,
1582 /* .pfnReserved0 = */ NULL,
1583 /* .pfnReserved1 = */ NULL,
1584 /* .pfnReserved2 = */ NULL,
1585 /* .pfnReserved3 = */ NULL,
1586 /* .pfnReserved4 = */ NULL,
1587 /* .pfnReserved5 = */ NULL,
1588 /* .pfnReserved6 = */ NULL,
1589 /* .pfnReserved7 = */ NULL,
1590#else
1591# error "Not in IN_RING3, IN_RING0 or IN_RC!"
1592#endif
1593 /* .u32VersionEnd = */ PDM_DEVREG_VERSION
1594};
1595
1596#endif /* VBOX_DEVICE_STRUCT_TESTCASE */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette