nb/intel/sandybridge/raminit: Add 100MHz refclock support
[coreboot.git] / payloads / bayou / config.c
blobad315c8fdabca90243f04994a73a658ba6a183f7
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.
16 #include "bayou.h"
18 struct bayoucfg bayoucfg;
20 static int add_payload(struct LAR *lar, struct larent *larent)
22 struct payload *payload;
23 int plen;
24 u8 *params = NULL;
25 u8 *fptr;
27 if (bayoucfg.n_entries == BAYOU_MAX_ENTRIES)
28 return -1;
30 payload = &bayoucfg.entries[bayoucfg.n_entries];
32 if (strncmp((char *)larent->name, "payload/", 8))
33 return -1;
35 if (larstat(lar, (const char *)larent->name, &payload->stat))
36 return -1;
38 /* Make sure the LAR entry is valid. */
39 if (!lfverify(lar, (const char *)larent->name))
40 return -1;
42 /* Get a pointer to the start of the file. */
43 fptr = larfptr(lar, (const char *)larent->name);
45 if (fptr == NULL)
46 return -1;
48 if (!verify_self(fptr))
49 return -1;
51 payload->pentry.index = bayoucfg.n_entries;
52 payload->pentry.parent = 0;
53 payload->pentry.type = BPT_TYPE_CHOOSER;
54 payload->pentry.flags = 0;
56 plen = self_get_params(fptr, &params);
57 payload_parse_params(payload, params, plen);
59 payload->fptr = fptr;
61 bayoucfg.n_entries++;
63 return 0;
66 static int lar_walk_files(struct LAR *lar,
67 int (*cb) (struct LAR *, struct larent *))
69 struct larent *larent;
70 int ret = 0;
72 rewindlar(lar);
74 while ((larent = readlar(lar)) != NULL) {
75 if ((ret = cb(lar, larent)))
76 break;
79 return ret;
82 /**
83 * If reading the bayou_payload_table fails for some reason, then construct
84 * a dummy table. All valid payloads in the lar are added as chooser items.
86 static void build_dummy_table(struct LAR *lar)
88 bayoucfg.timeout = 0xFF;
89 bayoucfg.n_entries = 0;
91 lar_walk_files(lar, add_payload);
94 int get_configuration(struct LAR *lar)
96 struct larstat stat;
97 struct bpt_config *bptcfg;
98 u8 *fptr, *ptr;
99 int i;
102 * If bayou_payload_table doesn't exist, then dummy up
103 * a table from the LAR contents.
105 if (larstat(lar, "bayou_payload_table", &stat) ||
106 !lfverify(lar, "bayou_payload_table"))
107 build_dummy_table(lar);
109 /* Open up the BPT and get the creamy goodness within. */
111 fptr = larfptr(lar, "bayou_payload_table");
113 if (fptr == NULL)
114 build_dummy_table(lar);
116 bptcfg = (struct bpt_config *)fptr;
117 bayoucfg.timeout = bptcfg->timeout;
119 bayoucfg.n_entries = bptcfg->entries;
121 if (bayoucfg.n_entries > BAYOU_MAX_ENTRIES) {
122 printf("W: Limiting the number of entries to %d\n",
123 BAYOU_MAX_ENTRIES);
124 bayoucfg.n_entries = BAYOU_MAX_ENTRIES;
127 ptr = fptr + sizeof(struct bpt_config);
129 for (i = 0; i < bayoucfg.n_entries; i++) {
130 struct bpt_pentry *entry = (struct bpt_pentry *)ptr;
131 struct payload *p = &(bayoucfg.entries[i]);
132 int plen;
133 u8 *params = NULL;
135 memcpy(&p->pentry, entry, sizeof(struct bpt_pentry));
137 if (entry->type != BPT_TYPE_CHAIN) {
138 char *lname = (char *)ptr + sizeof(struct bpt_pentry);
140 if (larstat(lar, (const char *)lname, &p->stat))
141 build_dummy_table(lar);
143 if (!lfverify(lar, (const char *)lname))
144 build_dummy_table(lar);
146 fptr = larfptr(lar, (const char *)lname);
148 if (verify_self(fptr))
149 p->fptr = fptr;
150 else
151 build_dummy_table(lar);
153 plen = self_get_params(fptr, &params);
154 payload_parse_params(p, params, plen);
157 ptr += sizeof(struct bpt_pentry) + entry->nlen;
160 return 0;