1008024f2SSepherosa Ziehau /*- 2008024f2SSepherosa Ziehau * Copyright (c) 2016 Microsoft Corp. 3008024f2SSepherosa Ziehau * All rights reserved. 4008024f2SSepherosa Ziehau * 5008024f2SSepherosa Ziehau * Redistribution and use in source and binary forms, with or without 6008024f2SSepherosa Ziehau * modification, are permitted provided that the following conditions 7008024f2SSepherosa Ziehau * are met: 8008024f2SSepherosa Ziehau * 1. Redistributions of source code must retain the above copyright 9008024f2SSepherosa Ziehau * notice unmodified, this list of conditions, and the following 10008024f2SSepherosa Ziehau * disclaimer. 11008024f2SSepherosa Ziehau * 2. Redistributions in binary form must reproduce the above copyright 12008024f2SSepherosa Ziehau * notice, this list of conditions and the following disclaimer in the 13008024f2SSepherosa Ziehau * documentation and/or other materials provided with the distribution. 14008024f2SSepherosa Ziehau * 15008024f2SSepherosa Ziehau * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16008024f2SSepherosa Ziehau * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17008024f2SSepherosa Ziehau * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18008024f2SSepherosa Ziehau * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19008024f2SSepherosa Ziehau * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20008024f2SSepherosa Ziehau * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21008024f2SSepherosa Ziehau * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22008024f2SSepherosa Ziehau * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23008024f2SSepherosa Ziehau * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24008024f2SSepherosa Ziehau * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25008024f2SSepherosa Ziehau * 26008024f2SSepherosa Ziehau * $FreeBSD$ 27008024f2SSepherosa Ziehau */ 28008024f2SSepherosa Ziehau 29008024f2SSepherosa Ziehau #ifndef _VMBUS_VAR_H_ 30008024f2SSepherosa Ziehau #define _VMBUS_VAR_H_ 31008024f2SSepherosa Ziehau 32008024f2SSepherosa Ziehau #include <sys/param.h> 330408d8b8SSepherosa Ziehau #include <sys/bus_dma.h> 34430d28dbSSepherosa Ziehau #include <sys/taskqueue.h> 35430d28dbSSepherosa Ziehau 360408d8b8SSepherosa Ziehau #include <dev/hyperv/include/hyperv_busdma.h> 37008024f2SSepherosa Ziehau 38430d28dbSSepherosa Ziehau /* 39430d28dbSSepherosa Ziehau * NOTE: DO NOT CHANGE THIS. 40430d28dbSSepherosa Ziehau */ 41430d28dbSSepherosa Ziehau #define VMBUS_SINT_MESSAGE 2 42430d28dbSSepherosa Ziehau /* 43430d28dbSSepherosa Ziehau * NOTE: 44430d28dbSSepherosa Ziehau * - DO NOT set it to the same value as VMBUS_SINT_MESSAGE. 45430d28dbSSepherosa Ziehau * - DO NOT set it to 0. 46430d28dbSSepherosa Ziehau */ 47430d28dbSSepherosa Ziehau #define VMBUS_SINT_TIMER 4 48430d28dbSSepherosa Ziehau 49008024f2SSepherosa Ziehau struct vmbus_pcpu_data { 500408d8b8SSepherosa Ziehau u_long *intr_cnt; /* Hyper-V interrupt counter */ 510408d8b8SSepherosa Ziehau struct vmbus_message *message; /* shared messages */ 5214aa3e80SSepherosa Ziehau uint32_t vcpuid; /* virtual cpuid */ 53008024f2SSepherosa Ziehau int event_flag_cnt; /* # of event flags */ 540408d8b8SSepherosa Ziehau union vmbus_event_flags *event_flag; /* shared event flags */ 550408d8b8SSepherosa Ziehau 560408d8b8SSepherosa Ziehau /* Rarely used fields */ 570408d8b8SSepherosa Ziehau struct hyperv_dma message_dma; /* busdma glue */ 580408d8b8SSepherosa Ziehau struct hyperv_dma event_flag_dma; /* busdma glue */ 5995a45414SSepherosa Ziehau struct taskqueue *event_tq; /* event taskq */ 6095a45414SSepherosa Ziehau struct taskqueue *message_tq; /* message taskq */ 6195a45414SSepherosa Ziehau struct task message_task; /* message task */ 62008024f2SSepherosa Ziehau } __aligned(CACHE_LINE_SIZE); 63008024f2SSepherosa Ziehau 64008024f2SSepherosa Ziehau struct vmbus_softc { 65646995bdSSepherosa Ziehau void (*vmbus_event_proc)(struct vmbus_softc *, int); 66008024f2SSepherosa Ziehau struct vmbus_pcpu_data vmbus_pcpu[MAXCPU]; 6795a45414SSepherosa Ziehau 6895a45414SSepherosa Ziehau /* Rarely used fields */ 69e2468dfeSSepherosa Ziehau device_t vmbus_dev; 70fc4d679fSSepherosa Ziehau int vmbus_idtvec; 7120bce8faSSepherosa Ziehau uint32_t vmbus_flags; /* see VMBUS_FLAG_ */ 72008024f2SSepherosa Ziehau }; 73008024f2SSepherosa Ziehau 7420bce8faSSepherosa Ziehau #define VMBUS_FLAG_ATTACHED 0x0001 /* vmbus was attached */ 7520bce8faSSepherosa Ziehau #define VMBUS_FLAG_SYNIC 0x0002 /* SynIC was setup */ 7620bce8faSSepherosa Ziehau 77008024f2SSepherosa Ziehau extern struct vmbus_softc *vmbus_sc; 78008024f2SSepherosa Ziehau 79008024f2SSepherosa Ziehau static __inline struct vmbus_softc * 80008024f2SSepherosa Ziehau vmbus_get_softc(void) 81008024f2SSepherosa Ziehau { 82008024f2SSepherosa Ziehau return vmbus_sc; 83008024f2SSepherosa Ziehau } 84008024f2SSepherosa Ziehau 85e2468dfeSSepherosa Ziehau static __inline device_t 86e2468dfeSSepherosa Ziehau vmbus_get_device(void) 87e2468dfeSSepherosa Ziehau { 88e2468dfeSSepherosa Ziehau return vmbus_sc->vmbus_dev; 89e2468dfeSSepherosa Ziehau } 90e2468dfeSSepherosa Ziehau 91bcc9e3e9SSepherosa Ziehau #define VMBUS_PCPU_GET(sc, field, cpu) (sc)->vmbus_pcpu[(cpu)].field 92bcc9e3e9SSepherosa Ziehau #define VMBUS_PCPU_PTR(sc, field, cpu) &(sc)->vmbus_pcpu[(cpu)].field 93008024f2SSepherosa Ziehau 94430d28dbSSepherosa Ziehau struct hv_vmbus_channel; 95430d28dbSSepherosa Ziehau struct trapframe; 96430d28dbSSepherosa Ziehau 97008024f2SSepherosa Ziehau void vmbus_on_channel_open(const struct hv_vmbus_channel *); 98646995bdSSepherosa Ziehau void vmbus_event_proc(struct vmbus_softc *, int); 99646995bdSSepherosa Ziehau void vmbus_event_proc_compat(struct vmbus_softc *, int); 100*98a68947SSepherosa Ziehau void vmbus_handle_intr(struct trapframe *); 101008024f2SSepherosa Ziehau 102430d28dbSSepherosa Ziehau void vmbus_et_intr(struct trapframe *); 103430d28dbSSepherosa Ziehau 104008024f2SSepherosa Ziehau #endif /* !_VMBUS_VAR_H_ */ 105