blob: 0db1ce59c997417418d37298139fb98ef9f7cd9d [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
Sven Schnelle0fa50a12012-06-21 22:19:48 +020027struct pci_irq_info {
28 int ioapic_irq_pin;
29 int ioapic_dst_id;
30};
Furquan Shaikh79e84122018-05-30 15:09:09 -070031
Duncan Laurie47b7b342020-05-15 15:39:08 -070032struct fw_config_option;
33struct fw_config_option {
34 const char *name;
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -060035 uint64_t value;
Duncan Laurie47b7b342020-05-15 15:39:08 -070036 struct fw_config_option *next;
37};
38struct fw_config_field;
39struct fw_config_field {
40 const char *name;
41 unsigned int start_bit;
42 unsigned int end_bit;
43 struct fw_config_field *next;
44 struct fw_config_option *options;
45};
46struct fw_config_probe;
47struct fw_config_probe {
48 const char *field;
49 const char *option;
50 struct fw_config_probe *next;
51};
52
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070053struct chip;
54struct chip_instance {
Furquan Shaikh4ebe9532020-05-02 15:34:42 -070055 /* Monotonically increasing ID for each chip instance. */
Furquan Shaikh79e84122018-05-30 15:09:09 -070056 int id;
57
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070058 /* Pointer to registers for this chip. */
59 struct reg *reg;
60
Nico Huber8e1ea522020-06-03 10:20:07 -070061 /* Pointer to references for this chip. */
62 struct reg *ref;
63
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070064 /* Pointer to chip of which this is instance. */
65 struct chip *chip;
66
67 /* Pointer to next instance of the same chip. */
68 struct chip_instance *next;
Furquan Shaikh27efc502018-06-22 09:19:15 -070069
70 /*
Furquan Shaikhbbade242020-05-02 16:05:29 -070071 * Pointer to corresponding chip instance in base devicetree.
72 * a) If the chip instance belongs to the base devicetree, then this pointer is set to
73 * NULL.
74 * b) If the chip instance belongs to override tree, then this pointer is set to its
75 * corresponding chip instance in base devicetree (if it exists), else to NULL.
76 *
77 * This is useful when generating chip instances and chip_ops for a device to determine
78 * 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 -070079 */
Furquan Shaikhbbade242020-05-02 16:05:29 -070080 struct chip_instance *base_chip_instance;
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070081};
82
83struct chip {
Furquan Shaikh79e84122018-05-30 15:09:09 -070084 /* Indicates if chip header exists for this chip. */
85 int chiph_exists;
86
87 /* Name of current chip. */
88 char *name;
89
90 /* Name of current chip normalized to _. */
91 char *name_underscore;
92
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070093 /* Pointer to first instance of this chip. */
94 struct chip_instance *instance;
Furquan Shaikh79e84122018-05-30 15:09:09 -070095
96 /* Pointer to next chip. */
97 struct chip *next;
98};
99
Patrick Georgi114e7b22010-05-05 11:19:50 +0000100struct device;
Furquan Shaikh93198262018-06-03 04:22:17 -0700101struct bus {
102 /* Instance/ID of the bus under the device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000103 int id;
Furquan Shaikh93198262018-06-03 04:22:17 -0700104
105 /* Pointer to device to which this bus belongs. */
106 struct device *dev;
107
108 /* Pointer to list of children. */
109 struct device *children;
110
111 /* Pointer to next bus for the device. */
112 struct bus *next_bus;
113};
114
115struct device {
Hung-Te Lin936dbe12018-09-10 10:51:26 +0800116 /* Indicates device status (enabled / hidden or not). */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000117 int enabled;
Hung-Te Lin936dbe12018-09-10 10:51:26 +0800118 int hidden;
Ronald G. Minnich466ca2c2019-10-22 02:02:24 +0000119 /* non-zero if the device should be included in all cases */
120 int mandatory;
Furquan Shaikh93198262018-06-03 04:22:17 -0700121
Furquan Shaikh93198262018-06-03 04:22:17 -0700122 /* Subsystem IDs for the device. */
Sven Schnelle270a9082011-03-01 19:58:15 +0000123 int subsystem_vendor;
124 int subsystem_device;
125 int inherit_subsystem;
Furquan Shaikh93198262018-06-03 04:22:17 -0700126
Furquan Shaikh93198262018-06-03 04:22:17 -0700127 /* Name of this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000128 char *name;
Furquan Shaikh93198262018-06-03 04:22:17 -0700129
Nico Huber8e1ea522020-06-03 10:20:07 -0700130 /* Alias of this device (for internal references) */
131 char *alias;
132
Furquan Shaikh93198262018-06-03 04:22:17 -0700133 /* Path of this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000134 char *path;
135 int path_a;
136 int path_b;
Furquan Shaikh93198262018-06-03 04:22:17 -0700137
138 /* Type of bus that exists under this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000139 int bustype;
Furquan Shaikh93198262018-06-03 04:22:17 -0700140
141 /* PCI IRQ info. */
Sven Schnelle0fa50a12012-06-21 22:19:48 +0200142 struct pci_irq_info pci_irq_info[4];
Furquan Shaikh79e84122018-05-30 15:09:09 -0700143
Furquan Shaikh93198262018-06-03 04:22:17 -0700144 /* Pointer to bus of parent on which this device resides. */
145 struct bus *parent;
146
147 /* Pointer to next child under the same parent. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000148 struct device *sibling;
Furquan Shaikh93198262018-06-03 04:22:17 -0700149
150 /* Pointer to resources for this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000151 struct resource *res;
Furquan Shaikh79e84122018-05-30 15:09:09 -0700152
Furquan Shaikh93198262018-06-03 04:22:17 -0700153 /* Pointer to chip instance for this device. */
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700154 struct chip_instance *chip_instance;
Furquan Shaikh93198262018-06-03 04:22:17 -0700155
156 /* Pointer to list of buses under this device. */
157 struct bus *bus;
158 /* Pointer to last bus under this device. */
159 struct bus *last_bus;
Patrick Rudolphac24d3c2019-04-12 14:42:17 +0200160
161 /* SMBIOS slot type */
162 char *smbios_slot_type;
163
164 /* SMBIOS slot data width */
165 char *smbios_slot_data_width;
166
167 /* SMBIOS slot description for reference designation */
168 char *smbios_slot_designation;
169
170 /* SMBIOS slot length */
171 char *smbios_slot_length;
Duncan Laurie47b7b342020-05-15 15:39:08 -0700172
173 /* List of field+option to probe. */
174 struct fw_config_probe *probe;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000175};
176
Furquan Shaikh93198262018-06-03 04:22:17 -0700177extern struct bus *root_parent;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000178
Duncan Lauriee335c2e2020-07-29 16:28:43 -0700179struct device *new_device_raw(struct bus *parent,
180 struct chip_instance *chip_instance,
181 const int bustype, const char *devnum,
182 char *alias, int status);
183
184struct device *new_device_reference(struct bus *parent,
185 struct chip_instance *chip_instance,
186 const char *reference, int status);
Furquan Shaikh93198262018-06-03 04:22:17 -0700187
188void add_resource(struct bus *bus, int type, int index, int base);
189
190void add_pci_subsystem_ids(struct bus *bus, int vendor, int device,
Martin Rothbec07532016-08-05 18:32:18 -0600191 int inherit);
Furquan Shaikh93198262018-06-03 04:22:17 -0700192
193void add_ioapic_info(struct bus *bus, int apicid, const char *_srcpin,
Martin Rothbec07532016-08-05 18:32:18 -0600194 int irqpin);
Stefan Reinauer2e78aa52016-05-07 01:11:14 -0700195
Patrick Rudolphac24d3c2019-04-12 14:42:17 +0200196void add_slot_desc(struct bus *bus, char *type, char *length, char *designation,
197 char *data_width);
198
Stefan Reinauer2e78aa52016-05-07 01:11:14 -0700199void yyrestart(FILE *input_file);
Furquan Shaikh79e84122018-05-30 15:09:09 -0700200
201/* Add chip data to tail of queue. */
202void chip_enqueue_tail(void *data);
203
204/* Retrieve chip data from tail of queue. */
205void *chip_dequeue_tail(void);
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700206
207struct chip_instance *new_chip_instance(char *path);
208void add_register(struct chip_instance *chip, char *name, char *val);
Nico Huber8e1ea522020-06-03 10:20:07 -0700209void add_reference(struct chip_instance *chip, char *name, char *alias);
Duncan Laurie47b7b342020-05-15 15:39:08 -0700210
211struct fw_config_field *get_fw_config_field(const char *name);
212
213struct fw_config_field *new_fw_config_field(const char *name,
214 unsigned int start_bit, unsigned int end_bit);
215
216void add_fw_config_option(struct fw_config_field *field, const char *name,
Tim Wawrzynczak24b4af62020-10-01 15:41:31 -0600217 uint64_t value);
Duncan Laurie47b7b342020-05-15 15:39:08 -0700218
219void add_fw_config_probe(struct bus *bus, const char *field, const char *option);