1 | /*␊ |
2 | * DRAM Controller Module␊ |
3 | * Scans the dram controller and notifies OS X of the memory modules.␊ |
4 | *␉This was converted from boot2 code to a boot2 module.␊ |
5 | *␊ |
6 | */␊ |
7 | ␊ |
8 | #include "libsaio.h"␊ |
9 | #include "pci.h"␊ |
10 | #include "platform.h"␊ |
11 | #include "dram_controllers.h"␊ |
12 | #include "spd.h"␊ |
13 | #include "mem.h"␊ |
14 | #include "bootstruct.h"␊ |
15 | #include "modules.h"␊ |
16 | ␊ |
17 | #define kEnableMemory␉␉"EnableMemoryModule"␉ ␊ |
18 | ␊ |
19 | pci_dt_t * dram_controller_dev = NULL;␊ |
20 | pci_dt_t * smbus_controller_dev = NULL;␊ |
21 | ␊ |
22 | ␊ |
23 | void Memory_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);␊ |
24 | void Memory_PCIDevice_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);␊ |
25 | void is_Memory_Registred_Hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);␊ |
26 | ␊ |
27 | void is_Memory_Registred_Hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6){}␊ |
28 | ␊ |
29 | void Memory_start(void);␊ |
30 | void Memory_start(void)␊ |
31 | {␊ |
32 | ␉␊ |
33 | ␉bool enable = true;␊ |
34 | ␉␊ |
35 | ␉getBoolForKey(kEnableMemory, &enable, DEFAULT_BOOT_CONFIG);␊ |
36 | ␊ |
37 | if (pci_config_read16(PCIADDR(0, 0x00, 0), 0x00) != 0x8086) ␊ |
38 | ␉␉enable = false;␊ |
39 | ␉␊ |
40 | ␉enable = (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS);␊ |
41 | ␉ ␊ |
42 | if (enable) {␊ |
43 | ␉␉register_hook_callback("PCIDevice", &Memory_PCIDevice_hook);␊ |
44 | ␉␉register_hook_callback("ScanMemory", &Memory_hook);␊ |
45 | ␉␉register_hook_callback("isMemoryRegistred", &is_Memory_Registred_Hook);␊ |
46 | ␉}␊ |
47 | }␊ |
48 | ␊ |
49 | void Memory_PCIDevice_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
50 | {␊ |
51 | ␉pci_dt_t* current = arg1;␊ |
52 | ␉if(current->class_id == PCI_CLASS_BRIDGE_HOST)␊ |
53 | ␉{␊ |
54 | ␉␉dram_controller_dev = current;␊ |
55 | ␉}␊ |
56 | ␉else if(is_smbus_controller(current))␊ |
57 | ␉{␊ |
58 | ␉␉smbus_controller_dev = current;␊ |
59 | ␉}␊ |
60 | ␊ |
61 | }␊ |
62 | ␊ |
63 | void Memory_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
64 | {␉␊ |
65 | ␉␊ |
66 | ␉if (dram_controller_dev!=NULL) {␊ |
67 | ␉␉scan_dram_controller(dram_controller_dev); // Rek: pci dev ram controller direct and fully informative scan ...␊ |
68 | ␉}␊ |
69 | ␉␉␉␊ |
70 | ␉if(smbus_controller_dev)␊ |
71 | ␉{␊ |
72 | #if UNUSED␊ |
73 | ␉␉scan_spd(Platform, smbus_controller_dev);␊ |
74 | #else␊ |
75 | ␉␉scan_spd(smbus_controller_dev);␊ |
76 | #endif␊ |
77 | ␉}␊ |
78 | ␉␊ |
79 | } |