Refactor QEMU firmware confguration device handling (based on patch by

Aurelien Jarno)


git-svn-id: svn://coreboot.org/openbios/openbios-devel@432 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
Blue Swirl
2009-01-31 08:49:16 +00:00
parent d474d768b1
commit 36bab875b8
14 changed files with 104 additions and 119 deletions

View File

@@ -33,8 +33,6 @@
#define NO_QEMU_PROTOS #define NO_QEMU_PROTOS
#include "openbios/fw_cfg.h" #include "openbios/fw_cfg.h"
#define CFG_ADDR 0xf0000510
#define UUID_FMT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" #define UUID_FMT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
struct cpudef { struct cpudef {
@@ -95,39 +93,6 @@ static const pci_arch_t known_arch[] = {
}; };
uint32_t isa_io_base; uint32_t isa_io_base;
static volatile uint16_t *fw_cfg_cmd = (void *)CFG_ADDR;
static volatile uint8_t *fw_cfg_data = (void *)(CFG_ADDR + 2);
static 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;
}
static uint32_t
fw_cfg_read_i32(uint16_t cmd)
{
char buf[sizeof(uint32_t)];
fw_cfg_read(cmd, buf, sizeof(uint32_t));
return __le32_to_cpu(*(uint32_t *)buf);
}
static uint16_t
fw_cfg_read_i16(uint16_t cmd)
{
char buf[sizeof(uint16_t)];
fw_cfg_read(cmd, buf, sizeof(uint16_t));
return __le16_to_cpu(*(uint16_t *)buf);
}
void void
entry( void ) entry( void )
{ {
@@ -136,6 +101,8 @@ entry( void )
arch = &known_arch[ARCH_HEATHROW]; arch = &known_arch[ARCH_HEATHROW];
fw_cfg_init();
fw_cfg_read(FW_CFG_SIGNATURE, buf, 4); fw_cfg_read(FW_CFG_SIGNATURE, buf, 4);
buf[4] = '\0'; buf[4] = '\0';
if (strncmp(buf, "QEMU", 4) == 0) { if (strncmp(buf, "QEMU", 4) == 0) {

View File

@@ -11,6 +11,7 @@
#include "asm/asi.h" #include "asm/asi.h"
#include "asm/crs.h" #include "asm/crs.h"
#define NO_QEMU_PROTOS #define NO_QEMU_PROTOS
#define NO_OPENBIOS_PROTOS
#include "openbios/fw_cfg.h" #include "openbios/fw_cfg.h"
#define CFG_ADDR 0x00000510 #define CFG_ADDR 0x00000510

View File

@@ -12,6 +12,7 @@
#include "pstate.h" #include "pstate.h"
#include "lsu.h" #include "lsu.h"
#define NO_QEMU_PROTOS #define NO_QEMU_PROTOS
#define NO_OPENBIOS_PROTOS
#include "openbios/fw_cfg.h" #include "openbios/fw_cfg.h"
#define PROM_ADDR 0x1fff0000000 #define PROM_ADDR 0x1fff0000000

View File

@@ -24,9 +24,6 @@
#include "openbios/fw_cfg.h" #include "openbios/fw_cfg.h"
#include "video_subr.h" #include "video_subr.h"
#define BIOS_CFG_CMD 0x510
#define BIOS_CFG_DATA 0x511
#define UUID_FMT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" #define UUID_FMT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
#define NVRAM_ADDR_LO 0x74 #define NVRAM_ADDR_LO 0x74
@@ -244,46 +241,6 @@ id_cpu(void)
for (;;); for (;;);
} }
static void
fw_cfg_read(uint16_t cmd, char *buf, unsigned int nbytes)
{
unsigned int i;
outw(cmd, BIOS_CFG_CMD);
for (i = 0; i < nbytes; i++)
buf[i] = inb(BIOS_CFG_DATA);
}
static uint64_t
fw_cfg_read_i64(uint16_t cmd)
{
char buf[sizeof(uint64_t)];
fw_cfg_read(cmd, buf, sizeof(uint64_t));
return __le64_to_cpu(*(uint64_t *)buf);
}
static uint32_t
fw_cfg_read_i32(uint16_t cmd)
{
char buf[sizeof(uint32_t)];
fw_cfg_read(cmd, buf, sizeof(uint32_t));
return __le32_to_cpu(*(uint32_t *)buf);
}
static uint16_t
fw_cfg_read_i16(uint16_t cmd)
{
char buf[sizeof(uint16_t)];
fw_cfg_read(cmd, buf, sizeof(uint16_t));
return __le16_to_cpu(*(uint16_t *)buf);
}
static uint8_t nvram_read_byte(uint16_t offset) static uint8_t nvram_read_byte(uint16_t offset)
{ {
outb(offset & 0xff, NVRAM_ADDR_LO); outb(offset & 0xff, NVRAM_ADDR_LO);
@@ -330,6 +287,8 @@ void arch_nvram_get(char *data)
nvram_read(0, (char *)&nv_info, sizeof(ohwcfg_v3_t)); nvram_read(0, (char *)&nv_info, sizeof(ohwcfg_v3_t));
fw_cfg_init();
fw_cfg_read(FW_CFG_SIGNATURE, buf, 4); fw_cfg_read(FW_CFG_SIGNATURE, buf, 4);
buf[4] = '\0'; buf[4] = '\0';

View File

@@ -75,5 +75,6 @@
<option name="CONFIG_DRIVER_VGA" type="boolean" value="true"/> <option name="CONFIG_DRIVER_VGA" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_MACIO" type="boolean" value="true"/> <option name="CONFIG_DRIVER_MACIO" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_ESCC" type="boolean" value="true"/> <option name="CONFIG_DRIVER_ESCC" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_FW_CFG" type="boolean" value="true"/>
<option name="CONFIG_FW_CFG_ADDR" type="integer" value="0xf0000510"/>
</config> </config>

View File

@@ -76,5 +76,6 @@
<option name="CONFIG_DEBUG_FLOPPY" type="boolean" value="false"/> <option name="CONFIG_DEBUG_FLOPPY" type="boolean" value="false"/>
<option name="CONFIG_DRIVER_ESCC" type="boolean" value="true"/> <option name="CONFIG_DRIVER_ESCC" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_ESCC_SUN" type="boolean" value="true"/> <option name="CONFIG_DRIVER_ESCC_SUN" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_FW_CFG" type="boolean" value="true"/>
<option name="CONFIG_FW_CFG_ADDR" type="integer" value="0xd00000510ULL"/>
</config> </config>

View File

@@ -77,5 +77,6 @@
<option name="CONFIG_DRIVER_EBUS" type="boolean" value="true"/> <option name="CONFIG_DRIVER_EBUS" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_PC_KBD" type="boolean" value="true"/> <option name="CONFIG_DRIVER_PC_KBD" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_PC_SERIAL" type="boolean" value="true"/> <option name="CONFIG_DRIVER_PC_SERIAL" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_FW_CFG" type="boolean" value="true"/>
<option name="CONFIG_FW_CFG_ADDR" type="integer" value="0x510"/>
</config> </config>

View File

@@ -75,5 +75,6 @@
<option name="CONFIG_DRIVER_VGA" type="boolean" value="true"/> <option name="CONFIG_DRIVER_VGA" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_MACIO" type="boolean" value="true"/> <option name="CONFIG_DRIVER_MACIO" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_ESCC" type="boolean" value="true"/> <option name="CONFIG_DRIVER_ESCC" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_FW_CFG" type="boolean" value="true"/>
<option name="CONFIG_FW_CFG_ADDR" type="integer" value="0xf0000510"/>
</config> </config>

View File

@@ -76,5 +76,6 @@
<option name="CONFIG_DEBUG_FLOPPY" type="boolean" value="false"/> <option name="CONFIG_DEBUG_FLOPPY" type="boolean" value="false"/>
<option name="CONFIG_DRIVER_ESCC" type="boolean" value="true"/> <option name="CONFIG_DRIVER_ESCC" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_ESCC_SUN" type="boolean" value="true"/> <option name="CONFIG_DRIVER_ESCC_SUN" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_FW_CFG" type="boolean" value="true"/>
<option name="CONFIG_FW_CFG_ADDR" type="integer" value="0xd00000510ULL"/>
</config> </config>

View File

@@ -77,5 +77,6 @@
<option name="CONFIG_DRIVER_EBUS" type="boolean" value="true"/> <option name="CONFIG_DRIVER_EBUS" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_PC_KBD" type="boolean" value="true"/> <option name="CONFIG_DRIVER_PC_KBD" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_PC_SERIAL" type="boolean" value="true"/> <option name="CONFIG_DRIVER_PC_SERIAL" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_FW_CFG" type="boolean" value="true"/>
<option name="CONFIG_FW_CFG_ADDR" type="integer" value="0x510"/>
</config> </config>

View File

@@ -22,6 +22,7 @@
<object source="pc_kbd.c" condition="DRIVER_PC_KBD"/> <object source="pc_kbd.c" condition="DRIVER_PC_KBD"/>
<object source="pc_serial.c" condition="DRIVER_PC_SERIAL"/> <object source="pc_serial.c" condition="DRIVER_PC_SERIAL"/>
<object source="escc.c" condition="DRIVER_ESCC"/> <object source="escc.c" condition="DRIVER_ESCC"/>
<object source="fw_cfg.c" condition="DRIVER_FW_CFG"/>
</library> </library>
<dictionary name="openbios" target="forth"> <dictionary name="openbios" target="forth">

76
drivers/fw_cfg.c Normal file
View File

@@ -0,0 +1,76 @@
#include "openbios/config.h"
#include "openbios/bindings.h"
#include "libc/byteorder.h"
#include "ofmem.h"
#define NO_QEMU_PROTOS
#include "openbios/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)
{
char buf[sizeof(uint64_t)];
fw_cfg_read(cmd, buf, sizeof(uint64_t));
return __le64_to_cpu(*(uint64_t *)buf);
}
uint32_t
fw_cfg_read_i32(uint16_t cmd)
{
char buf[sizeof(uint32_t)];
fw_cfg_read(cmd, buf, sizeof(uint32_t));
return __le32_to_cpu(*(uint32_t *)buf);
}
uint16_t
fw_cfg_read_i16(uint16_t cmd)
{
char buf[sizeof(uint16_t)];
fw_cfg_read(cmd, buf, sizeof(uint16_t));
return __le16_to_cpu(*(uint16_t *)buf);
}
void
fw_cfg_init(void)
{
#if defined(CONFIG_SPARC32)
fw_cfg_cmd = (void *)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
}

View File

@@ -646,39 +646,6 @@ id_machine(uint16_t machine_id)
for (;;); for (;;);
} }
static volatile uint16_t *fw_cfg_cmd;
static volatile uint8_t *fw_cfg_data;
static 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;
}
static uint32_t
fw_cfg_read_i32(uint16_t cmd)
{
char buf[sizeof(uint32_t)];
fw_cfg_read(cmd, buf, sizeof(uint32_t));
return __le32_to_cpu(*(uint32_t *)buf);
}
static uint16_t
fw_cfg_read_i16(uint16_t cmd)
{
char buf[sizeof(uint16_t)];
fw_cfg_read(cmd, buf, sizeof(uint16_t));
return __le16_to_cpu(*(uint16_t *)buf);
}
static uint8_t qemu_uuid[16]; static uint8_t qemu_uuid[16];
static void static void
@@ -710,8 +677,7 @@ ob_nvram_init(uint64_t base, uint64_t offset)
fword("finish-device"); fword("finish-device");
fw_cfg_cmd = map_io(CFG_ADDR, CFG_SIZE); fw_cfg_init();
fw_cfg_data = (uint8_t *)fw_cfg_cmd + 2;
fw_cfg_read(FW_CFG_SIGNATURE, buf, 4); fw_cfg_read(FW_CFG_SIGNATURE, buf, 4);
buf[4] = '\0'; buf[4] = '\0';

View File

@@ -30,4 +30,12 @@ void *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
#endif /* NO_QEMU_PROTOS */ #endif /* NO_QEMU_PROTOS */
#ifndef NO_OPENBIOS_PROTOS
void fw_cfg_read(uint16_t cmd, char *buf, unsigned int nbytes);
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);
#endif /* NO_OPENBIOS_PROTOS */
#endif #endif