1 /* $NetBSD: linux_dmi.c,v 1.1 2014/04/25 23:54:59 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.1 2014/04/25 23:54:59 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 static bool
dmi_found(const struct dmi_system_id * dsi)38 dmi_found(const struct dmi_system_id *dsi)
39 {
40 const char *p;
41 int i, slot;
42
43 for (i = 0; i < __arraycount(dsi->matches); i++) {
44 p = NULL;
45 slot = dsi->matches[i].slot;
46 switch (slot) {
47 case DMI_NONE:
48 continue;
49 case DMI_BIOS_VENDOR:
50 p = pmf_get_platform("bios-vendor");
51 break;
52 case DMI_BIOS_VERSION:
53 p = pmf_get_platform("bios-version");
54 break;
55 case DMI_BIOS_DATE:
56 p = pmf_get_platform("bios-date");
57 break;
58 case DMI_SYS_VENDOR:
59 p = pmf_get_platform("system-vendor");
60 break;
61 case DMI_PRODUCT_NAME:
62 p = pmf_get_platform("system-product");
63 break;
64 case DMI_PRODUCT_VERSION:
65 p = pmf_get_platform("system-version");
66 break;
67 case DMI_PRODUCT_SERIAL:
68 p = pmf_get_platform("system-serial");
69 break;
70 case DMI_PRODUCT_UUID:
71 p = pmf_get_platform("system-uuid");
72 break;
73 case DMI_BOARD_VENDOR:
74 p = pmf_get_platform("board-vendor");
75 break;
76 case DMI_BOARD_NAME:
77 p = pmf_get_platform("board-product");
78 break;
79 case DMI_BOARD_VERSION:
80 p = pmf_get_platform("board-version");
81 break;
82 case DMI_BOARD_SERIAL:
83 p = pmf_get_platform("board-serial");
84 break;
85 case DMI_BOARD_ASSET_TAG:
86 p = pmf_get_platform("board-asset-tag");
87 break;
88 case DMI_CHASSIS_VENDOR:
89 case DMI_CHASSIS_TYPE:
90 case DMI_CHASSIS_VERSION:
91 case DMI_CHASSIS_SERIAL:
92 case DMI_CHASSIS_ASSET_TAG:
93 return false;
94 case DMI_STRING_MAX:
95 default:
96 aprint_error("%s: unknown DMI field(%d)\n", __func__,
97 slot);
98 return false;
99 }
100 if (p == NULL || strcmp(p, dsi->matches[i].substr))
101 return false;
102 }
103 return true;
104 }
105
106 int
dmi_check_system(const struct dmi_system_id * sysid)107 dmi_check_system(const struct dmi_system_id *sysid)
108 {
109 const struct dmi_system_id *dsi;
110 int num = 0;
111
112 for (dsi = sysid; dsi->matches[0].slot != DMI_NONE; dsi++) {
113 if (dmi_found(dsi)) {
114 num++;
115 if (dsi->callback && dsi->callback(dsi))
116 break;
117 }
118 }
119 return num;
120 }
121