Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.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/version.h>
31 #include <linux/module.h>
32 #include <linux/interrupt.h>
33 #include <linux/slab.h>
34 #include <linux/blkdev.h>
35 #include <linux/vmalloc.h>
36 #include <asm/io.h>
37 #include <asm/setup.h>
38 #include <asm/pgalloc.h>
39 #include <xen/evtchn.h>
40 #include <asm/hypervisor.h>
41 #include <xen/interface/io/blkif.h>
42 #include <xen/interface/io/ring.h>
43 #include <xen/gnttab.h>
44 #include <xen/driver_util.h>
45
46 #define DPRINTK(_f, _a...) pr_debug("(file=%s, line=%d) " _f, \
47                                     __FILE__ , __LINE__ , ## _a )
48
49 #define WPRINTK(fmt, args...) printk(KERN_WARNING "blk_tap: " fmt, ##args)
50
51 struct backend_info;
52
53 typedef struct blkif_st {
54         /* Unique identifier for this interface. */
55         domid_t           domid;
56         unsigned int      handle;
57         /* Physical parameters of the comms window. */
58         unsigned int      evtchn;
59         unsigned int      irq;
60         /* Comms information. */
61         blkif_back_ring_t blk_ring;
62         struct vm_struct *blk_ring_area;
63         /* Back pointer to the backend_info. */
64         struct backend_info *be;
65         /* Private fields. */
66         spinlock_t       blk_ring_lock;
67         atomic_t         refcnt;
68
69         wait_queue_head_t   wq;
70         struct task_struct  *xenblkd;
71         unsigned int        waiting_reqs;
72         request_queue_t     *plug;
73
74         /* statistics */
75         unsigned long       st_print;
76         int                 st_rd_req;
77         int                 st_wr_req;
78         int                 st_oo_req;
79
80         wait_queue_head_t waiting_to_free;
81
82         grant_handle_t shmem_handle;
83         grant_ref_t    shmem_ref;
84         
85         int             dev_num;
86         uint64_t        sectors;
87 } blkif_t;
88
89 blkif_t *tap_alloc_blkif(domid_t domid);
90 void tap_blkif_free(blkif_t *blkif);
91 int tap_blkif_map(blkif_t *blkif, unsigned long shared_page, 
92                   unsigned int evtchn);
93 void tap_blkif_unmap(blkif_t *blkif);
94
95 #define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
96 #define blkif_put(_b)                                   \
97         do {                                            \
98                 if (atomic_dec_and_test(&(_b)->refcnt)) \
99                         wake_up(&(_b)->waiting_to_free);\
100         } while (0)
101
102
103 struct phys_req {
104         unsigned short       dev;
105         unsigned short       nr_sects;
106         struct block_device *bdev;
107         blkif_sector_t       sector_number;
108 };
109
110 void tap_blkif_interface_init(void);
111
112 void tap_blkif_xenbus_init(void);
113
114 irqreturn_t tap_blkif_be_int(int irq, void *dev_id, struct pt_regs *regs);
115 int tap_blkif_schedule(void *arg);
116
117 int dom_to_devid(domid_t domid, int xenbus_id, blkif_t *blkif);
118 void signal_tapdisk(int idx);
119
120 #endif /* __BLKIF__BACKEND__COMMON_H__ */