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