blob: a960b7f05588f74728eef44c5d14f746ef42a4a6 [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
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <sys/types.h>
Patrick Georgi114e7b22010-05-05 11:19:50 +00008#include <unistd.h>
9#include <errno.h>
10
Patrick Georgi114e7b22010-05-05 11:19:50 +000011struct resource;
12struct resource {
13 int type;
14 int index;
15 int base;
16 struct resource *next;
17};
18
19struct reg;
20struct reg {
21 char *key;
22 char *value;
23 struct reg *next;
24};
25
Sven Schnelle0fa50a12012-06-21 22:19:48 +020026struct pci_irq_info {
27 int ioapic_irq_pin;
28 int ioapic_dst_id;
29};
Furquan Shaikh79e84122018-05-30 15:09:09 -070030
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070031struct chip;
32struct chip_instance {
Furquan Shaikh4ebe9532020-05-02 15:34:42 -070033 /* Monotonically increasing ID for each chip instance. */
Furquan Shaikh79e84122018-05-30 15:09:09 -070034 int id;
35
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070036 /* Pointer to registers for this chip. */
37 struct reg *reg;
38
39 /* Pointer to chip of which this is instance. */
40 struct chip *chip;
41
42 /* Pointer to next instance of the same chip. */
43 struct chip_instance *next;
Furquan Shaikh27efc502018-06-22 09:19:15 -070044
45 /*
Furquan Shaikhbbade242020-05-02 16:05:29 -070046 * Pointer to corresponding chip instance in base devicetree.
47 * a) If the chip instance belongs to the base devicetree, then this pointer is set to
48 * NULL.
49 * b) If the chip instance belongs to override tree, then this pointer is set to its
50 * corresponding chip instance in base devicetree (if it exists), else to NULL.
51 *
52 * This is useful when generating chip instances and chip_ops for a device to determine
53 * 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 -070054 */
Furquan Shaikhbbade242020-05-02 16:05:29 -070055 struct chip_instance *base_chip_instance;
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070056};
57
58struct chip {
Furquan Shaikh79e84122018-05-30 15:09:09 -070059 /* Indicates if chip header exists for this chip. */
60 int chiph_exists;
61
62 /* Name of current chip. */
63 char *name;
64
65 /* Name of current chip normalized to _. */
66 char *name_underscore;
67
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070068 /* Pointer to first instance of this chip. */
69 struct chip_instance *instance;
Furquan Shaikh79e84122018-05-30 15:09:09 -070070
71 /* Pointer to next chip. */
72 struct chip *next;
73};
74
Patrick Georgi114e7b22010-05-05 11:19:50 +000075struct device;
Furquan Shaikh93198262018-06-03 04:22:17 -070076struct bus {
77 /* Instance/ID of the bus under the device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +000078 int id;
Furquan Shaikh93198262018-06-03 04:22:17 -070079
80 /* Pointer to device to which this bus belongs. */
81 struct device *dev;
82
83 /* Pointer to list of children. */
84 struct device *children;
85
86 /* Pointer to next bus for the device. */
87 struct bus *next_bus;
88};
89
90struct device {
Hung-Te Lin936dbe12018-09-10 10:51:26 +080091 /* Indicates device status (enabled / hidden or not). */
Patrick Georgi114e7b22010-05-05 11:19:50 +000092 int enabled;
Hung-Te Lin936dbe12018-09-10 10:51:26 +080093 int hidden;
Ronald G. Minnich466ca2c2019-10-22 02:02:24 +000094 /* non-zero if the device should be included in all cases */
95 int mandatory;
Furquan Shaikh93198262018-06-03 04:22:17 -070096
Furquan Shaikh93198262018-06-03 04:22:17 -070097 /* Subsystem IDs for the device. */
Sven Schnelle270a9082011-03-01 19:58:15 +000098 int subsystem_vendor;
99 int subsystem_device;
100 int inherit_subsystem;
Furquan Shaikh93198262018-06-03 04:22:17 -0700101
Furquan Shaikh93198262018-06-03 04:22:17 -0700102 /* Name of this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000103 char *name;
Furquan Shaikh93198262018-06-03 04:22:17 -0700104
105 /* Path of this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000106 char *path;
107 int path_a;
108 int path_b;
Furquan Shaikh93198262018-06-03 04:22:17 -0700109
110 /* Type of bus that exists under this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000111 int bustype;
Furquan Shaikh93198262018-06-03 04:22:17 -0700112
113 /* PCI IRQ info. */
Sven Schnelle0fa50a12012-06-21 22:19:48 +0200114 struct pci_irq_info pci_irq_info[4];
Furquan Shaikh79e84122018-05-30 15:09:09 -0700115
Furquan Shaikh93198262018-06-03 04:22:17 -0700116 /* Pointer to bus of parent on which this device resides. */
117 struct bus *parent;
118
119 /* Pointer to next child under the same parent. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000120 struct device *sibling;
Furquan Shaikh93198262018-06-03 04:22:17 -0700121
122 /* Pointer to resources for this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000123 struct resource *res;
Furquan Shaikh79e84122018-05-30 15:09:09 -0700124
Furquan Shaikh93198262018-06-03 04:22:17 -0700125 /* Pointer to chip instance for this device. */
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700126 struct chip_instance *chip_instance;
Furquan Shaikh93198262018-06-03 04:22:17 -0700127
128 /* Pointer to list of buses under this device. */
129 struct bus *bus;
130 /* Pointer to last bus under this device. */
131 struct bus *last_bus;
Patrick Rudolphac24d3c2019-04-12 14:42:17 +0200132
133 /* SMBIOS slot type */
134 char *smbios_slot_type;
135
136 /* SMBIOS slot data width */
137 char *smbios_slot_data_width;
138
139 /* SMBIOS slot description for reference designation */
140 char *smbios_slot_designation;
141
142 /* SMBIOS slot length */
143 char *smbios_slot_length;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000144};
145
Furquan Shaikh93198262018-06-03 04:22:17 -0700146extern struct bus *root_parent;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000147
Furquan Shaikh93198262018-06-03 04:22:17 -0700148struct device *new_device(struct bus *parent,
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700149 struct chip_instance *chip_instance,
Furquan Shaikha9b64292018-05-31 07:52:00 -0700150 const int bustype, const char *devnum,
Hung-Te Lin936dbe12018-09-10 10:51:26 +0800151 int status);
Furquan Shaikh93198262018-06-03 04:22:17 -0700152
153void add_resource(struct bus *bus, int type, int index, int base);
154
155void add_pci_subsystem_ids(struct bus *bus, int vendor, int device,
Martin Rothbec07532016-08-05 18:32:18 -0600156 int inherit);
Furquan Shaikh93198262018-06-03 04:22:17 -0700157
158void add_ioapic_info(struct bus *bus, int apicid, const char *_srcpin,
Martin Rothbec07532016-08-05 18:32:18 -0600159 int irqpin);
Stefan Reinauer2e78aa52016-05-07 01:11:14 -0700160
Patrick Rudolphac24d3c2019-04-12 14:42:17 +0200161void add_slot_desc(struct bus *bus, char *type, char *length, char *designation,
162 char *data_width);
163
Stefan Reinauer2e78aa52016-05-07 01:11:14 -0700164void yyrestart(FILE *input_file);
Furquan Shaikh79e84122018-05-30 15:09:09 -0700165
166/* Add chip data to tail of queue. */
167void chip_enqueue_tail(void *data);
168
169/* Retrieve chip data from tail of queue. */
170void *chip_dequeue_tail(void);
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700171
172struct chip_instance *new_chip_instance(char *path);
173void add_register(struct chip_instance *chip, char *name, char *val);