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 "modules.h"␊ |
15 | ␊ |
16 | pci_dt_t *dram_controller_dev;␊ |
17 | ␊ |
18 | ␊ |
19 | void Memory_hook(void* arg1, void* arg2, void* arg3, void* arg4);␊ |
20 | void Memory_PCIDevice_hook(void* arg1, void* arg2, void* arg3, void* arg4);␊ |
21 | ␊ |
22 | ␊ |
23 | void Memory_start()␊ |
24 | {␊ |
25 | ␉register_hook_callback("PCIDevice", &Memory_PCIDevice_hook);␊ |
26 | ␉register_hook_callback("ScanMemory", &Memory_hook);␊ |
27 | ␉␊ |
28 | }␊ |
29 | ␊ |
30 | void Memory_PCIDevice_hook(void* arg1, void* arg2, void* arg3, void* arg4)␊ |
31 | {␊ |
32 | ␉pci_dt_t* current = arg1;␊ |
33 | ␉␊ |
34 | ␉if (current->class_id == PCI_CLASS_BRIDGE_HOST␊ |
35 | ␉␉&& (current->dev.addr == PCIADDR(0, 0, 0))␊ |
36 | ␉{␊ |
37 | ␉␉dram_controller_dev = current;␊ |
38 | ␉}␊ |
39 | }␊ |
40 | ␊ |
41 | void Memory_hook(void* arg1, void* arg2, void* arg3, void* arg4)␊ |
42 | {␊ |
43 | ␉if (dram_controller_dev!=NULL) {␊ |
44 | ␉␉scan_dram_controller(dram_controller_dev); // Rek: pci dev ram controller direct and fully informative scan ...␊ |
45 | ␉}␊ |
46 | ␉//Azi: gone on Kabyl's...???␊ |
47 | //␉scan_memory(&Platform); // unfortunately still necesary for some comp where spd cant read correct speed␊ |
48 | ␉scan_spd(&Platform);␊ |
49 | }␊ |
50 | ␊ |
51 | ␊ |
52 | ␊ |
53 | /* Nedded to devide 64bit numbers correctly. TODO: look into why the module needs this␊ |
54 | * And why it isn't needed when compiled into boot2␊ |
55 | */␊ |
56 | ␊ |
57 | uint64_t __udivdi3(uint64_t numerator, uint64_t denominator)␊ |
58 | {␊ |
59 | ␉uint64_t quotient = 0, qbit = 1;␊ |
60 | ␉␊ |
61 | ␉if (denominator)␊ |
62 | ␉{␊ |
63 | ␉␉while ((int64_t) denominator >= 0)␊ |
64 | ␉␉{␊ |
65 | ␉␉␉denominator <<= 1;␊ |
66 | ␉␉␉qbit <<= 1;␊ |
67 | ␉␉}␊ |
68 | ␉␉␊ |
69 | ␉␉while (denominator)␊ |
70 | ␉␉{␊ |
71 | ␉␉␉if (denominator <= numerator)␊ |
72 | ␉␉␉{␊ |
73 | ␉␉␉␉numerator -= denominator;␊ |
74 | ␉␉␉␉quotient += qbit;␊ |
75 | ␉␉␉}␊ |
76 | ␉␉␉denominator >>= 1;␊ |
77 | ␉␉␉qbit >>= 1;␊ |
78 | ␉␉}␊ |
79 | ␉␉␊ |
80 | ␉␉return quotient;␊ |
81 | ␉}␊ |
82 | ␉else {␊ |
83 | ␉␉stop("Divide by 0");␊ |
84 | ␉␉return 0;␊ |
85 | ␉}␊ |
86 | ␉␊ |
87 | }␊ |
88 | |