win-pvdrivers

annotate xenpci/xenpci.h @ 259:161a8a26f3db

Enumeration now working, but no useful info passed to child devices yet.
author James Harper <james.harper@bendigoit.com.au>
date Sun May 04 16:40:30 2008 +1000 (2008-05-04)
parents 9b16ad37af17
children 952b8aa9c44c
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@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
james@0 53 #define NR_RESERVED_ENTRIES 8
james@0 54 #define NR_GRANT_FRAMES 4
james@0 55 #define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t))
james@0 56
james@0 57 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
james@0 58
andy@13 59 typedef struct _ev_action_t {
andy@13 60 PKSERVICE_ROUTINE ServiceRoutine;
andy@13 61 PVOID ServiceContext;
james@73 62 BOOLEAN DpcFlag;
james@258 63 KDPC Dpc;
andy@13 64 ULONG Count;
andy@13 65 } ev_action_t;
james@0 66
andy@15 67 typedef struct _XENBUS_WATCH_RING
andy@15 68 {
andy@15 69 char Path[128];
andy@15 70 char Token[10];
andy@15 71 } XENBUS_WATCH_RING;
james@0 72
andy@15 73 typedef struct _XENBUS_REQ_INFO
andy@15 74 {
andy@15 75 int In_Use:1;
andy@15 76 KEVENT WaitEvent;
andy@15 77 void *Reply;
andy@15 78 } XENBUS_REQ_INFO;
james@0 79
andy@15 80 typedef struct _XENBUS_WATCH_ENTRY {
andy@15 81 char Path[128];
andy@15 82 PXENBUS_WATCH_CALLBACK ServiceRoutine;
andy@15 83 PVOID ServiceContext;
andy@15 84 int Count;
andy@15 85 int Active;
james@138 86 int RemovePending;
james@128 87 int Running;
james@128 88 KEVENT CompleteEvent;
andy@15 89 } XENBUS_WATCH_ENTRY, *PXENBUS_WATCH_ENTRY;
james@0 90
andy@13 91 #define NR_EVENTS 1024
andy@15 92 #define WATCH_RING_SIZE 128
andy@15 93 #define NR_XB_REQS 32
andy@15 94 #define MAX_WATCH_ENTRIES 128
james@0 95
james@259 96 #define CHILD_STATE_EMPTY 0
james@259 97 #define CHILD_STATE_DELETED 1
james@259 98 #define CHILD_STATE_ADDED 2
james@259 99
james@259 100 // TODO: tidy up & organize this struct
james@258 101
james@258 102 typedef struct
james@258 103 {
james@258 104 PDEVICE_OBJECT fdo;
james@258 105 PDEVICE_OBJECT pdo;
james@258 106 PDEVICE_OBJECT lower_do;
james@259 107 } XENPCI_COMMON, *PXENPCI_COMMON;
james@259 108
james@259 109 typedef struct {
james@259 110 XENPCI_COMMON common;
james@259 111
andy@38 112 BOOLEAN XenBus_ShuttingDown;
james@0 113
james@258 114 PKINTERRUPT interrupt;
james@258 115 ULONG irq_number;
james@258 116 ULONG irq_vector;
james@258 117 KIRQL irq_level;
james@258 118 KAFFINITY irq_affinity;
james@0 119
andy@13 120 shared_info_t *shared_info_area;
james@0 121
andy@13 122 PHYSICAL_ADDRESS platform_mmio_addr;
andy@13 123 ULONG platform_mmio_orig_len;
andy@13 124 ULONG platform_mmio_len;
andy@13 125 ULONG platform_mmio_alloc;
andy@13 126
andy@13 127 char *hypercall_stubs;
andy@13 128
andy@13 129 evtchn_port_t xen_store_evtchn;
andy@13 130
andy@13 131 grant_entry_t *gnttab_table;
andy@13 132 PHYSICAL_ADDRESS gnttab_table_physical;
andy@13 133 grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
andy@13 134
andy@13 135 ev_action_t ev_actions[NR_EVENTS];
james@258 136 // unsigned long bound_ports[NR_EVENTS/(8*sizeof(unsigned long))];
james@0 137
andy@15 138 HANDLE XenBus_ReadThreadHandle;
andy@15 139 KEVENT XenBus_ReadThreadEvent;
andy@15 140 HANDLE XenBus_WatchThreadHandle;
andy@15 141 KEVENT XenBus_WatchThreadEvent;
andy@15 142
andy@15 143 XENBUS_WATCH_RING XenBus_WatchRing[WATCH_RING_SIZE];
andy@15 144 int XenBus_WatchRingReadIndex;
andy@15 145 int XenBus_WatchRingWriteIndex;
andy@15 146
andy@15 147 struct xenstore_domain_interface *xen_store_interface;
andy@15 148
andy@15 149 XENBUS_REQ_INFO req_info[NR_XB_REQS];
andy@15 150 int nr_live_reqs;
andy@15 151 XENBUS_WATCH_ENTRY XenBus_WatchEntries[MAX_WATCH_ENTRIES];
james@0 152
james@128 153 KSPIN_LOCK WatchLock;
james@176 154 KSPIN_LOCK grant_lock;
james@191 155
james@191 156 KGUARDED_MUTEX WatchHandlerMutex;
james@198 157
james@259 158 LIST_ENTRY child_list;
james@258 159
james@198 160 int suspending;
james@0 161 } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
james@0 162
james@259 163 typedef struct {
james@259 164 XENPCI_COMMON common;
james@259 165 char path[128];
james@259 166 ULONG index;
james@259 167 } XENPCI_PDO_DEVICE_DATA, *PXENPCI_PDO_DEVICE_DATA;
james@0 168
james@259 169 typedef struct
james@259 170 {
james@259 171 LIST_ENTRY entry;
james@259 172 int state;
james@259 173 PXENPCI_PDO_DEVICE_DATA context;
james@259 174 } XEN_CHILD, *PXEN_CHILD;
james@259 175
james@258 176 #include "hypercall.h"
james@124 177
james@0 178 typedef unsigned long xenbus_transaction_t;
james@0 179 typedef uint32_t XENSTORE_RING_IDX;
james@0 180
james@0 181 #define XBT_NIL ((xenbus_transaction_t)0)
james@0 182
james@259 183 NTSTATUS
james@259 184 XenPci_Power_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
james@259 185 NTSTATUS
james@259 186 XenPci_Dummy_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
james@259 187 NTSTATUS
james@259 188 XenPci_Pnp_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
james@259 189
james@259 190 NTSTATUS
james@259 191 XenPci_Power_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
james@259 192 NTSTATUS
james@259 193 XenPci_Dummy_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
james@259 194 NTSTATUS
james@259 195 XenPci_Pnp_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
james@259 196
james@259 197
james@259 198
james@0 199 char *
andy@13 200 XenBus_Read(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
james@0 201 char *
andy@13 202 XenBus_Write(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
james@0 203 char *
andy@13 204 XenBus_Printf(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
james@0 205 char *
andy@13 206 XenBus_StartTransaction(PVOID Context, xenbus_transaction_t *xbt);
james@0 207 char *
andy@13 208 XenBus_EndTransaction(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
andy@13 209 char *
andy@13 210 XenBus_List(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
james@0 211 char *
andy@13 212 XenBus_AddWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
james@0 213 char *
andy@13 214 XenBus_RemWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
james@0 215 VOID
james@0 216 XenBus_ThreadProc(PVOID StartContext);
james@258 217 NTSTATUS
james@258 218 XenBus_Init(PXENPCI_DEVICE_DATA xpdd);
james@258 219 NTSTATUS
james@258 220 XenBus_Close(PXENPCI_DEVICE_DATA xpdd);
james@258 221 NTSTATUS
james@258 222 XenBus_Start(PXENPCI_DEVICE_DATA xpdd);
james@258 223 NTSTATUS
james@258 224 XenBus_Stop(PXENPCI_DEVICE_DATA xpdd);
james@0 225
james@0 226 PHYSICAL_ADDRESS
james@258 227 XenPci_AllocMMIO(PXENPCI_DEVICE_DATA xpdd, ULONG len);
james@0 228
andy@15 229 NTSTATUS
james@258 230 EvtChn_Init(PXENPCI_DEVICE_DATA xpdd);
james@258 231 NTSTATUS
james@258 232 EvtChn_Shutdown(PXENPCI_DEVICE_DATA xpdd);
james@258 233
james@0 234 NTSTATUS
andy@13 235 EvtChn_Mask(PVOID Context, evtchn_port_t Port);
james@0 236 NTSTATUS
andy@13 237 EvtChn_Unmask(PVOID Context, evtchn_port_t Port);
james@0 238 NTSTATUS
andy@13 239 EvtChn_Bind(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
james@0 240 NTSTATUS
james@73 241 EvtChn_BindDpc(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
james@73 242 NTSTATUS
andy@13 243 EvtChn_Unbind(PVOID Context, evtchn_port_t Port);
andy@13 244 NTSTATUS
andy@13 245 EvtChn_Notify(PVOID Context, evtchn_port_t Port);
james@0 246 evtchn_port_t
andy@13 247 EvtChn_AllocUnbound(PVOID Context, domid_t Domain);
james@0 248
andy@15 249 VOID
james@258 250 GntTbl_Init(PXENPCI_DEVICE_DATA xpdd);
james@258 251
james@0 252 grant_ref_t
james@258 253 GntTbl_GrantAccess(PVOID Context, domid_t domid, uint32_t, int readonly, grant_ref_t ref);
james@0 254 BOOLEAN
james@258 255 GntTbl_EndAccess(PVOID Context, grant_ref_t ref, BOOLEAN keepref);
james@206 256 VOID
james@258 257 GntTbl_PutRef(PVOID Context, grant_ref_t ref);
james@206 258 grant_ref_t
james@258 259 GntTbl_GetRef(PVOID Context);
james@0 260
james@0 261 #endif