win-pvdrivers

view xenpci/xenpci.h @ 38:a5617e7e9f54

fixups from manual merge
author Andy Grover <andy.grover@oracle.com>
date Wed Dec 05 11:37:53 2007 -0800 (2007-12-05)
parents 3ac5c4431dbb
children 7ae8e22810a3
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;
105 BOOLEAN XenBus_ShuttingDown;
107 WDFINTERRUPT XenInterrupt;
108 ULONG irqNumber;
110 shared_info_t *shared_info_area;
112 PHYSICAL_ADDRESS platform_mmio_addr;
113 ULONG platform_mmio_orig_len;
114 ULONG platform_mmio_len;
115 ULONG platform_mmio_alloc;
117 char *hypercall_stubs;
119 evtchn_port_t xen_store_evtchn;
121 grant_entry_t *gnttab_table;
122 PHYSICAL_ADDRESS gnttab_table_physical;
123 grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
125 ev_action_t ev_actions[NR_EVENTS];
126 unsigned long bound_ports[NR_EVENTS/(8*sizeof(unsigned long))];
128 HANDLE XenBus_ReadThreadHandle;
129 KEVENT XenBus_ReadThreadEvent;
130 HANDLE XenBus_WatchThreadHandle;
131 KEVENT XenBus_WatchThreadEvent;
133 XENBUS_WATCH_RING XenBus_WatchRing[WATCH_RING_SIZE];
134 int XenBus_WatchRingReadIndex;
135 int XenBus_WatchRingWriteIndex;
137 struct xenstore_domain_interface *xen_store_interface;
139 XENBUS_REQ_INFO req_info[NR_XB_REQS];
140 int nr_live_reqs;
141 XENBUS_WATCH_ENTRY XenBus_WatchEntries[MAX_WATCH_ENTRIES];
143 } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
145 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENPCI_DEVICE_DATA, GetDeviceData);
147 typedef unsigned long xenbus_transaction_t;
148 typedef uint32_t XENSTORE_RING_IDX;
150 #define XBT_NIL ((xenbus_transaction_t)0)
152 char *
153 XenBus_Read(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
154 char *
155 XenBus_Write(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
156 char *
157 XenBus_Printf(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
158 char *
159 XenBus_StartTransaction(PVOID Context, xenbus_transaction_t *xbt);
160 char *
161 XenBus_EndTransaction(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
162 char *
163 XenBus_List(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
164 NTSTATUS
165 XenBus_Init(WDFDEVICE Device);
166 NTSTATUS
167 XenBus_Close(WDFDEVICE Device);
168 NTSTATUS
169 XenBus_Start(WDFDEVICE Device);
170 NTSTATUS
171 XenBus_Stop(WDFDEVICE Device);
172 char *
173 XenBus_AddWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
174 char *
175 XenBus_RemWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
176 VOID
177 XenBus_ThreadProc(PVOID StartContext);
179 PHYSICAL_ADDRESS
180 XenPCI_AllocMMIO(WDFDEVICE Device, ULONG len);
182 NTSTATUS
183 EvtChn_Init(WDFDEVICE Device);
184 BOOLEAN
185 EvtChn_Interrupt(WDFINTERRUPT Interrupt, ULONG MessageID);
186 BOOLEAN
187 EvtChn_InterruptDpc(WDFINTERRUPT Interrupt, WDFOBJECT AssociatedObject);
188 NTSTATUS
189 EvtChn_Mask(PVOID Context, evtchn_port_t Port);
190 NTSTATUS
191 EvtChn_Unmask(PVOID Context, evtchn_port_t Port);
192 NTSTATUS
193 EvtChn_Bind(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
194 NTSTATUS
195 EvtChn_Unbind(PVOID Context, evtchn_port_t Port);
196 NTSTATUS
197 EvtChn_Notify(PVOID Context, evtchn_port_t Port);
198 evtchn_port_t
199 EvtChn_AllocUnbound(PVOID Context, domid_t Domain);
200 evtchn_port_t
201 EvtChn_GetXenStorePort(WDFDEVICE Device);
202 PVOID
203 EvtChn_GetXenStoreRingAddr(WDFDEVICE Device);
205 VOID
206 GntTbl_Init(WDFDEVICE Device);
207 grant_ref_t
208 GntTbl_GrantAccess(WDFDEVICE Device, domid_t domid, unsigned long frame, int readonly);
209 BOOLEAN
210 GntTbl_EndAccess(WDFDEVICE Device, grant_ref_t ref);
212 #endif