SMBIOS介绍(3):实现

 Linux中实现了SMBIO内核模块,它是通过/proc文件系统,以一种用户可理解的格式或纯粹的二进制格式来访问SMBIOS结构的信息。sourceforge上有这个内核模块的源代码,地址为http://sourceforge.net/projects/smbios/,是在Linux 2.4内核中的实现,它同时也实现了DMI。注意Linux 2.6中的内核驱动程序模块结构与2.4中的基本相同,只是有一些少许的变化,这里就不展开了。
  1、bios.h文件: 
  (1)头文件中定义搜索起始地址0xF0000,固定字符串"_SM_"和"_DMI_"。
  (2)定义SMBIOS EPS表smbios_entry_point_struct,SMBIOS结构头部smbios_struct、DMI的EPS表及结构头部。
  (3)定义了模块在proc文件系统中的位置。有两种访问模式,即原始二进制格式(raw),用户可理解格式(cooked),因些访问位置有目录/proc/smbios,/proc/smbios/raw,/proc/smbios/cooked。
  (4)定义搜索EPS表的函数smbios_find_entry_point(void*),以及获取结构长度、在proc中创建或删除节点、从proc文件系统中读取原始的或可理解格式的SMBIOS数据,等等。
  这里的设计体现了初步的数据封装思想,即把数据结构和操作这些数据结构的函数封装在一个文件中。


[cpp]  view plain copy

  1. /** /文件 bios.h 
  2.  *  DMI-BIOS和SM-BIOS的原型及声明 
  3.  */  
  4.        
  5. #ifndef __BIOS_H__  
  6. #define __BIOS_H__  
  7. /* 
  8.  *   用来帮助调试的宏 
  9.  */  
  10. #undef PDEBUG /* 取消先前的定义(如果有的话),以防万一 */  
  11. #ifdef _DEBUG_   /* 定义调试宏 */  
  12. #  define PDEBUG(fmt, args...) printk( KERN_DEBUG "smbios: " fmt, ## args)  
  13. #else  
  14. #  define PDEBUG(fmt, args...) /* 不调试:不做任何事 */  
  15. #endif  
  16. #define BIOS_START_ADDRESS      0xF0000           /* 搜索SM-BIOS和DMI-BIOS的BISO段起始地址 */  
  17. #define BIOS_MAP_LENGTH         0x10000           /* 搜索的BIOS区域长度 */  
  18. #define SMBIOS_MAGIC_DWORD      0x5F4D535F        /* 固定字符串 "_SM_" */  
  19. #define DMIBIOS_MAGIC_DWORD     0x494d445f        /* 固定字符串 "_DMI" */  
  20. #define DMI_STRING              "_DMI_"  
  21. /** 有子类型的SMBIOS结构类型,可扩充! */  
  22. #define TYPES_WITH_SUBTYPES     185, 187, 208, 209, 210, 211, 212, 254  
  23. #define PROC_BLOCK_SIZE         (3*1024)          /* proc read函数最大的块大小 */  
  24. /** 模式 原始二进制模式/烹调好的(即用户可理解模式) */  
  25. #define FILE_MODE_RAW       0  
  26. #define FILE_MODE_COOKED    1  
  27.  /* SMBIOS EPS表 */  
  28. typedef struct smbios_entry_point_struct  
  29. {  
  30.   __u32 anchor_string                  __attribute__ ((packed));  
  31.   __u8  entry_point_checksum           __attribute__ ((packed));  
  32.   __u8  entry_point_length             __attribute__ ((packed));  
  33.   __u8  major_version                  __attribute__ ((packed));  
  34.   __u8  minor_version                  __attribute__ ((packed));  
  35.     __u16 max_struct_size                __attribute__ ((packed));  
  36.   __u8  revision                       __attribute__ ((packed));  
  37.   __u8  formated_area[5]               __attribute__ ((packed));  
  38.   __u8  intermediate_string[5]         __attribute__ ((packed));  
  39.   __u8  intermediate_checksum          __attribute__ ((packed));  
  40.   __u16 struct_table_length            __attribute__ ((packed));  
  41.   __u32 struct_table_address           __attribute__ ((packed));  
  42.   __u16 no_of_structures               __attribute__ ((packed));  
  43.   __u8  bcd_revision                   __attribute__ ((packed));  
  44. } smbios_entry_point_struct;  
  45. /** SM-BIOS和DMI-BIOS结构的头部 */  
  46. typedef struct smbios_struct  
  47. {  
  48.   __u8  type                           __attribute__ ((packed));  
  49.   __u8  length                         __attribute__ ((packed));  
  50.   __u16 handle                         __attribute__ ((packed));  
  51.   __u8  subtype                        __attribute__ ((packed));  
  52. } smbios_struct;  
  53. /** DMI-BIOS结构的头部 */  
  54. typedef struct dmibios_table_entry_struct  
  55. {  
  56.   __u16 size                           __attribute__ ((packed));  
  57.   __u16 handle                         __attribute__ ((packed));  
  58.   __u32 procedure                      __attribute__ ((packed));  
  59. } dmibios_table_entry_struct;  
  60. /** DMI-BIOS的EPS表 */  
  61. typedef struct dmibios_entry_point_struct  
  62. {  
  63.   __u8  signature[10]                  __attribute__ ((packed));  
  64.   __u8  revision                       __attribute__ ((packed));  
  65.   dmibios_table_entry_struct entry[1]  __attribute__ ((packed));  
  66. } dmibios_entry_point_struct;  
  67. /* 
  68.  *   变量 
  69.  */  
  70. extern struct proc_dir_entry * smbios_proc_dir;             /* /proc/smbios */  
  71. extern struct proc_dir_entry * smbios_raw_proc_dir;         /* /proc/smbios/raw */  
  72. extern struct proc_dir_entry * smbios_cooked_proc_dir;      /* /proc/smbios/cooked */  
  73. extern void * smbios_base;                                  /* F-Segment */  
  74. extern smbios_entry_point_struct * smbios_entry_point;      /* SMBIOS在F-Segment中的起始地址 */  
  75. extern dmibios_entry_point_struct * dmibios_entry_point;    /* DMIBIOS在F-Segment中的起始地址 */  
  76. extern void * smbios_structures_base;                       /* SMBIOS结构信息的基地址 */  
  77. extern unsigned char smbios_types_with_subtypes[];  
  78. extern char smbios_version_string[32];                      /* 支持的SMBIOS版本,例如V2.31 */  
  79. /* 搜索函数 */  
  80. smbios_entry_point_struct * smbios_find_entry_point(void * base);  
  81. dmibios_entry_point_struct * dmibios_find_entry_point(void * base);  
  82. unsigned char smbios_check_entry_point(void * addr);  
  83. int smbios_type_has_subtype(unsigned char type);  
  84. int smbios_get_struct_length(smbios_struct * struct_ptr);  
  85. int dmibios_get_struct_length(smbios_struct * struct_ptr);  
  86. int smbios_version_proc (char *page, char **start, off_t off, int count, int *eof, void *data);  
  87. int bios_read_raw_proc(char * page, char ** start, off_t off, int count, int * eof, void * data);  
  88. int bios_read_cooked_proc(char *page, char **start, off_t off, int count, int *eof, void *data);  
  89. int dmibios_read_raw_proc(char * page, char ** start, off_t off, int count, int * eof, void * data);  
  90. int dmibios_read_cooked_proc(char *page, char **start, off_t off, int count, int *eof, void *data);  
  91. int smbios_make_dir_entries(struct proc_dir_entry *smbiosdir, struct proc_dir_entry *rawdir, struct proc_dir_entry *cookeddir);  
  92. int smbios_make_version_entry(struct proc_dir_entry *smbiosdir);  
  93. int dmibios_make_dir_entries(struct proc_dir_entry * smbiosdir, struct proc_dir_entry * rawdir, struct proc_dir_entry * cookeddir);  
  94. void smbios_destroy_dir_entries(struct proc_dir_entry * dir);  
  95. unsigned int smbios_get_readable_name_ext(char *readable_name, smbios_struct *struct_ptr);  
  96. unsigned int smbios_get_readable_name(char *readable_name, smbios_struct *struct_ptr);  
  97. int make_file_entries (char *filename, struct proc_dir_entry *dir, smbios_struct *struct_ptr, int mode);  
  98. #endif /* __BIOS_H__ */  


  这里__attribute__ ((packed))是GCC的扩展,其作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐。__attribute__关键字主要是用来在函数或数据声明中设置属性。给函数赋予属性的主要目的在于让编译器进行优化。例如函数声明中的__attribute__((noreturn)),就是告诉编译器这个函数不会返回给调用者,以便编译器在优化时去掉不必要的函数返回代码。__attribute__可以设置函数属性、变量属性和类型属性。书写时要放置在声明的尾部,在分号“;”之前。函数属性可以帮助开发者把一些特性添加到函数声明中,从而可以使编译器在错误检查方面的功能更强大。GCC需要使用–Wall编译器来击活该功能,这是控制警告信息的一个很好的方式。这里的packed属性可以使得变量或者结构体成员使用最小的对齐方式,即对变量是一字节对齐,对域(field)是位对齐。
  2、cooking.h和strgdef.h文件: 由于要以用户可理解的方式显示SMBIOS信息,这需要把原始的SMBIOS结构数据映射到一些可理解的字符串上,以显示给用户看。在cooking.h中定义了各个SMBIOS结构以及解析这些结构的函数。有Type 0-Type 13、Type 16、Type 17、Type 19、Type 20、Type 32、Type 127共20个SMBIOS结构数据。这些结构在SMBIOS规范中都有清晰的描述,定义它们是比较直接的。例如Type 0和Type 1的定义如下:


[cpp]  view plain copy

  1. /* 解析成可理解的格式 */  
  2. unsigned char * bios_cook_type_0 (smbios_struct * smbiostype, unsigned int *length);  
  3. unsigned char * bios_cook_type_1 (smbios_struct * smbiostype, unsigned int *length);  
  4. typedef struct smbios_type_0  
  5. {  
  6.     smbios_header   header;  
  7.     __u8    vendor                          __attribute__ ((packed));  
  8.     __u8    version                         __attribute__ ((packed));  
  9.     __u16   startaddr                       __attribute__ ((packed));  
  10.     __u8    reldate                         __attribute__ ((packed));  
  11.     __u8    romsize                         __attribute__ ((packed));  
  12.     __u64   characteristics                 __attribute__ ((packed));  
  13.     __u8    ext1                            __attribute__ ((packed));  
  14.     __u8    ext2                            __attribute__ ((packed));  
  15. } smbios_type_0;  
  16. typedef struct smbios_type_1  
  17. {  
  18.     smbios_header   header;  
  19.     __u8    manufacturer                    __attribute__ ((packed));  
  20.     __u8    productname                     __attribute__ ((packed));  
  21.     __u8    version                         __attribute__ ((packed));  
  22.     __u8    serialnumber                    __attribute__ ((packed));  
  23.     __u8    uuid[16]                        __attribute__ ((packed));  
  24.     __u8    wakeuptype                      __attribute__ ((packed));  
  25. } smbios_type_1;  


  bios_cook_type_0()等函数就是把解析后的SMBIOS数据写入到/proc文件中。其他的结构就不列举了,在cooking.h中都有。strgdef.h中定义了各结构数据要解析成的友好信息,如结构中各个域的名称、字符串区域中各个字符串的值等,这在SMBIOS规范中也都有清晰的描述,定义时比较直接。例如对Type 0结构的信息,如下:


[cpp]  view plain copy

  1. /* 
  2.  * Type 0 - Bios 
  3.  */  
  4. #define TYPE0_NAME                      "(BIOS Information)"  
  5. #define TYPE0_VENDOR                    "Vendor"  
  6. #define TYPE0_VERSION                   "Version"  
  7. #define TYPE0_ADR_SEG                   "Starting Adr Seg"  
  8. #define TYPE0_REL_DATE                  "Rel. Date"  
  9. #define TYPE0_ROM_SIZE                  "ROM Size"  
  10. #define TYPE0_CHAR                      "Characteristics"  
  11. #define TYPE0_CHAR_RES                  "Reserved"  
  12. #define TYPE0_CHAR_UNKNOWN              "Unknown"  
  13. #define TYPE0_CHAR_NOTSUP               "Not Supported"  
  14. #define TYPE0_CHAR_ISA                  "ISA"  
  15. #define TYPE0_CHAR_MCA                  "MCA"  
  16. #define TYPE0_CHAR_EISA                 "EISA"  
  17. #define TYPE0_CHAR_PCI                  "PCI"  
  18. #define TYPE0_CHAR_PCMCIA               "PCMCIA"  
  19. #define TYPE0_CHAR_PNP                  "Plug and Play"  
  20. #define TYPE0_CHAR_APM                  "Advanced Power Management"  
  21. #define TYPE0_CHAR_FLASH                "Flash"  
  22. #define TYPE0_CHAR_SHADOWING            "Shadowing"  
  23. #define TYPE0_CHAR_VL                   "VL-Vesa"  
  24. #define TYPE0_CHAR_ESCD                 "ESCD"  
  25. #define TYPE0_CHAR_BOOTCD               "Boot from CD"  
  26. #define TYPE0_CHAR_SELBOOT              "Selectable Boot"  
  27. #define TYPE0_CHAR_BIOS_IS_SOCKETED     "Bios Rom is socketed"  
  28. #define TYPE0_CHAR_PCMCIA_BOOT          "Boot from PCMCIA"  
  29. #define TYPE0_CHAR_ENH_DISK_DRIVE       "Enhanced Disk Drive"  
  30. #define TYPE0_CHAR_FD_NEC               "Int13h - japanese Floppy NEC 1,2 MB"  
  31. #define TYPE0_CHAR_FD_TOSHIBA           "Int13h - japanese Floppy Toshiba 1,2 MB"  
  32. #define TYPE0_CHAR_360                  "Int13h - 360 kB Floppy"  
  33. #define TYPE0_CHAR_1200                 "Int13h - 1,2 MB Floppy"  
  34. #define TYPE0_CHAR_720                  "Int13h - 720 kB Floppy"  
  35. #define TYPE0_CHAR_2880                 "Int13h - 2,88 MB Floppy"  
  36. #define TYPE0_CHAR_PRINT_SCREEN         "Int5h - Print Screen"  
  37. #define TYPE0_CHAR_KEYBOARD             "Int9h - 8042 Keyboard"  
  38. #define TYPE0_CHAR_SER_SERVICES         "Int14h - Serial Services"  
  39. #define TYPE0_CHAR_PRINT_SERVICES       "Int17h - Printer Services"  
  40. #define TYPE0_CHAR_VIDEO_SERVICES       "Int10h - CGA,Mono Video Services"  
  41. #define TYPE0_CHAR_PC98                 "NEC PC-98"  
  42. #define TYPE0_EXT1_ACPI                 "ACPI"  
  43. #define TYPE0_EXT1_USB                  "USB Legacy"  
  44. #define TYPE0_EXT1_AGP                  "AGP"  
  45. #define TYPE0_EXT1_I2O_BOOT             "I2O Boot"  
  46. #define TYPE0_EXT1_LS120                "LS-120"  
  47. #define TYPE0_EXT1_ATAPI_ZIP_BOOT       "ATAPI ZIP Boot"  
  48. #define TYPE0_EXT1_1394_BOOT            "1394 Boot"  
  49. #define TYPE0_EXT1_SMART_BATTERY        "Smart Battery"  
  50. #define TYPE0_EXT2_BBS                  "Bios Boot Spec."  
  51. #define TYPE0_EXT2_NETWORK_BOOT         "Function key initiated Network Service Boot"  


  3、实现文件cooking.c和bios.c: 文件cooking.c中的各个函数,如bios_cook_type_0(),bios_cook_type_1(),是对相应SMBIOS结构数据的解析。各个函数做的工作类似,基本流程如下:
  (1)分配足够的空间(char[]型数组file)来存放整个结构的解析数据;
  (2)解析结构头部信息,把strgdef.h中的相应信息用strcpy写入到file中;
  (3)解析各个字符串信息,把strgdef.h中的相应字符串写入到file中;
  (4)用kmalloc分配proc文件的内存,然后把用memcpy把file数组写入到proc文件中。
  bios.c主要是实现对proc文件系统的操作,从内存的BIOS区域中(注意SMBIOS数据在BIOS启动时会被载入到内存的BIOS区域中),读取SMBIOS原始数据或解析成可理解的格式,然后写到proc文件系统中,由于proc文件系统在内存中,因此核心的实现就是把读取的数据用memcpy()直接拷贝到内存的proc区域中。实现的函数有:
  (1)smbios_find_entry_point(void* base):从base开始搜索SMBIOS EPS表,只要搜索到固定字符串"_SM_"即可;
  (2)dmibios_find_entry_point(void* base):从base开始搜索DMI EPS表,只要搜索到固定字符串"_DMI"即可;
  (3)smbios_check_entry_point (void *addr):校验EPS表格;
  (4)smbios_get_struct_length():返回指定类型的SMBIOS结构长度;
  (5)bios_read_raw_proc():当应用程序需要打开本驱动程序创建的proc文件中,本函数就会被内核调用,以获取proc文件中的原始数据;
  (6)dmibios_read_raw_proc():跟前一个类似。
  (7)bios_read_cooked_proc():跟前面类似,只 不过读取的是友好格式的数据;
  (8)smbios_make_version_entry():在proc文件系统中创建smbios_version文件;
  (9)smbios_make_dir_entries():在proc文件系统中创建多个文件,每个类型的SMBIOS结构对应一个文件type[-subtype].instance;
  (10)smbios_destroy_dir_entries():删除指定proc目录下的所有SMBIOS文件;
  (11)smbios_get_readable_name():把SMBIOS类型转换成可理解的格式;
  (12)make_file_entries():在指定的proc目录中创建一个文件。
  4、main.c文件: 包含本驱动模块的框架性函数。


[cpp]  view plain copy

  1. /** /文件 main.c 
  2.  *  smbios内核模块的内核接口函数 
  3.  */  
  4. #ifndef __KERNEL__  
  5. #  define __KERNEL__  
  6. #endif  
  7. #ifndef MODULE  
  8. #  define MODULE  
  9. #endif  
  10. #define __NO_VERSION__      /* 在module.h中不要定义kernel_version */  
  11. #include <linux/module.h>  
  12. #include <linux/version.h>  
  13. char kernel_version[] = UTS_RELEASE;  
  14. #include <linux/kernel.h> /* printk() */  
  15. #include <linux/errno.h>  /* 错误码 */  
  16. #include <linux/types.h>  /* size_t */  
  17. #include <linux/proc_fs.h>  
  18. #include <asm/io.h>           /* ioremap() */  
  19. #include "strgdef.h"        /* 所有解析成的字符串定义 */  
  20. #include "bios.h"           /* 本地定义 */  
  21. EXPORT_NO_SYMBOLS;  
  22. /** /fn 函数int init_module (void) 
  23.  *  /brief 模块初始化,成功返回0,否则返回一个错误码 
  24.  */  
  25. int  
  26. init_module (void)  
  27. {  
  28.     int err = 0;  
  29.     PDEBUG ("starting module initialization/n");  
  30.     /* 
  31.      *  映射SMBIOS存储段:ioremap把一个物理地址映射到虚拟地址,例如把BIOS起始地址映射成Bios F-段, 
  32.      *  即返回的起始虚拟地址smbios_base 
  33.      */  
  34.     if (!(smbios_base = ioremap (BIOS_START_ADDRESS, BIOS_MAP_LENGTH)))  
  35.     {  
  36.         PDEBUG ("ioremap() for entry point failed/n");  
  37.         err = -ENXIO;  
  38.         goto ioremap_for_entry_point_failed;  
  39.     }  
  40.     PDEBUG ("BIOS base set to 0x%p/n", smbios_base);  
  41.     /* 
  42.      *   搜索SMBIOS或DMIBIOS入口点(EPS表起始地址) 
  43.      */  
  44.     if (!(smbios_entry_point = smbios_find_entry_point (smbios_base)))  
  45.     {  
  46.         PDEBUG ("SM-BIOS entry point not found/n");  
  47.         if (!(dmibios_entry_point = dmibios_find_entry_point (smbios_base)))  
  48.         {  
  49.             PDEBUG ("DMI-BIOS entry point not found. Aborting.../n");  
  50.             err = -ENXIO;  
  51.             goto find_entry_point_failed;  
  52.         }  
  53.     }  
  54.     /* 
  55.      *  对SM-BIOS:检查指向DMI结构的指针是否存在。中间字符串_DMI_不是以'/0'结尾,因此strncmp()传入大小为sizeof(DMI_STRING)-1 
  56.      */  
  57.     if (smbios_entry_point)  
  58.     {  
  59.         if (strncmp((char *) &(smbios_entry_point->intermediate_string),  
  60.                         DMI_STRING, sizeof (DMI_STRING) - 1))  
  61.         {  
  62.             PDEBUG ("Pointer to DMI structures not found!/n");  
  63.             err = -ENXIO;  
  64.             goto check_dmi_failed;  
  65.         }  
  66.     }  
  67.     /* 
  68.      *  映射SMBIOS结构的物理地址段,返回的smbios_structures_base包含了SMBIOS结构数据起始地址 
  69.      */  
  70.     if (smbios_entry_point)  
  71.     {  
  72.         if (!(smbios_structures_base =  
  73.               ioremap (smbios_entry_point->struct_table_address,  
  74.                 (unsigned long) smbios_entry_point->struct_table_length)))  
  75.         {  
  76.             PDEBUG ("ioremap() for structures table failed/n");  
  77.             err = -ENXIO;  
  78.             goto ioremap_for_structures_table_failed;  
  79.         }  
  80.     }  
  81.     /* 
  82.      * 另一方面,如果我们有专有的DMI Bios,则smbios_structures_base会包含指向表格的指针,这个表格包含了到每个sm/dmi bios结构的偏移 
  83.      */  
  84.     if (dmibios_entry_point)  
  85.     {  
  86.         if (!(smbios_structures_base = dmibios_entry_point->entry))  
  87.         {  
  88.             PDEBUG ("invalid structure table entry%p,%p/n", smbios_structures_base,  
  89.                 dmibios_entry_point->entry);  
  90.             err = -ENXIO;  
  91.             goto ioremap_for_structures_table_failed;  
  92.         }  
  93.     }  
  94.     PDEBUG ("DMI structures base set to 0x%p/n", smbios_structures_base);  
  95.     /* 
  96.      *  创建/proc节点 
  97.      */  
  98.        
  99.     /* 创建/proc/smbios目录 */  
  100.     if (!(smbios_proc_dir =  
  101.            create_proc_entry (PROC_DIR_STRING, S_IFDIR, &proc_root)))  
  102.     {  
  103.         err = -ENOMEM;  
  104.         PDEBUG ("failed to create /proc/smbios directory entry/n");  
  105.         goto create_smbios_dir_failed;  
  106.     }  
  107.     PDEBUG ("/proc/smbios directory created./n");  
  108.      
  109.     /* 创建/proc/smbios/raw目录 */  
  110.     if (!(smbios_raw_proc_dir =  
  111.                  create_proc_entry (PROC_DIR_STRING_RAW, S_IFDIR, smbios_proc_dir)))  
  112.     {  
  113.         err = -ENOMEM;  
  114.         PDEBUG ("failed to create /proc/smbios/raw directory entry/n");  
  115.         goto create_smbios_raw_dir_failed;  
  116.     }  
  117.     PDEBUG ("/proc/smbios/raw directory created./n");  
  118.     /* 创建/proc/smbios/cooked目录 */  
  119.     if (!(smbios_cooked_proc_dir =  
  120.                  create_proc_entry (PROC_DIR_STRING_COOKED, S_IFDIR, smbios_proc_dir)))  
  121.     {  
  122.         err = -ENOMEM;  
  123.         PDEBUG ("failed to create /proc/smbios/cooked directory entry/n");  
  124.         goto create_smbios_cooked_dir_failed;  
  125.     }  
  126.     PDEBUG ("/proc/smbios/cooked directory created./n");  
  127.     /* 创建版本文件 */  
  128.     if (smbios_entry_point)  
  129.     {  
  130.         if ((err = smbios_make_version_entry (smbios_proc_dir)))  
  131.             goto smbios_make_version_entry_failed;  
  132.     }  
  133.    /* 创建各个SMBIOS结构对应的文件 */  
  134.    if (smbios_entry_point)  
  135.    {  
  136.         if ((err = smbios_make_dir_entries (smbios_proc_dir, smbios_raw_proc_dir, smbios_cooked_proc_dir)))  
  137.             goto make_smbios_dir_entries_failed;  
  138.    }      
  139.    /* 创建各个DMI BIOS结构对应的文件 */  
  140.    if (dmibios_entry_point)  
  141.    {  
  142.         if ((err = dmibios_make_dir_entries (smbios_proc_dir, smbios_raw_proc_dir, smbios_cooked_proc_dir)))  
  143.             goto make_smbios_dir_entries_failed;  
  144.    }      
  145.    PDEBUG ("module loaded succesfully/n");  
  146.    return 0;  
  147. /* 
  148.  * 发生错误时就会到达这里,需要对发生错误之前做的操作进行回滚处理(如申请了资源,则需要进行释放) 
  149.  */  
  150. make_smbios_dir_entries_failed:  
  151.     /* remove /proc/smbios/cooked files */  
  152.     smbios_destroy_dir_entries (smbios_cooked_proc_dir);  
  153.     /* remove /proc/smbios/raw files */  
  154.     smbios_destroy_dir_entries (smbios_raw_proc_dir);  
  155.     /* remove /proc/smbios files */  
  156.     smbios_destroy_dir_entries (smbios_proc_dir);     
  157. smbios_make_version_entry_failed:  
  158.     /* remove /proc/smbios/cooked directory */  
  159.     remove_proc_entry(PROC_DIR_STRING_COOKED, smbios_proc_dir);   
  160. create_smbios_cooked_dir_failed :  
  161.     /* remove /proc/smbios/raw directory */  
  162.     remove_proc_entry(PROC_DIR_STRING_RAW, smbios_proc_dir);  
  163. create_smbios_raw_dir_failed:  
  164.     /* remove /proc/smbios directory */  
  165.     remove_proc_entry(PROC_DIR_STRING, &proc_root);   
  166. create_smbios_dir_failed:  
  167.     /* unmap the virtual to physical memory binding */  
  168.     if (smbios_entry_point)  
  169.         iounmap (smbios_structures_base);  
  170. ioremap_for_structures_table_failed:  
  171. check_dmi_failed:  
  172. find_entry_point_failed:  
  173.     /* unmap the virtual to physical memory binding */  
  174.     iounmap (smbios_base);  
  175. ioremap_for_entry_point_failed:  
  176.     return err;  
  177. }  
  178. /** /fn 函数int cleanup_module (void) 
  179.  *  /brief 模块清理 
  180.  */  
  181. void  
  182. cleanup_module (void)  
  183. {  
  184.     /* 删除/proc/smbios/cooked下的各个文件 */  
  185.     smbios_destroy_dir_entries (smbios_cooked_proc_dir);  
  186.     /* 删除/proc/smbios/raw下的各个文件 */  
  187.     smbios_destroy_dir_entries (smbios_raw_proc_dir);  
  188.     /* 删除/proc/smbios下的文件 */  
  189.     smbios_destroy_dir_entries (smbios_proc_dir);     
  190.     /* 删除/proc/smbios/cooked目录 */  
  191.     remove_proc_entry(PROC_DIR_STRING_COOKED, smbios_proc_dir);  
  192.     /* 删除/proc/smbios/raw目录 */  
  193.     remove_proc_entry(PROC_DIR_STRING_RAW, smbios_proc_dir);  
  194.     /* 删除/proc/smbios目录 */  
  195.     remove_proc_entry(PROC_DIR_STRING, &proc_root);  
  196.       
  197.     /* 取消虚拟地址到物理地址的映射 */  
  198.     if (smbios_entry_point)  
  199.         iounmap (smbios_structures_base);  
  200.     iounmap (smbios_base);  
  201.     PDEBUG ("module unloaded/n");  
  202. }  

  (1)init_module():映射SMBIOS存储段地址(映射到虚拟地址上)、搜索SMBIOS或DMI的EPS表、映射SMBIOS结构的物理地址、创建目录结点/proc/smbios/raw和/proc/smbios/cooked、在其中创建各个类型的SMBIOS文件。
  (2)cleanup_module():删除proc中的各个SMBIOS文件、删除相应目录、解除地址映射。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
System Management BIOS (SMBIOS) Reference 6 Specification 7 Supersedes: 3.1.1 8 Document Class: Normative 9 Document Status: Published 10 Document Language: en-US 11System Management BIOS (SMBIOS) Reference Specification DSP0134 2 Published Version 3.2.0 12 Copyright Notice 13 Copyright © 2000, 2002, 2004–2016 Distributed Management Task Force, Inc. (DMTF). All rights 14 reserved. 15 DMTF is a not-for-profit association of industry members dedicated to promoting enterprise and systems 16 management and interoperability. Members and non-members may reproduce DMTF specifications and 17 documents, provided that correct attribution is given. As DMTF specifications may be revised from time to 18 time, the particular version and release date should always be noted. 19 Implementation of certain elements of this standard or proposed standard may be subject to third party 20 patent rights, including provisional patent rights (herein "patent rights"). DMTF makes no representations 21 to users of the standard as to the existence of such rights, and is not responsible to recognize, disclose, 22 or identify any or all such third party patent right, owners or claimants, nor for any incomplete or 23 inaccurate identification or disclosure of such rights, owners or claimants. DMTF shall have no liability to 24 any party, in any manner or circumstance, under any legal theory whatsoever, for failure to recognize, 25 disclose, or identify any such third party patent rights, or for such party’s reliance on the standard or 26 incorporation thereof in its product, protocols or testing procedures. DMTF shall have no liability to any 27 party implementing such standard, whether such implementation is foreseeable or not, nor to any patent 28 owner or claimant, and shall have no liability or responsibility for costs or losses incurred if a standard is 29 withdrawn or modified after publication, and shall be indemnified and held harmless by any party 30 implementing the standard from any and all claims of infringement by a patent owner for such 31 implementations. 32 For information about patents held by third-parties which have notified the DMTF that, in their opinion, 33 such patent may relate to or impact implementations of DMTF standards, visit 34 http://www.dmtf.org/about/policies/disclosures.php. 35 This document’s normative language is English. Translation into other languages is permitted.DSP0134 System Management BIOS (SMBIOS) Reference Specification Version 3.2.0 Published 3 36 CONTENTS 37 Foreword ....................................................................................................................................................... 9 38 Introduction.................................................................................................................................................. 10 39 Document conventions........................................................................................................................ 10 40 Typographical conventions ....................................................................................................... 10 41 Document version number conventions ................................................................................... 10 42 1 Scope .................................................................................................................................................. 13 43 1.1 Supported processor architectures........................................................................................... 13 44 2 Normative references .......................................................................................................................... 13 45 3 Terms and definitions .......................................................................................................................... 15 46 4 Symbols and abbreviated terms.......................................................................................................... 15 47 5 Accessing SMBIOS information .......................................................................................................... 21 48 5.1 General ..................................................................................................................................... 21 49 5.2 Table convention....................................................................................................................... 21 50 5.2.1 SMBIOS 2.1 (32-bit) Entry Point.................................................................................. 22 51 5.2.2 SMBIOS 3.0 (64-bit) Entry Point.................................................................................. 23 52 6 SMBIOS structures.............................................................................................................................. 24 53 6.1 Structure standards................................................................................................................... 24 54 6.1.1 Structure evolution and usage guidelines.................................................................... 25 55 6.1.2 Structure header format............................................................................................... 26 56 6.1.3 Text strings .................................................................................................................. 26 57 6.2 Required structures and data ................................................................................................... 27 58 6.3 SMBIOS fields and CIM MOF properties.................................................................................. 28 59 7 Structure definitions............................................................................................................................. 29 60 7.1 BIOS Information (Type 0)........................................................................................................ 29 61 7.1.1 BIOS Characteristics.................................................................................................... 31 62 7.1.2 BIOS Characteristics Extension Bytes......................................................................... 32 63 7.2 System Information (Type 1) .................................................................................................... 33 64 7.2.1 System — UUID........................................................................................................... 34 65 7.2.2 System — Wake-up Type............................................................................................ 35 66 7.3 Baseboard (or Module) Information (Type 2) ........................................................................... 35 67 7.3.1 Baseboard — feature flags .......................................................................................... 36 68 7.3.2 Baseboard — Board Type ........................................................................................... 37 69 7.4 System Enclosure or Chassis (Type 3) .................................................................................... 37 70 7.4.1 System Enclosure or Chassis Types........................................................................... 39 71 7.4.2 System Enclosure or Chassis States........................................................................... 40 72 7.4.3 System Enclosure or Chassis Security Status ............................................................ 41 73 7.4.4 System Enclosure or Chassis — Contained Elements................................................ 41 74 7.5 Processor Information (Type 4) ................................................................................................ 42 75 7.5.1 Processor Information — Processor Type................................................................... 45 76 7.5.2 Processor Information — Processor Family ................................................................ 46 77 7.5.3 Processor ID field format ............................................................................................. 52 78 7.5.4 Processor Information — Voltage................................................................................ 52 79 7.5.5 Processor Information — Processor Upgrade............................................................. 53 80 7.5.6 Processor Information — Core Count.......................................................................... 55 81 7.5.7 Processor Information — Core Enabled...................................................................... 55 82 7.5.8 Processor Information — Thread Count...................................................................... 56 83 7.5.9 Processor Characteristics............................................................................................ 56 84 7.6 Memory Controller Information (Type 5, Obsolete) .................................................................. 57 85 7.6.1 Memory Controller Error Detecting Method................................................................. 58 86 7.6.2 Memory Controller Error Correcting Capability............................................................ 58 87 7.6.3 Memory Controller Information — Interleave Support................................................. 58System Management BIOS (SMBIOS) Reference Specification DSP0134 4 Published Version 3.2.0 88 7.6.4 Memory Controller Information — Memory Speeds .................................................... 59 89 7.7 Memory Module Information (Type 6, Obsolete) ...................................................................... 59 90 7.7.1 Memory Module Information — Memory Types .......................................................... 60 91 7.7.2 Memory Module Information — Memory Size ............................................................. 60 92 7.7.3 Memory subsystem example ....................................................................................... 61 93 7.8 Cache Information (Type 7) ...................................................................................................... 63 94 7.8.1 Cache Information — Maximum Cache Size and Installed Size ................................. 65 95 7.8.2 Cache Information — SRAM Type .............................................................................. 65 96 7.8.3 Cache Information — Error Correction Type ............................................................... 66 97 7.8.4 Cache Information — System Cache Type ................................................................. 66 98 7.8.5 Cache Information — Associativity.............................................................................. 66 99 7.9 Port Connector Information (Type 8) ........................................................................................ 67 100 7.9.1 Port Information example............................................................................................. 68 101 7.9.2 Port Information — Connector Types .......................................................................... 68 102 7.9.3 Port Types.................................................................................................................... 69 103 7.10 System Slots (Type 9)............................................................................................................... 70 104 7.10.1 System Slots — Slot Type ........................................................................................... 71 105 7.10.2 System Slots — Slot Data Bus Width.......................................................................... 73 106 7.10.3 System Slots — Current Usage................................................................................... 74 107 7.10.4 System Slots — Slot Length ........................................................................................ 74 108 7.10.5 System Slots — Slot ID ............................................................................................... 74 109 7.10.6 Slot Characteristics 1................................................................................................... 75 110 7.10.7 Slot Characteristics 2................................................................................................... 75 111 7.10.8 Segment Group Number, Bus Number, Device/Func

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值