From 62e4100e3f24b84b904f3fa77510fd9baa728ee7 Mon Sep 17 00:00:00 2001 From: Nicolas Planel Date: Tue, 17 Aug 2004 07:19:06 +0000 Subject: rework smp-dmi, add dmi memory detection suppport --- perl-install/c/smp-dmi.c | 148 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 105 insertions(+), 43 deletions(-) (limited to 'perl-install/c/smp-dmi.c') diff --git a/perl-install/c/smp-dmi.c b/perl-install/c/smp-dmi.c index 672bc2c35..53cf734cd 100644 --- a/perl-install/c/smp-dmi.c +++ b/perl-install/c/smp-dmi.c @@ -133,81 +133,143 @@ static char *dmi_processor_family(u8 code) return processor_family[code]; } -static int dmi_table(int fd, u32 base, int len, int num) +typedef int (*dmi_decode)(u8 * data); + +static int decode_handle(int fd, u32 base, int len, int num, dmi_decode decode) { - char *buf=malloc(len); + u8 *buf = malloc(len); struct dmi_header *dm; u8 *data; - int i=0; - int processor=0; + int i = 0; + int ret = 0; - if(lseek(fd, (long)base, 0)==-1) - { + if (lseek(fd, (long)base, 0) == -1) { perror("dmi: lseek"); return; } - if(read(fd, buf, len)!=len) - { + if (read(fd, buf, len)!=len) { perror("dmi: read"); return; } data = buf; - while(itype == 4) && /*"Central Processor"*/(data[5] == 3)) { - if(/*Processor Manufacturer*/data[7] != 0) - processor++; - } + u8 *next; + struct dmi_header *dm = (struct dmi_header *)data; - data+=dm->length; - while(*data || data[1]) - data++; - data+=2; + /* look for the next handle */ + next=data+dm->length; + while(next-buf+1 1); + return ret; +} + +static int processor(u8 *data) { + struct dmi_header *dm = (struct dmi_header *)data; + + if((dm->type == 4) && /*"Central Processor"*/(data[5] == 3)) { + if(/*Processor Manufacturer*/data[7] != 0) + return 1; + } + return 0; +} + +static int memory_in_MB(u8 *data) +{ + struct dmi_header *dm; + + int form_factor_check(u8 code) { + /* 3.3.18.1 */ + static const char form_factor[]={ + 0, /* "Other", */ /* 0x01 */ + 0, /* "Unknown", */ + 1, /* "SIMM", */ + 1, /* "SIP", */ + 0, /* "Chip", */ + 1, /* "DIP", */ + 0, /* "ZIP", */ + 0, /* "Proprietary Card", */ + 1, /* "DIMM", */ + 0, /* "TSOP", */ + 0, /* "Row Of Chips", */ + 1, /* "RIMM", */ + 1, /* "SODIMM", */ + 1, /* "SRIMM" *//* 0x0E */ + }; + + if(code>=0x01 && code<=0x0E) + return form_factor[code-0x01]; + return 0; /* out of spec */ + } + int dmi_memory_device_size(u16 code) { + int mult = 1; + + if (code == 0 || code == 0xFFFF) + return 0; + if (code & 0x8000) /* code is in KB */ + mult = 1024; + return (code & 0x7FFF) * mult; + } + + dm = (struct dmi_header *)data; + + if ((dm->type == 17) && (dm->length >= 0x15)) { + if (form_factor_check(data[0x0E])) + return dmi_memory_device_size((data[0x0D] << 8) + data[0x0C]); + } + + return 0; +} + +int intelDetectSMP(void) { + return dmi_detect(processor) > 1; +} + +int dmiDetectMemory(void) { + return dmi_detect(memory_in_MB); } -- cgit v1.2.1