win-pvdrivers

view xenvbd/xenvbd.h @ 810:1293cb31aa0b

try and allocate less memory for dump mode.
This appears to break hibernation by corrupting memory - not sure why yet
author James Harper <james.harper@bendigoit.com.au>
date Wed Aug 11 09:10:15 2010 +1000 (2010-08-11)
parents bbc6c94b9621
children 4d1539643494
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 #define DDKAPI
25 //#include <ntifs.h>
26 #include <ntddk.h>
27 #include <wdm.h>
28 #include <initguid.h>
29 #define NTSTRSAFE_LIB
30 #include <ntstrsafe.h>
32 #include <ntdddisk.h>
33 #include <srb.h>
35 #define __DRIVER_NAME "XenVbd"
37 #include <xen_windows.h>
38 #include <memory.h>
39 //#include <grant_table.h>
40 #include <event_channel.h>
41 #include <hvm/params.h>
42 #include <hvm/hvm_op.h>
43 #include <xen_public.h>
44 #include <io/ring.h>
45 #include <io/blkif.h>
46 #include <io/xenbus.h>
48 #define XENVBD_POOL_TAG (ULONG) 'XVBD'
50 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
51 #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
52 #define BLK_OTHER_RING_SIZE __RING_SIZE((blkif_other_sring_t *)0, PAGE_SIZE)
54 #if defined(__x86_64__)
55 #pragma pack(push, 4)
56 #endif
57 struct blkif_other_request {
58 uint8_t operation;
59 uint8_t nr_segments;
60 blkif_vdev_t handle;
61 uint64_t id;
62 blkif_sector_t sector_number;
63 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
64 };
65 struct blkif_other_response {
66 uint64_t id;
67 uint8_t operation;
68 int16_t status;
69 };
70 #if defined(__x86_64__)
71 #pragma pack(pop)
72 #endif
74 typedef struct blkif_other_request blkif_other_request_t;
75 typedef struct blkif_other_response blkif_other_response_t;
76 DEFINE_RING_TYPES(blkif_other, struct blkif_other_request, struct blkif_other_response);
78 typedef struct {
79 LIST_ENTRY list_entry;
80 PSCSI_REQUEST_BLOCK srb;
81 } srb_list_entry_t;
83 typedef struct {
84 blkif_request_t req;
85 PSCSI_REQUEST_BLOCK srb;
86 BOOLEAN aligned_buffer_in_use;
87 } blkif_shadow_t;
89 #define MAX_SHADOW_ENTRIES 64
90 #define SHADOW_ENTRIES min(MAX_SHADOW_ENTRIES, min(BLK_RING_SIZE, BLK_OTHER_RING_SIZE))
92 typedef enum {
93 XENVBD_DEVICETYPE_UNKNOWN,
94 XENVBD_DEVICETYPE_DISK,
95 XENVBD_DEVICETYPE_CDROM,
96 XENVBD_DEVICETYPE_CONTROLLER // Not yet used
97 } XENVBD_DEVICETYPE;
99 typedef enum {
100 XENVBD_DEVICEMODE_UNKNOWN,
101 XENVBD_DEVICEMODE_READ,
102 XENVBD_DEVICEMODE_WRITE
103 } XENVBD_DEVICEMODE;
105 #define RING_DETECT_STATE_NOT_STARTED 0
106 #define RING_DETECT_STATE_DETECT1 1
107 #define RING_DETECT_STATE_DETECT2 2
108 #define RING_DETECT_STATE_COMPLETE 3
110 struct
111 {
112 BOOLEAN inactive;
114 blkif_shadow_t shadows[MAX_SHADOW_ENTRIES];
115 USHORT shadow_free_list[MAX_SHADOW_ENTRIES];
116 USHORT shadow_free;
117 USHORT shadow_min_free;
119 PUCHAR device_base;
121 blkif_sring_t *sring;
122 evtchn_port_t event_channel;
123 ULONG *event_channel_ptr;
124 union {
125 blkif_front_ring_t ring;
126 blkif_other_front_ring_t other_ring;
127 };
128 int ring_detect_state;
129 BOOLEAN use_other;
130 BOOLEAN cached_use_other;
131 UCHAR last_sense_key;
132 UCHAR last_additional_sense_code;
133 blkif_response_t tmp_rep;
134 XENVBD_DEVICETYPE device_type;
135 XENVBD_DEVICEMODE device_mode;
136 ULONG bytes_per_sector;
137 ULONGLONG total_sectors;
138 XENPCI_VECTORS vectors;
139 PXENPCI_DEVICE_STATE device_state;
140 LIST_ENTRY srb_list;
141 grant_ref_t dump_grant_refs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
142 BOOLEAN aligned_buffer_in_use;
143 PVOID aligned_buffer;
144 /*
145 ULONGLONG interrupts;
146 ULONGLONG aligned_requests;
147 ULONGLONG aligned_bytes;
148 ULONGLONG unaligned_requests;
149 ULONGLONG unaligned_bytes;
150 */
151 #define BLKIF_MAX_SEGMENTS_PER_REQUEST_DUMP_MODE 1
152 #define UNALIGNED_BUFFER_DATA_SIZE ((BLKIF_MAX_SEGMENTS_PER_REQUEST + 1) * PAGE_SIZE - 1)
153 #define UNALIGNED_BUFFER_DATA_SIZE_DUMP_MODE ((BLKIF_MAX_SEGMENTS_PER_REQUEST_DUMP_MODE + 1) * PAGE_SIZE - 1)
154 /* this has to be right at the end of DeviceExtension */
155 /* can't allocate too much data in dump mode so size DeviceExtensionSize accordingly */
156 UCHAR aligned_buffer_data[1];
157 } typedef XENVBD_DEVICE_DATA, *PXENVBD_DEVICE_DATA;
159 #endif