diff options
author | Nicolas Planel <nplanel@mandriva.com> | 2004-08-17 07:19:06 +0000 |
---|---|---|
committer | Nicolas Planel <nplanel@mandriva.com> | 2004-08-17 07:19:06 +0000 |
commit | 62e4100e3f24b84b904f3fa77510fd9baa728ee7 (patch) | |
tree | 34c6ec503c5f11782a252b70cdff3449c1539ab4 /perl-install/c | |
parent | 06bdc2d81905773e9afb9ae0a58bc4e796f4ff89 (diff) | |
download | drakx-62e4100e3f24b84b904f3fa77510fd9baa728ee7.tar drakx-62e4100e3f24b84b904f3fa77510fd9baa728ee7.tar.gz drakx-62e4100e3f24b84b904f3fa77510fd9baa728ee7.tar.bz2 drakx-62e4100e3f24b84b904f3fa77510fd9baa728ee7.tar.xz drakx-62e4100e3f24b84b904f3fa77510fd9baa728ee7.zip |
rework smp-dmi, add dmi memory detection suppport
Diffstat (limited to 'perl-install/c')
-rw-r--r-- | perl-install/c/smp-dmi.c | 148 | ||||
-rw-r--r-- | perl-install/c/stuff.xs.pl | 112 |
2 files changed, 115 insertions, 145 deletions
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(i<num) + while(i<num && data+sizeof(struct dmi_header)<=buf+len) { - u32 u; - u32 u2; - dm=(struct dmi_header *)data; - - if((dm->type == 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<len && (next[0]!=0 || next[1]!=0)) + next++; + next+=2; + if(next-buf<=len) + ret += decode(data); + else { + ret = 0; /* TRUNCATED */ + break; + } + data=next; i++; } free(buf); - return processor; + return ret; } -int intelDetectSMP(void) { +static int dmi_detect(dmi_decode decode) { unsigned char buf[20]; - int fd=open("/dev/mem", O_RDONLY); - long fp=0xE0000L; - int processor=0; - if(fd==-1) - { + int fd = open("/dev/mem", O_RDONLY); + long fp = 0xE0000L; + int ret = 0; + + if (fd == -1) { perror("/dev/mem"); exit(1); } - if(lseek(fd,fp,0)==-1) - { + if (lseek(fd, fp, 0) == -1) { perror("seek"); exit(1); } - - fp -= 16; - - while( fp < 0xFFFFF) + while (fp < 0xFFFFF) { - fp+=16; - if(read(fd, buf, 16)!=16) + if (read(fd, buf, 16) != 16) perror("read"); - if(memcmp(buf, "_DMI_", 5)==0) - { - u16 num=buf[13]<<8|buf[12]; - u16 len=buf[7]<<8|buf[6]; - u32 base=buf[11]<<24|buf[10]<<16|buf[9]<<8|buf[8]; + if (memcmp(buf, "_DMI_", 5) == 0) { + u16 num = buf[13]<<8|buf[12]; + u16 len = buf[7]<<8|buf[6]; + u32 base = buf[11]<<24|buf[10]<<16|buf[9]<<8|buf[8]; - processor=dmi_table(fd, base,len, num); + ret = decode_handle(fd, base, len, num, decode); break; } + fp += 16; } close(fd); - return (processor > 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); } diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl index 68a339243..dc2ceafb7 100644 --- a/perl-install/c/stuff.xs.pl +++ b/perl-install/c/stuff.xs.pl @@ -23,8 +23,6 @@ print ' #include <sys/stat.h> #include <sys/utsname.h> #include <sys/mount.h> -#undef __USE_MISC -#include <linux/wireless.h> #include <linux/keyboard.h> #include <linux/kd.h> #include <linux/hdreg.h> @@ -33,7 +31,6 @@ print ' #include <linux/cdrom.h> #include <linux/loop.h> #include <linux/blkpg.h> -#include <linux/iso_fs.h> #include <net/if.h> #include <net/route.h> #include <netinet/in.h> @@ -52,7 +49,6 @@ typedef __uint8_t u8; #include <ext2fs/ext2fs.h> // for UPS on USB: -# define HID_MAX_USAGES 1024 #include <linux/hiddev.h> #include <libldetect.h> @@ -73,11 +69,11 @@ char *promRootName(); '; -$Config{archname} =~ /i.86/ and print ' +$ENV{C_DRAKX} && $Config{archname} =~ /i.86/ and print ' char *pcmcia_probe(void); '; -print ' +$ENV{C_RPM} and print ' #undef Fflush #undef Mkdir #undef Stat @@ -95,7 +91,7 @@ void rpmError_callback(void) { '; -print ' +$ENV{C_DRAKX} and print ' void log_message(const char * s, ...) { va_list args; @@ -148,17 +144,11 @@ SV * iconv_(char* s, char* from_charset, char* to_charset) { return newSVpv(retval, 0); } -int length_of_space_padded(char *str, int len) { - while (len >= 0 && str[len-1] == \' \') - --len; - return len; -} - MODULE = c::stuff PACKAGE = c::stuff '; -$Config{archname} =~ /i.86/ and print ' +$ENV{C_DRAKX} && $Config{archname} =~ /i.86/ and print ' char * pcmcia_probe() '; @@ -229,23 +219,6 @@ is_ext3(device_name) OUTPUT: RETVAL -char * -get_ext2_label(device_name) - char * device_name - CODE: - { - ext2_filsys fs; - int retval = ext2fs_open (device_name, 0, 0, 0, unix_io_manager, &fs); - if (retval) { - RETVAL = 0; - } else { - RETVAL = fs->super->s_volume_name; - ext2fs_close(fs); - } - } - OUTPUT: - RETVAL - void setlocale() CODE: @@ -366,6 +339,9 @@ usleep(microseconds) int detectSMP() +int +dmiDetectMemory() + void pci_probe() PPCODE: @@ -425,68 +401,13 @@ hasNetDevice(device) int s = socket(AF_INET, SOCK_DGRAM, 0); if (s == -1) { RETVAL = 0; return; } - strncpy(req.ifr_name, device, IFNAMSIZ); + strcpy(req.ifr_name, device); RETVAL = ioctl(s, SIOCGIFFLAGS, &req) == 0; close(s); OUTPUT: RETVAL - -int -isNetDeviceWirelessAware(device) - char * device - CODE: - struct iwreq ifr; - - int s = socket(AF_INET, SOCK_DGRAM, 0); - - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, device, IFNAMSIZ); - RETVAL = ioctl(s, SIOCGIWNAME, &ifr) != -1; - close(s); - OUTPUT: - RETVAL - - -void -get_netdevices() - PPCODE: - struct ifconf ifc; - struct ifreq *ifr; - int i; - int numreqs = 10; - - int s = socket(AF_INET, SOCK_DGRAM, 0); - - ifc.ifc_buf = NULL; - for (;;) { - ifc.ifc_len = sizeof(struct ifreq) * numreqs; - ifc.ifc_buf = realloc(ifc.ifc_buf, ifc.ifc_len); - - if (ioctl(s, SIOCGIFCONF, &ifc) < 0) { - perror("SIOCGIFCONF"); - return; - } - if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) { - /* assume it overflowed and try again */ - numreqs += 10; - continue; - } - break; - } - if (ifc.ifc_len) { - ifr = ifc.ifc_req; - EXTEND(sp, ifc.ifc_len); - for (i=0; i < ifc.ifc_len; i+= sizeof(struct ifreq)) { - PUSHs(sv_2mortal(newSVpv(ifr->ifr_name, 0))); - ifr++; - } - } - - close(s); - - char* getNetDriver(char* device) ALIAS: @@ -497,7 +418,7 @@ getNetDriver(char* device) int s = socket(AF_INET, SOCK_DGRAM, 0); memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, device, IFNAMSIZ); + strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)-1); drvinfo.cmd = ETHTOOL_GDRVINFO; ifr.ifr_data = (caddr_t) &drvinfo; @@ -705,22 +626,9 @@ standard_charset() OUTPUT: RETVAL -void -get_iso_volume_ids(int fd) - INIT: - struct iso_primary_descriptor voldesc; - PPCODE: - lseek(fd, 16 * ISOFS_BLOCK_SIZE, SEEK_SET); - if (read(fd, &voldesc, sizeof(struct iso_primary_descriptor)) == sizeof(struct iso_primary_descriptor)) { - if (voldesc.type[0] == ISO_VD_PRIMARY && !strncmp(voldesc.id, ISO_STANDARD_ID, sizeof(voldesc.id))) { - XPUSHs(sv_2mortal(newSVpv(voldesc.volume_id, length_of_space_padded(voldesc.volume_id, sizeof(voldesc.volume_id))))); - XPUSHs(sv_2mortal(newSVpv(voldesc.application_id, length_of_space_padded(voldesc.application_id, sizeof(voldesc.application_id))))); - } - } - '; -print ' +$ENV{C_RPM} and print ' const char * rpmErrorString() |