README.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. Using the mtty vfio-mdev sample code
  2. ====================================
  3. mtty is a sample vfio-mdev driver that demonstrates how to use the mediated
  4. device framework.
  5. The sample driver creates an mdev device that simulates a serial port over a PCI
  6. card.
  7. 1. Build and load the mtty.ko module.
  8. This step creates a dummy device, /sys/devices/virtual/mtty/mtty/
  9. Files in this device directory in sysfs are similar to the following::
  10. # tree /sys/devices/virtual/mtty/mtty/
  11. /sys/devices/virtual/mtty/mtty/
  12. |-- mdev_supported_types
  13. | |-- mtty-1
  14. | | |-- available_instances
  15. | | |-- create
  16. | | |-- device_api
  17. | | |-- devices
  18. | | `-- name
  19. | `-- mtty-2
  20. | |-- available_instances
  21. | |-- create
  22. | |-- device_api
  23. | |-- devices
  24. | `-- name
  25. |-- mtty_dev
  26. | `-- sample_mtty_dev
  27. |-- power
  28. | |-- autosuspend_delay_ms
  29. | |-- control
  30. | |-- runtime_active_time
  31. | |-- runtime_status
  32. | `-- runtime_suspended_time
  33. |-- subsystem -> ../../../../class/mtty
  34. `-- uevent
  35. 2. Create a mediated device by using the dummy device that you created in the
  36. previous step::
  37. # echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001" > \
  38. /sys/devices/virtual/mtty/mtty/mdev_supported_types/mtty-2/create
  39. 3. Add parameters to qemu-kvm::
  40. -device vfio-pci,\
  41. sysfsdev=/sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001
  42. 4. Boot the VM.
  43. In the Linux guest VM, with no hardware on the host, the device appears
  44. as follows::
  45. # lspci -s 00:05.0 -xxvv
  46. 00:05.0 Serial controller: Device 4348:3253 (rev 10) (prog-if 02 [16550])
  47. Subsystem: Device 4348:3253
  48. Physical Slot: 5
  49. Control: I/O+ Mem- BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr-
  50. Stepping- SERR- FastB2B- DisINTx-
  51. Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort-
  52. <TAbort- <MAbort- >SERR- <PERR- INTx-
  53. Interrupt: pin A routed to IRQ 10
  54. Region 0: I/O ports at c150 [size=8]
  55. Region 1: I/O ports at c158 [size=8]
  56. Kernel driver in use: serial
  57. 00: 48 43 53 32 01 00 00 02 10 02 00 07 00 00 00 00
  58. 10: 51 c1 00 00 59 c1 00 00 00 00 00 00 00 00 00 00
  59. 20: 00 00 00 00 00 00 00 00 00 00 00 00 48 43 53 32
  60. 30: 00 00 00 00 00 00 00 00 00 00 00 00 0a 01 00 00
  61. In the Linux guest VM, dmesg output for the device is as follows:
  62. serial 0000:00:05.0: PCI INT A -> Link[LNKA] -> GSI 10 (level, high) -> IRQ 10
  63. 0000:00:05.0: ttyS1 at I/O 0xc150 (irq = 10) is a 16550A
  64. 0000:00:05.0: ttyS2 at I/O 0xc158 (irq = 10) is a 16550A
  65. 5. In the Linux guest VM, check the serial ports::
  66. # setserial -g /dev/ttyS*
  67. /dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
  68. /dev/ttyS1, UART: 16550A, Port: 0xc150, IRQ: 10
  69. /dev/ttyS2, UART: 16550A, Port: 0xc158, IRQ: 10
  70. 6. Using minicom or any terminal emulation program, open port /dev/ttyS1 or
  71. /dev/ttyS2 with hardware flow control disabled.
  72. 7. Type data on the minicom terminal or send data to the terminal emulation
  73. program and read the data.
  74. Data is loop backed from hosts mtty driver.
  75. 8. Destroy the mediated device that you created::
  76. # echo 1 > /sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001/remove