xref: /aosp_15_r20/external/coreboot/util/sconfig/sconfig.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* sconfig, coreboot device tree compiler */
2 /* SPDX-License-Identifier: GPL-2.0-only */
3 
4 #include <stdint.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <sys/types.h>
9 #include <unistd.h>
10 #include <errno.h>
11 
12 struct resource;
13 struct resource {
14 	int type;
15 	int index;
16 	int base;
17 	struct resource *next;
18 };
19 
20 struct reg;
21 struct reg {
22 	char *key;
23 	char *value;
24 	struct reg *next;
25 };
26 
27 struct fw_config_option;
28 struct fw_config_option {
29 	const char *name;
30 	uint64_t value;
31 	struct fw_config_option *next;
32 };
33 
34 struct fw_config_field_bits;
35 struct fw_config_field_bits {
36 	unsigned int start_bit;
37 	unsigned int end_bit;
38 	struct fw_config_field_bits *next;
39 };
40 
41 struct fw_config_field;
42 struct fw_config_field {
43 	const char *name;
44 	struct fw_config_field_bits *bits;
45 	struct fw_config_field *next;
46 	struct fw_config_option *options;
47 };
48 struct fw_config_probe;
49 struct fw_config_probe {
50 	const char *field;
51 	const char *option;
52 	struct fw_config_probe *next;
53 };
54 
55 struct identifier {
56 	const char *id;
57 	struct identifier *next;
58 };
59 
60 struct chip;
61 struct chip_instance {
62 	/* Monotonically increasing ID for each chip instance. */
63 	int id;
64 
65 	/* Pointer to registers for this chip. */
66 	struct reg *reg;
67 
68 	/* Pointer to references for this chip. */
69 	struct reg *ref;
70 
71 	/* Pointer to chip of which this is instance. */
72 	struct chip *chip;
73 
74 	/* Pointer to next instance of the same chip. */
75 	struct chip_instance *next;
76 
77 	/*
78 	 * Pointer to corresponding chip instance in base devicetree.
79 	 * a) If the chip instance belongs to the base devicetree, then this pointer is set to
80 	 * NULL.
81 	 * b) If the chip instance belongs to override tree, then this pointer is set to its
82 	 * corresponding chip instance in base devicetree (if it exists), else to NULL.
83 	 *
84 	 * This is useful when generating chip instances and chip_ops for a device to determine
85 	 * if this is the instance to emit or if there is a base chip instance to use instead.
86 	 */
87 	struct chip_instance *base_chip_instance;
88 };
89 
90 struct chip {
91 	/* Indicates if chip header exists for this chip. */
92 	int chiph_exists;
93 
94 	/* Name of current chip. */
95 	char *name;
96 
97 	/* Name of current chip normalized to _. */
98 	char *name_underscore;
99 
100 	/* Pointer to first instance of this chip. */
101 	struct chip_instance *instance;
102 
103 	/* Pointer to next chip. */
104 	struct chip *next;
105 };
106 
107 struct device;
108 struct bus {
109 	/* Pointer to device to which this bus belongs. */
110 	struct device *dev;
111 
112 	/* Pointer to list of children. */
113 	struct device *children;
114 };
115 
116 struct device {
117 	/* Indicates device status (enabled / hidden or not). */
118 	int enabled;
119 	int hidden;
120 	/* non-zero if the device should be included in all cases */
121 	int mandatory;
122 
123 	/* Subsystem IDs for the device. */
124 	int subsystem_vendor;
125 	int subsystem_device;
126 	int inherit_subsystem;
127 
128 	/* Name of this device. */
129 	char *name;
130 
131 	/* Alias of this device (for internal references) */
132 	char *alias;
133 
134 	/* Path of this device. */
135 	char *path;
136 	int path_a;
137 	int path_b;
138 
139 	/* Type of bus that exists under this device. */
140 	int bustype;
141 
142 	/* Pointer to bus of parent on which this device resides. */
143 	struct bus *parent;
144 
145 	/* Pointer to next child under the same parent. */
146 	struct device *sibling;
147 
148 	/* Pointer to resources for this device. */
149 	struct resource *res;
150 
151 	/* Pointer to chip instance for this device. */
152 	struct chip_instance *chip_instance;
153 
154 	/* Pointer to the bus under this device. */
155 	struct bus *bus;
156 
157 	/* Global identifier of the ops for this device. */
158 	char *ops_id;
159 
160 	/* SMBIOS slot type */
161 	char *smbios_slot_type;
162 
163 	/* SMBIOS slot data width */
164 	char *smbios_slot_data_width;
165 
166 	/* SMBIOS slot description for reference designation */
167 	char *smbios_slot_designation;
168 
169 	/* SMBIOS slot length */
170 	char *smbios_slot_length;
171 
172 	/* SMBIOS type41 fields */
173 	int smbios_instance_id_valid;
174 	unsigned int smbios_instance_id;
175 	const char *smbios_refdes;
176 
177 	/* List of field+option to probe. */
178 	struct fw_config_probe *probe;
179 };
180 
181 extern struct bus *root_parent;
182 
183 struct device *new_device_raw(struct bus *parent,
184 			      struct chip_instance *chip_instance,
185 			      const int bustype, const char *devnum,
186 			      char *alias, int status);
187 
188 struct device *new_device_reference(struct bus *parent,
189 				    struct chip_instance *chip_instance,
190 				    const char *reference, int status);
191 
192 void add_resource(struct bus *bus, int type, int index, int base);
193 
194 void add_pci_subsystem_ids(struct bus *bus, int vendor, int device,
195 			   int inherit);
196 
197 void add_slot_desc(struct bus *bus, char *type, char *length, char *designation,
198 		   char *data_width);
199 
200 void add_smbios_dev_info(struct bus *bus, long instance_id, const char *refdes);
201 
202 void yyrestart(FILE *input_file);
203 
204 /* Add chip data to tail of queue. */
205 void chip_enqueue_tail(void *data);
206 
207 /* Retrieve chip data from tail of queue. */
208 void *chip_dequeue_tail(void);
209 
210 struct chip_instance *new_chip_instance(char *path);
211 void add_register(struct chip_instance *chip, char *name, char *val);
212 void add_reference(struct chip_instance *chip, char *name, char *alias);
213 
214 struct fw_config_field *get_fw_config_field(const char *name);
215 
216 void add_fw_config_field_bits(struct fw_config_field *field,
217 			      unsigned int start_bit, unsigned int end_bit);
218 
219 struct fw_config_field *new_fw_config_field(const char *name, struct fw_config_field_bits *bits);
220 
221 void add_fw_config_option(struct fw_config_field *field, const char *name,
222 			  uint64_t value);
223 
224 void add_fw_config_probe(struct bus *bus, const char *field, const char *option);
225 
226 void append_fw_config_bits(struct fw_config_field_bits **bits,
227 			   unsigned int start_bit, unsigned int end_bit);
228 
229 void add_device_ops(struct bus *, char *ops_id);
230