win-pvdrivers

view xenpci/xenpci.h @ 15:7f0f866dced6

wean xenbus.c off of global variables

rename some variables from deviceData to xpdd for brevity
some whitespace fixes
author Andy Grover <andy@groveronline.com>
date Wed Nov 28 16:49:26 2007 -0800 (2007-11-28)
parents be8c09632f31
children f56c47274c37
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 // ULONG DeviceIndex;
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 ULONG Count;
73 } ev_action_t;
75 typedef struct _XENBUS_WATCH_RING
76 {
77 char Path[128];
78 char Token[10];
79 } XENBUS_WATCH_RING;
81 typedef struct _XENBUS_REQ_INFO
82 {
83 int In_Use:1;
84 KEVENT WaitEvent;
85 void *Reply;
86 } XENBUS_REQ_INFO;
88 typedef struct _XENBUS_WATCH_ENTRY {
89 char Path[128];
90 PXENBUS_WATCH_CALLBACK ServiceRoutine;
91 PVOID ServiceContext;
92 int Count;
93 int Active;
94 } XENBUS_WATCH_ENTRY, *PXENBUS_WATCH_ENTRY;
96 #define NR_EVENTS 1024
97 #define WATCH_RING_SIZE 128
98 #define NR_XB_REQS 32
99 #define MAX_WATCH_ENTRIES 128
101 // TODO: tidy up & organize this struct
102 typedef struct {
104 WDFDEVICE Device;
106 WDFINTERRUPT XenInterrupt;
107 ULONG irqNumber;
109 shared_info_t *shared_info_area;
111 PHYSICAL_ADDRESS platform_mmio_addr;
112 ULONG platform_mmio_orig_len;
113 ULONG platform_mmio_len;
114 ULONG platform_mmio_alloc;
116 char *hypercall_stubs;
118 evtchn_port_t xen_store_evtchn;
120 grant_entry_t *gnttab_table;
121 PHYSICAL_ADDRESS gnttab_table_physical;
122 grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
124 ev_action_t ev_actions[NR_EVENTS];
125 unsigned long bound_ports[NR_EVENTS/(8*sizeof(unsigned long))];
127 HANDLE XenBus_ReadThreadHandle;
128 KEVENT XenBus_ReadThreadEvent;
129 HANDLE XenBus_WatchThreadHandle;
130 KEVENT XenBus_WatchThreadEvent;
132 XENBUS_WATCH_RING XenBus_WatchRing[WATCH_RING_SIZE];
133 int XenBus_WatchRingReadIndex;
134 int XenBus_WatchRingWriteIndex;
136 struct xenstore_domain_interface *xen_store_interface;
138 XENBUS_REQ_INFO req_info[NR_XB_REQS];
139 int nr_live_reqs;
140 XENBUS_WATCH_ENTRY XenBus_WatchEntries[MAX_WATCH_ENTRIES];
142 } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
144 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENPCI_DEVICE_DATA, GetDeviceData);
146 typedef unsigned long xenbus_transaction_t;
147 typedef uint32_t XENSTORE_RING_IDX;
149 #define XBT_NIL ((xenbus_transaction_t)0)
151 char *
152 XenBus_Read(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
153 char *
154 XenBus_Write(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
155 char *
156 XenBus_Printf(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
157 char *
158 XenBus_StartTransaction(PVOID Context, xenbus_transaction_t *xbt);
159 char *
160 XenBus_EndTransaction(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
161 char *
162 XenBus_List(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
163 NTSTATUS
164 XenBus_Init(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 BOOLEAN
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_Unbind(PVOID Context, evtchn_port_t Port);
193 NTSTATUS
194 EvtChn_Notify(PVOID Context, evtchn_port_t Port);
195 evtchn_port_t
196 EvtChn_AllocUnbound(PVOID Context, domid_t Domain);
197 evtchn_port_t
198 EvtChn_GetXenStorePort(WDFDEVICE Device);
199 PVOID
200 EvtChn_GetXenStoreRingAddr(WDFDEVICE Device);
202 VOID
203 GntTbl_Init(WDFDEVICE Device);
204 grant_ref_t
205 GntTbl_GrantAccess(WDFDEVICE Device, domid_t domid, unsigned long frame, int readonly);
206 BOOLEAN
207 GntTbl_EndAccess(WDFDEVICE Device, grant_ref_t ref);
209 #endif