xref: /freebsd/stand/libsa/features.c (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1 /*-
2  * Copyright (c) 2023 Kyle Evans <kevans@FreeBSD.org>
3  *
4  * SPDX-License-Identifier: BSD-2-Clause
5  *
6  */
7 
8 #include <sys/param.h>
9 
10 #include "stand.h"
11 
12 static uint32_t loader_features;
13 
14 #define	FEATURE_ENTRY(name, desc)	{ FEATURE_##name, #name, desc }
15 static const struct feature_entry {
16 	uint32_t	value;
17 	const char	*name;
18 	const char	*desc;
19 } feature_map[] = {
20 	FEATURE_ENTRY(EARLY_ACPI,  "Loader probes ACPI in early startup"),
21 };
22 
23 void
24 feature_enable(uint32_t mask)
25 {
26 
27 	loader_features |= mask;
28 }
29 
30 bool
31 feature_name_is_enabled(const char *name)
32 {
33 	const struct feature_entry *entry;
34 
35 	for (size_t i = 0; i < nitems(feature_map); i++) {
36 		entry = &feature_map[i];
37 
38 		if (strcmp(entry->name, name) == 0)
39 			return ((loader_features & entry->value) != 0);
40 	}
41 
42 	return (false);
43 }
44 
45 void
46 feature_iter(feature_iter_fn *iter_fn, void *cookie)
47 {
48 	const struct feature_entry *entry;
49 
50 	for (size_t i = 0; i < nitems(feature_map); i++) {
51 		entry = &feature_map[i];
52 
53 		(*iter_fn)(cookie, entry->name, entry->desc,
54 		    (loader_features & entry->value) != 0);
55 	}
56 }
57