win-pvdrivers

view xenpci/xenpci.h @ 73:f74723639713

Corrected merge of dpc patches.
Releasing 0.5.0.0
author James Harper <james.harper@bendigoit.com.au>
date Thu Dec 20 13:07:44 2007 +1100 (2007-12-20)
parents 7ae8e22810a3
children 06b4321b7068
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 #include <xen_windows.h>
37 #include <memory.h>
38 #include <grant_table.h>
39 #include <event_channel.h>
40 #include <hvm/params.h>
41 #include <hvm/hvm_op.h>
43 #include <evtchn_public.h>
44 #include <xenbus_public.h>
45 #include <xen_public.h>
46 #include <gnttbl_public.h>
48 //{C828ABE9-14CA-4445-BAA6-82C2376C6518}
49 DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC828ABE9, 0x14CA, 0x4445, 0xBA, 0xA6, 0x82, 0xC2, 0x37, 0x6C, 0x65, 0x18);
51 #define __DRIVER_NAME "XenPCI"
52 #define XENPCI_POOL_TAG (ULONG) 'XenP'
53 //#define XENPCI_FDO_INSTANCE_SIGNATURE (ULONG) 'XENP'
55 #define NR_RESERVED_ENTRIES 8
56 #define NR_GRANT_FRAMES 4
57 #define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t))
59 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
61 typedef struct _XENPCI_IDENTIFICATION_DESCRIPTION
62 {
63 WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER Header;
64 UNICODE_STRING DeviceType;
65 char Path[128];
66 } XENPCI_IDENTIFICATION_DESCRIPTION, *PXENPCI_IDENTIFICATION_DESCRIPTION;
68 typedef struct _ev_action_t {
69 PKSERVICE_ROUTINE ServiceRoutine;
70 PVOID ServiceContext;
71 BOOLEAN DpcFlag;
72 WDFDPC Dpc;
73 ULONG Count;
74 } ev_action_t;
76 typedef struct {
77 ev_action_t *Action;
78 } EVTCHN_DEVICE_DATA, *PEVTCHN_DEVICE_DATA;
79 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(EVTCHN_DEVICE_DATA, GetEvtChnDeviceData);
81 typedef struct _XENBUS_WATCH_RING
82 {
83 char Path[128];
84 char Token[10];
85 } XENBUS_WATCH_RING;
87 typedef struct _XENBUS_REQ_INFO
88 {
89 int In_Use:1;
90 KEVENT WaitEvent;
91 void *Reply;
92 } XENBUS_REQ_INFO;
94 typedef struct _XENBUS_WATCH_ENTRY {
95 char Path[128];
96 PXENBUS_WATCH_CALLBACK ServiceRoutine;
97 PVOID ServiceContext;
98 int Count;
99 int Active;
100 } XENBUS_WATCH_ENTRY, *PXENBUS_WATCH_ENTRY;
102 #define NR_EVENTS 1024
103 #define WATCH_RING_SIZE 128
104 #define NR_XB_REQS 32
105 #define MAX_WATCH_ENTRIES 128
107 // TODO: tidy up & organize this struct
108 typedef struct {
110 WDFDEVICE Device;
111 BOOLEAN XenBus_ShuttingDown;
113 WDFINTERRUPT XenInterrupt;
114 ULONG irqNumber;
116 shared_info_t *shared_info_area;
118 PHYSICAL_ADDRESS platform_mmio_addr;
119 ULONG platform_mmio_orig_len;
120 ULONG platform_mmio_len;
121 ULONG platform_mmio_alloc;
123 char *hypercall_stubs;
125 evtchn_port_t xen_store_evtchn;
127 grant_entry_t *gnttab_table;
128 PHYSICAL_ADDRESS gnttab_table_physical;
129 grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
131 ev_action_t ev_actions[NR_EVENTS];
132 unsigned long bound_ports[NR_EVENTS/(8*sizeof(unsigned long))];
134 HANDLE XenBus_ReadThreadHandle;
135 KEVENT XenBus_ReadThreadEvent;
136 HANDLE XenBus_WatchThreadHandle;
137 KEVENT XenBus_WatchThreadEvent;
139 XENBUS_WATCH_RING XenBus_WatchRing[WATCH_RING_SIZE];
140 int XenBus_WatchRingReadIndex;
141 int XenBus_WatchRingWriteIndex;
143 struct xenstore_domain_interface *xen_store_interface;
145 XENBUS_REQ_INFO req_info[NR_XB_REQS];
146 int nr_live_reqs;
147 XENBUS_WATCH_ENTRY XenBus_WatchEntries[MAX_WATCH_ENTRIES];
149 } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
151 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENPCI_DEVICE_DATA, GetDeviceData);
153 typedef unsigned long xenbus_transaction_t;
154 typedef uint32_t XENSTORE_RING_IDX;
156 #define XBT_NIL ((xenbus_transaction_t)0)
158 char *
159 XenBus_Read(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
160 char *
161 XenBus_Write(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
162 char *
163 XenBus_Printf(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
164 char *
165 XenBus_StartTransaction(PVOID Context, xenbus_transaction_t *xbt);
166 char *
167 XenBus_EndTransaction(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
168 char *
169 XenBus_List(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
170 NTSTATUS
171 XenBus_Init(WDFDEVICE Device);
172 NTSTATUS
173 XenBus_Close(WDFDEVICE Device);
174 NTSTATUS
175 XenBus_Start(WDFDEVICE Device);
176 NTSTATUS
177 XenBus_Stop(WDFDEVICE Device);
178 char *
179 XenBus_AddWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
180 char *
181 XenBus_RemWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
182 VOID
183 XenBus_ThreadProc(PVOID StartContext);
185 PHYSICAL_ADDRESS
186 XenPCI_AllocMMIO(WDFDEVICE Device, ULONG len);
188 NTSTATUS
189 EvtChn_Init(WDFDEVICE Device);
190 BOOLEAN
191 EvtChn_Interrupt(WDFINTERRUPT Interrupt, ULONG MessageID);
192 VOID
193 EvtChn_InterruptDpc(WDFINTERRUPT Interrupt, WDFOBJECT AssociatedObject);
194 NTSTATUS
195 EvtChn_Mask(PVOID Context, evtchn_port_t Port);
196 NTSTATUS
197 EvtChn_Unmask(PVOID Context, evtchn_port_t Port);
198 NTSTATUS
199 EvtChn_Bind(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
200 NTSTATUS
201 EvtChn_BindDpc(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
202 NTSTATUS
203 EvtChn_Unbind(PVOID Context, evtchn_port_t Port);
204 NTSTATUS
205 EvtChn_Notify(PVOID Context, evtchn_port_t Port);
206 evtchn_port_t
207 EvtChn_AllocUnbound(PVOID Context, domid_t Domain);
208 evtchn_port_t
209 EvtChn_GetXenStorePort(WDFDEVICE Device);
210 PVOID
211 EvtChn_GetXenStoreRingAddr(WDFDEVICE Device);
213 VOID
214 GntTbl_Init(WDFDEVICE Device);
215 grant_ref_t
216 GntTbl_GrantAccess(WDFDEVICE Device, domid_t domid, unsigned long frame, int readonly);
217 BOOLEAN
218 GntTbl_EndAccess(WDFDEVICE Device, grant_ref_t ref);
220 #endif