1 | /*␊ |
2 | * Copyright 2011,2012 cparm. All rights reserved.␊ |
3 | */␊ |
4 | #include "libsaio.h"␊ |
5 | #include "bootstruct.h"␊ |
6 | #include "modules.h"␊ |
7 | #include "Platform.h"␊ |
8 | #include "smbios_patcher.h"␊ |
9 | #include "efi.h"␊ |
10 | ␊ |
11 | #ifndef DEBUG_SMBIOS␊ |
12 | #define DEBUG_SMBIOS 0␊ |
13 | #endif␊ |
14 | ␊ |
15 | #if DEBUG_SMBIOS==2␊ |
16 | #define DBG(x...)␉printf(x)␊ |
17 | #elif DEBUG_SMBIOS==1␊ |
18 | #define DBG(x...) msglog(x)␊ |
19 | #else␊ |
20 | #define DBG(x...)␉␊ |
21 | #endif␊ |
22 | ␊ |
23 | void getSmbiosPatched_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);␊ |
24 | void getProductName_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);␊ |
25 | void getboardproduct_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);␊ |
26 | ␊ |
27 | void getSmbiosPatched_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
28 | {␉␊ |
29 | ␉struct SMBEntryPoint *patched_smb = NULL;␊ |
30 | ␉␊ |
31 | getSmbiosTableStructure(getSmbiosOriginal()); // generate tables entry list for fast table finding␊ |
32 | ␊ |
33 | ␉if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) ␊ |
34 | scan_memory();␊ |
35 | ␊ |
36 | ␉execute_hook("ScanMemory", NULL, NULL, NULL, NULL, NULL, NULL);␉␊ |
37 | ␉␊ |
38 | ␉patched_smb = getSmbiosPatched(getSmbiosOriginal());␊ |
39 | ␉␊ |
40 | ␉if (patched_smb)␊ |
41 | Register_Smbios_Efi(patched_smb);␊ |
42 | ␉else␊ |
43 | {␊ |
44 | ␉␉verbose("Error: Could not get patched SMBIOS, fallback to original SMBIOS !!\n");␊ |
45 | ␊ |
46 | Register_Smbios_Efi(getSmbiosOriginal());␊ |
47 | ␊ |
48 | } ␊ |
49 | ␊ |
50 | }␊ |
51 | ␊ |
52 | void getProductName_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
53 | {␉␊ |
54 | ␉setupSmbiosConfigFile("SMBIOS.plist");␊ |
55 | ␉int len = 0;␊ |
56 | ␉const char *val = 0;␊ |
57 | ␉␊ |
58 | ␉if (getValueForKey("SMproductname", &val, &len, DEFAULT_SMBIOS_CONFIG)) {␊ |
59 | ␉␉SetgPlatformName(val);␊ |
60 | ␉} else {␊ |
61 | ␉␉const char *productName = sm_get_defstr("SMproductname", 0);␉␊ |
62 | ␉␉SetgPlatformName(productName);␊ |
63 | ␉}␉␊ |
64 | ␉DBG("SMBIOS Product name: %s\n",productName);␊ |
65 | ␊ |
66 | ␉␊ |
67 | }␊ |
68 | ␊ |
69 | void getboardproduct_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
70 | {␉␊ |
71 | ␉setupSmbiosConfigFile("SMBIOS.plist");␊ |
72 | ␉int len = 0;␊ |
73 | ␉const char *val = 0;␊ |
74 | ␉␊ |
75 | ␉if (getValueForKey("SMboardproduct", &val, &len, DEFAULT_SMBIOS_CONFIG)) {␊ |
76 | ␊ |
77 | ␉␉Setgboardproduct(val);␊ |
78 | ␊ |
79 | ␉} else {␊ |
80 | const char *productBoard = sm_get_defstr("SMboardproduct", 0);␉␊ |
81 | Setgboardproduct(productBoard);␊ |
82 | ␉}␉␊ |
83 | ␉␊ |
84 | }␊ |
85 | ␊ |
86 | void SMBiosPatcher_start(void);␊ |
87 | void SMBiosPatcher_start(void)␊ |
88 | {␉␊ |
89 | ␊ |
90 | ␉register_hook_callback("getSmbiosPatched", &getSmbiosPatched_hook);␉␊ |
91 | ␉register_hook_callback("getProductNamePatched", &getProductName_hook);␊ |
92 | register_hook_callback("getboardproductPatched", &getboardproduct_hook);␊ |
93 | ␊ |
94 | }␊ |
95 | |