Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/Chazi/i386/modules/Memory/Memory.c

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

Archive Download this file

Revision: 817