Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / xen / blktap / common.h
1 /* 
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License version 2
4  * as published by the Free Software Foundation; or, when distributed
5  * separately from the Linux kernel or incorporated into other
6  * software packages, subject to the following license:
7  * 
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this source file (the "Software"), to deal in the Software without
10  * restriction, including without limitation the rights to use, copy, modify,
11  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
12  * and to permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  * 
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  * 
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24  * IN THE SOFTWARE.
25  */
26
27 #ifndef __BLKIF__BACKEND__COMMON_H__
28 #define __BLKIF__BACKEND__COMMON_H__
29
30 #include <linux/interrupt.h>
31 #include <linux/slab.h>
32 #include <linux/blkdev.h>
33 #include <asm/hypervisor.h>
34 #include <xen/blkif.h>
35 #include <xen/xenbus.h>
36 #include <xen/interface/event_channel.h>
37
38 #define DPRINTK(_f, _a...) pr_debug("(file=%s, line=%d) " _f, \
39                                     __FILE__ , __LINE__ , ## _a )
40
41 #define WPRINTK(fmt, args...) pr_warning("blktap: " fmt, ##args)
42
43 struct backend_info;
44
45 typedef struct blkif_st {
46         /* Unique identifier for this interface. */
47         domid_t           domid;
48         unsigned int      handle;
49         /* Physical parameters of the comms window. */
50         unsigned int      irq;
51         /* Comms information. */
52         enum blkif_protocol blk_protocol;
53         blkif_back_rings_t blk_rings;
54         struct vm_struct *blk_ring_area;
55         /* Back pointer to the backend_info. */
56         struct backend_info *be;
57         /* Private fields. */
58         spinlock_t       blk_ring_lock;
59         atomic_t         refcnt;
60
61         wait_queue_head_t   wq;
62         struct task_struct  *xenblkd;
63         unsigned int        waiting_reqs;
64         struct request_queue *plug;
65
66         /* statistics */
67         unsigned long       st_print;
68         int                 st_rd_req;
69         int                 st_wr_req;
70         int                 st_oo_req;
71         int                 st_pk_req;
72         int                 st_rd_sect;
73         int                 st_wr_sect;
74
75         wait_queue_head_t waiting_to_free;
76
77         int             dev_num;
78         uint64_t        sectors;
79 } blkif_t;
80
81 blkif_t *tap_alloc_blkif(domid_t domid);
82 void tap_blkif_free(blkif_t *, struct xenbus_device *);
83 void tap_blkif_kmem_cache_free(blkif_t *blkif);
84 int tap_blkif_map(blkif_t *, struct xenbus_device *, grant_ref_t,
85                   evtchn_port_t);
86
87 #define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
88 #define blkif_put(_b)                                   \
89         do {                                            \
90                 if (atomic_dec_and_test(&(_b)->refcnt)) \
91                         wake_up(&(_b)->waiting_to_free);\
92         } while (0)
93
94
95 struct phys_req {
96         unsigned short       dev;
97         unsigned short       nr_sects;
98         struct block_device *bdev;
99         blkif_sector_t       sector_number;
100 };
101
102 void tap_blkif_interface_init(void);
103
104 void tap_blkif_xenbus_init(void);
105
106 irqreturn_t tap_blkif_be_int(int irq, void *dev_id);
107 int tap_blkif_schedule(void *arg);
108
109 int dom_to_devid(domid_t domid, int xenbus_id, blkif_t *blkif);
110 void signal_tapdisk(int idx);
111
112 #endif /* __BLKIF__BACKEND__COMMON_H__ */