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