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.
18 struct bayoucfg bayoucfg
;
20 static int add_payload(struct LAR
*lar
, struct larent
*larent
)
22 struct payload
*payload
;
27 if (bayoucfg
.n_entries
== BAYOU_MAX_ENTRIES
)
30 payload
= &bayoucfg
.entries
[bayoucfg
.n_entries
];
32 if (strncmp((char *)larent
->name
, "payload/", 8))
35 if (larstat(lar
, (const char *)larent
->name
, &payload
->stat
))
38 /* Make sure the LAR entry is valid. */
39 if (!lfverify(lar
, (const char *)larent
->name
))
42 /* Get a pointer to the start of the file. */
43 fptr
= larfptr(lar
, (const char *)larent
->name
);
48 if (!verify_self(fptr
))
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
, ¶ms
);
57 payload_parse_params(payload
, params
, plen
);
66 static int lar_walk_files(struct LAR
*lar
,
67 int (*cb
) (struct LAR
*, struct larent
*))
69 struct larent
*larent
;
74 while ((larent
= readlar(lar
)) != NULL
) {
75 if ((ret
= cb(lar
, larent
)))
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
)
97 struct bpt_config
*bptcfg
;
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");
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",
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
]);
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
))
151 build_dummy_table(lar
);
153 plen
= self_get_params(fptr
, ¶ms
);
154 payload_parse_params(p
, params
, plen
);
157 ptr
+= sizeof(struct bpt_pentry
) + entry
->nlen
;