qdev-device-use.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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 devices, the old way was actually different:
  85. -usbdevice disk:format=FMT:FILENAME
  86. "Was" because "disk:" is gone since v2.12.0.
  87. The old way provided much less control than -drive's OPTS... The new
  88. way fixes that:
  89. -device usb-storage,drive=DRIVE-ID,removable=RMB
  90. The removable parameter gives control over the SCSI INQUIRY removable
  91. (RMB) bit. USB thumbdrives usually set removable=on, while USB hard
  92. disks set removable=off.
  93. Bug: usb-storage pretends to be a block device, but it's really a SCSI
  94. controller that can serve only a single device, which it creates
  95. automatically. The automatic creation guesses what kind of guest part
  96. to create from the host part, like -drive if=scsi. Host and guest
  97. part are not cleanly separated.
  98. === Character Devices ===
  99. A QEMU character device has a host and a guest part.
  100. The old ways to define character devices define host and guest part
  101. together.
  102. The new way keeps the parts separate: you create the host part with
  103. -chardev, and the guest device with -device.
  104. The various old ways to define a character device are all of the
  105. general form
  106. -FOO FOO-OPTS...,LEGACY-CHARDEV
  107. where FOO-OPTS... is specific to -FOO, and the host part
  108. LEGACY-CHARDEV is the same everywhere.
  109. In the new way, this becomes
  110. -chardev HOST-OPTS...,id=CHR-ID
  111. -device DEVNAME,chardev=CHR-ID,DEV-OPTS...
  112. The appropriate DEVNAME depends on the machine type. For type "pc":
  113. * -serial becomes -device isa-serial,iobase=IOADDR,irq=IRQ,index=IDX
  114. This lets you control I/O ports and IRQs.
  115. * -parallel becomes -device isa-parallel,iobase=IOADDR,irq=IRQ,index=IDX
  116. This lets you control I/O ports and IRQs.
  117. * -usbdevice braille doesn't support LEGACY-CHARDEV syntax. It always
  118. uses "braille". With -device, this useful default is gone, so you
  119. have to use something like
  120. -device usb-braille,chardev=braille -chardev braille,id=braille
  121. * -usbdevice serial::chardev is gone since v2.12.0. It became
  122. -device usb-serial,chardev=dev.
  123. LEGACY-CHARDEV translates to -chardev HOST-OPTS... as follows:
  124. * null becomes -chardev null
  125. * pty, msmouse, wctablet, braille, stdio likewise
  126. * vc:WIDTHxHEIGHT becomes -chardev vc,width=WIDTH,height=HEIGHT
  127. * vc:<COLS>Cx<ROWS>C becomes -chardev vc,cols=<COLS>,rows=<ROWS>
  128. * con: becomes -chardev console
  129. * COM<NUM> becomes -chardev serial,path=COM<NUM>
  130. * file:FNAME becomes -chardev file,path=FNAME
  131. * pipe:FNAME becomes -chardev pipe,path=FNAME
  132. * tcp:HOST:PORT,OPTS... becomes -chardev socket,host=HOST,port=PORT,OPTS...
  133. * telnet:HOST:PORT,OPTS... becomes
  134. -chardev socket,host=HOST,port=PORT,OPTS...,telnet=on
  135. * udp:HOST:PORT@LOCALADDR:LOCALPORT becomes
  136. -chardev udp,host=HOST,port=PORT,localaddr=LOCALADDR,localport=LOCALPORT
  137. * unix:FNAME becomes -chardev socket,path=FNAME
  138. * /dev/parportN becomes -chardev parallel,file=/dev/parportN
  139. * /dev/ppiN likewise
  140. * Any other /dev/FNAME becomes -chardev serial,path=/dev/FNAME
  141. * mon:LEGACY-CHARDEV is special: it multiplexes the monitor onto the
  142. character device defined by LEGACY-CHARDEV. -chardev provides more
  143. general multiplexing instead: you can connect up to four users to a
  144. single host part. You need to pass mux=on to -chardev to enable
  145. switching the input focus.
  146. QEMU uses LEGACY-CHARDEV syntax not just to set up guest devices, but
  147. also in various other places such as -monitor or -net
  148. user,guestfwd=... You can use chardev:CHR-ID in place of
  149. LEGACY-CHARDEV to refer to a host part defined with -chardev.
  150. === Network Devices ===
  151. Host and guest part of network devices have always been separate.
  152. The old way to define the guest part looks like this:
  153. -net nic,netdev=NET-ID,macaddr=MACADDR,model=MODEL,name=ID,addr=STR,vectors=V
  154. Except for USB it looked like this:
  155. -usbdevice net:netdev=NET-ID,macaddr=MACADDR,name=ID
  156. "Looked" because "net:" is gone since v2.12.0.
  157. The new way is -device:
  158. -device DEVNAME,netdev=NET-ID,mac=MACADDR,DEV-OPTS...
  159. DEVNAME equals MODEL, except for virtio you have to name the virtio
  160. device appropriate for the bus (virtio-net-pci for PCI), and for USB
  161. you have to use usb-net.
  162. The old name=ID parameter becomes the usual id=ID with -device.
  163. For PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control the PCI
  164. device address, as usual. The old -net nic provides parameter addr
  165. for that, which is silently ignored when the NIC is not a PCI device.
  166. For virtio-net-pci, you can control whether or not ioeventfd is used for
  167. virtqueue notify by setting ioeventfd= to on or off (default).
  168. -net nic accepts vectors=V for all models, but it's silently ignored
  169. except for virtio-net-pci (model=virtio). With -device, only devices
  170. that support it accept it.
  171. Not all devices are available with -device at this time. All PCI
  172. devices and ne2k_isa are.
  173. Some PCI devices aren't available with -net nic, e.g. i82558a.
  174. === Graphics Devices ===
  175. Host and guest part of graphics devices have always been separate.
  176. The old way to define the guest graphics device is -vga VGA. Not all
  177. machines support all -vga options.
  178. The new way is -device. The mapping from -vga argument to -device
  179. depends on the machine type. For machine "pc", it's:
  180. std -device VGA
  181. cirrus -device cirrus-vga
  182. vmware -device vmware-svga
  183. qxl -device qxl-vga
  184. none -nodefaults
  185. disables more than just VGA, see "Default Devices"
  186. As for all PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control
  187. the PCI device address.
  188. -device VGA supports properties bios-offset and bios-size, but they
  189. aren't used with machine type "pc".
  190. For machine "isapc", it's
  191. std -device isa-vga
  192. cirrus not yet available with -device
  193. none -nodefaults
  194. disables more than just VGA, see "Default Devices"
  195. Bug: the new way doesn't work for machine types "pc" and "isapc",
  196. because it violates obscure device initialization ordering
  197. constraints.
  198. === Audio Devices ===
  199. Host and guest part of audio devices have always been separate.
  200. The old way to define guest audio devices is -soundhw C1,...
  201. The new way is to define each guest audio device separately with
  202. -device.
  203. Map from -soundhw sound card name to -device:
  204. ac97 -device AC97
  205. cs4231a -device cs4231a,iobase=IOADDR,irq=IRQ,dma=DMA
  206. es1370 -device ES1370
  207. gus -device gus,iobase=IOADDR,irq=IRQ,dma=DMA,freq=F
  208. hda -device intel-hda,msi=MSI -device hda-duplex
  209. sb16 -device sb16,iobase=IOADDR,irq=IRQ,dma=DMA,dma16=DMA16,version=V
  210. adlib not yet available with -device
  211. pcspk not yet available with -device
  212. For PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control the PCI
  213. device address, as usual.
  214. === USB Devices ===
  215. The old way to define a virtual USB device is -usbdevice DRIVER:OPTS...
  216. The new way is -device DEVNAME,DEV-OPTS... Details depend on DRIVER:
  217. * ccid -device usb-ccid
  218. * keyboard -device usb-kbd
  219. * mouse -device usb-mouse
  220. * tablet -device usb-tablet
  221. * wacom-tablet -device usb-wacom-tablet
  222. * u2f -device u2f-{emulated,passthru}
  223. * braille See "Character Devices"
  224. Until v2.12.0, we additionally had
  225. * host:... See "Host Device Assignment"
  226. * disk:... See "Block Devices"
  227. * serial:... See "Character Devices"
  228. * net:... See "Network Devices"
  229. === Watchdog Devices ===
  230. Host and guest part of watchdog devices have always been separate.
  231. The old way to define a guest watchdog device is -watchdog DEVNAME.
  232. The new way is -device DEVNAME. For PCI devices, you can add
  233. bus=PCI-BUS,addr=DEVFN to control the PCI device address, as usual.
  234. === Host Device Assignment ===
  235. QEMU supports assigning host PCI devices (qemu-kvm only at this time)
  236. and host USB devices. PCI devices can only be assigned with -device:
  237. -device vfio-pci,host=ADDR,id=ID
  238. The old way to assign a USB host device
  239. -usbdevice host:auto:BUS.ADDR:VID:PRID
  240. was removed in v2.12.0. Any of BUS, ADDR, VID, PRID could be the
  241. wildcard *.
  242. The new way is
  243. -device usb-host,hostbus=BUS,hostaddr=ADDR,vendorid=VID,productid=PRID
  244. Omitted options match anything.
  245. === Default Devices ===
  246. QEMU creates a number of devices by default, depending on the machine
  247. type.
  248. -device DEVNAME... and global DEVNAME... suppress default devices for
  249. some DEVNAMEs:
  250. default device suppressing DEVNAMEs
  251. CD-ROM ide-cd, ide-hd, scsi-cd, scsi-hd
  252. floppy floppy, isa-fdc
  253. parallel isa-parallel
  254. serial isa-serial
  255. VGA VGA, cirrus-vga, isa-vga, isa-cirrus-vga,
  256. vmware-svga, qxl-vga, virtio-vga, ati-vga,
  257. vhost-user-vga
  258. The default NIC is connected to a default part created along with it.
  259. It is *not* suppressed by configuring a NIC with -device (you may call
  260. that a bug). -net and -netdev suppress the default NIC.
  261. -nodefaults suppresses all the default devices mentioned above, plus a
  262. few other things such as default SD-Card drive and default monitor.