blob: 60842f12a1d66fa396aff7fa3b37d7dacd2f1913 [file] [log] [blame]
Patrick Georgi114e7b22010-05-05 11:19:50 +00001/*
2 * sconfig, coreboot device tree compiler
3 *
4 * Copyright (C) 2010 coresystems GmbH
Stefan Reinauer2e78aa52016-05-07 01:11:14 -07005 * written by Patrick Georgi <patrick@georgi-clan.de>
Patrick Georgi114e7b22010-05-05 11:19:50 +00006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Patrick Georgi114e7b22010-05-05 11:19:50 +000015 */
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include <sys/types.h>
Patrick Georgi114e7b22010-05-05 11:19:50 +000021#include <unistd.h>
22#include <errno.h>
23
Patrick Georgi114e7b22010-05-05 11:19:50 +000024struct resource;
25struct resource {
26 int type;
27 int index;
28 int base;
29 struct resource *next;
30};
31
32struct reg;
33struct reg {
34 char *key;
35 char *value;
36 struct reg *next;
37};
38
Sven Schnelle0fa50a12012-06-21 22:19:48 +020039struct pci_irq_info {
40 int ioapic_irq_pin;
41 int ioapic_dst_id;
42};
Furquan Shaikh79e84122018-05-30 15:09:09 -070043
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070044struct chip;
45struct chip_instance {
Furquan Shaikh79e84122018-05-30 15:09:09 -070046 /*
47 * Monotonically increasing ID for each newly allocated
48 * node(chip/device).
49 */
50 int id;
51
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070052 /* Pointer to registers for this chip. */
53 struct reg *reg;
54
55 /* Pointer to chip of which this is instance. */
56 struct chip *chip;
57
58 /* Pointer to next instance of the same chip. */
59 struct chip_instance *next;
Furquan Shaikh27efc502018-06-22 09:19:15 -070060
61 /*
62 * Reference count - Indicates how many devices hold pointer to this
63 * chip instance.
64 */
65 int ref_count;
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070066};
67
68struct chip {
Furquan Shaikh79e84122018-05-30 15:09:09 -070069 /* Indicates if chip header exists for this chip. */
70 int chiph_exists;
71
72 /* Name of current chip. */
73 char *name;
74
75 /* Name of current chip normalized to _. */
76 char *name_underscore;
77
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -070078 /* Pointer to first instance of this chip. */
79 struct chip_instance *instance;
Furquan Shaikh79e84122018-05-30 15:09:09 -070080
81 /* Pointer to next chip. */
82 struct chip *next;
83};
84
Patrick Georgi114e7b22010-05-05 11:19:50 +000085struct device;
Furquan Shaikh93198262018-06-03 04:22:17 -070086struct bus {
87 /* Instance/ID of the bus under the device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +000088 int id;
Furquan Shaikh93198262018-06-03 04:22:17 -070089
90 /* Pointer to device to which this bus belongs. */
91 struct device *dev;
92
93 /* Pointer to list of children. */
94 struct device *children;
95
96 /* Pointer to next bus for the device. */
97 struct bus *next_bus;
98};
99
100struct device {
101 /* Monotonically increasing ID for the device. */
102 int id;
103
Hung-Te Lin936dbe12018-09-10 10:51:26 +0800104 /* Indicates device status (enabled / hidden or not). */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000105 int enabled;
Hung-Te Lin936dbe12018-09-10 10:51:26 +0800106 int hidden;
Ronald G. Minnich466ca2c2019-10-22 02:02:24 +0000107 /* non-zero if the device should be included in all cases */
108 int mandatory;
Furquan Shaikh93198262018-06-03 04:22:17 -0700109
Furquan Shaikh93198262018-06-03 04:22:17 -0700110 /* Subsystem IDs for the device. */
Sven Schnelle270a9082011-03-01 19:58:15 +0000111 int subsystem_vendor;
112 int subsystem_device;
113 int inherit_subsystem;
Furquan Shaikh93198262018-06-03 04:22:17 -0700114
Furquan Shaikh93198262018-06-03 04:22:17 -0700115 /* Name of this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000116 char *name;
Furquan Shaikh93198262018-06-03 04:22:17 -0700117
118 /* Path of this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000119 char *path;
120 int path_a;
121 int path_b;
Furquan Shaikh93198262018-06-03 04:22:17 -0700122
123 /* Type of bus that exists under this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000124 int bustype;
Furquan Shaikh93198262018-06-03 04:22:17 -0700125
126 /* PCI IRQ info. */
Sven Schnelle0fa50a12012-06-21 22:19:48 +0200127 struct pci_irq_info pci_irq_info[4];
Furquan Shaikh79e84122018-05-30 15:09:09 -0700128
Furquan Shaikh93198262018-06-03 04:22:17 -0700129 /* Pointer to bus of parent on which this device resides. */
130 struct bus *parent;
131
132 /* Pointer to next child under the same parent. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000133 struct device *sibling;
Furquan Shaikh93198262018-06-03 04:22:17 -0700134
135 /* Pointer to resources for this device. */
Patrick Georgi114e7b22010-05-05 11:19:50 +0000136 struct resource *res;
Furquan Shaikh79e84122018-05-30 15:09:09 -0700137
Furquan Shaikh93198262018-06-03 04:22:17 -0700138 /* Pointer to chip instance for this device. */
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700139 struct chip_instance *chip_instance;
Furquan Shaikh93198262018-06-03 04:22:17 -0700140
141 /* Pointer to list of buses under this device. */
142 struct bus *bus;
143 /* Pointer to last bus under this device. */
144 struct bus *last_bus;
Patrick Rudolphac24d3c2019-04-12 14:42:17 +0200145
146 /* SMBIOS slot type */
147 char *smbios_slot_type;
148
149 /* SMBIOS slot data width */
150 char *smbios_slot_data_width;
151
152 /* SMBIOS slot description for reference designation */
153 char *smbios_slot_designation;
154
155 /* SMBIOS slot length */
156 char *smbios_slot_length;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000157};
158
Furquan Shaikh93198262018-06-03 04:22:17 -0700159extern struct bus *root_parent;
Patrick Georgi114e7b22010-05-05 11:19:50 +0000160
Furquan Shaikh93198262018-06-03 04:22:17 -0700161struct device *new_device(struct bus *parent,
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700162 struct chip_instance *chip_instance,
Furquan Shaikha9b64292018-05-31 07:52:00 -0700163 const int bustype, const char *devnum,
Hung-Te Lin936dbe12018-09-10 10:51:26 +0800164 int status);
Furquan Shaikh93198262018-06-03 04:22:17 -0700165
166void add_resource(struct bus *bus, int type, int index, int base);
167
168void add_pci_subsystem_ids(struct bus *bus, int vendor, int device,
Martin Rothbec07532016-08-05 18:32:18 -0600169 int inherit);
Furquan Shaikh93198262018-06-03 04:22:17 -0700170
171void add_ioapic_info(struct bus *bus, int apicid, const char *_srcpin,
Martin Rothbec07532016-08-05 18:32:18 -0600172 int irqpin);
Stefan Reinauer2e78aa52016-05-07 01:11:14 -0700173
Patrick Rudolphac24d3c2019-04-12 14:42:17 +0200174void add_slot_desc(struct bus *bus, char *type, char *length, char *designation,
175 char *data_width);
176
Stefan Reinauer2e78aa52016-05-07 01:11:14 -0700177void yyrestart(FILE *input_file);
Furquan Shaikh79e84122018-05-30 15:09:09 -0700178
179/* Add chip data to tail of queue. */
180void chip_enqueue_tail(void *data);
181
182/* Retrieve chip data from tail of queue. */
183void *chip_dequeue_tail(void);
Furquan Shaikhc56ae2f2018-05-31 10:33:16 -0700184
185struct chip_instance *new_chip_instance(char *path);
186void add_register(struct chip_instance *chip, char *name, char *val);