win-pvdrivers

view xenpci/xenpci.h @ 74:06b4321b7068

Created a common AllocagePages routine in xen_windows.h
Updated xennet and xenvbd to use it.
Updated xennet's method of getting the virtual address from the Mdl
author James Harper <james.harper@bendigoit.com.au>
date Thu Dec 20 21:37:20 2007 +1100 (2007-12-20)
parents f74723639713
children b7863ede7a37
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 <evtchn_public.h>
46 #include <xenbus_public.h>
47 #include <xen_public.h>
48 #include <gnttbl_public.h>
50 //{C828ABE9-14CA-4445-BAA6-82C2376C6518}
51 DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC828ABE9, 0x14CA, 0x4445, 0xBA, 0xA6, 0x82, 0xC2, 0x37, 0x6C, 0x65, 0x18);
53 #define XENPCI_POOL_TAG (ULONG) 'XenP'
54 //#define XENPCI_FDO_INSTANCE_SIGNATURE (ULONG) 'XENP'
56 #define NR_RESERVED_ENTRIES 8
57 #define NR_GRANT_FRAMES 4
58 #define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t))
60 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
62 typedef struct _XENPCI_IDENTIFICATION_DESCRIPTION
63 {
64 WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER Header;
65 UNICODE_STRING DeviceType;
66 char Path[128];
67 } XENPCI_IDENTIFICATION_DESCRIPTION, *PXENPCI_IDENTIFICATION_DESCRIPTION;
69 typedef struct _ev_action_t {
70 PKSERVICE_ROUTINE ServiceRoutine;
71 PVOID ServiceContext;
72 BOOLEAN DpcFlag;
73 WDFDPC Dpc;
74 ULONG Count;
75 } ev_action_t;
77 typedef struct {
78 ev_action_t *Action;
79 } EVTCHN_DEVICE_DATA, *PEVTCHN_DEVICE_DATA;
80 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(EVTCHN_DEVICE_DATA, GetEvtChnDeviceData);
82 typedef struct _XENBUS_WATCH_RING
83 {
84 char Path[128];
85 char Token[10];
86 } XENBUS_WATCH_RING;
88 typedef struct _XENBUS_REQ_INFO
89 {
90 int In_Use:1;
91 KEVENT WaitEvent;
92 void *Reply;
93 } XENBUS_REQ_INFO;
95 typedef struct _XENBUS_WATCH_ENTRY {
96 char Path[128];
97 PXENBUS_WATCH_CALLBACK ServiceRoutine;
98 PVOID ServiceContext;
99 int Count;
100 int Active;
101 } XENBUS_WATCH_ENTRY, *PXENBUS_WATCH_ENTRY;
103 #define NR_EVENTS 1024
104 #define WATCH_RING_SIZE 128
105 #define NR_XB_REQS 32
106 #define MAX_WATCH_ENTRIES 128
108 // TODO: tidy up & organize this struct
109 typedef struct {
111 WDFDEVICE Device;
112 BOOLEAN XenBus_ShuttingDown;
114 WDFINTERRUPT XenInterrupt;
115 ULONG irqNumber;
117 shared_info_t *shared_info_area;
119 PHYSICAL_ADDRESS platform_mmio_addr;
120 ULONG platform_mmio_orig_len;
121 ULONG platform_mmio_len;
122 ULONG platform_mmio_alloc;
124 char *hypercall_stubs;
126 evtchn_port_t xen_store_evtchn;
128 grant_entry_t *gnttab_table;
129 PHYSICAL_ADDRESS gnttab_table_physical;
130 grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
132 ev_action_t ev_actions[NR_EVENTS];
133 unsigned long bound_ports[NR_EVENTS/(8*sizeof(unsigned long))];
135 HANDLE XenBus_ReadThreadHandle;
136 KEVENT XenBus_ReadThreadEvent;
137 HANDLE XenBus_WatchThreadHandle;
138 KEVENT XenBus_WatchThreadEvent;
140 XENBUS_WATCH_RING XenBus_WatchRing[WATCH_RING_SIZE];
141 int XenBus_WatchRingReadIndex;
142 int XenBus_WatchRingWriteIndex;
144 struct xenstore_domain_interface *xen_store_interface;
146 XENBUS_REQ_INFO req_info[NR_XB_REQS];
147 int nr_live_reqs;
148 XENBUS_WATCH_ENTRY XenBus_WatchEntries[MAX_WATCH_ENTRIES];
150 } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
152 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENPCI_DEVICE_DATA, GetDeviceData);
154 typedef unsigned long xenbus_transaction_t;
155 typedef uint32_t XENSTORE_RING_IDX;
157 #define XBT_NIL ((xenbus_transaction_t)0)
159 char *
160 XenBus_Read(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
161 char *
162 XenBus_Write(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
163 char *
164 XenBus_Printf(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
165 char *
166 XenBus_StartTransaction(PVOID Context, xenbus_transaction_t *xbt);
167 char *
168 XenBus_EndTransaction(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
169 char *
170 XenBus_List(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
171 NTSTATUS
172 XenBus_Init(WDFDEVICE Device);
173 NTSTATUS
174 XenBus_Close(WDFDEVICE Device);
175 NTSTATUS
176 XenBus_Start(WDFDEVICE Device);
177 NTSTATUS
178 XenBus_Stop(WDFDEVICE Device);
179 char *
180 XenBus_AddWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
181 char *
182 XenBus_RemWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
183 VOID
184 XenBus_ThreadProc(PVOID StartContext);
186 PHYSICAL_ADDRESS
187 XenPCI_AllocMMIO(WDFDEVICE Device, ULONG len);
189 NTSTATUS
190 EvtChn_Init(WDFDEVICE Device);
191 BOOLEAN
192 EvtChn_Interrupt(WDFINTERRUPT Interrupt, ULONG MessageID);
193 VOID
194 EvtChn_InterruptDpc(WDFINTERRUPT Interrupt, WDFOBJECT AssociatedObject);
195 NTSTATUS
196 EvtChn_Mask(PVOID Context, evtchn_port_t Port);
197 NTSTATUS
198 EvtChn_Unmask(PVOID Context, evtchn_port_t Port);
199 NTSTATUS
200 EvtChn_Bind(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
201 NTSTATUS
202 EvtChn_BindDpc(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
203 NTSTATUS
204 EvtChn_Unbind(PVOID Context, evtchn_port_t Port);
205 NTSTATUS
206 EvtChn_Notify(PVOID Context, evtchn_port_t Port);
207 evtchn_port_t
208 EvtChn_AllocUnbound(PVOID Context, domid_t Domain);
209 evtchn_port_t
210 EvtChn_GetXenStorePort(WDFDEVICE Device);
211 PVOID
212 EvtChn_GetXenStoreRingAddr(WDFDEVICE Device);
214 VOID
215 GntTbl_Init(WDFDEVICE Device);
216 grant_ref_t
217 GntTbl_GrantAccess(WDFDEVICE Device, domid_t domid, unsigned long frame, int readonly);
218 BOOLEAN
219 GntTbl_EndAccess(WDFDEVICE Device, grant_ref_t ref);
221 #endif