evtchn.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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. evtchn_port_t port;
  78. bool enabled;
  79. };
  80. static void evtchn_free_ring(evtchn_port_t *ring)
  81. {
  82. kvfree(ring);
  83. }
  84. static unsigned int evtchn_ring_offset(struct per_user_data *u,
  85. unsigned int idx)
  86. {
  87. return idx & (u->ring_size - 1);
  88. }
  89. static evtchn_port_t *evtchn_ring_entry(struct per_user_data *u,
  90. unsigned int idx)
  91. {
  92. return u->ring + evtchn_ring_offset(u, idx);
  93. }
  94. static int add_evtchn(struct per_user_data *u, struct user_evtchn *evtchn)
  95. {
  96. struct rb_node **new = &(u->evtchns.rb_node), *parent = NULL;
  97. u->nr_evtchns++;
  98. while (*new) {
  99. struct user_evtchn *this;
  100. this = rb_entry(*new, struct user_evtchn, node);
  101. parent = *new;
  102. if (this->port < evtchn->port)
  103. new = &((*new)->rb_left);
  104. else if (this->port > evtchn->port)
  105. new = &((*new)->rb_right);
  106. else
  107. return -EEXIST;
  108. }
  109. /* Add new node and rebalance tree. */
  110. rb_link_node(&evtchn->node, parent, new);
  111. rb_insert_color(&evtchn->node, &u->evtchns);
  112. return 0;
  113. }
  114. static void del_evtchn(struct per_user_data *u, struct user_evtchn *evtchn)
  115. {
  116. u->nr_evtchns--;
  117. rb_erase(&evtchn->node, &u->evtchns);
  118. kfree(evtchn);
  119. }
  120. static struct user_evtchn *find_evtchn(struct per_user_data *u,
  121. evtchn_port_t port)
  122. {
  123. struct rb_node *node = u->evtchns.rb_node;
  124. while (node) {
  125. struct user_evtchn *evtchn;
  126. evtchn = rb_entry(node, struct user_evtchn, node);
  127. if (evtchn->port < port)
  128. node = node->rb_left;
  129. else if (evtchn->port > port)
  130. node = node->rb_right;
  131. else
  132. return evtchn;
  133. }
  134. return NULL;
  135. }
  136. static irqreturn_t evtchn_interrupt(int irq, void *data)
  137. {
  138. struct user_evtchn *evtchn = data;
  139. struct per_user_data *u = evtchn->user;
  140. unsigned int prod, cons;
  141. WARN(!evtchn->enabled,
  142. "Interrupt for port %u, but apparently not enabled; per-user %p\n",
  143. evtchn->port, u);
  144. evtchn->enabled = false;
  145. spin_lock(&u->ring_prod_lock);
  146. prod = READ_ONCE(u->ring_prod);
  147. cons = READ_ONCE(u->ring_cons);
  148. if ((prod - cons) < u->ring_size) {
  149. *evtchn_ring_entry(u, prod) = evtchn->port;
  150. smp_wmb(); /* Ensure ring contents visible */
  151. WRITE_ONCE(u->ring_prod, prod + 1);
  152. if (cons == prod) {
  153. wake_up_interruptible(&u->evtchn_wait);
  154. kill_fasync(&u->evtchn_async_queue,
  155. SIGIO, POLL_IN);
  156. }
  157. } else
  158. u->ring_overflow = 1;
  159. spin_unlock(&u->ring_prod_lock);
  160. return IRQ_HANDLED;
  161. }
  162. static ssize_t evtchn_read(struct file *file, char __user *buf,
  163. size_t count, loff_t *ppos)
  164. {
  165. int rc;
  166. unsigned int c, p, bytes1 = 0, bytes2 = 0;
  167. struct per_user_data *u = file->private_data;
  168. /* Whole number of ports. */
  169. count &= ~(sizeof(evtchn_port_t)-1);
  170. if (count == 0)
  171. return 0;
  172. if (count > PAGE_SIZE)
  173. count = PAGE_SIZE;
  174. for (;;) {
  175. mutex_lock(&u->ring_cons_mutex);
  176. rc = -EFBIG;
  177. if (u->ring_overflow)
  178. goto unlock_out;
  179. c = READ_ONCE(u->ring_cons);
  180. p = READ_ONCE(u->ring_prod);
  181. if (c != p)
  182. break;
  183. mutex_unlock(&u->ring_cons_mutex);
  184. if (file->f_flags & O_NONBLOCK)
  185. return -EAGAIN;
  186. rc = wait_event_interruptible(u->evtchn_wait,
  187. READ_ONCE(u->ring_cons) != READ_ONCE(u->ring_prod));
  188. if (rc)
  189. return rc;
  190. }
  191. /* Byte lengths of two chunks. Chunk split (if any) is at ring wrap. */
  192. if (((c ^ p) & u->ring_size) != 0) {
  193. bytes1 = (u->ring_size - evtchn_ring_offset(u, c)) *
  194. sizeof(evtchn_port_t);
  195. bytes2 = evtchn_ring_offset(u, p) * sizeof(evtchn_port_t);
  196. } else {
  197. bytes1 = (p - c) * sizeof(evtchn_port_t);
  198. bytes2 = 0;
  199. }
  200. /* Truncate chunks according to caller's maximum byte count. */
  201. if (bytes1 > count) {
  202. bytes1 = count;
  203. bytes2 = 0;
  204. } else if ((bytes1 + bytes2) > count) {
  205. bytes2 = count - bytes1;
  206. }
  207. rc = -EFAULT;
  208. smp_rmb(); /* Ensure that we see the port before we copy it. */
  209. if (copy_to_user(buf, evtchn_ring_entry(u, c), bytes1) ||
  210. ((bytes2 != 0) &&
  211. copy_to_user(&buf[bytes1], &u->ring[0], bytes2)))
  212. goto unlock_out;
  213. WRITE_ONCE(u->ring_cons, c + (bytes1 + bytes2) / sizeof(evtchn_port_t));
  214. rc = bytes1 + bytes2;
  215. unlock_out:
  216. mutex_unlock(&u->ring_cons_mutex);
  217. return rc;
  218. }
  219. static ssize_t evtchn_write(struct file *file, const char __user *buf,
  220. size_t count, loff_t *ppos)
  221. {
  222. int rc, i;
  223. evtchn_port_t *kbuf = (evtchn_port_t *)__get_free_page(GFP_KERNEL);
  224. struct per_user_data *u = file->private_data;
  225. if (kbuf == NULL)
  226. return -ENOMEM;
  227. /* Whole number of ports. */
  228. count &= ~(sizeof(evtchn_port_t)-1);
  229. rc = 0;
  230. if (count == 0)
  231. goto out;
  232. if (count > PAGE_SIZE)
  233. count = PAGE_SIZE;
  234. rc = -EFAULT;
  235. if (copy_from_user(kbuf, buf, count) != 0)
  236. goto out;
  237. mutex_lock(&u->bind_mutex);
  238. for (i = 0; i < (count/sizeof(evtchn_port_t)); i++) {
  239. evtchn_port_t port = kbuf[i];
  240. struct user_evtchn *evtchn;
  241. evtchn = find_evtchn(u, port);
  242. if (evtchn && !evtchn->enabled) {
  243. evtchn->enabled = true;
  244. xen_irq_lateeoi(irq_from_evtchn(port), 0);
  245. }
  246. }
  247. mutex_unlock(&u->bind_mutex);
  248. rc = count;
  249. out:
  250. free_page((unsigned long)kbuf);
  251. return rc;
  252. }
  253. static int evtchn_resize_ring(struct per_user_data *u)
  254. {
  255. unsigned int new_size;
  256. evtchn_port_t *new_ring, *old_ring;
  257. /*
  258. * Ensure the ring is large enough to capture all possible
  259. * events. i.e., one free slot for each bound event.
  260. */
  261. if (u->nr_evtchns <= u->ring_size)
  262. return 0;
  263. if (u->ring_size == 0)
  264. new_size = 64;
  265. else
  266. new_size = 2 * u->ring_size;
  267. new_ring = kvmalloc_array(new_size, sizeof(*new_ring), GFP_KERNEL);
  268. if (!new_ring)
  269. return -ENOMEM;
  270. old_ring = u->ring;
  271. /*
  272. * Access to the ring contents is serialized by either the
  273. * prod /or/ cons lock so take both when resizing.
  274. */
  275. mutex_lock(&u->ring_cons_mutex);
  276. spin_lock_irq(&u->ring_prod_lock);
  277. /*
  278. * Copy the old ring contents to the new ring.
  279. *
  280. * To take care of wrapping, a full ring, and the new index
  281. * pointing into the second half, simply copy the old contents
  282. * twice.
  283. *
  284. * +---------+ +------------------+
  285. * |34567 12| -> |34567 1234567 12|
  286. * +-----p-c-+ +-------c------p---+
  287. */
  288. memcpy(new_ring, old_ring, u->ring_size * sizeof(*u->ring));
  289. memcpy(new_ring + u->ring_size, old_ring,
  290. u->ring_size * sizeof(*u->ring));
  291. u->ring = new_ring;
  292. u->ring_size = new_size;
  293. spin_unlock_irq(&u->ring_prod_lock);
  294. mutex_unlock(&u->ring_cons_mutex);
  295. evtchn_free_ring(old_ring);
  296. return 0;
  297. }
  298. static int evtchn_bind_to_user(struct per_user_data *u, evtchn_port_t port)
  299. {
  300. struct user_evtchn *evtchn;
  301. struct evtchn_close close;
  302. int rc = 0;
  303. /*
  304. * Ports are never reused, so every caller should pass in a
  305. * unique port.
  306. *
  307. * (Locking not necessary because we haven't registered the
  308. * interrupt handler yet, and our caller has already
  309. * serialized bind operations.)
  310. */
  311. evtchn = kzalloc(sizeof(*evtchn), GFP_KERNEL);
  312. if (!evtchn)
  313. return -ENOMEM;
  314. evtchn->user = u;
  315. evtchn->port = port;
  316. evtchn->enabled = true; /* start enabled */
  317. rc = add_evtchn(u, evtchn);
  318. if (rc < 0)
  319. goto err;
  320. rc = evtchn_resize_ring(u);
  321. if (rc < 0)
  322. goto err;
  323. rc = bind_evtchn_to_irqhandler_lateeoi(port, evtchn_interrupt, 0,
  324. u->name, evtchn);
  325. if (rc < 0)
  326. goto err;
  327. rc = evtchn_make_refcounted(port);
  328. return rc;
  329. err:
  330. /* bind failed, should close the port now */
  331. close.port = port;
  332. if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
  333. BUG();
  334. del_evtchn(u, evtchn);
  335. return rc;
  336. }
  337. static void evtchn_unbind_from_user(struct per_user_data *u,
  338. struct user_evtchn *evtchn)
  339. {
  340. int irq = irq_from_evtchn(evtchn->port);
  341. BUG_ON(irq < 0);
  342. unbind_from_irqhandler(irq, evtchn);
  343. del_evtchn(u, evtchn);
  344. }
  345. static long evtchn_ioctl(struct file *file,
  346. unsigned int cmd, unsigned long arg)
  347. {
  348. int rc;
  349. struct per_user_data *u = file->private_data;
  350. void __user *uarg = (void __user *) arg;
  351. /* Prevent bind from racing with unbind */
  352. mutex_lock(&u->bind_mutex);
  353. switch (cmd) {
  354. case IOCTL_EVTCHN_BIND_VIRQ: {
  355. struct ioctl_evtchn_bind_virq bind;
  356. struct evtchn_bind_virq bind_virq;
  357. rc = -EACCES;
  358. if (u->restrict_domid != UNRESTRICTED_DOMID)
  359. break;
  360. rc = -EFAULT;
  361. if (copy_from_user(&bind, uarg, sizeof(bind)))
  362. break;
  363. bind_virq.virq = bind.virq;
  364. bind_virq.vcpu = xen_vcpu_nr(0);
  365. rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq,
  366. &bind_virq);
  367. if (rc != 0)
  368. break;
  369. rc = evtchn_bind_to_user(u, bind_virq.port);
  370. if (rc == 0)
  371. rc = bind_virq.port;
  372. break;
  373. }
  374. case IOCTL_EVTCHN_BIND_INTERDOMAIN: {
  375. struct ioctl_evtchn_bind_interdomain bind;
  376. struct evtchn_bind_interdomain bind_interdomain;
  377. rc = -EFAULT;
  378. if (copy_from_user(&bind, uarg, sizeof(bind)))
  379. break;
  380. rc = -EACCES;
  381. if (u->restrict_domid != UNRESTRICTED_DOMID &&
  382. u->restrict_domid != bind.remote_domain)
  383. break;
  384. bind_interdomain.remote_dom = bind.remote_domain;
  385. bind_interdomain.remote_port = bind.remote_port;
  386. rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain,
  387. &bind_interdomain);
  388. if (rc != 0)
  389. break;
  390. rc = evtchn_bind_to_user(u, bind_interdomain.local_port);
  391. if (rc == 0)
  392. rc = bind_interdomain.local_port;
  393. break;
  394. }
  395. case IOCTL_EVTCHN_BIND_UNBOUND_PORT: {
  396. struct ioctl_evtchn_bind_unbound_port bind;
  397. struct evtchn_alloc_unbound alloc_unbound;
  398. rc = -EACCES;
  399. if (u->restrict_domid != UNRESTRICTED_DOMID)
  400. break;
  401. rc = -EFAULT;
  402. if (copy_from_user(&bind, uarg, sizeof(bind)))
  403. break;
  404. alloc_unbound.dom = DOMID_SELF;
  405. alloc_unbound.remote_dom = bind.remote_domain;
  406. rc = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound,
  407. &alloc_unbound);
  408. if (rc != 0)
  409. break;
  410. rc = evtchn_bind_to_user(u, alloc_unbound.port);
  411. if (rc == 0)
  412. rc = alloc_unbound.port;
  413. break;
  414. }
  415. case IOCTL_EVTCHN_UNBIND: {
  416. struct ioctl_evtchn_unbind unbind;
  417. struct user_evtchn *evtchn;
  418. rc = -EFAULT;
  419. if (copy_from_user(&unbind, uarg, sizeof(unbind)))
  420. break;
  421. rc = -EINVAL;
  422. if (unbind.port >= xen_evtchn_nr_channels())
  423. break;
  424. rc = -ENOTCONN;
  425. evtchn = find_evtchn(u, unbind.port);
  426. if (!evtchn)
  427. break;
  428. disable_irq(irq_from_evtchn(unbind.port));
  429. evtchn_unbind_from_user(u, evtchn);
  430. rc = 0;
  431. break;
  432. }
  433. case IOCTL_EVTCHN_NOTIFY: {
  434. struct ioctl_evtchn_notify notify;
  435. struct user_evtchn *evtchn;
  436. rc = -EFAULT;
  437. if (copy_from_user(&notify, uarg, sizeof(notify)))
  438. break;
  439. rc = -ENOTCONN;
  440. evtchn = find_evtchn(u, notify.port);
  441. if (evtchn) {
  442. notify_remote_via_evtchn(notify.port);
  443. rc = 0;
  444. }
  445. break;
  446. }
  447. case IOCTL_EVTCHN_RESET: {
  448. /* Initialise the ring to empty. Clear errors. */
  449. mutex_lock(&u->ring_cons_mutex);
  450. spin_lock_irq(&u->ring_prod_lock);
  451. WRITE_ONCE(u->ring_cons, 0);
  452. WRITE_ONCE(u->ring_prod, 0);
  453. u->ring_overflow = 0;
  454. spin_unlock_irq(&u->ring_prod_lock);
  455. mutex_unlock(&u->ring_cons_mutex);
  456. rc = 0;
  457. break;
  458. }
  459. case IOCTL_EVTCHN_RESTRICT_DOMID: {
  460. struct ioctl_evtchn_restrict_domid ierd;
  461. rc = -EACCES;
  462. if (u->restrict_domid != UNRESTRICTED_DOMID)
  463. break;
  464. rc = -EFAULT;
  465. if (copy_from_user(&ierd, uarg, sizeof(ierd)))
  466. break;
  467. rc = -EINVAL;
  468. if (ierd.domid == 0 || ierd.domid >= DOMID_FIRST_RESERVED)
  469. break;
  470. u->restrict_domid = ierd.domid;
  471. rc = 0;
  472. break;
  473. }
  474. default:
  475. rc = -ENOSYS;
  476. break;
  477. }
  478. mutex_unlock(&u->bind_mutex);
  479. return rc;
  480. }
  481. static __poll_t evtchn_poll(struct file *file, poll_table *wait)
  482. {
  483. __poll_t mask = EPOLLOUT | EPOLLWRNORM;
  484. struct per_user_data *u = file->private_data;
  485. poll_wait(file, &u->evtchn_wait, wait);
  486. if (READ_ONCE(u->ring_cons) != READ_ONCE(u->ring_prod))
  487. mask |= EPOLLIN | EPOLLRDNORM;
  488. if (u->ring_overflow)
  489. mask = EPOLLERR;
  490. return mask;
  491. }
  492. static int evtchn_fasync(int fd, struct file *filp, int on)
  493. {
  494. struct per_user_data *u = filp->private_data;
  495. return fasync_helper(fd, filp, on, &u->evtchn_async_queue);
  496. }
  497. static int evtchn_open(struct inode *inode, struct file *filp)
  498. {
  499. struct per_user_data *u;
  500. u = kzalloc(sizeof(*u), GFP_KERNEL);
  501. if (u == NULL)
  502. return -ENOMEM;
  503. u->name = kasprintf(GFP_KERNEL, "evtchn:%s", current->comm);
  504. if (u->name == NULL) {
  505. kfree(u);
  506. return -ENOMEM;
  507. }
  508. init_waitqueue_head(&u->evtchn_wait);
  509. mutex_init(&u->bind_mutex);
  510. mutex_init(&u->ring_cons_mutex);
  511. spin_lock_init(&u->ring_prod_lock);
  512. u->restrict_domid = UNRESTRICTED_DOMID;
  513. filp->private_data = u;
  514. return stream_open(inode, filp);
  515. }
  516. static int evtchn_release(struct inode *inode, struct file *filp)
  517. {
  518. struct per_user_data *u = filp->private_data;
  519. struct rb_node *node;
  520. while ((node = u->evtchns.rb_node)) {
  521. struct user_evtchn *evtchn;
  522. evtchn = rb_entry(node, struct user_evtchn, node);
  523. disable_irq(irq_from_evtchn(evtchn->port));
  524. evtchn_unbind_from_user(u, evtchn);
  525. }
  526. evtchn_free_ring(u->ring);
  527. kfree(u->name);
  528. kfree(u);
  529. return 0;
  530. }
  531. static const struct file_operations evtchn_fops = {
  532. .owner = THIS_MODULE,
  533. .read = evtchn_read,
  534. .write = evtchn_write,
  535. .unlocked_ioctl = evtchn_ioctl,
  536. .poll = evtchn_poll,
  537. .fasync = evtchn_fasync,
  538. .open = evtchn_open,
  539. .release = evtchn_release,
  540. .llseek = no_llseek,
  541. };
  542. static struct miscdevice evtchn_miscdev = {
  543. .minor = MISC_DYNAMIC_MINOR,
  544. .name = "xen/evtchn",
  545. .fops = &evtchn_fops,
  546. };
  547. static int __init evtchn_init(void)
  548. {
  549. int err;
  550. if (!xen_domain())
  551. return -ENODEV;
  552. /* Create '/dev/xen/evtchn'. */
  553. err = misc_register(&evtchn_miscdev);
  554. if (err != 0) {
  555. pr_err("Could not register /dev/xen/evtchn\n");
  556. return err;
  557. }
  558. pr_info("Event-channel device installed\n");
  559. return 0;
  560. }
  561. static void __exit evtchn_cleanup(void)
  562. {
  563. misc_deregister(&evtchn_miscdev);
  564. }
  565. module_init(evtchn_init);
  566. module_exit(evtchn_cleanup);
  567. MODULE_LICENSE("GPL");