qdev-device-use.txt 14 KB

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