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 - */ 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 + 12 15 13 16 Virtual Function I/O (VFIO) Mediated devices[1] 14 17 =============================================== ··· 45 42 46 43 The following high-level block diagram shows the main components and interfaces 47 44 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. 45 + devices as examples, as these devices are the first devices to use this module:: 49 46 50 47 +---------------+ 51 48 | | ··· 94 91 ------------------------------------------------ 95 92 96 93 The registration interface for a mediated bus driver provides the following 97 - structure to represent a mediated device's driver: 94 + structure to represent a mediated device's driver:: 98 95 99 96 /* 100 97 * struct mdev_driver [2] - Mediated device's driver ··· 113 110 A mediated bus driver for mdev should use this structure in the function calls 114 111 to register and unregister itself with the core driver: 115 112 116 - * Register: 113 + * Register:: 117 114 118 - extern int mdev_register_driver(struct mdev_driver *drv, 115 + extern int mdev_register_driver(struct mdev_driver *drv, 119 116 struct module *owner); 120 117 121 - * Unregister: 118 + * Unregister:: 122 119 123 - extern void mdev_unregister_driver(struct mdev_driver *drv); 120 + extern void mdev_unregister_driver(struct mdev_driver *drv); 124 121 125 122 The mediated bus driver is responsible for adding mediated devices to the VFIO 126 123 group when devices are bound to the driver and removing mediated devices from ··· 155 152 * mmap: mmap emulation callback 156 153 157 154 A driver should use the mdev_parent_ops structure in the function call to 158 - register itself with the mdev core driver: 155 + register itself with the mdev core driver:: 159 156 160 - extern int mdev_register_device(struct device *dev, 161 - const struct mdev_parent_ops *ops); 157 + extern int mdev_register_device(struct device *dev, 158 + const struct mdev_parent_ops *ops); 162 159 163 160 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: 161 + that a driver should use to unregister itself with the mdev core driver:: 165 162 166 - extern void mdev_unregister_device(struct device *dev); 163 + extern void mdev_unregister_device(struct device *dev); 167 164 168 165 169 166 Mediated Device Management Interface Through sysfs ··· 186 183 Directories and files under the sysfs for Each Physical Device 187 184 -------------------------------------------------------------- 188 185 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] 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] 213 212 214 213 * [mdev_supported_types] 215 214 ··· 224 219 225 220 The [<type-id>] name is created by adding the device driver string as a prefix 226 221 to the string provided by the vendor driver. This format of this name is as 227 - follows: 222 + follows:: 228 223 229 224 sprintf(buf, "%s-%s", dev_driver_string(parent->dev), group->name); 230 225 231 226 (or using mdev_parent_dev(mdev) to arrive at the parent device outside 232 - of the core mdev code) 227 + of the core mdev code) 233 228 234 229 * device_api 235 230 ··· 244 239 * [device] 245 240 246 241 This directory contains links to the devices of type <type-id> that have been 247 - created. 242 + created. 248 243 249 244 * name 250 245 ··· 258 253 Directories and Files Under the sysfs for Each mdev Device 259 254 ---------------------------------------------------------- 260 255 261 - |- [parent phy device] 262 - |--- [$MDEV_UUID] 256 + :: 257 + 258 + |- [parent phy device] 259 + |--- [$MDEV_UUID] 263 260 |--- remove 264 261 |--- mdev_type {link to its type} 265 262 |--- vendor-specific-attributes [optional] 266 263 267 264 * remove (write only) 265 + 268 266 Writing '1' to the 'remove' file destroys the mdev device. The vendor driver can 269 267 fail the remove() callback if that device is active and the vendor driver 270 268 doesn't support hot unplug. 271 269 272 - Example: 270 + Example:: 271 + 273 272 # echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove 274 273 275 - Mediated device Hot plug: 274 + Mediated device Hot plug 276 275 ------------------------ 277 276 278 277 Mediated devices can be created and assigned at runtime. The procedure to hot ··· 286 277 ===================================== 287 278 288 279 The following APIs are provided for translating user pfn to host pfn in a VFIO 289 - driver: 280 + driver:: 290 281 291 - extern int vfio_pin_pages(struct device *dev, unsigned long *user_pfn, 292 - int npage, int prot, unsigned long *phys_pfn); 282 + extern int vfio_pin_pages(struct device *dev, unsigned long *user_pfn, 283 + int npage, int prot, unsigned long *phys_pfn); 293 284 294 - extern int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn, 295 - int npage); 285 + extern int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn, 286 + int npage); 296 287 297 288 These functions call back into the back-end IOMMU module by using the pin_pages 298 289 and unpin_pages callbacks of the struct vfio_iommu_driver_ops[4]. Currently ··· 313 304 314 305 This step creates a dummy device, /sys/devices/virtual/mtty/mtty/ 315 306 316 - Files in this device directory in sysfs are similar to the following: 307 + Files in this device directory in sysfs are similar to the following:: 317 308 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 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 343 334 344 335 2. Create a mediated device by using the dummy device that you created in the 345 - previous step. 336 + previous step:: 346 337 347 - # echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001" > \ 338 + # echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001" > \ 348 339 /sys/devices/virtual/mtty/mtty/mdev_supported_types/mtty-2/create 349 340 350 - 3. Add parameters to qemu-kvm. 341 + 3. Add parameters to qemu-kvm:: 351 342 352 - -device vfio-pci,\ 353 - sysfsdev=/sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001 343 + -device vfio-pci,\ 344 + sysfsdev=/sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001 354 345 355 346 4. Boot the VM. 356 347 357 348 In the Linux guest VM, with no hardware on the host, the device appears 358 - as follows: 349 + as follows:: 359 350 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 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 376 367 377 - In the Linux guest VM, dmesg output for the device is as follows: 368 + In the Linux guest VM, dmesg output for the device is as follows: 378 369 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 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 383 373 384 374 385 - 5. In the Linux guest VM, check the serial ports. 375 + 5. In the Linux guest VM, check the serial ports:: 386 376 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 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 391 381 392 382 6. Using minicom or any terminal emulation program, open port /dev/ttyS1 or 393 383 /dev/ttyS2 with hardware flow control disabled. ··· 396 388 397 389 Data is loop backed from hosts mtty driver. 398 390 399 - 8. Destroy the mediated device that you created. 391 + 8. Destroy the mediated device that you created:: 400 392 401 - # echo 1 > /sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001/remove 393 + # echo 1 > /sys/bus/mdev/devices/83b8f4f2-509f-382f-3c1e-e6bfe0fa1001/remove 402 394 403 395 References 404 396 ========== 405 397 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 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