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 "boot.h"␊ |
15 | #include "bootstruct.h"␊ |
16 | #include "modules.h"␊ |
17 | ␊ |
18 | #define DEBUG_MEMORY 0␊ |
19 | ␊ |
20 | #if DEBUG_MEMORY␊ |
21 | #define DBG(x...) verbose(x)␊ |
22 | #else␊ |
23 | #define DBG(x...)␊ |
24 | #endif␊ |
25 | ␊ |
26 | ␊ |
27 | pci_dt_t * dram_controller_dev = NULL;␊ |
28 | pci_dt_t * smbus_controller_dev = NULL;␊ |
29 | ␊ |
30 | ␊ |
31 | void Memory_hook(void* arg1, void* arg2, void* arg3, void* arg4);␊ |
32 | void Memory_PCIDevice_hook(void* arg1, void* arg2, void* arg3, void* arg4);␊ |
33 | ␊ |
34 | ␊ |
35 | void Memory_start()␊ |
36 | {␊ |
37 | ␉register_hook_callback("PCIDevice", &Memory_PCIDevice_hook);␊ |
38 | ␉register_hook_callback("ScanMemory", &Memory_hook);␊ |
39 | ␉␊ |
40 | }␊ |
41 | ␊ |
42 | void Memory_PCIDevice_hook(void* arg1, void* arg2, void* arg3, void* arg4)␊ |
43 | {␊ |
44 | ␉pci_dt_t* current = arg1;␊ |
45 | ␉if(current->class_id == PCI_CLASS_BRIDGE_HOST)␊ |
46 | ␉{␊ |
47 | ␉␉dram_controller_dev = current;␊ |
48 | ␉␉DBG("dram_controller_dev found devID=%08x\n", current->device_id);␊ |
49 | ␉}␊ |
50 | ␉else if(is_smbus_controller(current))␊ |
51 | ␉{␊ |
52 | ␉␉smbus_controller_dev = current;␊ |
53 | ␉␉DBG("smbus_controller_dev found devID=%08x\n", current->device_id);␊ |
54 | ␉}␊ |
55 | ␊ |
56 | }␊ |
57 | ␊ |
58 | void Memory_hook(void* arg1, void* arg2, void* arg3, void* arg4)␊ |
59 | {␊ |
60 | ␉bool useAutodetection = true;␊ |
61 | getBoolForKey(kUseMemDetect, &useAutodetection, &bootInfo->bootConfig);␊ |
62 | ␉␊ |
63 | ␉␊ |
64 | if (useAutodetection) {␊ |
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 | ␉␉scan_memory(Platform); // unfortunately still necesary for some comp where spd cant read correct speed␊ |
70 | ␉␉DBG("scan_memory \n");␊ |
71 | ␉␉if(smbus_controller_dev)␊ |
72 | ␉␉{␊ |
73 | ␉␉␉scan_spd(Platform, smbus_controller_dev);␊ |
74 | ␉␉␉DBG("scan_spd \n");␊ |
75 | ␉␉}␊ |
76 | }␊ |
77 | ␉␊ |
78 | } |