hyperv.h revision 322612
153642Sguido/*-
280482Sdarrenr * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
353642Sguido * Copyright (c) 2012 NetApp Inc.
480482Sdarrenr * Copyright (c) 2012 Citrix Inc.
553642Sguido * All rights reserved.
692685Sdarrenr *
792685Sdarrenr * Redistribution and use in source and binary forms, with or without
892685Sdarrenr * modification, are permitted provided that the following conditions
953642Sguido * are met:
1053642Sguido * 1. Redistributions of source code must retain the above copyright
1153642Sguido *    notice unmodified, this list of conditions, and the following
1253642Sguido *    disclaimer.
1353642Sguido * 2. Redistributions in binary form must reproduce the above copyright
1453642Sguido *    notice, this list of conditions and the following disclaimer in the
1553642Sguido *    documentation and/or other materials provided with the distribution.
1653642Sguido *
1753642Sguido * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1853642Sguido * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1960850Sdarrenr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2053642Sguido * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2153642Sguido * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2253642Sguido * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2353642Sguido * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2453642Sguido * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2553642Sguido * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2653642Sguido * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2753642Sguido *
2853642Sguido * $FreeBSD: stable/11/sys/dev/hyperv/include/hyperv.h 322612 2017-08-17 05:09:22Z sephe $
2957096Sguido */
3053642Sguido
3153642Sguido#ifndef _HYPERV_H_
3253642Sguido#define _HYPERV_H_
3353642Sguido
3453642Sguido#ifdef _KERNEL
3553642Sguido
3653642Sguido#include <sys/param.h>
3753642Sguido#include <sys/systm.h>
3853642Sguido
3953642Sguido#define MSR_HV_TIME_REF_COUNT		0x40000020
4053642Sguido
4153642Sguido#define CPUID_HV_MSR_TIME_REFCNT	0x0002	/* MSR_HV_TIME_REF_COUNT */
4253642Sguido#define CPUID_HV_MSR_SYNIC		0x0004	/* MSRs for SynIC */
4353642Sguido#define CPUID_HV_MSR_SYNTIMER		0x0008	/* MSRs for SynTimer */
4453642Sguido#define CPUID_HV_MSR_APIC		0x0010	/* MSR_HV_{EOI,ICR,TPR} */
4564105Sroberto#define CPUID_HV_MSR_HYPERCALL		0x0020	/* MSR_HV_GUEST_OS_ID
4653642Sguido						 * MSR_HV_HYPERCALL */
4753642Sguido#define CPUID_HV_MSR_VP_INDEX		0x0040	/* MSR_HV_VP_INDEX */
4853642Sguido#define CPUID_HV_MSR_REFERENCE_TSC	0x0200	/* MSR_HV_REFERENCE_TSC */
4953642Sguido#define CPUID_HV_MSR_GUEST_IDLE		0x0400	/* MSR_HV_GUEST_IDLE */
5053642Sguido
5153642Sguido#ifndef NANOSEC
5253642Sguido#define NANOSEC				1000000000ULL
5353642Sguido#endif
5453642Sguido#define HYPERV_TIMER_NS_FACTOR		100ULL
5553642Sguido#define HYPERV_TIMER_FREQ		(NANOSEC / HYPERV_TIMER_NS_FACTOR)
5653642Sguido
5753642Sguido#endif	/* _KERNEL */
5853642Sguido
5953642Sguido#define HYPERV_REFTSC_DEVNAME		"hv_tsc"
6053642Sguido
6153642Sguido/*
6253642Sguido * Hyper-V Reference TSC
6353642Sguido */
6453642Sguidostruct hyperv_reftsc {
6553642Sguido	volatile uint32_t		tsc_seq;
6653642Sguido	volatile uint32_t		tsc_rsvd1;
6753642Sguido	volatile uint64_t		tsc_scale;
6853642Sguido	volatile int64_t		tsc_ofs;
6953642Sguido} __packed __aligned(PAGE_SIZE);
7053642Sguido#ifdef CTASSERT
7153642SguidoCTASSERT(sizeof(struct hyperv_reftsc) == PAGE_SIZE);
7253642Sguido#endif
7353642Sguido
7453642Sguido#ifdef _KERNEL
7553642Sguido
7680482Sdarrenrstruct hyperv_guid {
7753642Sguido	uint8_t				hv_guid[16];
7853642Sguido} __packed;
7953642Sguido
8053642Sguido#define HYPERV_GUID_STRLEN		40
8153642Sguido
8253642Sguidotypedef uint64_t			(*hyperv_tc64_t)(void);
8353642Sguido
8453642Sguidoint			hyperv_guid2str(const struct hyperv_guid *, char *,
8553642Sguido			    size_t);
8653642Sguido
8753642Sguido/*
8853642Sguido * hyperv_tc64 could be NULL, if there were no suitable Hyper-V
8953642Sguido * specific timecounter.
9053642Sguido */
9153642Sguidoextern hyperv_tc64_t	hyperv_tc64;
9253642Sguidoextern u_int		hyperv_features;	/* CPUID_HV_MSR_ */
9353642Sguido
9453642Sguido#endif	/* _KERNEL */
9553642Sguido
9653642Sguido#endif  /* _HYPERV_H_ */
9753642Sguido