1 | /*␊ |
2 | * Copyright 2010 AsereBLN. All rights reserved. <aserebln@googlemail.com>␊ |
3 | *␊ |
4 | * mem.c - obtain system memory information␊ |
5 | */␊ |
6 | ␊ |
7 | #include "libsaio.h"␊ |
8 | #include "pci.h"␊ |
9 | #include "platform.h"␊ |
10 | #include "cpu.h"␊ |
11 | #include "mem.h"␊ |
12 | #include "smbios_patcher.h"␊ |
13 | ␊ |
14 | #ifndef DEBUG_MEM␊ |
15 | #define DEBUG_MEM 0␊ |
16 | #endif␊ |
17 | ␊ |
18 | #if DEBUG_MEM␊ |
19 | #define DBG(x...)␉␉printf(x)␊ |
20 | #else␊ |
21 | #define DBG(x...)␊ |
22 | #endif␊ |
23 | ␊ |
24 | #define DC(c) (c >= 0x20 && c < 0x7f ? (char) c : '.')␊ |
25 | #define STEP 16␊ |
26 | ␊ |
27 | void dumpPhysAddr(const char * title, void * a, int len)␊ |
28 | {␊ |
29 | int i,j;␊ |
30 | u_int8_t* ad = (u_int8_t*) a;␊ |
31 | char buffer[80];␊ |
32 | char str[16];␊ |
33 | ␊ |
34 | if(ad==NULL) return;␊ |
35 | ␊ |
36 | printf("%s addr=0x%08x len=%04d\n",title ? title : "Dump of ", a, len);␊ |
37 | i = (len/STEP)*STEP;␊ |
38 | for (j=0; j < i; j+=STEP)␊ |
39 | {␊ |
40 | printf("%02x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",␊ |
41 | j, ␊ |
42 | ad[j], ad[j+1], ad[j+2], ad[j+3] , ad[j+4], ad[j+5], ad[j+6], ad[j+7],␊ |
43 | ad[j+8], ad[j+9], ad[j+10], ad[j+11] , ad[j+12], ad[j+13], ad[j+14], ad[j+15],␊ |
44 | DC(ad[j]), DC(ad[j+1]), DC(ad[j+2]), DC(ad[j+3]) , DC(ad[j+4]), DC(ad[j+5]), DC(ad[j+6]), DC(ad[j+7]),␊ |
45 | DC(ad[j+8]), DC(ad[j+9]), DC(ad[j+10]), DC(ad[j+11]) , DC(ad[j+12]), DC(ad[j+13]), DC(ad[j+14]), DC(ad[j+15])␊ |
46 | ); ␊ |
47 | }␊ |
48 | ␊ |
49 | if (len%STEP==0) return;␊ |
50 | sprintf(buffer,"%02x:", i);␊ |
51 | for (j=0; j < STEP; j++) {␊ |
52 | if (j<(len%STEP))␊ |
53 | sprintf(str, " %02x", ad[i+j]);␊ |
54 | else␊ |
55 | strcpy(str, " " ); ␊ |
56 | strncat(buffer, str, sizeof(buffer));␊ |
57 | }␊ |
58 | strncat(buffer," ", sizeof(buffer));␊ |
59 | for (j=0; j < (len%STEP); j++) {␊ |
60 | sprintf(str, "%c", DC(ad[i+j])); ␊ |
61 | strncat(buffer, str, sizeof(buffer));␊ |
62 | }␊ |
63 | printf("%s\n",buffer);␊ |
64 | }␊ |
65 | ␊ |
66 | void scan_memory(PlatformInfo_t *p)␊ |
67 | {␊ |
68 | #if 0␊ |
69 | ␉struct SMBEntryPoint␉*smbios;␊ |
70 | //struct DMIHeader * dmihdr;␊ |
71 | ␊ |
72 | struct DMIMemoryControllerInfo* ctrlInfo;␊ |
73 | struct DMIMemoryModuleInfo* memInfo;␊ |
74 | struct DMIPhysicalMemoryArray* physMemArray;␊ |
75 | struct DMIMemoryDevice* memDev;␊ |
76 | ␊ |
77 | ␉smbios = getSmbios(SMBIOS_ORIGINAL);␉/* checks for _SM_ anchor and table header checksum */␊ |
78 | ␉if (smbios==NULL) return ; // getSmbios() return a non null value if smbios is found␊ |
79 | ␊ |
80 | ctrlInfo = (struct DMIMemoryControllerInfo*) getSmbiosTableStructure(smbios, 5, 0x1);␊ |
81 | memInfo = (struct DMIMemoryModuleInfo*) getSmbiosTableStructure(smbios, 6, 0x1);␊ |
82 | physMemArray = (struct DMIPhysicalMemoryArray*) getSmbiosTableStructure(smbios, 16, 0x1);␊ |
83 | memDev = (struct DMIMemoryDevice*) getSmbiosTableStructure(smbios, 17, 0x1);␊ |
84 | ␊ |
85 | dumpPhysAddr("Memory Controller Info (05):", ctrlInfo, ctrlInfo->dmiHeader.length);␊ |
86 | dumpPhysAddr("Memory Module Info (06):",memInfo, memInfo->dmiHeader.length);␊ |
87 | dumpPhysAddr("Physical Memory Array (16):",physMemArray, physMemArray->dmiHeader.length);␊ |
88 | dumpPhysAddr("Memory Device (17):",memDev, memDev->dmiHeader.length);␊ |
89 | getc();␊ |
90 | #endif␊ |
91 | }␊ |
92 | |