evtchn.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /******************************************************************************
  2. * evtchn.c
  3. *
  4. * Driver for receiving and demuxing event-channel signals.
  5. *
  6. * Copyright (c) 2004-2005, K A Fraser
  7. * Multi-process extensions Copyright (c) 2004, Steven Smith
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation; or, when distributed
  12. * separately from the Linux kernel or incorporated into other
  13. * software packages, subject to the following license:
  14. *
  15. * Permission is hereby granted, free of charge, to any person obtaining a copy
  16. * of this source file (the "Software"), to deal in the Software without
  17. * restriction, including without limitation the rights to use, copy, modify,
  18. * merge, publish, distribute, sublicense, and/or sell copies of the Software,
  19. * and to permit persons to whom the Software is furnished to do so, subject to
  20. * the following conditions:
  21. *
  22. * The above copyright notice and this permission notice shall be included in
  23. * all copies or substantial portions of the Software.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  26. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  27. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  28. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  29. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  30. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  31. * IN THE SOFTWARE.
  32. */
  33. #define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt
  34. #include <linux/module.h>
  35. #include <linux/kernel.h>
  36. #include <linux/sched.h>
  37. #include <linux/slab.h>
  38. #include <linux/string.h>
  39. #include <linux/errno.h>
  40. #include <linux/fs.h>
  41. #include <linux/miscdevice.h>
  42. #include <linux/major.h>
  43. #include <linux/proc_fs.h>
  44. #include <linux/stat.h>
  45. #include <linux/poll.h>
  46. #include <linux/irq.h>
  47. #include <linux/init.h>
  48. #include <linux/mutex.h>
  49. #include <linux/cpu.h>
  50. #include <linux/mm.h>
  51. #include <linux/vmalloc.h>
  52. #include <xen/xen.h>
  53. #include <xen/events.h>
  54. #include <xen/evtchn.h>
  55. #include <xen/xen-ops.h>
  56. #include <asm/xen/hypervisor.h>
  57. struct per_user_data {
  58. struct mutex bind_mutex; /* serialize bind/unbind operations */
  59. struct rb_root evtchns;
  60. unsigned int nr_evtchns;
  61. /* Notification ring, accessed via /dev/xen/evtchn. */
  62. unsigned int ring_size;
  63. evtchn_port_t *ring;
  64. unsigned int ring_cons, ring_prod, ring_overflow;
  65. struct mutex ring_cons_mutex; /* protect against concurrent readers */
  66. spinlock_t ring_prod_lock; /* product against concurrent interrupts */
  67. /* Processes wait on this queue when ring is empty. */
  68. wait_queue_head_t evtchn_wait;
  69. struct fasync_struct *evtchn_async_queue;
  70. const char *name;
  71. domid_t restrict_domid;
  72. };
  73. #define UNRESTRICTED_DOMID ((domid_t)-1)
  74. struct user_evtchn {
  75. struct rb_node node;
  76. struct per_user_data *user;
  77. unsigned port;
  78. bool enabled;
  79. };
  80. static evtchn_port_t *evtchn_alloc_ring(unsigned int size)
  81. {
  82. evtchn_port_t *ring;
  83. size_t s = size * sizeof(*ring);
  84. ring = kmalloc(s, GFP_KERNEL);
  85. if (!ring)
  86. ring = vmalloc(s);
  87. return ring;
  88. }
  89. static void evtchn_free_ring(evtchn_port_t *ring)
  90. {
  91. kvfree(ring);
  92. }
  93. static unsigned int evtchn_ring_offset(struct per_user_data *u,
  94. unsigned int idx)
  95. {
  96. return idx & (u->ring_size - 1);
  97. }
  98. static evtchn_port_t *evtchn_ring_entry(struct per_user_data *u,
  99. unsigned int idx)
  100. {
  101. return u->ring + evtchn_ring_offset(u, idx);
  102. }
  103. static int add_evtchn(struct per_user_data *u, struct user_evtchn *evtchn)
  104. {
  105. struct rb_node **new = &(u->evtchns.rb_node), *parent = NULL;
  106. u->nr_evtchns++;
  107. while (*new) {
  108. struct user_evtchn *this;
  109. this = container_of(*new, struct user_evtchn, node);
  110. parent = *new;
  111. if (this->port < evtchn->port)
  112. new = &((*new)->rb_left);
  113. else if (this->port > evtchn->port)
  114. new = &((*new)->rb_right);
  115. else
  116. return -EEXIST;
  117. }
  118. /* Add new node and rebalance tree. */
  119. rb_link_node(&evtchn->node, parent, new);
  120. rb_insert_color(&evtchn->node, &u->evtchns);
  121. return 0;
  122. }
  123. static void del_evtchn(struct per_user_data *u, struct user_evtchn *evtchn)
  124. {
  125. u->nr_evtchns--;
  126. rb_erase(&evtchn->node, &u->evtchns);
  127. kfree(evtchn);
  128. }
  129. static struct user_evtchn *find_evtchn(struct per_user_data *u, unsigned port)
  130. {
  131. struct rb_node *node = u->evtchns.rb_node;
  132. while (node) {
  133. struct user_evtchn *evtchn;
  134. evtchn = container_of(node, struct user_evtchn, node);
  135. if (evtchn->port < port)
  136. node = node->rb_left;
  137. else if (evtchn->port > port)
  138. node = node->rb_right;
  139. else
  140. return evtchn;
  141. }
  142. return NULL;
  143. }
  144. static irqreturn_t evtchn_interrupt(int irq, void *data)
  145. {
  146. struct user_evtchn *evtchn = data;
  147. struct per_user_data *u = evtchn->user;
  148. WARN(!evtchn->enabled,
  149. "Interrupt for port %d, but apparently not enabled; per-user %p\n",
  150. evtchn->port, u);
  151. disable_irq_nosync(irq);
  152. evtchn->enabled = false;
  153. spin_lock(&u->ring_prod_lock);
  154. if ((u->ring_prod - u->ring_cons) < u->ring_size) {
  155. *evtchn_ring_entry(u, u->ring_prod) = evtchn->port;
  156. wmb(); /* Ensure ring contents visible */
  157. if (u->ring_cons == u->ring_prod++) {
  158. wake_up_interruptible(&u->evtchn_wait);
  159. kill_fasync(&u->evtchn_async_queue,
  160. SIGIO, POLL_IN);
  161. }
  162. } else
  163. u->ring_overflow = 1;
  164. spin_unlock(&u->ring_prod_lock);
  165. return IRQ_HANDLED;
  166. }
  167. static ssize_t evtchn_read(struct file *file, char __user *buf,
  168. size_t count, loff_t *ppos)
  169. {
  170. int rc;
  171. unsigned int c, p, bytes1 = 0, bytes2 = 0;
  172. struct per_user_data *u = file->private_data;
  173. /* Whole number of ports. */
  174. count &= ~(sizeof(evtchn_port_t)-1);
  175. if (count == 0)
  176. return 0;
  177. if (count > PAGE_SIZE)
  178. count = PAGE_SIZE;
  179. for (;;) {
  180. mutex_lock(&u->ring_cons_mutex);
  181. rc = -EFBIG;
  182. if (u->ring_overflow)
  183. goto unlock_out;
  184. c = u->ring_cons;
  185. p = u->ring_prod;
  186. if (c != p)
  187. break;
  188. mutex_unlock(&u->ring_cons_mutex);
  189. if (file->f_flags & O_NONBLOCK)
  190. return -EAGAIN;
  191. rc = wait_event_interruptible(u->evtchn_wait,
  192. u->ring_cons != u->ring_prod);
  193. if (rc)
  194. return rc;
  195. }
  196. /* Byte lengths of two chunks. Chunk split (if any) is at ring wrap. */
  197. if (((c ^ p) & u->ring_size) != 0) {
  198. bytes1 = (u->ring_size - evtchn_ring_offset(u, c)) *
  199. sizeof(evtchn_port_t);
  200. bytes2 = evtchn_ring_offset(u, p) * sizeof(evtchn_port_t);
  201. } else {
  202. bytes1 = (p - c) * sizeof(evtchn_port_t);
  203. bytes2 = 0;
  204. }
  205. /* Truncate chunks according to caller's maximum byte count. */
  206. if (bytes1 > count) {
  207. bytes1 = count;
  208. bytes2 = 0;
  209. } else if ((bytes1 + bytes2) > count) {
  210. bytes2 = count - bytes1;
  211. }
  212. rc = -EFAULT;
  213. rmb(); /* Ensure that we see the port before we copy it. */
  214. if (copy_to_user(buf, evtchn_ring_entry(u, c), bytes1) ||
  215. ((bytes2 != 0) &&
  216. copy_to_user(&buf[bytes1], &u->ring[0], bytes2)))
  217. goto unlock_out;
  218. u->ring_cons += (bytes1 + bytes2) / sizeof(evtchn_port_t);
  219. rc = bytes1 + bytes2;
  220. unlock_out:
  221. mutex_unlock(&u->ring_cons_mutex);
  222. return rc;
  223. }
  224. static ssize_t evtchn_write(struct file *file, const char __user *buf,
  225. size_t count, loff_t *ppos)
  226. {
  227. int rc, i;
  228. evtchn_port_t *kbuf = (evtchn_port_t *)__get_free_page(GFP_KERNEL);
  229. struct per_user_data *u = file->private_data;
  230. if (kbuf == NULL)
  231. return -ENOMEM;
  232. /* Whole number of ports. */
  233. count &= ~(sizeof(evtchn_port_t)-1);
  234. rc = 0;
  235. if (count == 0)
  236. goto out;
  237. if (count > PAGE_SIZE)
  238. count = PAGE_SIZE;
  239. rc = -EFAULT;
  240. if (copy_from_user(kbuf, buf, count) != 0)
  241. goto out;
  242. mutex_lock(&u->bind_mutex);
  243. for (i = 0; i < (count/sizeof(evtchn_port_t)); i++) {
  244. unsigned port = kbuf[i];
  245. struct user_evtchn *evtchn;
  246. evtchn = find_evtchn(u, port);
  247. if (evtchn && !evtchn->enabled) {
  248. evtchn->enabled = true;
  249. enable_irq(irq_from_evtchn(port));
  250. }
  251. }
  252. mutex_unlock(&u->bind_mutex);
  253. rc = count;
  254. out:
  255. free_page((unsigned long)kbuf);
  256. return rc;
  257. }
  258. static int evtchn_resize_ring(struct per_user_data *u)
  259. {
  260. unsigned int new_size;
  261. evtchn_port_t *new_ring, *old_ring;
  262. /*
  263. * Ensure the ring is large enough to capture all possible
  264. * events. i.e., one free slot for each bound event.
  265. */
  266. if (u->nr_evtchns <= u->ring_size)
  267. return 0;
  268. if (u->ring_size == 0)
  269. new_size = 64;
  270. else
  271. new_size = 2 * u->ring_size;
  272. new_ring = evtchn_alloc_ring(new_size);
  273. if (!new_ring)
  274. return -ENOMEM;
  275. old_ring = u->ring;
  276. /*
  277. * Access to the ring contents is serialized by either the
  278. * prod /or/ cons lock so take both when resizing.
  279. */
  280. mutex_lock(&u->ring_cons_mutex);
  281. spin_lock_irq(&u->ring_prod_lock);
  282. /*
  283. * Copy the old ring contents to the new ring.
  284. *
  285. * To take care of wrapping, a full ring, and the new index
  286. * pointing into the second half, simply copy the old contents
  287. * twice.
  288. *
  289. * +---------+ +------------------+
  290. * |34567 12| -> |34567 1234567 12|
  291. * +-----p-c-+ +-------c------p---+
  292. */
  293. memcpy(new_ring, old_ring, u->ring_size * sizeof(*u->ring));
  294. memcpy(new_ring + u->ring_size, old_ring,
  295. u->ring_size * sizeof(*u->ring));
  296. u->ring = new_ring;
  297. u->ring_size = new_size;
  298. spin_unlock_irq(&u->ring_prod_lock);
  299. mutex_unlock(&u->ring_cons_mutex);
  300. evtchn_free_ring(old_ring);
  301. return 0;
  302. }
  303. static int evtchn_bind_to_user(struct per_user_data *u, int port)
  304. {
  305. struct user_evtchn *evtchn;
  306. struct evtchn_close close;
  307. int rc = 0;
  308. /*
  309. * Ports are never reused, so every caller should pass in a
  310. * unique port.
  311. *
  312. * (Locking not necessary because we haven't registered the
  313. * interrupt handler yet, and our caller has already
  314. * serialized bind operations.)
  315. */
  316. evtchn = kzalloc(sizeof(*evtchn), GFP_KERNEL);
  317. if (!evtchn)
  318. return -ENOMEM;
  319. evtchn->user = u;
  320. evtchn->port = port;
  321. evtchn->enabled = true; /* start enabled */
  322. rc = add_evtchn(u, evtchn);
  323. if (rc < 0)
  324. goto err;
  325. rc = evtchn_resize_ring(u);
  326. if (rc < 0)
  327. goto err;
  328. rc = bind_evtchn_to_irqhandler(port, evtchn_interrupt, 0,
  329. u->name, evtchn);
  330. if (rc < 0)
  331. goto err;
  332. rc = evtchn_make_refcounted(port);
  333. return rc;
  334. err:
  335. /* bind failed, should close the port now */
  336. close.port = port;
  337. if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
  338. BUG();
  339. del_evtchn(u, evtchn);
  340. return rc;
  341. }
  342. static void evtchn_unbind_from_user(struct per_user_data *u,
  343. struct user_evtchn *evtchn)
  344. {
  345. int irq = irq_from_evtchn(evtchn->port);
  346. BUG_ON(irq < 0);
  347. unbind_from_irqhandler(irq, evtchn);
  348. del_evtchn(u, evtchn);
  349. }
  350. static long evtchn_ioctl(struct file *file,
  351. unsigned int cmd, unsigned long arg)
  352. {
  353. int rc;
  354. struct per_user_data *u = file->private_data;
  355. void __user *uarg = (void __user *) arg;
  356. /* Prevent bind from racing with unbind */
  357. mutex_lock(&u->bind_mutex);
  358. switch (cmd) {
  359. case IOCTL_EVTCHN_BIND_VIRQ: {
  360. struct ioctl_evtchn_bind_virq bind;
  361. struct evtchn_bind_virq bind_virq;
  362. rc = -EACCES;
  363. if (u->restrict_domid != UNRESTRICTED_DOMID)
  364. break;
  365. rc = -EFAULT;
  366. if (copy_from_user(&bind, uarg, sizeof(bind)))
  367. break;
  368. bind_virq.virq = bind.virq;
  369. bind_virq.vcpu = xen_vcpu_nr(0);
  370. rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq,
  371. &bind_virq);
  372. if (rc != 0)
  373. break;
  374. rc = evtchn_bind_to_user(u, bind_virq.port);
  375. if (rc == 0)
  376. rc = bind_virq.port;
  377. break;
  378. }
  379. case IOCTL_EVTCHN_BIND_INTERDOMAIN: {
  380. struct ioctl_evtchn_bind_interdomain bind;
  381. struct evtchn_bind_interdomain bind_interdomain;
  382. rc = -EFAULT;
  383. if (copy_from_user(&bind, uarg, sizeof(bind)))
  384. break;
  385. rc = -EACCES;
  386. if (u->restrict_domid != UNRESTRICTED_DOMID &&
  387. u->restrict_domid != bind.remote_domain)
  388. break;
  389. bind_interdomain.remote_dom = bind.remote_domain;
  390. bind_interdomain.remote_port = bind.remote_port;
  391. rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain,
  392. &bind_interdomain);
  393. if (rc != 0)
  394. break;
  395. rc = evtchn_bind_to_user(u, bind_interdomain.local_port);
  396. if (rc == 0)
  397. rc = bind_interdomain.local_port;
  398. break;
  399. }
  400. case IOCTL_EVTCHN_BIND_UNBOUND_PORT: {
  401. struct ioctl_evtchn_bind_unbound_port bind;
  402. struct evtchn_alloc_unbound alloc_unbound;
  403. rc = -EACCES;
  404. if (u->restrict_domid != UNRESTRICTED_DOMID)
  405. break;
  406. rc = -EFAULT;
  407. if (copy_from_user(&bind, uarg, sizeof(bind)))
  408. break;
  409. alloc_unbound.dom = DOMID_SELF;
  410. alloc_unbound.remote_dom = bind.remote_domain;
  411. rc = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound,
  412. &alloc_unbound);
  413. if (rc != 0)
  414. break;
  415. rc = evtchn_bind_to_user(u, alloc_unbound.port);
  416. if (rc == 0)
  417. rc = alloc_unbound.port;
  418. break;
  419. }
  420. case IOCTL_EVTCHN_UNBIND: {
  421. struct ioctl_evtchn_unbind unbind;
  422. struct user_evtchn *evtchn;
  423. rc = -EFAULT;
  424. if (copy_from_user(&unbind, uarg, sizeof(unbind)))
  425. break;
  426. rc = -EINVAL;
  427. if (unbind.port >= xen_evtchn_nr_channels())
  428. break;
  429. rc = -ENOTCONN;
  430. evtchn = find_evtchn(u, unbind.port);
  431. if (!evtchn)
  432. break;
  433. disable_irq(irq_from_evtchn(unbind.port));
  434. evtchn_unbind_from_user(u, evtchn);
  435. rc = 0;
  436. break;
  437. }
  438. case IOCTL_EVTCHN_NOTIFY: {
  439. struct ioctl_evtchn_notify notify;
  440. struct user_evtchn *evtchn;
  441. rc = -EFAULT;
  442. if (copy_from_user(&notify, uarg, sizeof(notify)))
  443. break;
  444. rc = -ENOTCONN;
  445. evtchn = find_evtchn(u, notify.port);
  446. if (evtchn) {
  447. notify_remote_via_evtchn(notify.port);
  448. rc = 0;
  449. }
  450. break;
  451. }
  452. case IOCTL_EVTCHN_RESET: {
  453. /* Initialise the ring to empty. Clear errors. */
  454. mutex_lock(&u->ring_cons_mutex);
  455. spin_lock_irq(&u->ring_prod_lock);
  456. u->ring_cons = u->ring_prod = u->ring_overflow = 0;
  457. spin_unlock_irq(&u->ring_prod_lock);
  458. mutex_unlock(&u->ring_cons_mutex);
  459. rc = 0;
  460. break;
  461. }
  462. case IOCTL_EVTCHN_RESTRICT_DOMID: {
  463. struct ioctl_evtchn_restrict_domid ierd;
  464. rc = -EACCES;
  465. if (u->restrict_domid != UNRESTRICTED_DOMID)
  466. break;
  467. rc = -EFAULT;
  468. if (copy_from_user(&ierd, uarg, sizeof(ierd)))
  469. break;
  470. rc = -EINVAL;
  471. if (ierd.domid == 0 || ierd.domid >= DOMID_FIRST_RESERVED)
  472. break;
  473. u->restrict_domid = ierd.domid;
  474. rc = 0;
  475. break;
  476. }
  477. default:
  478. rc = -ENOSYS;
  479. break;
  480. }
  481. mutex_unlock(&u->bind_mutex);
  482. return rc;
  483. }
  484. static unsigned int evtchn_poll(struct file *file, poll_table *wait)
  485. {
  486. unsigned int mask = POLLOUT | POLLWRNORM;
  487. struct per_user_data *u = file->private_data;
  488. poll_wait(file, &u->evtchn_wait, wait);
  489. if (u->ring_cons != u->ring_prod)
  490. mask |= POLLIN | POLLRDNORM;
  491. if (u->ring_overflow)
  492. mask = POLLERR;
  493. return mask;
  494. }
  495. static int evtchn_fasync(int fd, struct file *filp, int on)
  496. {
  497. struct per_user_data *u = filp->private_data;
  498. return fasync_helper(fd, filp, on, &u->evtchn_async_queue);
  499. }
  500. static int evtchn_open(struct inode *inode, struct file *filp)
  501. {
  502. struct per_user_data *u;
  503. u = kzalloc(sizeof(*u), GFP_KERNEL);
  504. if (u == NULL)
  505. return -ENOMEM;
  506. u->name = kasprintf(GFP_KERNEL, "evtchn:%s", current->comm);
  507. if (u->name == NULL) {
  508. kfree(u);
  509. return -ENOMEM;
  510. }
  511. init_waitqueue_head(&u->evtchn_wait);
  512. mutex_init(&u->bind_mutex);
  513. mutex_init(&u->ring_cons_mutex);
  514. spin_lock_init(&u->ring_prod_lock);
  515. u->restrict_domid = UNRESTRICTED_DOMID;
  516. filp->private_data = u;
  517. return nonseekable_open(inode, filp);
  518. }
  519. static int evtchn_release(struct inode *inode, struct file *filp)
  520. {
  521. struct per_user_data *u = filp->private_data;
  522. struct rb_node *node;
  523. while ((node = u->evtchns.rb_node)) {
  524. struct user_evtchn *evtchn;
  525. evtchn = rb_entry(node, struct user_evtchn, node);
  526. disable_irq(irq_from_evtchn(evtchn->port));
  527. evtchn_unbind_from_user(u, evtchn);
  528. }
  529. evtchn_free_ring(u->ring);
  530. kfree(u->name);
  531. kfree(u);
  532. return 0;
  533. }
  534. static const struct file_operations evtchn_fops = {
  535. .owner = THIS_MODULE,
  536. .read = evtchn_read,
  537. .write = evtchn_write,
  538. .unlocked_ioctl = evtchn_ioctl,
  539. .poll = evtchn_poll,
  540. .fasync = evtchn_fasync,
  541. .open = evtchn_open,
  542. .release = evtchn_release,
  543. .llseek = no_llseek,
  544. };
  545. static struct miscdevice evtchn_miscdev = {
  546. .minor = MISC_DYNAMIC_MINOR,
  547. .name = "xen/evtchn",
  548. .fops = &evtchn_fops,
  549. };
  550. static int __init evtchn_init(void)
  551. {
  552. int err;
  553. if (!xen_domain())
  554. return -ENODEV;
  555. /* Create '/dev/xen/evtchn'. */
  556. err = misc_register(&evtchn_miscdev);
  557. if (err != 0) {
  558. pr_err("Could not register /dev/xen/evtchn\n");
  559. return err;
  560. }
  561. pr_info("Event-channel device installed\n");
  562. return 0;
  563. }
  564. static void __exit evtchn_cleanup(void)
  565. {
  566. misc_deregister(&evtchn_miscdev);
  567. }
  568. module_init(evtchn_init);
  569. module_exit(evtchn_cleanup);
  570. MODULE_LICENSE("GPL");