Home | History | Annotate | Line # | Download | only in hyperv
hypervvar.h revision 1.1.2.2
      1 /*	$NetBSD: hypervvar.h,v 1.1.2.2 2019/03/09 17:10:19 martin Exp $	*/
      2 
      3 /*-
      4  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
      5  *
      6  * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
      7  * Copyright (c) 2012 NetApp Inc.
      8  * Copyright (c) 2012 Citrix Inc.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice unmodified, this list of conditions, and the following
     16  *    disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  *
     32  * $FreeBSD: head/sys/dev/hyperv/include/hyperv.h 326255 2017-11-27 14:52:40Z pfg $
     33  */
     34 
     35 #ifndef _HYPERVVAR_H_
     36 #define _HYPERVVAR_H_
     37 
     38 #if defined(_KERNEL)
     39 
     40 #include <sys/bus.h>
     41 #include <sys/timex.h>
     42 
     43 #define HYPERV_TIMER_NS_FACTOR	100ULL
     44 #define HYPERV_TIMER_FREQ	(NANOSECOND / HYPERV_TIMER_NS_FACTOR)
     45 
     46 #endif	/* _KERNEL */
     47 
     48 /*
     49  * Hyper-V Reference TSC
     50  */
     51 struct hyperv_reftsc {
     52 	volatile uint32_t	tsc_seq;
     53 	volatile uint32_t	tsc_rsvd1;
     54 	volatile uint64_t	tsc_scale;
     55 	volatile int64_t	tsc_ofs;
     56 } __packed __aligned(PAGE_SIZE);
     57 #ifdef __CTASSERT
     58 __CTASSERT(sizeof(struct hyperv_reftsc) == PAGE_SIZE);
     59 #endif
     60 
     61 #if defined(_KERNEL)
     62 
     63 int	hyperv_hypercall_enabled(void);
     64 int	hyperv_synic_supported(void);
     65 void	hyperv_send_eom(void);
     66 void	hyperv_intr(void);
     67 
     68 struct vmbus_softc;
     69 void	vmbus_init_interrupts_md(struct vmbus_softc *);
     70 void	vmbus_deinit_interrupts_md(struct vmbus_softc *);
     71 void	vmbus_init_synic_md(struct vmbus_softc *, cpuid_t);
     72 void	vmbus_deinit_synic_md(struct vmbus_softc *, cpuid_t);
     73 
     74 #define HYPERV_GUID_STRLEN	40
     75 struct hyperv_guid;
     76 int	hyperv_guid2str(const struct hyperv_guid *, char *, size_t);
     77 
     78 /*
     79  * hyperv_tc64 could be NULL, if there were no suitable Hyper-V
     80  * specific timecounter.
     81  */
     82 typedef uint64_t (*hyperv_tc64_t)(void);
     83 extern hyperv_tc64_t hyperv_tc64;
     84 
     85 uint64_t hyperv_hypercall(uint64_t, paddr_t, paddr_t);
     86 uint64_t hyperv_hypercall_post_message(paddr_t);
     87 uint64_t hyperv_hypercall_signal_event(paddr_t);
     88 
     89 typedef void (*hyperv_proc_t)(void *, struct cpu_info *);
     90 void	hyperv_set_event_proc(hyperv_proc_t, void *);
     91 void	hyperv_set_message_proc(hyperv_proc_t, void *);
     92 
     93 /*
     94  * Hyper-V bus_dma utilities.
     95  */
     96 struct hyperv_dma {
     97 	bus_dmamap_t		map;
     98 	bus_dma_segment_t	*segs;
     99 	void			*addr;
    100 	int			nsegs;
    101 };
    102 
    103 static __inline bus_addr_t
    104 hyperv_dma_get_paddr(struct hyperv_dma *dma)
    105 {
    106 	return dma->map->dm_segs[0].ds_addr;
    107 }
    108 
    109 void *hyperv_dma_alloc(bus_dma_tag_t, struct hyperv_dma *, bus_size_t,
    110     bus_size_t, bus_size_t, int);
    111 void hyperv_dma_free(bus_dma_tag_t, struct hyperv_dma *);
    112 
    113 #endif	/* _KERNEL */
    114 
    115 #endif	/* _HYPERVVAR_H_ */
    116