Debian Codegraph @

Documentation/drivers/cfr_internal.md

raw symbols SCIP
1 # CFR - coreboot form representation - Internals
2
3 This documents the API internally used by coreboot to be used
4 by ramstage code.
5
6 Please read [CFR](cfr.md) first.
7
8 ## Enabling CFR support
9
10 Users should select `DRIVERS_OPTION_CFR` in Kconfig to enable CFR
11 support. Mainboards should select `DRIVERS_OPTION_CFR_ENABLED` to
12 enable `DRIVERS_OPTION_CFR` by default.
13
14 ## Using CFR
15
16 When CFR support is enabled there are two possibilites to generate
17 the records:
18
19 - mainboard specific code
20 - automatic collection
21
22 In both cases you have to add `C` structs in ramstage to describe the
23 option and group them together into a form. CFR objects should reside
24 on the heap as they can be modified to match the current boot flow.
25
26 ### Updating CFR options
27
28 The CFR options should be updated before tables are written.
29 You can use a callback, using the `WITH_CALLBACK()` macro, to update
30 single or multiple options when the CFR table is written into the
31 coreboot table.
32
33 **Example:** Updates the option serial_number with the contents from the
34 EMI eeprom.
35
36 ```
37 static void update_serial(const struct sm_object *obj, struct sm_object *new)
38 {
39 new->sm_varchar.default_value = get_emi_eeprom_vpd()->serial_number;
40 }
41
42 static const struct sm_object serial_number = SM_DECLARE_VARCHAR({
43 .flags = CFR_OPTFLAG_READONLY | CFR_OPTFLAG_VOLATILE,
44 .opt_name = "serial_number",
45 .ui_name = "Serial Number",
46 }, WITH_CALLBACK(update_serial));
47 ```
48
49 ### Dependencies in CFR options
50
51 The CFR options can have a dependency that must be evaluated at runtime by
52 the OS/payload that parses the CFR record and displays the UI.
53 By using the `WITH_DEP()` macro you can specify another numeric option that
54 is checked to hide the current option. The `WITH_DEP_VALUES()` macro allows
55 specifying one or more values that cause the dependent option to be displayed.
56
57 **Example:** Declares a dependency from `sata_disable_port0` to `sata_enable`.
58 The option `sata_disable_port0` will be hidden as long as "sata_enable" is 0.
59 When the user changes "sata_enable" to 1 or it was 1 then the option
60 `sata_disable_port0` should be visible.
61
62 ```
63 static struct sm_object sata_enable = SM_DECLARE_BOOL({
64 .flags = CFR_OPTFLAG_RUNTIME,
65 .opt_name = "sata_enable",
66 .ui_name = "Enable SATA controller",
67 .ui_helptext = NULL,
68 .default_value = true,
69 });
70
71 static struct sm_object sata_disable_port0 = SM_DECLARE_BOOL({
72 .flags = CFR_OPTFLAG_RUNTIME,
73 .opt_name = "sata_disable_port0",
74 .ui_name = "Disable SATA port #0",
75 .ui_helptext = NULL,
76 .default_value = false,
77 }, WITH_DEP(&sata_enable));
78 ```
79
80 **Example:** Declares a dependency from `com1_termination` to `com1_mode`.
81 The option `com1_termination` will only be shown if `com1_mode` is set to RS-485.
82
83 ```
84 #define COM_MODE_DISABLED 3
85 #define COM_MODE_RS232 0
86 #define COM_MODE_RS485 1
87
88 static struct sm_object com1_mode = SM_DECLARE_ENUM({
89 .flags = CFR_OPTFLAG_RUNTIME,
90 .opt_name = "com1_mode",
91 .ui_name = "COM1 Mode",
92 .ui_helptext = NULL,
93 .default_value = 1,
94 .values = (const struct sm_enum_value[]) {
95 { "Disabled", COM_MODE_DISABLED },
96 { "RS-232", COM_MODE_RS232 },
97 { "RS-485", COM_MODE_RS485 },
98 SM_ENUM_VALUE_END },
99 });
100
101 static struct sm_object com1_termination = SM_DECLARE_BOOL({
102 .flags = CFR_OPTFLAG_RUNTIME,
103 .opt_name = "com1_termination",
104 .ui_name = "Enable COM1 termination resistors",
105 .ui_helptext = NULL,
106 .default_value = false,
107 }, WITH_DEP_VALUES(&com1_mode, COM_MODE_RS485));
108
109 ```
110
111 ### Providing mainboard custom options
112
113 A mainboard that uses CFR can provide a list of custom options
114 be overwriting the weak `void mb_cfr_setup_menu(struct lb_cfr *cfr_root);`
115 function in ramstage.
116
117 ### Automatic CFR collection
118
119 CFR forms that have the `__cfr_form` attribute are automatically collected
120 and inserted into the coreboot table.
121
122 ## Example
123
124 The following CFR form `southbridge` will be automatically added to the
125 coreboot table and it will have a single option called `Enable NMI` that
126 allows the variable `nmi` to be changed to *0* or *1*.
127
128 **Example:**
129 ```C
130 static struct sm_object nmi = SM_DECLARE_BOOL({
131 .flags = CFR_OPTFLAG_RUNTIME,
132 .opt_name = "nmi",
133 .ui_name = "Enable NMI",
134 .ui_helptext = NULL,
135 .default_value = false,
136 });
137
138 static const __cfr_form struct sm_obj_form southbridge = {
139 .flags = 0,
140 .ui_name = "Southbridge",
141 .obj_list = (const struct sm_object *[]) {
142 &nmi,
143 NULL
144 },
145 };
146 ```