xref: /openbmc/linux/drivers/xen/acpi.c (revision cfafae94)
1211063dcSKonrad Rzeszutek Wilk /******************************************************************************
2211063dcSKonrad Rzeszutek Wilk  * acpi.c
3211063dcSKonrad Rzeszutek Wilk  * acpi file for domain 0 kernel
4211063dcSKonrad Rzeszutek Wilk  *
5211063dcSKonrad Rzeszutek Wilk  * Copyright (c) 2011 Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
6211063dcSKonrad Rzeszutek Wilk  * Copyright (c) 2011 Yu Ke ke.yu@intel.com
7211063dcSKonrad Rzeszutek Wilk  *
8211063dcSKonrad Rzeszutek Wilk  * This program is free software; you can redistribute it and/or
9211063dcSKonrad Rzeszutek Wilk  * modify it under the terms of the GNU General Public License version 2
10211063dcSKonrad Rzeszutek Wilk  * as published by the Free Software Foundation; or, when distributed
11211063dcSKonrad Rzeszutek Wilk  * separately from the Linux kernel or incorporated into other
12211063dcSKonrad Rzeszutek Wilk  * software packages, subject to the following license:
13211063dcSKonrad Rzeszutek Wilk  *
14211063dcSKonrad Rzeszutek Wilk  * Permission is hereby granted, free of charge, to any person obtaining a copy
15211063dcSKonrad Rzeszutek Wilk  * of this source file (the "Software"), to deal in the Software without
16211063dcSKonrad Rzeszutek Wilk  * restriction, including without limitation the rights to use, copy, modify,
17211063dcSKonrad Rzeszutek Wilk  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
18211063dcSKonrad Rzeszutek Wilk  * and to permit persons to whom the Software is furnished to do so, subject to
19211063dcSKonrad Rzeszutek Wilk  * the following conditions:
20211063dcSKonrad Rzeszutek Wilk  *
21211063dcSKonrad Rzeszutek Wilk  * The above copyright notice and this permission notice shall be included in
22211063dcSKonrad Rzeszutek Wilk  * all copies or substantial portions of the Software.
23211063dcSKonrad Rzeszutek Wilk  *
24211063dcSKonrad Rzeszutek Wilk  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25211063dcSKonrad Rzeszutek Wilk  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26211063dcSKonrad Rzeszutek Wilk  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27211063dcSKonrad Rzeszutek Wilk  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28211063dcSKonrad Rzeszutek Wilk  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29211063dcSKonrad Rzeszutek Wilk  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30211063dcSKonrad Rzeszutek Wilk  * IN THE SOFTWARE.
31211063dcSKonrad Rzeszutek Wilk  */
32211063dcSKonrad Rzeszutek Wilk 
33211063dcSKonrad Rzeszutek Wilk #include <xen/acpi.h>
34211063dcSKonrad Rzeszutek Wilk #include <xen/interface/platform.h>
35211063dcSKonrad Rzeszutek Wilk #include <asm/xen/hypercall.h>
36211063dcSKonrad Rzeszutek Wilk #include <asm/xen/hypervisor.h>
37211063dcSKonrad Rzeszutek Wilk 
xen_acpi_notify_hypervisor_state(u8 sleep_state,u32 val_a,u32 val_b,bool extended)38be6b25d1SBen Guthro static int xen_acpi_notify_hypervisor_state(u8 sleep_state,
39be6b25d1SBen Guthro 					    u32 val_a, u32 val_b,
40be6b25d1SBen Guthro 					    bool extended)
41211063dcSKonrad Rzeszutek Wilk {
42be6b25d1SBen Guthro 	unsigned int bits = extended ? 8 : 16;
43be6b25d1SBen Guthro 
44211063dcSKonrad Rzeszutek Wilk 	struct xen_platform_op op = {
45211063dcSKonrad Rzeszutek Wilk 		.cmd = XENPF_enter_acpi_sleep,
46211063dcSKonrad Rzeszutek Wilk 		.interface_version = XENPF_INTERFACE_VERSION,
47be6b25d1SBen Guthro 		.u.enter_acpi_sleep = {
48be6b25d1SBen Guthro 			.val_a = (u16)val_a,
49be6b25d1SBen Guthro 			.val_b = (u16)val_b,
50211063dcSKonrad Rzeszutek Wilk 			.sleep_state = sleep_state,
51be6b25d1SBen Guthro 			.flags = extended ? XENPF_ACPI_SLEEP_EXTENDED : 0,
52211063dcSKonrad Rzeszutek Wilk 		},
53211063dcSKonrad Rzeszutek Wilk 	};
54211063dcSKonrad Rzeszutek Wilk 
55be6b25d1SBen Guthro 	if (WARN((val_a & (~0 << bits)) || (val_b & (~0 << bits)),
56be6b25d1SBen Guthro 		 "Using more than %u bits of sleep control values %#x/%#x!"
57be6b25d1SBen Guthro 		 "Email xen-devel@lists.xen.org - Thank you.\n", \
58be6b25d1SBen Guthro 		 bits, val_a, val_b))
59211063dcSKonrad Rzeszutek Wilk 		return -1;
60211063dcSKonrad Rzeszutek Wilk 
61cfafae94SStefano Stabellini 	HYPERVISOR_platform_op(&op);
62211063dcSKonrad Rzeszutek Wilk 	return 1;
63211063dcSKonrad Rzeszutek Wilk }
64be6b25d1SBen Guthro 
xen_acpi_notify_hypervisor_sleep(u8 sleep_state,u32 pm1a_cnt,u32 pm1b_cnt)65be6b25d1SBen Guthro int xen_acpi_notify_hypervisor_sleep(u8 sleep_state,
66be6b25d1SBen Guthro 				     u32 pm1a_cnt, u32 pm1b_cnt)
67be6b25d1SBen Guthro {
68be6b25d1SBen Guthro 	return xen_acpi_notify_hypervisor_state(sleep_state, pm1a_cnt,
69be6b25d1SBen Guthro 						pm1b_cnt, false);
70be6b25d1SBen Guthro }
71be6b25d1SBen Guthro 
xen_acpi_notify_hypervisor_extended_sleep(u8 sleep_state,u32 val_a,u32 val_b)72be6b25d1SBen Guthro int xen_acpi_notify_hypervisor_extended_sleep(u8 sleep_state,
73be6b25d1SBen Guthro 				     u32 val_a, u32 val_b)
74be6b25d1SBen Guthro {
75be6b25d1SBen Guthro 	return xen_acpi_notify_hypervisor_state(sleep_state, val_a,
76be6b25d1SBen Guthro 						val_b, true);
77be6b25d1SBen Guthro }
78