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