/* * CPU detetion based on DMI decode rev 1.2 * * (C) 2003 Nicolas Planel * * Licensed under the GNU Public license. If you want to use it in with * another license just ask. */ #include #include #include #include #include #include typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; #define DEFAULT_MEM_DEV "/dev/mem" void *mem_chunk(u32 base, u32 len, const char *devmem) { void *p; int fd; off_t mmoffset; void *mmp; if ((fd = open(devmem, O_RDONLY)) < 0) return NULL; if ((p = malloc(len)) == NULL) return NULL; mmoffset = base % getpagesize(); mmp = mmap(0, mmoffset + len, PROT_READ, MAP_SHARED, fd, base - mmoffset); if (mmp == MAP_FAILED) { free(p); return NULL; } memcpy(p, (u8 *)mmp + mmoffset, len); munmap(mmp, mmoffset + len); close(fd); return p; } struct dmi_header { u8 type; u8 length; u16 handle; }; typedef int (*dmi_decode)(u8 * data); static int decode_handle(u32 base, int len, int num, dmi_decode decode) { u8 *buf; u8 *data; int i = 0; int ret = 0; if ((buf = mem_chunk(base, len, DEFAULT_MEM_DEV)) == NULL) return 0; data = buf; while(ilength; while(next-buf+1type == 4) && /*"Central Processor"*/(data[5] == 3)) { if(/*Processor Manufacturer*/data[7] != 0 && /*Populated*/(data[0x18] & (1 << 6)) && !/*Disabled {User:2h, BIOS:3}*/(data[0x18] & (1 << 1))) return 1; } return 0; } int intelDetectSMP(void) { return dmi_detect(processor) > 1; }