blob: bb9a98f268b9a2f6dc2ccb13a0ea4dcd7b45293b [file] [log] [blame]
Patrick Georgiea063cb2020-05-08 19:28:13 +02001/* sconfig, coreboot device tree compiler */
Patrick Georgi7333a112020-05-08 20:48:04 +02002/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgi114e7b22010-05-05 11:19:50 +00003
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -06004#include <stdint.h>
Patrick Georgi114e7b22010-05-05 11:19:50 +00005#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8#include <sys/types.h>
Patrick Georgi114e7b22010-05-05 11:19:50 +00009#include <unistd.h>
10#include <errno.h>
11
Patrick Georgi114e7b22010-05-05 11:19:50 +000012struct resource;
13struct resource {
14 int type;
15 int index;
16 int base;
17 struct resource *next;
18};
19
20struct reg;
21struct reg {
22 char *key;
23 char *value;
24 struct reg *next;
25};
26
Duncan Laurie47b7b342020-05-15 15:39:08 -070027struct fw_config_option;
28struct fw_config_option {
29 const char *name;
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -060030 uint64_t value;
Duncan Laurie47b7b342020-05-15 15:39:08 -070031 struct fw_config_option *next;
32};
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -060033
34struct fw_config_field_bits;
35struct fw_config_field_bits {
36 unsigned int start_bit;
37 unsigned int end_bit;
38 struct fw_config_field_bits *next;
39};
40
Duncan Laurie47b7b342020-05-15 15:39:08 -070041struct fw_config_field;
42struct fw_config_field {
43 const char *name;
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -060044 struct fw_config_field_bits *bits;
Duncan Laurie47b7b342020-05-15 15:39:08 -070045 struct fw_config_field *next;
46 struct fw_config_option *options;
47};
48struct fw_config_probe;
49struct fw_config_probe {
50 const char *field;
51 const char *option;
52 struct fw_config_probe *next;
53};
54
Nico Huberc0fc38e2022-08-06 19:02:59 +020055struct identifier {
56 const char *id;
57 struct identifier *next;
58};
59
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070060struct chip;
61struct chip_instance {
Furquan Shaikh4ebe9532020-05-02 15:34:42 -070062 /* Monotonically increasing ID for each chip instance. */
Furquan Shaikh79e84122018-05-30 15:09:09 -070063 int id;
64
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070065 /* Pointer to registers for this chip. */
66 struct reg *reg;
67
Nico Huber8e1ea522020-06-03 10:20:07 -070068 /* Pointer to references for this chip. */
69 struct reg *ref;
70
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070071 /* 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;
Furquan Shaikh27efc502018-06-22 09:19:15 -070076
77 /*
Furquan Shaikhbbade242020-05-02 16:05:29 -070078 * 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.
Furquan Shaikh27efc502018-06-22 09:19:15 -070086 */
Furquan Shaikhbbade242020-05-02 16:05:29 -070087 struct chip_instance *base_chip_instance;
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070088};
89
90struct chip {
Furquan Shaikh79e84122018-05-30 15:09:09 -070091 /* 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
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700100 /* Pointer to first instance of this chip. */
101 struct chip_instance *instance;
Furquan Shaikh79e84122018-05-30 15:09:09 -0700102
103 /* Pointer to next chip. */
104 struct chip *next;
105};
106
Patrick Georgi114e7b22010-05-05 11:19:50 +0000107struct device;
Furquan Shaikh93198262018-06-03 04:22:17 -0700108struct bus {
Furquan Shaikh93198262018-06-03 04:22:17 -0700109 /* Pointer to device to which this bus belongs. */
110 struct device *dev;
111
112 /* Pointer to list of children. */
113 struct device *children;
Furquan Shaikh93198262018-06-03 04:22:17 -0700114};
115
116struct device {
Hung-Te Lin936dbe12018-09-10 10:51:26 +0800117 /* Indicates device status (enabled / hidden or not). */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000118 int enabled;
Hung-Te Lin936dbe12018-09-10 10:51:26 +0800119 int hidden;
Ronald G. Minnich466ca2c2019-10-22 02:02:24 +0000120 /* non-zero if the device should be included in all cases */
121 int mandatory;
Furquan Shaikh93198262018-06-03 04:22:17 -0700122
Furquan Shaikh93198262018-06-03 04:22:17 -0700123 /* Subsystem IDs for the device. */
Sven Schnelle270a9082011-03-01 19:58:15 +0000124 int subsystem_vendor;
125 int subsystem_device;
126 int inherit_subsystem;
Furquan Shaikh93198262018-06-03 04:22:17 -0700127
Furquan Shaikh93198262018-06-03 04:22:17 -0700128 /* Name of this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000129 char *name;
Furquan Shaikh93198262018-06-03 04:22:17 -0700130
Nico Huber8e1ea522020-06-03 10:20:07 -0700131 /* Alias of this device (for internal references) */
132 char *alias;
133
Furquan Shaikh93198262018-06-03 04:22:17 -0700134 /* Path of this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000135 char *path;
136 int path_a;
137 int path_b;
Furquan Shaikh93198262018-06-03 04:22:17 -0700138
139 /* Type of bus that exists under this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000140 int bustype;
Furquan Shaikh93198262018-06-03 04:22:17 -0700141
Furquan Shaikh93198262018-06-03 04:22:17 -0700142 /* Pointer to bus of parent on which this device resides. */
143 struct bus *parent;
144
145 /* Pointer to next child under the same parent. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000146 struct device *sibling;
Furquan Shaikh93198262018-06-03 04:22:17 -0700147
148 /* Pointer to resources for this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000149 struct resource *res;
Furquan Shaikh79e84122018-05-30 15:09:09 -0700150
Furquan Shaikh93198262018-06-03 04:22:17 -0700151 /* Pointer to chip instance for this device. */
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700152 struct chip_instance *chip_instance;
Furquan Shaikh93198262018-06-03 04:22:17 -0700153
Arthur Heymans80c79a52023-08-24 15:12:19 +0200154 /* Pointer to the bus under this device. */
Furquan Shaikh93198262018-06-03 04:22:17 -0700155 struct bus *bus;
Patrick Rudolphac24d3c2019-04-12 14:42:17 +0200156
Nico Huberc0fc38e2022-08-06 19:02:59 +0200157 /* Global identifier of the ops for this device. */
158 char *ops_id;
159
Patrick Rudolphac24d3c2019-04-12 14:42:17 +0200160 /* 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;
Duncan Laurie47b7b342020-05-15 15:39:08 -0700171
Angel Pons437da712021-09-03 16:51:40 +0200172 /* SMBIOS type41 fields */
173 int smbios_instance_id_valid;
174 unsigned int smbios_instance_id;
175 const char *smbios_refdes;
176
Duncan Laurie47b7b342020-05-15 15:39:08 -0700177 /* List of field+option to probe. */
178 struct fw_config_probe *probe;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000179};
180
Furquan Shaikh93198262018-06-03 04:22:17 -0700181extern struct bus *root_parent;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000182
Duncan Lauriee335c2e2020-07-29 16:28:43 -0700183struct 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
188struct device *new_device_reference(struct bus *parent,
189 struct chip_instance *chip_instance,
190 const char *reference, int status);
Furquan Shaikh93198262018-06-03 04:22:17 -0700191
192void add_resource(struct bus *bus, int type, int index, int base);
193
194void add_pci_subsystem_ids(struct bus *bus, int vendor, int device,
Martin Rothbec07532016-08-05 18:32:18 -0600195 int inherit);
Furquan Shaikh93198262018-06-03 04:22:17 -0700196
Patrick Rudolphac24d3c2019-04-12 14:42:17 +0200197void add_slot_desc(struct bus *bus, char *type, char *length, char *designation,
198 char *data_width);
199
Angel Pons437da712021-09-03 16:51:40 +0200200void add_smbios_dev_info(struct bus *bus, long instance_id, const char *refdes);
201
Stefan Reinauer2e78aa52016-05-07 01:11:14 -0700202void yyrestart(FILE *input_file);
Furquan Shaikh79e84122018-05-30 15:09:09 -0700203
204/* Add chip data to tail of queue. */
205void chip_enqueue_tail(void *data);
206
207/* Retrieve chip data from tail of queue. */
208void *chip_dequeue_tail(void);
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700209
210struct chip_instance *new_chip_instance(char *path);
211void add_register(struct chip_instance *chip, char *name, char *val);
Nico Huber8e1ea522020-06-03 10:20:07 -0700212void add_reference(struct chip_instance *chip, char *name, char *alias);
Duncan Laurie47b7b342020-05-15 15:39:08 -0700213
214struct fw_config_field *get_fw_config_field(const char *name);
215
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600216void add_fw_config_field_bits(struct fw_config_field *field,
217 unsigned int start_bit, unsigned int end_bit);
218
219struct fw_config_field *new_fw_config_field(const char *name, struct fw_config_field_bits *bits);
Duncan Laurie47b7b342020-05-15 15:39:08 -0700220
221void add_fw_config_option(struct fw_config_field *field, const char *name,
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -0600222 uint64_t value);
Duncan Laurie47b7b342020-05-15 15:39:08 -0700223
224void add_fw_config_probe(struct bus *bus, const char *field, const char *option);
Tim Wawrzynczak13e240c2021-04-28 14:03:07 -0600225
226void append_fw_config_bits(struct fw_config_field_bits **bits,
227 unsigned int start_bit, unsigned int end_bit);
Nico Huberc0fc38e2022-08-06 19:02:59 +0200228
229void add_device_ops(struct bus *, char *ops_id);