Konrad Rzeszutek Wilk
2011-Nov-15 21:31 UTC
[Xen-devel] [PATCH] ACPI cleanup''s and enablement for Xen ACPI S3 [v3]
Attached is an [v3] set of patches to enable S3 to work with the Xen hypervisor. Changes since v2: [https://lkml.org/lkml/2011/9/29/408] - Moved tboot_sleep out to the osl.c code. - Dropped some patches. since the RFC posting [http://comments.gmane.org/gmane.linux.acpi.devel/50701]: - Per review comments added: __unused__ attribute, support for PM1A/B if more than 16-bit, copyright/license. - Added support for PHYSDEVOP_restore_msi_ext call. The first two patches can be considered independently as cleanup - they move the tboot_sleep out of the ACPI code and move it in the OS part. That is the OSPM code changes required. The more complex ones are in the ACPI x86 code. I was not sure how to post the patches so I grouped in the "functionality" parts. 1). Use the acpi_os_prepare_sleep to register a variant of it. The reason for the need for this is explained in more details below. The patches are: [PATCH 1/7] x86, acpi, tboot: Have a ACPI os prepare sleep instead [PATCH 2/7] tboot: Add return values for tboot_sleep [PATCH 3/7] xen/acpi/sleep: Enable ACPI sleep via the 2). Expand x86_msi_ops. Every time we resume, we end up calling write_msi_irq to resume the MSI vectors. But when using Xen, we would write the MSI vectors using the other x86_msi_ops - hence we expand the x86_msi_ops indirection mechanism to take resume in account. The paches are: [PATCH 4/7] x86: Expand the x86_msi_ops to have a restore MSIs. [PATCH 5/7] xen/pci: Utilize the restore_msi_irqs hook. 3). Make acpi_suspend_lowlevel be a function pointer instead of a function. Details of why we want to omit the lowlevel values is explained below. Originally I was thinking that perhaps doing it via a registration function would be better? But not sure what folks leanings are in this case. The patches are: [PATCH 6/7] x86/acpi/sleep: Provide registration for [PATCH 7/7] xen/acpi/sleep: Register to the acpi_suspend_lowlevel a Details of what I said in the first postings: The Xen ACPI S3 functionality requires help from the Linux kernel. The Linux kernel does the ACPI "stuff" and tells the hypervisor to do the low-level stuff (such as program the IOAPIC, setup vectors, etc). Naturally do it correctly the Xen hypervisor must be programmed with correct values that are extracted as part of parsing the ACPI. The ACPI code used during suspend is mostly all in hwsleep.c and there is one particular case where ''hwsleep.c'' is calling in the tboot.c code. This is replaced by making the call go through the OS part of the ACPI code. The reason for doing this is two fold: 1) cleanup, 2) for Xen case, it needs to make a hypercall so that the hypervisor can write the PM1A/PM1B bits. The major difficulties we hit was with ''acpi_suspend_lowlevel'' - which tweaks a lot of lowlevel values and some of them are not properly handled by Xen. Liang Tang has figured which ones of them we trip over (read below) - and he suggested that perhaps we can provide a registration mechanism to abstract this away. The reason for all of this is that Linux does not talk to the BIOS directly - instead it simply walks through the necessary ACPI methods and then issues hypercall to Xen which then further completes the remaining suspend steps. So the attached patches do exactly that - there are two entry points in the ACPI. 1). For S3: acpi_suspend_lowlevel -> .. lots of code -> acpi_enter_sleep_state 2). For S1/S4/S5: acpi_enter_sleep_state The first naive idea was of abstracting away in the ''acpi_enter_sleep_state'' function the tboot_sleep code so that we can use it too. And low-behold - it worked splendidly for powering off (S5 I believe) For S3 that did not work - during suspend the hypervisor tripped over when saving cr8. During resume it tripped over at restoring the cr3, cr8, idt, and gdt values. When I posted the RFC, the feedback I got was to use a higher upper interface to make the call to the hypervisor. Instead of doing it at the lower pv-ops case for cr3, cr8, idt, gdt, etc. The code is much nicer this way, I''ve to say. Anyhow, please take a look! The patches are also located at git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen.git devel/acpi-s3.v5 Konrad Rzeszutek Wilk (5): tboot: Add return values for tboot_sleep xen/acpi/sleep: Enable ACPI sleep via the acpi_os_prepare_sleep_register x86: Expand the x86_msi_ops to have a restore MSIs. x86/acpi/sleep: Provide registration for acpi_suspend_lowlevel xen/acpi/sleep: Register to the acpi_suspend_lowlevel a callback. Tang Liang (2): x86, acpi, tboot: Have a ACPI os prepare sleep instead of calling tboot_sleep. xen/pci: Utilize the restore_msi_irqs hook. arch/x86/include/asm/acpi.h | 2 +- arch/x86/include/asm/pci.h | 9 +++++ arch/x86/include/asm/x86_init.h | 1 + arch/x86/kernel/acpi/boot.c | 2 + arch/x86/kernel/acpi/sleep.c | 4 +- arch/x86/kernel/acpi/sleep.h | 2 + arch/x86/kernel/tboot.c | 18 ++++++++-- arch/x86/kernel/x86_init.c | 1 + arch/x86/pci/xen.c | 27 ++++++++++++++ arch/x86/xen/enlighten.c | 3 ++ drivers/acpi/acpica/hwsleep.c | 7 ++-- drivers/acpi/osl.c | 19 ++++++++++ drivers/acpi/sleep.c | 2 + drivers/pci/msi.c | 29 ++++++++++++++- drivers/xen/Makefile | 2 +- drivers/xen/acpi.c | 62 ++++++++++++++++++++++++++++++++ include/acpi/acpiosxf.h | 6 +++ include/linux/tboot.h | 3 -- include/xen/acpi.h | 74 +++++++++++++++++++++++++++++++++++++++ include/xen/interface/physdev.h | 7 ++++ 20 files changed, 265 insertions(+), 15 deletions(-) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Konrad Rzeszutek Wilk
2011-Nov-15 21:31 UTC
[Xen-devel] [PATCH 1/7] x86, acpi, tboot: Have a ACPI os prepare sleep instead of calling tboot_sleep.
From: Tang Liang <liang.tang@oracle.com> The ACPI suspend path makes a call to tboot_sleep right before it writes the PM1A, PM1B values. We replace the direct call to tboot via an registration callback similar to __acpi_register_gsi. As part of this, the tboot_sleep need only to register with the acpi_os_prepare_sleep_register and if it not (on IA64) then it simply won''t be called. We can also remove the tboot_sleep declerations. [v1: Added __attribute__ ((unused))] [v2: Introduced a wrapper instead of changing tboot_sleep return values] Signed-off-by: Tang Liang <liang.tang@oracle.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> --- arch/x86/kernel/tboot.c | 9 +++++++++ drivers/acpi/acpica/hwsleep.c | 7 ++++--- drivers/acpi/osl.c | 19 +++++++++++++++++++ include/acpi/acpiosxf.h | 6 ++++++ include/linux/tboot.h | 3 --- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c index e2410e2..751d673 100644 --- a/arch/x86/kernel/tboot.c +++ b/arch/x86/kernel/tboot.c @@ -31,6 +31,7 @@ #include <linux/pfn.h> #include <linux/mm.h> #include <linux/tboot.h> +#include <acpi/acpiosxf.h> #include <asm/trampoline.h> #include <asm/processor.h> @@ -297,6 +298,12 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control) tboot_shutdown(acpi_shutdown_map[sleep_state]); } +static acpi_status tboot_sleep_wrapper(u8 sleep_state, u32 pm1a_control, + u32 pm1b_control) +{ + tboot_sleep(sleep_state, pm1a_control, pm1b_control); + return AE_OK; +} static atomic_t ap_wfs_count; @@ -345,6 +352,8 @@ static __init int tboot_late_init(void) atomic_set(&ap_wfs_count, 0); register_hotcpu_notifier(&tboot_cpu_notifier); + + acpi_os_prepare_sleep_register(&tboot_sleep_wrapper); return 0; } diff --git a/drivers/acpi/acpica/hwsleep.c b/drivers/acpi/acpica/hwsleep.c index d52da30..b10bc90 100644 --- a/drivers/acpi/acpica/hwsleep.c +++ b/drivers/acpi/acpica/hwsleep.c @@ -45,7 +45,6 @@ #include <acpi/acpi.h> #include "accommon.h" #include "actables.h" -#include <linux/tboot.h> #include <linux/module.h> #define _COMPONENT ACPI_HARDWARE @@ -344,8 +343,10 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state) ACPI_FLUSH_CPU_CACHE(); - tboot_sleep(sleep_state, pm1a_control, pm1b_control); - + status = acpi_os_prepare_sleep(sleep_state, pm1a_control, + pm1b_control); + if (ACPI_FAILURE(status)) + return_ACPI_STATUS(status); /* Write #2: Write both SLP_TYP + SLP_EN */ status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control); diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index f31c5c5..40daa68 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -1659,3 +1659,22 @@ acpi_status acpi_os_terminate(void) return AE_OK; } + +acpi_status (*__acpi_os_prepare_sleep)(u8 sleep_state, u32 pm1a_ctrl, + u32 pm1b_ctrl); + +acpi_status acpi_os_prepare_sleep(u8 sleep_state, u32 pm1a_control, + u32 pm1b_control) +{ + if (__acpi_os_prepare_sleep) + return __acpi_os_prepare_sleep(sleep_state, pm1a_control, + pm1b_control); + else + return AE_OK; +} + +void acpi_os_prepare_sleep_register(acpi_status (*func)(u8 sleep_state, + u32 pm1a_ctrl, u32 pm1b_ctrl)) +{ + __acpi_os_prepare_sleep = func; +} diff --git a/include/acpi/acpiosxf.h b/include/acpi/acpiosxf.h index 83062ed..ebde1e1 100644 --- a/include/acpi/acpiosxf.h +++ b/include/acpi/acpiosxf.h @@ -108,6 +108,12 @@ void acpi_os_delete_lock(acpi_spinlock handle); acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock handle); +void acpi_os_prepare_sleep_register(acpi_status (*func)(u8 sleep_state, + u32 pm1a_ctrl, u32 pm1b_ctrl)); + +acpi_status acpi_os_prepare_sleep(u8 sleep_state, u32 pm1a_control, + u32 pm1b_control); + void acpi_os_release_lock(acpi_spinlock handle, acpi_cpu_flags flags); /* diff --git a/include/linux/tboot.h b/include/linux/tboot.h index 1dba6ee..d57732d 100644 --- a/include/linux/tboot.h +++ b/include/linux/tboot.h @@ -143,7 +143,6 @@ static inline int tboot_enabled(void) extern void tboot_probe(void); extern void tboot_shutdown(u32 shutdown_type); -extern void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control); extern struct acpi_table_header *tboot_get_dmar_table( struct acpi_table_header *dmar_tbl); extern int tboot_force_iommu(void); @@ -153,8 +152,6 @@ extern int tboot_force_iommu(void); #define tboot_enabled() 0 #define tboot_probe() do { } while (0) #define tboot_shutdown(shutdown_type) do { } while (0) -#define tboot_sleep(sleep_state, pm1a_control, pm1b_control) \ - do { } while (0) #define tboot_get_dmar_table(dmar_tbl) (dmar_tbl) #define tboot_force_iommu() 0 -- 1.7.7.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Konrad Rzeszutek Wilk
2011-Nov-15 21:31 UTC
[Xen-devel] [PATCH 2/7] tboot: Add return values for tboot_sleep
. as appropiately. As tboot_sleep now returns values, we are free to remove the tboot_sleep_wrapper function altogether. Suggested-by: "Rafael J. Wysocki" <rjw@sisk.pl> CC: Joseph Cihula <joseph.cihula@intel.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> --- arch/x86/kernel/tboot.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c index 751d673..5ab5362 100644 --- a/arch/x86/kernel/tboot.c +++ b/arch/x86/kernel/tboot.c @@ -273,7 +273,8 @@ static void tboot_copy_fadt(const struct acpi_table_fadt *fadt) offsetof(struct acpi_table_facs, firmware_waking_vector); } -void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control) +static acpi_status tboot_sleep(u8 sleep_state, u32 pm1a_control, + u32 pm1b_control) { static u32 acpi_shutdown_map[ACPI_S_STATE_COUNT] = { /* S0,1,2: */ -1, -1, -1, @@ -282,7 +283,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control) /* S5: */ TB_SHUTDOWN_S5 }; if (!tboot_enabled()) - return; + return AE_OK; tboot_copy_fadt(&acpi_gbl_FADT); tboot->acpi_sinfo.pm1a_cnt_val = pm1a_control; @@ -293,10 +294,12 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control) if (sleep_state >= ACPI_S_STATE_COUNT || acpi_shutdown_map[sleep_state] == -1) { pr_warning("unsupported sleep state 0x%x\n", sleep_state); - return; + return AE_ERROR; } tboot_shutdown(acpi_shutdown_map[sleep_state]); + + return AE_OK; } static acpi_status tboot_sleep_wrapper(u8 sleep_state, u32 pm1a_control, u32 pm1b_control) @@ -353,7 +356,7 @@ static __init int tboot_late_init(void) atomic_set(&ap_wfs_count, 0); register_hotcpu_notifier(&tboot_cpu_notifier); - acpi_os_prepare_sleep_register(&tboot_sleep_wrapper); + acpi_os_prepare_sleep_register(&tboot_sleep); return 0; } -- 1.7.7.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Konrad Rzeszutek Wilk
2011-Nov-15 21:31 UTC
[Xen-devel] [PATCH 3/7] xen/acpi/sleep: Enable ACPI sleep via the acpi_os_prepare_sleep_register
Provide the registration callback to call in the Xen''s ACPI sleep functionality. This means that during S3/S5 we make a hypercall XENPF_enter_acpi_sleep with the proper PM1A/PM1B registers. Based of Ke Yu''s <ke.yu@intel.com> initial idea. [ From http://xenbits.xensource.com/linux-2.6.18-xen.hg change c68699484a65 ] [v1: Added Copyright and license] [v2: Added check if PM1A/B the 16-bits MSB contain something. The spec only uses 16-bits but might have more in future] Signed-off-by: Liang Tang <liang.tang@oracle.com> [v1: Improved the git commit description] Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> --- arch/x86/xen/enlighten.c | 3 ++ drivers/xen/Makefile | 2 +- drivers/xen/acpi.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ include/xen/acpi.h | 59 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 1 deletions(-) create mode 100644 drivers/xen/acpi.c create mode 100644 include/xen/acpi.h diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index da8afd5..bb0c864 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@ -42,6 +42,7 @@ #include <xen/page.h> #include <xen/hvm.h> #include <xen/hvc-console.h> +#include <xen/acpi.h> #include <asm/paravirt.h> #include <asm/apic.h> @@ -1277,6 +1278,8 @@ asmlinkage void __init xen_start_kernel(void) /* Make sure ACS will be enabled */ pci_request_acs(); + + xen_acpi_sleep_register(); } diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile index 974fffd..0435996 100644 --- a/drivers/xen/Makefile +++ b/drivers/xen/Makefile @@ -17,7 +17,7 @@ obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o obj-$(CONFIG_XEN_PVHVM) += platform-pci.o obj-$(CONFIG_XEN_TMEM) += tmem.o obj-$(CONFIG_SWIOTLB_XEN) += swiotlb-xen.o -obj-$(CONFIG_XEN_DOM0) += pci.o +obj-$(CONFIG_XEN_DOM0) += pci.o acpi.o obj-$(CONFIG_XEN_PCIDEV_BACKEND) += xen-pciback/ xen-evtchn-y := evtchn.o diff --git a/drivers/xen/acpi.c b/drivers/xen/acpi.c new file mode 100644 index 0000000..9f81a0f --- /dev/null +++ b/drivers/xen/acpi.c @@ -0,0 +1,62 @@ +/****************************************************************************** + * acpi.c + * acpi file for domain 0 kernel + * + * Copyright (c) 2011 Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> + * Copyright (c) 2011 Yu Ke ke.yu@intel.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation; or, when distributed + * separately from the Linux kernel or incorporated into other + * software packages, subject to the following license: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this source file (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include <xen/acpi.h> +#include <xen/interface/platform.h> +#include <asm/xen/hypercall.h> +#include <asm/xen/hypervisor.h> + +acpi_status xen_acpi_notify_hypervisor_state(u8 sleep_state, + u32 pm1a_cnt, u32 pm1b_cnt) +{ + struct xen_platform_op op = { + .cmd = XENPF_enter_acpi_sleep, + .interface_version = XENPF_INTERFACE_VERSION, + .u = { + .enter_acpi_sleep = { + .pm1a_cnt_val = (u16)pm1a_cnt, + .pm1b_cnt_val = (u16)pm1b_cnt, + .sleep_state = sleep_state, + }, + }, + }; + + if ((pm1a_cnt & 0xffff0000) || (pm1b_cnt & 0xffff0000)) { + WARN(1, "Using more than 16bits of PM1A/B 0x%x/0x%x!" + "Email xen-devel@lists.xensource.com Thank you.\n", \ + pm1a_cnt, pm1b_cnt); + return AE_ERROR; + } + + HYPERVISOR_dom0_op(&op); + return AE_ERROR; +} diff --git a/include/xen/acpi.h b/include/xen/acpi.h new file mode 100644 index 0000000..69a6890 --- /dev/null +++ b/include/xen/acpi.h @@ -0,0 +1,59 @@ +/****************************************************************************** + * acpi.h + * acpi file for domain 0 kernel + * + * Copyright (c) 2011 Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> + * Copyright (c) 2011 Yu Ke <ke.yu@intel.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation; or, when distributed + * separately from the Linux kernel or incorporated into other + * software packages, subject to the following license: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this source file (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef _XEN_ACPI_H +#define _XEN_ACPI_H + +#include <linux/types.h> + +#ifdef CONFIG_XEN_DOM0 +#include <asm/xen/hypervisor.h> +#include <xen/xen.h> +#include <linux/acpi.h> +#include <acpi/acpiosxf.h> + +acpi_status xen_acpi_notify_hypervisor_state(u8 sleep_state, + u32 pm1a_cnt, u32 pm1b_cnd); + +static inline void xen_acpi_sleep_register(void) +{ + if (xen_initial_domain()) + acpi_os_prepare_sleep_register( + &xen_acpi_notify_hypervisor_state); +} +#else +static inline void xen_acpi_sleep_register(void) +{ +} +#endif + +#endif /* _XEN_ACPI_H */ -- 1.7.7.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Konrad Rzeszutek Wilk
2011-Nov-15 21:31 UTC
[Xen-devel] [PATCH 4/7] x86: Expand the x86_msi_ops to have a restore MSIs.
The MSI restore function will become a function pointer in an x86_msi_ops struct. It defaults to the implementation in the io_apic.c and msi.c. We piggyback on the indirection mechanism introduced by "x86: Introduce x86_msi_ops". Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> --- arch/x86/include/asm/pci.h | 9 +++++++++ arch/x86/include/asm/x86_init.h | 1 + arch/x86/kernel/x86_init.c | 1 + drivers/pci/msi.c | 29 +++++++++++++++++++++++++++-- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/pci.h b/arch/x86/include/asm/pci.h index d498943..df75d07 100644 --- a/arch/x86/include/asm/pci.h +++ b/arch/x86/include/asm/pci.h @@ -112,19 +112,28 @@ static inline void x86_teardown_msi_irq(unsigned int irq) { x86_msi.teardown_msi_irq(irq); } +static inline void x86_restore_msi_irqs(struct pci_dev *dev, int irq) +{ + x86_msi.restore_msi_irqs(dev, irq); +} #define arch_setup_msi_irqs x86_setup_msi_irqs #define arch_teardown_msi_irqs x86_teardown_msi_irqs #define arch_teardown_msi_irq x86_teardown_msi_irq +#define arch_restore_msi_irqs x86_restore_msi_irqs /* implemented in arch/x86/kernel/apic/io_apic. */ int native_setup_msi_irqs(struct pci_dev *dev, int nvec, int type); void native_teardown_msi_irq(unsigned int irq); +void native_restore_msi_irqs(struct pci_dev *dev, int irq); /* default to the implementation in drivers/lib/msi.c */ #define HAVE_DEFAULT_MSI_TEARDOWN_IRQS +#define HAVE_DEFAULT_MSI_RESTORE_IRQS void default_teardown_msi_irqs(struct pci_dev *dev); +void default_restore_msi_irqs(struct pci_dev *dev, int irq); #else #define native_setup_msi_irqs NULL #define native_teardown_msi_irq NULL #define default_teardown_msi_irqs NULL +#define default_restore_msi_irqs NULL #endif #define PCI_DMA_BUS_IS_PHYS (dma_ops->is_phys) diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h index d3d8590..7af18be 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -174,6 +174,7 @@ struct x86_msi_ops { int (*setup_msi_irqs)(struct pci_dev *dev, int nvec, int type); void (*teardown_msi_irq)(unsigned int irq); void (*teardown_msi_irqs)(struct pci_dev *dev); + void (*restore_msi_irqs)(struct pci_dev *dev, int irq); }; extern struct x86_init_ops x86_init; diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index 6f164bd..bd1fe10 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -110,4 +110,5 @@ struct x86_msi_ops x86_msi = { .setup_msi_irqs = native_setup_msi_irqs, .teardown_msi_irq = native_teardown_msi_irq, .teardown_msi_irqs = default_teardown_msi_irqs, + .restore_msi_irqs = default_restore_msi_irqs, }; diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 0e6d04d..ba2ea4e 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -86,6 +86,31 @@ void default_teardown_msi_irqs(struct pci_dev *dev) } #endif +#ifndef arch_restore_msi_irqs +# define arch_restore_msi_irqs default_restore_msi_irqs +# define HAVE_DEFAULT_MSI_RESTORE_IRQS +#endif + +#ifdef HAVE_DEFAULT_MSI_RESTORE_IRQS +void default_restore_msi_irqs(struct pci_dev *dev, int irq) +{ + struct msi_desc *entry; + + entry = NULL; + if (dev->msix_enabled) { + list_for_each_entry(entry, &dev->msi_list, list) { + if (irq == entry->irq) + break; + } + } else if (dev->msi_enabled) { + entry = irq_get_msi_desc(irq); + } + + if (entry) + write_msi_msg(irq, &entry->msg); +} +#endif + static void msi_set_enable(struct pci_dev *dev, int pos, int enable) { u16 control; @@ -360,7 +385,7 @@ static void __pci_restore_msi_state(struct pci_dev *dev) pci_intx_for_msi(dev, 0); msi_set_enable(dev, pos, 0); - write_msi_msg(dev->irq, &entry->msg); + arch_restore_msi_irqs(dev, dev->irq); pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control); msi_mask_irq(entry, msi_capable_mask(control), entry->masked); @@ -388,7 +413,7 @@ static void __pci_restore_msix_state(struct pci_dev *dev) pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control); list_for_each_entry(entry, &dev->msi_list, list) { - write_msi_msg(entry->irq, &entry->msg); + arch_restore_msi_irqs(dev, entry->irq); msix_mask_irq(entry, entry->masked); } -- 1.7.7.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Konrad Rzeszutek Wilk
2011-Nov-15 21:31 UTC
[Xen-devel] [PATCH 5/7] xen/pci: Utilize the restore_msi_irqs hook.
From: Tang Liang <liang.tang@oracle.com> to make a hypercall to restore the vectors in the MSI/MSI-X configuration space. Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> --- arch/x86/pci/xen.c | 27 +++++++++++++++++++++++++++ include/xen/interface/physdev.h | 7 +++++++ 2 files changed, 34 insertions(+), 0 deletions(-) diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c index 492ade8..249a5ae 100644 --- a/arch/x86/pci/xen.c +++ b/arch/x86/pci/xen.c @@ -324,6 +324,32 @@ static int xen_initdom_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) out: return ret; } + +static void xen_initdom_restore_msi_irqs(struct pci_dev *dev, int irq) +{ + int ret = 0; + + if (pci_seg_supported) { + struct physdev_pci_device restore_ext; + + restore_ext.seg = pci_domain_nr(dev->bus); + restore_ext.bus = dev->bus->number; + restore_ext.devfn = dev->devfn; + ret = HYPERVISOR_physdev_op(PHYSDEVOP_restore_msi_ext, + &restore_ext); + if (ret == -ENOSYS) + pci_seg_supported = false; + WARN(ret && ret != -ENOSYS, "restore_msi_ext -> %d\n", ret); + } + if (!pci_seg_supported) { + struct physdev_restore_msi restore; + + restore.bus = dev->bus->number; + restore.devfn = dev->devfn; + ret = HYPERVISOR_physdev_op(PHYSDEVOP_restore_msi, &restore); + WARN(ret && ret != -ENOSYS, "restore_msi -> %d\n", ret); + } +} #endif static void xen_teardown_msi_irqs(struct pci_dev *dev) @@ -446,6 +472,7 @@ int __init pci_xen_initial_domain(void) #ifdef CONFIG_PCI_MSI x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs; x86_msi.teardown_msi_irq = xen_teardown_msi_irq; + x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs; #endif xen_setup_acpi_sci(); __acpi_register_gsi = acpi_register_gsi_xen; diff --git a/include/xen/interface/physdev.h b/include/xen/interface/physdev.h index c1080d9..0c28989 100644 --- a/include/xen/interface/physdev.h +++ b/include/xen/interface/physdev.h @@ -145,6 +145,13 @@ struct physdev_manage_pci { uint8_t devfn; }; +#define PHYSDEVOP_restore_msi 19 +struct physdev_restore_msi { + /* IN */ + uint8_t bus; + uint8_t devfn; +}; + #define PHYSDEVOP_manage_pci_add_ext 20 struct physdev_manage_pci_ext { /* IN */ -- 1.7.7.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Konrad Rzeszutek Wilk
2011-Nov-15 21:31 UTC
[Xen-devel] [PATCH 6/7] x86/acpi/sleep: Provide registration for acpi_suspend_lowlevel
Which by default will be x86_acpi_suspend_lowlevel. This registration allows us to register another callback if there is a need to use another platform specific callback. Signed-off-by: Liang Tang <liang.tang@oracle.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> --- arch/x86/include/asm/acpi.h | 2 +- arch/x86/kernel/acpi/boot.c | 2 ++ arch/x86/kernel/acpi/sleep.c | 4 ++-- arch/x86/kernel/acpi/sleep.h | 2 ++ drivers/acpi/sleep.c | 2 ++ 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/acpi.h b/arch/x86/include/asm/acpi.h index 610001d..68cf060 100644 --- a/arch/x86/include/asm/acpi.h +++ b/arch/x86/include/asm/acpi.h @@ -115,7 +115,7 @@ static inline void acpi_disable_pci(void) } /* Low-level suspend routine. */ -extern int acpi_suspend_lowlevel(void); +extern int (*acpi_suspend_lowlevel)(void); extern const unsigned char acpi_wakeup_code[]; #define acpi_wakeup_address (__pa(TRAMPOLINE_SYM(acpi_wakeup_code))) diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c index 4558f0d..eb85e88 100644 --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -44,6 +44,7 @@ #include <asm/mpspec.h> #include <asm/smp.h> +#include "sleep.h" /* To include x86_acpi_suspend_lowlevel */ static int __initdata acpi_force = 0; u32 acpi_rsdt_forced; int acpi_disabled; @@ -552,6 +553,7 @@ static int acpi_register_gsi_ioapic(struct device *dev, u32 gsi, int (*__acpi_register_gsi)(struct device *dev, u32 gsi, int trigger, int polarity) = acpi_register_gsi_pic; +int (*acpi_suspend_lowlevel)(void) = x86_acpi_suspend_lowlevel; /* * success: return IRQ number (>=0) * failure: return < 0 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c index 103b6ab..4d2d0b1 100644 --- a/arch/x86/kernel/acpi/sleep.c +++ b/arch/x86/kernel/acpi/sleep.c @@ -25,12 +25,12 @@ static char temp_stack[4096]; #endif /** - * acpi_suspend_lowlevel - save kernel state + * x86_acpi_suspend_lowlevel - save kernel state * * Create an identity mapped page table and copy the wakeup routine to * low memory. */ -int acpi_suspend_lowlevel(void) +int x86_acpi_suspend_lowlevel(void) { struct wakeup_header *header; /* address in low memory of the wakeup routine. */ diff --git a/arch/x86/kernel/acpi/sleep.h b/arch/x86/kernel/acpi/sleep.h index 416d4be..4d3feb5 100644 --- a/arch/x86/kernel/acpi/sleep.h +++ b/arch/x86/kernel/acpi/sleep.h @@ -13,3 +13,5 @@ extern unsigned long acpi_copy_wakeup_routine(unsigned long); extern void wakeup_long64(void); extern void do_suspend_lowlevel(void); + +extern int x86_acpi_suspend_lowlevel(void); diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c index 6d9a3ab..b8b26e8 100644 --- a/drivers/acpi/sleep.c +++ b/drivers/acpi/sleep.c @@ -254,6 +254,8 @@ static int acpi_suspend_enter(suspend_state_t pm_state) break; case ACPI_STATE_S3: + if (!acpi_suspend_lowlevel) + return -ENODEV; error = acpi_suspend_lowlevel(); if (error) return error; -- 1.7.7.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Konrad Rzeszutek Wilk
2011-Nov-15 21:31 UTC
[Xen-devel] [PATCH 7/7] xen/acpi/sleep: Register to the acpi_suspend_lowlevel a callback.
We piggyback on "x86/acpi: Provide registration for acpi_suspend_lowlevel." to register a Xen version of the callback. The callback does not do anything special - except it omits the x86_acpi_suspend_lowlevel. It does that b/c during suspend it tries to save cr8 values (which the hypervisor does not support), and then on resume path the cr3, cr8, idt, and gdt are all resumed which clashes with what the hypervisor has set up for the guest. Signed-off-by: Liang Tang <liang.tang@oracle.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> --- include/xen/acpi.h | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/include/xen/acpi.h b/include/xen/acpi.h index 69a6890..832b5e5 100644 --- a/include/xen/acpi.h +++ b/include/xen/acpi.h @@ -44,11 +44,26 @@ acpi_status xen_acpi_notify_hypervisor_state(u8 sleep_state, u32 pm1a_cnt, u32 pm1b_cnd); +static inline int xen_acpi_suspend_lowlevel(void) +{ + /* + * Xen will save and restore CPU context, so + * we can skip that and just go straight to + * the suspend. + */ + acpi_enter_sleep_state(ACPI_STATE_S3); + return 0; +} + + static inline void xen_acpi_sleep_register(void) { - if (xen_initial_domain()) + if (xen_initial_domain()){ acpi_os_prepare_sleep_register( &xen_acpi_notify_hypervisor_state); + + acpi_suspend_lowlevel = xen_acpi_suspend_lowlevel; + } } #else static inline void xen_acpi_sleep_register(void) -- 1.7.7.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel