/target/linux/omap4/

ame='id' value='40326f9fc30fb0fa94f7367e7e41c2e7a6b1efa1'/> xenJames
aboutsummaryrefslogtreecommitdiffstats
path: root/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.h
blob: b3368aa7d6f6ab3a03521a98df0c91c0d07fdedf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
 * blktap.h
 * 
 * Interfaces for the Xen block tap driver.
 * 
 * (c) 2004, Andrew Warfield, University of Cambridge
 * 
 */

#ifndef __BLKTAP_H__
#define __BLKTAP_H__

#include <linux/version.h>
#include <linux/blkdev.h>
#include <linux/config.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <asm-xen/ctrl_if.h>
#include <linux/slab.h>
#include <linux/blkdev.h>
#include <asm/io.h>
#include <asm/setup.h>
#include <asm/pgalloc.h>
#include <asm-xen/hypervisor.h>
#include <asm-xen/xen-public/io/blkif.h>
#include <asm-xen/xen-public/io/ring.h>

/* Used to signal to the backend that this is a tap domain. */
#define BLKTAP_COOKIE 0xbeadfeed

/* -------[ debug / pretty printing ]--------------------------------- */

#define PRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
                           __FILE__ , __LINE__ , ## _a )
#if 0
#define DPRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
                           __FILE__ , __LINE__ , ## _a )
#else
#define DPRINTK(_f, _a...) ((void)0)
#endif

#if 1
#define ASSERT(_p) \
    if ( !(_p) ) { printk("Assertion '%s' failed, line %d, file %s", #_p , \
    __LINE__, __FILE__); *(int*)0=0; }
#else
#define ASSERT(_p) ((void)0)
#endif

#define WPRINTK(fmt, args...) printk(KERN_WARNING "blk_tap: " fmt, ##args)


/* -------[ state descriptors ]--------------------------------------- */

#define BLKIF_STATE_CLOSED       0
#define BLKIF_STATE_DISCONNECTED 1
#define BLKIF_STATE_CONNECTED    2

/* -------[ connection tracking ]------------------------------------- */

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
#define VMALLOC_VMADDR(x) ((unsigned long)(x))
#endif

extern spinlock_t blkif_io_lock;

typedef struct blkif_st {
    /* Unique identifier for this interface. */
    domid_t             domid;
    unsigned int        handle;
    /* Physical parameters of the comms window. */
    unsigned long       shmem_frame;
    unsigned int        evtchn;
    /* Comms information. */
    blkif_back_ring_t   blk_ring;
    
    enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
    /*
     * DISCONNECT response is deferred until pending requests are ack'ed.
     * We therefore need to store the id from the original request.
     */    
    u8                  disconnect_rspid;
    struct blkif_st    *hash_next;
    struct list_head    blkdev_list;
    spinlock_t          blk_ring_lock;
    atomic_t            refcnt;
    struct work_struct work;
#ifdef CONFIG_XEN_BLKDEV_GRANT
    u16 shmem_handle;
    memory_t shmem_vaddr;
    grant_ref_t shmem_ref;
#endif
} blkif_t;

blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle);
void blkif_disconnect_complete(blkif_t *blkif);
#define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
#define blkif_put(_b)                             \
    do {                                          \
        if ( atomic_dec_and_test(&(_b)->refcnt) ) \
            blkif_disconnect_complete(_b);        \
    } while (0)


/* -------[ active request tracking ]--------------------------------- */

typedef struct {
    blkif_t       *blkif;
    unsigned long  id;
    int            nr_pages;
    int            next_free;
} active_req_t;

typedef unsigned int ACTIVE_RING_IDX;

active_req_t *lookup_active_req(ACTIVE_RING_IDX idx);

extern inline unsigned int ID_TO_IDX(unsigned long id) 
{ 
    return ( id & 0x0000ffff );
}

extern inline domid_t ID_TO_DOM(unsigned long id) 
{ 
    return (id >> 16); 
}

void active_reqs_init(void);

/* -------[ interposition -> character device interface ]------------- */

/* /dev/xen/blktap resides at device number major=10, minor=200        */ 
#define BLKTAP_MINOR 202

/* size of the extra VMA area to map in attached pages. */
#define BLKTAP_VMA_PAGES BLKIF_RING_SIZE

/* blktap IOCTLs:                                                      */
#define BLKTAP_IOCTL_KICK_FE         1
#define BLKTAP_IOCTL_KICK_BE         2
#define BLKTAP_IOCTL_SETMODE         3
#define BLKTAP_IOCTL_PRINT_IDXS      100  

/* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE)             */
#define BLKTAP_MODE_PASSTHROUGH      0x00000000  /* default            */
#define BLKTAP_MODE_INTERCEPT_FE     0x00000001
#define BLKTAP_MODE_INTERCEPT_BE     0x00000002
#define BLKTAP_MODE_COPY_FE          0x00000004
#define BLKTAP_MODE_COPY_BE          0x00000008
#define BLKTAP_MODE_COPY_FE_PAGES    0x00000010
#define BLKTAP_MODE_COPY_BE_PAGES    0x00000020

#define BLKTAP_MODE_INTERPOSE \