xenbus.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /*
  2. * PCI Backend Xenbus Setup - handles setup with frontend and xend
  3. *
  4. * Author: Ryan Wilson <hap9@epoch.ncsc.mil>
  5. */
  6. #include <linux/module.h>
  7. #include <linux/init.h>
  8. #include <linux/list.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/workqueue.h>
  11. #include <xen/xenbus.h>
  12. #include <xen/events.h>
  13. #include <asm/xen/pci.h>
  14. #include <linux/workqueue.h>
  15. #include "pciback.h"
  16. #define INVALID_EVTCHN_IRQ (-1)
  17. struct workqueue_struct *pciback_wq;
  18. static struct pciback_device *alloc_pdev(struct xenbus_device *xdev)
  19. {
  20. struct pciback_device *pdev;
  21. pdev = kzalloc(sizeof(struct pciback_device), GFP_KERNEL);
  22. if (pdev == NULL)
  23. goto out;
  24. dev_dbg(&xdev->dev, "allocated pdev @ 0x%p\n", pdev);
  25. pdev->xdev = xdev;
  26. dev_set_drvdata(&xdev->dev, pdev);
  27. spin_lock_init(&pdev->dev_lock);
  28. pdev->sh_info = NULL;
  29. pdev->evtchn_irq = INVALID_EVTCHN_IRQ;
  30. pdev->be_watching = 0;
  31. INIT_WORK(&pdev->op_work, pciback_do_op);
  32. if (pciback_init_devices(pdev)) {
  33. kfree(pdev);
  34. pdev = NULL;
  35. }
  36. out:
  37. return pdev;
  38. }
  39. static void pciback_disconnect(struct pciback_device *pdev)
  40. {
  41. spin_lock(&pdev->dev_lock);
  42. /* Ensure the guest can't trigger our handler before removing devices */
  43. if (pdev->evtchn_irq != INVALID_EVTCHN_IRQ) {
  44. unbind_from_irqhandler(pdev->evtchn_irq, pdev);
  45. pdev->evtchn_irq = INVALID_EVTCHN_IRQ;
  46. }
  47. spin_unlock(&pdev->dev_lock);
  48. /* If the driver domain started an op, make sure we complete it
  49. * before releasing the shared memory */
  50. /* Note, the workqueue does not use spinlocks at all.*/
  51. flush_workqueue(pciback_wq);
  52. spin_lock(&pdev->dev_lock);
  53. if (pdev->sh_info != NULL) {
  54. xenbus_unmap_ring_vfree(pdev->xdev, pdev->sh_info);
  55. pdev->sh_info = NULL;
  56. }
  57. spin_unlock(&pdev->dev_lock);
  58. }
  59. static void free_pdev(struct pciback_device *pdev)
  60. {
  61. if (pdev->be_watching) {
  62. unregister_xenbus_watch(&pdev->be_watch);
  63. pdev->be_watching = 0;
  64. }
  65. pciback_disconnect(pdev);
  66. pciback_release_devices(pdev);
  67. dev_set_drvdata(&pdev->xdev->dev, NULL);
  68. pdev->xdev = NULL;
  69. kfree(pdev);
  70. }
  71. static int pciback_do_attach(struct pciback_device *pdev, int gnt_ref,
  72. int remote_evtchn)
  73. {
  74. int err = 0;
  75. void *vaddr;
  76. dev_dbg(&pdev->xdev->dev,
  77. "Attaching to frontend resources - gnt_ref=%d evtchn=%d\n",
  78. gnt_ref, remote_evtchn);
  79. err = xenbus_map_ring_valloc(pdev->xdev, gnt_ref, &vaddr);
  80. if (err < 0) {
  81. xenbus_dev_fatal(pdev->xdev, err,
  82. "Error mapping other domain page in ours.");
  83. goto out;
  84. }
  85. spin_lock(&pdev->dev_lock);
  86. pdev->sh_info = vaddr;
  87. spin_unlock(&pdev->dev_lock);
  88. err = bind_interdomain_evtchn_to_irqhandler(
  89. pdev->xdev->otherend_id, remote_evtchn, pciback_handle_event,
  90. 0, "pciback", pdev);
  91. if (err < 0) {
  92. xenbus_dev_fatal(pdev->xdev, err,
  93. "Error binding event channel to IRQ");
  94. goto out;
  95. }
  96. spin_lock(&pdev->dev_lock);
  97. pdev->evtchn_irq = err;
  98. spin_unlock(&pdev->dev_lock);
  99. err = 0;
  100. dev_dbg(&pdev->xdev->dev, "Attached!\n");
  101. out:
  102. return err;
  103. }
  104. static int pciback_attach(struct pciback_device *pdev)
  105. {
  106. int err = 0;
  107. int gnt_ref, remote_evtchn;
  108. char *magic = NULL;
  109. /* Make sure we only do this setup once */
  110. if (xenbus_read_driver_state(pdev->xdev->nodename) !=
  111. XenbusStateInitialised)
  112. goto out;
  113. /* Wait for frontend to state that it has published the configuration */
  114. if (xenbus_read_driver_state(pdev->xdev->otherend) !=
  115. XenbusStateInitialised)
  116. goto out;
  117. dev_dbg(&pdev->xdev->dev, "Reading frontend config\n");
  118. err = xenbus_gather(XBT_NIL, pdev->xdev->otherend,
  119. "pci-op-ref", "%u", &gnt_ref,
  120. "event-channel", "%u", &remote_evtchn,
  121. "magic", NULL, &magic, NULL);
  122. if (err) {
  123. /* If configuration didn't get read correctly, wait longer */
  124. xenbus_dev_fatal(pdev->xdev, err,
  125. "Error reading configuration from frontend");
  126. goto out;
  127. }
  128. if (magic == NULL || strcmp(magic, XEN_PCI_MAGIC) != 0) {
  129. xenbus_dev_fatal(pdev->xdev, -EFAULT,
  130. "version mismatch (%s/%s) with pcifront - "
  131. "halting pciback",
  132. magic, XEN_PCI_MAGIC);
  133. goto out;
  134. }
  135. err = pciback_do_attach(pdev, gnt_ref, remote_evtchn);
  136. if (err)
  137. goto out;
  138. dev_dbg(&pdev->xdev->dev, "Connecting...\n");
  139. err = xenbus_switch_state(pdev->xdev, XenbusStateConnected);
  140. if (err)
  141. xenbus_dev_fatal(pdev->xdev, err,
  142. "Error switching to connected state!");
  143. dev_dbg(&pdev->xdev->dev, "Connected? %d\n", err);
  144. out:
  145. kfree(magic);
  146. return err;
  147. }
  148. static int pciback_publish_pci_dev(struct pciback_device *pdev,
  149. unsigned int domain, unsigned int bus,
  150. unsigned int devfn, unsigned int devid)
  151. {
  152. int err;
  153. int len;
  154. char str[64];
  155. len = snprintf(str, sizeof(str), "vdev-%d", devid);
  156. if (unlikely(len >= (sizeof(str) - 1))) {
  157. err = -ENOMEM;
  158. goto out;
  159. }
  160. err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str,
  161. "%04x:%02x:%02x.%02x", domain, bus,
  162. PCI_SLOT(devfn), PCI_FUNC(devfn));
  163. out:
  164. return err;
  165. }
  166. static int pciback_export_device(struct pciback_device *pdev,
  167. int domain, int bus, int slot, int func,
  168. int devid)
  169. {
  170. struct pci_dev *dev;
  171. int err = 0;
  172. dev_dbg(&pdev->xdev->dev, "exporting dom %x bus %x slot %x func %x\n",
  173. domain, bus, slot, func);
  174. dev = pcistub_get_pci_dev_by_slot(pdev, domain, bus, slot, func);
  175. if (!dev) {
  176. err = -EINVAL;
  177. xenbus_dev_fatal(pdev->xdev, err,
  178. "Couldn't locate PCI device "
  179. "(%04x:%02x:%02x.%01x)! "
  180. "perhaps already in-use?",
  181. domain, bus, slot, func);
  182. goto out;
  183. }
  184. err = pciback_add_pci_dev(pdev, dev, devid, pciback_publish_pci_dev);
  185. if (err)
  186. goto out;
  187. dev_dbg(&dev->dev, "registering for %d\n", pdev->xdev->otherend_id);
  188. if (xen_register_device_domain_owner(dev,
  189. pdev->xdev->otherend_id) != 0) {
  190. dev_err(&dev->dev, "device has been assigned to another " \
  191. "domain! Over-writting the ownership, but beware.\n");
  192. xen_unregister_device_domain_owner(dev);
  193. xen_register_device_domain_owner(dev, pdev->xdev->otherend_id);
  194. }
  195. /* TODO: It'd be nice to export a bridge and have all of its children
  196. * get exported with it. This may be best done in xend (which will
  197. * have to calculate resource usage anyway) but we probably want to
  198. * put something in here to ensure that if a bridge gets given to a
  199. * driver domain, that all devices under that bridge are not given
  200. * to other driver domains (as he who controls the bridge can disable
  201. * it and stop the other devices from working).
  202. */
  203. out:
  204. return err;
  205. }
  206. static int pciback_remove_device(struct pciback_device *pdev,
  207. int domain, int bus, int slot, int func)
  208. {
  209. int err = 0;
  210. struct pci_dev *dev;
  211. dev_dbg(&pdev->xdev->dev, "removing dom %x bus %x slot %x func %x\n",
  212. domain, bus, slot, func);
  213. dev = pciback_get_pci_dev(pdev, domain, bus, PCI_DEVFN(slot, func));
  214. if (!dev) {
  215. err = -EINVAL;
  216. dev_dbg(&pdev->xdev->dev, "Couldn't locate PCI device "
  217. "(%04x:%02x:%02x.%01x)! not owned by this domain\n",
  218. domain, bus, slot, func);
  219. goto out;
  220. }
  221. dev_dbg(&dev->dev, "unregistering for %d\n", pdev->xdev->otherend_id);
  222. xen_unregister_device_domain_owner(dev);
  223. pciback_release_pci_dev(pdev, dev);
  224. out:
  225. return err;
  226. }
  227. static int pciback_publish_pci_root(struct pciback_device *pdev,
  228. unsigned int domain, unsigned int bus)
  229. {
  230. unsigned int d, b;
  231. int i, root_num, len, err;
  232. char str[64];
  233. dev_dbg(&pdev->xdev->dev, "Publishing pci roots\n");
  234. err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
  235. "root_num", "%d", &root_num);
  236. if (err == 0 || err == -ENOENT)
  237. root_num = 0;
  238. else if (err < 0)
  239. goto out;
  240. /* Verify that we haven't already published this pci root */
  241. for (i = 0; i < root_num; i++) {
  242. len = snprintf(str, sizeof(str), "root-%d", i);
  243. if (unlikely(len >= (sizeof(str) - 1))) {
  244. err = -ENOMEM;
  245. goto out;
  246. }
  247. err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
  248. str, "%x:%x", &d, &b);
  249. if (err < 0)
  250. goto out;
  251. if (err != 2) {
  252. err = -EINVAL;
  253. goto out;
  254. }
  255. if (d == domain && b == bus) {
  256. err = 0;
  257. goto out;
  258. }
  259. }
  260. len = snprintf(str, sizeof(str), "root-%d", root_num);
  261. if (unlikely(len >= (sizeof(str) - 1))) {
  262. err = -ENOMEM;
  263. goto out;
  264. }
  265. dev_dbg(&pdev->xdev->dev, "writing root %d at %04x:%02x\n",
  266. root_num, domain, bus);
  267. err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str,
  268. "%04x:%02x", domain, bus);
  269. if (err)
  270. goto out;
  271. err = xenbus_printf(XBT_NIL, pdev->xdev->nodename,
  272. "root_num", "%d", (root_num + 1));
  273. out:
  274. return err;
  275. }
  276. static int pciback_reconfigure(struct pciback_device *pdev)
  277. {
  278. int err = 0;
  279. int num_devs;
  280. int domain, bus, slot, func;
  281. int substate;
  282. int i, len;
  283. char state_str[64];
  284. char dev_str[64];
  285. dev_dbg(&pdev->xdev->dev, "Reconfiguring device ...\n");
  286. /* Make sure we only reconfigure once */
  287. if (xenbus_read_driver_state(pdev->xdev->nodename) !=
  288. XenbusStateReconfiguring)
  289. goto out;
  290. err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, "num_devs", "%d",
  291. &num_devs);
  292. if (err != 1) {
  293. if (err >= 0)
  294. err = -EINVAL;
  295. xenbus_dev_fatal(pdev->xdev, err,
  296. "Error reading number of devices");
  297. goto out;
  298. }
  299. for (i = 0; i < num_devs; i++) {
  300. len = snprintf(state_str, sizeof(state_str), "state-%d", i);
  301. if (unlikely(len >= (sizeof(state_str) - 1))) {
  302. err = -ENOMEM;
  303. xenbus_dev_fatal(pdev->xdev, err,
  304. "String overflow while reading "
  305. "configuration");
  306. goto out;
  307. }
  308. err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, state_str,
  309. "%d", &substate);
  310. if (err != 1)
  311. substate = XenbusStateUnknown;
  312. switch (substate) {
  313. case XenbusStateInitialising:
  314. dev_dbg(&pdev->xdev->dev, "Attaching dev-%d ...\n", i);
  315. len = snprintf(dev_str, sizeof(dev_str), "dev-%d", i);
  316. if (unlikely(len >= (sizeof(dev_str) - 1))) {
  317. err = -ENOMEM;
  318. xenbus_dev_fatal(pdev->xdev, err,
  319. "String overflow while "
  320. "reading configuration");
  321. goto out;
  322. }
  323. err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
  324. dev_str, "%x:%x:%x.%x",
  325. &domain, &bus, &slot, &func);
  326. if (err < 0) {
  327. xenbus_dev_fatal(pdev->xdev, err,
  328. "Error reading device "
  329. "configuration");
  330. goto out;
  331. }
  332. if (err != 4) {
  333. err = -EINVAL;
  334. xenbus_dev_fatal(pdev->xdev, err,
  335. "Error parsing pci device "
  336. "configuration");
  337. goto out;
  338. }
  339. err = pciback_export_device(pdev, domain, bus, slot,
  340. func, i);
  341. if (err)
  342. goto out;
  343. /* Publish pci roots. */
  344. err = pciback_publish_pci_roots(pdev,
  345. pciback_publish_pci_root);
  346. if (err) {
  347. xenbus_dev_fatal(pdev->xdev, err,
  348. "Error while publish PCI root"
  349. "buses for frontend");
  350. goto out;
  351. }
  352. err = xenbus_printf(XBT_NIL, pdev->xdev->nodename,
  353. state_str, "%d",
  354. XenbusStateInitialised);
  355. if (err) {
  356. xenbus_dev_fatal(pdev->xdev, err,
  357. "Error switching substate of "
  358. "dev-%d\n", i);
  359. goto out;
  360. }
  361. break;
  362. case XenbusStateClosing:
  363. dev_dbg(&pdev->xdev->dev, "Detaching dev-%d ...\n", i);
  364. len = snprintf(dev_str, sizeof(dev_str), "vdev-%d", i);
  365. if (unlikely(len >= (sizeof(dev_str) - 1))) {
  366. err = -ENOMEM;
  367. xenbus_dev_fatal(pdev->xdev, err,
  368. "String overflow while "
  369. "reading configuration");
  370. goto out;
  371. }
  372. err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
  373. dev_str, "%x:%x:%x.%x",
  374. &domain, &bus, &slot, &func);
  375. if (err < 0) {
  376. xenbus_dev_fatal(pdev->xdev, err,
  377. "Error reading device "
  378. "configuration");
  379. goto out;
  380. }
  381. if (err != 4) {
  382. err = -EINVAL;
  383. xenbus_dev_fatal(pdev->xdev, err,
  384. "Error parsing pci device "
  385. "configuration");
  386. goto out;
  387. }
  388. err = pciback_remove_device(pdev, domain, bus, slot,
  389. func);
  390. if (err)
  391. goto out;
  392. /* TODO: If at some point we implement support for pci
  393. * root hot-remove on pcifront side, we'll need to
  394. * remove unnecessary xenstore nodes of pci roots here.
  395. */
  396. break;
  397. default:
  398. break;
  399. }
  400. }
  401. err = xenbus_switch_state(pdev->xdev, XenbusStateReconfigured);
  402. if (err) {
  403. xenbus_dev_fatal(pdev->xdev, err,
  404. "Error switching to reconfigured state!");
  405. goto out;
  406. }
  407. out:
  408. return 0;
  409. }
  410. static void pciback_frontend_changed(struct xenbus_device *xdev,
  411. enum xenbus_state fe_state)
  412. {
  413. struct pciback_device *pdev = dev_get_drvdata(&xdev->dev);
  414. dev_dbg(&xdev->dev, "fe state changed %d\n", fe_state);
  415. switch (fe_state) {
  416. case XenbusStateInitialised:
  417. pciback_attach(pdev);
  418. break;
  419. case XenbusStateReconfiguring:
  420. pciback_reconfigure(pdev);
  421. break;
  422. case XenbusStateConnected:
  423. /* pcifront switched its state from reconfiguring to connected.
  424. * Then switch to connected state.
  425. */
  426. xenbus_switch_state(xdev, XenbusStateConnected);
  427. break;
  428. case XenbusStateClosing:
  429. pciback_disconnect(pdev);
  430. xenbus_switch_state(xdev, XenbusStateClosing);
  431. break;
  432. case XenbusStateClosed:
  433. pciback_disconnect(pdev);
  434. xenbus_switch_state(xdev, XenbusStateClosed);
  435. if (xenbus_dev_is_online(xdev))
  436. break;
  437. /* fall through if not online */
  438. case XenbusStateUnknown:
  439. dev_dbg(&xdev->dev, "frontend is gone! unregister device\n");
  440. device_unregister(&xdev->dev);
  441. break;
  442. default:
  443. break;
  444. }
  445. }
  446. static int pciback_setup_backend(struct pciback_device *pdev)
  447. {
  448. /* Get configuration from xend (if available now) */
  449. int domain, bus, slot, func;
  450. int err = 0;
  451. int i, num_devs;
  452. char dev_str[64];
  453. char state_str[64];
  454. /* It's possible we could get the call to setup twice, so make sure
  455. * we're not already connected.
  456. */
  457. if (xenbus_read_driver_state(pdev->xdev->nodename) !=
  458. XenbusStateInitWait)
  459. goto out;
  460. dev_dbg(&pdev->xdev->dev, "getting be setup\n");
  461. err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, "num_devs", "%d",
  462. &num_devs);
  463. if (err != 1) {
  464. if (err >= 0)
  465. err = -EINVAL;
  466. xenbus_dev_fatal(pdev->xdev, err,
  467. "Error reading number of devices");
  468. goto out;
  469. }
  470. for (i = 0; i < num_devs; i++) {
  471. int l = snprintf(dev_str, sizeof(dev_str), "dev-%d", i);
  472. if (unlikely(l >= (sizeof(dev_str) - 1))) {
  473. err = -ENOMEM;
  474. xenbus_dev_fatal(pdev->xdev, err,
  475. "String overflow while reading "
  476. "configuration");
  477. goto out;
  478. }
  479. err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, dev_str,
  480. "%x:%x:%x.%x", &domain, &bus, &slot, &func);
  481. if (err < 0) {
  482. xenbus_dev_fatal(pdev->xdev, err,
  483. "Error reading device configuration");
  484. goto out;
  485. }
  486. if (err != 4) {
  487. err = -EINVAL;
  488. xenbus_dev_fatal(pdev->xdev, err,
  489. "Error parsing pci device "
  490. "configuration");
  491. goto out;
  492. }
  493. err = pciback_export_device(pdev, domain, bus, slot, func, i);
  494. if (err)
  495. goto out;
  496. /* Switch substate of this device. */
  497. l = snprintf(state_str, sizeof(state_str), "state-%d", i);
  498. if (unlikely(l >= (sizeof(state_str) - 1))) {
  499. err = -ENOMEM;
  500. xenbus_dev_fatal(pdev->xdev, err,
  501. "String overflow while reading "
  502. "configuration");
  503. goto out;
  504. }
  505. err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, state_str,
  506. "%d", XenbusStateInitialised);
  507. if (err) {
  508. xenbus_dev_fatal(pdev->xdev, err, "Error switching "
  509. "substate of dev-%d\n", i);
  510. goto out;
  511. }
  512. }
  513. err = pciback_publish_pci_roots(pdev, pciback_publish_pci_root);
  514. if (err) {
  515. xenbus_dev_fatal(pdev->xdev, err,
  516. "Error while publish PCI root buses "
  517. "for frontend");
  518. goto out;
  519. }
  520. err = xenbus_switch_state(pdev->xdev, XenbusStateInitialised);
  521. if (err)
  522. xenbus_dev_fatal(pdev->xdev, err,
  523. "Error switching to initialised state!");
  524. out:
  525. if (!err)
  526. /* see if pcifront is already configured (if not, we'll wait) */
  527. pciback_attach(pdev);
  528. return err;
  529. }
  530. static void pciback_be_watch(struct xenbus_watch *watch,
  531. const char **vec, unsigned int len)
  532. {
  533. struct pciback_device *pdev =
  534. container_of(watch, struct pciback_device, be_watch);
  535. switch (xenbus_read_driver_state(pdev->xdev->nodename)) {
  536. case XenbusStateInitWait:
  537. pciback_setup_backend(pdev);
  538. break;
  539. default:
  540. break;
  541. }
  542. }
  543. static int pciback_xenbus_probe(struct xenbus_device *dev,
  544. const struct xenbus_device_id *id)
  545. {
  546. int err = 0;
  547. struct pciback_device *pdev = alloc_pdev(dev);
  548. if (pdev == NULL) {
  549. err = -ENOMEM;
  550. xenbus_dev_fatal(dev, err,
  551. "Error allocating pciback_device struct");
  552. goto out;
  553. }
  554. /* wait for xend to configure us */
  555. err = xenbus_switch_state(dev, XenbusStateInitWait);
  556. if (err)
  557. goto out;
  558. /* watch the backend node for backend configuration information */
  559. err = xenbus_watch_path(dev, dev->nodename, &pdev->be_watch,
  560. pciback_be_watch);
  561. if (err)
  562. goto out;
  563. pdev->be_watching = 1;
  564. /* We need to force a call to our callback here in case
  565. * xend already configured us!
  566. */
  567. pciback_be_watch(&pdev->be_watch, NULL, 0);
  568. out:
  569. return err;
  570. }
  571. static int pciback_xenbus_remove(struct xenbus_device *dev)
  572. {
  573. struct pciback_device *pdev = dev_get_drvdata(&dev->dev);
  574. if (pdev != NULL)
  575. free_pdev(pdev);
  576. return 0;
  577. }
  578. static const struct xenbus_device_id xenpci_ids[] = {
  579. {"pci"},
  580. {""},
  581. };
  582. static struct xenbus_driver xenbus_pciback_driver = {
  583. .name = "pciback",
  584. .owner = THIS_MODULE,
  585. .ids = xenpci_ids,
  586. .probe = pciback_xenbus_probe,
  587. .remove = pciback_xenbus_remove,
  588. .otherend_changed = pciback_frontend_changed,
  589. };
  590. int __init pciback_xenbus_register(void)
  591. {
  592. pciback_wq = create_workqueue("pciback_workqueue");
  593. if (!pciback_wq) {
  594. printk(KERN_ERR "%s: create"
  595. "pciback_workqueue failed\n", __func__);
  596. return -EFAULT;
  597. }
  598. return xenbus_register_backend(&xenbus_pciback_driver);
  599. }
  600. void __exit pciback_xenbus_unregister(void)
  601. {
  602. destroy_workqueue(pciback_wq);
  603. xenbus_unregister_driver(&xenbus_pciback_driver);
  604. }