ia64/xen-unstable

view tools/blktap/blkif.c @ 9488:0a6f5527ca4b

[IA64] set itv handoff as masked and enable reading irr[0-3]

Set initial vcpu itv handoff state to mask the timer vector.
This seems to match hardware and makes logical sense from a
spurious interrupt perspective. Enable vcpu_get_irr[0-3]
functions as they seem to work and have the proper backing.
This enables the check_sal_cache_flush() in arch/ia64/kernel.sal.c
to work unmodified, allowing us to remove the Xen changes from
the file (and thus the file from the sparse tree).

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
author awilliam@xenbuild.aw
date Tue Apr 04 09:39:45 2006 -0600 (2006-04-04)
parents fcb7e5616102
children
line source
1 /*
2 * blkif.c
3 *
4 * The blkif interface for blktap. A blkif describes an in-use virtual disk.
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <errno.h>
10 #include <string.h>
11 #include <err.h>
13 #include "blktaplib.h"
15 #if 1
16 #define DPRINTF(_f, _a...) printf ( _f , ## _a )
17 #else
18 #define DPRINTF(_f, _a...) ((void)0)
19 #endif
21 #define BLKIF_HASHSZ 1024
22 #define BLKIF_HASH(_d,_h) (((int)(_d)^(int)(_h))&(BLKIF_HASHSZ-1))
24 static blkif_t *blkif_hash[BLKIF_HASHSZ];
26 blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle)
27 {
28 blkif_t *blkif = blkif_hash[BLKIF_HASH(domid, handle)];
29 while ( (blkif != NULL) &&
30 ((blkif->domid != domid) || (blkif->handle != handle)) )
31 blkif = blkif->hash_next;
32 return blkif;
33 }
35 blkif_t *alloc_blkif(domid_t domid)
36 {
37 blkif_t *blkif;
39 blkif = (blkif_t *)malloc(sizeof(blkif_t));
40 if (!blkif)
41 return NULL;
43 memset(blkif, 0, sizeof(*blkif));
44 blkif->domid = domid;
46 return blkif;
47 }
49 static int (*new_blkif_hook)(blkif_t *blkif) = NULL;
50 void register_new_blkif_hook(int (*fn)(blkif_t *blkif))
51 {
52 new_blkif_hook = fn;
53 }
55 int blkif_init(blkif_t *blkif, long int handle, long int pdev,
56 long int readonly)
57 {
58 domid_t domid;
59 blkif_t **pblkif;
61 if (blkif == NULL)
62 return -EINVAL;
64 domid = blkif->domid;
65 blkif->handle = handle;
66 blkif->pdev = pdev;
67 blkif->readonly = readonly;
69 /*
70 * Call out to the new_blkif_hook. The tap application should define this,
71 * and it should return having set blkif->ops
72 *
73 */
74 if (new_blkif_hook == NULL)
75 {
76 warn("Probe detected a new blkif, but no new_blkif_hook!");
77 return -1;
78 }
79 new_blkif_hook(blkif);
81 /* Now wire it in. */
82 pblkif = &blkif_hash[BLKIF_HASH(domid, handle)];
83 while ( *pblkif != NULL )
84 {
85 if ( ((*pblkif)->domid == domid) && ((*pblkif)->handle == handle) )
86 {
87 DPRINTF("Could not create blkif: already exists\n");
88 return -1;
89 }
90 pblkif = &(*pblkif)->hash_next;
91 }
92 blkif->hash_next = NULL;
93 *pblkif = blkif;
95 return 0;
96 }
98 void free_blkif(blkif_t *blkif)
99 {
100 blkif_t **pblkif, *curs;
102 pblkif = &blkif_hash[BLKIF_HASH(blkif->domid, blkif->handle)];
103 while ( (curs = *pblkif) != NULL )
104 {
105 if ( blkif == curs )
106 {
107 *pblkif = curs->hash_next;
108 }
109 pblkif = &curs->hash_next;
110 }
111 free(blkif);
112 }
114 void blkif_register_request_hook(blkif_t *blkif, char *name,
115 int (*rh)(blkif_t *, blkif_request_t *, int))
116 {
117 request_hook_t *rh_ent, **c;
119 rh_ent = (request_hook_t *)malloc(sizeof(request_hook_t));
120 if (!rh_ent)
121 {
122 warn("couldn't allocate a new hook");
123 return;
124 }
126 rh_ent->func = rh;
127 rh_ent->next = NULL;
128 if (asprintf(&rh_ent->name, "%s", name) == -1)
129 {
130 free(rh_ent);
131 warn("couldn't allocate a new hook name");
132 return;
133 }
135 c = &blkif->request_hook_chain;
136 while (*c != NULL) {
137 c = &(*c)->next;
138 }
139 *c = rh_ent;
140 }
142 void blkif_register_response_hook(blkif_t *blkif, char *name,
143 int (*rh)(blkif_t *, blkif_response_t *, int))
144 {
145 response_hook_t *rh_ent, **c;
147 rh_ent = (response_hook_t *)malloc(sizeof(response_hook_t));
148 if (!rh_ent)
149 {
150 warn("couldn't allocate a new hook");
151 return;
152 }
154 rh_ent->func = rh;
155 rh_ent->next = NULL;
156 if (asprintf(&rh_ent->name, "%s", name) == -1)
157 {
158 free(rh_ent);
159 warn("couldn't allocate a new hook name");
160 return;
161 }
163 c = &blkif->response_hook_chain;
164 while (*c != NULL) {
165 c = &(*c)->next;
166 }
167 *c = rh_ent;
168 }
170 void blkif_print_hooks(blkif_t *blkif)
171 {
172 request_hook_t *req_hook;
173 response_hook_t *rsp_hook;
175 DPRINTF("Request Hooks:\n");
176 req_hook = blkif->request_hook_chain;
177 while (req_hook != NULL)
178 {
179 DPRINTF(" [0x%p] %s\n", req_hook->func, req_hook->name);
180 req_hook = req_hook->next;
181 }
183 DPRINTF("Response Hooks:\n");
184 rsp_hook = blkif->response_hook_chain;
185 while (rsp_hook != NULL)
186 {
187 DPRINTF(" [0x%p] %s\n", rsp_hook->func, rsp_hook->name);
188 rsp_hook = rsp_hook->next;
189 }
190 }
193 long int vbd_size(blkif_t *blkif)
194 {
195 return 1000000000;
196 }
198 long int vbd_secsize(blkif_t *blkif)
199 {
200 return 512;
201 }
203 unsigned vbd_info(blkif_t *blkif)
204 {
205 return 0;
206 }
209 void __init_blkif(void)
210 {
211 memset(blkif_hash, 0, sizeof(blkif_hash));
212 }