1a6546f89SThomas Gleixner.. SPDX-License-Identifier: GPL-2.0-only 2baa293e9SMauro Carvalho Chehab.. include:: <isonum.txt> 3baa293e9SMauro Carvalho Chehab 4baa293e9SMauro Carvalho Chehab===================== 5baa293e9SMauro Carvalho ChehabVFIO Mediated devices 6baa293e9SMauro Carvalho Chehab===================== 7baa293e9SMauro Carvalho Chehab 8baa293e9SMauro Carvalho Chehab:Copyright: |copy| 2016, NVIDIA CORPORATION. All rights reserved. 9baa293e9SMauro Carvalho Chehab:Author: Neo Jia <cjia@nvidia.com> 10baa293e9SMauro Carvalho Chehab:Author: Kirti Wankhede <kwankhede@nvidia.com> 11baa293e9SMauro Carvalho Chehab 12baa293e9SMauro Carvalho Chehab 13baa293e9SMauro Carvalho Chehab 14baa293e9SMauro Carvalho ChehabVirtual Function I/O (VFIO) Mediated devices[1] 15baa293e9SMauro Carvalho Chehab=============================================== 16baa293e9SMauro Carvalho Chehab 17baa293e9SMauro Carvalho ChehabThe number of use cases for virtualizing DMA devices that do not have built-in 18baa293e9SMauro Carvalho ChehabSR_IOV capability is increasing. Previously, to virtualize such devices, 19baa293e9SMauro Carvalho Chehabdevelopers had to create their own management interfaces and APIs, and then 20baa293e9SMauro Carvalho Chehabintegrate them with user space software. To simplify integration with user space 21baa293e9SMauro Carvalho Chehabsoftware, we have identified common requirements and a unified management 22baa293e9SMauro Carvalho Chehabinterface for such devices. 23baa293e9SMauro Carvalho Chehab 24baa293e9SMauro Carvalho ChehabThe VFIO driver framework provides unified APIs for direct device access. It is 25baa293e9SMauro Carvalho Chehaban IOMMU/device-agnostic framework for exposing direct device access to user 26baa293e9SMauro Carvalho Chehabspace in a secure, IOMMU-protected environment. This framework is used for 27baa293e9SMauro Carvalho Chehabmultiple devices, such as GPUs, network adapters, and compute accelerators. With 28baa293e9SMauro Carvalho Chehabdirect device access, virtual machines or user space applications have direct 29baa293e9SMauro Carvalho Chehabaccess to the physical device. This framework is reused for mediated devices. 30baa293e9SMauro Carvalho Chehab 31baa293e9SMauro Carvalho ChehabThe mediated core driver provides a common interface for mediated device 32baa293e9SMauro Carvalho Chehabmanagement that can be used by drivers of different devices. This module 33baa293e9SMauro Carvalho Chehabprovides a generic interface to perform these operations: 34baa293e9SMauro Carvalho Chehab 35baa293e9SMauro Carvalho Chehab* Create and destroy a mediated device 36baa293e9SMauro Carvalho Chehab* Add a mediated device to and remove it from a mediated bus driver 37baa293e9SMauro Carvalho Chehab* Add a mediated device to and remove it from an IOMMU group 38baa293e9SMauro Carvalho Chehab 39baa293e9SMauro Carvalho ChehabThe mediated core driver also provides an interface to register a bus driver. 40baa293e9SMauro Carvalho ChehabFor example, the mediated VFIO mdev driver is designed for mediated devices and 41baa293e9SMauro Carvalho Chehabsupports VFIO APIs. The mediated bus driver adds a mediated device to and 42baa293e9SMauro Carvalho Chehabremoves it from a VFIO group. 43baa293e9SMauro Carvalho Chehab 44baa293e9SMauro Carvalho ChehabThe following high-level block diagram shows the main components and interfaces 45baa293e9SMauro Carvalho Chehabin the VFIO mediated driver framework. The diagram shows NVIDIA, Intel, and IBM 46baa293e9SMauro Carvalho Chehabdevices as examples, as these devices are the first devices to use this module:: 47baa293e9SMauro Carvalho Chehab 48baa293e9SMauro Carvalho Chehab +---------------+ 49baa293e9SMauro Carvalho Chehab | | 50baa293e9SMauro Carvalho Chehab | +-----------+ | mdev_register_driver() +--------------+ 51baa293e9SMauro Carvalho Chehab | | | +<------------------------+ | 52baa293e9SMauro Carvalho Chehab | | mdev | | | | 53baa293e9SMauro Carvalho Chehab | | bus | +------------------------>+ vfio_mdev.ko |<-> VFIO user 54baa293e9SMauro Carvalho Chehab | | driver | | probe()/remove() | | APIs 55baa293e9SMauro Carvalho Chehab | | | | +--------------+ 56baa293e9SMauro Carvalho Chehab | +-----------+ | 57baa293e9SMauro Carvalho Chehab | | 58baa293e9SMauro Carvalho Chehab | MDEV CORE | 59baa293e9SMauro Carvalho Chehab | MODULE | 60baa293e9SMauro Carvalho Chehab | mdev.ko | 6189345d51SChristoph Hellwig | +-----------+ | mdev_register_parent() +--------------+ 62baa293e9SMauro Carvalho Chehab | | | +<------------------------+ | 63baa293e9SMauro Carvalho Chehab | | | | | nvidia.ko |<-> physical 64baa293e9SMauro Carvalho Chehab | | | +------------------------>+ | device 65baa293e9SMauro Carvalho Chehab | | | | callbacks +--------------+ 66baa293e9SMauro Carvalho Chehab | | Physical | | 6789345d51SChristoph Hellwig | | device | | mdev_register_parent() +--------------+ 68baa293e9SMauro Carvalho Chehab | | interface | |<------------------------+ | 69baa293e9SMauro Carvalho Chehab | | | | | i915.ko |<-> physical 70baa293e9SMauro Carvalho Chehab | | | +------------------------>+ | device 71baa293e9SMauro Carvalho Chehab | | | | callbacks +--------------+ 72baa293e9SMauro Carvalho Chehab | | | | 7389345d51SChristoph Hellwig | | | | mdev_register_parent() +--------------+ 74baa293e9SMauro Carvalho Chehab | | | +<------------------------+ | 75baa293e9SMauro Carvalho Chehab | | | | | ccw_device.ko|<-> physical 76baa293e9SMauro Carvalho Chehab | | | +------------------------>+ | device 77baa293e9SMauro Carvalho Chehab | | | | callbacks +--------------+ 78baa293e9SMauro Carvalho Chehab | +-----------+ | 79baa293e9SMauro Carvalho Chehab +---------------+ 80baa293e9SMauro Carvalho Chehab 81baa293e9SMauro Carvalho Chehab 82baa293e9SMauro Carvalho ChehabRegistration Interfaces 83baa293e9SMauro Carvalho Chehab======================= 84baa293e9SMauro Carvalho Chehab 85baa293e9SMauro Carvalho ChehabThe mediated core driver provides the following types of registration 86baa293e9SMauro Carvalho Chehabinterfaces: 87baa293e9SMauro Carvalho Chehab 88baa293e9SMauro Carvalho Chehab* Registration interface for a mediated bus driver 89baa293e9SMauro Carvalho Chehab* Physical device driver interface 90baa293e9SMauro Carvalho Chehab 91baa293e9SMauro Carvalho ChehabRegistration Interface for a Mediated Bus Driver 92baa293e9SMauro Carvalho Chehab------------------------------------------------ 93baa293e9SMauro Carvalho Chehab 9488a21f26SJason GunthorpeThe registration interface for a mediated device driver provides the following 95baa293e9SMauro Carvalho Chehabstructure to represent a mediated device's driver:: 96baa293e9SMauro Carvalho Chehab 97baa293e9SMauro Carvalho Chehab /* 98baa293e9SMauro Carvalho Chehab * struct mdev_driver [2] - Mediated device's driver 99baa293e9SMauro Carvalho Chehab * @probe: called when new device created 100baa293e9SMauro Carvalho Chehab * @remove: called when device removed 101baa293e9SMauro Carvalho Chehab * @driver: device driver structure 102baa293e9SMauro Carvalho Chehab */ 103baa293e9SMauro Carvalho Chehab struct mdev_driver { 1042a3d15f2SJason Gunthorpe int (*probe) (struct mdev_device *dev); 1052a3d15f2SJason Gunthorpe void (*remove) (struct mdev_device *dev); 106da44c340SChristoph Hellwig const struct attribute * const *types_attrs; 107baa293e9SMauro Carvalho Chehab struct device_driver driver; 108baa293e9SMauro Carvalho Chehab }; 109baa293e9SMauro Carvalho Chehab 110baa293e9SMauro Carvalho ChehabA mediated bus driver for mdev should use this structure in the function calls 111baa293e9SMauro Carvalho Chehabto register and unregister itself with the core driver: 112baa293e9SMauro Carvalho Chehab 113baa293e9SMauro Carvalho Chehab* Register:: 114baa293e9SMauro Carvalho Chehab 115d1877e63SAlex Williamson int mdev_register_driver(struct mdev_driver *drv); 116baa293e9SMauro Carvalho Chehab 117baa293e9SMauro Carvalho Chehab* Unregister:: 118baa293e9SMauro Carvalho Chehab 119d1877e63SAlex Williamson void mdev_unregister_driver(struct mdev_driver *drv); 120baa293e9SMauro Carvalho Chehab 1216b42f491SJason GunthorpeThe mediated bus driver's probe function should create a vfio_device on top of 1226b42f491SJason Gunthorpethe mdev_device and connect it to an appropriate implementation of 1236b42f491SJason Gunthorpevfio_device_ops. 124baa293e9SMauro Carvalho Chehab 12588a21f26SJason GunthorpeWhen a driver wants to add the GUID creation sysfs to an existing device it has 12688a21f26SJason Gunthorpeprobe'd to then it should call:: 127baa293e9SMauro Carvalho Chehab 12889345d51SChristoph Hellwig int mdev_register_parent(struct mdev_parent *parent, struct device *dev, 1296b42f491SJason Gunthorpe struct mdev_driver *mdev_driver); 130baa293e9SMauro Carvalho Chehab 13188a21f26SJason GunthorpeThis will provide the 'mdev_supported_types/XX/create' files which can then be 13288a21f26SJason Gunthorpeused to trigger the creation of a mdev_device. The created mdev_device will be 13388a21f26SJason Gunthorpeattached to the specified driver. 13488a21f26SJason Gunthorpe 13588a21f26SJason GunthorpeWhen the driver needs to remove itself it calls:: 136baa293e9SMauro Carvalho Chehab 13789345d51SChristoph Hellwig void mdev_unregister_parent(struct mdev_parent *parent); 138baa293e9SMauro Carvalho Chehab 13988a21f26SJason GunthorpeWhich will unbind and destroy all the created mdevs and remove the sysfs files. 140baa293e9SMauro Carvalho Chehab 141baa293e9SMauro Carvalho ChehabMediated Device Management Interface Through sysfs 142baa293e9SMauro Carvalho Chehab================================================== 143baa293e9SMauro Carvalho Chehab 144baa293e9SMauro Carvalho ChehabThe management interface through sysfs enables user space software, such as 145baa293e9SMauro Carvalho Chehablibvirt, to query and configure mediated devices in a hardware-agnostic fashion. 146baa293e9SMauro Carvalho ChehabThis management interface provides flexibility to the underlying physical 147baa293e9SMauro Carvalho Chehabdevice's driver to support features such as: 148baa293e9SMauro Carvalho Chehab 149baa293e9SMauro Carvalho Chehab* Mediated device hot plug 150baa293e9SMauro Carvalho Chehab* Multiple mediated devices in a single virtual machine 151baa293e9SMauro Carvalho Chehab* Multiple mediated devices from different physical devices 152baa293e9SMauro Carvalho Chehab 153baa293e9SMauro Carvalho ChehabLinks in the mdev_bus Class Directory 154baa293e9SMauro Carvalho Chehab------------------------------------- 155baa293e9SMauro Carvalho ChehabThe /sys/class/mdev_bus/ directory contains links to devices that are registered 156baa293e9SMauro Carvalho Chehabwith the mdev core driver. 157baa293e9SMauro Carvalho Chehab 158baa293e9SMauro Carvalho ChehabDirectories and files under the sysfs for Each Physical Device 159baa293e9SMauro Carvalho Chehab-------------------------------------------------------------- 160baa293e9SMauro Carvalho Chehab 161baa293e9SMauro Carvalho Chehab:: 162baa293e9SMauro Carvalho Chehab 163baa293e9SMauro Carvalho Chehab |- [parent physical device] 164baa293e9SMauro Carvalho Chehab |--- Vendor-specific-attributes [optional] 165baa293e9SMauro Carvalho Chehab |--- [mdev_supported_types] 166baa293e9SMauro Carvalho Chehab | |--- [<type-id>] 167baa293e9SMauro Carvalho Chehab | | |--- create 168baa293e9SMauro Carvalho Chehab | | |--- name 169baa293e9SMauro Carvalho Chehab | | |--- available_instances 170baa293e9SMauro Carvalho Chehab | | |--- device_api 171baa293e9SMauro Carvalho Chehab | | |--- description 172baa293e9SMauro Carvalho Chehab | | |--- [devices] 173baa293e9SMauro Carvalho Chehab | |--- [<type-id>] 174baa293e9SMauro Carvalho Chehab | | |--- create 175baa293e9SMauro Carvalho Chehab | | |--- name 176baa293e9SMauro Carvalho Chehab | | |--- available_instances 177baa293e9SMauro Carvalho Chehab | | |--- device_api 178baa293e9SMauro Carvalho Chehab | | |--- description 179baa293e9SMauro Carvalho Chehab | | |--- [devices] 180baa293e9SMauro Carvalho Chehab | |--- [<type-id>] 181baa293e9SMauro Carvalho Chehab | |--- create 182baa293e9SMauro Carvalho Chehab | |--- name 183baa293e9SMauro Carvalho Chehab | |--- available_instances 184baa293e9SMauro Carvalho Chehab | |--- device_api 185baa293e9SMauro Carvalho Chehab | |--- description 186baa293e9SMauro Carvalho Chehab | |--- [devices] 187baa293e9SMauro Carvalho Chehab 188baa293e9SMauro Carvalho Chehab* [mdev_supported_types] 189baa293e9SMauro Carvalho Chehab 190baa293e9SMauro Carvalho Chehab The list of currently supported mediated device types and their details. 191baa293e9SMauro Carvalho Chehab 192baa293e9SMauro Carvalho Chehab [<type-id>], device_api, and available_instances are mandatory attributes 193baa293e9SMauro Carvalho Chehab that should be provided by vendor driver. 194baa293e9SMauro Carvalho Chehab 195baa293e9SMauro Carvalho Chehab* [<type-id>] 196baa293e9SMauro Carvalho Chehab 197baa293e9SMauro Carvalho Chehab The [<type-id>] name is created by adding the device driver string as a prefix 198baa293e9SMauro Carvalho Chehab to the string provided by the vendor driver. This format of this name is as 199baa293e9SMauro Carvalho Chehab follows:: 200baa293e9SMauro Carvalho Chehab 201baa293e9SMauro Carvalho Chehab sprintf(buf, "%s-%s", dev_driver_string(parent->dev), group->name); 202baa293e9SMauro Carvalho Chehab 203baa293e9SMauro Carvalho Chehab* device_api 204baa293e9SMauro Carvalho Chehab 205290aac5dSJason Gunthorpe This attribute shows which device API is being created, for example, 206baa293e9SMauro Carvalho Chehab "vfio-pci" for a PCI device. 207baa293e9SMauro Carvalho Chehab 208baa293e9SMauro Carvalho Chehab* available_instances 209baa293e9SMauro Carvalho Chehab 210baa293e9SMauro Carvalho Chehab This attribute should show the number of devices of type <type-id> that can be 211baa293e9SMauro Carvalho Chehab created. 212baa293e9SMauro Carvalho Chehab 213baa293e9SMauro Carvalho Chehab* [device] 214baa293e9SMauro Carvalho Chehab 215baa293e9SMauro Carvalho Chehab This directory contains links to the devices of type <type-id> that have been 216baa293e9SMauro Carvalho Chehab created. 217baa293e9SMauro Carvalho Chehab 218baa293e9SMauro Carvalho Chehab* name 219baa293e9SMauro Carvalho Chehab 220*0bc79069SChristoph Hellwig This attribute shows a human readable name. 221baa293e9SMauro Carvalho Chehab 222baa293e9SMauro Carvalho Chehab* description 223baa293e9SMauro Carvalho Chehab 224baa293e9SMauro Carvalho Chehab This attribute should show brief features/description of the type. This is 225baa293e9SMauro Carvalho Chehab optional attribute. 226baa293e9SMauro Carvalho Chehab 227baa293e9SMauro Carvalho ChehabDirectories and Files Under the sysfs for Each mdev Device 228baa293e9SMauro Carvalho Chehab---------------------------------------------------------- 229baa293e9SMauro Carvalho Chehab 230baa293e9SMauro Carvalho Chehab:: 231baa293e9SMauro Carvalho Chehab 232baa293e9SMauro Carvalho Chehab |- [parent phy device] 233baa293e9SMauro Carvalho Chehab |--- [$MDEV_UUID] 234baa293e9SMauro Carvalho Chehab |--- remove 235baa293e9SMauro Carvalho Chehab |--- mdev_type {link to its type} 236baa293e9SMauro Carvalho Chehab |--- vendor-specific-attributes [optional] 237baa293e9SMauro Carvalho Chehab 238baa293e9SMauro Carvalho Chehab* remove (write only) 239baa293e9SMauro Carvalho Chehab 240baa293e9SMauro Carvalho ChehabWriting '1' to the 'remove' file destroys the mdev device. The vendor driver can 241baa293e9SMauro Carvalho Chehabfail the remove() callback if that device is active and the vendor driver 242baa293e9SMauro Carvalho Chehabdoesn't support hot unplug. 243baa293e9SMauro Carvalho Chehab 244baa293e9SMauro Carvalho ChehabExample:: 245baa293e9SMauro Carvalho Chehab 246baa293e9SMauro Carvalho Chehab # echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove 247baa293e9SMauro Carvalho Chehab 248baa293e9SMauro Carvalho ChehabMediated device Hot plug 249baa293e9SMauro Carvalho Chehab------------------------ 250baa293e9SMauro Carvalho Chehab 251baa293e9SMauro Carvalho ChehabMediated devices can be created and assigned at runtime. The procedure to hot 252baa293e9SMauro Carvalho Chehabplug a mediated device is the same as the procedure to hot plug a PCI device. 253baa293e9SMauro Carvalho Chehab 254baa293e9SMauro Carvalho ChehabTranslation APIs for Mediated Devices 255baa293e9SMauro Carvalho Chehab===================================== 256baa293e9SMauro Carvalho Chehab 257baa293e9SMauro Carvalho ChehabThe following APIs are provided for translating user pfn to host pfn in a VFIO 258baa293e9SMauro Carvalho Chehabdriver:: 259baa293e9SMauro Carvalho Chehab 26044abdd16SNicolin Chen int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, 26134a255e6SNicolin Chen int npage, int prot, struct page **pages); 262baa293e9SMauro Carvalho Chehab 26344abdd16SNicolin Chen void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, 264baa293e9SMauro Carvalho Chehab int npage); 265baa293e9SMauro Carvalho Chehab 266baa293e9SMauro Carvalho ChehabThese functions call back into the back-end IOMMU module by using the pin_pages 267baa293e9SMauro Carvalho Chehaband unpin_pages callbacks of the struct vfio_iommu_driver_ops[4]. Currently 268baa293e9SMauro Carvalho Chehabthese callbacks are supported in the TYPE1 IOMMU module. To enable them for 269baa293e9SMauro Carvalho Chehabother IOMMU backend modules, such as PPC64 sPAPR module, they need to provide 270baa293e9SMauro Carvalho Chehabthese two callback functions. 271baa293e9SMauro Carvalho Chehab 272baa293e9SMauro Carvalho ChehabUsing the Sample Code 273baa293e9SMauro Carvalho Chehab===================== 274baa293e9SMauro Carvalho Chehab 275baa293e9SMauro Carvalho Chehabmtty.c in samples/vfio-mdev/ directory is a sample driver program to 276baa293e9SMauro Carvalho Chehabdemonstrate how to use the mediated device framework. 277baa293e9SMauro Carvalho Chehab 278baa293e9SMauro Carvalho ChehabThe sample driver creates an mdev device that simulates a serial port over a PCI 279baa293e9SMauro Carvalho Chehabcard. 280baa293e9SMauro Carvalho Chehab 281baa293e9SMauro Carvalho Chehab1. Build and load the mtty.ko module. 282baa293e9SMauro Carvalho Chehab 283baa293e9SMauro Carvalho Chehab This step creates a dummy device, /sys/devices/virtual/mtty/mtty/ 284baa293e9SMauro Carvalho Chehab 285baa293e9SMauro Carvalho Chehab Files in this device directory in sysfs are similar to the following:: 286baa293e9SMauro Carvalho Chehab 287baa293e9SMauro Carvalho Chehab # tree /sys/devices/virtual/mtty/mtty/ 288baa293e9SMauro Carvalho Chehab /sys/devices/virtual/mtty/mtty/ 289baa293e9SMauro Carvalho Chehab |-- mdev_supported_types 290baa293e9SMauro Carvalho Chehab | |-- mtty-1 291baa293e9SMauro Carvalho Chehab | | |-- available_instances 292baa293e9SMauro Carvalho Chehab | | |-- create 293baa293e9SMauro Carvalho Chehab | | |-- device_api 294baa293e9SMauro Carvalho Chehab | | |-- devices 295baa293e9SMauro Carvalho Chehab | | `-- name 296baa293e9SMauro Carvalho Chehab | `-- mtty-2 297baa293e9SMauro Carvalho Chehab | |-- available_instances 298baa293e9SMauro Carvalho Chehab | |-- create 299baa293e9SMauro Carvalho Chehab | |-- device_api 300baa293e9SMauro Carvalho Chehab | |-- devices 301baa293e9SMauro Carvalho Chehab | `-- name 302baa293e9SMauro Carvalho Chehab |-- mtty_dev 303baa293e9SMauro Carvalho Chehab | `-- sample_mtty_dev 304baa293e9SMauro Carvalho Chehab |-- power 305baa293e9SMauro Carvalho Chehab | |-- autosuspend_delay_ms 306baa293e9SMauro Carvalho Chehab | |-- control 307baa293e9SMauro Carvalho Chehab | |-- runtime_active_time 308baa293e9SMauro Carvalho Chehab | |-- runtime_status 309baa293e9SMauro Carvalho Chehab | `-- runtime_suspended_time 310baa293e9SMauro Carvalho Chehab |-- subsystem -> ../../../../class/mtty 311baa293e9SMauro Carvalho Chehab `-- uevent 312baa293e9SMauro Carvalho Chehab 313baa293e9SMauro Carvalho Chehab2. Create a mediated device by using the dummy device that you created in the 314baa293e9SMauro Carvalho Chehab previous step:: 315baa293e9SMauro Carvalho Chehab 316baa293e9SMauro Carvalho Chehab # echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001" > \ 317baa293e9SMauro Carvalho Chehab /sys/devices/virtual/mtty/mtty/mdev_supported_types/mtty-2/create 318baa293e9SMauro Carvalho Chehab 319baa293e9SMauro Carvalho Chehab3. Add parameters to qemu-kvm:: 320baa293e9SMauro Carvalho Chehab 321baa293e9SMauro Carvalho Chehab -device vfio-pci,\ 322baa293e9SMauro Carvalho Chehab sysfsdev=/sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001 323baa293e9SMauro Carvalho Chehab 324baa293e9SMauro Carvalho Chehab4. Boot the VM. 325baa293e9SMauro Carvalho Chehab 326baa293e9SMauro Carvalho Chehab In the Linux guest VM, with no hardware on the host, the device appears 327baa293e9SMauro Carvalho Chehab as follows:: 328baa293e9SMauro Carvalho Chehab 329baa293e9SMauro Carvalho Chehab # lspci -s 00:05.0 -xxvv 330baa293e9SMauro Carvalho Chehab 00:05.0 Serial controller: Device 4348:3253 (rev 10) (prog-if 02 [16550]) 331baa293e9SMauro Carvalho Chehab Subsystem: Device 4348:3253 332baa293e9SMauro Carvalho Chehab Physical Slot: 5 333baa293e9SMauro Carvalho Chehab Control: I/O+ Mem- BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- 334baa293e9SMauro Carvalho Chehab Stepping- SERR- FastB2B- DisINTx- 335baa293e9SMauro Carvalho Chehab Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- 336baa293e9SMauro Carvalho Chehab <TAbort- <MAbort- >SERR- <PERR- INTx- 337baa293e9SMauro Carvalho Chehab Interrupt: pin A routed to IRQ 10 338baa293e9SMauro Carvalho Chehab Region 0: I/O ports at c150 [size=8] 339baa293e9SMauro Carvalho Chehab Region 1: I/O ports at c158 [size=8] 340baa293e9SMauro Carvalho Chehab Kernel driver in use: serial 341baa293e9SMauro Carvalho Chehab 00: 48 43 53 32 01 00 00 02 10 02 00 07 00 00 00 00 342baa293e9SMauro Carvalho Chehab 10: 51 c1 00 00 59 c1 00 00 00 00 00 00 00 00 00 00 343baa293e9SMauro Carvalho Chehab 20: 00 00 00 00 00 00 00 00 00 00 00 00 48 43 53 32 344baa293e9SMauro Carvalho Chehab 30: 00 00 00 00 00 00 00 00 00 00 00 00 0a 01 00 00 345baa293e9SMauro Carvalho Chehab 346baa293e9SMauro Carvalho Chehab In the Linux guest VM, dmesg output for the device is as follows: 347baa293e9SMauro Carvalho Chehab 348baa293e9SMauro Carvalho Chehab serial 0000:00:05.0: PCI INT A -> Link[LNKA] -> GSI 10 (level, high) -> IRQ 10 349baa293e9SMauro Carvalho Chehab 0000:00:05.0: ttyS1 at I/O 0xc150 (irq = 10) is a 16550A 350baa293e9SMauro Carvalho Chehab 0000:00:05.0: ttyS2 at I/O 0xc158 (irq = 10) is a 16550A 351baa293e9SMauro Carvalho Chehab 352baa293e9SMauro Carvalho Chehab 353baa293e9SMauro Carvalho Chehab5. In the Linux guest VM, check the serial ports:: 354baa293e9SMauro Carvalho Chehab 355baa293e9SMauro Carvalho Chehab # setserial -g /dev/ttyS* 356baa293e9SMauro Carvalho Chehab /dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4 357baa293e9SMauro Carvalho Chehab /dev/ttyS1, UART: 16550A, Port: 0xc150, IRQ: 10 358baa293e9SMauro Carvalho Chehab /dev/ttyS2, UART: 16550A, Port: 0xc158, IRQ: 10 359baa293e9SMauro Carvalho Chehab 360baa293e9SMauro Carvalho Chehab6. Using minicom or any terminal emulation program, open port /dev/ttyS1 or 361baa293e9SMauro Carvalho Chehab /dev/ttyS2 with hardware flow control disabled. 362baa293e9SMauro Carvalho Chehab 363baa293e9SMauro Carvalho Chehab7. Type data on the minicom terminal or send data to the terminal emulation 364baa293e9SMauro Carvalho Chehab program and read the data. 365baa293e9SMauro Carvalho Chehab 366baa293e9SMauro Carvalho Chehab Data is loop backed from hosts mtty driver. 367baa293e9SMauro Carvalho Chehab 368baa293e9SMauro Carvalho Chehab8. Destroy the mediated device that you created:: 369baa293e9SMauro Carvalho Chehab 370baa293e9SMauro Carvalho Chehab # echo 1 > /sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001/remove 371baa293e9SMauro Carvalho Chehab 372baa293e9SMauro Carvalho ChehabReferences 373baa293e9SMauro Carvalho Chehab========== 374baa293e9SMauro Carvalho Chehab 375baa293e9SMauro Carvalho Chehab1. See Documentation/driver-api/vfio.rst for more information on VFIO. 376baa293e9SMauro Carvalho Chehab2. struct mdev_driver in include/linux/mdev.h 377baa293e9SMauro Carvalho Chehab3. struct mdev_parent_ops in include/linux/mdev.h 378baa293e9SMauro Carvalho Chehab4. struct vfio_iommu_driver_ops in include/linux/vfio.h 379