Debian Codegraph @

src/drivers/option/cfr_frontend.h

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #ifndef DRIVERS_OPTION_CFR_H
4 #define DRIVERS_OPTION_CFR_H
5
6 #include <commonlib/coreboot_tables.h>
7 #include <commonlib/cfr.h>
8 #include <types.h>
9
10 /* Front-end */
11 struct sm_enum_value {
12 const char *ui_name;
13 uint32_t value;
14 };
15
16 #define SM_ENUM_VALUE_END ((struct sm_enum_value) {0})
17
18 struct sm_obj_enum {
19 uint32_t flags; /* enum cfr_option_flags */
20 const char *opt_name;
21 const char *ui_name;
22 const char *ui_helptext;
23 uint32_t default_value;
24 const struct sm_enum_value *values;
25 };
26
27 struct sm_obj_number {
28 uint32_t flags; /* enum cfr_option_flags */
29 const char *opt_name;
30 const char *ui_name;
31 const char *ui_helptext;
32 uint32_t default_value;
33 uint32_t min;
34 uint32_t max;
35 uint32_t step;
36 uint32_t display_flags; /* enum cfr_numeric_option_display_flags */
37 };
38
39 struct sm_obj_bool {
40 uint32_t flags; /* enum cfr_option_flags */
41 const char *opt_name;
42 const char *ui_name;
43 const char *ui_helptext;
44 bool default_value;
45 };
46
47 struct sm_obj_varchar {
48 uint32_t flags; /* enum cfr_option_flags */
49 const char *opt_name;
50 const char *ui_name;
51 const char *ui_helptext;
52 const char *default_value;
53 };
54
55 struct sm_obj_comment {
56 uint32_t flags; /* enum cfr_option_flags */
57 const char *ui_name;
58 const char *ui_helptext;
59 };
60
61 struct sm_object;
62
63 struct sm_obj_form {
64 uint32_t flags; /* enum cfr_option_flags */
65 const char *ui_name;
66 const struct sm_object **obj_list; /* NULL terminated */
67 };
68
69 enum sm_object_kind {
70 SM_OBJ_NONE = 0,
71 SM_OBJ_ENUM,
72 SM_OBJ_NUMBER,
73 SM_OBJ_BOOL,
74 SM_OBJ_VARCHAR,
75 SM_OBJ_COMMENT,
76 SM_OBJ_FORM,
77 };
78
79 struct sm_object {
80 enum sm_object_kind kind;
81 const struct sm_object *dep;
82 const uint32_t *dep_values;
83 const uint32_t num_dep_values;
84 void (*ctor)(const struct sm_object *obj, struct sm_object *new); /* Called on object creation */
85 union {
86 struct sm_obj_enum sm_enum;
87 struct sm_obj_number sm_number;
88 struct sm_obj_bool sm_bool;
89 struct sm_obj_varchar sm_varchar;
90 struct sm_obj_comment sm_comment;
91 struct sm_obj_form sm_form;
92 };
93 };
94
95 /* sm_object helpers with type checking */
96 #define SM_DECLARE_ENUM(...) { .kind = SM_OBJ_ENUM, .dep = NULL, \
97 .dep_values = NULL, .num_dep_values = 0, \
98 .ctor = NULL, .sm_enum = __VA_ARGS__ }
99 #define SM_DECLARE_NUMBER(...) { .kind = SM_OBJ_NUMBER, .dep = NULL, \
100 .dep_values = NULL, .num_dep_values = 0, \
101 .ctor = NULL, .sm_number = __VA_ARGS__ }
102 #define SM_DECLARE_BOOL(...) { .kind = SM_OBJ_BOOL, .dep = NULL, \
103 .dep_values = NULL, .num_dep_values = 0, \
104 .ctor = NULL, .sm_bool = __VA_ARGS__ }
105 #define SM_DECLARE_VARCHAR(...) { .kind = SM_OBJ_VARCHAR, .dep = NULL, \
106 .dep_values = NULL, .num_dep_values = 0, \
107 .ctor = NULL, .sm_varchar = __VA_ARGS__ }
108 #define SM_DECLARE_COMMENT(...) { .kind = SM_OBJ_COMMENT, .dep = NULL, \
109 .dep_values = NULL, .num_dep_values = 0, \
110 .ctor = NULL, .sm_comment = __VA_ARGS__ }
111 #define SM_DECLARE_FORM(...) { .kind = SM_OBJ_FORM, .dep = NULL, \
112 .dep_values = NULL, .num_dep_values = 0, \
113 .ctor = NULL, .sm_form = __VA_ARGS__ }
114
115 #define WITH_CALLBACK(c) .ctor = (c)
116 #define WITH_DEP(d) .dep = (d)
117 #define WITH_DEP_VALUES(d, ...) \
118 .dep = (d), \
119 .dep_values = ((const uint32_t[]) { __VA_ARGS__ }), \
120 .num_dep_values = sizeof((uint32_t[]) { __VA_ARGS__ }) / sizeof(uint32_t)
121
122 void cfr_write_setup_menu(struct lb_cfr *cfr_root, struct sm_obj_form *sm_root[]);
123
124 #if ENV_RAMSTAGE
125 #define __cfr_form __attribute__((used, __section__(".rodata.cfr_forms")))
126 #else
127 #define __cfr_form __maybe_unused
128 #endif
129
130 /** start of compile time generated cfr form array */
131 extern struct sm_obj_form _cfr_forms[];
132 /** end of compile time generated cfr form array */
133 extern struct sm_obj_form _ecfr_forms[];
134
135 #endif /* DRIVERS_OPTION_CFR_H */