xref: /dflybsd-src/sys/dev/drm/linux_dmi.c (revision eb0e71460f3a21be2d9efc2391a834f95ba94974)
1*eb0e7146SFrançois Tigeot /*
2*eb0e7146SFrançois Tigeot  * Copyright (c) 2019 François Tigeot <ftigeot@wolfpond.org>
3*eb0e7146SFrançois Tigeot  * All rights reserved.
4*eb0e7146SFrançois Tigeot  *
5*eb0e7146SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
6*eb0e7146SFrançois Tigeot  * modification, are permitted provided that the following conditions
7*eb0e7146SFrançois Tigeot  * are met:
8*eb0e7146SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
9*eb0e7146SFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
10*eb0e7146SFrançois Tigeot  *    disclaimer.
11*eb0e7146SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
12*eb0e7146SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
13*eb0e7146SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
14*eb0e7146SFrançois Tigeot  *
15*eb0e7146SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*eb0e7146SFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*eb0e7146SFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*eb0e7146SFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19*eb0e7146SFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*eb0e7146SFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*eb0e7146SFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*eb0e7146SFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*eb0e7146SFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*eb0e7146SFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*eb0e7146SFrançois Tigeot  */
26*eb0e7146SFrançois Tigeot 
27*eb0e7146SFrançois Tigeot #include <linux/types.h>
28*eb0e7146SFrançois Tigeot #include <linux/string.h>
29*eb0e7146SFrançois Tigeot #include <linux/init.h>
30*eb0e7146SFrançois Tigeot #include <linux/module.h>
31*eb0e7146SFrançois Tigeot #include <linux/ctype.h>
32*eb0e7146SFrançois Tigeot #include <linux/dmi.h>
33*eb0e7146SFrançois Tigeot #include <asm/unaligned.h>
34*eb0e7146SFrançois Tigeot 
35*eb0e7146SFrançois Tigeot bool
dmi_match(enum dmi_field f,const char * str)36*eb0e7146SFrançois Tigeot dmi_match(enum dmi_field f, const char *str)
37*eb0e7146SFrançois Tigeot {
38*eb0e7146SFrançois Tigeot 	const char *s = NULL;
39*eb0e7146SFrançois Tigeot 
40*eb0e7146SFrançois Tigeot 	switch (f) {
41*eb0e7146SFrançois Tigeot 	case DMI_NONE:
42*eb0e7146SFrançois Tigeot 		break;
43*eb0e7146SFrançois Tigeot 	case DMI_SYS_VENDOR:
44*eb0e7146SFrançois Tigeot 		s = kgetenv("smbios.system.maker");
45*eb0e7146SFrançois Tigeot 		if (s != NULL && !strcmp(s, str))
46*eb0e7146SFrançois Tigeot 			return true;
47*eb0e7146SFrançois Tigeot 		break;
48*eb0e7146SFrançois Tigeot 	case DMI_BOARD_VENDOR:
49*eb0e7146SFrançois Tigeot 		s = kgetenv("smbios.planar.maker");
50*eb0e7146SFrançois Tigeot 		if (s != NULL && !strcmp(s, str))
51*eb0e7146SFrançois Tigeot 			return true;
52*eb0e7146SFrançois Tigeot 		break;
53*eb0e7146SFrançois Tigeot 	case DMI_PRODUCT_NAME:
54*eb0e7146SFrançois Tigeot 		s = kgetenv("smbios.system.product");
55*eb0e7146SFrançois Tigeot 		if (s != NULL && !strcmp(s, str))
56*eb0e7146SFrançois Tigeot 			return true;
57*eb0e7146SFrançois Tigeot 		break;
58*eb0e7146SFrançois Tigeot 	case DMI_BOARD_NAME:
59*eb0e7146SFrançois Tigeot 		s = kgetenv("smbios.planar.product");
60*eb0e7146SFrançois Tigeot 		if (s != NULL && !strcmp(s, str))
61*eb0e7146SFrançois Tigeot 			return true;
62*eb0e7146SFrançois Tigeot 		break;
63*eb0e7146SFrançois Tigeot 	default:
64*eb0e7146SFrançois Tigeot 		return false;
65*eb0e7146SFrançois Tigeot 	}
66*eb0e7146SFrançois Tigeot 
67*eb0e7146SFrançois Tigeot 	return false;
68*eb0e7146SFrançois Tigeot }
69