virtio_mmio.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * Virtio memory mapped device driver
  3. *
  4. * Copyright 2011, ARM Ltd.
  5. *
  6. * This module allows virtio devices to be used over a virtual, memory mapped
  7. * platform device.
  8. *
  9. * The guest device(s) may be instantiated in one of three equivalent ways:
  10. *
  11. * 1. Static platform device in board's code, eg.:
  12. *
  13. * static struct platform_device v2m_virtio_device = {
  14. * .name = "virtio-mmio",
  15. * .id = -1,
  16. * .num_resources = 2,
  17. * .resource = (struct resource []) {
  18. * {
  19. * .start = 0x1001e000,
  20. * .end = 0x1001e0ff,
  21. * .flags = IORESOURCE_MEM,
  22. * }, {
  23. * .start = 42 + 32,
  24. * .end = 42 + 32,
  25. * .flags = IORESOURCE_IRQ,
  26. * },
  27. * }
  28. * };
  29. *
  30. * 2. Device Tree node, eg.:
  31. *
  32. * virtio_block@1e000 {
  33. * compatible = "virtio,mmio";
  34. * reg = <0x1e000 0x100>;
  35. * interrupts = <42>;
  36. * }
  37. *
  38. * 3. Kernel module (or command line) parameter. Can be used more than once -
  39. * one device will be created for each one. Syntax:
  40. *
  41. * [virtio_mmio.]device=<size>@<baseaddr>:<irq>[:<id>]
  42. * where:
  43. * <size> := size (can use standard suffixes like K, M or G)
  44. * <baseaddr> := physical base address
  45. * <irq> := interrupt number (as passed to request_irq())
  46. * <id> := (optional) platform device id
  47. * eg.:
  48. * virtio_mmio.device=0x100@0x100b0000:48 \
  49. * virtio_mmio.device=1K@0x1001e000:74
  50. *
  51. *
  52. *
  53. * Registers layout (all 32-bit wide):
  54. *
  55. * offset d. name description
  56. * ------ -- ---------------- -----------------
  57. *
  58. * 0x000 R MagicValue Magic value "virt"
  59. * 0x004 R Version Device version (current max. 1)
  60. * 0x008 R DeviceID Virtio device ID
  61. * 0x00c R VendorID Virtio vendor ID
  62. *
  63. * 0x010 R HostFeatures Features supported by the host
  64. * 0x014 W HostFeaturesSel Set of host features to access via HostFeatures
  65. *
  66. * 0x020 W GuestFeatures Features activated by the guest
  67. * 0x024 W GuestFeaturesSel Set of activated features to set via GuestFeatures
  68. * 0x028 W GuestPageSize Size of guest's memory page in bytes
  69. *
  70. * 0x030 W QueueSel Queue selector
  71. * 0x034 R QueueNumMax Maximum size of the currently selected queue
  72. * 0x038 W QueueNum Queue size for the currently selected queue
  73. * 0x03c W QueueAlign Used Ring alignment for the current queue
  74. * 0x040 RW QueuePFN PFN for the currently selected queue
  75. *
  76. * 0x050 W QueueNotify Queue notifier
  77. * 0x060 R InterruptStatus Interrupt status register
  78. * 0x064 W InterruptACK Interrupt acknowledge register
  79. * 0x070 RW Status Device status register
  80. *
  81. * 0x100+ RW Device-specific configuration space
  82. *
  83. * Based on Virtio PCI driver by Anthony Liguori, copyright IBM Corp. 2007
  84. *
  85. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  86. * See the COPYING file in the top-level directory.
  87. */
  88. #define pr_fmt(fmt) "virtio-mmio: " fmt
  89. #include <linux/highmem.h>
  90. #include <linux/interrupt.h>
  91. #include <linux/io.h>
  92. #include <linux/list.h>
  93. #include <linux/module.h>
  94. #include <linux/platform_device.h>
  95. #include <linux/slab.h>
  96. #include <linux/spinlock.h>
  97. #include <linux/virtio.h>
  98. #include <linux/virtio_config.h>
  99. #include <linux/virtio_mmio.h>
  100. #include <linux/virtio_ring.h>
  101. /* The alignment to use between consumer and producer parts of vring.
  102. * Currently hardcoded to the page size. */
  103. #define VIRTIO_MMIO_VRING_ALIGN PAGE_SIZE
  104. #define to_virtio_mmio_device(_plat_dev) \
  105. container_of(_plat_dev, struct virtio_mmio_device, vdev)
  106. struct virtio_mmio_device {
  107. struct virtio_device vdev;
  108. struct platform_device *pdev;
  109. void __iomem *base;
  110. unsigned long version;
  111. /* a list of queues so we can dispatch IRQs */
  112. spinlock_t lock;
  113. struct list_head virtqueues;
  114. };
  115. struct virtio_mmio_vq_info {
  116. /* the actual virtqueue */
  117. struct virtqueue *vq;
  118. /* the number of entries in the queue */
  119. unsigned int num;
  120. /* the virtual address of the ring queue */
  121. void *queue;
  122. /* the list node for the virtqueues list */
  123. struct list_head node;
  124. };
  125. /* Configuration interface */
  126. static u32 vm_get_features(struct virtio_device *vdev)
  127. {
  128. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
  129. /* TODO: Features > 32 bits */
  130. writel(0, vm_dev->base + VIRTIO_MMIO_HOST_FEATURES_SEL);
  131. return readl(vm_dev->base + VIRTIO_MMIO_HOST_FEATURES);
  132. }
  133. static void vm_finalize_features(struct virtio_device *vdev)
  134. {
  135. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
  136. int i;
  137. /* Give virtio_ring a chance to accept features. */
  138. vring_transport_features(vdev);
  139. for (i = 0; i < ARRAY_SIZE(vdev->features); i++) {
  140. writel(i, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SEL);
  141. writel(vdev->features[i],
  142. vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES);
  143. }
  144. }
  145. static void vm_get(struct virtio_device *vdev, unsigned offset,
  146. void *buf, unsigned len)
  147. {
  148. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
  149. u8 *ptr = buf;
  150. int i;
  151. for (i = 0; i < len; i++)
  152. ptr[i] = readb(vm_dev->base + VIRTIO_MMIO_CONFIG + offset + i);
  153. }
  154. static void vm_set(struct virtio_device *vdev, unsigned offset,
  155. const void *buf, unsigned len)
  156. {
  157. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
  158. const u8 *ptr = buf;
  159. int i;
  160. for (i = 0; i < len; i++)
  161. writeb(ptr[i], vm_dev->base + VIRTIO_MMIO_CONFIG + offset + i);
  162. }
  163. static u8 vm_get_status(struct virtio_device *vdev)
  164. {
  165. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
  166. return readl(vm_dev->base + VIRTIO_MMIO_STATUS) & 0xff;
  167. }
  168. static void vm_set_status(struct virtio_device *vdev, u8 status)
  169. {
  170. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
  171. /* We should never be setting status to 0. */
  172. BUG_ON(status == 0);
  173. writel(status, vm_dev->base + VIRTIO_MMIO_STATUS);
  174. }
  175. static void vm_reset(struct virtio_device *vdev)
  176. {
  177. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
  178. /* 0 status means a reset. */
  179. writel(0, vm_dev->base + VIRTIO_MMIO_STATUS);
  180. }
  181. /* Transport interface */
  182. /* the notify function used when creating a virt queue */
  183. static void vm_notify(struct virtqueue *vq)
  184. {
  185. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev);
  186. /* We write the queue's selector into the notification register to
  187. * signal the other end */
  188. writel(vq->index, vm_dev->base + VIRTIO_MMIO_QUEUE_NOTIFY);
  189. }
  190. /* Notify all virtqueues on an interrupt. */
  191. static irqreturn_t vm_interrupt(int irq, void *opaque)
  192. {
  193. struct virtio_mmio_device *vm_dev = opaque;
  194. struct virtio_mmio_vq_info *info;
  195. struct virtio_driver *vdrv = container_of(vm_dev->vdev.dev.driver,
  196. struct virtio_driver, driver);
  197. unsigned long status;
  198. unsigned long flags;
  199. irqreturn_t ret = IRQ_NONE;
  200. /* Read and acknowledge interrupts */
  201. status = readl(vm_dev->base + VIRTIO_MMIO_INTERRUPT_STATUS);
  202. writel(status, vm_dev->base + VIRTIO_MMIO_INTERRUPT_ACK);
  203. if (unlikely(status & VIRTIO_MMIO_INT_CONFIG)
  204. && vdrv && vdrv->config_changed) {
  205. vdrv->config_changed(&vm_dev->vdev);
  206. ret = IRQ_HANDLED;
  207. }
  208. if (likely(status & VIRTIO_MMIO_INT_VRING)) {
  209. spin_lock_irqsave(&vm_dev->lock, flags);
  210. list_for_each_entry(info, &vm_dev->virtqueues, node)
  211. ret |= vring_interrupt(irq, info->vq);
  212. spin_unlock_irqrestore(&vm_dev->lock, flags);
  213. }
  214. return ret;
  215. }
  216. static void vm_del_vq(struct virtqueue *vq)
  217. {
  218. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev);
  219. struct virtio_mmio_vq_info *info = vq->priv;
  220. unsigned long flags, size;
  221. unsigned int index = vq->index;
  222. spin_lock_irqsave(&vm_dev->lock, flags);
  223. list_del(&info->node);
  224. spin_unlock_irqrestore(&vm_dev->lock, flags);
  225. vring_del_virtqueue(vq);
  226. /* Select and deactivate the queue */
  227. writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
  228. writel(0, vm_dev->base + VIRTIO_MMIO_QUEUE_PFN);
  229. size = PAGE_ALIGN(vring_size(info->num, VIRTIO_MMIO_VRING_ALIGN));
  230. free_pages_exact(info->queue, size);
  231. kfree(info);
  232. }
  233. static void vm_del_vqs(struct virtio_device *vdev)
  234. {
  235. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
  236. struct virtqueue *vq, *n;
  237. list_for_each_entry_safe(vq, n, &vdev->vqs, list)
  238. vm_del_vq(vq);
  239. free_irq(platform_get_irq(vm_dev->pdev, 0), vm_dev);
  240. }
  241. static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index,
  242. void (*callback)(struct virtqueue *vq),
  243. const char *name)
  244. {
  245. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
  246. struct virtio_mmio_vq_info *info;
  247. struct virtqueue *vq;
  248. unsigned long flags, size;
  249. int err;
  250. if (!name)
  251. return NULL;
  252. /* Select the queue we're interested in */
  253. writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
  254. /* Queue shouldn't already be set up. */
  255. if (readl(vm_dev->base + VIRTIO_MMIO_QUEUE_PFN)) {
  256. err = -ENOENT;
  257. goto error_available;
  258. }
  259. /* Allocate and fill out our active queue description */
  260. info = kmalloc(sizeof(*info), GFP_KERNEL);
  261. if (!info) {
  262. err = -ENOMEM;
  263. goto error_kmalloc;
  264. }
  265. /* Allocate pages for the queue - start with a queue as big as
  266. * possible (limited by maximum size allowed by device), drop down
  267. * to a minimal size, just big enough to fit descriptor table
  268. * and two rings (which makes it "alignment_size * 2")
  269. */
  270. info->num = readl(vm_dev->base + VIRTIO_MMIO_QUEUE_NUM_MAX);
  271. /* If the device reports a 0 entry queue, we won't be able to
  272. * use it to perform I/O, and vring_new_virtqueue() can't create
  273. * empty queues anyway, so don't bother to set up the device.
  274. */
  275. if (info->num == 0) {
  276. err = -ENOENT;
  277. goto error_alloc_pages;
  278. }
  279. while (1) {
  280. size = PAGE_ALIGN(vring_size(info->num,
  281. VIRTIO_MMIO_VRING_ALIGN));
  282. /* Did the last iter shrink the queue below minimum size? */
  283. if (size < VIRTIO_MMIO_VRING_ALIGN * 2) {
  284. err = -ENOMEM;
  285. goto error_alloc_pages;
  286. }
  287. info->queue = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
  288. if (info->queue)
  289. break;
  290. info->num /= 2;
  291. }
  292. /* Activate the queue */
  293. writel(info->num, vm_dev->base + VIRTIO_MMIO_QUEUE_NUM);
  294. writel(VIRTIO_MMIO_VRING_ALIGN,
  295. vm_dev->base + VIRTIO_MMIO_QUEUE_ALIGN);
  296. writel(virt_to_phys(info->queue) >> PAGE_SHIFT,
  297. vm_dev->base + VIRTIO_MMIO_QUEUE_PFN);
  298. /* Create the vring */
  299. vq = vring_new_virtqueue(index, info->num, VIRTIO_MMIO_VRING_ALIGN, vdev,
  300. true, info->queue, vm_notify, callback, name);
  301. if (!vq) {
  302. err = -ENOMEM;
  303. goto error_new_virtqueue;
  304. }
  305. vq->priv = info;
  306. info->vq = vq;
  307. spin_lock_irqsave(&vm_dev->lock, flags);
  308. list_add(&info->node, &vm_dev->virtqueues);
  309. spin_unlock_irqrestore(&vm_dev->lock, flags);
  310. return vq;
  311. error_new_virtqueue:
  312. writel(0, vm_dev->base + VIRTIO_MMIO_QUEUE_PFN);
  313. free_pages_exact(info->queue, size);
  314. error_alloc_pages:
  315. kfree(info);
  316. error_kmalloc:
  317. error_available:
  318. return ERR_PTR(err);
  319. }
  320. static int vm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
  321. struct virtqueue *vqs[],
  322. vq_callback_t *callbacks[],
  323. const char *names[])
  324. {
  325. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
  326. unsigned int irq = platform_get_irq(vm_dev->pdev, 0);
  327. int i, err;
  328. err = request_irq(irq, vm_interrupt, IRQF_SHARED,
  329. dev_name(&vdev->dev), vm_dev);
  330. if (err)
  331. return err;
  332. for (i = 0; i < nvqs; ++i) {
  333. vqs[i] = vm_setup_vq(vdev, i, callbacks[i], names[i]);
  334. if (IS_ERR(vqs[i])) {
  335. vm_del_vqs(vdev);
  336. return PTR_ERR(vqs[i]);
  337. }
  338. }
  339. return 0;
  340. }
  341. static const char *vm_bus_name(struct virtio_device *vdev)
  342. {
  343. struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
  344. return vm_dev->pdev->name;
  345. }
  346. static const struct virtio_config_ops virtio_mmio_config_ops = {
  347. .get = vm_get,
  348. .set = vm_set,
  349. .get_status = vm_get_status,
  350. .set_status = vm_set_status,
  351. .reset = vm_reset,
  352. .find_vqs = vm_find_vqs,
  353. .del_vqs = vm_del_vqs,
  354. .get_features = vm_get_features,
  355. .finalize_features = vm_finalize_features,
  356. .bus_name = vm_bus_name,
  357. };
  358. /* Platform device */
  359. static int virtio_mmio_probe(struct platform_device *pdev)
  360. {
  361. struct virtio_mmio_device *vm_dev;
  362. struct resource *mem;
  363. unsigned long magic;
  364. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  365. if (!mem)
  366. return -EINVAL;
  367. if (!devm_request_mem_region(&pdev->dev, mem->start,
  368. resource_size(mem), pdev->name))
  369. return -EBUSY;
  370. vm_dev = devm_kzalloc(&pdev->dev, sizeof(*vm_dev), GFP_KERNEL);
  371. if (!vm_dev)
  372. return -ENOMEM;
  373. vm_dev->vdev.dev.parent = &pdev->dev;
  374. vm_dev->vdev.config = &virtio_mmio_config_ops;
  375. vm_dev->pdev = pdev;
  376. INIT_LIST_HEAD(&vm_dev->virtqueues);
  377. spin_lock_init(&vm_dev->lock);
  378. vm_dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
  379. if (vm_dev->base == NULL)
  380. return -EFAULT;
  381. /* Check magic value */
  382. magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE);
  383. if (memcmp(&magic, "virt", 4) != 0) {
  384. dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
  385. return -ENODEV;
  386. }
  387. /* Check device version */
  388. vm_dev->version = readl(vm_dev->base + VIRTIO_MMIO_VERSION);
  389. if (vm_dev->version != 1) {
  390. dev_err(&pdev->dev, "Version %ld not supported!\n",
  391. vm_dev->version);
  392. return -ENXIO;
  393. }
  394. vm_dev->vdev.id.device = readl(vm_dev->base + VIRTIO_MMIO_DEVICE_ID);
  395. vm_dev->vdev.id.vendor = readl(vm_dev->base + VIRTIO_MMIO_VENDOR_ID);
  396. writel(PAGE_SIZE, vm_dev->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
  397. platform_set_drvdata(pdev, vm_dev);
  398. return register_virtio_device(&vm_dev->vdev);
  399. }
  400. static int virtio_mmio_remove(struct platform_device *pdev)
  401. {
  402. struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
  403. unregister_virtio_device(&vm_dev->vdev);
  404. return 0;
  405. }
  406. /* Devices list parameter */
  407. #if defined(CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES)
  408. static struct device vm_cmdline_parent = {
  409. .init_name = "virtio-mmio-cmdline",
  410. };
  411. static int vm_cmdline_parent_registered;
  412. static int vm_cmdline_id;
  413. static int vm_cmdline_set(const char *device,
  414. const struct kernel_param *kp)
  415. {
  416. int err;
  417. struct resource resources[2] = {};
  418. char *str;
  419. long long int base, size;
  420. unsigned int irq;
  421. int processed, consumed = 0;
  422. struct platform_device *pdev;
  423. /* Consume "size" part of the command line parameter */
  424. size = memparse(device, &str);
  425. /* Get "@<base>:<irq>[:<id>]" chunks */
  426. processed = sscanf(str, "@%lli:%u%n:%d%n",
  427. &base, &irq, &consumed,
  428. &vm_cmdline_id, &consumed);
  429. /*
  430. * sscanf() must processes at least 2 chunks; also there
  431. * must be no extra characters after the last chunk, so
  432. * str[consumed] must be '\0'
  433. */
  434. if (processed < 2 || str[consumed])
  435. return -EINVAL;
  436. resources[0].flags = IORESOURCE_MEM;
  437. resources[0].start = base;
  438. resources[0].end = base + size - 1;
  439. resources[1].flags = IORESOURCE_IRQ;
  440. resources[1].start = resources[1].end = irq;
  441. if (!vm_cmdline_parent_registered) {
  442. err = device_register(&vm_cmdline_parent);
  443. if (err) {
  444. pr_err("Failed to register parent device!\n");
  445. return err;
  446. }
  447. vm_cmdline_parent_registered = 1;
  448. }
  449. pr_info("Registering device virtio-mmio.%d at 0x%llx-0x%llx, IRQ %d.\n",
  450. vm_cmdline_id,
  451. (unsigned long long)resources[0].start,
  452. (unsigned long long)resources[0].end,
  453. (int)resources[1].start);
  454. pdev = platform_device_register_resndata(&vm_cmdline_parent,
  455. "virtio-mmio", vm_cmdline_id++,
  456. resources, ARRAY_SIZE(resources), NULL, 0);
  457. if (IS_ERR(pdev))
  458. return PTR_ERR(pdev);
  459. return 0;
  460. }
  461. static int vm_cmdline_get_device(struct device *dev, void *data)
  462. {
  463. char *buffer = data;
  464. unsigned int len = strlen(buffer);
  465. struct platform_device *pdev = to_platform_device(dev);
  466. snprintf(buffer + len, PAGE_SIZE - len, "0x%llx@0x%llx:%llu:%d\n",
  467. pdev->resource[0].end - pdev->resource[0].start + 1ULL,
  468. (unsigned long long)pdev->resource[0].start,
  469. (unsigned long long)pdev->resource[1].start,
  470. pdev->id);
  471. return 0;
  472. }
  473. static int vm_cmdline_get(char *buffer, const struct kernel_param *kp)
  474. {
  475. buffer[0] = '\0';
  476. device_for_each_child(&vm_cmdline_parent, buffer,
  477. vm_cmdline_get_device);
  478. return strlen(buffer) + 1;
  479. }
  480. static struct kernel_param_ops vm_cmdline_param_ops = {
  481. .set = vm_cmdline_set,
  482. .get = vm_cmdline_get,
  483. };
  484. device_param_cb(device, &vm_cmdline_param_ops, NULL, S_IRUSR);
  485. static int vm_unregister_cmdline_device(struct device *dev,
  486. void *data)
  487. {
  488. platform_device_unregister(to_platform_device(dev));
  489. return 0;
  490. }
  491. static void vm_unregister_cmdline_devices(void)
  492. {
  493. if (vm_cmdline_parent_registered) {
  494. device_for_each_child(&vm_cmdline_parent, NULL,
  495. vm_unregister_cmdline_device);
  496. device_unregister(&vm_cmdline_parent);
  497. vm_cmdline_parent_registered = 0;
  498. }
  499. }
  500. #else
  501. static void vm_unregister_cmdline_devices(void)
  502. {
  503. }
  504. #endif
  505. /* Platform driver */
  506. static struct of_device_id virtio_mmio_match[] = {
  507. { .compatible = "virtio,mmio", },
  508. {},
  509. };
  510. MODULE_DEVICE_TABLE(of, virtio_mmio_match);
  511. static struct platform_driver virtio_mmio_driver = {
  512. .probe = virtio_mmio_probe,
  513. .remove = virtio_mmio_remove,
  514. .driver = {
  515. .name = "virtio-mmio",
  516. .owner = THIS_MODULE,
  517. .of_match_table = virtio_mmio_match,
  518. },
  519. };
  520. static int __init virtio_mmio_init(void)
  521. {
  522. return platform_driver_register(&virtio_mmio_driver);
  523. }
  524. static void __exit virtio_mmio_exit(void)
  525. {
  526. platform_driver_unregister(&virtio_mmio_driver);
  527. vm_unregister_cmdline_devices();
  528. }
  529. module_init(virtio_mmio_init);
  530. module_exit(virtio_mmio_exit);
  531. MODULE_AUTHOR("Pawel Moll <pawel.moll@arm.com>");
  532. MODULE_DESCRIPTION("Platform bus driver for memory mapped virtio devices");
  533. MODULE_LICENSE("GPL");