From e1971e4774a6ebb5ed33a09bdd60afa2c0534b6f Mon Sep 17 00:00:00 2001 From: Bob Gilligan Date: Fri, 5 Feb 2010 09:54:11 -0800 Subject: Initial commit. --- src/dmidecode/config.h | 29 ++++ src/dmidecode/dmidecode.c | 382 ++++++++++++++++++++++++++++++++++++++++++++++ src/dmidecode/dmidecode.h | 55 +++++++ src/dmidecode/dmioem.c | 120 +++++++++++++++ src/dmidecode/dmioem.h | 26 ++++ src/dmidecode/types.h | 27 ++++ src/dmidecode/util.c | 165 ++++++++++++++++++++ src/dmidecode/util.h | 8 + 8 files changed, 812 insertions(+) create mode 100644 src/dmidecode/config.h create mode 100644 src/dmidecode/dmidecode.c create mode 100644 src/dmidecode/dmidecode.h create mode 100644 src/dmidecode/dmioem.c create mode 100644 src/dmidecode/dmioem.h create mode 100644 src/dmidecode/types.h create mode 100644 src/dmidecode/util.c create mode 100644 src/dmidecode/util.h (limited to 'src/dmidecode') diff --git a/src/dmidecode/config.h b/src/dmidecode/config.h new file mode 100644 index 0000000..52fd3c3 --- /dev/null +++ b/src/dmidecode/config.h @@ -0,0 +1,29 @@ +/* + * Configuration + */ + +#ifndef CONFIG_H +#define CONFIG_H + +/* Default memory device file */ +#ifdef __BEOS__ +#define DEFAULT_MEM_DEV "/dev/misc/mem" +#else +#ifdef __sun +#define DEFAULT_MEM_DEV "/dev/xsvc" +#else +#define DEFAULT_MEM_DEV "/dev/mem" +#endif +#endif + +/* Use mmap or not */ +#ifndef __BEOS__ +#define USE_MMAP +#endif + +/* Use memory alignment workaround or not */ +#ifdef __ia64__ +#define ALIGNMENT_WORKAROUND +#endif + +#endif diff --git a/src/dmidecode/dmidecode.c b/src/dmidecode/dmidecode.c new file mode 100644 index 0000000..5c542a6 --- /dev/null +++ b/src/dmidecode/dmidecode.c @@ -0,0 +1,382 @@ +/* + * Trimmed from DMI Decode http://savannah.nongnu.org/projects/dmidecode + * + * (C) 2000-2002 Alan Cox + * (C) 2002-2007 Jean Delvare + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. + */ + +#include +#include +#include +#include + +#include "config.h" +#include "types.h" +#include "util.h" +#include "dmidecode.h" +#include "dmioem.h" +#include "../state.h" +#include "../pci.h" + +static const char *out_of_spec = ""; +static const char *bad_index = ""; + +/* + * Type-independant Stuff + */ + +const char *dmi_string(struct dmi_header *dm, u8 s) +{ + char *bp=(char *)dm->data; + size_t i, len; + + if(s==0) + return "Not Specified"; + + bp+=dm->length; + while(s>1 && *bp) + { + bp+=strlen(bp); + bp++; + s--; + } + + if(!*bp) + return bad_index; + + /* ASCII filtering */ + len=strlen(bp); + for(i=0; i=0x01 && code<=0x04) + return usage[code-0x01]; + return out_of_spec; +} + +static void dmi_slot_segment_bus_func(u16 code1, u8 code2, u8 code3, u8 type, const char *prefix) +{ + /* 3.3.10.8 */ + if (!(code1==0xFFFF && code2==0xFF && code3==0xFF)) + printf("%sSegment Group %u, Bus %u, Device %u, Function %u ", + prefix, code1, code2, (code3>>3)&0x1F, (code3&0x7)); + switch(type) + { + case 0x06: /* PCI */ + case 0x0E: /* PCI */ + case 0x0F: /* AGP */ + case 0x10: /* AGP */ + case 0x11: /* AGP */ + case 0x12: /* PCI-X */ + case 0x13: /* AGP */ + case 0xA5: /* PCI Express */ + printf("\n"); + break; + default: + if (code1 != 0xFF || code2 != 0xFF || code3 != 0xFF) + printf("%s\n", out_of_spec); + break; + } +} + +static u8 onboard_device_type(u8 code, const char *prefix) +{ + /* 3.3.x.2 */ + u8 e = (code & 0x80)>>7; + static const char *type[]={ + "Other", /* 1 */ + "Unknown", + "Video", + "SCSI Controller", + "Ethernet", + "Token Ring", + "Sound", + "PATA Controller", + "SATA Controller", + "SAS Controller" /* 0x0A */ + }; + code = code & 0x7F; + if(code>=0x01 && code<=0x0A) { + printf("%sStatus: %s\n", prefix, e?"Enabled":"Disabled"); + printf("%sDevice Type: %s\n", prefix, type[code-0x01]); + } + else + printf("%sDevice Type: %s\n", prefix, out_of_spec); +} + +/* + * Main + */ + +#define MIN(a,b) (((a)<(b))?(a):(b)) + +static void dmi_decode(struct dmi_header *h, u16 ver, const struct libbiosdevname_state *state) +{ + u8 *data=h->data; + int domain, bus, device, function; + struct pci_device *pdev; + switch(h->type) + { + case 9: /* 3.3.10 System Slots */ + if (h->length >= 0x0E && h->length >=0x11) { + domain = WORD(data+0x0D); + bus = data[0x0F]; + device = (data[0x10]>>3)&0x1F; + function = data[0x10] & 7; + if (! (domain == 0xFFFF && bus == 0xFF && data[0x10] == 0xFF)) { + device = (data[0x10]>>3)&0x1F; + function = data[0x10] & 7; + pdev = find_pci_dev_by_pci_addr(state, domain, bus, device, function); + if (pdev) { + pdev->physical_slot = WORD(data+0x09); + pdev->smbios_type = 0; + pdev->smbios_instance = 0; + } + } + } + break; + case 41: /* 3.3.xx Onboard Device Information */ + domain = WORD(data+0x07); + bus = data[0x09]; + device = (data[0xa]>>3) & 0x1F; + function = data[0xa] & 0x7; + pdev = find_pci_dev_by_pci_addr(state, domain, bus, device, function); + if (pdev) { + pdev->physical_slot = 0; + pdev->smbios_enabled = !!(data[0x05] & 0x80); + pdev->smbios_type = data[0x05] & 0x7F; + pdev->smbios_instance = data[0x06]; + } + break; + + default: + if(dmi_decode_oem(h, state)) + break; + } +} + +static void to_dmi_header(struct dmi_header *h, u8 *data) +{ + h->type=data[0]; + h->length=data[1]; + h->handle=WORD(data+2); + h->data=data; +} + +static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, const struct libbiosdevname_state *state) +{ + u8 *buf; + u8 *data; + int i=0; + + if((buf=mem_chunk(base, len, devmem))==NULL) + { +#ifndef USE_MMAP + printf("Table is unreachable, sorry. Try compiling dmidecode with -DUSE_MMAP.\n"); +#endif + return; + } + + data=buf; + while(i=5) + dmi_set_vendor(dmi_string(&h, data[0x04])); + + /* look for the next handle */ + next=data+h.length; + while(next-buf+1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +struct dmi_header +{ + u8 type; + u8 length; + u16 handle; + u8 *data; +}; + +const char *dmi_string(struct dmi_header *dm, u8 s); + +struct dmi_embedded_device +{ + u8 type; + u8 instance; + u16 domain; + u8 bus; + u8 device; + u8 function; + const char *reference_designation; +}; + +struct dmi_addon_device +{ + u8 type; + u8 instance; + u16 domain; + u8 bus; + u8 device; + u8 function; + const char *reference_designation; +}; + +struct libbiosdevname_state; +int dmidecode_main(const struct libbiosdevname_state *state); + diff --git a/src/dmidecode/dmioem.c b/src/dmidecode/dmioem.c new file mode 100644 index 0000000..217c13a --- /dev/null +++ b/src/dmidecode/dmioem.c @@ -0,0 +1,120 @@ +/* + * Decoding of OEM-specific entries + * This file is part of the dmidecode project. + * + * (C) 2007 Jean Delvare + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +#include "types.h" +#include "dmidecode.h" +#include "dmioem.h" +#include "../pci.h" + +/* + * Globals for vendor-specific decodes + */ + +enum DMI_VENDORS { VENDOR_UNKNOWN, VENDOR_HP }; + +static enum DMI_VENDORS dmi_vendor=VENDOR_UNKNOWN; + +/* + * Remember the system vendor for later use. We only actually store the + * value if we know how to decode at least one specific entry type for + * that vendor. + */ +void dmi_set_vendor(const char *s) +{ + if(strcmp(s, "HP")==0) + dmi_vendor=VENDOR_HP; +} + +/* + * HP-specific data structures are decoded here. + * + * Code contributed by John Cagle. + */ + +static int dmi_decode_hp(struct dmi_header *h, const struct libbiosdevname_state *state) +{ + u8 *data=h->data; + int nic, ptr; + u8 smbios_type = 0; + u8 bus, device, func; + struct pci_device *pdev; + + switch(h->type) + { + case 209: + case 221: + /* + * Vendor Specific: HP ProLiant NIC MAC Information + * + * This prints the BIOS NIC number, + * PCI bus/device/function, and MAC address + */ + if (h->type == 221) + smbios_type=0; + else + smbios_type=0x05; + + nic=1; + ptr=4; + while(h->length>=ptr+8) + { + bus = data[ptr+1]; + device = data[ptr]>>3; + func = data[ptr]&7; + pdev = find_pci_dev_by_pci_addr(state, 0, bus, device, func); + if (pdev) { + if((data[ptr]==0x00 && data[ptr+1]==0x00) || + (data[ptr]==0xFF && data[ptr+1]==0xFF)) + pdev->smbios_enabled = 0; + else { + pdev->smbios_enabled = 1; + pdev->smbios_type = smbios_type; + pdev->smbios_instance = nic; + } + } + nic++; + ptr+=8; + } + break; + + default: + return 0; + } + return 1; +} + +/* + * Dispatch vendor-specific entries decoding + * Return 1 if decoding was successful, 0 otherwise + */ +int dmi_decode_oem(struct dmi_header *h, const struct libbiosdevname_state *state) +{ + switch(dmi_vendor) + { + case VENDOR_HP: + return dmi_decode_hp(h, state); + default: + return 0; + } +} diff --git a/src/dmidecode/dmioem.h b/src/dmidecode/dmioem.h new file mode 100644 index 0000000..bacdab7 --- /dev/null +++ b/src/dmidecode/dmioem.h @@ -0,0 +1,26 @@ +/* + * Decoding of OEM-specific entries + * This file is part of the dmidecode project. + * + * (C) 2007 Jean Delvare + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "../state.h" +struct dmi_header; + +void dmi_set_vendor(const char *s); +int dmi_decode_oem(struct dmi_header *h, const struct libbiosdevname_state *state); diff --git a/src/dmidecode/types.h b/src/dmidecode/types.h new file mode 100644 index 0000000..12f3c65 --- /dev/null +++ b/src/dmidecode/types.h @@ -0,0 +1,27 @@ +#ifndef TYPES_H +#define TYPES_H + +#include "config.h" + +typedef unsigned char u8; +typedef unsigned short u16; +typedef signed short i16; +typedef unsigned int u32; + +#ifdef ALIGNMENT_WORKAROUND +# ifdef BIGENDIAN +# define WORD(x) (u16)((x)[1]+((x)[0]<<8)) +# define DWORD(x) (u32)((x)[3]+((x)[2]<<8)+((x)[1]<<16)+((x)[0]<<24)) +# define QWORD(x) (U64(DWORD(x+4), DWORD(x))) +# else /* BIGENDIAN */ +# define WORD(x) (u16)((x)[0]+((x)[1]<<8)) +# define DWORD(x) (u32)((x)[0]+((x)[1]<<8)+((x)[2]<<16)+((x)[3]<<24)) +# define QWORD(x) (U64(DWORD(x), DWORD(x+4))) +# endif /* BIGENDIAN */ +#else /* ALIGNMENT_WORKAROUND */ +#define WORD(x) (u16)(*(const u16 *)(x)) +#define DWORD(x) (u32)(*(const u32 *)(x)) +#define QWORD(x) (*(const u64 *)(x)) +#endif /* ALIGNMENT_WORKAROUND */ + +#endif diff --git a/src/dmidecode/util.c b/src/dmidecode/util.c new file mode 100644 index 0000000..9eda714 --- /dev/null +++ b/src/dmidecode/util.c @@ -0,0 +1,165 @@ +/* + * Common "util" functions + * This file is part of the dmidecode project. + * + * (C) 2002-2005 Jean Delvare + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. + */ + +#include +#include + +#include "config.h" + +#ifdef USE_MMAP +#include +#ifndef MAP_FAILED +#define MAP_FAILED ((void *) -1) +#endif /* !MAP_FAILED */ +#endif /* USE MMAP */ + +#include +#include +#include +#include +#include +#include + +#include "types.h" +#include "util.h" + +#ifndef USE_MMAP +static int myread(int fd, u8 *buf, size_t count, const char *prefix) +{ + ssize_t r=1; + size_t r2=0; + + while(r2!=count && r!=0) + { + r=read(fd, buf+r2, count-r2); + if(r==-1) + { + if(errno!=EINTR) + { + close(fd); + perror(prefix); + return -1; + } + } + else + r2+=r; + } + + if(r2!=count) + { + close(fd); + fprintf(stderr, "%s: Unexpected end of file\n", prefix); + return -1; + } + + return 0; +} +#endif + +int checksum(const u8 *buf, size_t len) +{ + u8 sum=0; + size_t a; + + for(a=0; a + +#include "types.h" + +#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) + +int checksum(const u8 *buf, size_t len); +void *mem_chunk(size_t base, size_t len, const char *devmem); -- cgit v1.2.3