qdev-device-use.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. = How to convert to -device & friends =
  2. === Specifying Bus and Address on Bus ===
  3. In qdev, each device has a parent bus. Some devices provide one or
  4. more buses for children. You can specify a device's parent bus with
  5. -device parameter bus.
  6. A device typically has a device address on its parent bus. For buses
  7. where this address can be configured, devices provide a bus-specific
  8. property. Examples:
  9. bus property name value format
  10. PCI addr %x.%x (dev.fn, .fn optional)
  11. I2C address %u
  12. SCSI scsi-id %u
  13. IDE unit %u
  14. HDA cad %u
  15. virtio-serial-bus nr %u
  16. ccid-bus slot %u
  17. USB port %d(.%d)* (port.port...)
  18. Example: device i440FX-pcihost is on the root bus, and provides a PCI
  19. bus named pci.0. To put a FOO device into its slot 4, use -device
  20. FOO,bus=/i440FX-pcihost/pci.0,addr=4. The abbreviated form bus=pci.0
  21. also works as long as the bus name is unique.
  22. === Block Devices ===
  23. A QEMU block device (drive) has a host and a guest part.
  24. In the general case, the guest device is connected to a controller
  25. device. For instance, the IDE controller provides two IDE buses, each
  26. of which can have up to two devices, and each device is a guest part,
  27. and is connected to a host part.
  28. Except we sometimes lump controller, bus(es) and drive device(s) all
  29. together into a single device. For instance, the ISA floppy
  30. controller is connected to up to two host drives.
  31. The old ways to define block devices define host and guest part
  32. together. Sometimes, they can even define a controller device in
  33. addition to the block device.
  34. The new way keeps the parts separate: you create the host part with
  35. -drive, and guest device(s) with -device.
  36. The various old ways to define drives all boil down to the common form
  37. -drive if=TYPE,bus=BUS,unit=UNIT,OPTS...
  38. TYPE, BUS and UNIT identify the controller device, which of its buses
  39. to use, and the drive's address on that bus. Details depend on TYPE.
  40. Instead of bus=BUS,unit=UNIT, you can also say index=IDX.
  41. In the new way, this becomes something like
  42. -drive if=none,id=DRIVE-ID,HOST-OPTS...
  43. -device DEVNAME,drive=DRIVE-ID,DEV-OPTS...
  44. The old OPTS get split into HOST-OPTS and DEV-OPTS as follows:
  45. * file, format, snapshot, cache, aio, readonly, rerror, werror go into
  46. HOST-OPTS.
  47. * cyls, head, secs and trans go into HOST-OPTS. Future work: they
  48. should go into DEV-OPTS instead.
  49. * serial goes into DEV-OPTS, for devices supporting serial numbers.
  50. For other devices, it goes nowhere.
  51. * media is special. In the old way, it selects disk vs. CD-ROM with
  52. if=ide, if=scsi and if=xen. The new way uses DEVNAME for that.
  53. Additionally, readonly=on goes into HOST-OPTS.
  54. * addr is special, see if=virtio below.
  55. The -device argument differs in detail for each type of drive:
  56. * if=ide
  57. -device DEVNAME,drive=DRIVE-ID,bus=IDE-BUS,unit=UNIT
  58. where DEVNAME is either ide-hd or ide-cd, IDE-BUS identifies an IDE
  59. bus, normally either ide.0 or ide.1, and UNIT is either 0 or 1.
  60. * if=scsi
  61. The old way implicitly creates SCSI controllers as needed. The new
  62. way makes that explicit:
  63. -device lsi53c895a,id=ID
  64. As for all PCI devices, you can add bus=PCI-BUS,addr=DEVFN to
  65. control the PCI device address.
  66. This SCSI controller provides a single SCSI bus, named ID.0. Put a
  67. disk on it:
  68. -device DEVNAME,drive=DRIVE-ID,bus=ID.0,scsi-id=UNIT
  69. where DEVNAME is either scsi-hd, scsi-cd or scsi-generic.
  70. * if=floppy
  71. -device floppy,unit=UNIT,drive=DRIVE-ID
  72. Without any -device floppy,... you get an empty unit 0 and no unit
  73. 1. You can use -nodefaults to suppress the default unit 0, see
  74. "Default Devices".
  75. * if=virtio
  76. -device virtio-blk-pci,drive=DRIVE-ID,class=C,vectors=V,ioeventfd=IOEVENTFD
  77. This lets you control PCI device class and MSI-X vectors.
  78. IOEVENTFD controls whether or not ioeventfd is used for virtqueue
  79. notify. It can be set to on (default) or off.
  80. As for all PCI devices, you can add bus=PCI-BUS,addr=DEVFN to
  81. control the PCI device address. This replaces option addr available
  82. with -drive if=virtio.
  83. * if=pflash, if=mtd, if=sd, if=xen are not yet available with -device
  84. For USB storage devices, you can use something like:
  85. -device usb-storage,drive=DRIVE-ID,removable=RMB
  86. The removable parameter gives control over the SCSI INQUIRY removable
  87. (RMB) bit. USB thumbdrives usually set removable=on, while USB hard
  88. disks set removable=off.
  89. Bug: usb-storage pretends to be a block device, but it's really a SCSI
  90. controller that can serve only a single device, which it creates
  91. automatically. The automatic creation guesses what kind of guest part
  92. to create from the host part, like -drive if=scsi. Host and guest
  93. part are not cleanly separated.
  94. === Character Devices ===
  95. A QEMU character device has a host and a guest part.
  96. The old ways to define character devices define host and guest part
  97. together.
  98. The new way keeps the parts separate: you create the host part with
  99. -chardev, and the guest device with -device.
  100. The various old ways to define a character device are all of the
  101. general form
  102. -FOO FOO-OPTS...,LEGACY-CHARDEV
  103. where FOO-OPTS... is specific to -FOO, and the host part
  104. LEGACY-CHARDEV is the same everywhere.
  105. In the new way, this becomes
  106. -chardev HOST-OPTS...,id=CHR-ID
  107. -device DEVNAME,chardev=CHR-ID,DEV-OPTS...
  108. The appropriate DEVNAME depends on the machine type. For type "pc":
  109. * -serial becomes -device isa-serial,iobase=IOADDR,irq=IRQ,index=IDX
  110. This lets you control I/O ports and IRQs.
  111. * -parallel becomes -device isa-parallel,iobase=IOADDR,irq=IRQ,index=IDX
  112. This lets you control I/O ports and IRQs.
  113. * -usbdevice braille doesn't support LEGACY-CHARDEV syntax. It always
  114. uses "braille". With -device, this useful default is gone, so you
  115. have to use something like
  116. -device usb-braille,chardev=braille -chardev braille,id=braille
  117. LEGACY-CHARDEV translates to -chardev HOST-OPTS... as follows:
  118. * null becomes -chardev null
  119. * pty, msmouse, wctablet, braille, stdio likewise
  120. * vc:WIDTHxHEIGHT becomes -chardev vc,width=WIDTH,height=HEIGHT
  121. * vc:<COLS>Cx<ROWS>C becomes -chardev vc,cols=<COLS>,rows=<ROWS>
  122. * con: becomes -chardev console
  123. * COM<NUM> becomes -chardev serial,path=COM<NUM>
  124. * file:FNAME becomes -chardev file,path=FNAME
  125. * pipe:FNAME becomes -chardev pipe,path=FNAME
  126. * tcp:HOST:PORT,OPTS... becomes -chardev socket,host=HOST,port=PORT,OPTS...
  127. * telnet:HOST:PORT,OPTS... becomes
  128. -chardev socket,host=HOST,port=PORT,OPTS...,telnet=on
  129. * udp:HOST:PORT@LOCALADDR:LOCALPORT becomes
  130. -chardev udp,host=HOST,port=PORT,localaddr=LOCALADDR,localport=LOCALPORT
  131. * unix:FNAME becomes -chardev socket,path=FNAME
  132. * /dev/parportN becomes -chardev parport,file=/dev/parportN
  133. * /dev/ppiN likewise
  134. * Any other /dev/FNAME becomes -chardev tty,path=/dev/FNAME
  135. * mon:LEGACY-CHARDEV is special: it multiplexes the monitor onto the
  136. character device defined by LEGACY-CHARDEV. -chardev provides more
  137. general multiplexing instead: you can connect up to four users to a
  138. single host part. You need to pass mux=on to -chardev to enable
  139. switching the input focus.
  140. QEMU uses LEGACY-CHARDEV syntax not just to set up guest devices, but
  141. also in various other places such as -monitor or -net
  142. user,guestfwd=... You can use chardev:CHR-ID in place of
  143. LEGACY-CHARDEV to refer to a host part defined with -chardev.
  144. === Network Devices ===
  145. Host and guest part of network devices have always been separate.
  146. The old way to define the guest part looks like this:
  147. -net nic,netdev=NET-ID,macaddr=MACADDR,model=MODEL,name=ID,addr=STR,vectors=V
  148. The new way is -device:
  149. -device DEVNAME,netdev=NET-ID,mac=MACADDR,DEV-OPTS...
  150. DEVNAME equals MODEL, except for virtio you have to name the virtio
  151. device appropriate for the bus (virtio-net-pci for PCI), and for USB
  152. you have to use usb-net.
  153. The old name=ID parameter becomes the usual id=ID with -device.
  154. For PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control the PCI
  155. device address, as usual. The old -net nic provides parameter addr
  156. for that, which is silently ignored when the NIC is not a PCI device.
  157. For virtio-net-pci, you can control whether or not ioeventfd is used for
  158. virtqueue notify by setting ioeventfd= to on or off (default).
  159. -net nic accepts vectors=V for all models, but it's silently ignored
  160. except for virtio-net-pci (model=virtio). With -device, only devices
  161. that support it accept it.
  162. Not all devices are available with -device at this time. All PCI
  163. devices and ne2k_isa are.
  164. Some PCI devices aren't available with -net nic, e.g. i82558a.
  165. === Graphics Devices ===
  166. Host and guest part of graphics devices have always been separate.
  167. The old way to define the guest graphics device is -vga VGA. Not all
  168. machines support all -vga options.
  169. The new way is -device. The mapping from -vga argument to -device
  170. depends on the machine type. For machine "pc", it's:
  171. std -device VGA
  172. cirrus -device cirrus-vga
  173. vmware -device vmware-svga
  174. qxl -device qxl-vga
  175. none -nodefaults
  176. disables more than just VGA, see "Default Devices"
  177. As for all PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control
  178. the PCI device address.
  179. -device VGA supports properties bios-offset and bios-size, but they
  180. aren't used with machine type "pc".
  181. For machine "isapc", it's
  182. std -device isa-vga
  183. cirrus not yet available with -device
  184. none -nodefaults
  185. disables more than just VGA, see "Default Devices"
  186. Bug: the new way doesn't work for machine types "pc" and "isapc",
  187. because it violates obscure device initialization ordering
  188. constraints.
  189. === Audio Devices ===
  190. Host and guest part of audio devices have always been separate.
  191. The old way to define guest audio devices is -soundhw C1,...
  192. The new way is to define each guest audio device separately with
  193. -device.
  194. Map from -soundhw sound card name to -device:
  195. ac97 -device AC97
  196. cs4231a -device cs4231a,iobase=IOADDR,irq=IRQ,dma=DMA
  197. es1370 -device ES1370
  198. gus -device gus,iobase=IOADDR,irq=IRQ,dma=DMA,freq=F
  199. hda -device intel-hda,msi=MSI -device hda-duplex
  200. sb16 -device sb16,iobase=IOADDR,irq=IRQ,dma=DMA,dma16=DMA16,version=V
  201. adlib not yet available with -device
  202. pcspk not yet available with -device
  203. For PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control the PCI
  204. device address, as usual.
  205. === USB Devices ===
  206. The old way to define a virtual USB device is -usbdevice DRIVER:OPTS...
  207. The new way is -device DEVNAME,DEV-OPTS... Details depend on DRIVER:
  208. * ccid -device usb-ccid
  209. * keyboard -device usb-kbd
  210. * mouse -device usb-mouse
  211. * tablet -device usb-tablet
  212. * wacom-tablet -device usb-wacom-tablet
  213. * braille See "Character Devices"
  214. === Watchdog Devices ===
  215. Host and guest part of watchdog devices have always been separate.
  216. The old way to define a guest watchdog device is -watchdog DEVNAME.
  217. The new way is -device DEVNAME. For PCI devices, you can add
  218. bus=PCI-BUS,addr=DEVFN to control the PCI device address, as usual.
  219. === Host Device Assignment ===
  220. QEMU supports assigning host PCI devices (qemu-kvm only at this time)
  221. and host USB devices. PCI devices can only be assigned with -device:
  222. -device vfio-pci,host=ADDR,id=ID
  223. To assign a host USB device use:
  224. -device usb-host,hostbus=BUS,hostaddr=ADDR,vendorid=VID,productid=PRID
  225. Omitted options match anything.
  226. === Default Devices ===
  227. QEMU creates a number of devices by default, depending on the machine
  228. type.
  229. -device DEVNAME... and global DEVNAME... suppress default devices for
  230. some DEVNAMEs:
  231. default device suppressing DEVNAMEs
  232. CD-ROM ide-cd, ide-drive, ide-hd, scsi-cd, scsi-hd
  233. floppy floppy, isa-fdc
  234. parallel isa-parallel
  235. serial isa-serial
  236. VGA VGA, cirrus-vga, isa-vga, isa-cirrus-vga,
  237. vmware-svga, qxl-vga, virtio-vga, ati-vga,
  238. vhost-user-vga
  239. The default NIC is connected to a default part created along with it.
  240. It is *not* suppressed by configuring a NIC with -device (you may call
  241. that a bug). -net and -netdev suppress the default NIC.
  242. -nodefaults suppresses all the default devices mentioned above, plus a
  243. few other things such as default SD-Card drive and default monitor.