These allow OpenBIOS to locate fw_cfg files by name and then read them via the fw_cfg interface.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/fw_cfg.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/arch/common/fw_cfg.h | 15 +++++++++++++++ 2 files changed, 57 insertions(+)
diff --git a/drivers/fw_cfg.c b/drivers/fw_cfg.c index 7086873..a95538a 100644 --- a/drivers/fw_cfg.c +++ b/drivers/fw_cfg.c @@ -73,6 +73,48 @@ fw_cfg_read_i16(uint16_t cmd) return __le16_to_cpu(buf); }
+uint32_t +fw_cfg_find_file(const char *filename, uint16_t *select, uint32_t *size) +{ + FWCfgFile f; + unsigned int i; + uint32_t buf, count; + + /* Unusually all FW_CFG_FILE_DIR fields are BE */ + fw_cfg_read(FW_CFG_FILE_DIR, (char *)&buf, sizeof(uint32_t)); + count = __be32_to_cpu(buf); + + for (i = 0; i < count; i++) { + fw_cfg_read_bytes((char *)&f, sizeof(f)); + + if (!strcmp(f.name, filename)) { + *select = __be16_to_cpu(f.select); + *size = __be32_to_cpu(f.size); + + return -1; + } + } + + return 0; +} + +char * +fw_cfg_read_file(const char *filename, uint32_t *size) +{ + uint16_t cmd; + uint32_t nbytes; + char *buf; + + if (fw_cfg_find_file(filename, &cmd, &nbytes)) { + buf = malloc(nbytes); + fw_cfg_read(cmd, buf, nbytes); + *size = nbytes; + return buf; + } + + return NULL; +} + void fw_cfg_init(void) { diff --git a/include/arch/common/fw_cfg.h b/include/arch/common/fw_cfg.h index df44c2e..1c43a9d 100644 --- a/include/arch/common/fw_cfg.h +++ b/include/arch/common/fw_cfg.h @@ -85,6 +85,21 @@ uint64_t fw_cfg_read_i64(uint16_t cmd); uint32_t fw_cfg_read_i32(uint16_t cmd); uint16_t fw_cfg_read_i16(uint16_t cmd); void fw_cfg_init(void); + +typedef struct FWCfgFile { + uint32_t size; /* file size */ + uint16_t select; /* write this to 0x510 to read it */ + uint16_t reserved; + char name[56]; +} FWCfgFile; + +typedef struct FWCfgFiles { + uint32_t count; + FWCfgFile f[]; +} FWCfgFiles; + +unsigned int fw_cfg_find_file(const char *filename, uint16_t *select, uint32_t *size); +char *fw_cfg_read_file(const char *filename, uint32_t *size); #endif /* NO_OPENBIOS_PROTOS */
#endif