VirtualBox

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

Last change on this file since 96312 was 93944, checked in by vboxsync, 3 years ago

Devices: Must not use PAGE_SIZE, PAGE_SHIFT, PAGE_OFFSET_MASK, PAGE_ADDRESS or PHYS_PAGE_ADDRESS here either. bugref:9898

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 56.6 KB
Line 
1/* $Id: DevSmc.cpp 93944 2022-02-24 21:15:14Z 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-2022 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#if defined(IN_RING0) && (defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86))
35# include <iprt/asm-amd64-x86.h>
36# include <iprt/once.h>
37#endif
38#if defined(RT_OS_DARWIN) && defined(IN_RING3) && !defined(VBOX_DEVICE_STRUCT_TESTCASE) /* drags in bad page size define */
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#if defined(IN_RING0) && (defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86))
355
356/** Do once for the SMC ring-0 static data (g_abOsk0And1, g_fHaveOsk). */
357static RTONCE g_SmcR0Once = RTONCE_INITIALIZER;
358/** Indicates whether we've successfully queried the OSK* keys. */
359static bool g_fHaveOsk = false;
360/** The OSK0 and OSK1 values. */
361static uint8_t g_abOsk0And1[32+32];
362
363
364/**
365 * Waits for the specified state on the host SMC.
366 *
367 * @returns success indicator.
368 * @param bState The desired state.
369 * @param pszWhat What we're currently doing. For the log.
370 */
371static bool devR0SmcWaitHostState(uint8_t bState, const char *pszWhat)
372{
373 uint8_t bCurState = 0; /* (MSC is potentially uninitialized) */
374 for (uint32_t cMsSleep = 1; cMsSleep <= 64; cMsSleep <<= 1)
375 {
376 RTThreadSleep(cMsSleep);
377 bCurState = ASMInU16(SMC_PORT_CMD);
378 if ((bCurState & 0xf) == bState)
379 return true;
380 }
381
382 LogRel(("devR0Smc: %s: bCurState=%#x, wanted %#x.\n", pszWhat, bCurState, bState));
383#if 0
384 uint8_t bCurStatus2 = ASMInU8(SMC_PORT_STATUS_CODE);
385 uint8_t bCurStatus3 = ASMInU8(SMC_PORT_STATUS_CODE);
386 uint16_t wCurStatus3 = ASMInU16(SMC_PORT_STATUS_CODE);
387 uint32_t dwCurStatus3 = ASMInU32(SMC_PORT_STATUS_CODE);
388 LogRel(("SMC: status2=%#x status3=%#x w=%#x dw=%#x\n", bCurStatus2, bCurStatus3, wCurStatus3, dwCurStatus3));
389#endif
390 return false;
391}
392
393
394/**
395 * Reads a key by name from the host SMC.
396 *
397 * @returns success indicator.
398 * @param pszName The key name, must be exactly 4 chars long.
399 * @param pbBuf The output buffer.
400 * @param cbBuf The buffer size. Max 32 bytes.
401 */
402static bool devR0SmcQueryHostKey(const char *pszName, uint8_t *pbBuf, size_t cbBuf)
403{
404 Assert(strlen(pszName) == 4);
405 Assert(cbBuf <= 32);
406 Assert(cbBuf > 0);
407
408 /*
409 * Issue the READ command.
410 */
411 uint32_t cMsSleep = 1;
412 for (;;)
413 {
414 ASMOutU32(SMC_PORT_CMD, SMC_CMD_GET_KEY_VALUE);
415 RTThreadSleep(cMsSleep);
416 uint8_t bCurState = ASMInU8(SMC_PORT_CMD);
417 if ((bCurState & 0xf) == 0xc)
418 break;
419 cMsSleep <<= 1;
420 if (cMsSleep > 64)
421 {
422 LogRel(("devR0Smc: %s: bCurState=%#x, wanted %#x.\n", "cmd", bCurState, 0xc));
423 return false;
424 }
425 }
426
427 /*
428 * Send it the key.
429 */
430 for (unsigned off = 0; off < 4; off++)
431 {
432 ASMOutU8(SMC_PORT_DATA, pszName[off]);
433 if (!devR0SmcWaitHostState(4, "key"))
434 return false;
435 }
436
437 /*
438 * The desired amount of output.
439 */
440 ASMOutU8(SMC_PORT_DATA, (uint8_t)cbBuf);
441
442 /*
443 * Read the output.
444 */
445 for (size_t off = 0; off < cbBuf; off++)
446 {
447 if (!devR0SmcWaitHostState(5, off ? "data" : "len"))
448 return false;
449 pbBuf[off] = ASMInU8(SMC_PORT_DATA);
450 }
451
452 LogRel(("SMC: pbBuf=%.*s\n", cbBuf, pbBuf));
453 return true;
454}
455
456
457/**
458 * RTOnce callback that initializes g_fHaveOsk and g_abOsk0And1.
459 *
460 * @returns VINF_SUCCESS.
461 * @param pvUserIgnored Ignored.
462 */
463static DECLCALLBACK(int) devR0SmcInitOnce(void *pvUserIgnored)
464{
465 g_fHaveOsk = devR0SmcQueryHostKey("OSK0", &g_abOsk0And1[0], 32)
466 && devR0SmcQueryHostKey("OSK1", &g_abOsk0And1[32], 32);
467
468#if 0
469 /*
470 * Dump the device registers.
471 */
472 for (uint16_t uPort = 0x300; uPort < 0x320; uPort ++)
473 LogRel(("SMC: %#06x=%#010x w={%#06x, %#06x}, b={%#04x %#04x %#04x %#04x}\n", uPort,
474 ASMInU32(uPort), ASMInU16(uPort), ASMInU16(uPort + 2),
475 ASMInU8(uPort), ASMInU8(uPort + 1), ASMInU8(uPort +2), ASMInU8(uPort + 3) ));
476#endif
477
478 NOREF(pvUserIgnored);
479 return VINF_SUCCESS;
480}
481
482
483/**
484 * @interface_method_impl{PDMDEVREGR0,pfnRequest}
485 */
486static DECLCALLBACK(int) devR0SmcReqHandler(PPDMDEVINS pDevIns, uint32_t uReq, uint64_t uArg)
487{
488 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
489 int rc = VERR_INVALID_FUNCTION;
490 RT_NOREF_PV(uArg);
491
492 if (uReq == SMC_CALLR0_READ_OSK)
493 {
494 rc = RTOnce(&g_SmcR0Once, devR0SmcInitOnce, NULL);
495 if ( RT_SUCCESS(rc)
496 && g_fHaveOsk)
497 {
498 AssertCompile(sizeof(g_abOsk0And1) + 1 == sizeof(pThis->szOsk0And1));
499 memcpy(pThis->szOsk0And1, g_abOsk0And1, sizeof(pThis->szOsk0And1) - 1);
500 pThis->szOsk0And1[sizeof(pThis->szOsk0And1) - 1] = '\0';
501 }
502 }
503 return rc;
504}
505
506#endif /* IN_RING0 && (AMD64 || X86) */
507
508#if defined(IN_RING3) && defined(RT_OS_DARWIN)
509
510/**
511 * Preferred method to retrieve the SMC key.
512 *
513 * @param pabKey where to store the key.
514 * @param cbKey size of the buffer.
515 */
516static int getSmcKeyOs(char *pabKey, uint32_t cbKey)
517{
518 /*
519 * Method as described in Amit Singh's article:
520 * http://osxbook.com/book/bonus/chapter7/tpmdrmmyth/
521 */
522 typedef struct
523 {
524 uint32_t key;
525 uint8_t pad0[22];
526 uint32_t datasize;
527 uint8_t pad1[10];
528 uint8_t cmd;
529 uint32_t pad2;
530 uint8_t data[32];
531 } AppleSMCBuffer;
532
533 AssertReturn(cbKey >= 65, VERR_INTERNAL_ERROR);
534
535 io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
536 IOServiceMatching("AppleSMC"));
537 if (!service)
538 return VERR_NOT_FOUND;
539
540 io_connect_t port = (io_connect_t)0;
541 kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &port);
542 IOObjectRelease(service);
543
544 if (kr != kIOReturnSuccess)
545 return RTErrConvertFromDarwin(kr);
546
547 AppleSMCBuffer inputStruct = { 0, {0}, 32, {0}, 5, };
548 AppleSMCBuffer outputStruct;
549 size_t cbOutputStruct = sizeof(outputStruct);
550
551 for (int i = 0; i < 2; i++)
552 {
553 inputStruct.key = (uint32_t)(i == 0 ? 'OSK0' : 'OSK1');
554 kr = IOConnectCallStructMethod((mach_port_t)port,
555 (uint32_t)2,
556 (const void *)&inputStruct,
557 sizeof(inputStruct),
558 (void *)&outputStruct,
559 &cbOutputStruct);
560 if (kr != kIOReturnSuccess)
561 {
562 IOServiceClose(port);
563 return RTErrConvertFromDarwin(kr);
564 }
565
566 for (int j = 0; j < 32; j++)
567 pabKey[j + i*32] = outputStruct.data[j];
568 }
569
570 IOServiceClose(port);
571
572 pabKey[64] = 0;
573
574 return VINF_SUCCESS;
575}
576
577#endif /* IN_RING3 && RT_OS_DARWIN */
578
579
580/** @callback_method_impl{FNDEVSMCKEYGETTER, OSK0 and OSK1} */
581static DECLCALLBACK(uint8_t) scmKeyGetOSKs(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
582{
583 RT_NOREF1(bCmd);
584 Assert(SMC4CH_EQ(&pKeyDesc->Key, "OSK0") || SMC4CH_EQ(&pKeyDesc->Key, "OSK1"));
585 const char *pszSrc = pThis->szOsk0And1;
586 if (SMC4CH_EQ(&pKeyDesc->Key, "OSK1"))
587 pszSrc += 32;
588 memcpy(pCurKey->Value.ab, pszSrc, 32);
589 return SMC_STATUS_CD_SUCCESS;
590}
591
592
593/** @callback_method_impl{FNDEVSMCKEYGETTER, \#KEY} */
594static DECLCALLBACK(uint8_t) scmKeyGetKeyCount(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
595{
596 RT_NOREF3(pThis, bCmd, pKeyDesc);
597 Assert(pKeyDesc == &g_aSmcKeys[SMC_KEYIDX_FIRST_ENUM]);
598 uint32_t cKeys = RT_ELEMENTS(g_aSmcKeys) - SMC_KEYIDX_FIRST_ENUM;
599 pCurKey->Value.u32 = RT_H2BE_U32(cKeys);
600 return SMC_STATUS_CD_SUCCESS;
601}
602
603
604/** @callback_method_impl{FNDEVSMCKEYGETTER, REV - Source revision.} */
605static DECLCALLBACK(uint8_t) scmKeyGetRevision(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
606{
607 RT_NOREF3(pThis, bCmd, pKeyDesc);
608#ifdef VBOX_WITH_SMC_2_x
609 pCurKey->Value.ab[0] = 0x02;
610 pCurKey->Value.ab[1] = 0x03;
611 pCurKey->Value.ab[2] = 0x0f;
612 pCurKey->Value.ab[3] = 0x00;
613 pCurKey->Value.ab[4] = 0x00;
614 pCurKey->Value.ab[5] = 0x35;
615#else
616 pCurKey->Value.ab[0] = 0x01;
617 pCurKey->Value.ab[1] = 0x25;
618 pCurKey->Value.ab[2] = 0x0f;
619 pCurKey->Value.ab[3] = 0x00;
620 pCurKey->Value.ab[4] = 0x00;
621 pCurKey->Value.ab[5] = 0x04;
622#endif
623 return SMC_STATUS_CD_SUCCESS;
624}
625
626#ifdef VBOX_WITH_SMC_2_x
627
628/** @callback_method_impl{FNDEVSMCKEYGETTER, $Adr - SMC address.} */
629static DECLCALLBACK(uint8_t) scmKeyGetDollarAddress(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
630{
631 RT_NOREF3(pThis, bCmd, pKeyDesc);
632 pCurKey->Value.u32 = RT_H2BE_U32(SMC_PORT_FIRST);
633 return VINF_SUCCESS;
634}
635
636
637/** @callback_method_impl{FNDEVSMCKEYGETTER, $Num - Some kind of number.} */
638static DECLCALLBACK(uint8_t) scmKeyGetDollarNumber(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
639{
640 RT_NOREF2(bCmd, pKeyDesc);
641 pCurKey->Value.ab[0] = pThis->bDollaryNumber;
642 return VINF_SUCCESS;
643}
644
645/** @callback_method_impl{FNDEVSMCKEYPUTTER, $Num - Some kind of number.} */
646static DECLCALLBACK(uint8_t) scmKeyPutDollarNumber(PDEVSMC pThis, PCDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
647{
648 RT_NOREF2(bCmd, pKeyDesc);
649 Log(("scmKeyPutDollarNumber: %#x -> %#x\n", pThis->bDollaryNumber, pCurKey->Value.ab[0]));
650 pThis->bDollaryNumber = pCurKey->Value.ab[0];
651 return VINF_SUCCESS;
652}
653
654#endif /* VBOX_WITH_SMC_2_x */
655
656/** @callback_method_impl{FNDEVSMCKEYGETTER, MSSD - Machine Shutdown reason.} */
657static DECLCALLBACK(uint8_t) scmKeyGetShutdownReason(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
658{
659 RT_NOREF2(bCmd, pKeyDesc);
660 pCurKey->Value.ab[0] = pThis->bShutdownReason;
661 return SMC_STATUS_CD_SUCCESS;
662}
663
664
665/** @callback_method_impl{FNDEVSMCKEYPUTTER, MSSD - Machine Shutdown reason.} */
666static DECLCALLBACK(uint8_t) scmKeyPutShutdownReason(PDEVSMC pThis, PCDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
667{
668 RT_NOREF2(bCmd, pKeyDesc);
669 Log(("scmKeyPutShutdownReason: %#x -> %#x\n", pThis->bShutdownReason, pCurKey->Value.ab[0]));
670 pThis->bShutdownReason = pCurKey->Value.ab[0];
671 return SMC_STATUS_CD_SUCCESS;
672}
673
674
675/** @callback_method_impl{FNDEVSMCKEYGETTER, MSSD - Ninja timer action job.} */
676static DECLCALLBACK(uint8_t)
677scmKeyGetNinjaTimerAction(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
678{
679 RT_NOREF2(bCmd, pKeyDesc);
680 pCurKey->Value.ab[0] = pThis->bNinjaActionTimerJob;
681 return SMC_STATUS_CD_SUCCESS;
682}
683
684
685/** @callback_method_impl{FNDEVSMCKEYPUTTER, NATJ - Ninja timer action job.} */
686static DECLCALLBACK(uint8_t)
687scmKeyPutNinjaTimerAction(PDEVSMC pThis, PCDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
688{
689 RT_NOREF2(bCmd, pKeyDesc);
690 Log(("scmKeyPutNinjaTimerAction: %#x -> %#x\n", pThis->bNinjaActionTimerJob, pCurKey->Value.ab[0]));
691 pThis->bNinjaActionTimerJob = pCurKey->Value.ab[0];
692 return SMC_STATUS_CD_SUCCESS;
693}
694
695#ifdef VBOX_WITH_SMC_2_x
696
697/** @callback_method_impl{FNDEVSMCKEYGETTER, Generic one getter.} */
698static DECLCALLBACK(uint8_t) scmKeyGetOne(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
699{
700 RT_NOREF2(pThis, bCmd);
701 memset(&pCurKey->Value.ab[0], 0, pKeyDesc->cbValue);
702 pCurKey->Value.ab[pKeyDesc->cbValue - 1] = 1;
703 return SMC_STATUS_CD_SUCCESS;
704}
705
706#endif /* VBOX_WITH_SMC_2_x */
707
708/** @callback_method_impl{FNDEVSMCKEYGETTER, Generic zero getter.} */
709static DECLCALLBACK(uint8_t) scmKeyGetZero(PDEVSMC pThis, PDEVSMCCURKEY pCurKey, uint8_t bCmd, PCDEVSMCKEYDESC pKeyDesc)
710{
711 RT_NOREF2(pThis, bCmd);
712 memset(&pCurKey->Value.ab[0], 0, pKeyDesc->cbValue);
713 return SMC_STATUS_CD_SUCCESS;
714}
715
716
717/**
718 * Looks up a key and copies its value and attributes into the CurKey.
719 *
720 * @returns Key index on success, UINT32_MAX on failure.
721 * @param uKeyValue The key value (DEVSMC4CHID.u32).
722 */
723static uint32_t smcKeyLookup(uint32_t uKeyValue)
724{
725 uint32_t iKey = RT_ELEMENTS(g_aSmcKeys);
726 while (iKey-- > 0)
727 if (g_aSmcKeys[iKey].Key.u32 == uKeyValue)
728 return iKey;
729 return UINT32_MAX;
730}
731
732
733/**
734 * Looks up a key and copies its value and attributes into the CurKey.
735 *
736 * @returns Apple SMC Status Code.
737 * @param pThis The SMC instance data.
738 */
739static uint8_t smcKeyGetByName(PDEVSMC pThis)
740{
741 uint8_t bRc;
742#ifdef LOG_ENABLED
743 uint32_t const uKeyValueLog = RT_H2LE_U32(pThis->CurKey.Key.u32);
744#endif
745 uint32_t iKey = smcKeyLookup(pThis->CurKey.Key.u32);
746 if (iKey != UINT32_MAX)
747 {
748 if ( g_aSmcKeys[iKey].cbValue == pThis->CurKey.cbValue
749 || !g_aSmcKeys[iKey].cbValue)
750 {
751 pThis->CurKey.Type = g_aSmcKeys[iKey].Type;
752 pThis->CurKey.fAttr = g_aSmcKeys[iKey].fAttr;
753 RT_ZERO(pThis->CurKey.Value);
754 if (g_aSmcKeys[iKey].pfnGet)
755 {
756 bRc = g_aSmcKeys[iKey].pfnGet(pThis, &pThis->CurKey, pThis->bCmd, &g_aSmcKeys[iKey]);
757 if (bRc == SMC_STATUS_CD_SUCCESS)
758 {
759 LogFlow(("smcKeyGetByName: key=%4.4s value=%.*Rhxs\n",
760 &uKeyValueLog, pThis->CurKey.cbValue, &pThis->CurKey.Value));
761 return SMC_STATUS_CD_SUCCESS;
762 }
763
764 Log(("smcKeyGetByName: key=%4.4s getter failed! bRc=%#x\n", &uKeyValueLog, bRc));
765 }
766 else
767 {
768 Log(("smcKeyGetByName: key=%4.4s is not readable!\n", &uKeyValueLog));
769 bRc = SMC_STATUS_CD_KEY_NOT_READABLE;
770 }
771 }
772 else
773 {
774 Log(("smcKeyGetByName: Wrong value size; user=%#x smc=%#x key=%4.4s !\n",
775 pThis->CurKey.cbValue, g_aSmcKeys[iKey].cbValue, &uKeyValueLog));
776 bRc = SMC_STATUS_CD_KEY_SIZE_MISMATCH;
777 }
778 }
779 else
780 {
781 Log(("smcKeyGetByName: Key not found! key=%4.4s size=%#x\n", &uKeyValueLog, pThis->CurKey.cbValue));
782 bRc = SMC_STATUS_CD_KEY_NOT_FOUND;
783 }
784
785 RT_ZERO(pThis->CurKey);
786 return bRc;
787}
788
789
790/**
791 * Looks up a key by index and copies its name (and attributes) into the CurKey.
792 *
793 * @returns Apple SMC Status Code.
794 * @param pThis The SMC instance data.
795 */
796static uint8_t smcKeyGetByIndex(PDEVSMC pThis)
797{
798 uint8_t bRc;
799 uint32_t iKey = RT_BE2H_U32(pThis->CurKey.Key.u32);
800 if (iKey < RT_ELEMENTS(g_aSmcKeys) - SMC_KEYIDX_FIRST_ENUM)
801 {
802 pThis->CurKey.Key = g_aSmcKeys[iKey].Key;
803 pThis->CurKey.Type = g_aSmcKeys[iKey].Type;
804 pThis->CurKey.fAttr = g_aSmcKeys[iKey].fAttr;
805 pThis->CurKey.cbValue = g_aSmcKeys[iKey].cbValue;
806 RT_ZERO(pThis->CurKey.Value);
807 Log(("smcKeyGetByIndex: %#x -> %c%c%c%c\n", iKey,
808 pThis->CurKey.Key.ab[3], pThis->CurKey.Key.ab[2], pThis->CurKey.Key.ab[1], pThis->CurKey.Key.ab[0]));
809 bRc = SMC_STATUS_CD_SUCCESS;
810 }
811 else
812 {
813 Log(("smcKeyGetByIndex: Key out or range: %#x, max %#x\n", iKey, RT_ELEMENTS(g_aSmcKeys) - SMC_KEYIDX_FIRST_ENUM));
814 bRc = SMC_STATUS_CD_KEY_NOT_FOUND;
815 }
816 return bRc;
817}
818
819
820/**
821 * Looks up a key by index and copies its attributes into the CurKey.
822 *
823 * @returns Apple SMC Status Code.
824 * @param pThis The SMC instance data.
825 */
826static uint8_t smcKeyGetAttrByName(PDEVSMC pThis)
827{
828 uint8_t bRc;
829#ifdef LOG_ENABLED
830 uint32_t const uKeyValueLog = RT_H2LE_U32(pThis->CurKey.Key.u32);
831#endif
832 uint32_t iKey = smcKeyLookup(pThis->CurKey.Key.u32);
833 if (iKey != UINT32_MAX)
834 {
835 pThis->CurKey.Type = g_aSmcKeys[iKey].Type;
836 pThis->CurKey.fAttr = g_aSmcKeys[iKey].fAttr;
837 pThis->CurKey.cbValue = g_aSmcKeys[iKey].cbValue;
838 RT_ZERO(pThis->CurKey.Value);
839 if (g_aSmcKeys[iKey].cbValue)
840 bRc = SMC_STATUS_CD_SUCCESS;
841 else
842 bRc = g_aSmcKeys[iKey].pfnGet(pThis, &pThis->CurKey, pThis->bCmd, &g_aSmcKeys[iKey]);
843 if (bRc == SMC_STATUS_CD_SUCCESS)
844 {
845 LogFlow(("smcKeyGetAttrByName: key=%4.4s value=%.*Rhxs\n",
846 &uKeyValueLog, pThis->CurKey.cbValue, &pThis->CurKey.Value));
847 return SMC_STATUS_CD_SUCCESS;
848 }
849
850 Log(("smcKeyGetAttrByName: key=%4.4s getter failed! bRc=%#x\n", &uKeyValueLog, bRc));
851 }
852 else
853 {
854 Log(("smcKeyGetAttrByName: Key not found! key=%4.4s size=%#x\n", &uKeyValueLog, pThis->CurKey.cbValue));
855 bRc = SMC_STATUS_CD_KEY_NOT_FOUND;
856 }
857
858 RT_ZERO(pThis->CurKey);
859 return bRc;
860}
861
862
863static uint8_t smcKeyPutPrepare(PDEVSMC pThis)
864{
865 RT_NOREF1(pThis);
866 return 0;
867}
868
869static uint8_t smcKeyPutValue(PDEVSMC pThis)
870{
871 RT_NOREF1(pThis);
872 return 0;
873}
874
875
876/**
877 * Data register read.
878 *
879 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
880 * @param uReg The register number.
881 * @param pbValue Where to return the value.
882 */
883static VBOXSTRICTRC smcRegData_r(PDEVSMC pThis, uint8_t uReg, uint8_t *pbValue)
884{
885 RT_NOREF1(uReg);
886 switch (pThis->bCmd)
887 {
888 case SMC_CMD_GET_KEY_VALUE:
889 if ( pThis->u.s.bState == 0x05
890 && pThis->offValue < pThis->CurKey.cbValue)
891 {
892 *pbValue = pThis->CurKey.Value.ab[pThis->offValue];
893 if (++pThis->offValue >= pThis->CurKey.cbValue)
894 pThis->u.s.bState = 0x00;
895 pThis->u.s.bStatusCode = SMC_STATUS_CD_SUCCESS;
896 }
897 else
898 {
899 Log(("smcRegData_r: Reading too much or at wrong time during SMC_CMD_GET_KEY_INFO! bState=%#x offValue=%#x\n",
900 pThis->u.s.bState, pThis->offValue));
901 pThis->u.s.bState = 0x00;
902 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA; /** @todo check status code */
903 }
904 break;
905
906 case SMC_CMD_GET_KEY_INFO:
907 if ( pThis->u.s.bState == 0x05
908 && pThis->offValue < 6)
909 {
910 if (pThis->offValue == 0)
911 *pbValue = pThis->CurKey.cbValue;
912 else if (pThis->offValue < 1 + 4)
913 *pbValue = pThis->CurKey.Type.ab[pThis->offValue - 1];
914 else
915 *pbValue = pThis->CurKey.fAttr;
916 if (++pThis->offValue >= 6)
917 pThis->u.s.bState = 0x00;
918 pThis->u.s.bStatusCode = SMC_STATUS_CD_SUCCESS;
919 }
920 else
921 {
922 Log(("smcRegData_r: Reading too much or at wrong time during SMC_CMD_GET_KEY_INFO! bState=%#x offValue=%#x\n",
923 pThis->u.s.bState, pThis->offValue));
924 pThis->u.s.bState = 0x00;
925 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA; /** @todo check status code */
926 }
927 break;
928
929 case SMC_CMD_GET_KEY_BY_INDEX:
930 if ( pThis->u.s.bState == 0x05
931 && pThis->offValue < sizeof(pThis->CurKey.Key))
932 {
933 *pbValue = pThis->CurKey.Key.ab[pThis->offValue];
934 if (++pThis->offValue >= sizeof(pThis->CurKey.Key))
935 pThis->u.s.bState = 0x00;
936 pThis->u.s.bStatusCode = SMC_STATUS_CD_SUCCESS;
937 }
938 else
939 {
940 Log(("smcRegData_r: Reading too much or at wrong time during GET_KEY_BY_INDEX! bState=%#x offValue=%#x\n",
941 pThis->u.s.bState, pThis->offValue));
942 pThis->u.s.bState = 0x00;
943 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA; /** @todo check status code */
944 }
945 break;
946
947 case SMC_CMD_PUT_KEY:
948 Log(("smcRegData_r: Attempting to read data during PUT_KEY!\n"));
949 *pbValue = 0xff;
950 pThis->u.s.bState = 0;
951 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA;
952 break;
953
954 default:
955 Log(("smcRegData_r: Unknown command attempts reading data\n"));
956 *pbValue = 0xff;
957 pThis->u.s.bState = 0;
958 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA;
959 break;
960 }
961
962 return VINF_SUCCESS;
963}
964
965
966/**
967 * Data register write.
968 *
969 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
970 * @param uReg The register number.
971 * @param bValue The value being written.
972 */
973static VBOXSTRICTRC smcRegData_w(PDEVSMC pThis, uint8_t uReg, uint8_t bValue)
974{
975 RT_NOREF1(uReg);
976 switch (pThis->bCmd)
977 {
978 /*
979 * Get or put key value.
980 *
981 * 5 bytes written, first 4 is the key the 5th is the value size. In
982 * the case of a put the value bytes are then written, while a get will
983 * read the value bytes.
984 */
985 case SMC_CMD_GET_KEY_VALUE:
986 case SMC_CMD_PUT_KEY:
987 if (pThis->offKey < 4)
988 {
989 /* Key byte. */
990 pThis->CurKey.Key.ab[pThis->offKey++] = bValue;
991 pThis->u.s.bState = 0x04;
992 pThis->u.s.bStatusCode = SMC_STATUS_CD_SUCCESS;
993 }
994 else if (pThis->offKey == 4)
995 {
996 /* Data length. */
997 pThis->u.s.bState = 0;
998 if (bValue <= sizeof(pThis->CurKey.Value))
999 {
1000 pThis->CurKey.cbValue = bValue;
1001 pThis->offKey = 5;
1002 Assert(pThis->offValue == 0);
1003
1004 if (pThis->bCmd == SMC_CMD_GET_KEY_VALUE)
1005 pThis->u.s.bStatusCode = smcKeyGetByName(pThis);
1006 else
1007 pThis->u.s.bStatusCode = smcKeyPutPrepare(pThis);
1008 if (pThis->u.s.bStatusCode == SMC_STATUS_CD_SUCCESS)
1009 pThis->u.s.bState = 0x05;
1010 }
1011 else
1012 {
1013 Log(("smcRegData_w: Guest attempts to get/put too many value bytes: %#x (max %#x)!\n",
1014 bValue, sizeof(pThis->CurKey.Value)));
1015 pThis->u.s.bStatusCode = SMC_STATUS_CD_KEY_SIZE_MISMATCH; /** @todo check this case! */
1016 }
1017 }
1018 else if ( pThis->bCmd == SMC_CMD_PUT_KEY
1019 && pThis->offValue < pThis->CurKey.cbValue)
1020 {
1021 /* More value bytes for put key action. */
1022 pThis->CurKey.Value.ab[pThis->offValue++] = bValue;
1023 if (pThis->offValue != pThis->CurKey.cbValue)
1024 pThis->u.s.bState = 0x05;
1025 else
1026 {
1027 pThis->u.s.bState = 0x00;
1028 pThis->u.s.bStatusCode = smcKeyPutValue(pThis);
1029 }
1030 }
1031 else
1032 {
1033 Log(("smcRegData_w: Writing too much data on %s command!\n", pThis->bCmd == SMC_CMD_PUT_KEY ? "put" : "get"));
1034 pThis->u.s.bState = 0x00;
1035 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA;
1036 }
1037 break;
1038
1039 /*
1040 * Get key info and key by index seems to take action after the last
1041 * key char is written. They then both go into a data reading phase.
1042 */
1043 case SMC_CMD_GET_KEY_INFO:
1044 case SMC_CMD_GET_KEY_BY_INDEX:
1045 if (pThis->offKey < 4)
1046 {
1047 pThis->CurKey.Key.ab[pThis->offKey] = bValue;
1048 if (++pThis->offKey == 4)
1049 {
1050 if (pThis->bCmd == SMC_CMD_GET_KEY_BY_INDEX)
1051 pThis->u.s.bStatusCode = smcKeyGetByIndex(pThis);
1052 else
1053 pThis->u.s.bStatusCode = smcKeyGetAttrByName(pThis);
1054 pThis->u.s.bState = pThis->u.s.bStatusCode == SMC_STATUS_CD_SUCCESS ? 0x05 : 0x00;
1055 }
1056 else
1057 {
1058 pThis->u.s.bState = 0x04;
1059 pThis->u.s.bStatusCode = SMC_STATUS_CD_SUCCESS;
1060 }
1061 }
1062 else
1063 {
1064 Log(("smcRegData_w: Writing data beyond 5th byte on get %s command!\n",
1065 pThis->bCmd == SMC_CMD_GET_KEY_INFO ? "info" : "by index"));
1066 pThis->u.s.bState = 0x00;
1067 pThis->u.s.bStatusCode = SMC_STATUS_CD_SPURIOUS_DATA;
1068 }
1069 break;
1070
1071 default:
1072 Log(("smcRegData_w: Unknown command %#x!\n", bValue));
1073 pThis->u.s.bState = 0x00; /** @todo Check statuses with real HW. */
1074 pThis->u.s.bStatusCode = SMC_STATUS_CD_BAD_COMMAND;
1075 break;
1076 }
1077 return VINF_SUCCESS;
1078}
1079
1080
1081/**
1082 * Command register write.
1083 *
1084 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
1085 * @param uReg The register number.
1086 * @param bValue The value being written.
1087 */
1088static VBOXSTRICTRC smcRegCmd_w(PDEVSMC pThis, uint8_t uReg, uint8_t bValue)
1089{
1090 LogFlow(("smcRegCmd_w: New command: %#x (old=%#x)\n", bValue, pThis->bCmd)); NOREF(uReg);
1091
1092 pThis->bCmd = bValue;
1093
1094 /* Validate the command. */
1095 switch (bValue)
1096 {
1097 case SMC_CMD_GET_KEY_VALUE:
1098 case SMC_CMD_PUT_KEY:
1099 case SMC_CMD_GET_KEY_BY_INDEX:
1100 case SMC_CMD_GET_KEY_INFO:
1101 pThis->u.s.bState = 0x0c;
1102 pThis->u.s.bStatusCode = SMC_STATUS_CD_SUCCESS;
1103 break;
1104
1105 default:
1106 Log(("SMC: Unknown command %#x!\n", bValue));
1107 pThis->u.s.bState = 0x00; /** @todo Check state with real HW. */
1108 pThis->u.s.bStatusCode = SMC_STATUS_CD_BAD_COMMAND;
1109 break;
1110 }
1111
1112 /* Reset the value/key related state. */
1113 pThis->offKey = 0;
1114 pThis->offValue = 0;
1115 pThis->CurKey.Key.u32 = 0;
1116 pThis->CurKey.cbValue = 0;
1117
1118 return VINF_SUCCESS;
1119}
1120
1121
1122/**
1123 * Generic register write.
1124 *
1125 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
1126 * @param uReg The register number.
1127 * @param bValue The value being written.
1128 */
1129static VBOXSTRICTRC smcRegGen_w(PDEVSMC pThis, uint8_t uReg, uint8_t bValue)
1130{
1131 Log(("smcRegGen_w: %#04x: %#x -> %#x (write)\n", uReg, pThis->u.abRegsRW[uReg], bValue));
1132 pThis->u.abRegsRW[uReg] = bValue;
1133 return VINF_SUCCESS;
1134}
1135
1136
1137/**
1138 * Read from register that isn't writable and reads as 0xFF.
1139 *
1140 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
1141 * @param uReg The register number.
1142 * @param pbValue Where to return the value.
1143 */
1144static VBOXSTRICTRC smcRegGen_r(PDEVSMC pThis, uint8_t uReg, uint8_t *pbValue)
1145{
1146 Log(("smcRegGen_r: %#04x: %#x (read)\n", uReg, pThis->u.abRegsRW[uReg]));
1147 *pbValue = pThis->u.abRegsRW[uReg];
1148 return VINF_SUCCESS;
1149}
1150
1151
1152/**
1153 * Write to register that isn't writable and reads as 0xFF.
1154 *
1155 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
1156 * @param uReg The register number.
1157 * @param bValue The value being written.
1158 */
1159static VBOXSTRICTRC smcRegFF_w(PDEVSMC pThis, uint8_t uReg, uint8_t bValue)
1160{
1161 RT_NOREF3(pThis, uReg, bValue);
1162 Log(("SMC: %#04x: Writing %#x to unknown register!\n", uReg, bValue));
1163 return VINF_SUCCESS;
1164}
1165
1166
1167/**
1168 * Read from register that isn't writable and reads as 0xFF.
1169 *
1170 * @returns VINF_SUCCESS or VINF_IOM_R3_IOPORT_WRITE.
1171 * @param uReg The register number.
1172 * @param pbValue Where to return the value.
1173 */
1174static VBOXSTRICTRC smcRegFF_r(PDEVSMC pThis, uint8_t uReg, uint8_t *pbValue)
1175{
1176 RT_NOREF2(pThis, uReg);
1177 Log(("SMC: %#04x: Reading from unknown register!\n", uReg));
1178 *pbValue = 0xff;
1179 return VINF_SUCCESS;
1180}
1181
1182
1183
1184/**
1185 * SMC register handlers (indexed by relative I/O port).
1186 *
1187 * The device seems to be all byte registers and will split wider
1188 * accesses between registers like if it was MMIO. To better illustrate it
1189 * here is the output of the code in devR0SmcInitOnce on a MacPro3,1:
1190 * @verbatim
1191 * SMC: 0x0300=0xffffff63 w={0xff63, 0xffff}, b={0x63 0xff 0xff 0xff}
1192 * SMC: 0x0301=0x0cffffff w={0xffff, 0x0cff}, b={0xff 0xff 0xff 0x0c}
1193 * SMC: 0x0302=0xff0cffff w={0xffff, 0xff0c}, b={0xff 0xff 0x0c 0xff}
1194 * SMC: 0x0303=0xffff0cff w={0x0cff, 0xffff}, b={0xff 0x0c 0xff 0xff}
1195 * SMC: 0x0304=0xffffff0c w={0xff0c, 0xffff}, b={0x0c 0xff 0xff 0xff}
1196 * SMC: 0x0305=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1197 * SMC: 0x0306=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1198 * SMC: 0x0307=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1199 * SMC: 0x0308=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1200 * SMC: 0x0309=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1201 * SMC: 0x030a=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1202 * SMC: 0x030b=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1203 * SMC: 0x030c=0xffffffff w={0xffff, 0xffff}, b={0xff 0xff 0xff 0xff}
1204 * SMC: 0x030d=0x00ffffff w={0xffff, 0x00ff}, b={0xff 0xff 0xff 0x00}
1205 * SMC: 0x030e=0x0000ffff w={0xffff, 0x0000}, b={0xff 0xff 0x00 0x00}
1206 * SMC: 0x030f=0x000000ff w={0x00ff, 0x0000}, b={0xff 0x00 0x00 0x00}
1207 * SMC: 0x0310=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1208 * SMC: 0x0311=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1209 * SMC: 0x0312=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1210 * SMC: 0x0313=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1211 * SMC: 0x0314=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1212 * SMC: 0x0315=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1213 * SMC: 0x0316=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1214 * SMC: 0x0317=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1215 * SMC: 0x0318=0x00000000 w={0x0000, 0x0000}, b={0x00 0x00 0x00 0x00}
1216 * SMC: 0x0319=0xbe000000 w={0x0000, 0xbe00}, b={0x00 0x00 0x00 0xbe}
1217 * SMC: 0x031a=0xbabe0000 w={0x0000, 0xbabe}, b={0x00 0x00 0xbe 0xba}
1218 * SMC: 0x031b=0x00babe00 w={0xbe00, 0x00ba}, b={0x00 0xbe 0xba 0x00}
1219 * SMC: 0x031c=0xbe00babe w={0xbabe, 0xbe00}, b={0xbe 0xba 0x00 0xbe}
1220 * SMC: 0x031d=0xffbe00ba w={0x00ba, 0xffbe}, b={0xba 0x00 0xbe 0xff}
1221 * SMC: 0x031e=0xffffbe00 w={0xbe00, 0xffff}, b={0x00 0xbe 0xff 0xff}
1222 * SMC: 0x031f=0xffffffbe w={0xffbe, 0xffff}, b={0xbe 0xff 0xff 0xff}
1223 * @endverbatim
1224 *
1225 * The last dword is writable (0xbeXXbabe) where in the register at 0x1e is some
1226 * kind of status register for qualifying search failures and the like and will
1227 * be cleared under certain conditions. The whole dword can be written and read
1228 * back unchanged, according to my experiments. The 0x00 and 0x04 registers
1229 * does not read back what is written.
1230 *
1231 * My guess is that the 0xff values indicates ports that are not writable and
1232 * hardwired to 0xff, while the other values indicates ports that can be written
1233 * to and normally read back as written. I'm not going to push my luck too far
1234 * wrt to exact behavior until I see the guest using the registers.
1235 */
1236static const struct
1237{
1238 VBOXSTRICTRC (*pfnWrite)(PDEVSMC pThis, uint8_t uReg, uint8_t bValue);
1239 VBOXSTRICTRC (*pfnRead)(PDEVSMC pThis, uint8_t uReg, uint8_t *pbValue);
1240} g_aSmcRegs[SMC_REG_COUNT] =
1241{
1242 /* [0x00] = */ { smcRegData_w, smcRegData_r },
1243 /* [0x01] = */ { smcRegFF_w, smcRegFF_r },
1244 /* [0x02] = */ { smcRegFF_w, smcRegFF_r },
1245 /* [0x03] = */ { smcRegFF_w, smcRegFF_r },
1246 /* [0x04] = */ { smcRegCmd_w, smcRegGen_r },
1247 /* [0x05] = */ { smcRegFF_w, smcRegFF_r },
1248 /* [0x06] = */ { smcRegFF_w, smcRegFF_r },
1249 /* [0x07] = */ { smcRegFF_w, smcRegFF_r },
1250 /* [0x08] = */ { smcRegFF_w, smcRegFF_r },
1251 /* [0x09] = */ { smcRegFF_w, smcRegFF_r },
1252 /* [0x0a] = */ { smcRegFF_w, smcRegFF_r },
1253 /* [0x0b] = */ { smcRegFF_w, smcRegFF_r },
1254 /* [0x0c] = */ { smcRegFF_w, smcRegFF_r },
1255 /* [0x0d] = */ { smcRegFF_w, smcRegFF_r },
1256 /* [0x0e] = */ { smcRegFF_w, smcRegFF_r },
1257 /* [0x0f] = */ { smcRegFF_w, smcRegFF_r },
1258 /* [0x10] = */ { smcRegGen_w, smcRegGen_r },
1259 /* [0x11] = */ { smcRegGen_w, smcRegGen_r },
1260 /* [0x12] = */ { smcRegGen_w, smcRegGen_r },
1261 /* [0x13] = */ { smcRegGen_w, smcRegGen_r },
1262 /* [0x14] = */ { smcRegGen_w, smcRegGen_r },
1263 /* [0x15] = */ { smcRegGen_w, smcRegGen_r },
1264 /* [0x16] = */ { smcRegGen_w, smcRegGen_r },
1265 /* [0x17] = */ { smcRegGen_w, smcRegGen_r },
1266 /* [0x18] = */ { smcRegGen_w, smcRegGen_r },
1267 /* [0x19] = */ { smcRegGen_w, smcRegGen_r },
1268 /* [0x1a] = */ { smcRegGen_w, smcRegGen_r },
1269 /* [0x1b] = */ { smcRegGen_w, smcRegGen_r },
1270 /* [0x1c] = */ { smcRegGen_w, smcRegGen_r },
1271 /* [0x1d] = */ { smcRegGen_w, smcRegGen_r },
1272 /* [0x1e] = */ { smcRegGen_w, smcRegGen_r },
1273 /* [0x1f] = */ { smcRegGen_w, smcRegGen_r },
1274};
1275
1276
1277/**
1278 * @callback_method_impl{FNIOMIOPORTNEWOUT}
1279 */
1280static DECLCALLBACK(VBOXSTRICTRC) smcIoPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
1281{
1282 RT_NOREF1(pvUser);
1283#ifndef IN_RING3
1284 if (cb > 1)
1285 {
1286 Log3(("smcIoPortWrite: %#04x write access: %#x (LB %u) -> ring-3\n", offPort, u32, cb));
1287 return VINF_IOM_R3_IOPORT_WRITE;
1288 }
1289#endif
1290#ifdef LOG_ENABLED
1291 RTIOPORT const offPortLog = offPort;
1292 unsigned const cbLog = cb;
1293#endif
1294
1295 /*
1296 * The first register, usually only one is accessed.
1297 */
1298 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
1299 AssertReturn(offPort < RT_ELEMENTS(g_aSmcRegs), VERR_INTERNAL_ERROR_3); /* impossible*/
1300 VBOXSTRICTRC rc = g_aSmcRegs[offPort].pfnWrite(pThis, offPort, u32);
1301
1302 /*
1303 * On the off chance that multiple registers are being read.
1304 */
1305 if (cb > 1)
1306 {
1307 while (cb > 1 && offPort < SMC_REG_COUNT - 1)
1308 {
1309 cb--;
1310 offPort++;
1311 u32 >>= 8;
1312 VBOXSTRICTRC rc2 = g_aSmcRegs[offPort].pfnWrite(pThis, offPort, u32);
1313 if (rc2 != VINF_SUCCESS)
1314 {
1315 if ( rc == VINF_SUCCESS
1316 || (RT_FAILURE(rc2) && RT_SUCCESS(rc))
1317 || (rc2 < rc && RT_SUCCESS(rc2) && RT_SUCCESS(rc)))
1318 rc = rc2;
1319 }
1320 }
1321 }
1322
1323 LogFlow(("smcIoPortWrite: %#04x write access: %#x (LB %u) rc=%Rrc\n", offPortLog, u32, cbLog, VBOXSTRICTRC_VAL(rc) ));
1324 return rc;
1325}
1326
1327
1328/**
1329 * @callback_method_impl{FNIOMIOPORTNEWIN}
1330 */
1331static DECLCALLBACK(VBOXSTRICTRC) smcIoPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
1332{
1333 RT_NOREF1(pvUser);
1334#ifndef IN_RING3
1335 if (cb > 1)
1336 return VINF_IOM_R3_IOPORT_READ;
1337#endif
1338
1339 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
1340#ifdef LOG_ENABLED
1341 RTIOPORT const offPortLog = offPort;
1342 unsigned const cbLog = cb;
1343#endif
1344
1345 /*
1346 * The first register, usually only one is accessed.
1347 */
1348 AssertReturn(offPort < RT_ELEMENTS(g_aSmcRegs), VERR_INTERNAL_ERROR_3); /* impossible*/
1349 Log2(("smcIoPortRead: %#04x read access: LB %u\n", offPort, cb));
1350 uint8_t bValue = 0xff;
1351 VBOXSTRICTRC rc = g_aSmcRegs[offPort].pfnRead(pThis, offPort, &bValue);
1352 *pu32 = bValue;
1353
1354 /*
1355 * On the off chance that multiple registers are being read.
1356 */
1357 if (cb > 1)
1358 {
1359 do
1360 {
1361 cb--;
1362 offPort++;
1363 bValue = 0xff;
1364 if (offPort < SMC_REG_COUNT)
1365 {
1366 VBOXSTRICTRC rc2 = g_aSmcRegs[offPort].pfnRead(pThis, offPort, &bValue);
1367 if (rc2 != VINF_SUCCESS)
1368 {
1369 if ( rc == VINF_SUCCESS
1370 || (RT_FAILURE(rc2) && RT_SUCCESS(rc))
1371 || (rc2 < rc && RT_SUCCESS(rc2) && RT_SUCCESS(rc)))
1372 rc = rc2;
1373 }
1374 }
1375 *pu32 |= (uint32_t)bValue << ((4 - cb) * 8);
1376 } while (cb > 1);
1377 }
1378 LogFlow(("smcIoPortRead: %#04x read access: %#x (LB %u) rc=%Rrc\n", offPortLog, *pu32, cbLog, VBOXSTRICTRC_VAL(rc)));
1379 return rc;
1380}
1381
1382#ifdef IN_RING3
1383
1384/** @callback_method_impl{FNSSMDEVSAVEEXEC} */
1385static DECLCALLBACK(int) smcR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
1386{
1387 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
1388 RT_NOREF2(pSSM, pThis);
1389
1390 /** @todo */
1391
1392 return VINF_SUCCESS;
1393}
1394
1395
1396/** @callback_method_impl{FNSSMDEVLOADEXEC} */
1397static DECLCALLBACK(int) smcR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
1398{
1399 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
1400 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
1401 RT_NOREF2(pSSM, pThis);
1402
1403 /* Fend off unsupported versions. */
1404 if ( uVersion != SMC_SAVED_STATE_VERSION
1405#if SMC_SAVED_STATE_VERSION != SMC_SAVED_STATE_VERSION_BAKA
1406 && uVersion != SMC_SAVED_STATE_VERSION_BAKA
1407#endif
1408 && uVersion != SMC_SAVED_STATE_VERSION_BAKA + 1)
1409 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
1410
1411 /*
1412 * Do the actual restoring.
1413 */
1414 if (uVersion == SMC_SAVED_STATE_VERSION)
1415 {
1416 /** @todo */
1417 }
1418
1419 return VINF_SUCCESS;
1420}
1421
1422
1423/**
1424 * @interface_method_impl{PDMDEVREG,pfnConstruct}
1425 */
1426static DECLCALLBACK(int) smcR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
1427{
1428 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
1429 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
1430 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
1431
1432 Assert(iInstance == 0); RT_NOREF1(iInstance);
1433
1434 /*
1435 * Init the data.
1436 */
1437 pThis->bDollaryNumber = 1;
1438 pThis->bShutdownReason = 3; /* STOP_CAUSE_POWERKEY_GOOD_CODE */
1439
1440 /*
1441 * Validate configuration.
1442 */
1443 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "DeviceKey|GetKeyFromRealSMC", "");
1444
1445 /*
1446 * Read configuration.
1447 */
1448
1449 /* The DeviceKey sets OSK0 and OSK1. */
1450 int rc = pHlp->pfnCFGMQueryStringDef(pCfg, "DeviceKey", pThis->szOsk0And1, sizeof(pThis->szOsk0And1), "");
1451 if (RT_FAILURE(rc))
1452 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
1453 N_("Configuration error: Querying \"DeviceKey\" as a string failed"));
1454
1455 /* Query the key from the OS / real hardware if asked to do so. */
1456 bool fGetKeyFromRealSMC;
1457 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "GetKeyFromRealSMC", &fGetKeyFromRealSMC, false);
1458 if (RT_FAILURE(rc))
1459 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
1460 N_("Configuration error: Querying \"GetKeyFromRealSMC\" as a boolean failed"));
1461 if (fGetKeyFromRealSMC)
1462 {
1463# ifdef RT_OS_DARWIN
1464 rc = getSmcKeyOs(pThis->szOsk0And1, sizeof(pThis->szOsk0And1));
1465 if (RT_FAILURE(rc))
1466 {
1467 LogRel(("SMC: Retrieving the SMC key from the OS failed (%Rrc), trying to read it from hardware\n", rc));
1468# endif
1469 rc = PDMDevHlpCallR0(pDevIns, SMC_CALLR0_READ_OSK, 0 /*uArg*/);
1470 if (RT_SUCCESS(rc))
1471 LogRel(("SMC: Successfully retrieved the SMC key from hardware\n"));
1472 else
1473 LogRel(("SMC: Retrieving the SMC key from hardware failed(%Rrc)\n", rc));
1474# ifdef RT_OS_DARWIN
1475 }
1476 else
1477 LogRel(("SMC: Successfully retrieved the SMC key from the OS\n"));
1478# endif
1479 if (RT_FAILURE(rc))
1480 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
1481 N_("Failed to query SMC value from the host"));
1482 }
1483
1484 /*
1485 * Register I/O Ports
1486 */
1487 rc = PDMDevHlpIoPortCreateAndMap(pDevIns, SMC_PORT_FIRST, SMC_REG_COUNT, smcIoPortWrite, smcIoPortRead,
1488 "SMC data port", NULL, &pThis->hIoPorts);
1489 AssertRCReturn(rc, rc);
1490
1491 /** @todo Newer versions (2.03) have an MMIO mapping as well (ACPI). */
1492
1493
1494 /*
1495 * Saved state.
1496 */
1497 rc = PDMDevHlpSSMRegister(pDevIns, SMC_SAVED_STATE_VERSION, sizeof(*pThis), smcR3SaveExec, smcR3LoadExec);
1498 if (RT_FAILURE(rc))
1499 return rc;
1500
1501 return VINF_SUCCESS;
1502}
1503
1504#else /* !IN_RING3 */
1505
1506/**
1507 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
1508 */
1509static DECLCALLBACK(int) smcRZConstruct(PPDMDEVINS pDevIns)
1510{
1511 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
1512 PDEVSMC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSMC);
1513
1514 int rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPorts, smcIoPortWrite, smcIoPortRead, NULL /*pvUser*/);
1515 AssertRCReturn(rc, rc);
1516 RT_NOREF(pThis);
1517
1518 return VINF_SUCCESS;
1519}
1520
1521#endif /* !IN_RING3 */
1522
1523
1524/**
1525 * The device registration structure.
1526 */
1527const PDMDEVREG g_DeviceSmc =
1528{
1529 /* .u32Version = */ PDM_DEVREG_VERSION,
1530 /* .uReserved0 = */ 0,
1531 /* .szName = */ "smc",
1532 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ | PDM_DEVREG_FLAGS_NEW_STYLE,
1533 /* .fClass = */ PDM_DEVREG_CLASS_ARCH,
1534 /* .cMaxInstances = */ 1,
1535 /* .uSharedVersion = */ 42,
1536 /* .cbInstanceShared = */ sizeof(DEVSMC),
1537 /* .cbInstanceCC = */ 0,
1538 /* .cbInstanceRC = */ 0,
1539 /* .cMaxPciDevices = */ 0,
1540 /* .cMaxMsixVectors = */ 0,
1541 /* .pszDescription = */ "Apple System Management Controller",
1542#if defined(IN_RING3)
1543 /* .pszRCMod = */ "VBoxDDRC.rc",
1544 /* .pszR0Mod = */ "VBoxDDR0.r0",
1545 /* .pfnConstruct = */ smcR3Construct,
1546 /* .pfnDestruct = */ NULL,
1547 /* .pfnRelocate = */ NULL,
1548 /* .pfnMemSetup = */ NULL,
1549 /* .pfnPowerOn = */ NULL,
1550 /* .pfnReset = */ NULL,
1551 /* .pfnSuspend = */ NULL,
1552 /* .pfnResume = */ NULL,
1553 /* .pfnAttach = */ NULL,
1554 /* .pfnDetach = */ NULL,
1555 /* .pfnQueryInterface = */ NULL,
1556 /* .pfnInitComplete = */ NULL,
1557 /* .pfnPowerOff = */ NULL,
1558 /* .pfnSoftReset = */ NULL,
1559 /* .pfnReserved0 = */ NULL,
1560 /* .pfnReserved1 = */ NULL,
1561 /* .pfnReserved2 = */ NULL,
1562 /* .pfnReserved3 = */ NULL,
1563 /* .pfnReserved4 = */ NULL,
1564 /* .pfnReserved5 = */ NULL,
1565 /* .pfnReserved6 = */ NULL,
1566 /* .pfnReserved7 = */ NULL,
1567#elif defined(IN_RING0)
1568 /* .pfnEarlyConstruct = */ NULL,
1569 /* .pfnConstruct = */ smcRZConstruct,
1570 /* .pfnDestruct = */ NULL,
1571 /* .pfnFinalDestruct = */ NULL,
1572# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
1573 /* .pfnRequest = */ devR0SmcReqHandler,
1574# else
1575 /* .pfnRequest = */ NULL,
1576# endif
1577 /* .pfnReserved0 = */ NULL,
1578 /* .pfnReserved1 = */ NULL,
1579 /* .pfnReserved2 = */ NULL,
1580 /* .pfnReserved3 = */ NULL,
1581 /* .pfnReserved4 = */ NULL,
1582 /* .pfnReserved5 = */ NULL,
1583 /* .pfnReserved6 = */ NULL,
1584 /* .pfnReserved7 = */ NULL,
1585#elif defined(IN_RC)
1586 /* .pfnConstruct = */ smcRZConstruct,
1587 /* .pfnReserved0 = */ NULL,
1588 /* .pfnReserved1 = */ NULL,
1589 /* .pfnReserved2 = */ NULL,
1590 /* .pfnReserved3 = */ NULL,
1591 /* .pfnReserved4 = */ NULL,
1592 /* .pfnReserved5 = */ NULL,
1593 /* .pfnReserved6 = */ NULL,
1594 /* .pfnReserved7 = */ NULL,
1595#else
1596# error "Not in IN_RING3, IN_RING0 or IN_RC!"
1597#endif
1598 /* .u32VersionEnd = */ PDM_DEVREG_VERSION
1599};
1600
1601#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