win-pvdrivers

view xenvbd/xenvbd_storport.h @ 979:8f483a2b2991

Fix up PREfast warnings
author James Harper <james.harper@bendigoit.com.au>
date Sun Apr 15 19:47:10 2012 +1000 (2012-04-15)
parents 4b8b40cda748
children e9011a1ba5bb aefd5458e6c3
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(_XENVBD_H_)
21 #define _XENVBD_H_
23 #include <ntddk.h>
24 #include <wdm.h>
25 #include <initguid.h>
26 #define NTSTRSAFE_LIB
27 #include <ntstrsafe.h>
28 #include <storport.h>
29 #include <ntddscsi.h>
30 #include <ntdddisk.h>
31 #include <stdlib.h>
33 #define __DRIVER_NAME "XenVbd"
35 #include <xen_windows.h>
36 #include <xen_public.h>
37 #include <io/protocols.h>
38 #include <memory.h>
39 #include <event_channel.h>
40 #include <hvm/params.h>
41 #include <hvm/hvm_op.h>
42 #include <io/ring.h>
43 #include <io/blkif.h>
44 #include <io/xenbus.h>
46 #define XENVBD_POOL_TAG (ULONG) 'XVBD'
48 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
49 #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
50 #define BLK_OTHER_RING_SIZE __RING_SIZE((blkif_other_sring_t *)0, PAGE_SIZE)
52 #if defined(__x86_64__)
53 #pragma pack(push, 4)
54 #endif
55 struct blkif_other_request {
56 uint8_t operation;
57 uint8_t nr_segments;
58 blkif_vdev_t handle;
59 uint64_t id;
60 blkif_sector_t sector_number;
61 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
62 };
63 struct blkif_other_response {
64 uint64_t id;
65 uint8_t operation;
66 int16_t status;
67 };
68 #if defined(__x86_64__)
69 #pragma pack(pop)
70 #endif
72 typedef struct blkif_other_request blkif_other_request_t;
73 typedef struct blkif_other_response blkif_other_response_t;
74 DEFINE_RING_TYPES(blkif_other, struct blkif_other_request, struct blkif_other_response);
76 typedef struct {
77 LIST_ENTRY list_entry;
78 PSCSI_REQUEST_BLOCK srb;
79 ULONG length; /* cached srb length */
80 ULONG offset; /* current srb offset */
81 ULONG outstanding_requests; /* number of requests sent to xen for this srb */
82 BOOLEAN error; /* true if any sub requests have returned an error */
83 } srb_list_entry_t;
85 typedef struct {
86 blkif_request_t req;
87 srb_list_entry_t *srb_list_entry;
88 PSCSI_REQUEST_BLOCK srb;
89 PVOID system_address;
90 ULONG length;
91 BOOLEAN aligned_buffer_in_use;
92 BOOLEAN reset;
93 #if DBG && NTDDI_VERSION >= NTDDI_WINXP
94 LARGE_INTEGER ring_submit_time;
95 #endif
96 } blkif_shadow_t;
98 #define MAX_SHADOW_ENTRIES 64
99 #define SHADOW_ID_ID_MASK 0x03FF /* maximum of 1024 requests - currently use a maximum of 64 though */
100 #define SHADOW_ID_DUMP_FLAG 0x8000 /* indicates the request was generated by dump mode */
102 #define SHADOW_ENTRIES min(MAX_SHADOW_ENTRIES, min(BLK_RING_SIZE, BLK_OTHER_RING_SIZE))
104 typedef enum {
105 XENVBD_DEVICETYPE_UNKNOWN,
106 XENVBD_DEVICETYPE_DISK,
107 XENVBD_DEVICETYPE_CDROM,
108 XENVBD_DEVICETYPE_CONTROLLER // Not yet used
109 } XENVBD_DEVICETYPE;
111 typedef enum {
112 XENVBD_DEVICEMODE_UNKNOWN,
113 XENVBD_DEVICEMODE_READ,
114 XENVBD_DEVICEMODE_WRITE
115 } XENVBD_DEVICEMODE;
117 #define RING_DETECT_STATE_NOT_STARTED 0
118 #define RING_DETECT_STATE_DETECT1 1
119 #define RING_DETECT_STATE_DETECT2 2
120 #define RING_DETECT_STATE_COMPLETE 3
122 /* if this is ever increased to more than 1 then we need a way of tracking it properly */
123 #define DUMP_MODE_UNALIGNED_PAGES 1 /* only for unaligned buffer use */
125 struct
126 {
127 BOOLEAN inactive;
129 blkif_shadow_t shadows[MAX_SHADOW_ENTRIES];
130 USHORT shadow_free_list[MAX_SHADOW_ENTRIES];
131 USHORT shadow_free;
132 USHORT shadow_min_free;
133 ULONG grant_tag;
135 PUCHAR device_base;
137 blkif_sring_t *sring;
138 evtchn_port_t event_channel;
139 ULONG *event_channel_ptr;
140 union {
141 blkif_front_ring_t ring;
142 blkif_other_front_ring_t other_ring;
143 };
144 int ring_detect_state;
145 BOOLEAN use_other;
146 BOOLEAN cached_use_other;
147 UCHAR last_sense_key;
148 UCHAR last_additional_sense_code;
149 blkif_response_t tmp_rep;
150 XENVBD_DEVICETYPE device_type;
151 XENVBD_DEVICEMODE device_mode;
152 ULONG bytes_per_sector;
153 ULONGLONG total_sectors;
154 XENPCI_VECTORS vectors;
155 PXENPCI_DEVICE_STATE device_state;
156 LIST_ENTRY srb_list;
157 BOOLEAN aligned_buffer_in_use;
158 ULONG aligned_buffer_size;
159 PVOID aligned_buffer;
160 /*
161 ULONGLONG interrupts;
162 ULONGLONG aligned_requests;
163 ULONGLONG aligned_bytes;
164 ULONGLONG unaligned_requests;
165 ULONGLONG unaligned_bytes;
166 */
167 /* this is the size of the buffer to allocate at the end of DeviceExtenstion. It includes an extra PAGE_SIZE-1 bytes to assure that we can always align to PAGE_SIZE */
168 #define UNALIGNED_BUFFER_DATA_SIZE ((BLKIF_MAX_SEGMENTS_PER_REQUEST + 1) * PAGE_SIZE - 1)
169 #define UNALIGNED_BUFFER_DATA_SIZE_DUMP_MODE ((DUMP_MODE_UNALIGNED_PAGES + 1) * PAGE_SIZE - 1)
170 /* this has to be right at the end of DeviceExtension */
171 /* can't allocate too much data in dump mode so size DeviceExtensionSize accordingly */
172 UCHAR aligned_buffer_data[1];
173 } typedef XENVBD_DEVICE_DATA, *PXENVBD_DEVICE_DATA;
175 #endif