1 /* $NetBSD: linux_dmi.c,v 1.2 2018/08/27 06:45:44 riastradh Exp $ */ 2 3 /*- 4 * Copyright (C) 2014 NONAKA Kimihiro <nonaka@netbsd.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #include <sys/cdefs.h> 29 __KERNEL_RCSID(0, "$NetBSD: linux_dmi.c,v 1.2 2018/08/27 06:45:44 riastradh Exp $"); 30 31 #include <sys/param.h> 32 #include <sys/types.h> 33 #include <sys/pmf.h> 34 35 #include <linux/dmi.h> 36 37 bool 38 dmi_match(enum dmi_field slot, const char *text) 39 { 40 const char *p = NULL; 41 42 switch (slot) { 43 case DMI_NONE: 44 aprint_error("%s: dmi_match on none makes no sense", __func__); 45 return false; 46 case DMI_BIOS_VENDOR: 47 p = pmf_get_platform("bios-vendor"); 48 break; 49 case DMI_BIOS_VERSION: 50 p = pmf_get_platform("bios-version"); 51 break; 52 case DMI_BIOS_DATE: 53 p = pmf_get_platform("bios-date"); 54 break; 55 case DMI_SYS_VENDOR: 56 p = pmf_get_platform("system-vendor"); 57 break; 58 case DMI_PRODUCT_NAME: 59 p = pmf_get_platform("system-product"); 60 break; 61 case DMI_PRODUCT_VERSION: 62 p = pmf_get_platform("system-version"); 63 break; 64 case DMI_PRODUCT_SERIAL: 65 p = pmf_get_platform("system-serial"); 66 break; 67 case DMI_PRODUCT_UUID: 68 p = pmf_get_platform("system-uuid"); 69 break; 70 case DMI_BOARD_VENDOR: 71 p = pmf_get_platform("board-vendor"); 72 break; 73 case DMI_BOARD_NAME: 74 p = pmf_get_platform("board-product"); 75 break; 76 case DMI_BOARD_VERSION: 77 p = pmf_get_platform("board-version"); 78 break; 79 case DMI_BOARD_SERIAL: 80 p = pmf_get_platform("board-serial"); 81 break; 82 case DMI_BOARD_ASSET_TAG: 83 p = pmf_get_platform("board-asset-tag"); 84 break; 85 case DMI_CHASSIS_VENDOR: 86 case DMI_CHASSIS_TYPE: 87 case DMI_CHASSIS_VERSION: 88 case DMI_CHASSIS_SERIAL: 89 case DMI_CHASSIS_ASSET_TAG: 90 return false; 91 case DMI_STRING_MAX: 92 default: 93 aprint_error("%s: unknown DMI field(%d)\n", __func__, slot); 94 return false; 95 } 96 if (p == NULL || strcmp(p, text)) 97 return false; 98 99 return true; 100 } 101 102 static bool 103 dmi_found(const struct dmi_system_id *dsi) 104 { 105 int i; 106 107 for (i = 0; i < __arraycount(dsi->matches); i++) { 108 if (dsi->matches[i].slot == DMI_NONE) 109 break; 110 if (!dmi_match(dsi->matches[i].slot, dsi->matches[i].substr)) 111 return false; 112 } 113 return true; 114 } 115 116 int 117 dmi_check_system(const struct dmi_system_id *sysid) 118 { 119 const struct dmi_system_id *dsi; 120 int num = 0; 121 122 for (dsi = sysid; dsi->matches[0].slot != DMI_NONE; dsi++) { 123 if (dmi_found(dsi)) { 124 num++; 125 if (dsi->callback && dsi->callback(dsi)) 126 break; 127 } 128 } 129 return num; 130 } 131