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