aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeir Fraser <keir@xen.org>2010-10-29 18:42:34 +0100
committerKeir Fraser <keir@xen.org>2010-10-29 18:42:34 +0100
commitf0ad21c499f735b1e9b04cf2454ed3808201fc56 (patch)
treeac628efd879ff657f6838c364be1a73319bf2377
parent2911af8256327c067ad8ec05ed5054e9812fc06d (diff)
downloadxen-f0ad21c499f735b1e9b04cf2454ed3808201fc56.tar.gz
xen-f0ad21c499f735b1e9b04cf2454ed3808201fc56.tar.bz2
xen-f0ad21c499f735b1e9b04cf2454ed3808201fc56.zip
x86 hvm: Introduce pmtimer_change_ioport and HVM_PARAM_ACPI_IOPORTS_LOCATION
By default, Xen will handle the old ACPI IO port. But it can switch to the new one by setting the HVM_PARAM_ACPI_IOPORTS_LOCATION to 1. Signed-off-by: Anthony PERARD <anthony.perard@citrix.com> Signed-off-by: Keir Fraser <keir@xen.org>
-rw-r--r--xen/arch/x86/hvm/hvm.c3
-rw-r--r--xen/arch/x86/hvm/intercept.c16
-rw-r--r--xen/arch/x86/hvm/pmtimer.c41
-rw-r--r--xen/include/asm-x86/hvm/io.h12
-rw-r--r--xen/include/asm-x86/hvm/vpt.h1
-rw-r--r--xen/include/public/hvm/ioreq.h20
-rw-r--r--xen/include/public/hvm/params.h13
7 files changed, 82 insertions, 24 deletions
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 472df2f82e..45afb530d6 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -2991,6 +2991,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg)
rc = -EINVAL;
break;
+ case HVM_PARAM_ACPI_IOPORTS_LOCATION:
+ rc = pmtimer_change_ioport(d, a.value);
+ break;
}
if ( rc == 0 )
diff --git a/xen/arch/x86/hvm/intercept.c b/xen/arch/x86/hvm/intercept.c
index 2d88cc86b0..6ce49b6ad8 100644
--- a/xen/arch/x86/hvm/intercept.c
+++ b/xen/arch/x86/hvm/intercept.c
@@ -241,24 +241,18 @@ void register_io_handler(
handler->num_slot++;
}
-void unregister_io_handler(
- struct domain *d, unsigned long addr, unsigned long size, int type)
+void relocate_io_handler(
+ struct domain *d, unsigned long old_addr, unsigned long new_addr,
+ unsigned long size, int type)
{
struct hvm_io_handler *handler = &d->arch.hvm_domain.io_handler;
int i;
for ( i = 0; i < handler->num_slot; i++ )
- if ( (handler->hdl_list[i].addr == addr) &&
+ if ( (handler->hdl_list[i].addr == old_addr) &&
(handler->hdl_list[i].size == size) &&
(handler->hdl_list[i].type == type) )
- goto found;
- return;
-
- found:
- memcpy(&handler->hdl_list[i],
- &handler->hdl_list[handler->num_slot-1],
- sizeof(struct io_handler));
- handler->num_slot--;
+ handler->hdl_list[i].addr = new_addr;
}
/*
diff --git a/xen/arch/x86/hvm/pmtimer.c b/xen/arch/x86/hvm/pmtimer.c
index 1b9ab7ba18..4e8c98d357 100644
--- a/xen/arch/x86/hvm/pmtimer.c
+++ b/xen/arch/x86/hvm/pmtimer.c
@@ -22,8 +22,12 @@
#include <asm/hvm/io.h>
#include <asm/hvm/support.h>
#include <asm/acpi.h> /* for hvm_acpi_power_button prototype */
+#include <public/hvm/params.h>
/* Slightly more readable port I/O addresses for the registers we intercept */
+#define PM1a_STS_ADDR_OLD (ACPI_PM1A_EVT_BLK_ADDRESS_OLD)
+#define PM1a_EN_ADDR_OLD (ACPI_PM1A_EVT_BLK_ADDRESS_OLD + 2)
+#define TMR_VAL_ADDR_OLD (ACPI_PM_TMR_BLK_ADDRESS_OLD)
#define PM1a_STS_ADDR (ACPI_PM1A_EVT_BLK_ADDRESS)
#define PM1a_EN_ADDR (ACPI_PM1A_EVT_BLK_ADDRESS + 2)
#define TMR_VAL_ADDR (ACPI_PM_TMR_BLK_ADDRESS)
@@ -155,16 +159,20 @@ static int handle_evt_io(
switch ( addr )
{
/* PM1a_STS register bits are write-to-clear */
+ case PM1a_STS_ADDR_OLD:
case PM1a_STS_ADDR:
s->pm.pm1a_sts &= ~byte;
break;
+ case PM1a_STS_ADDR_OLD + 1:
case PM1a_STS_ADDR + 1:
s->pm.pm1a_sts &= ~(byte << 8);
break;
+ case PM1a_EN_ADDR_OLD:
case PM1a_EN_ADDR:
s->pm.pm1a_en = (s->pm.pm1a_en & 0xff00) | byte;
break;
+ case PM1a_EN_ADDR_OLD + 1:
case PM1a_EN_ADDR + 1:
s->pm.pm1a_en = (s->pm.pm1a_en & 0xff) | (byte << 8);
break;
@@ -272,6 +280,35 @@ static int pmtimer_load(struct domain *d, hvm_domain_context_t *h)
HVM_REGISTER_SAVE_RESTORE(PMTIMER, pmtimer_save, pmtimer_load,
1, HVMSR_PER_DOM);
+int pmtimer_change_ioport(struct domain *d, unsigned int version)
+{
+ unsigned int old_version;
+
+ /* Check that version is changing. */
+ old_version = d->arch.hvm_domain.params[HVM_PARAM_ACPI_IOPORTS_LOCATION];
+ if ( version == old_version )
+ return 0;
+
+ /* Only allow changes between versions 0 and 1. */
+ if ( (version ^ old_version) != 1 )
+ return -EINVAL;
+
+ if ( version == 1 )
+ {
+ /* Moving from version 0 to version 1. */
+ relocate_portio_handler(d, TMR_VAL_ADDR_OLD, TMR_VAL_ADDR, 4);
+ relocate_portio_handler(d, PM1a_STS_ADDR_OLD, PM1a_STS_ADDR, 4);
+ }
+ else
+ {
+ /* Moving from version 1 to version 0. */
+ relocate_portio_handler(d, TMR_VAL_ADDR, TMR_VAL_ADDR_OLD, 4);
+ relocate_portio_handler(d, PM1a_STS_ADDR, PM1a_STS_ADDR_OLD, 4);
+ }
+
+ return 0;
+}
+
void pmtimer_init(struct vcpu *v)
{
PMTState *s = &v->domain->arch.hvm_domain.pl_time.vpmt;
@@ -284,8 +321,8 @@ void pmtimer_init(struct vcpu *v)
/* Intercept port I/O (need two handlers because PM1a_CNT is between
* PM1a_EN and TMR_VAL and is handled by qemu) */
- register_portio_handler(v->domain, TMR_VAL_ADDR, 4, handle_pmt_io);
- register_portio_handler(v->domain, PM1a_STS_ADDR, 4, handle_evt_io);
+ register_portio_handler(v->domain, TMR_VAL_ADDR_OLD, 4, handle_pmt_io);
+ register_portio_handler(v->domain, PM1a_STS_ADDR_OLD, 4, handle_evt_io);
/* Set up callback to fire SCIs when the MSB of TMR_VAL changes */
init_timer(&s->timer, pmt_timer_callback, s, v->processor);
diff --git a/xen/include/asm-x86/hvm/io.h b/xen/include/asm-x86/hvm/io.h
index 8a81bff225..fe2ecdad0e 100644
--- a/xen/include/asm-x86/hvm/io.h
+++ b/xen/include/asm-x86/hvm/io.h
@@ -69,8 +69,9 @@ int hvm_io_intercept(ioreq_t *p, int type);
void register_io_handler(
struct domain *d, unsigned long addr, unsigned long size,
void *action, int type);
-void unregister_io_handler(
- struct domain *d, unsigned long addr, unsigned long size, int type);
+void relocate_io_handler(
+ struct domain *d, unsigned long old_addr, unsigned long new_addr,
+ unsigned long size, int type);
static inline int hvm_portio_intercept(ioreq_t *p)
{
@@ -92,10 +93,11 @@ static inline void register_portio_handler(
register_io_handler(d, addr, size, action, HVM_PORTIO);
}
-static inline void unregister_portio_handler(
- struct domain *d, unsigned long addr, unsigned long size)
+static inline void relocate_portio_handler(
+ struct domain *d, unsigned long old_addr, unsigned long new_addr,
+ unsigned long size)
{
- unregister_io_handler(d, addr, size, HVM_PORTIO);
+ relocate_io_handler(d, old_addr, new_addr, size, HVM_PORTIO);
}
static inline void register_buffered_io_handler(
diff --git a/xen/include/asm-x86/hvm/vpt.h b/xen/include/asm-x86/hvm/vpt.h
index 65b0dffb98..0fe8dbfd7e 100644
--- a/xen/include/asm-x86/hvm/vpt.h
+++ b/xen/include/asm-x86/hvm/vpt.h
@@ -179,6 +179,7 @@ void rtc_update_clock(struct domain *d);
void pmtimer_init(struct vcpu *v);
void pmtimer_deinit(struct domain *d);
void pmtimer_reset(struct domain *d);
+int pmtimer_change_ioport(struct domain *d, unsigned int version);
void hpet_init(struct vcpu *v);
void hpet_deinit(struct domain *d);
diff --git a/xen/include/public/hvm/ioreq.h b/xen/include/public/hvm/ioreq.h
index 0c10c08a6d..9b67bf09c5 100644
--- a/xen/include/public/hvm/ioreq.h
+++ b/xen/include/public/hvm/ioreq.h
@@ -100,11 +100,21 @@ struct buffered_piopage {
};
#endif /* defined(__ia64__) */
-#define ACPI_PM1A_EVT_BLK_ADDRESS 0x0000000000001f40
-#define ACPI_PM1A_CNT_BLK_ADDRESS (ACPI_PM1A_EVT_BLK_ADDRESS + 0x04)
-#define ACPI_PM_TMR_BLK_ADDRESS (ACPI_PM1A_EVT_BLK_ADDRESS + 0x08)
-#define ACPI_GPE0_BLK_ADDRESS (ACPI_PM_TMR_BLK_ADDRESS + 0x20)
-#define ACPI_GPE0_BLK_LEN 0x08
+/*
+ * Value used by old qemu-dm, there have been replace to match
+ * the QEMU BIOS.
+ */
+#define ACPI_PM1A_EVT_BLK_ADDRESS_OLD 0x1f40
+#define ACPI_PM1A_CNT_BLK_ADDRESS_OLD (ACPI_PM1A_EVT_BLK_ADDRESS_OLD + 0x04)
+#define ACPI_PM_TMR_BLK_ADDRESS_OLD (ACPI_PM1A_EVT_BLK_ADDRESS_OLD + 0x08)
+#define ACPI_GPE0_BLK_ADDRESS_OLD (ACPI_PM_TMR_BLK_ADDRESS_OLD + 0x20)
+#define ACPI_GPE0_BLK_LEN_OLD 0x08
+
+#define ACPI_PM1A_EVT_BLK_ADDRESS 0xb000
+#define ACPI_PM1A_CNT_BLK_ADDRESS (ACPI_PM1A_EVT_BLK_ADDRESS + 0x04)
+#define ACPI_PM_TMR_BLK_ADDRESS (ACPI_PM1A_EVT_BLK_ADDRESS + 0x08)
+#define ACPI_GPE0_BLK_ADDRESS 0xafe0
+#define ACPI_GPE0_BLK_LEN 0x04
#endif /* _IOREQ_H_ */
diff --git a/xen/include/public/hvm/params.h b/xen/include/public/hvm/params.h
index 673148bbfa..2359f33fe9 100644
--- a/xen/include/public/hvm/params.h
+++ b/xen/include/public/hvm/params.h
@@ -113,6 +113,17 @@
#define HVM_PARAM_CONSOLE_PFN 17
#define HVM_PARAM_CONSOLE_EVTCHN 18
-#define HVM_NR_PARAMS 19
+/*
+ * Select location of ACPI PM1a and TMR control blocks. Currently two locations
+ * are supported, specified by version 0 or 1 in this parameter:
+ * - 0: default, use the old addresses
+ * PM1A_EVT == 0x1f40; PM1A_CNT == 0x1f44; PM_TMR == 0x1f48
+ * - 1: use the new default qemu addresses
+ * PM1A_EVT == 0xb000; PM1A_CNT == 0xb004; PM_TMR == 0xb008
+ * You can find these address definitions in <hvm/ioreq.h>
+ */
+#define HVM_PARAM_ACPI_IOPORTS_LOCATION 19
+
+#define HVM_NR_PARAMS 20
#endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */