win-pvdrivers

annotate xenpci/xenpci.h @ 198:c5f21187ef46

Working on suspend/resume. Suspend works (well... you get a checkpoint file), but resume fails.
author James Harper <james.harper@bendigoit.com.au>
date Thu Feb 28 09:06:35 2008 +1100 (2008-02-28)
parents 8609c27c4893
children d841932ba7ae
rev   line source
james@0 1 /*
james@0 2 PV Drivers for Windows Xen HVM Domains
james@0 3 Copyright (C) 2007 James Harper
james@0 4
james@0 5 This program is free software; you can redistribute it and/or
james@0 6 modify it under the terms of the GNU General Public License
james@0 7 as published by the Free Software Foundation; either version 2
james@0 8 of the License, or (at your option) any later version.
james@0 9
james@0 10 This program is distributed in the hope that it will be useful,
james@0 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
james@0 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
james@0 13 GNU General Public License for more details.
james@0 14
james@0 15 You should have received a copy of the GNU General Public License
james@0 16 along with this program; if not, write to the Free Software
james@0 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
james@0 18 */
james@0 19
james@0 20 #if !defined(_XENPCI_H_)
james@0 21 #define _XENPCI_H_
james@0 22
james@0 23 #define __attribute__(arg) /* empty */
james@0 24 #define EISCONN 127
james@0 25
james@0 26 #include <ntddk.h>
james@0 27 #include <wdm.h>
james@0 28 #include <wdf.h>
james@0 29 #include <initguid.h>
james@0 30 #include <wdmguid.h>
james@0 31 #include <errno.h>
james@0 32
james@0 33 #define NTSTRSAFE_LIB
james@0 34 #include <ntstrsafe.h>
james@0 35
james@74 36 #define __DRIVER_NAME "XenPCI"
james@74 37
james@0 38 #include <xen_windows.h>
james@0 39 #include <memory.h>
james@0 40 #include <grant_table.h>
james@0 41 #include <event_channel.h>
james@0 42 #include <hvm/params.h>
james@0 43 #include <hvm/hvm_op.h>
james@198 44 #include <sched.h>
james@0 45
andy@15 46 #include <xen_public.h>
andy@15 47
james@0 48 //{C828ABE9-14CA-4445-BAA6-82C2376C6518}
james@0 49 DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC828ABE9, 0x14CA, 0x4445, 0xBA, 0xA6, 0x82, 0xC2, 0x37, 0x6C, 0x65, 0x18);
james@0 50
james@0 51 #define XENPCI_POOL_TAG (ULONG) 'XenP'
james@0 52 //#define XENPCI_FDO_INSTANCE_SIGNATURE (ULONG) 'XENP'
james@0 53
james@0 54 #define NR_RESERVED_ENTRIES 8
james@0 55 #define NR_GRANT_FRAMES 4
james@0 56 #define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t))
james@0 57
james@0 58 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
james@0 59
andy@13 60 typedef struct _ev_action_t {
andy@13 61 PKSERVICE_ROUTINE ServiceRoutine;
andy@13 62 PVOID ServiceContext;
james@73 63 BOOLEAN DpcFlag;
james@73 64 WDFDPC Dpc;
andy@13 65 ULONG Count;
andy@13 66 } ev_action_t;
james@0 67
james@73 68 typedef struct {
james@73 69 ev_action_t *Action;
james@73 70 } EVTCHN_DEVICE_DATA, *PEVTCHN_DEVICE_DATA;
james@73 71 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(EVTCHN_DEVICE_DATA, GetEvtChnDeviceData);
james@73 72
andy@15 73 typedef struct _XENBUS_WATCH_RING
andy@15 74 {
andy@15 75 char Path[128];
andy@15 76 char Token[10];
andy@15 77 } XENBUS_WATCH_RING;
james@0 78
andy@15 79 typedef struct _XENBUS_REQ_INFO
andy@15 80 {
andy@15 81 int In_Use:1;
andy@15 82 KEVENT WaitEvent;
andy@15 83 void *Reply;
andy@15 84 } XENBUS_REQ_INFO;
james@0 85
andy@15 86 typedef struct _XENBUS_WATCH_ENTRY {
andy@15 87 char Path[128];
andy@15 88 PXENBUS_WATCH_CALLBACK ServiceRoutine;
andy@15 89 PVOID ServiceContext;
andy@15 90 int Count;
andy@15 91 int Active;
james@138 92 int RemovePending;
james@128 93 int Running;
james@128 94 KEVENT CompleteEvent;
andy@15 95 } XENBUS_WATCH_ENTRY, *PXENBUS_WATCH_ENTRY;
james@0 96
andy@13 97 #define NR_EVENTS 1024
andy@15 98 #define WATCH_RING_SIZE 128
andy@15 99 #define NR_XB_REQS 32
andy@15 100 #define MAX_WATCH_ENTRIES 128
james@0 101
andy@15 102 // TODO: tidy up & organize this struct
james@0 103 typedef struct {
james@0 104
andy@13 105 WDFDEVICE Device;
andy@38 106 BOOLEAN XenBus_ShuttingDown;
james@0 107
andy@13 108 WDFINTERRUPT XenInterrupt;
andy@13 109 ULONG irqNumber;
james@0 110
andy@13 111 shared_info_t *shared_info_area;
james@0 112
andy@13 113 PHYSICAL_ADDRESS platform_mmio_addr;
andy@13 114 ULONG platform_mmio_orig_len;
andy@13 115 ULONG platform_mmio_len;
andy@13 116 ULONG platform_mmio_alloc;
andy@13 117
andy@13 118 char *hypercall_stubs;
andy@13 119
andy@13 120 evtchn_port_t xen_store_evtchn;
andy@13 121
andy@13 122 grant_entry_t *gnttab_table;
andy@13 123 PHYSICAL_ADDRESS gnttab_table_physical;
andy@13 124 grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
andy@13 125
andy@13 126 ev_action_t ev_actions[NR_EVENTS];
andy@13 127 unsigned long bound_ports[NR_EVENTS/(8*sizeof(unsigned long))];
james@0 128
andy@15 129 HANDLE XenBus_ReadThreadHandle;
andy@15 130 KEVENT XenBus_ReadThreadEvent;
andy@15 131 HANDLE XenBus_WatchThreadHandle;
andy@15 132 KEVENT XenBus_WatchThreadEvent;
andy@15 133
andy@15 134 XENBUS_WATCH_RING XenBus_WatchRing[WATCH_RING_SIZE];
andy@15 135 int XenBus_WatchRingReadIndex;
andy@15 136 int XenBus_WatchRingWriteIndex;
andy@15 137
andy@15 138 struct xenstore_domain_interface *xen_store_interface;
andy@15 139
andy@15 140 XENBUS_REQ_INFO req_info[NR_XB_REQS];
andy@15 141 int nr_live_reqs;
andy@15 142 XENBUS_WATCH_ENTRY XenBus_WatchEntries[MAX_WATCH_ENTRIES];
james@0 143
james@128 144 KSPIN_LOCK WatchLock;
james@176 145 KSPIN_LOCK grant_lock;
james@191 146
james@191 147 KGUARDED_MUTEX WatchHandlerMutex;
james@198 148
james@198 149 int suspending;
james@0 150 } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
james@0 151
james@0 152 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENPCI_DEVICE_DATA, GetDeviceData);
james@0 153
james@126 154 #if defined(_X86_)
james@126 155 #include "hypercall_x86.h"
james@126 156 #else
james@126 157 #if defined(_AMD64_)
james@126 158 #include "hypercall_amd64.h"
james@126 159 #endif
james@126 160 #endif
james@124 161
james@0 162 typedef unsigned long xenbus_transaction_t;
james@0 163 typedef uint32_t XENSTORE_RING_IDX;
james@0 164
james@0 165 #define XBT_NIL ((xenbus_transaction_t)0)
james@0 166
james@0 167 char *
andy@13 168 XenBus_Read(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
james@0 169 char *
andy@13 170 XenBus_Write(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
james@0 171 char *
andy@13 172 XenBus_Printf(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
james@0 173 char *
andy@13 174 XenBus_StartTransaction(PVOID Context, xenbus_transaction_t *xbt);
james@0 175 char *
andy@13 176 XenBus_EndTransaction(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
andy@13 177 char *
andy@13 178 XenBus_List(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
james@0 179 NTSTATUS
andy@15 180 XenBus_Init(WDFDEVICE Device);
james@0 181 NTSTATUS
andy@37 182 XenBus_Close(WDFDEVICE Device);
andy@37 183 NTSTATUS
andy@15 184 XenBus_Start(WDFDEVICE Device);
andy@15 185 NTSTATUS
andy@15 186 XenBus_Stop(WDFDEVICE Device);
james@0 187 char *
andy@13 188 XenBus_AddWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
james@0 189 char *
andy@13 190 XenBus_RemWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
james@0 191 VOID
james@0 192 XenBus_ThreadProc(PVOID StartContext);
james@0 193
james@0 194 PHYSICAL_ADDRESS
andy@13 195 XenPCI_AllocMMIO(WDFDEVICE Device, ULONG len);
james@0 196
andy@15 197 NTSTATUS
andy@15 198 EvtChn_Init(WDFDEVICE Device);
james@0 199 BOOLEAN
james@0 200 EvtChn_Interrupt(WDFINTERRUPT Interrupt, ULONG MessageID);
andy@68 201 VOID
james@0 202 EvtChn_InterruptDpc(WDFINTERRUPT Interrupt, WDFOBJECT AssociatedObject);
james@0 203 NTSTATUS
andy@13 204 EvtChn_Mask(PVOID Context, evtchn_port_t Port);
james@0 205 NTSTATUS
andy@13 206 EvtChn_Unmask(PVOID Context, evtchn_port_t Port);
james@0 207 NTSTATUS
andy@13 208 EvtChn_Bind(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
james@0 209 NTSTATUS
james@73 210 EvtChn_BindDpc(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
james@73 211 NTSTATUS
andy@13 212 EvtChn_Unbind(PVOID Context, evtchn_port_t Port);
andy@13 213 NTSTATUS
andy@13 214 EvtChn_Notify(PVOID Context, evtchn_port_t Port);
james@0 215 evtchn_port_t
andy@13 216 EvtChn_AllocUnbound(PVOID Context, domid_t Domain);
andy@15 217 evtchn_port_t
andy@15 218 EvtChn_GetXenStorePort(WDFDEVICE Device);
andy@15 219 PVOID
andy@15 220 EvtChn_GetXenStoreRingAddr(WDFDEVICE Device);
james@0 221
andy@15 222 VOID
andy@15 223 GntTbl_Init(WDFDEVICE Device);
james@0 224 grant_ref_t
james@147 225 GntTbl_GrantAccess(WDFDEVICE Device, domid_t domid, uint32_t, int readonly);
james@0 226 BOOLEAN
andy@13 227 GntTbl_EndAccess(WDFDEVICE Device, grant_ref_t ref);
james@0 228
james@0 229 #endif