blob: b8a231a1c220e2159687e6c85fe6611c923333f8 [file] [log] [blame]
Patrick Georgi114e7b22010-05-05 11:19:50 +00001/*
2 * sconfig, coreboot device tree compiler
3 *
4 * Copyright (C) 2010 coresystems GmbH
5 * written by Patrick Georgi <patrick.georgi@coresystems.de>
6 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
19 */
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <unistd.h>
27#include <errno.h>
28
29enum devtype { chip, device };
30
31struct resource;
32struct resource {
33 int type;
34 int index;
35 int base;
36 struct resource *next;
37};
38
39struct reg;
40struct reg {
41 char *key;
42 char *value;
43 struct reg *next;
44};
45
Sven Schnelle0fa50a12012-06-21 22:19:48 +020046struct pci_irq_info {
47 int ioapic_irq_pin;
48 int ioapic_dst_id;
49};
Patrick Georgi114e7b22010-05-05 11:19:50 +000050struct device;
51struct device {
52 int id;
53 int enabled;
54 int used;
55 int multidev;
56 int link;
57 int rescnt;
58 int chiph_exists;
Sven Schnelle270a9082011-03-01 19:58:15 +000059 int subsystem_vendor;
60 int subsystem_device;
61 int inherit_subsystem;
Patrick Georgi114e7b22010-05-05 11:19:50 +000062 char *ops;
63 char *name;
Patrick Georgi114e7b22010-05-05 11:19:50 +000064 char *name_underscore;
65 char *path;
66 int path_a;
67 int path_b;
68 int bustype;
Sven Schnelle0fa50a12012-06-21 22:19:48 +020069 struct pci_irq_info pci_irq_info[4];
Patrick Georgi114e7b22010-05-05 11:19:50 +000070 enum devtype type;
71 struct device *parent;
72 struct device *bus;
73 struct device *next;
74 struct device *nextdev;
75 struct device *children;
76 struct device *latestchild;
77 struct device *next_sibling;
78 struct device *sibling;
79 struct device *chip;
80 struct resource *res;
81 struct reg *reg;
82};
83
Patrick Georgi68befd52010-05-05 12:05:25 +000084struct device *head;
Patrick Georgi114e7b22010-05-05 11:19:50 +000085
86struct header;
87struct header {
88 char *name;
Kyösti Mälkkiaada2e12012-10-07 15:08:32 +020089 int chiph_exists;
Patrick Georgi114e7b22010-05-05 11:19:50 +000090 struct header *next;
91};
92
93void fold_in(struct device *parent);
94
95void postprocess_devtree(void);
Patrick Georgi68befd52010-05-05 12:05:25 +000096struct device *new_chip(struct device *parent, struct device *bus, char *path);
Patrick Georgi114e7b22010-05-05 11:19:50 +000097void add_header(struct device *dev);
Patrick Georgi68befd52010-05-05 12:05:25 +000098struct device *new_device(struct device *parent, struct device *busdev, const int bus, const char *devnum, int enabled);
Patrick Georgi114e7b22010-05-05 11:19:50 +000099void alias_siblings(struct device *d);
Patrick Georgi68befd52010-05-05 12:05:25 +0000100void add_resource(struct device *dev, int type, int index, int base);
101void add_register(struct device *dev, char *name, char *val);
Sven Schnelle270a9082011-03-01 19:58:15 +0000102void add_pci_subsystem_ids(struct device *dev, int vendor, int device, int inherit);