1
0

smbios.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. smbios.c
  5. Abstract:
  6. This module implements SMBIOS tables for the TI BeagleBone Black.
  7. Author:
  8. Evan Green 7-May-2014
  9. Environment:
  10. Firmware
  11. --*/
  12. //
  13. // ------------------------------------------------------------------- Includes
  14. //
  15. #include <minoca/lib/types.h>
  16. #include <minoca/fw/smbios.h>
  17. #include "uefifw.h"
  18. #include "bbonefw.h"
  19. //
  20. // ---------------------------------------------------------------- Definitions
  21. //
  22. #define BBONE_EEPROM_ADDRESS 0x50
  23. #define BBONE_SMBIOS_BIOS_VENDOR "Minoca Corp"
  24. #define BBONE_SMBIOS_SYSTEM_MANUFACTURER "Texas Instruments"
  25. #define BBONE_SMBIOS_MODULE_MANUFACTURER "Texas Instruments"
  26. #define BBONE_SMBIOS_PROCESSOR_MANUFACTURER "Texas Instruments"
  27. #define BBONE_SMBIOS_PROCESSOR_PART "AM3358"
  28. #define BBONE_SMBIOS_PROCESSOR_EXTERNAL_CLOCK 24
  29. #define BBONE_SMBIOS_PROCESSOR_MAX_SPEED 1000
  30. #define BBONE_SMBIOS_PROCESSOR_CURRENT_SPEED 1000
  31. #define BBONE_SMBIOS_PROCESSOR_CORE_COUNT 1
  32. #define BBONE_SMBIOS_CACHE_L1_SIZE 32
  33. #define BBONE_SMBIOS_CACHE_L2_SIZE 256
  34. #define BBONE_BLACK_EEPROM_HEADER 0xEE3355AA
  35. #define BBONE_BLACK_BOARD_NAME_SIZE 8
  36. #define BBONE_BLACK_VERSION_SIZE 4
  37. #define BBONE_BLACK_SERIAL_NUMBER_SIZE 12
  38. #define BBONE_BLACK_CONFIGURATION_OPTIONS_SIZE 32
  39. #define BBONE_BLACK_RESERVED_SIZE 6
  40. //
  41. // ------------------------------------------------------ Data Type Definitions
  42. //
  43. /*++
  44. Structure Description:
  45. This structure describes the format of the EEPROM in the BeagleBone Black.
  46. Members:
  47. Header - Stores the magic header value. Should be set to the value
  48. BBONE_BLACK_EEPROM_HEADER.
  49. BoardName - Stores the ASCII name for the board, which might be A335BNLT.
  50. Version - Stores the hardware version for the board in ASCII.
  51. SerialNumber - Stores the ASCII serial number for the board.
  52. Configuration - Stores the configuration data, contents currently unused.
  53. Reserved - Stores a reserved area.
  54. --*/
  55. typedef struct _EFI_BBONE_EEPROM {
  56. UINT32 Header;
  57. UINT8 BoardName[BBONE_BLACK_BOARD_NAME_SIZE];
  58. UINT8 Version[BBONE_BLACK_VERSION_SIZE];
  59. UINT8 SerialNumber[BBONE_BLACK_SERIAL_NUMBER_SIZE];
  60. UINT8 Configuration[BBONE_BLACK_CONFIGURATION_OPTIONS_SIZE];
  61. UINT8 Reserved[BBONE_BLACK_RESERVED_SIZE];
  62. } PACKED EFI_BBONE_EEPROM, *PEFI_BBONE_EEPROM;
  63. //
  64. // ----------------------------------------------- Internal Function Prototypes
  65. //
  66. EFI_STATUS
  67. EfipBeagleBoneBlackReadEeprom (
  68. VOID
  69. );
  70. //
  71. // -------------------------------------------------------------------- Globals
  72. //
  73. //
  74. // Store the EEPROM data.
  75. //
  76. EFI_BBONE_EEPROM EfiBeagleBoneBlackEeprom;
  77. SMBIOS_BIOS_INFORMATION EfiBeagleBoneSmbiosBiosInformation = {
  78. {
  79. SmbiosBiosInformation,
  80. sizeof(SMBIOS_BIOS_INFORMATION),
  81. 0x0100
  82. },
  83. 1,
  84. 2,
  85. 0,
  86. 3,
  87. 0,
  88. SMBIOS_BIOS_CHARACTERISTIC_UNSUPPORTED,
  89. 0,
  90. 0,
  91. 0,
  92. 0,
  93. 0
  94. };
  95. SMBIOS_SYSTEM_INFORMATION EfiBeagleBoneSmbiosSystemInformation = {
  96. {
  97. SmbiosSystemInformation,
  98. sizeof(SMBIOS_SYSTEM_INFORMATION),
  99. 0x0101
  100. },
  101. 1,
  102. 2,
  103. 3,
  104. 4,
  105. {0},
  106. SMBIOS_SYSTEM_WAKEUP_UNKNOWN,
  107. 3,
  108. 2
  109. };
  110. SMBIOS_MODULE_INFORMATION EfiBeagleBoneSmbiosModuleInformation = {
  111. {
  112. SmbiosModuleInformation,
  113. sizeof(SMBIOS_MODULE_INFORMATION),
  114. 0x0102
  115. },
  116. 1,
  117. 2,
  118. 0,
  119. 0,
  120. 0,
  121. SMBIOS_MODULE_MOTHERBOARD,
  122. 0,
  123. 0x0104,
  124. SMBIOS_MODULE_TYPE_MOTHERBOARD,
  125. 0
  126. };
  127. SMBIOS_ENCLOSURE EfiBeagleBoneSmbiosEnclosure = {
  128. {
  129. SmbiosSystemEnclosure,
  130. sizeof(SMBIOS_ENCLOSURE),
  131. 0x0104
  132. },
  133. 0,
  134. SMBIOS_ENCLOSURE_TYPE_UNKNOWN,
  135. 0,
  136. 0,
  137. 0,
  138. SMBIOS_ENCLOSURE_STATE_UNKNOWN,
  139. SMBIOS_ENCLOSURE_STATE_UNKNOWN,
  140. SMBIOS_ENCLOSURE_SECURITY_STATE_UNKNOWN,
  141. 0,
  142. 0,
  143. 0,
  144. 0,
  145. 0,
  146. 0
  147. };
  148. SMBIOS_PROCESSOR_INFORMATION EfiBeagleBoneSmbiosProcessorInformation = {
  149. {
  150. SmbiosProcessorInformation,
  151. sizeof(SMBIOS_PROCESSOR_INFORMATION),
  152. 0x0105
  153. },
  154. 0,
  155. SMBIOS_PROCESSOR_TYPE_CENTRAL_PROCESSOR,
  156. 0x2,
  157. 1,
  158. 0,
  159. 0,
  160. 0,
  161. BBONE_SMBIOS_PROCESSOR_EXTERNAL_CLOCK,
  162. BBONE_SMBIOS_PROCESSOR_MAX_SPEED,
  163. BBONE_SMBIOS_PROCESSOR_CURRENT_SPEED,
  164. SMBIOS_PROCESSOR_STATUS_ENABLED,
  165. 0,
  166. 0x0106,
  167. 0x0107,
  168. 0xFFFF,
  169. 2,
  170. 0,
  171. 3,
  172. BBONE_SMBIOS_PROCESSOR_CORE_COUNT,
  173. 0,
  174. SMBIOS_PROCESSOR_CHARACTERISTIC_UNKNOWN,
  175. 0
  176. };
  177. SMBIOS_CACHE_INFORMATION EfiBeagleBoneSmbiosL1Cache = {
  178. {
  179. SmbiosCacheInformation,
  180. sizeof(SMBIOS_CACHE_INFORMATION),
  181. 0x0106
  182. },
  183. 0,
  184. SMBIOS_CACHE_ENABLED | SMBIOS_CACHE_WRITE_BACK,
  185. BBONE_SMBIOS_CACHE_L1_SIZE,
  186. BBONE_SMBIOS_CACHE_L1_SIZE,
  187. SMBIOS_CACHE_SRAM_UNKNOWN,
  188. SMBIOS_CACHE_SRAM_UNKNOWN,
  189. 0,
  190. SMBIOS_CACHE_ERROR_CORRECTION_NONE,
  191. SMBIOS_CACHE_TYPE_DATA,
  192. SMBIOS_CACHE_ASSOCIATIVITY_4_WAY_SET
  193. };
  194. SMBIOS_CACHE_INFORMATION EfiBeagleBoneSmbiosL2Cache = {
  195. {
  196. SmbiosCacheInformation,
  197. sizeof(SMBIOS_CACHE_INFORMATION),
  198. 0x0107
  199. },
  200. 0,
  201. SMBIOS_CACHE_ENABLED | SMBIOS_CACHE_WRITE_BACK,
  202. BBONE_SMBIOS_CACHE_L2_SIZE,
  203. BBONE_SMBIOS_CACHE_L2_SIZE,
  204. SMBIOS_CACHE_SRAM_UNKNOWN,
  205. SMBIOS_CACHE_SRAM_UNKNOWN,
  206. 0,
  207. SMBIOS_CACHE_ERROR_CORRECTION_NONE,
  208. SMBIOS_CACHE_TYPE_DATA,
  209. SMBIOS_CACHE_ASSOCIATIVITY_16_WAY_SET
  210. };
  211. //
  212. // ------------------------------------------------------------------ Functions
  213. //
  214. EFI_STATUS
  215. EfipBeagleBoneCreateSmbiosTables (
  216. VOID
  217. )
  218. /*++
  219. Routine Description:
  220. This routine creates the SMBIOS tables.
  221. Arguments:
  222. None.
  223. Return Value:
  224. EFI Status code.
  225. --*/
  226. {
  227. CHAR8 ProductName[BBONE_BLACK_BOARD_NAME_SIZE + 1];
  228. CHAR8 ProductVersion[BBONE_BLACK_VERSION_SIZE + 1];
  229. CHAR8 SerialNumber[BBONE_BLACK_SERIAL_NUMBER_SIZE + 1];
  230. EFI_STATUS Status;
  231. Status = EfipBeagleBoneBlackReadEeprom();
  232. if (EFI_ERROR(Status)) {
  233. return Status;
  234. }
  235. EfiBeagleBoneSmbiosBiosInformation.BiosMajorRelease = EfiVersionMajor;
  236. EfiBeagleBoneSmbiosBiosInformation.BiosMinorRelease = EfiVersionMinor;
  237. Status = EfiSmbiosAddStructure(&EfiBeagleBoneSmbiosBiosInformation,
  238. BBONE_SMBIOS_BIOS_VENDOR,
  239. EfiBuildString,
  240. EfiBuildTimeString,
  241. NULL);
  242. if (EFI_ERROR(Status)) {
  243. return Status;
  244. }
  245. //
  246. // Set the serial number as the UUID.
  247. //
  248. EfiCopyMem(SerialNumber,
  249. EfiBeagleBoneBlackEeprom.SerialNumber,
  250. BBONE_BLACK_SERIAL_NUMBER_SIZE);
  251. SerialNumber[BBONE_BLACK_SERIAL_NUMBER_SIZE] = '\0';
  252. EfiCopyMem(EfiBeagleBoneSmbiosSystemInformation.Uuid,
  253. EfiBeagleBoneBlackEeprom.SerialNumber,
  254. BBONE_BLACK_SERIAL_NUMBER_SIZE);
  255. EfiCopyMem(ProductName,
  256. EfiBeagleBoneBlackEeprom.BoardName,
  257. BBONE_BLACK_BOARD_NAME_SIZE);
  258. ProductName[BBONE_BLACK_BOARD_NAME_SIZE] = '\0';
  259. EfiCopyMem(ProductVersion,
  260. EfiBeagleBoneBlackEeprom.Version,
  261. BBONE_BLACK_VERSION_SIZE);
  262. ProductVersion[BBONE_BLACK_VERSION_SIZE] = '\0';
  263. Status = EfiSmbiosAddStructure(&EfiBeagleBoneSmbiosSystemInformation,
  264. BBONE_SMBIOS_SYSTEM_MANUFACTURER,
  265. ProductName,
  266. ProductVersion,
  267. SerialNumber,
  268. NULL);
  269. if (EFI_ERROR(Status)) {
  270. return Status;
  271. }
  272. Status = EfiSmbiosAddStructure(&EfiBeagleBoneSmbiosModuleInformation,
  273. BBONE_SMBIOS_MODULE_MANUFACTURER,
  274. ProductName,
  275. NULL);
  276. if (EFI_ERROR(Status)) {
  277. return Status;
  278. }
  279. Status = EfiSmbiosAddStructure(&EfiBeagleBoneSmbiosEnclosure, NULL);
  280. if (EFI_ERROR(Status)) {
  281. return Status;
  282. }
  283. Status = EfiSmbiosAddStructure(&EfiBeagleBoneSmbiosProcessorInformation,
  284. BBONE_SMBIOS_PROCESSOR_MANUFACTURER,
  285. SerialNumber,
  286. BBONE_SMBIOS_PROCESSOR_PART,
  287. NULL);
  288. if (EFI_ERROR(Status)) {
  289. return Status;
  290. }
  291. Status = EfiSmbiosAddStructure(&EfiBeagleBoneSmbiosL1Cache, NULL);
  292. if (EFI_ERROR(Status)) {
  293. return Status;
  294. }
  295. Status = EfiSmbiosAddStructure(&EfiBeagleBoneSmbiosL2Cache, NULL);
  296. if (EFI_ERROR(Status)) {
  297. return Status;
  298. }
  299. return EFI_SUCCESS;
  300. }
  301. //
  302. // --------------------------------------------------------- Internal Functions
  303. //
  304. EFI_STATUS
  305. EfipBeagleBoneBlackReadEeprom (
  306. VOID
  307. )
  308. /*++
  309. Routine Description:
  310. This routine reads and verifies the EEPROM in the BeagleBone Black.
  311. Arguments:
  312. None.
  313. Return Value:
  314. EFI Status code.
  315. --*/
  316. {
  317. UINT16 Address;
  318. EfipAm335I2c0Initialize();
  319. EfipAm335I2c0SetSlaveAddress(BBONE_EEPROM_ADDRESS);
  320. //
  321. // Write the 0 address to the EEPROM to reset its internal address counter.
  322. //
  323. Address = 0;
  324. EfipAm335I2c0Write(-1, 2, (UINT8 *)&Address);
  325. //
  326. // Now read the EEPROM structure.
  327. //
  328. EfipAm335I2c0Read(-1,
  329. sizeof(EFI_BBONE_EEPROM),
  330. (UINT8 *)&EfiBeagleBoneBlackEeprom);
  331. if (EfiBeagleBoneBlackEeprom.Header != BBONE_BLACK_EEPROM_HEADER) {
  332. return EFI_NOT_FOUND;
  333. }
  334. return EFI_SUCCESS;
  335. }