18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Simple wrappers around HVM functions */
38c2ecf20Sopenharmony_ci#ifndef XEN_HVM_H__
48c2ecf20Sopenharmony_ci#define XEN_HVM_H__
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <xen/interface/hvm/params.h>
78c2ecf20Sopenharmony_ci#include <asm/xen/hypercall.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_cistatic const char *param_name(int op)
108c2ecf20Sopenharmony_ci{
118c2ecf20Sopenharmony_ci#define PARAM(x) [HVM_PARAM_##x] = #x
128c2ecf20Sopenharmony_ci	static const char *const names[] = {
138c2ecf20Sopenharmony_ci		PARAM(CALLBACK_IRQ),
148c2ecf20Sopenharmony_ci		PARAM(STORE_PFN),
158c2ecf20Sopenharmony_ci		PARAM(STORE_EVTCHN),
168c2ecf20Sopenharmony_ci		PARAM(PAE_ENABLED),
178c2ecf20Sopenharmony_ci		PARAM(IOREQ_PFN),
188c2ecf20Sopenharmony_ci		PARAM(BUFIOREQ_PFN),
198c2ecf20Sopenharmony_ci		PARAM(TIMER_MODE),
208c2ecf20Sopenharmony_ci		PARAM(HPET_ENABLED),
218c2ecf20Sopenharmony_ci		PARAM(IDENT_PT),
228c2ecf20Sopenharmony_ci		PARAM(DM_DOMAIN),
238c2ecf20Sopenharmony_ci		PARAM(ACPI_S_STATE),
248c2ecf20Sopenharmony_ci		PARAM(VM86_TSS),
258c2ecf20Sopenharmony_ci		PARAM(VPT_ALIGN),
268c2ecf20Sopenharmony_ci		PARAM(CONSOLE_PFN),
278c2ecf20Sopenharmony_ci		PARAM(CONSOLE_EVTCHN),
288c2ecf20Sopenharmony_ci	};
298c2ecf20Sopenharmony_ci#undef PARAM
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci	if (op >= ARRAY_SIZE(names))
328c2ecf20Sopenharmony_ci		return "unknown";
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	if (!names[op])
358c2ecf20Sopenharmony_ci		return "reserved";
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	return names[op];
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_cistatic inline int hvm_get_parameter(int idx, uint64_t *value)
408c2ecf20Sopenharmony_ci{
418c2ecf20Sopenharmony_ci	struct xen_hvm_param xhv;
428c2ecf20Sopenharmony_ci	int r;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	xhv.domid = DOMID_SELF;
458c2ecf20Sopenharmony_ci	xhv.index = idx;
468c2ecf20Sopenharmony_ci	r = HYPERVISOR_hvm_op(HVMOP_get_param, &xhv);
478c2ecf20Sopenharmony_ci	if (r < 0) {
488c2ecf20Sopenharmony_ci		pr_err("Cannot get hvm parameter %s (%d): %d!\n",
498c2ecf20Sopenharmony_ci		       param_name(idx), idx, r);
508c2ecf20Sopenharmony_ci		return r;
518c2ecf20Sopenharmony_ci	}
528c2ecf20Sopenharmony_ci	*value = xhv.value;
538c2ecf20Sopenharmony_ci	return r;
548c2ecf20Sopenharmony_ci}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define HVM_CALLBACK_VIA_TYPE_VECTOR 0x2
578c2ecf20Sopenharmony_ci#define HVM_CALLBACK_VIA_TYPE_SHIFT 56
588c2ecf20Sopenharmony_ci#define HVM_CALLBACK_VECTOR(x) (((uint64_t)HVM_CALLBACK_VIA_TYPE_VECTOR)<<\
598c2ecf20Sopenharmony_ci		HVM_CALLBACK_VIA_TYPE_SHIFT | (x))
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_civoid xen_setup_callback_vector(void);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#endif /* XEN_HVM_H__ */
64