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
22 struct bayoucfg bayoucfg
;
24 static int add_payload(struct LAR
*lar
, struct larent
*larent
)
26 struct payload
*payload
;
31 if (bayoucfg
.n_entries
== BAYOU_MAX_ENTRIES
)
34 payload
= &bayoucfg
.entries
[bayoucfg
.n_entries
];
36 if (strncmp((char *)larent
->name
, "payload/", 8))
39 if (larstat(lar
, (const char *)larent
->name
, &payload
->stat
))
42 /* Make sure the LAR entry is valid. */
43 if (!lfverify(lar
, (const char *)larent
->name
))
46 /* Get a pointer to the start of the file. */
47 fptr
= larfptr(lar
, (const char *)larent
->name
);
52 if (!verify_self(fptr
))
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
, ¶ms
);
61 payload_parse_params(payload
, params
, plen
);
70 static int lar_walk_files(struct LAR
*lar
,
71 int (*cb
) (struct LAR
*, struct larent
*))
73 struct larent
*larent
;
78 while ((larent
= readlar(lar
)) != NULL
) {
79 if ((ret
= cb(lar
, larent
)))
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
)
101 struct bpt_config
*bptcfg
;
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");
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",
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
]);
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
))
155 build_dummy_table(lar
);
157 plen
= self_get_params(fptr
, ¶ms
);
158 payload_parse_params(p
, params
, plen
);
161 ptr
+= sizeof(struct bpt_pentry
) + entry
->nlen
;