win-pvdrivers

annotate xenpci/xenpci.h @ 284:4954c15a4921

misc fixes. Mainly multiple requests per lu in xenvbd
author James Harper <james.harper@bendigoit.com.au>
date Sat May 31 22:35:41 2008 +1000 (2008-05-31)
parents 685399b9adb0
children 89e1a0af859c
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@258 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@267 45 #include <io/xenbus.h>
james@0 46
andy@15 47 #include <xen_public.h>
andy@15 48
james@0 49 //{C828ABE9-14CA-4445-BAA6-82C2376C6518}
james@0 50 DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC828ABE9, 0x14CA, 0x4445, 0xBA, 0xA6, 0x82, 0xC2, 0x37, 0x6C, 0x65, 0x18);
james@0 51
james@0 52 #define XENPCI_POOL_TAG (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
james@267 60 #define EVT_ACTION_TYPE_EMPTY 0
james@267 61 #define EVT_ACTION_TYPE_NORMAL 1
james@267 62 #define EVT_ACTION_TYPE_DPC 2
james@267 63 #define EVT_ACTION_TYPE_IRQ 3
james@267 64
andy@13 65 typedef struct _ev_action_t {
andy@13 66 PKSERVICE_ROUTINE ServiceRoutine;
andy@13 67 PVOID ServiceContext;
james@267 68 ULONG type; /* EVT_ACTION_TYPE_* */
james@258 69 KDPC Dpc;
james@267 70 ULONG vector;
andy@13 71 ULONG Count;
andy@13 72 } ev_action_t;
james@0 73
andy@15 74 typedef struct _XENBUS_WATCH_RING
andy@15 75 {
andy@15 76 char Path[128];
andy@15 77 char Token[10];
andy@15 78 } XENBUS_WATCH_RING;
james@0 79
andy@15 80 typedef struct _XENBUS_REQ_INFO
andy@15 81 {
andy@15 82 int In_Use:1;
andy@15 83 KEVENT WaitEvent;
andy@15 84 void *Reply;
andy@15 85 } XENBUS_REQ_INFO;
james@0 86
andy@15 87 typedef struct _XENBUS_WATCH_ENTRY {
andy@15 88 char Path[128];
andy@15 89 PXENBUS_WATCH_CALLBACK ServiceRoutine;
andy@15 90 PVOID ServiceContext;
andy@15 91 int Count;
andy@15 92 int Active;
james@138 93 int RemovePending;
james@128 94 int Running;
james@128 95 KEVENT CompleteEvent;
andy@15 96 } XENBUS_WATCH_ENTRY, *PXENBUS_WATCH_ENTRY;
james@0 97
andy@13 98 #define NR_EVENTS 1024
andy@15 99 #define WATCH_RING_SIZE 128
andy@15 100 #define NR_XB_REQS 32
andy@15 101 #define MAX_WATCH_ENTRIES 128
james@0 102
james@259 103 #define CHILD_STATE_EMPTY 0
james@259 104 #define CHILD_STATE_DELETED 1
james@259 105 #define CHILD_STATE_ADDED 2
james@259 106
james@259 107 // TODO: tidy up & organize this struct
james@258 108
james@274 109 typedef enum {
james@274 110 Unknown = 0,
james@274 111 NotStarted,
james@274 112 Started,
james@274 113 StopPending,
james@274 114 Stopped,
james@274 115 RemovePending,
james@274 116 SurpriseRemovePending,
james@274 117 Removed
james@274 118 } DEVICE_PNP_STATE;
james@274 119
james@258 120 typedef struct
james@258 121 {
james@258 122 PDEVICE_OBJECT fdo;
james@258 123 PDEVICE_OBJECT pdo;
james@258 124 PDEVICE_OBJECT lower_do;
james@274 125
james@284 126 DEVICE_PNP_STATE current_pnp_state;
james@284 127 DEVICE_PNP_STATE previous_pnp_state;
james@274 128 DEVICE_POWER_STATE device_power_state;
james@284 129 SYSTEM_POWER_STATE system_power_state;
james@284 130
james@284 131 ULONG device_usage_paging;
james@284 132 ULONG device_usage_dump;
james@284 133 ULONG device_usage_hibernation;
james@259 134 } XENPCI_COMMON, *PXENPCI_COMMON;
james@259 135
james@284 136 static __inline INIT_PNP_STATE(PXENPCI_COMMON common)
james@284 137 {
james@284 138 common->current_pnp_state = NotStarted;
james@284 139 common->previous_pnp_state = NotStarted;
james@284 140 }
james@284 141
james@284 142 static __inline SET_PNP_STATE(PXENPCI_COMMON common, DEVICE_PNP_STATE state)
james@284 143 {
james@284 144 common->previous_pnp_state = common->current_pnp_state;
james@284 145 common->current_pnp_state = state;
james@284 146 }
james@284 147
james@284 148 static __inline REVERT_PNP_STATE(PXENPCI_COMMON common)
james@284 149 {
james@284 150 common->current_pnp_state = common->previous_pnp_state;
james@284 151 }
james@284 152
james@272 153 #define SHUTDOWN_RING_SIZE 128
james@272 154
james@259 155 typedef struct {
james@259 156 XENPCI_COMMON common;
james@259 157
andy@38 158 BOOLEAN XenBus_ShuttingDown;
james@0 159
james@258 160 PKINTERRUPT interrupt;
james@258 161 ULONG irq_number;
james@258 162 ULONG irq_vector;
james@258 163 KIRQL irq_level;
james@258 164 KAFFINITY irq_affinity;
james@0 165
andy@13 166 shared_info_t *shared_info_area;
james@0 167
andy@13 168 PHYSICAL_ADDRESS platform_mmio_addr;
andy@13 169 ULONG platform_mmio_orig_len;
andy@13 170 ULONG platform_mmio_len;
andy@13 171 ULONG platform_mmio_alloc;
james@267 172 USHORT platform_mmio_flags;
andy@13 173
andy@13 174 char *hypercall_stubs;
andy@13 175
andy@13 176 evtchn_port_t xen_store_evtchn;
andy@13 177
andy@13 178 grant_entry_t *gnttab_table;
andy@13 179 PHYSICAL_ADDRESS gnttab_table_physical;
andy@13 180 grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
andy@13 181
andy@13 182 ev_action_t ev_actions[NR_EVENTS];
james@258 183 // unsigned long bound_ports[NR_EVENTS/(8*sizeof(unsigned long))];
james@0 184
andy@15 185 HANDLE XenBus_ReadThreadHandle;
andy@15 186 KEVENT XenBus_ReadThreadEvent;
andy@15 187 HANDLE XenBus_WatchThreadHandle;
andy@15 188 KEVENT XenBus_WatchThreadEvent;
andy@15 189
andy@15 190 XENBUS_WATCH_RING XenBus_WatchRing[WATCH_RING_SIZE];
andy@15 191 int XenBus_WatchRingReadIndex;
andy@15 192 int XenBus_WatchRingWriteIndex;
andy@15 193
andy@15 194 struct xenstore_domain_interface *xen_store_interface;
andy@15 195
andy@15 196 XENBUS_REQ_INFO req_info[NR_XB_REQS];
andy@15 197 int nr_live_reqs;
andy@15 198 XENBUS_WATCH_ENTRY XenBus_WatchEntries[MAX_WATCH_ENTRIES];
james@0 199
james@128 200 KSPIN_LOCK WatchLock;
james@176 201 KSPIN_LOCK grant_lock;
james@191 202
james@191 203 KGUARDED_MUTEX WatchHandlerMutex;
james@198 204
james@259 205 LIST_ENTRY child_list;
james@258 206
james@198 207 int suspending;
james@271 208
james@271 209 UNICODE_STRING interface_name;
james@272 210 BOOLEAN interface_open;
james@272 211
james@272 212 KSPIN_LOCK shutdown_ring_lock;
james@272 213 CHAR shutdown_ring[SHUTDOWN_RING_SIZE];
james@272 214 ULONG shutdown_prod;
james@272 215 ULONG shutdown_cons;
james@272 216 ULONG shutdown_start; /* the start of the most recent message on the ring */
james@272 217 PIRP shutdown_irp;
james@0 218 } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
james@0 219
james@274 220 /* The total number of event channels or rings allowed per device... probably never more than 2 */
james@274 221 #define MAX_RESOURCES 4
james@274 222
james@259 223 typedef struct {
james@259 224 XENPCI_COMMON common;
james@261 225 PDEVICE_OBJECT bus_fdo;
james@259 226 char path[128];
james@267 227 char device[128];
james@259 228 ULONG index;
james@267 229 ULONG irq_vector;
james@267 230 KIRQL irq_level;
james@267 231 char backend_path[128];
james@274 232 PVOID xenbus_request;
james@267 233 KEVENT backend_state_event;
james@267 234 ULONG backend_state;
james@274 235 grant_ref_t grant_refs[MAX_RESOURCES];
james@274 236 PMDL mdls[MAX_RESOURCES];
james@274 237 evtchn_port_t event_channels[MAX_RESOURCES];
james@259 238 } XENPCI_PDO_DEVICE_DATA, *PXENPCI_PDO_DEVICE_DATA;
james@0 239
james@259 240 typedef struct
james@259 241 {
james@259 242 LIST_ENTRY entry;
james@259 243 int state;
james@259 244 PXENPCI_PDO_DEVICE_DATA context;
james@259 245 } XEN_CHILD, *PXEN_CHILD;
james@267 246
james@267 247 #define SWINT(x) case x: __asm { int x } break;
james@267 248
james@274 249 #if defined(_X86_)
james@267 250 static __inline VOID
james@267 251 sw_interrupt(UCHAR intno)
james@267 252 {
james@269 253 //KdPrint((__DRIVER_NAME " Calling interrupt %02X\n", intno));
james@267 254 switch (intno)
james@267 255 {
james@267 256 SWINT(0x10) SWINT(0x11) SWINT(0x12) SWINT(0x13) SWINT(0x14) SWINT(0x15) SWINT(0x16) SWINT(0x17)
james@267 257 SWINT(0x18) SWINT(0x19) SWINT(0x1A) SWINT(0x1B) SWINT(0x1C) SWINT(0x1D) SWINT(0x1E) SWINT(0x1F)
james@267 258 SWINT(0x20) SWINT(0x21) SWINT(0x22) SWINT(0x23) SWINT(0x24) SWINT(0x25) SWINT(0x26) SWINT(0x27)
james@267 259 SWINT(0x28) SWINT(0x29) SWINT(0x2A) SWINT(0x2B) SWINT(0x2C) SWINT(0x2D) SWINT(0x2E) SWINT(0x2F)
james@267 260 SWINT(0x30) SWINT(0x31) SWINT(0x32) SWINT(0x33) SWINT(0x34) SWINT(0x35) SWINT(0x36) SWINT(0x37)
james@267 261 SWINT(0x38) SWINT(0x39) SWINT(0x3A) SWINT(0x3B) SWINT(0x3C) SWINT(0x3D) SWINT(0x3E) SWINT(0x3F)
james@267 262 SWINT(0x40) SWINT(0x41) SWINT(0x42) SWINT(0x43) SWINT(0x44) SWINT(0x45) SWINT(0x46) SWINT(0x47)
james@267 263 SWINT(0x48) SWINT(0x49) SWINT(0x4A) SWINT(0x4B) SWINT(0x4C) SWINT(0x4D) SWINT(0x4E) SWINT(0x4F)
james@267 264
james@267 265 SWINT(0x80) SWINT(0x81) SWINT(0x82) SWINT(0x83) SWINT(0x84) SWINT(0x85) SWINT(0x86) SWINT(0x87)
james@267 266 SWINT(0x88) SWINT(0x89) SWINT(0x8A) SWINT(0x8B) SWINT(0x8C) SWINT(0x8D) SWINT(0x8E) SWINT(0x8F)
james@267 267
james@267 268 SWINT(0xB0) SWINT(0xB1) SWINT(0xB2) SWINT(0xB3) SWINT(0xB4) SWINT(0xB5) SWINT(0xB6) SWINT(0xB7)
james@267 269 SWINT(0xB8) SWINT(0xB9) SWINT(0xBA) SWINT(0xBB) SWINT(0xBC) SWINT(0xBD) SWINT(0xBE) SWINT(0xBF)
james@267 270
james@267 271 default:
james@267 272 KdPrint((__DRIVER_NAME " interrupt %02X not set up. Blame James.\n", intno));
james@267 273 KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000002, (ULONG)intno, 0x00000000, 0x00000000);
james@267 274 break;
james@267 275 }
james@267 276 }
james@274 277 #else
james@274 278 VOID _sw_interrupt(UCHAR);
james@274 279
james@274 280 static __inline VOID
james@274 281 sw_interrupt(UCHAR intno)
james@274 282 {
james@274 283 _sw_interrupt(intno);
james@274 284 }
james@274 285 #endif
james@274 286
james@259 287
james@258 288 #include "hypercall.h"
james@124 289
james@0 290 typedef unsigned long xenbus_transaction_t;
james@0 291 typedef uint32_t XENSTORE_RING_IDX;
james@0 292
james@0 293 #define XBT_NIL ((xenbus_transaction_t)0)
james@0 294
james@267 295 static __inline VOID
james@267 296 XenPci_FreeMem(PVOID Ptr)
james@267 297 {
james@267 298 ExFreePoolWithTag(Ptr, XENPCI_POOL_TAG);
james@267 299 }
james@267 300
james@259 301 NTSTATUS
james@259 302 XenPci_Power_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
james@259 303 NTSTATUS
james@259 304 XenPci_Dummy_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
james@259 305 NTSTATUS
james@259 306 XenPci_Pnp_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
james@272 307 NTSTATUS
james@272 308 XenPci_Irp_Create_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
james@272 309 NTSTATUS
james@272 310 XenPci_Irp_Close_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
james@272 311 NTSTATUS
james@272 312 XenPci_Irp_Read_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
james@272 313 NTSTATUS
james@272 314 XenPci_Irp_Cleanup_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
james@259 315
james@259 316 NTSTATUS
james@259 317 XenPci_Power_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
james@272 318 //NTSTATUS
james@272 319 //XenPci_Dummy_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
james@259 320 NTSTATUS
james@259 321 XenPci_Pnp_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
james@272 322 NTSTATUS
james@272 323 XenPci_Irp_Create_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
james@272 324 NTSTATUS
james@272 325 XenPci_Irp_Close_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
james@272 326 NTSTATUS
james@272 327 XenPci_Irp_Read_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
james@272 328 NTSTATUS
james@272 329 XenPci_Irp_Cleanup_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
james@259 330
james@259 331
james@259 332
james@0 333 char *
andy@13 334 XenBus_Read(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
james@0 335 char *
andy@13 336 XenBus_Write(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
james@0 337 char *
andy@13 338 XenBus_Printf(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
james@0 339 char *
andy@13 340 XenBus_StartTransaction(PVOID Context, xenbus_transaction_t *xbt);
james@0 341 char *
andy@13 342 XenBus_EndTransaction(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
andy@13 343 char *
andy@13 344 XenBus_List(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
james@0 345 char *
andy@13 346 XenBus_AddWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
james@0 347 char *
andy@13 348 XenBus_RemWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
james@279 349 //VOID
james@279 350 //XenBus_ThreadProc(PVOID StartContext);
james@258 351 NTSTATUS
james@258 352 XenBus_Init(PXENPCI_DEVICE_DATA xpdd);
james@258 353 NTSTATUS
james@258 354 XenBus_Close(PXENPCI_DEVICE_DATA xpdd);
james@258 355 NTSTATUS
james@258 356 XenBus_Start(PXENPCI_DEVICE_DATA xpdd);
james@258 357 NTSTATUS
james@258 358 XenBus_Stop(PXENPCI_DEVICE_DATA xpdd);
james@279 359 VOID
james@279 360 XenBus_Resume(PXENPCI_DEVICE_DATA xpdd);
james@0 361
james@0 362 PHYSICAL_ADDRESS
james@258 363 XenPci_AllocMMIO(PXENPCI_DEVICE_DATA xpdd, ULONG len);
james@0 364
andy@15 365 NTSTATUS
james@258 366 EvtChn_Init(PXENPCI_DEVICE_DATA xpdd);
james@258 367 NTSTATUS
james@258 368 EvtChn_Shutdown(PXENPCI_DEVICE_DATA xpdd);
james@258 369
james@0 370 NTSTATUS
andy@13 371 EvtChn_Mask(PVOID Context, evtchn_port_t Port);
james@0 372 NTSTATUS
andy@13 373 EvtChn_Unmask(PVOID Context, evtchn_port_t Port);
james@0 374 NTSTATUS
andy@13 375 EvtChn_Bind(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
james@0 376 NTSTATUS
james@73 377 EvtChn_BindDpc(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
james@73 378 NTSTATUS
james@267 379 EvtChn_BindIrq(PVOID Context, evtchn_port_t Port, ULONG vector);
james@267 380 NTSTATUS
andy@13 381 EvtChn_Unbind(PVOID Context, evtchn_port_t Port);
andy@13 382 NTSTATUS
andy@13 383 EvtChn_Notify(PVOID Context, evtchn_port_t Port);
james@0 384 evtchn_port_t
andy@13 385 EvtChn_AllocUnbound(PVOID Context, domid_t Domain);
james@0 386
andy@15 387 VOID
james@258 388 GntTbl_Init(PXENPCI_DEVICE_DATA xpdd);
james@258 389
james@0 390 grant_ref_t
james@258 391 GntTbl_GrantAccess(PVOID Context, domid_t domid, uint32_t, int readonly, grant_ref_t ref);
james@0 392 BOOLEAN
james@258 393 GntTbl_EndAccess(PVOID Context, grant_ref_t ref, BOOLEAN keepref);
james@206 394 VOID
james@258 395 GntTbl_PutRef(PVOID Context, grant_ref_t ref);
james@206 396 grant_ref_t
james@258 397 GntTbl_GetRef(PVOID Context);
james@279 398 int
james@279 399 GntTbl_Map(PVOID Context, unsigned int start_idx, unsigned int end_idx);
james@0 400 #endif