win-pvdrivers

view xenpci/xenpci.h @ 75:b7863ede7a37

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