diff options
author | fishsoupisgood <github@madingley.org> | 2019-04-29 01:17:54 +0100 |
---|---|---|
committer | fishsoupisgood <github@madingley.org> | 2019-05-27 03:43:43 +0100 |
commit | 3f2546b2ef55b661fd8dd69682b38992225e86f6 (patch) | |
tree | 65ca85f13617aee1dce474596800950f266a456c /roms/openbios/drivers/fw_cfg.c | |
download | qemu-master.tar.gz qemu-master.tar.bz2 qemu-master.zip |
Diffstat (limited to 'roms/openbios/drivers/fw_cfg.c')
-rw-r--r-- | roms/openbios/drivers/fw_cfg.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/roms/openbios/drivers/fw_cfg.c b/roms/openbios/drivers/fw_cfg.c new file mode 100644 index 00000000..40275707 --- /dev/null +++ b/roms/openbios/drivers/fw_cfg.c @@ -0,0 +1,76 @@ +#include "config.h" +#include "libopenbios/bindings.h" +#include "libc/byteorder.h" +#include "libopenbios/ofmem.h" +#define NO_QEMU_PROTOS +#include "arch/common/fw_cfg.h" + +#if !defined(CONFIG_SPARC64) +static volatile uint16_t *fw_cfg_cmd; +static volatile uint8_t *fw_cfg_data; + +void +fw_cfg_read(uint16_t cmd, char *buf, unsigned int nbytes) +{ + unsigned int i; + + *fw_cfg_cmd = cmd; + for (i = 0; i < nbytes; i++) + buf[i] = *fw_cfg_data; +} +#else +// XXX depends on PCI bus location, should be removed +void +fw_cfg_read(uint16_t cmd, char *buf, unsigned int nbytes) +{ + unsigned int i; + + outw(cmd, CONFIG_FW_CFG_ADDR); + for (i = 0; i < nbytes; i++) + buf[i] = inb(CONFIG_FW_CFG_ADDR + 1); +} +#endif + +uint64_t +fw_cfg_read_i64(uint16_t cmd) +{ + uint64_t buf; + + fw_cfg_read(cmd, (char *)&buf, sizeof(uint64_t)); + + return __le64_to_cpu(buf); +} + +uint32_t +fw_cfg_read_i32(uint16_t cmd) +{ + uint32_t buf; + + fw_cfg_read(cmd, (char *)&buf, sizeof(uint32_t)); + + return __le32_to_cpu(buf); +} + +uint16_t +fw_cfg_read_i16(uint16_t cmd) +{ + uint16_t buf; + + fw_cfg_read(cmd, (char *)&buf, sizeof(uint16_t)); + + return __le16_to_cpu(buf); +} + +void +fw_cfg_init(void) +{ +#if defined(CONFIG_SPARC32) + fw_cfg_cmd = (void *)ofmem_map_io(CONFIG_FW_CFG_ADDR, 2); + fw_cfg_data = (uint8_t *)fw_cfg_cmd + 2; +#elif defined(CONFIG_SPARC64) + // Nothing for the port version +#elif defined(CONFIG_PPC) + fw_cfg_cmd = (void *)CONFIG_FW_CFG_ADDR; + fw_cfg_data = (void *)(CONFIG_FW_CFG_ADDR + 2); +#endif +} |