sconfig: Reformat C code
Change-Id: Idfd1bd8240413026b992ae1382a57bccf9d8ddb5 Signed-off-by: Martin Roth <martinroth@google.com> Reviewed-on: https://review.coreboot.org/16082 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
parent
c9c27bb14e
commit
bec07535ac
|
@ -57,7 +57,8 @@ static struct device root = {
|
||||||
.enabled = 1
|
.enabled = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct device *new_dev(struct device *parent, struct device *bus) {
|
static struct device *new_dev(struct device *parent, struct device *bus)
|
||||||
|
{
|
||||||
struct device *dev = malloc(sizeof(struct device));
|
struct device *dev = malloc(sizeof(struct device));
|
||||||
memset(dev, 0, sizeof(struct device));
|
memset(dev, 0, sizeof(struct device));
|
||||||
dev->id = ++devcount;
|
dev->id = ++devcount;
|
||||||
|
@ -70,18 +71,22 @@ static struct device *new_dev(struct device *parent, struct device *bus) {
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int device_match(struct device *a, struct device *b) {
|
static int device_match(struct device *a, struct device *b)
|
||||||
if ((a->bustype == b->bustype) && (a->bus == b->bus) && (a->path_a == b->path_a) && (a->path_b == b->path_b))
|
{
|
||||||
|
if ((a->bustype == b->bustype) && (a->bus == b->bus)
|
||||||
|
&& (a->path_a == b->path_a) && (a->path_b == b->path_b))
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fold_in(struct device *parent) {
|
void fold_in(struct device *parent)
|
||||||
|
{
|
||||||
struct device *child = parent->children;
|
struct device *child = parent->children;
|
||||||
struct device *latest = 0;
|
struct device *latest = 0;
|
||||||
while (child != latest) {
|
while (child != latest) {
|
||||||
if (child->children) {
|
if (child->children) {
|
||||||
if (!latest) latest = child->children;
|
if (!latest)
|
||||||
|
latest = child->children;
|
||||||
parent->latestchild->next_sibling = child->children;
|
parent->latestchild->next_sibling = child->children;
|
||||||
parent->latestchild = child->latestchild;
|
parent->latestchild = child->latestchild;
|
||||||
}
|
}
|
||||||
|
@ -89,38 +94,45 @@ void fold_in(struct device *parent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int yywrap(void) {
|
int yywrap(void)
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void yyerror (char const *str)
|
void yyerror(char const *str)
|
||||||
{
|
{
|
||||||
extern char *yytext;
|
extern char *yytext;
|
||||||
fprintf (stderr, "line %d: %s: %s\n", linenum + 1, yytext, str);
|
fprintf(stderr, "line %d: %s: %s\n", linenum + 1, yytext, str);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void postprocess_devtree(void) {
|
void postprocess_devtree(void)
|
||||||
|
{
|
||||||
root.next_sibling = root.children;
|
root.next_sibling = root.children;
|
||||||
root.next_sibling->next_sibling = root.next_sibling->children;
|
root.next_sibling->next_sibling = root.next_sibling->children;
|
||||||
|
|
||||||
struct device *dev = &root;
|
struct device *dev = &root;
|
||||||
while (dev) {
|
while (dev) {
|
||||||
/* skip "chip" elements in children chain */
|
/* skip "chip" elements in children chain */
|
||||||
while (dev->children && (dev->children->type == chip)) dev->children = dev->children->children;
|
while (dev->children && (dev->children->type == chip))
|
||||||
|
dev->children = dev->children->children;
|
||||||
/* skip "chip" elements and functions of the same device in sibling chain */
|
/* skip "chip" elements and functions of the same device in sibling chain */
|
||||||
while (dev->sibling && dev->sibling->used) dev->sibling = dev->sibling->sibling;
|
while (dev->sibling && dev->sibling->used)
|
||||||
|
dev->sibling = dev->sibling->sibling;
|
||||||
/* If end of chain, and parent is a chip, move on */
|
/* If end of chain, and parent is a chip, move on */
|
||||||
if (!dev->sibling && (dev->parent->type == chip)) dev->sibling = dev->parent->sibling;
|
if (!dev->sibling && (dev->parent->type == chip))
|
||||||
|
dev->sibling = dev->parent->sibling;
|
||||||
/* skip chips */
|
/* skip chips */
|
||||||
while (dev->sibling && dev->sibling->type == chip) dev->sibling = dev->sibling->children;
|
while (dev->sibling && dev->sibling->type == chip)
|
||||||
|
dev->sibling = dev->sibling->children;
|
||||||
/* skip duplicate function elements in nextdev chain */
|
/* skip duplicate function elements in nextdev chain */
|
||||||
while (dev->nextdev && dev->nextdev->used) dev->nextdev = dev->nextdev->nextdev;
|
while (dev->nextdev && dev->nextdev->used)
|
||||||
|
dev->nextdev = dev->nextdev->nextdev;
|
||||||
dev = dev->next_sibling;
|
dev = dev->next_sibling;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char * translate_name(const char *str, translate_t mode)
|
char *translate_name(const char *str, translate_t mode)
|
||||||
{
|
{
|
||||||
char *b, *c;
|
char *b, *c;
|
||||||
b = c = strdup(str);
|
b = c = strdup(str);
|
||||||
|
@ -129,8 +141,10 @@ char * translate_name(const char *str, translate_t mode)
|
||||||
*c = 0;
|
*c = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*c == '/') *c = '_';
|
if (*c == '/')
|
||||||
if (*c == '-') *c = '_';
|
*c = '_';
|
||||||
|
if (*c == '-')
|
||||||
|
*c = '_';
|
||||||
if (mode == TO_UPPER)
|
if (mode == TO_UPPER)
|
||||||
*c = toupper(*c);
|
*c = toupper(*c);
|
||||||
if (mode == TO_LOWER)
|
if (mode == TO_LOWER)
|
||||||
|
@ -140,7 +154,8 @@ char * translate_name(const char *str, translate_t mode)
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct device *new_chip(struct device *parent, struct device *bus, char *path) {
|
struct device *new_chip(struct device *parent, struct device *bus, char *path)
|
||||||
|
{
|
||||||
struct device *new_chip = new_dev(parent, bus);
|
struct device *new_chip = new_dev(parent, bus);
|
||||||
new_chip->chiph_exists = 1;
|
new_chip->chiph_exists = 1;
|
||||||
new_chip->name = path;
|
new_chip->name = path;
|
||||||
|
@ -149,7 +164,7 @@ struct device *new_chip(struct device *parent, struct device *bus, char *path) {
|
||||||
new_chip->chip = new_chip;
|
new_chip->chip = new_chip;
|
||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *chip_h = malloc(strlen(path)+18);
|
char *chip_h = malloc(strlen(path) + 18);
|
||||||
sprintf(chip_h, "src/%s", path);
|
sprintf(chip_h, "src/%s", path);
|
||||||
if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) {
|
if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) {
|
||||||
/* root_complex gets away without a separate directory, but
|
/* root_complex gets away without a separate directory, but
|
||||||
|
@ -165,7 +180,7 @@ struct device *new_chip(struct device *parent, struct device *bus, char *path) {
|
||||||
sprintf(chip_h, "src/%s/chip.h", path);
|
sprintf(chip_h, "src/%s/chip.h", path);
|
||||||
|
|
||||||
if ((stat(chip_h, &st) == -1) && (errno == ENOENT))
|
if ((stat(chip_h, &st) == -1) && (errno == ENOENT))
|
||||||
new_chip->chiph_exists = 0;
|
new_chip->chiph_exists = 0;
|
||||||
|
|
||||||
if (parent->latestchild) {
|
if (parent->latestchild) {
|
||||||
parent->latestchild->next_sibling = new_chip;
|
parent->latestchild->next_sibling = new_chip;
|
||||||
|
@ -178,7 +193,8 @@ struct device *new_chip(struct device *parent, struct device *bus, char *path) {
|
||||||
return new_chip;
|
return new_chip;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_header(struct device *dev) {
|
void add_header(struct device *dev)
|
||||||
|
{
|
||||||
int include_exists = 0;
|
int include_exists = 0;
|
||||||
struct header *h = &headers;
|
struct header *h = &headers;
|
||||||
while (h->next) {
|
while (h->next) {
|
||||||
|
@ -187,7 +203,8 @@ void add_header(struct device *dev) {
|
||||||
include_exists = 1;
|
include_exists = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (result < 0) break;
|
if (result < 0)
|
||||||
|
break;
|
||||||
h = h->next;
|
h = h->next;
|
||||||
}
|
}
|
||||||
if (!include_exists) {
|
if (!include_exists) {
|
||||||
|
@ -200,7 +217,9 @@ void add_header(struct device *dev) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct device *new_device(struct device *parent, struct device *busdev, const int bus, const char *devnum, int enabled) {
|
struct device *new_device(struct device *parent, struct device *busdev,
|
||||||
|
const int bus, const char *devnum, int enabled)
|
||||||
|
{
|
||||||
struct device *new_d = new_dev(parent, busdev);
|
struct device *new_d = new_dev(parent, busdev);
|
||||||
new_d->bustype = bus;
|
new_d->bustype = bus;
|
||||||
|
|
||||||
|
@ -214,7 +233,7 @@ struct device *new_device(struct device *parent, struct device *busdev, const in
|
||||||
char *name = malloc(10);
|
char *name = malloc(10);
|
||||||
sprintf(name, "_dev%d", new_d->id);
|
sprintf(name, "_dev%d", new_d->id);
|
||||||
new_d->name = name;
|
new_d->name = name;
|
||||||
new_d->name_underscore = name; // shouldn't be necessary, but avoid 0-ptr
|
new_d->name_underscore = name; // shouldn't be necessary, but avoid 0-ptr
|
||||||
new_d->type = device;
|
new_d->type = device;
|
||||||
new_d->enabled = enabled;
|
new_d->enabled = enabled;
|
||||||
new_d->chip = new_d->parent->chip;
|
new_d->chip = new_d->parent->chip;
|
||||||
|
@ -230,7 +249,7 @@ struct device *new_device(struct device *parent, struct device *busdev, const in
|
||||||
lastdev->nextdev = new_d;
|
lastdev->nextdev = new_d;
|
||||||
lastdev = new_d;
|
lastdev = new_d;
|
||||||
|
|
||||||
switch(bus) {
|
switch (bus) {
|
||||||
case PCI:
|
case PCI:
|
||||||
new_d->path = ".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}";
|
new_d->path = ".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}";
|
||||||
break;
|
break;
|
||||||
|
@ -270,12 +289,14 @@ struct device *new_device(struct device *parent, struct device *busdev, const in
|
||||||
return new_d;
|
return new_d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void alias_siblings(struct device *d) {
|
void alias_siblings(struct device *d)
|
||||||
|
{
|
||||||
while (d) {
|
while (d) {
|
||||||
int link = 0;
|
int link = 0;
|
||||||
struct device *cmp = d->next_sibling;
|
struct device *cmp = d->next_sibling;
|
||||||
while (cmp && (cmp->bus == d->bus) && (cmp->path_a == d->path_a) && (cmp->path_b == d->path_b)) {
|
while (cmp && (cmp->bus == d->bus) && (cmp->path_a == d->path_a)
|
||||||
if (cmp->type==device && !cmp->used) {
|
&& (cmp->path_b == d->path_b)) {
|
||||||
|
if (cmp->type == device && !cmp->used) {
|
||||||
if (device_match(d, cmp)) {
|
if (device_match(d, cmp)) {
|
||||||
d->multidev = 1;
|
d->multidev = 1;
|
||||||
|
|
||||||
|
@ -291,15 +312,17 @@ void alias_siblings(struct device *d) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_resource(struct device *dev, int type, int index, int base) {
|
void add_resource(struct device *dev, int type, int index, int base)
|
||||||
|
{
|
||||||
struct resource *r = malloc(sizeof(struct resource));
|
struct resource *r = malloc(sizeof(struct resource));
|
||||||
memset (r, 0, sizeof(struct resource));
|
memset(r, 0, sizeof(struct resource));
|
||||||
r->type = type;
|
r->type = type;
|
||||||
r->index = index;
|
r->index = index;
|
||||||
r->base = base;
|
r->base = base;
|
||||||
if (dev->res) {
|
if (dev->res) {
|
||||||
struct resource *head = dev->res;
|
struct resource *head = dev->res;
|
||||||
while (head->next) head = head->next;
|
while (head->next)
|
||||||
|
head = head->next;
|
||||||
head->next = r;
|
head->next = r;
|
||||||
} else {
|
} else {
|
||||||
dev->res = r;
|
dev->res = r;
|
||||||
|
@ -307,9 +330,10 @@ void add_resource(struct device *dev, int type, int index, int base) {
|
||||||
dev->rescnt++;
|
dev->rescnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_register(struct device *dev, char *name, char *val) {
|
void add_register(struct device *dev, char *name, char *val)
|
||||||
|
{
|
||||||
struct reg *r = malloc(sizeof(struct reg));
|
struct reg *r = malloc(sizeof(struct reg));
|
||||||
memset (r, 0, sizeof(struct reg));
|
memset(r, 0, sizeof(struct reg));
|
||||||
r->key = name;
|
r->key = name;
|
||||||
r->value = val;
|
r->value = val;
|
||||||
if (dev->reg) {
|
if (dev->reg) {
|
||||||
|
@ -320,11 +344,13 @@ void add_register(struct device *dev, char *name, char *val) {
|
||||||
printf("ERROR: duplicate 'register' key.\n");
|
printf("ERROR: duplicate 'register' key.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (sort<0) {
|
if (sort < 0) {
|
||||||
r->next = head;
|
r->next = head;
|
||||||
dev->reg = r;
|
dev->reg = r;
|
||||||
} else {
|
} else {
|
||||||
while ((head->next) && (strcmp(head->next->key, r->key)<0)) head = head->next;
|
while ((head->next)
|
||||||
|
&& (strcmp(head->next->key, r->key) < 0))
|
||||||
|
head = head->next;
|
||||||
r->next = head->next;
|
r->next = head->next;
|
||||||
head->next = r;
|
head->next = r;
|
||||||
}
|
}
|
||||||
|
@ -333,7 +359,8 @@ void add_register(struct device *dev, char *name, char *val) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_pci_subsystem_ids(struct device *dev, int vendor, int device, int inherit)
|
void add_pci_subsystem_ids(struct device *dev, int vendor, int device,
|
||||||
|
int inherit)
|
||||||
{
|
{
|
||||||
if (dev->bustype != PCI && dev->bustype != DOMAIN) {
|
if (dev->bustype != PCI && dev->bustype != DOMAIN) {
|
||||||
printf("ERROR: 'subsystem' only allowed for PCI devices\n");
|
printf("ERROR: 'subsystem' only allowed for PCI devices\n");
|
||||||
|
@ -345,13 +372,14 @@ void add_pci_subsystem_ids(struct device *dev, int vendor, int device, int inher
|
||||||
dev->inherit_subsystem = inherit;
|
dev->inherit_subsystem = inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_ioapic_info(struct device *dev, int apicid, const char *_srcpin, int irqpin)
|
void add_ioapic_info(struct device *dev, int apicid, const char *_srcpin,
|
||||||
|
int irqpin)
|
||||||
{
|
{
|
||||||
|
|
||||||
int srcpin;
|
int srcpin;
|
||||||
|
|
||||||
if (!_srcpin || strlen(_srcpin) < 4 ||strncasecmp(_srcpin, "INT", 3) ||
|
if (!_srcpin || strlen(_srcpin) < 4 || strncasecmp(_srcpin, "INT", 3) ||
|
||||||
_srcpin[3] < 'A' || _srcpin[3] > 'D') {
|
_srcpin[3] < 'A' || _srcpin[3] > 'D') {
|
||||||
printf("ERROR: malformed ioapic_irq args: %s\n", _srcpin);
|
printf("ERROR: malformed ioapic_irq args: %s\n", _srcpin);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -371,104 +399,136 @@ void add_ioapic_info(struct device *dev, int apicid, const char *_srcpin, int ir
|
||||||
dev->pci_irq_info[srcpin].ioapic_dst_id = apicid;
|
dev->pci_irq_info[srcpin].ioapic_dst_id = apicid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pass0(FILE *fil, struct device *ptr) {
|
static void pass0(FILE * fil, struct device *ptr)
|
||||||
|
{
|
||||||
if (ptr->type == device && ptr->id == 0)
|
if (ptr->type == device && ptr->id == 0)
|
||||||
fprintf(fil, "ROMSTAGE_CONST struct bus %s_links[];\n", ptr->name);
|
fprintf(fil, "ROMSTAGE_CONST struct bus %s_links[];\n",
|
||||||
|
ptr->name);
|
||||||
|
|
||||||
if ((ptr->type == device) && (ptr->id != 0) && (!ptr->used)) {
|
if ((ptr->type == device) && (ptr->id != 0) && (!ptr->used)) {
|
||||||
fprintf(fil, "ROMSTAGE_CONST static struct device %s;\n", ptr->name);
|
fprintf(fil, "ROMSTAGE_CONST static struct device %s;\n",
|
||||||
|
ptr->name);
|
||||||
if (ptr->rescnt > 0)
|
if (ptr->rescnt > 0)
|
||||||
fprintf(fil, "ROMSTAGE_CONST struct resource %s_res[];\n", ptr->name);
|
fprintf(fil,
|
||||||
|
"ROMSTAGE_CONST struct resource %s_res[];\n",
|
||||||
|
ptr->name);
|
||||||
if (ptr->children || ptr->multidev)
|
if (ptr->children || ptr->multidev)
|
||||||
fprintf(fil, "ROMSTAGE_CONST struct bus %s_links[];\n",
|
fprintf(fil, "ROMSTAGE_CONST struct bus %s_links[];\n",
|
||||||
ptr->name);
|
ptr->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pass1(FILE *fil, struct device *ptr)
|
static void pass1(FILE * fil, struct device *ptr)
|
||||||
{
|
{
|
||||||
int pin;
|
int pin;
|
||||||
if (!ptr->used && (ptr->type == device)) {
|
if (!ptr->used && (ptr->type == device)) {
|
||||||
if (ptr->id != 0)
|
if (ptr->id != 0)
|
||||||
fprintf(fil, "static ");
|
fprintf(fil, "static ");
|
||||||
fprintf(fil, "ROMSTAGE_CONST struct device %s = {\n", ptr->name);
|
fprintf(fil, "ROMSTAGE_CONST struct device %s = {\n",
|
||||||
|
ptr->name);
|
||||||
fprintf(fil, "#ifndef __PRE_RAM__\n");
|
fprintf(fil, "#ifndef __PRE_RAM__\n");
|
||||||
fprintf(fil, "\t.ops = %s,\n", (ptr->ops)?(ptr->ops):"0");
|
fprintf(fil, "\t.ops = %s,\n", (ptr->ops) ? (ptr->ops) : "0");
|
||||||
fprintf(fil, "#endif\n");
|
fprintf(fil, "#endif\n");
|
||||||
fprintf(fil, "\t.bus = &%s_links[%d],\n", ptr->bus->name, ptr->bus->link);
|
fprintf(fil, "\t.bus = &%s_links[%d],\n", ptr->bus->name,
|
||||||
|
ptr->bus->link);
|
||||||
fprintf(fil, "\t.path = {");
|
fprintf(fil, "\t.path = {");
|
||||||
fprintf(fil, ptr->path, ptr->path_a, ptr->path_b);
|
fprintf(fil, ptr->path, ptr->path_a, ptr->path_b);
|
||||||
fprintf(fil, "},\n");
|
fprintf(fil, "},\n");
|
||||||
fprintf(fil, "\t.enabled = %d,\n", ptr->enabled);
|
fprintf(fil, "\t.enabled = %d,\n", ptr->enabled);
|
||||||
fprintf(fil, "\t.on_mainboard = 1,\n");
|
fprintf(fil, "\t.on_mainboard = 1,\n");
|
||||||
if (ptr->subsystem_vendor > 0)
|
if (ptr->subsystem_vendor > 0)
|
||||||
fprintf(fil, "\t.subsystem_vendor = 0x%04x,\n", ptr->subsystem_vendor);
|
fprintf(fil, "\t.subsystem_vendor = 0x%04x,\n",
|
||||||
|
ptr->subsystem_vendor);
|
||||||
|
|
||||||
for(pin = 0; pin < 4; pin++) {
|
for (pin = 0; pin < 4; pin++) {
|
||||||
if (ptr->pci_irq_info[pin].ioapic_irq_pin > 0)
|
if (ptr->pci_irq_info[pin].ioapic_irq_pin > 0)
|
||||||
fprintf(fil, "\t.pci_irq_info[%d].ioapic_irq_pin = %d,\n", pin, ptr->pci_irq_info[pin].ioapic_irq_pin);
|
fprintf(fil, "\t.pci_irq_info[%d].ioapic_irq_pin = %d,\n",
|
||||||
|
pin, ptr->pci_irq_info[pin].ioapic_irq_pin);
|
||||||
|
|
||||||
if (ptr->pci_irq_info[pin].ioapic_dst_id > 0)
|
if (ptr->pci_irq_info[pin].ioapic_dst_id > 0)
|
||||||
fprintf(fil, "\t.pci_irq_info[%d].ioapic_dst_id = %d,\n", pin, ptr->pci_irq_info[pin].ioapic_dst_id);
|
fprintf(fil, "\t.pci_irq_info[%d].ioapic_dst_id = %d,\n",
|
||||||
|
pin, ptr->pci_irq_info[pin].ioapic_dst_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptr->subsystem_device > 0)
|
if (ptr->subsystem_device > 0)
|
||||||
fprintf(fil, "\t.subsystem_device = 0x%04x,\n", ptr->subsystem_device);
|
fprintf(fil, "\t.subsystem_device = 0x%04x,\n",
|
||||||
|
ptr->subsystem_device);
|
||||||
|
|
||||||
if (ptr->rescnt > 0) {
|
if (ptr->rescnt > 0) {
|
||||||
fprintf(fil, "\t.resource_list = &%s_res[0],\n", ptr->name);
|
fprintf(fil, "\t.resource_list = &%s_res[0],\n",
|
||||||
|
ptr->name);
|
||||||
}
|
}
|
||||||
if (ptr->children || ptr->multidev)
|
if (ptr->children || ptr->multidev)
|
||||||
fprintf(fil, "\t.link_list = &%s_links[0],\n", ptr->name);
|
fprintf(fil, "\t.link_list = &%s_links[0],\n",
|
||||||
|
ptr->name);
|
||||||
else
|
else
|
||||||
fprintf(fil, "\t.link_list = NULL,\n");
|
fprintf(fil, "\t.link_list = NULL,\n");
|
||||||
if (ptr->sibling)
|
if (ptr->sibling)
|
||||||
fprintf(fil, "\t.sibling = &%s,\n", ptr->sibling->name);
|
fprintf(fil, "\t.sibling = &%s,\n", ptr->sibling->name);
|
||||||
fprintf(fil, "#ifndef __PRE_RAM__\n");
|
fprintf(fil, "#ifndef __PRE_RAM__\n");
|
||||||
fprintf(fil, "\t.chip_ops = &%s_ops,\n", ptr->chip->name_underscore);
|
fprintf(fil, "\t.chip_ops = &%s_ops,\n",
|
||||||
|
ptr->chip->name_underscore);
|
||||||
if (ptr->chip->chip == &mainboard)
|
if (ptr->chip->chip == &mainboard)
|
||||||
fprintf(fil, "\t.name = mainboard_name,\n");
|
fprintf(fil, "\t.name = mainboard_name,\n");
|
||||||
fprintf(fil, "#endif\n");
|
fprintf(fil, "#endif\n");
|
||||||
if (ptr->chip->chiph_exists)
|
if (ptr->chip->chiph_exists)
|
||||||
fprintf(fil, "\t.chip_info = &%s_info_%d,\n", ptr->chip->name_underscore, ptr->chip->id);
|
fprintf(fil, "\t.chip_info = &%s_info_%d,\n",
|
||||||
|
ptr->chip->name_underscore, ptr->chip->id);
|
||||||
if (ptr->nextdev)
|
if (ptr->nextdev)
|
||||||
fprintf(fil, "\t.next=&%s\n", ptr->nextdev->name);
|
fprintf(fil, "\t.next=&%s\n", ptr->nextdev->name);
|
||||||
fprintf(fil, "};\n");
|
fprintf(fil, "};\n");
|
||||||
}
|
}
|
||||||
if (ptr->rescnt > 0) {
|
if (ptr->rescnt > 0) {
|
||||||
int i=1;
|
int i = 1;
|
||||||
fprintf(fil, "ROMSTAGE_CONST struct resource %s_res[] = {\n",
|
fprintf(fil, "ROMSTAGE_CONST struct resource %s_res[] = {\n",
|
||||||
ptr->name);
|
ptr->name);
|
||||||
struct resource *r = ptr->res;
|
struct resource *r = ptr->res;
|
||||||
while (r) {
|
while (r) {
|
||||||
fprintf(fil, "\t\t{ .flags=IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_");
|
fprintf(fil,
|
||||||
if (r->type == IRQ) fprintf(fil, "IRQ");
|
"\t\t{ .flags=IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_");
|
||||||
if (r->type == DRQ) fprintf(fil, "DRQ");
|
if (r->type == IRQ)
|
||||||
if (r->type == IO) fprintf(fil, "IO");
|
fprintf(fil, "IRQ");
|
||||||
fprintf(fil, ", .index=0x%x, .base=0x%x,", r->index, r->base);
|
if (r->type == DRQ)
|
||||||
|
fprintf(fil, "DRQ");
|
||||||
|
if (r->type == IO)
|
||||||
|
fprintf(fil, "IO");
|
||||||
|
fprintf(fil, ", .index=0x%x, .base=0x%x,", r->index,
|
||||||
|
r->base);
|
||||||
if (r->next)
|
if (r->next)
|
||||||
fprintf(fil, ".next=&%s_res[%d]},\n", ptr->name, i++);
|
fprintf(fil, ".next=&%s_res[%d]},\n", ptr->name,
|
||||||
|
i++);
|
||||||
else
|
else
|
||||||
fprintf(fil, ".next=NULL },\n");
|
fprintf(fil, ".next=NULL },\n");
|
||||||
r = r->next;
|
r = r->next;
|
||||||
}
|
}
|
||||||
fprintf(fil, "\t };\n");
|
fprintf(fil, "\t };\n");
|
||||||
}
|
}
|
||||||
if (!ptr->used && ptr->type == device && (ptr->children || ptr->multidev)) {
|
if (!ptr->used && ptr->type == device
|
||||||
fprintf(fil, "ROMSTAGE_CONST struct bus %s_links[] = {\n", ptr->name);
|
&& (ptr->children || ptr->multidev)) {
|
||||||
|
fprintf(fil, "ROMSTAGE_CONST struct bus %s_links[] = {\n",
|
||||||
|
ptr->name);
|
||||||
if (ptr->multidev) {
|
if (ptr->multidev) {
|
||||||
struct device *d = ptr;
|
struct device *d = ptr;
|
||||||
while (d) {
|
while (d) {
|
||||||
if (device_match(d, ptr)) {
|
if (device_match(d, ptr)) {
|
||||||
fprintf(fil, "\t\t[%d] = {\n", d->link);
|
fprintf(fil, "\t\t[%d] = {\n", d->link);
|
||||||
fprintf(fil, "\t\t\t.link_num = %d,\n", d->link);
|
fprintf(fil, "\t\t\t.link_num = %d,\n",
|
||||||
fprintf(fil, "\t\t\t.dev = &%s,\n", d->name);
|
d->link);
|
||||||
|
fprintf(fil, "\t\t\t.dev = &%s,\n",
|
||||||
|
d->name);
|
||||||
if (d->children)
|
if (d->children)
|
||||||
fprintf(fil, "\t\t\t.children = &%s,\n", d->children->name);
|
fprintf(fil,
|
||||||
if (d->next_sibling && device_match(d->next_sibling, ptr))
|
"\t\t\t.children = &%s,\n",
|
||||||
fprintf(fil, "\t\t\t.next=&%s_links[%d],\n", d->name, d->link+1);
|
d->children->name);
|
||||||
|
if (d->next_sibling
|
||||||
|
&& device_match(d->next_sibling,
|
||||||
|
ptr))
|
||||||
|
fprintf(fil,
|
||||||
|
"\t\t\t.next=&%s_links[%d],\n",
|
||||||
|
d->name, d->link + 1);
|
||||||
else
|
else
|
||||||
fprintf(fil, "\t\t\t.next = NULL,\n");
|
fprintf(fil,
|
||||||
|
"\t\t\t.next = NULL,\n");
|
||||||
fprintf(fil, "\t\t},\n");
|
fprintf(fil, "\t\t},\n");
|
||||||
}
|
}
|
||||||
d = d->next_sibling;
|
d = d->next_sibling;
|
||||||
|
@ -478,7 +538,8 @@ static void pass1(FILE *fil, struct device *ptr)
|
||||||
fprintf(fil, "\t\t[0] = {\n");
|
fprintf(fil, "\t\t[0] = {\n");
|
||||||
fprintf(fil, "\t\t\t.link_num = 0,\n");
|
fprintf(fil, "\t\t\t.link_num = 0,\n");
|
||||||
fprintf(fil, "\t\t\t.dev = &%s,\n", ptr->name);
|
fprintf(fil, "\t\t\t.dev = &%s,\n", ptr->name);
|
||||||
fprintf(fil, "\t\t\t.children = &%s,\n", ptr->children->name);
|
fprintf(fil, "\t\t\t.children = &%s,\n",
|
||||||
|
ptr->children->name);
|
||||||
fprintf(fil, "\t\t\t.next = NULL,\n");
|
fprintf(fil, "\t\t\t.next = NULL,\n");
|
||||||
fprintf(fil, "\t\t},\n");
|
fprintf(fil, "\t\t},\n");
|
||||||
}
|
}
|
||||||
|
@ -487,7 +548,8 @@ static void pass1(FILE *fil, struct device *ptr)
|
||||||
}
|
}
|
||||||
if ((ptr->type == chip) && (ptr->chiph_exists)) {
|
if ((ptr->type == chip) && (ptr->chiph_exists)) {
|
||||||
if (ptr->reg) {
|
if (ptr->reg) {
|
||||||
fprintf(fil, "ROMSTAGE_CONST struct %s_config %s_info_%d = {\n",
|
fprintf(fil,
|
||||||
|
"ROMSTAGE_CONST struct %s_config %s_info_%d = {\n",
|
||||||
ptr->name_underscore, ptr->name_underscore,
|
ptr->name_underscore, ptr->name_underscore,
|
||||||
ptr->id);
|
ptr->id);
|
||||||
struct reg *r = ptr->reg;
|
struct reg *r = ptr->reg;
|
||||||
|
@ -497,20 +559,25 @@ static void pass1(FILE *fil, struct device *ptr)
|
||||||
}
|
}
|
||||||
fprintf(fil, "};\n\n");
|
fprintf(fil, "};\n\n");
|
||||||
} else {
|
} else {
|
||||||
fprintf(fil, "ROMSTAGE_CONST struct %s_config %s_info_%d = { };\n",
|
fprintf(fil,
|
||||||
ptr->name_underscore, ptr->name_underscore, ptr->id);
|
"ROMSTAGE_CONST struct %s_config %s_info_%d = { };\n",
|
||||||
|
ptr->name_underscore, ptr->name_underscore,
|
||||||
|
ptr->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void walk_device_tree(FILE *fil, struct device *ptr, void (*func)(FILE *, struct device*), struct device *chips) {
|
static void walk_device_tree(FILE * fil, struct device *ptr,
|
||||||
|
void (*func) (FILE *, struct device *),
|
||||||
|
struct device *chips)
|
||||||
|
{
|
||||||
do {
|
do {
|
||||||
func(fil, ptr);
|
func(fil, ptr);
|
||||||
ptr = ptr->next_sibling;
|
ptr = ptr->next_sibling;
|
||||||
} while (ptr);
|
} while (ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inherit_subsystem_ids(FILE *file, struct device *dev)
|
static void inherit_subsystem_ids(FILE * file, struct device *dev)
|
||||||
{
|
{
|
||||||
struct device *p;
|
struct device *p;
|
||||||
|
|
||||||
|
@ -519,7 +586,7 @@ static void inherit_subsystem_ids(FILE *file, struct device *dev)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(p = dev; p && p != p->parent; p = p->parent) {
|
for (p = dev; p && p != p->parent; p = p->parent) {
|
||||||
|
|
||||||
if (p->bustype != PCI && p->bustype != DOMAIN)
|
if (p->bustype != PCI && p->bustype != DOMAIN)
|
||||||
continue;
|
continue;
|
||||||
|
@ -535,16 +602,18 @@ static void inherit_subsystem_ids(FILE *file, struct device *dev)
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
printf("usage: sconfig devicetree_file output_file\n");
|
printf("usage: sconfig devicetree_file output_file\n");
|
||||||
exit (1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
DEVICEFILE_ARG = 1,
|
DEVICEFILE_ARG = 1,
|
||||||
OUTPUTFILE_ARG};
|
OUTPUTFILE_ARG
|
||||||
|
};
|
||||||
|
|
||||||
#define ARG_COUNT 3
|
#define ARG_COUNT 3
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
if (argc != ARG_COUNT)
|
if (argc != ARG_COUNT)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
@ -570,12 +639,14 @@ int main(int argc, char** argv) {
|
||||||
if ((head->type == chip) && (!head->chiph_exists)) {
|
if ((head->type == chip) && (!head->chiph_exists)) {
|
||||||
struct device *tmp = head;
|
struct device *tmp = head;
|
||||||
head = &root;
|
head = &root;
|
||||||
while (head->next != tmp) head = head->next;
|
while (head->next != tmp)
|
||||||
|
head = head->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *autogen = fopen(outputc, "w");
|
FILE *autogen = fopen(outputc, "w");
|
||||||
if (!autogen) {
|
if (!autogen) {
|
||||||
fprintf(stderr, "Could not open file '%s' for writing: ", outputc);
|
fprintf(stderr, "Could not open file '%s' for writing: ",
|
||||||
|
outputc);
|
||||||
perror(NULL);
|
perror(NULL);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -590,12 +661,15 @@ int main(int argc, char** argv) {
|
||||||
fprintf(autogen, "#include \"%s/chip.h\"\n", h->name);
|
fprintf(autogen, "#include \"%s/chip.h\"\n", h->name);
|
||||||
}
|
}
|
||||||
fprintf(autogen, "\n#ifndef __PRE_RAM__\n");
|
fprintf(autogen, "\n#ifndef __PRE_RAM__\n");
|
||||||
fprintf(autogen, "__attribute__((weak)) struct chip_operations mainboard_ops = {};\n");
|
fprintf(autogen,
|
||||||
|
"__attribute__((weak)) struct chip_operations mainboard_ops = {};\n");
|
||||||
h = &headers;
|
h = &headers;
|
||||||
while (h->next) {
|
while (h->next) {
|
||||||
h = h->next;
|
h = h->next;
|
||||||
char *name_underscore = translate_name(h->name, UNSLASH);
|
char *name_underscore = translate_name(h->name, UNSLASH);
|
||||||
fprintf(autogen, "__attribute__((weak)) struct chip_operations %s_ops = {};\n", name_underscore);
|
fprintf(autogen,
|
||||||
|
"__attribute__((weak)) struct chip_operations %s_ops = {};\n",
|
||||||
|
name_underscore);
|
||||||
free(name_underscore);
|
free(name_underscore);
|
||||||
}
|
}
|
||||||
fprintf(autogen, "#endif\n");
|
fprintf(autogen, "#endif\n");
|
||||||
|
@ -604,7 +678,8 @@ int main(int argc, char** argv) {
|
||||||
fprintf(autogen, "\n/* pass 0 */\n");
|
fprintf(autogen, "\n/* pass 0 */\n");
|
||||||
walk_device_tree(autogen, &root, pass0, NULL);
|
walk_device_tree(autogen, &root, pass0, NULL);
|
||||||
fprintf(autogen, "\n/* pass 1 */\n"
|
fprintf(autogen, "\n/* pass 1 */\n"
|
||||||
"ROMSTAGE_CONST struct device * ROMSTAGE_CONST last_dev = &%s;\n", lastdev->name);
|
"ROMSTAGE_CONST struct device * ROMSTAGE_CONST last_dev = &%s;\n",
|
||||||
|
lastdev->name);
|
||||||
walk_device_tree(autogen, &root, pass1, NULL);
|
walk_device_tree(autogen, &root, pass1, NULL);
|
||||||
|
|
||||||
fclose(autogen);
|
fclose(autogen);
|
||||||
|
|
|
@ -91,11 +91,14 @@ void fold_in(struct device *parent);
|
||||||
void postprocess_devtree(void);
|
void postprocess_devtree(void);
|
||||||
struct device *new_chip(struct device *parent, struct device *bus, char *path);
|
struct device *new_chip(struct device *parent, struct device *bus, char *path);
|
||||||
void add_header(struct device *dev);
|
void add_header(struct device *dev);
|
||||||
struct device *new_device(struct device *parent, struct device *busdev, const int bus, const char *devnum, int enabled);
|
struct device *new_device(struct device *parent, struct device *busdev,
|
||||||
|
const int bus, const char *devnum, int enabled);
|
||||||
void alias_siblings(struct device *d);
|
void alias_siblings(struct device *d);
|
||||||
void add_resource(struct device *dev, int type, int index, int base);
|
void add_resource(struct device *dev, int type, int index, int base);
|
||||||
void add_register(struct device *dev, char *name, char *val);
|
void add_register(struct device *dev, char *name, char *val);
|
||||||
void add_pci_subsystem_ids(struct device *dev, int vendor, int device, int inherit);
|
void add_pci_subsystem_ids(struct device *dev, int vendor, int device,
|
||||||
void add_ioapic_info(struct device *dev, int apicid, const char *_srcpin, int irqpin);
|
int inherit);
|
||||||
|
void add_ioapic_info(struct device *dev, int apicid, const char *_srcpin,
|
||||||
|
int irqpin);
|
||||||
|
|
||||||
void yyrestart(FILE *input_file);
|
void yyrestart(FILE *input_file);
|
||||||
|
|
Loading…
Reference in New Issue