goecprot.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /*++
  2. Copyright (c) 2015 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. goecprot.h
  5. Abstract:
  6. This header contains definitions for the Google Embedded Controller
  7. communication protocol.
  8. Author:
  9. Evan Green 25-Aug-2015
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. //
  15. // ---------------------------------------------------------------- Definitions
  16. //
  17. //
  18. // Define the current supported version of EC commands.
  19. //
  20. #define GOEC_COMMAND_HEADER_VERSION 3
  21. #define GOEC_RESPONSE_HEADER_VERSION GOEC_COMMAND_HEADER_VERSION
  22. #define GOEC_MESSAGE_HEADER_BYTES 3
  23. #define GOEC_MESSAGE_TRAILER_BYTES 2
  24. #define GOEC_MESSAGE_PROTOCOL_BYTES \
  25. (GOEC_MESSAGE_HEADER_BYTES + GOEC_MESSAGE_TRAILER_BYTES)
  26. #define GOEC_PROTO2_MAX_PARAM_SIZE 0xFC
  27. #define GOEC_PROTO3_MAX_PACKET_SIZE 268
  28. #define GOEC_MAX_DATA (GOEC_PROTO2_MAX_PARAM_SIZE + GOEC_MESSAGE_PROTOCOL_BYTES)
  29. //
  30. // Define NVRAM context values.
  31. //
  32. #define GOEC_VBNV_CONTEXT_VERSION 1
  33. #define GOEC_VBNV_CONTEXT_OP_READ 0
  34. #define GOEC_VBNV_CONTEXT_OP_WRITE 1
  35. #define GOEC_VBNV_BLOCK_SIZE 16
  36. //
  37. // Define NVRAM data values.
  38. //
  39. #define GOEC_NVRAM_HEADER_SIGNATURE_MASK 0xC0
  40. #define GOEC_NVRAM_HEADER_SIGNATURE_VALUE 0x40
  41. #define GOEC_NVRAM_HEADER_FIRMWARE_SETTINGS_RESET 0x20
  42. #define GOEC_NVRAM_HEADER_KERNEL_SETTINGS_RESET 0x10
  43. #define GOEC_NVRAM_HEADER_WIPEOUT 0x08
  44. #define GOEC_NVRAM_BOOT_DEBUG_RESET_MODE 0x80
  45. #define GOEC_NVRAM_BOOT_DISABLE_DEV_REQUEST 0x40
  46. #define GOEC_NVRAM_BOOT_OPROM_NEEDED 0x20
  47. #define GOEC_NVRAM_BOOT_BACKUP_NVRAM 0x10
  48. #define GOEC_NVRAM_BOOT_TRY_B_COUNT_MASK 0x0F
  49. #define GOEC_NVRAM_DEV_BOOT_USB 0x01
  50. #define GOEC_NVRAM_DEV_BOOT_SIGNED_ONLY 0x02
  51. #define GOEC_NVRAM_DEV_BOOT_LEGACY 0x04
  52. #define GOEC_NVRAM_DEV_BOOT_FASTBOOT_FULL_CAP 0x08
  53. #define GOEC_NVRAM_TPM_CLEAR_OWNER_REQUEST 0x01
  54. #define GOEC_NVRAM_TPM_CLEAR_OWNER_DONE 0x02
  55. #define GOEC_NVRAM_TPM_REBOOTED 0x04
  56. #define GOEC_NVRAM_BOOT2_RESULT_MASK 0x03
  57. #define GOEC_NVRAM_BOOT2_TRIED 0x04
  58. #define GOEC_NVRAM_BOOT2_TRY_NEXT 0x08
  59. #define GOEC_NVRAM_BOOT2_PREVIOUS_RESULT_MASK 0x30
  60. #define GOEC_NVRAM_BOOT2_PREVIOUS_RESULT_SHIFT 4
  61. #define GOEC_NVRAM_BOOT2_PREVIOUS_TRIED 0x40
  62. #define GOEC_NVRAM_MISC_UNLOCK_FASTBOOT 0x01
  63. #define GOEC_NVRAM_MISC_BOOT_ON_AC_DETECT 0x02
  64. //
  65. // ------------------------------------------------------ Data Type Definitions
  66. //
  67. typedef enum _GOEC_COMMAND_CODE {
  68. GoecCommandHello = 0x01,
  69. GoecCommandGetVersion = 0x02,
  70. GoecCommandReadTest = 0x03,
  71. GoecCommandGetBuildInfo = 0x04,
  72. GoecCommandGetChipInfo = 0x05,
  73. GoecCommandGetBoardVersion = 0x06,
  74. GoecCommandReadMemoryMap = 0x07,
  75. GoecCommandGetCommandVersions = 0x08,
  76. GoecCommandGetCommsStatus = 0x09,
  77. GoecCommandTestProtocol = 0x0A,
  78. GoecCommandGetProtocolInfo = 0x0B,
  79. GoecCommandFlashInfo = 0x10,
  80. GoecCommandFlashRead = 0x11,
  81. GoecCommandFlashWrite = 0x12,
  82. GoecCommandFlashErase = 0x13,
  83. GoecCommandFlashProtect = 0x15,
  84. GoecCommandFlashRegionInfo = 0x16,
  85. GoecCommandVbNvContext = 0x17,
  86. GoecCommandPwmGetFanTargetRpm = 0x20,
  87. GoecCommandPwmSetFanTargetRpm = 0x21,
  88. GoecCommandPwmGetKeyboardBacklight = 0x22,
  89. GoecCommandPwmSetKeyboardBacklight = 0x23,
  90. GoecCommandPwmSetFanDuty = 0x24,
  91. GoecCommandLightBar = 0x28,
  92. GoecCommandLedControl = 0x29,
  93. GoecCommandVBootHash = 0x2A,
  94. GoecCommandMotionSense = 0x2B,
  95. GoecCommandUsbChargeSetMode = 0x30,
  96. GoecCommandPstoreRead = 0x41,
  97. GoecCommandPstoreWrite = 0x42,
  98. GoecCommandRtcGetValue = 0x44,
  99. GoecCommandRtcGetAlarm = 0x45,
  100. GoecCommandRtcSetValue = 0x46,
  101. GoecCommandRtcSetAlarm = 0x47,
  102. GoecCommandPort80Read = 0x48,
  103. GoecCommandThermalSetThreshold = 0x50,
  104. GoecCommandThermalGetThreshold = 0x51,
  105. GoecCommandThermalAutoFanControl = 0x52,
  106. GoecCommandTmp006GetCalibration = 0x53,
  107. GoecCommandTmp006SetCalibration = 0x54,
  108. GoecCommandTmp006GetRaw = 0x55,
  109. GoecCommandKeyboardState = 0x60,
  110. GoecCommandKeyboardInfo = 0x61,
  111. GoecCommandKeyboardSimulateKey = 0x62,
  112. GoecCommandKeyboardSetConfig = 0x64,
  113. GoecCommandKeyboardGetConfig = 0x65,
  114. GoecCommandKeyscanSequenceControl = 0x66,
  115. GoecCommandTempSensorGetInfo = 0x70,
  116. GoecCommandAcpiRead = 0x80,
  117. GoecCommandAcpiWrite = 0x81,
  118. GoecCommandAcpiQueryEvent = 0x84,
  119. GoecCommandHostGetEventB = 0x87,
  120. GoecCommandHostGetSmiMask = 0x88,
  121. GoecCommandHostGetSciMask = 0x89,
  122. GoecCommandHostGetWakeMask = 0x8D,
  123. GoecCommandHostSetSmiMask = 0x8A,
  124. GoecCommandHostSetSciMask = 0x8B,
  125. GoecCommandHostEventClear = 0x8C,
  126. GoecCommandHostSetWakeMask = 0x8E,
  127. GoecCommandHostClearB = 0x8F,
  128. GoecCommandSwitchEnableBacklight = 0x90,
  129. GoecCommandSwitchEnableWireless = 0x91,
  130. GoecCommandGpioSet = 0x92,
  131. GoecCommandGpioGet = 0x93,
  132. GoecCommandI2cRead = 0x94,
  133. GoecCommandI2cWrite = 0x95,
  134. GoecCommandChargeControl = 0x96,
  135. GoecCommandConsoleSnapshot = 0x97,
  136. GoecCommandConsoleRead = 0x98,
  137. GoecCommandBatteryCutoff = 0x99,
  138. GoecCommandUsbMux = 0x9A,
  139. GoecCommandLdoSet = 0x9B,
  140. GoecCommandLdoGet = 0x9C,
  141. GoecCommandPowerInfo = 0x9D,
  142. GoecCommandI2cPassthrough = 0x9E,
  143. GoecCommandHangDetect = 0x9F,
  144. GoecCommandChargeState = 0xA0,
  145. GoecCommandChargeCurrentLimit = 0xA1,
  146. GoecCommandExtPowerCurrentLimit = 0xA2,
  147. GoecCommandBatteryReadWord = 0xB0,
  148. GoecCommandBatteryWriteWord = 0xB1,
  149. GoecCommandBatteryReadBlock = 0xB2,
  150. GoecCommandBatteryWriteBlock = 0xB3,
  151. GoecCommandBatteryVendorParameter = 0xB4,
  152. GoecCommandFirmwareUpdate = 0xB5,
  153. GoecCommandEnteringMode = 0xB6,
  154. GoecCommandRebootEc = 0xD2,
  155. GoecCommandGetPanicInfo = 0xD3,
  156. GoecCommandReboot = 0xD1,
  157. GoecCommandResendResponse = 0xD2,
  158. GoecCommandVersion0 = 0xDC,
  159. GoecCommandPdExchangeStatus = 0x100,
  160. GoecCommandUsePdControl = 0x101,
  161. GoecCommandUsbPdFirmwareUpdate = 0x110,
  162. GoecCommandUsbPdRwHashEntry = 0x111,
  163. GoecCommandUsbPdDevInfo = 0x112
  164. } GOEC_COMMAND_CODE, *PGOEC_COMMAND_CODE;
  165. typedef enum _GOEC_SPI_STATUS {
  166. GoecSpiFrameStart = 0xEC,
  167. GoecSpiPastEnd = 0xED,
  168. GoecSpiRxReady = 0xF8,
  169. GoecSpiReceiving = 0xF9,
  170. GoecSpiProcessing = 0xFA,
  171. GoecSpiRxBadData = 0xFB,
  172. GoecSpiNotReady = 0xFC,
  173. GoecSpiOldReady = 0xFD
  174. } GOEC_SPI_STATUS, *PGOEC_SPI_STATUS;
  175. typedef enum _GOEC_STATUS {
  176. GoecStatusSuccess = 0,
  177. GoecStatusInvalidCommand = 1,
  178. GoecStatusError = 2,
  179. GoecStatusInvalidParameter = 3,
  180. GoecStatusAccessDenied = 4,
  181. GoecStatusInvalidResponse = 5,
  182. GoecStatusInvalidVersion = 6,
  183. GoecStatusInvalidChecksum = 7,
  184. GoecStatusInProgress = 8,
  185. GoecStatusUnavailable = 9,
  186. GoecStatusTimeout = 10,
  187. GoecStatusOverflow = 11,
  188. GoecStatusInvalidHeader = 12,
  189. GoecStatusRequestTruncated = 13,
  190. GoecStatusResponseTooBig = 14
  191. } GOEC_STATUS, *PGOEC_STATUS;
  192. /*++
  193. Structure Description:
  194. This structure defines the software structure of a Google Embedded
  195. Controller command.
  196. Members:
  197. Code - Stores the command code on input, and status on output.
  198. Version - Stores the command version.
  199. DataIn - Stores an optional pointer to the command data.
  200. DataOut - Stores an optional pointer to the response data.
  201. SizeIn - Stores the size of the command data.
  202. SizeOut - Stores the expected size of the command response on input.
  203. Returns the actual size of data received on output.
  204. DeviceIndex - Stores the device index for I2C passthrough.
  205. --*/
  206. typedef struct _GOEC_COMMAND {
  207. USHORT Code;
  208. UCHAR Version;
  209. PVOID DataIn;
  210. PVOID DataOut;
  211. USHORT SizeIn;
  212. USHORT SizeOut;
  213. INT DeviceIndex;
  214. } GOEC_COMMAND, *PGOEC_COMMAND;
  215. /*++
  216. Structure Description:
  217. This structure defines the hardware structure of a Google Embedded
  218. Controller command header.
  219. Members:
  220. Version - Stores the version of this structure. Set to
  221. GOEC_COMMAND_HEADER_VERSION.
  222. Checksum - Stores the checksum of the request and data. The checksum is
  223. defined such that the sum of all the bytes including the checksum
  224. should total zero.
  225. Command - Stores the command code.
  226. CommandVersion - Stores the version number of the command.
  227. Reserved - Stores a reserved byte that should always be zero.
  228. DataLength - Stores the length of the data following this header.
  229. --*/
  230. typedef struct _GOEC_COMMAND_HEADER {
  231. UCHAR Version;
  232. UCHAR Checksum;
  233. USHORT Command;
  234. UCHAR CommandVersion;
  235. UCHAR Reserved;
  236. USHORT DataLength;
  237. } PACKED GOEC_COMMAND_HEADER, *PGOEC_COMMAND_HEADER;
  238. /*++
  239. Structure Description:
  240. This structure defines the hardware structure of a Google Embedded
  241. Controller response header.
  242. Members:
  243. Version - Stores the version of this structure. Set to
  244. GOEC_RESPONSE_HEADER_VERSION.
  245. Checksum - Stores the checksum of the request and data. The checksum is
  246. defined such that the sum of all the bytes including the checksum
  247. should total zero.
  248. Result - Stores the result code of the command.
  249. DataLength - Stores the length of the data following this header.
  250. Reserved - Stores a reserved value that should always be zero.
  251. --*/
  252. typedef struct _GOEC_RESPONSE_HEADER {
  253. UCHAR Version;
  254. UCHAR Checksum;
  255. USHORT Result;
  256. USHORT DataLength;
  257. USHORT Reserved;
  258. } PACKED GOEC_RESPONSE_HEADER, *PGOEC_RESPONSE_HEADER;
  259. /*++
  260. Structure Description:
  261. This structure defines the hardware structure of a Google Embedded
  262. Controller command, version 3.
  263. Members:
  264. Header - Stores the common packet header.
  265. Data - Stores the command-specific data.
  266. --*/
  267. typedef struct _GOEC_COMMAND_V3 {
  268. GOEC_COMMAND_HEADER Header;
  269. UCHAR Data[GOEC_MAX_DATA];
  270. } GOEC_COMMAND_V3, *PGOEC_COMMAND_V3;
  271. /*++
  272. Structure Description:
  273. This structure defines the hardware structure of a Google Embedded
  274. Controller response, version 3.
  275. Members:
  276. Header - Stores the common response header.
  277. Data - Stores the command-specific data.
  278. --*/
  279. typedef struct _GOEC_RESPONSE_V3 {
  280. GOEC_RESPONSE_HEADER Header;
  281. UCHAR Data[GOEC_MAX_DATA];
  282. } GOEC_RESPONSE_V3, *PGOEC_RESPONSE_V3;
  283. /*++
  284. Structure Description:
  285. This structure defines the parameters for the Hello command.
  286. Members:
  287. InData - Stores any value.
  288. --*/
  289. typedef struct _GOEC_PARAMS_HELLO {
  290. ULONG InData;
  291. } PACKED GOEC_PARAMS_HELLO, *PGOEC_PARAMS_HELLO;
  292. /*++
  293. Structure Description:
  294. This structure defines the response for the Hello command.
  295. Members:
  296. OutData - Stores the parameter InData plus 0x01020304.
  297. --*/
  298. typedef struct _GOEC_RESPONSE_HELLO {
  299. ULONG OutData;
  300. } PACKED GOEC_RESPONSE_HELLO, *PGOEC_RESPONSE_HELLO;
  301. typedef enum _GOEC_CURRENT_IMAGE {
  302. GoecImageUnknown = 0,
  303. GoecImageReadOnly = 1,
  304. GoecImageReadWrite = 2,
  305. } GOEC_CURRENT_IMAGE, *PGOEC_CURRENT_IMAGE;
  306. /*++
  307. Structure Description:
  308. This structure defines the response for the Get Version command.
  309. Members:
  310. VersionStringRo - Stores the version string of the read-only firmware.
  311. VersionStringRw - Stores the version string of the read-write firmware.
  312. Reserved - Stores an unused string (that used to be the RW-B version).
  313. CurrentImage - Stores the current running image. See GOEC_CURRENT_IMAGE.
  314. --*/
  315. typedef struct _GOEC_RESPONSE_GET_VERSION {
  316. CHAR VersionStringRo[32];
  317. CHAR VersionStringRw[32];
  318. CHAR Reserved[32];
  319. ULONG CurrentImage;
  320. } PACKED GOEC_RESPONSE_GET_VERSION, *PGOEC_RESPONSE_GET_VERSION;
  321. /*++
  322. Structure Description:
  323. This structure defines the response for the Keyboard Information
  324. command.
  325. Members:
  326. Rows - Stores the number of rows in the matrix keyboard.
  327. Columns - Stores the number of columns in the matrix keyboard.
  328. Switches - Stores the number of switches in the matrix keyboard.
  329. --*/
  330. typedef struct _GOEC_RESPONSE_KEYBOARD_INFO {
  331. ULONG Rows;
  332. ULONG Columns;
  333. UCHAR Switches;
  334. } PACKED GOEC_RESPONSE_KEYBOARD_INFO, *PGOEC_RESPONSE_KEYBOARD_INFO;
  335. /*++
  336. Structure Description:
  337. This structure defines the the the response for a verified boot NVRAM
  338. request.
  339. Members:
  340. Header - Stores some header bits and global reset bits.
  341. BootFlags - Stores boot command flag bits, like debug reset mode, disable
  342. dev request, and backup NVRAM bits.
  343. Recovery - Stores the recovery information.
  344. Localization - Stores the localization information.
  345. DevFlags - Stores developer mode flags, like enabling USB/SD boot or
  346. requiring signed kernels.
  347. TpmFlags - Stores TPM flags, like clearing the TPM owner.
  348. RecoverSubcode - Stores the recovery subcode.
  349. Boot2 - Stores additional boot flags like the boot results mask.
  350. Miscellaneous - Stores miscellaneous flags like unlocking fastboot or
  351. booting on AC detect.
  352. Reserved - Stores two currently unused bytes.
  353. KernelField - Stores the kernel field value.
  354. Reserved2 - Stores an additional set of unused bytes.
  355. Crc8 - Stores the CRC8 of the table, except for this byte.
  356. --*/
  357. typedef struct _GOEC_NVRAM {
  358. UCHAR Header;
  359. UCHAR BootFlags;
  360. UCHAR Recovery;
  361. UCHAR Localization;
  362. UCHAR DevFlags;
  363. UCHAR TpmFlags;
  364. UCHAR RecoverySubcode;
  365. UCHAR Boot2;
  366. UCHAR Miscellaneous;
  367. UCHAR Reserved[2];
  368. UCHAR KernelField;
  369. UCHAR Reserved2[3];
  370. UCHAR Crc8;
  371. } PACKED GOEC_NVRAM, *PGOEC_NVRAM;
  372. /*++
  373. Structure Description:
  374. This structure defines the request parameters for the verified boot
  375. non-volatile RAM request.
  376. Members:
  377. Operation - Stores the requested operation. See GOEC_VBNV_CONTEXT_OP_*
  378. definitions.
  379. NvRam - Stores the data to read or write.
  380. --*/
  381. typedef struct _GOEC_PARAMS_VBNV_CONTEXT {
  382. ULONG Operation;
  383. GOEC_NVRAM NvRam;
  384. } PACKED GOEC_PARAMS_VBNV_CONTEXT, *PGOEC_PARAMS_VBNV_CONTEXT;
  385. /*++
  386. Structure Description:
  387. This structure defines the response for a verified boot NVRAM request.
  388. Members:
  389. NvRam - Stores the resulting data.
  390. --*/
  391. typedef struct _GOEC_RESPONSE_VBNV_CONTEXT {
  392. GOEC_NVRAM NvRam;
  393. } PACKED GOEC_RESPONSE_VBNV_CONTEXT, *PGOEC_RESPONSE_VBNV_CONTEXT;
  394. //
  395. // -------------------------------------------------------------------- Globals
  396. //
  397. //
  398. // -------------------------------------------------------- Function Prototypes
  399. //