vfio-mediated-device.txt: standardize document format

Each text file under Documentation follows a different
format. Some doesn't even have titles!

In this specific document, the title, copyright and authorship
are added as if it were a C file!

Change its representation to follow the adopted standard,
using ReST markups for it to be parseable by Sphinx:
- convert document preambule to the proper format;
- mark literal blocks;
- adjust identation;
- use numbered lists for references.

Reviewed by: Kirti Wankhede <kwankhede@nvidia.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>

authored by Mauro Carvalho Chehab and committed by Jonathan Corbet 2a26ed8e c6ebaf6b

+130 -122
+130 -122
Documentation/vfio-mediated-device.txt
··· 1 - /* 2 - * VFIO Mediated devices 3 - * 4 - * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 5 - * Author: Neo Jia <cjia@nvidia.com> 6 - * Kirti Wankhede <kwankhede@nvidia.com> 7 - * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License version 2 as 10 - * published by the Free Software Foundation. 11 - */ 12 13 Virtual Function I/O (VFIO) Mediated devices[1] 14 =============================================== ··· 45 46 The following high-level block diagram shows the main components and interfaces 47 in the VFIO mediated driver framework. The diagram shows NVIDIA, Intel, and IBM 48 - devices as examples, as these devices are the first devices to use this module. 49 50 +---------------+ 51 | | ··· 94 ------------------------------------------------ 95 96 The registration interface for a mediated bus driver provides the following 97 - structure to represent a mediated device's driver: 98 99 /* 100 * struct mdev_driver [2] - Mediated device's driver ··· 113 A mediated bus driver for mdev should use this structure in the function calls 114 to register and unregister itself with the core driver: 115 116 - * Register: 117 118 - extern int mdev_register_driver(struct mdev_driver *drv, 119 struct module *owner); 120 121 - * Unregister: 122 123 - extern void mdev_unregister_driver(struct mdev_driver *drv); 124 125 The mediated bus driver is responsible for adding mediated devices to the VFIO 126 group when devices are bound to the driver and removing mediated devices from ··· 155 * mmap: mmap emulation callback 156 157 A driver should use the mdev_parent_ops structure in the function call to 158 - register itself with the mdev core driver: 159 160 - extern int mdev_register_device(struct device *dev, 161 - const struct mdev_parent_ops *ops); 162 163 However, the mdev_parent_ops structure is not required in the function call 164 - that a driver should use to unregister itself with the mdev core driver: 165 166 - extern void mdev_unregister_device(struct device *dev); 167 168 169 Mediated Device Management Interface Through sysfs ··· 186 Directories and files under the sysfs for Each Physical Device 187 -------------------------------------------------------------- 188 189 - |- [parent physical device] 190 - |--- Vendor-specific-attributes [optional] 191 - |--- [mdev_supported_types] 192 - | |--- [<type-id>] 193 - | | |--- create 194 - | | |--- name 195 - | | |--- available_instances 196 - | | |--- device_api 197 - | | |--- description 198 - | | |--- [devices] 199 - | |--- [<type-id>] 200 - | | |--- create 201 - | | |--- name 202 - | | |--- available_instances 203 - | | |--- device_api 204 - | | |--- description 205 - | | |--- [devices] 206 - | |--- [<type-id>] 207 - | |--- create 208 - | |--- name 209 - | |--- available_instances 210 - | |--- device_api 211 - | |--- description 212 - | |--- [devices] 213 214 * [mdev_supported_types] 215 ··· 224 225 The [<type-id>] name is created by adding the device driver string as a prefix 226 to the string provided by the vendor driver. This format of this name is as 227 - follows: 228 229 sprintf(buf, "%s-%s", dev_driver_string(parent->dev), group->name); 230 231 (or using mdev_parent_dev(mdev) to arrive at the parent device outside 232 - of the core mdev code) 233 234 * device_api 235 ··· 244 * [device] 245 246 This directory contains links to the devices of type <type-id> that have been 247 - created. 248 249 * name 250 ··· 258 Directories and Files Under the sysfs for Each mdev Device 259 ---------------------------------------------------------- 260 261 - |- [parent phy device] 262 - |--- [$MDEV_UUID] 263 |--- remove 264 |--- mdev_type {link to its type} 265 |--- vendor-specific-attributes [optional] 266 267 * remove (write only) 268 Writing '1' to the 'remove' file destroys the mdev device. The vendor driver can 269 fail the remove() callback if that device is active and the vendor driver 270 doesn't support hot unplug. 271 272 - Example: 273 # echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove 274 275 - Mediated device Hot plug: 276 ------------------------ 277 278 Mediated devices can be created and assigned at runtime. The procedure to hot ··· 286 ===================================== 287 288 The following APIs are provided for translating user pfn to host pfn in a VFIO 289 - driver: 290 291 - extern int vfio_pin_pages(struct device *dev, unsigned long *user_pfn, 292 - int npage, int prot, unsigned long *phys_pfn); 293 294 - extern int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn, 295 - int npage); 296 297 These functions call back into the back-end IOMMU module by using the pin_pages 298 and unpin_pages callbacks of the struct vfio_iommu_driver_ops[4]. Currently ··· 313 314 This step creates a dummy device, /sys/devices/virtual/mtty/mtty/ 315 316 - Files in this device directory in sysfs are similar to the following: 317 318 - # tree /sys/devices/virtual/mtty/mtty/ 319 - /sys/devices/virtual/mtty/mtty/ 320 - |-- mdev_supported_types 321 - | |-- mtty-1 322 - | | |-- available_instances 323 - | | |-- create 324 - | | |-- device_api 325 - | | |-- devices 326 - | | `-- name 327 - | `-- mtty-2 328 - | |-- available_instances 329 - | |-- create 330 - | |-- device_api 331 - | |-- devices 332 - | `-- name 333 - |-- mtty_dev 334 - | `-- sample_mtty_dev 335 - |-- power 336 - | |-- autosuspend_delay_ms 337 - | |-- control 338 - | |-- runtime_active_time 339 - | |-- runtime_status 340 - | `-- runtime_suspended_time 341 - |-- subsystem -> ../../../../class/mtty 342 - `-- uevent 343 344 2. Create a mediated device by using the dummy device that you created in the 345 - previous step. 346 347 - # echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001" > \ 348 /sys/devices/virtual/mtty/mtty/mdev_supported_types/mtty-2/create 349 350 - 3. Add parameters to qemu-kvm. 351 352 - -device vfio-pci,\ 353 - sysfsdev=/sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001 354 355 4. Boot the VM. 356 357 In the Linux guest VM, with no hardware on the host, the device appears 358 - as follows: 359 360 - # lspci -s 00:05.0 -xxvv 361 - 00:05.0 Serial controller: Device 4348:3253 (rev 10) (prog-if 02 [16550]) 362 - Subsystem: Device 4348:3253 363 - Physical Slot: 5 364 - Control: I/O+ Mem- BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- 365 - Stepping- SERR- FastB2B- DisINTx- 366 - Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- 367 - <TAbort- <MAbort- >SERR- <PERR- INTx- 368 - Interrupt: pin A routed to IRQ 10 369 - Region 0: I/O ports at c150 [size=8] 370 - Region 1: I/O ports at c158 [size=8] 371 - Kernel driver in use: serial 372 - 00: 48 43 53 32 01 00 00 02 10 02 00 07 00 00 00 00 373 - 10: 51 c1 00 00 59 c1 00 00 00 00 00 00 00 00 00 00 374 - 20: 00 00 00 00 00 00 00 00 00 00 00 00 48 43 53 32 375 - 30: 00 00 00 00 00 00 00 00 00 00 00 00 0a 01 00 00 376 377 - In the Linux guest VM, dmesg output for the device is as follows: 378 379 - serial 0000:00:05.0: PCI INT A -> Link[LNKA] -> GSI 10 (level, high) -> IRQ 380 - 10 381 - 0000:00:05.0: ttyS1 at I/O 0xc150 (irq = 10) is a 16550A 382 - 0000:00:05.0: ttyS2 at I/O 0xc158 (irq = 10) is a 16550A 383 384 385 - 5. In the Linux guest VM, check the serial ports. 386 387 - # setserial -g /dev/ttyS* 388 - /dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4 389 - /dev/ttyS1, UART: 16550A, Port: 0xc150, IRQ: 10 390 - /dev/ttyS2, UART: 16550A, Port: 0xc158, IRQ: 10 391 392 6. Using minicom or any terminal emulation program, open port /dev/ttyS1 or 393 /dev/ttyS2 with hardware flow control disabled. ··· 396 397 Data is loop backed from hosts mtty driver. 398 399 - 8. Destroy the mediated device that you created. 400 401 - # echo 1 > /sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001/remove 402 403 References 404 ========== 405 406 - [1] See Documentation/vfio.txt for more information on VFIO. 407 - [2] struct mdev_driver in include/linux/mdev.h 408 - [3] struct mdev_parent_ops in include/linux/mdev.h 409 - [4] struct vfio_iommu_driver_ops in include/linux/vfio.h
··· 1 + .. include:: <isonum.txt> 2 + 3 + ===================== 4 + VFIO Mediated devices 5 + ===================== 6 + 7 + :Copyright: |copy| 2016, NVIDIA CORPORATION. All rights reserved. 8 + :Author: Neo Jia <cjia@nvidia.com> 9 + :Author: Kirti Wankhede <kwankhede@nvidia.com> 10 + 11 + This program is free software; you can redistribute it and/or modify 12 + it under the terms of the GNU General Public License version 2 as 13 + published by the Free Software Foundation. 14 + 15 16 Virtual Function I/O (VFIO) Mediated devices[1] 17 =============================================== ··· 42 43 The following high-level block diagram shows the main components and interfaces 44 in the VFIO mediated driver framework. The diagram shows NVIDIA, Intel, and IBM 45 + devices as examples, as these devices are the first devices to use this module:: 46 47 +---------------+ 48 | | ··· 91 ------------------------------------------------ 92 93 The registration interface for a mediated bus driver provides the following 94 + structure to represent a mediated device's driver:: 95 96 /* 97 * struct mdev_driver [2] - Mediated device's driver ··· 110 A mediated bus driver for mdev should use this structure in the function calls 111 to register and unregister itself with the core driver: 112 113 + * Register:: 114 115 + extern int mdev_register_driver(struct mdev_driver *drv, 116 struct module *owner); 117 118 + * Unregister:: 119 120 + extern void mdev_unregister_driver(struct mdev_driver *drv); 121 122 The mediated bus driver is responsible for adding mediated devices to the VFIO 123 group when devices are bound to the driver and removing mediated devices from ··· 152 * mmap: mmap emulation callback 153 154 A driver should use the mdev_parent_ops structure in the function call to 155 + register itself with the mdev core driver:: 156 157 + extern int mdev_register_device(struct device *dev, 158 + const struct mdev_parent_ops *ops); 159 160 However, the mdev_parent_ops structure is not required in the function call 161 + that a driver should use to unregister itself with the mdev core driver:: 162 163 + extern void mdev_unregister_device(struct device *dev); 164 165 166 Mediated Device Management Interface Through sysfs ··· 183 Directories and files under the sysfs for Each Physical Device 184 -------------------------------------------------------------- 185 186 + :: 187 + 188 + |- [parent physical device] 189 + |--- Vendor-specific-attributes [optional] 190 + |--- [mdev_supported_types] 191 + | |--- [<type-id>] 192 + | | |--- create 193 + | | |--- name 194 + | | |--- available_instances 195 + | | |--- device_api 196 + | | |--- description 197 + | | |--- [devices] 198 + | |--- [<type-id>] 199 + | | |--- create 200 + | | |--- name 201 + | | |--- available_instances 202 + | | |--- device_api 203 + | | |--- description 204 + | | |--- [devices] 205 + | |--- [<type-id>] 206 + | |--- create 207 + | |--- name 208 + | |--- available_instances 209 + | |--- device_api 210 + | |--- description 211 + | |--- [devices] 212 213 * [mdev_supported_types] 214 ··· 219 220 The [<type-id>] name is created by adding the device driver string as a prefix 221 to the string provided by the vendor driver. This format of this name is as 222 + follows:: 223 224 sprintf(buf, "%s-%s", dev_driver_string(parent->dev), group->name); 225 226 (or using mdev_parent_dev(mdev) to arrive at the parent device outside 227 + of the core mdev code) 228 229 * device_api 230 ··· 239 * [device] 240 241 This directory contains links to the devices of type <type-id> that have been 242 + created. 243 244 * name 245 ··· 253 Directories and Files Under the sysfs for Each mdev Device 254 ---------------------------------------------------------- 255 256 + :: 257 + 258 + |- [parent phy device] 259 + |--- [$MDEV_UUID] 260 |--- remove 261 |--- mdev_type {link to its type} 262 |--- vendor-specific-attributes [optional] 263 264 * remove (write only) 265 + 266 Writing '1' to the 'remove' file destroys the mdev device. The vendor driver can 267 fail the remove() callback if that device is active and the vendor driver 268 doesn't support hot unplug. 269 270 + Example:: 271 + 272 # echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove 273 274 + Mediated device Hot plug 275 ------------------------ 276 277 Mediated devices can be created and assigned at runtime. The procedure to hot ··· 277 ===================================== 278 279 The following APIs are provided for translating user pfn to host pfn in a VFIO 280 + driver:: 281 282 + extern int vfio_pin_pages(struct device *dev, unsigned long *user_pfn, 283 + int npage, int prot, unsigned long *phys_pfn); 284 285 + extern int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn, 286 + int npage); 287 288 These functions call back into the back-end IOMMU module by using the pin_pages 289 and unpin_pages callbacks of the struct vfio_iommu_driver_ops[4]. Currently ··· 304 305 This step creates a dummy device, /sys/devices/virtual/mtty/mtty/ 306 307 + Files in this device directory in sysfs are similar to the following:: 308 309 + # tree /sys/devices/virtual/mtty/mtty/ 310 + /sys/devices/virtual/mtty/mtty/ 311 + |-- mdev_supported_types 312 + | |-- mtty-1 313 + | | |-- available_instances 314 + | | |-- create 315 + | | |-- device_api 316 + | | |-- devices 317 + | | `-- name 318 + | `-- mtty-2 319 + | |-- available_instances 320 + | |-- create 321 + | |-- device_api 322 + | |-- devices 323 + | `-- name 324 + |-- mtty_dev 325 + | `-- sample_mtty_dev 326 + |-- power 327 + | |-- autosuspend_delay_ms 328 + | |-- control 329 + | |-- runtime_active_time 330 + | |-- runtime_status 331 + | `-- runtime_suspended_time 332 + |-- subsystem -> ../../../../class/mtty 333 + `-- uevent 334 335 2. Create a mediated device by using the dummy device that you created in the 336 + previous step:: 337 338 + # echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001" > \ 339 /sys/devices/virtual/mtty/mtty/mdev_supported_types/mtty-2/create 340 341 + 3. Add parameters to qemu-kvm:: 342 343 + -device vfio-pci,\ 344 + sysfsdev=/sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001 345 346 4. Boot the VM. 347 348 In the Linux guest VM, with no hardware on the host, the device appears 349 + as follows:: 350 351 + # lspci -s 00:05.0 -xxvv 352 + 00:05.0 Serial controller: Device 4348:3253 (rev 10) (prog-if 02 [16550]) 353 + Subsystem: Device 4348:3253 354 + Physical Slot: 5 355 + Control: I/O+ Mem- BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- 356 + Stepping- SERR- FastB2B- DisINTx- 357 + Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- 358 + <TAbort- <MAbort- >SERR- <PERR- INTx- 359 + Interrupt: pin A routed to IRQ 10 360 + Region 0: I/O ports at c150 [size=8] 361 + Region 1: I/O ports at c158 [size=8] 362 + Kernel driver in use: serial 363 + 00: 48 43 53 32 01 00 00 02 10 02 00 07 00 00 00 00 364 + 10: 51 c1 00 00 59 c1 00 00 00 00 00 00 00 00 00 00 365 + 20: 00 00 00 00 00 00 00 00 00 00 00 00 48 43 53 32 366 + 30: 00 00 00 00 00 00 00 00 00 00 00 00 0a 01 00 00 367 368 + In the Linux guest VM, dmesg output for the device is as follows: 369 370 + serial 0000:00:05.0: PCI INT A -> Link[LNKA] -> GSI 10 (level, high) -> IRQ 10 371 + 0000:00:05.0: ttyS1 at I/O 0xc150 (irq = 10) is a 16550A 372 + 0000:00:05.0: ttyS2 at I/O 0xc158 (irq = 10) is a 16550A 373 374 375 + 5. In the Linux guest VM, check the serial ports:: 376 377 + # setserial -g /dev/ttyS* 378 + /dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4 379 + /dev/ttyS1, UART: 16550A, Port: 0xc150, IRQ: 10 380 + /dev/ttyS2, UART: 16550A, Port: 0xc158, IRQ: 10 381 382 6. Using minicom or any terminal emulation program, open port /dev/ttyS1 or 383 /dev/ttyS2 with hardware flow control disabled. ··· 388 389 Data is loop backed from hosts mtty driver. 390 391 + 8. Destroy the mediated device that you created:: 392 393 + # echo 1 > /sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001/remove 394 395 References 396 ========== 397 398 + 1. See Documentation/vfio.txt for more information on VFIO. 399 + 2. struct mdev_driver in include/linux/mdev.h 400 + 3. struct mdev_parent_ops in include/linux/mdev.h 401 + 4. struct vfio_iommu_driver_ops in include/linux/vfio.h