xenbus.c 17 KB

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