18c2ecf20Sopenharmony_ci/******************************************************************************
28c2ecf20Sopenharmony_ci * acpi.h
38c2ecf20Sopenharmony_ci * acpi file for domain 0 kernel
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2011 Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
68c2ecf20Sopenharmony_ci * Copyright (c) 2011 Yu Ke <ke.yu@intel.com>
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or
98c2ecf20Sopenharmony_ci * modify it under the terms of the GNU General Public License version 2
108c2ecf20Sopenharmony_ci * as published by the Free Software Foundation; or, when distributed
118c2ecf20Sopenharmony_ci * separately from the Linux kernel or incorporated into other
128c2ecf20Sopenharmony_ci * software packages, subject to the following license:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy
158c2ecf20Sopenharmony_ci * of this source file (the "Software"), to deal in the Software without
168c2ecf20Sopenharmony_ci * restriction, including without limitation the rights to use, copy, modify,
178c2ecf20Sopenharmony_ci * merge, publish, distribute, sublicense, and/or sell copies of the Software,
188c2ecf20Sopenharmony_ci * and to permit persons to whom the Software is furnished to do so, subject to
198c2ecf20Sopenharmony_ci * the following conditions:
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
228c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
258c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
268c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
278c2ecf20Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
288c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
298c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
308c2ecf20Sopenharmony_ci * IN THE SOFTWARE.
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#ifndef _XEN_ACPI_H
348c2ecf20Sopenharmony_ci#define _XEN_ACPI_H
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#include <linux/types.h>
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#ifdef CONFIG_XEN_DOM0
398c2ecf20Sopenharmony_ci#include <asm/xen/hypervisor.h>
408c2ecf20Sopenharmony_ci#include <xen/xen.h>
418c2ecf20Sopenharmony_ci#include <linux/acpi.h>
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define ACPI_MEMORY_DEVICE_CLASS        "memory"
448c2ecf20Sopenharmony_ci#define ACPI_MEMORY_DEVICE_HID          "PNP0C80"
458c2ecf20Sopenharmony_ci#define ACPI_MEMORY_DEVICE_NAME         "Hotplug Mem Device"
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciint xen_stub_memory_device_init(void);
488c2ecf20Sopenharmony_civoid xen_stub_memory_device_exit(void);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define ACPI_PROCESSOR_CLASS            "processor"
518c2ecf20Sopenharmony_ci#define ACPI_PROCESSOR_DEVICE_HID       "ACPI0007"
528c2ecf20Sopenharmony_ci#define ACPI_PROCESSOR_DEVICE_NAME      "Processor"
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ciint xen_stub_processor_init(void);
558c2ecf20Sopenharmony_civoid xen_stub_processor_exit(void);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_civoid xen_pcpu_hotplug_sync(void);
588c2ecf20Sopenharmony_ciint xen_pcpu_id(uint32_t acpi_id);
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic inline int xen_acpi_get_pxm(acpi_handle h)
618c2ecf20Sopenharmony_ci{
628c2ecf20Sopenharmony_ci	unsigned long long pxm;
638c2ecf20Sopenharmony_ci	acpi_status status;
648c2ecf20Sopenharmony_ci	acpi_handle handle;
658c2ecf20Sopenharmony_ci	acpi_handle phandle = h;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	do {
688c2ecf20Sopenharmony_ci		handle = phandle;
698c2ecf20Sopenharmony_ci		status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm);
708c2ecf20Sopenharmony_ci		if (ACPI_SUCCESS(status))
718c2ecf20Sopenharmony_ci			return pxm;
728c2ecf20Sopenharmony_ci		status = acpi_get_parent(handle, &phandle);
738c2ecf20Sopenharmony_ci	} while (ACPI_SUCCESS(status));
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	return -ENXIO;
768c2ecf20Sopenharmony_ci}
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ciint xen_acpi_notify_hypervisor_sleep(u8 sleep_state,
798c2ecf20Sopenharmony_ci				     u32 pm1a_cnt, u32 pm1b_cnd);
808c2ecf20Sopenharmony_ciint xen_acpi_notify_hypervisor_extended_sleep(u8 sleep_state,
818c2ecf20Sopenharmony_ci				     u32 val_a, u32 val_b);
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_cistatic inline int xen_acpi_suspend_lowlevel(void)
848c2ecf20Sopenharmony_ci{
858c2ecf20Sopenharmony_ci	/*
868c2ecf20Sopenharmony_ci	* Xen will save and restore CPU context, so
878c2ecf20Sopenharmony_ci	* we can skip that and just go straight to
888c2ecf20Sopenharmony_ci	* the suspend.
898c2ecf20Sopenharmony_ci	*/
908c2ecf20Sopenharmony_ci	acpi_enter_sleep_state(ACPI_STATE_S3);
918c2ecf20Sopenharmony_ci	return 0;
928c2ecf20Sopenharmony_ci}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistatic inline void xen_acpi_sleep_register(void)
958c2ecf20Sopenharmony_ci{
968c2ecf20Sopenharmony_ci	if (xen_initial_domain()) {
978c2ecf20Sopenharmony_ci		acpi_os_set_prepare_sleep(
988c2ecf20Sopenharmony_ci			&xen_acpi_notify_hypervisor_sleep);
998c2ecf20Sopenharmony_ci		acpi_os_set_prepare_extended_sleep(
1008c2ecf20Sopenharmony_ci			&xen_acpi_notify_hypervisor_extended_sleep);
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci		acpi_suspend_lowlevel = xen_acpi_suspend_lowlevel;
1038c2ecf20Sopenharmony_ci	}
1048c2ecf20Sopenharmony_ci}
1058c2ecf20Sopenharmony_ci#else
1068c2ecf20Sopenharmony_cistatic inline void xen_acpi_sleep_register(void)
1078c2ecf20Sopenharmony_ci{
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ci#endif
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#endif	/* _XEN_ACPI_H */
112