1 | /*␊ |
2 | * Copyright 2011 cparm <armelcadetpetit@gmail.com>. All rights reserved.␊ |
3 | */␊ |
4 | #include "boot.h"␊ |
5 | #include "bootstruct.h"␊ |
6 | #include "libsaio.h"␊ |
7 | #include "modules.h"␊ |
8 | #include "Platform.h"␊ |
9 | #include "smbios_patcher.h"␊ |
10 | #include "efi.h"␊ |
11 | ␊ |
12 | #ifndef DEBUG_SMBIOS␊ |
13 | #define DEBUG_SMBIOS 0␊ |
14 | #endif␊ |
15 | ␊ |
16 | #if DEBUG_SMBIOS==2␊ |
17 | #define DBG(x...)␉printf(x)␊ |
18 | #elif DEBUG_SMBIOS==1␊ |
19 | #define DBG(x...) msglog(x)␊ |
20 | #else␊ |
21 | #define DBG(x...)␉␊ |
22 | #endif␊ |
23 | ␊ |
24 | void getSmbiosPatched_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
25 | {␉␊ |
26 | ␉struct SMBEntryPoint *smbios_o = (struct SMBEntryPoint *)arg1;␊ |
27 | ␉struct SMBEntryPoint *patched_smb = NULL;␊ |
28 | ␉␊ |
29 | ␉execute_hook("ScanMemory", NULL, NULL, NULL, NULL, NULL, NULL);␉␊ |
30 | ␉␊ |
31 | ␉patched_smb = getSmbiosPatched(smbios_o);␊ |
32 | ␉␊ |
33 | ␉if (patched_smb)␊ |
34 | ␉␉smbios_p = (EFI_PTR32)patched_smb; ␊ |
35 | ␉else␊ |
36 | ␉␉verbose("Error: Could not get patched SMBIOS, fallback to original SMBIOS !!\n");␊ |
37 | }␊ |
38 | ␊ |
39 | void smbios_helper_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
40 | {␉␊ |
41 | ␉struct SMBEntryPoint *orig = (struct SMBEntryPoint *)arg1;␊ |
42 | ␉getSmbiosTableStructure(orig); // generate tables entry list for fast table finding␊ |
43 | ␉␉␊ |
44 | ␉if (is_module_loaded("Memory")) ␊ |
45 | ␉scan_memory(Platform);␊ |
46 | }␊ |
47 | ␊ |
48 | void getProductName_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
49 | {␉␊ |
50 | ␉setupSmbiosConfigFile("SMBIOS.plist");␊ |
51 | ␉int len = 0;␊ |
52 | ␉const char *val = 0;␊ |
53 | ␉␊ |
54 | ␉if (getValueForKey("SMproductname", &val, &len, &bootInfo->smbiosConfig)) {␊ |
55 | ␉␉gPlatformName = (char *)val;␊ |
56 | ␉} else {␊ |
57 | ␉␉const char *productName = sm_get_defstr("SMproductname", 0);␉␊ |
58 | ␉␉gPlatformName = (char *)productName;␊ |
59 | ␉}␉␊ |
60 | ␉DBG("SMBIOS Product name: %s\n",productName);␊ |
61 | ␊ |
62 | ␉␊ |
63 | }␊ |
64 | ␊ |
65 | void SMBiosPatcher_start()␊ |
66 | {␉␊ |
67 | ␉register_hook_callback("getSmbiosPatched", &getSmbiosPatched_hook);␉␊ |
68 | ␉register_hook_callback("smbios_helper", &smbios_helper_hook);␊ |
69 | ␉register_hook_callback("getProductNamePatched", &getProductName_hook);␊ |
70 | }␊ |
71 | |