2
0

qdev-device-use.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. -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::chardev becomes -device usb-serial,chardev=dev.
  121. * -usbdevice braille doesn't support LEGACY-CHARDEV syntax. It always
  122. uses "braille". With -device, this useful default is gone, so you
  123. have to use something like
  124. -device usb-braille,chardev=braille -chardev braille,id=braille
  125. LEGACY-CHARDEV translates to -chardev HOST-OPTS... as follows:
  126. * null becomes -chardev null
  127. * pty, msmouse, wctablet, braille, stdio likewise
  128. * vc:WIDTHxHEIGHT becomes -chardev vc,width=WIDTH,height=HEIGHT
  129. * vc:<COLS>Cx<ROWS>C becomes -chardev vc,cols=<COLS>,rows=<ROWS>
  130. * con: becomes -chardev console
  131. * COM<NUM> becomes -chardev serial,path=COM<NUM>
  132. * file:FNAME becomes -chardev file,path=FNAME
  133. * pipe:FNAME becomes -chardev pipe,path=FNAME
  134. * tcp:HOST:PORT,OPTS... becomes -chardev socket,host=HOST,port=PORT,OPTS...
  135. * telnet:HOST:PORT,OPTS... becomes
  136. -chardev socket,host=HOST,port=PORT,OPTS...,telnet=on
  137. * udp:HOST:PORT@LOCALADDR:LOCALPORT becomes
  138. -chardev udp,host=HOST,port=PORT,localaddr=LOCALADDR,localport=LOCALPORT
  139. * unix:FNAME becomes -chardev socket,path=FNAME
  140. * /dev/parportN becomes -chardev parport,file=/dev/parportN
  141. * /dev/ppiN likewise
  142. * Any other /dev/FNAME becomes -chardev tty,path=/dev/FNAME
  143. * mon:LEGACY-CHARDEV is special: it multiplexes the monitor onto the
  144. character device defined by LEGACY-CHARDEV. -chardev provides more
  145. general multiplexing instead: you can connect up to four users to a
  146. single host part. You need to pass mux=on to -chardev to enable
  147. switching the input focus.
  148. QEMU uses LEGACY-CHARDEV syntax not just to set up guest devices, but
  149. also in various other places such as -monitor or -net
  150. user,guestfwd=... You can use chardev:CHR-ID in place of
  151. LEGACY-CHARDEV to refer to a host part defined with -chardev.
  152. === Network Devices ===
  153. Host and guest part of network devices have always been separate.
  154. The old way to define the guest part looks like this:
  155. -net nic,netdev=NET-ID,macaddr=MACADDR,model=MODEL,name=ID,addr=STR,vectors=V
  156. Except for USB it looks like this:
  157. -usbdevice net:netdev=NET-ID,macaddr=MACADDR,name=ID
  158. The new way is -device:
  159. -device DEVNAME,netdev=NET-ID,mac=MACADDR,DEV-OPTS...
  160. DEVNAME equals MODEL, except for virtio you have to name the virtio
  161. device appropriate for the bus (virtio-net-pci for PCI), and for USB
  162. you have to use usb-net.
  163. The old name=ID parameter becomes the usual id=ID with -device.
  164. For PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control the PCI
  165. device address, as usual. The old -net nic provides parameter addr
  166. for that, which is silently ignored when the NIC is not a PCI device.
  167. For virtio-net-pci, you can control whether or not ioeventfd is used for
  168. virtqueue notify by setting ioeventfd= to on or off (default).
  169. -net nic accepts vectors=V for all models, but it's silently ignored
  170. except for virtio-net-pci (model=virtio). With -device, only devices
  171. that support it accept it.
  172. Not all devices are available with -device at this time. All PCI
  173. devices and ne2k_isa are.
  174. Some PCI devices aren't available with -net nic, e.g. i82558a.
  175. === Graphics Devices ===
  176. Host and guest part of graphics devices have always been separate.
  177. The old way to define the guest graphics device is -vga VGA. Not all
  178. machines support all -vga options.
  179. The new way is -device. The mapping from -vga argument to -device
  180. depends on the machine type. For machine "pc", it's:
  181. std -device VGA
  182. cirrus -device cirrus-vga
  183. vmware -device vmware-svga
  184. qxl -device qxl-vga
  185. none -nodefaults
  186. disables more than just VGA, see "Default Devices"
  187. As for all PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control
  188. the PCI device address.
  189. -device VGA supports properties bios-offset and bios-size, but they
  190. aren't used with machine type "pc".
  191. For machine "isapc", it's
  192. std -device isa-vga
  193. cirrus not yet available with -device
  194. none -nodefaults
  195. disables more than just VGA, see "Default Devices"
  196. Bug: the new way doesn't work for machine types "pc" and "isapc",
  197. because it violates obscure device initialization ordering
  198. constraints.
  199. === Audio Devices ===
  200. Host and guest part of audio devices have always been separate.
  201. The old way to define guest audio devices is -soundhw C1,...
  202. The new way is to define each guest audio device separately with
  203. -device.
  204. Map from -soundhw sound card name to -device:
  205. ac97 -device AC97
  206. cs4231a -device cs4231a,iobase=IOADDR,irq=IRQ,dma=DMA
  207. es1370 -device ES1370
  208. gus -device gus,iobase=IOADDR,irq=IRQ,dma=DMA,freq=F
  209. hda -device intel-hda,msi=MSI -device hda-duplex
  210. sb16 -device sb16,iobase=IOADDR,irq=IRQ,dma=DMA,dma16=DMA16,version=V
  211. adlib not yet available with -device
  212. pcspk not yet available with -device
  213. For PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control the PCI
  214. device address, as usual.
  215. === USB Devices ===
  216. The old way to define a virtual USB device is -usbdevice DRIVER:OPTS...
  217. The new way is -device DEVNAME,DEV-OPTS... Details depend on DRIVER:
  218. * ccid -device usb-ccid
  219. * keyboard -device usb-kbd
  220. * mouse -device usb-mouse
  221. * tablet -device usb-tablet
  222. * wacom-tablet -device usb-wacom-tablet
  223. * host:... See "Host Device Assignment"
  224. * disk:... See "Block Devices"
  225. * serial:... See "Character Devices"
  226. * braille See "Character Devices"
  227. * net:... See "Network Devices"
  228. * bt:... not yet available with -device
  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 host USB device is
  239. -usbdevice host:auto:BUS.ADDR:VID:PRID
  240. where any of BUS, ADDR, VID, PRID can be the wildcard *.
  241. The new way is
  242. -device usb-host,hostbus=BUS,hostaddr=ADDR,vendorid=VID,productid=PRID
  243. Omitted options match anything, just like the old way's wildcard.
  244. === Default Devices ===
  245. QEMU creates a number of devices by default, depending on the machine
  246. type.
  247. -device DEVNAME... and global DEVNAME... suppress default devices for
  248. some DEVNAMEs:
  249. default device suppressing DEVNAMEs
  250. CD-ROM ide-cd, ide-drive, ide-hd, scsi-cd, scsi-hd
  251. isa-fdc's driveA floppy, isa-fdc
  252. parallel isa-parallel
  253. serial isa-serial
  254. VGA VGA, cirrus-vga, isa-vga, isa-cirrus-vga,
  255. vmware-svga, qxl-vga, virtio-vga
  256. virtioconsole virtio-serial-pci, virtio-serial
  257. The default NIC is connected to a default part created along with it.
  258. It is *not* suppressed by configuring a NIC with -device (you may call
  259. that a bug). -net and -netdev suppress the default NIC.
  260. -nodefaults suppresses all the default devices mentioned above, plus a
  261. few other things such as default SD-Card drive and default monitor.