Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/xen/io/xenbus_dev.c
+++ new/usr/src/uts/common/xen/io/xenbus_dev.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /*
28 28 * xenbus_dev.c
29 29 *
30 30 * Driver giving user-space access to the kernel's xenbus connection
31 31 * to xenstore.
32 32 *
33 33 * Copyright (c) 2005, Christian Limpach
34 34 * Copyright (c) 2005, Rusty Russell, IBM Corporation
35 35 *
36 36 * This file may be distributed separately from the Linux kernel, or
37 37 * incorporated into other software packages, subject to the following license:
38 38 *
39 39 * Permission is hereby granted, free of charge, to any person obtaining a copy
40 40 * of this source file (the "Software"), to deal in the Software without
41 41 * restriction, including without limitation the rights to use, copy, modify,
42 42 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
43 43 * and to permit persons to whom the Software is furnished to do so, subject to
44 44 * the following conditions:
45 45 *
46 46 * The above copyright notice and this permission notice shall be included in
47 47 * all copies or substantial portions of the Software.
48 48 *
49 49 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50 50 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51 51 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52 52 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53 53 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
54 54 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
55 55 * IN THE SOFTWARE.
56 56 */
57 57
58 58
59 59 #include <sys/types.h>
60 60 #include <sys/sysmacros.h>
61 61 #include <sys/conf.h>
62 62 #include <sys/stat.h>
63 63 #include <sys/modctl.h>
64 64 #include <sys/uio.h>
65 65 #include <sys/list.h>
66 66 #include <sys/file.h>
67 67 #include <sys/errno.h>
68 68 #include <sys/open.h>
69 69 #include <sys/cred.h>
70 70 #include <sys/condvar.h>
71 71 #include <sys/ddi.h>
72 72 #include <sys/sunddi.h>
73 73 #include <sys/policy.h>
74 74
75 75 #ifdef XPV_HVM_DRIVER
76 76 #include <public/io/xenbus.h>
77 77 #include <public/io/xs_wire.h>
78 78 #include <sys/xpv_support.h>
79 79 #endif
80 80 #include <sys/hypervisor.h>
81 81 #include <xen/sys/xenbus.h>
82 82 #include <xen/sys/xenbus_comms.h>
83 83 #include <xen/sys/xenbus_impl.h>
84 84 #include <xen/public/io/xs_wire.h>
85 85
86 86 #ifdef DEBUG
87 87 #define XENBUSDRV_DBPRINT(fmt) { if (xenbusdrv_debug) cmn_err fmt; }
88 88 #else
89 89 #define XENBUSDRV_DBPRINT(fmt)
90 90 #endif /* ifdef DEBUG */
91 91
92 92 /* Some handy macros */
93 93 #define XENBUSDRV_MASK_READ_IDX(idx) ((idx) & (PAGESIZE - 1))
94 94 #define XENBUSDRV_MINOR2INST(minor) ((int)(minor))
95 95 #define XENBUSDRV_NCLONES 256
96 96 #define XENBUSDRV_INST2SOFTS(instance) \
97 97 ((xenbus_dev_t *)ddi_get_soft_state(xenbusdrv_statep, (instance)))
98 98
99 99 static int xenbusdrv_debug = 0;
100 100 static int xenbusdrv_clone_tab[XENBUSDRV_NCLONES];
101 101 static dev_info_t *xenbusdrv_dip;
102 102 static kmutex_t xenbusdrv_clone_tab_mutex;
103 103
104 104 struct xenbus_dev_transaction {
105 105 list_t list;
106 106 xenbus_transaction_t handle;
107 107 };
108 108
109 109 /* Soft state data structure for xenbus driver */
110 110 struct xenbus_dev_data {
111 111 dev_info_t *dip;
112 112
113 113 /* In-progress transaction. */
114 114 list_t transactions;
115 115
116 116 /* Partial request. */
117 117 unsigned int len;
118 118 union {
119 119 struct xsd_sockmsg msg;
120 120 char buffer[MMU_PAGESIZE];
121 121 } u;
122 122
123 123 /* Response queue. */
124 124 char read_buffer[MMU_PAGESIZE];
125 125 unsigned int read_cons, read_prod;
126 126 kcondvar_t read_cv;
127 127 kmutex_t read_mutex;
128 128 int xenstore_inst;
129 129 };
130 130 typedef struct xenbus_dev_data xenbus_dev_t;
131 131 static void *xenbusdrv_statep;
132 132
133 133 static int xenbusdrv_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
134 134 static int xenbusdrv_attach(dev_info_t *, ddi_attach_cmd_t);
135 135 static int xenbusdrv_detach(dev_info_t *, ddi_detach_cmd_t);
136 136 static int xenbusdrv_open(dev_t *, int, int, cred_t *);
137 137 static int xenbusdrv_close(dev_t, int, int, cred_t *);
138 138 static int xenbusdrv_read(dev_t, struct uio *, cred_t *);
139 139 static int xenbusdrv_write(dev_t, struct uio *, cred_t *);
140 140 static int xenbusdrv_devmap(dev_t, devmap_cookie_t, offset_t, size_t, size_t *,
141 141 uint_t);
142 142 static int xenbusdrv_segmap(dev_t, off_t, ddi_as_handle_t, caddr_t *, off_t,
143 143 uint_t, uint_t, uint_t, cred_t *);
144 144 static int xenbusdrv_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
145 145 static int xenbusdrv_queue_reply(xenbus_dev_t *, const struct xsd_sockmsg *,
146 146 const char *);
147 147
148 148 /* Solaris driver framework */
149 149
150 150 static struct cb_ops xenbusdrv_cb_ops = {
151 151 xenbusdrv_open, /* cb_open */
152 152 xenbusdrv_close, /* cb_close */
153 153 nodev, /* cb_strategy */
154 154 nodev, /* cb_print */
155 155 nodev, /* cb_dump */
156 156 xenbusdrv_read, /* cb_read */
157 157 xenbusdrv_write, /* cb_write */
158 158 xenbusdrv_ioctl, /* cb_ioctl */
159 159 xenbusdrv_devmap, /* cb_devmap */
160 160 NULL, /* cb_mmap */
161 161 xenbusdrv_segmap, /* cb_segmap */
162 162 nochpoll, /* cb_chpoll */
163 163 ddi_prop_op, /* cb_prop_op */
164 164 0, /* cb_stream */
165 165 D_DEVMAP | D_NEW | D_MP, /* cb_flag */
166 166 CB_REV
167 167 };
168 168
169 169 static struct dev_ops xenbusdrv_dev_ops = {
170 170 DEVO_REV, /* devo_rev */
171 171 0, /* devo_refcnt */
172 172 xenbusdrv_info, /* devo_getinfo */
173 173 nulldev, /* devo_identify */
174 174 nulldev, /* devo_probe */
175 175 xenbusdrv_attach, /* devo_attach */
176 176 xenbusdrv_detach, /* devo_detach */
177 177 nodev, /* devo_reset */
178 178 &xenbusdrv_cb_ops, /* devo_cb_ops */
179 179 NULL, /* devo_bus_ops */
180 180 NULL, /* devo_power */
181 181 ddi_quiesce_not_needed, /* devo_quiesce */
↓ open down ↓ |
181 lines elided |
↑ open up ↑ |
182 182 };
183 183
184 184 static struct modldrv modldrv = {
185 185 &mod_driverops, /* Type of module. This one is a driver */
186 186 "virtual bus driver", /* Name of the module. */
187 187 &xenbusdrv_dev_ops /* driver ops */
188 188 };
189 189
190 190 static struct modlinkage modlinkage = {
191 191 MODREV_1,
192 - &modldrv,
193 - NULL
192 + { &modldrv, NULL }
194 193 };
195 194
196 195 int
197 196 _init(void)
198 197 {
199 198 int e;
200 199
201 200 e = ddi_soft_state_init(&xenbusdrv_statep, sizeof (xenbus_dev_t), 1);
202 201 if (e)
203 202 return (e);
204 203
205 204 e = mod_install(&modlinkage);
206 205 if (e)
207 206 ddi_soft_state_fini(&xenbusdrv_statep);
208 207
209 208 return (e);
210 209 }
211 210
212 211 int
213 212 _fini(void)
214 213 {
215 214 int e;
216 215
217 216 e = mod_remove(&modlinkage);
218 217 if (e)
219 218 return (e);
220 219
221 220 ddi_soft_state_fini(&xenbusdrv_statep);
222 221
223 222 return (0);
224 223 }
225 224
226 225 int
227 226 _info(struct modinfo *modinfop)
228 227 {
229 228 return (mod_info(&modlinkage, modinfop));
230 229 }
231 230
232 231 /* ARGSUSED */
233 232 static int
234 233 xenbusdrv_info(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
235 234 {
236 235 dev_t dev = (dev_t)arg;
237 236 minor_t minor = getminor(dev);
238 237 int retval;
239 238
240 239 switch (cmd) {
241 240 case DDI_INFO_DEVT2DEVINFO:
242 241 if (minor != 0 || xenbusdrv_dip == NULL) {
243 242 *result = (void *)NULL;
244 243 retval = DDI_FAILURE;
245 244 } else {
246 245 *result = (void *)xenbusdrv_dip;
247 246 retval = DDI_SUCCESS;
248 247 }
249 248 break;
250 249 case DDI_INFO_DEVT2INSTANCE:
251 250 *result = (void *)0;
252 251 retval = DDI_SUCCESS;
253 252 break;
254 253 default:
255 254 retval = DDI_FAILURE;
256 255 }
257 256 return (retval);
258 257 }
259 258
260 259 static int
261 260 xenbusdrv_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
262 261 {
263 262 int error;
264 263 int unit = ddi_get_instance(dip);
265 264
266 265
267 266 switch (cmd) {
268 267 case DDI_ATTACH:
269 268 break;
270 269 case DDI_RESUME:
271 270 return (DDI_SUCCESS);
272 271 default:
273 272 cmn_err(CE_WARN, "xenbus_attach: unknown cmd 0x%x\n", cmd);
274 273 return (DDI_FAILURE);
275 274 }
276 275
277 276 /* DDI_ATTACH */
278 277
279 278 /*
280 279 * only one instance - but we clone using the open routine
281 280 */
282 281 if (ddi_get_instance(dip) > 0)
283 282 return (DDI_FAILURE);
284 283
285 284 mutex_init(&xenbusdrv_clone_tab_mutex, NULL, MUTEX_DRIVER,
286 285 NULL);
287 286
288 287 error = ddi_create_minor_node(dip, "xenbus", S_IFCHR, unit,
289 288 DDI_PSEUDO, NULL);
290 289 if (error != DDI_SUCCESS)
291 290 goto fail;
292 291
293 292 /*
294 293 * save dip for getinfo
295 294 */
296 295 xenbusdrv_dip = dip;
297 296 ddi_report_dev(dip);
298 297
299 298 #ifndef XPV_HVM_DRIVER
300 299 if (DOMAIN_IS_INITDOMAIN(xen_info))
301 300 xs_dom0_init();
302 301 #endif
303 302
304 303 return (DDI_SUCCESS);
305 304
306 305 fail:
307 306 (void) xenbusdrv_detach(dip, DDI_DETACH);
308 307 return (error);
309 308 }
310 309
311 310 static int
312 311 xenbusdrv_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
313 312 {
314 313 /*
315 314 * again, only one instance
316 315 */
317 316 if (ddi_get_instance(dip) > 0)
318 317 return (DDI_FAILURE);
319 318
320 319 switch (cmd) {
321 320 case DDI_DETACH:
322 321 ddi_remove_minor_node(dip, NULL);
323 322 mutex_destroy(&xenbusdrv_clone_tab_mutex);
324 323 xenbusdrv_dip = NULL;
325 324 return (DDI_SUCCESS);
326 325 case DDI_SUSPEND:
327 326 return (DDI_SUCCESS);
328 327 default:
329 328 cmn_err(CE_WARN, "xenbus_detach: unknown cmd 0x%x\n", cmd);
330 329 return (DDI_FAILURE);
331 330 }
332 331 }
333 332
334 333 /* ARGSUSED */
335 334 static int
336 335 xenbusdrv_open(dev_t *devp, int flag, int otyp, cred_t *cr)
337 336 {
338 337 xenbus_dev_t *xbs;
339 338 minor_t minor = getminor(*devp);
340 339
341 340 if (otyp == OTYP_BLK)
342 341 return (ENXIO);
343 342
344 343 /*
345 344 * only allow open on minor = 0 - the clone device
346 345 */
347 346 if (minor != 0)
348 347 return (ENXIO);
349 348
350 349 /*
351 350 * find a free slot and grab it
352 351 */
353 352 mutex_enter(&xenbusdrv_clone_tab_mutex);
354 353 for (minor = 1; minor < XENBUSDRV_NCLONES; minor++) {
355 354 if (xenbusdrv_clone_tab[minor] == 0) {
356 355 xenbusdrv_clone_tab[minor] = 1;
357 356 break;
358 357 }
359 358 }
360 359 mutex_exit(&xenbusdrv_clone_tab_mutex);
361 360 if (minor == XENBUSDRV_NCLONES)
362 361 return (EAGAIN);
363 362
364 363 /* Allocate softstate structure */
365 364 if (ddi_soft_state_zalloc(xenbusdrv_statep,
366 365 XENBUSDRV_MINOR2INST(minor)) != DDI_SUCCESS) {
367 366 mutex_enter(&xenbusdrv_clone_tab_mutex);
368 367 xenbusdrv_clone_tab[minor] = 0;
369 368 mutex_exit(&xenbusdrv_clone_tab_mutex);
370 369 return (EAGAIN);
371 370 }
372 371 xbs = XENBUSDRV_INST2SOFTS(XENBUSDRV_MINOR2INST(minor));
373 372
374 373 /* ... and init it */
375 374 xbs->dip = xenbusdrv_dip;
376 375 mutex_init(&xbs->read_mutex, NULL, MUTEX_DRIVER, NULL);
377 376 cv_init(&xbs->read_cv, NULL, CV_DEFAULT, NULL);
378 377 list_create(&xbs->transactions, sizeof (struct xenbus_dev_transaction),
379 378 offsetof(struct xenbus_dev_transaction, list));
380 379
381 380 /* clone driver */
382 381 *devp = makedevice(getmajor(*devp), minor);
383 382 XENBUSDRV_DBPRINT((CE_NOTE, "Xenbus drv open succeeded, minor=%d",
384 383 minor));
385 384
386 385 return (0);
387 386 }
388 387
389 388 /* ARGSUSED */
390 389 static int
391 390 xenbusdrv_close(dev_t dev, int flag, int otyp, struct cred *cr)
392 391 {
393 392 xenbus_dev_t *xbs;
394 393 minor_t minor = getminor(dev);
395 394 struct xenbus_dev_transaction *trans;
396 395
397 396 xbs = XENBUSDRV_INST2SOFTS(XENBUSDRV_MINOR2INST(minor));
398 397 if (xbs == NULL)
399 398 return (ENXIO);
400 399
401 400 #ifdef notyet
402 401 /*
403 402 * XXPV - would like to be able to notify xenstore down here, but
404 403 * as the daemon is currently written, it doesn't leave the device
405 404 * open after initial setup, so we have no way of knowing if it has
406 405 * gone away.
407 406 */
408 407 if (xbs->xenstore_inst)
409 408 xs_notify_xenstore_down();
410 409 #endif
411 410 /* free pending transaction */
412 411 while (trans = (struct xenbus_dev_transaction *)
413 412 list_head(&xbs->transactions)) {
414 413 (void) xenbus_transaction_end(trans->handle, 1);
415 414 list_remove(&xbs->transactions, (void *)trans);
416 415 kmem_free(trans, sizeof (*trans));
417 416 }
418 417
419 418 mutex_destroy(&xbs->read_mutex);
420 419 cv_destroy(&xbs->read_cv);
421 420 ddi_soft_state_free(xenbusdrv_statep, XENBUSDRV_MINOR2INST(minor));
422 421
423 422 /*
424 423 * free clone tab slot
425 424 */
426 425 mutex_enter(&xenbusdrv_clone_tab_mutex);
427 426 xenbusdrv_clone_tab[minor] = 0;
428 427 mutex_exit(&xenbusdrv_clone_tab_mutex);
429 428
430 429 XENBUSDRV_DBPRINT((CE_NOTE, "Xenbus drv close succeeded, minor=%d",
431 430 minor));
432 431
433 432 return (0);
434 433 }
435 434
436 435 /* ARGSUSED */
437 436 static int
438 437 xenbusdrv_read(dev_t dev, struct uio *uiop, cred_t *cr)
439 438 {
440 439 xenbus_dev_t *xbs;
441 440 size_t len;
442 441 int res, ret;
443 442 int idx;
444 443
445 444 XENBUSDRV_DBPRINT((CE_NOTE, "xenbusdrv_read called"));
446 445
447 446 if (secpolicy_xvm_control(cr))
448 447 return (EPERM);
449 448
450 449 xbs = XENBUSDRV_INST2SOFTS(XENBUSDRV_MINOR2INST(getminor(dev)));
451 450
452 451 mutex_enter(&xbs->read_mutex);
453 452
454 453 /* check if we have something to read */
455 454 while (xbs->read_prod == xbs->read_cons) {
456 455 if (cv_wait_sig(&xbs->read_cv, &xbs->read_mutex) == 0) {
457 456 mutex_exit(&xbs->read_mutex);
458 457 return (EINTR);
459 458 }
460 459 }
461 460
462 461 idx = XENBUSDRV_MASK_READ_IDX(xbs->read_cons);
463 462 res = uiop->uio_resid;
464 463
465 464 len = xbs->read_prod - xbs->read_cons;
466 465
467 466 if (len > (sizeof (xbs->read_buffer) - idx))
468 467 len = sizeof (xbs->read_buffer) - idx;
469 468 if (len > res)
470 469 len = res;
471 470
472 471 ret = uiomove(xbs->read_buffer + idx, len, UIO_READ, uiop);
473 472 xbs->read_cons += res - uiop->uio_resid;
474 473 mutex_exit(&xbs->read_mutex);
475 474
476 475 return (ret);
477 476 }
478 477
479 478 /*
480 479 * prepare data for xenbusdrv_read()
481 480 */
482 481 static int
483 482 xenbusdrv_queue_reply(xenbus_dev_t *xbs, const struct xsd_sockmsg *msg,
484 483 const char *reply)
485 484 {
486 485 int i;
487 486 int remaining;
488 487
489 488 XENBUSDRV_DBPRINT((CE_NOTE, "xenbusdrv_queue_reply called"));
490 489
491 490 mutex_enter(&xbs->read_mutex);
492 491
493 492 remaining = sizeof (xbs->read_buffer) -
494 493 (xbs->read_prod - xbs->read_cons);
495 494
496 495 if (sizeof (*msg) + msg->len > remaining) {
497 496 mutex_exit(&xbs->read_mutex);
498 497 return (EOVERFLOW);
499 498 }
500 499
501 500 for (i = 0; i < sizeof (*msg); i++, xbs->read_prod++) {
502 501 xbs->read_buffer[XENBUSDRV_MASK_READ_IDX(xbs->read_prod)] =
503 502 ((char *)msg)[i];
504 503 }
505 504
506 505 for (i = 0; i < msg->len; i++, xbs->read_prod++) {
507 506 xbs->read_buffer[XENBUSDRV_MASK_READ_IDX(xbs->read_prod)] =
508 507 reply[i];
509 508 }
510 509
511 510 cv_broadcast(&xbs->read_cv);
512 511
513 512 mutex_exit(&xbs->read_mutex);
514 513
515 514 XENBUSDRV_DBPRINT((CE_NOTE, "xenbusdrv_queue_reply exited"));
516 515
517 516 return (0);
518 517 }
519 518
520 519 /* ARGSUSED */
521 520 static int
522 521 xenbusdrv_write(dev_t dev, struct uio *uiop, cred_t *cr)
523 522 {
524 523 xenbus_dev_t *xbs;
525 524 struct xenbus_dev_transaction *trans;
526 525 void *reply;
527 526 size_t len;
528 527 int rc = 0;
529 528
530 529 XENBUSDRV_DBPRINT((CE_NOTE, "xenbusdrv_write called"));
531 530
532 531 if (secpolicy_xvm_control(cr))
533 532 return (EPERM);
534 533
535 534 xbs = XENBUSDRV_INST2SOFTS(XENBUSDRV_MINOR2INST(getminor(dev)));
536 535 len = uiop->uio_resid;
537 536
538 537 if ((len + xbs->len) > sizeof (xbs->u.buffer)) {
539 538 XENBUSDRV_DBPRINT((CE_WARN, "Request is too big"));
540 539 rc = EINVAL;
541 540 goto out;
542 541 }
543 542
544 543 if (uiomove(xbs->u.buffer + xbs->len, len, UIO_WRITE, uiop) != 0) {
545 544 XENBUSDRV_DBPRINT((CE_WARN, "Uiomove failed"));
546 545 rc = EFAULT;
547 546 goto out;
548 547 }
549 548
550 549 xbs->len += len;
551 550
552 551 if (xbs->len < (sizeof (xbs->u.msg)) ||
553 552 xbs->len < (sizeof (xbs->u.msg) + xbs->u.msg.len)) {
554 553 XENBUSDRV_DBPRINT((CE_NOTE, "Partial request"));
555 554 return (0);
556 555 }
557 556
558 557 switch (xbs->u.msg.type) {
559 558 case XS_TRANSACTION_START:
560 559 case XS_TRANSACTION_END:
561 560 case XS_DIRECTORY:
562 561 case XS_READ:
563 562 case XS_GET_PERMS:
564 563 case XS_RELEASE:
565 564 case XS_GET_DOMAIN_PATH:
566 565 case XS_WRITE:
567 566 case XS_MKDIR:
568 567 case XS_RM:
569 568 case XS_SET_PERMS:
570 569 /* send the request to xenstore and get feedback */
571 570 rc = xenbus_dev_request_and_reply(&xbs->u.msg, &reply);
572 571 if (rc) {
573 572 XENBUSDRV_DBPRINT((CE_WARN,
574 573 "xenbus_dev_request_and_reply failed"));
575 574 goto out;
576 575 }
577 576
578 577 /* handle transaction start/end */
579 578 if (xbs->u.msg.type == XS_TRANSACTION_START) {
580 579 trans = kmem_alloc(sizeof (*trans), KM_SLEEP);
581 580 (void) ddi_strtoul((char *)reply, NULL, 0,
582 581 (unsigned long *)&trans->handle);
583 582 list_insert_tail(&xbs->transactions, (void *)trans);
584 583 } else if (xbs->u.msg.type == XS_TRANSACTION_END) {
585 584 /* try to find out the ending transaction */
586 585 for (trans = (struct xenbus_dev_transaction *)
587 586 list_head(&xbs->transactions); trans;
588 587 trans = (struct xenbus_dev_transaction *)
589 588 list_next(&xbs->transactions, (void *)trans))
590 589 if (trans->handle ==
591 590 (xenbus_transaction_t)
592 591 xbs->u.msg.tx_id)
593 592 break;
594 593 ASSERT(trans);
595 594 /* free it, if we find it */
596 595 list_remove(&xbs->transactions, (void *)trans);
597 596 kmem_free(trans, sizeof (*trans));
598 597 }
599 598
600 599 /* prepare data for xenbusdrv_read() to get */
601 600 rc = xenbusdrv_queue_reply(xbs, &xbs->u.msg, reply);
602 601
603 602 kmem_free(reply, xbs->u.msg.len + 1);
604 603 break;
605 604 default:
606 605 rc = EINVAL;
607 606 }
608 607
609 608 out:
610 609 xbs->len = 0;
611 610 return (rc);
612 611 }
613 612
614 613 /*ARGSUSED*/
615 614 static int
616 615 xenbusdrv_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len,
617 616 size_t *maplen, uint_t model)
618 617 {
619 618 xenbus_dev_t *xbs;
620 619 int err;
621 620
622 621 xbs = XENBUSDRV_INST2SOFTS(XENBUSDRV_MINOR2INST(getminor(dev)));
623 622
624 623 if (off != 0 || len != PAGESIZE)
625 624 return (-1);
626 625
627 626 if (!DOMAIN_IS_INITDOMAIN(xen_info))
628 627 return (-1);
629 628
630 629 err = devmap_umem_setup(dhp, xbs->dip, NULL, xb_xenstore_cookie(),
631 630 0, PAGESIZE, PROT_READ | PROT_WRITE | PROT_USER, 0, NULL);
632 631
633 632 if (err)
634 633 return (err);
635 634
636 635 *maplen = PAGESIZE;
637 636
638 637 return (0);
639 638 }
640 639
641 640 static int
642 641 xenbusdrv_segmap(dev_t dev, off_t off, ddi_as_handle_t as, caddr_t *addrp,
643 642 off_t len, uint_t prot, uint_t maxprot, uint_t flags, cred_t *cr)
644 643 {
645 644
646 645 if (secpolicy_xvm_control(cr))
647 646 return (EPERM);
648 647
649 648 return (ddi_devmap_segmap(dev, off, as, addrp, len, prot,
650 649 maxprot, flags, cr));
651 650 }
652 651
653 652 /*ARGSUSED*/
654 653 static int
655 654 xenbusdrv_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *cr,
656 655 int *rvalp)
657 656 {
658 657 xenbus_dev_t *xbs;
659 658
660 659 if (secpolicy_xvm_control(cr))
661 660 return (EPERM);
662 661
663 662 xbs = XENBUSDRV_INST2SOFTS(XENBUSDRV_MINOR2INST(getminor(dev)));
664 663 switch (cmd) {
665 664 case IOCTL_XENBUS_XENSTORE_EVTCHN:
666 665 *rvalp = xen_info->store_evtchn;
667 666 break;
668 667 case IOCTL_XENBUS_NOTIFY_UP:
669 668 xs_notify_xenstore_up();
670 669 xbs->xenstore_inst = 1;
671 670 break;
672 671 default:
673 672 return (EINVAL);
674 673 }
675 674
676 675 return (0);
677 676 }
↓ open down ↓ |
474 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX