t132: Add TTB_BUFFER to resource reserved
[coreboot.git] / payloads / bayou / config.c
blob3b69c4c8de760a1df5aab8a4321c9b1610799677
1 /*
2 * This file is part of the bayou project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "bayou.h"
22 struct bayoucfg bayoucfg;
24 static int add_payload(struct LAR *lar, struct larent *larent)
26 struct payload *payload;
27 int plen;
28 u8 *params = NULL;
29 u8 *fptr;
31 if (bayoucfg.n_entries == BAYOU_MAX_ENTRIES)
32 return -1;
34 payload = &bayoucfg.entries[bayoucfg.n_entries];
36 if (strncmp((char *)larent->name, "payload/", 8))
37 return -1;
39 if (larstat(lar, (const char *)larent->name, &payload->stat))
40 return -1;
42 /* Make sure the LAR entry is valid. */
43 if (!lfverify(lar, (const char *)larent->name))
44 return -1;
46 /* Get a pointer to the start of the file. */
47 fptr = larfptr(lar, (const char *)larent->name);
49 if (fptr == NULL)
50 return -1;
52 if (!verify_self(fptr))
53 return -1;
55 payload->pentry.index = bayoucfg.n_entries;
56 payload->pentry.parent = 0;
57 payload->pentry.type = BPT_TYPE_CHOOSER;
58 payload->pentry.flags = 0;
60 plen = self_get_params(fptr, &params);
61 payload_parse_params(payload, params, plen);
63 payload->fptr = fptr;
65 bayoucfg.n_entries++;
67 return 0;
70 static int lar_walk_files(struct LAR *lar,
71 int (*cb) (struct LAR *, struct larent *))
73 struct larent *larent;
74 int ret = 0;
76 rewindlar(lar);
78 while ((larent = readlar(lar)) != NULL) {
79 if ((ret = cb(lar, larent)))
80 break;
83 return ret;
86 /**
87 * If reading the bayou_payload_table fails for some reason, then construct
88 * a dummy table. All valid payloads in the lar are added as chooser items.
90 static void build_dummy_table(struct LAR *lar)
92 bayoucfg.timeout = 0xFF;
93 bayoucfg.n_entries = 0;
95 lar_walk_files(lar, add_payload);
98 int get_configuration(struct LAR *lar)
100 struct larstat stat;
101 struct bpt_config *bptcfg;
102 u8 *fptr, *ptr;
103 int i;
106 * If bayou_payload_table doesn't exist, then dummy up
107 * a table from the LAR contents.
109 if (larstat(lar, "bayou_payload_table", &stat) ||
110 !lfverify(lar, "bayou_payload_table"))
111 build_dummy_table(lar);
113 /* Open up the BPT and get the creamy goodness within. */
115 fptr = larfptr(lar, "bayou_payload_table");
117 if (fptr == NULL)
118 build_dummy_table(lar);
120 bptcfg = (struct bpt_config *)fptr;
121 bayoucfg.timeout = bptcfg->timeout;
123 bayoucfg.n_entries = bptcfg->entries;
125 if (bayoucfg.n_entries > BAYOU_MAX_ENTRIES) {
126 printf("W: Limiting the number of entries to %d\n",
127 BAYOU_MAX_ENTRIES);
128 bayoucfg.n_entries = BAYOU_MAX_ENTRIES;
131 ptr = fptr + sizeof(struct bpt_config);
133 for (i = 0; i < bayoucfg.n_entries; i++) {
134 struct bpt_pentry *entry = (struct bpt_pentry *)ptr;
135 struct payload *p = &(bayoucfg.entries[i]);
136 int plen;
137 u8 *params = NULL;
139 memcpy(&p->pentry, entry, sizeof(struct bpt_pentry));
141 if (entry->type != BPT_TYPE_CHAIN) {
142 char *lname = (char *)ptr + sizeof(struct bpt_pentry);
144 if (larstat(lar, (const char *)lname, &p->stat))
145 build_dummy_table(lar);
147 if (!lfverify(lar, (const char *)lname))
148 build_dummy_table(lar);
150 fptr = larfptr(lar, (const char *)lname);
152 if (verify_self(fptr))
153 p->fptr = fptr;
154 else
155 build_dummy_table(lar);
157 plen = self_get_params(fptr, &params);
158 payload_parse_params(p, params, plen);
161 ptr += sizeof(struct bpt_pentry) + entry->nlen;
164 return 0;