blob: cc53e97dcdaa0d02850f242b6047d6cf32ab9a99 [file] [log] [blame]
Markus Armbruster96560cb2009-12-17 17:19:17 +01001= How to convert to -device & friends =
2
3=== Specifying Bus and Address on Bus ===
4
5In qdev, each device has a parent bus. Some devices provide one or
6more buses for children. You can specify a device's parent bus with
7-device parameter bus.
8
9A device typically has a device address on its parent bus. For buses
10where this address can be configured, devices provide a bus-specific
Markus Armbruster23bf93b2011-06-07 10:34:31 +020011property. Examples:
Markus Armbruster96560cb2009-12-17 17:19:17 +010012
Markus Armbruster23bf93b2011-06-07 10:34:31 +020013 bus property name value format
14 PCI addr %x.%x (dev.fn, .fn optional)
15 I2C address %u
16 SCSI scsi-id %u
17 IDE unit %u
18 HDA cad %u
19 virtio-serial-bus nr %u
20 ccid-bus slot %u
21 USB port %d(.%d)* (port.port...)
Markus Armbruster96560cb2009-12-17 17:19:17 +010022
23Example: device i440FX-pcihost is on the root bus, and provides a PCI
24bus named pci.0. To put a FOO device into its slot 4, use -device
25FOO,bus=/i440FX-pcihost/pci.0,addr=4. The abbreviated form bus=pci.0
26also works as long as the bus name is unique.
27
Markus Armbruster96560cb2009-12-17 17:19:17 +010028=== Block Devices ===
29
30A QEMU block device (drive) has a host and a guest part.
31
32In the general case, the guest device is connected to a controller
33device. For instance, the IDE controller provides two IDE buses, each
Markus Armbruster1c9f3b82017-05-09 11:41:15 +020034of which can have up to two devices, and each device is a guest part,
35and is connected to a host part.
Markus Armbruster96560cb2009-12-17 17:19:17 +010036
37Except we sometimes lump controller, bus(es) and drive device(s) all
38together into a single device. For instance, the ISA floppy
39controller is connected to up to two host drives.
40
41The old ways to define block devices define host and guest part
42together. Sometimes, they can even define a controller device in
43addition to the block device.
44
45The new way keeps the parts separate: you create the host part with
46-drive, and guest device(s) with -device.
47
48The various old ways to define drives all boil down to the common form
49
Markus Armbruster23bf93b2011-06-07 10:34:31 +020050 -drive if=TYPE,bus=BUS,unit=UNIT,OPTS...
Markus Armbruster96560cb2009-12-17 17:19:17 +010051
52TYPE, BUS and UNIT identify the controller device, which of its buses
53to use, and the drive's address on that bus. Details depend on TYPE.
Markus Armbruster23bf93b2011-06-07 10:34:31 +020054
55Instead of bus=BUS,unit=UNIT, you can also say index=IDX.
Markus Armbruster96560cb2009-12-17 17:19:17 +010056
57In the new way, this becomes something like
58
59 -drive if=none,id=DRIVE-ID,HOST-OPTS...
60 -device DEVNAME,drive=DRIVE-ID,DEV-OPTS...
61
Markus Armbruster23bf93b2011-06-07 10:34:31 +020062The old OPTS get split into HOST-OPTS and DEV-OPTS as follows:
63
64* file, format, snapshot, cache, aio, readonly, rerror, werror go into
65 HOST-OPTS.
66
67* cyls, head, secs and trans go into HOST-OPTS. Future work: they
68 should go into DEV-OPTS instead.
69
70* serial goes into DEV-OPTS, for devices supporting serial numbers.
71 For other devices, it goes nowhere.
72
73* media is special. In the old way, it selects disk vs. CD-ROM with
74 if=ide, if=scsi and if=xen. The new way uses DEVNAME for that.
75 Additionally, readonly=on goes into HOST-OPTS.
76
77* addr is special, see if=virtio below.
78
79The -device argument differs in detail for each type of drive:
Markus Armbruster96560cb2009-12-17 17:19:17 +010080
81* if=ide
82
Markus Armbruster23bf93b2011-06-07 10:34:31 +020083 -device DEVNAME,drive=DRIVE-ID,bus=IDE-BUS,unit=UNIT
Markus Armbruster96560cb2009-12-17 17:19:17 +010084
Markus Armbruster23bf93b2011-06-07 10:34:31 +020085 where DEVNAME is either ide-hd or ide-cd, IDE-BUS identifies an IDE
86 bus, normally either ide.0 or ide.1, and UNIT is either 0 or 1.
Markus Armbruster96560cb2009-12-17 17:19:17 +010087
88* if=scsi
89
90 The old way implicitly creates SCSI controllers as needed. The new
91 way makes that explicit:
92
93 -device lsi53c895a,id=ID
94
95 As for all PCI devices, you can add bus=PCI-BUS,addr=DEVFN to
96 control the PCI device address.
97
Markus Armbruster23bf93b2011-06-07 10:34:31 +020098 This SCSI controller provides a single SCSI bus, named ID.0. Put a
99 disk on it:
Markus Armbruster96560cb2009-12-17 17:19:17 +0100100
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200101 -device DEVNAME,drive=DRIVE-ID,bus=ID.0,scsi-id=UNIT
Stefan Hajnoczia5c062e2011-01-24 15:35:01 +0000102
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200103 where DEVNAME is either scsi-hd, scsi-cd or scsi-generic.
Markus Armbruster96560cb2009-12-17 17:19:17 +0100104
105* if=floppy
106
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200107 -global isa-fdc.driveA=DRIVE-ID
108 -global isa-fdc.driveB=DRIVE-ID
Markus Armbruster96560cb2009-12-17 17:19:17 +0100109
110 This is -global instead of -device, because the floppy controller is
111 created automatically, and we want to configure that one, not create
112 a second one (which isn't possible anyway).
113
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200114 Without any -global isa-fdc,... you get an empty driveA and no
115 driveB. You can use -nodefaults to suppress the default driveA, see
116 "Default Devices".
Markus Armbruster96560cb2009-12-17 17:19:17 +0100117
118* if=virtio
119
Stefan Hajnoczi65d6dcb2010-12-17 12:01:52 +0000120 -device virtio-blk-pci,drive=DRIVE-ID,class=C,vectors=V,ioeventfd=IOEVENTFD
Markus Armbruster96560cb2009-12-17 17:19:17 +0100121
122 This lets you control PCI device class and MSI-X vectors.
123
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200124 IOEVENTFD controls whether or not ioeventfd is used for virtqueue
125 notify. It can be set to on (default) or off.
Stefan Hajnoczi65d6dcb2010-12-17 12:01:52 +0000126
Markus Armbruster96560cb2009-12-17 17:19:17 +0100127 As for all PCI devices, you can add bus=PCI-BUS,addr=DEVFN to
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200128 control the PCI device address. This replaces option addr available
129 with -drive if=virtio.
Markus Armbruster96560cb2009-12-17 17:19:17 +0100130
131* if=pflash, if=mtd, if=sd, if=xen are not yet available with -device
132
133For USB devices, the old way is actually different:
134
135 -usbdevice disk:format=FMT:FILENAME
136
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200137Provides much less control than -drive's OPTS... The new way fixes
138that:
Markus Armbruster96560cb2009-12-17 17:19:17 +0100139
Stefan Hajnoczia5c062e2011-01-24 15:35:01 +0000140 -device usb-storage,drive=DRIVE-ID,removable=RMB
141
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200142The removable parameter gives control over the SCSI INQUIRY removable
143(RMB) bit. USB thumbdrives usually set removable=on, while USB hard
144disks set removable=off.
145
146Bug: usb-storage pretends to be a block device, but it's really a SCSI
147controller that can serve only a single device, which it creates
148automatically. The automatic creation guesses what kind of guest part
149to create from the host part, like -drive if=scsi. Host and guest
150part are not cleanly separated.
Markus Armbruster96560cb2009-12-17 17:19:17 +0100151
152=== Character Devices ===
153
154A QEMU character device has a host and a guest part.
155
156The old ways to define character devices define host and guest part
157together.
158
159The new way keeps the parts separate: you create the host part with
160-chardev, and the guest device with -device.
161
162The various old ways to define a character device are all of the
163general form
164
165 -FOO FOO-OPTS...,LEGACY-CHARDEV
166
167where FOO-OPTS... is specific to -FOO, and the host part
168LEGACY-CHARDEV is the same everywhere.
169
170In the new way, this becomes
171
172 -chardev HOST-OPTS...,id=CHR-ID
173 -device DEVNAME,chardev=CHR-ID,DEV-OPTS...
174
175The appropriate DEVNAME depends on the machine type. For type "pc":
176
177* -serial becomes -device isa-serial,iobase=IOADDR,irq=IRQ,index=IDX
178
179 This lets you control I/O ports and IRQs.
180
181* -parallel becomes -device isa-parallel,iobase=IOADDR,irq=IRQ,index=IDX
182
183 This lets you control I/O ports and IRQs.
184
Thomas Hutha92ff8c2017-05-08 17:13:49 +0200185* -usbdevice serial::chardev becomes -device usb-serial,chardev=dev.
Markus Armbruster96560cb2009-12-17 17:19:17 +0100186
187* -usbdevice braille doesn't support LEGACY-CHARDEV syntax. It always
188 uses "braille". With -device, this useful default is gone, so you
189 have to use something like
190
Thomas Hutha92ff8c2017-05-08 17:13:49 +0200191 -device usb-braille,chardev=braille -chardev braille,id=braille
Markus Armbruster96560cb2009-12-17 17:19:17 +0100192
Markus Armbruster96560cb2009-12-17 17:19:17 +0100193LEGACY-CHARDEV translates to -chardev HOST-OPTS... as follows:
194
195* null becomes -chardev null
196
Anatoli Huseu1378af962017-02-06 15:23:27 +0100197* pty, msmouse, wctablet, braille, stdio likewise
Markus Armbruster96560cb2009-12-17 17:19:17 +0100198
199* vc:WIDTHxHEIGHT becomes -chardev vc,width=WIDTH,height=HEIGHT
200
201* vc:<COLS>Cx<ROWS>C becomes -chardev vc,cols=<COLS>,rows=<ROWS>
202
203* con: becomes -chardev console
204
Markus Armbruster6e93a442011-09-06 10:01:36 +0200205* COM<NUM> becomes -chardev serial,path=COM<NUM>
Markus Armbruster96560cb2009-12-17 17:19:17 +0100206
207* file:FNAME becomes -chardev file,path=FNAME
208
209* pipe:FNAME becomes -chardev pipe,path=FNAME
210
211* tcp:HOST:PORT,OPTS... becomes -chardev socket,host=HOST,port=PORT,OPTS...
212
213* telnet:HOST:PORT,OPTS... becomes
214 -chardev socket,host=HOST,port=PORT,OPTS...,telnet=on
215
216* udp:HOST:PORT@LOCALADDR:LOCALPORT becomes
217 -chardev udp,host=HOST,port=PORT,localaddr=LOCALADDR,localport=LOCALPORT
218
219* unix:FNAME becomes -chardev socket,path=FNAME
220
221* /dev/parportN becomes -chardev parport,file=/dev/parportN
222
223* /dev/ppiN likewise
224
225* Any other /dev/FNAME becomes -chardev tty,path=/dev/FNAME
226
227* mon:LEGACY-CHARDEV is special: it multiplexes the monitor onto the
228 character device defined by LEGACY-CHARDEV. -chardev provides more
229 general multiplexing instead: you can connect up to four users to a
230 single host part. You need to pass mux=on to -chardev to enable
231 switching the input focus.
232
233QEMU uses LEGACY-CHARDEV syntax not just to set up guest devices, but
234also in various other places such as -monitor or -net
235user,guestfwd=... You can use chardev:CHR-ID in place of
236LEGACY-CHARDEV to refer to a host part defined with -chardev.
237
238=== Network Devices ===
239
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200240Host and guest part of network devices have always been separate.
Markus Armbruster96560cb2009-12-17 17:19:17 +0100241
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200242The old way to define the guest part looks like this:
Markus Armbruster96560cb2009-12-17 17:19:17 +0100243
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200244 -net nic,netdev=NET-ID,macaddr=MACADDR,model=MODEL,name=ID,addr=STR,vectors=V
Markus Armbruster96560cb2009-12-17 17:19:17 +0100245
246Except for USB it looks like this:
247
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200248 -usbdevice net:netdev=NET-ID,macaddr=MACADDR,name=ID
Markus Armbruster96560cb2009-12-17 17:19:17 +0100249
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200250The new way is -device:
Markus Armbruster96560cb2009-12-17 17:19:17 +0100251
Markus Armbruster96560cb2009-12-17 17:19:17 +0100252 -device DEVNAME,netdev=NET-ID,mac=MACADDR,DEV-OPTS...
253
Markus Armbruster96560cb2009-12-17 17:19:17 +0100254DEVNAME equals MODEL, except for virtio you have to name the virtio
255device appropriate for the bus (virtio-net-pci for PCI), and for USB
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200256you have to use usb-net.
Markus Armbruster96560cb2009-12-17 17:19:17 +0100257
258The old name=ID parameter becomes the usual id=ID with -device.
259
260For PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control the PCI
261device address, as usual. The old -net nic provides parameter addr
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200262for that, which is silently ignored when the NIC is not a PCI device.
Markus Armbruster96560cb2009-12-17 17:19:17 +0100263
Stefan Hajnoczi65d6dcb2010-12-17 12:01:52 +0000264For virtio-net-pci, you can control whether or not ioeventfd is used for
265virtqueue notify by setting ioeventfd= to on or off (default).
266
Markus Armbruster96560cb2009-12-17 17:19:17 +0100267-net nic accepts vectors=V for all models, but it's silently ignored
268except for virtio-net-pci (model=virtio). With -device, only devices
269that support it accept it.
270
271Not all devices are available with -device at this time. All PCI
272devices and ne2k_isa are.
273
274Some PCI devices aren't available with -net nic, e.g. i82558a.
275
Markus Armbruster96560cb2009-12-17 17:19:17 +0100276=== Graphics Devices ===
277
278Host and guest part of graphics devices have always been separate.
279
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200280The old way to define the guest graphics device is -vga VGA. Not all
281machines support all -vga options.
Markus Armbruster96560cb2009-12-17 17:19:17 +0100282
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200283The new way is -device. The mapping from -vga argument to -device
284depends on the machine type. For machine "pc", it's:
Markus Armbruster96560cb2009-12-17 17:19:17 +0100285
286 std -device VGA
287 cirrus -device cirrus-vga
288 vmware -device vmware-svga
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200289 qxl -device qxl-vga
290 none -nodefaults
291 disables more than just VGA, see "Default Devices"
Markus Armbruster96560cb2009-12-17 17:19:17 +0100292
293As for all PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control
294the PCI device address.
295
296-device VGA supports properties bios-offset and bios-size, but they
297aren't used with machine type "pc".
298
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200299For machine "isapc", it's
Markus Armbruster96560cb2009-12-17 17:19:17 +0100300
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200301 std -device isa-vga
302 cirrus not yet available with -device
303 none -nodefaults
304 disables more than just VGA, see "Default Devices"
Markus Armbruster96560cb2009-12-17 17:19:17 +0100305
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200306Bug: the new way doesn't work for machine types "pc" and "isapc",
307because it violates obscure device initialization ordering
308constraints.
Markus Armbruster96560cb2009-12-17 17:19:17 +0100309
310=== Audio Devices ===
311
312Host and guest part of audio devices have always been separate.
313
314The old way to define guest audio devices is -soundhw C1,...
315
316The new way is to define each guest audio device separately with
317-device.
318
319Map from -soundhw sound card name to -device:
320
321 ac97 -device AC97
322 cs4231a -device cs4231a,iobase=IOADDR,irq=IRQ,dma=DMA
323 es1370 -device ES1370
324 gus -device gus,iobase=IOADDR,irq=IRQ,dma=DMA,freq=F
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200325 hda -device intel-hda,msi=MSI -device hda-duplex
Markus Armbruster96560cb2009-12-17 17:19:17 +0100326 sb16 -device sb16,iobase=IOADDR,irq=IRQ,dma=DMA,dma16=DMA16,version=V
327 adlib not yet available with -device
328 pcspk not yet available with -device
329
330For PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control the PCI
331device address, as usual.
332
333=== USB Devices ===
334
335The old way to define a virtual USB device is -usbdevice DRIVER:OPTS...
336
337The new way is -device DEVNAME,DEV-OPTS... Details depend on DRIVER:
338
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200339* ccid -device usb-ccid
340* keyboard -device usb-kbd
Markus Armbruster96560cb2009-12-17 17:19:17 +0100341* mouse -device usb-mouse
342* tablet -device usb-tablet
Markus Armbruster96560cb2009-12-17 17:19:17 +0100343* wacom-tablet -device usb-wacom-tablet
344* host:... See "Host Device Assignment"
345* disk:... See "Block Devices"
346* serial:... See "Character Devices"
347* braille See "Character Devices"
348* net:... See "Network Devices"
349* bt:... not yet available with -device
350
351=== Watchdog Devices ===
352
353Host and guest part of watchdog devices have always been separate.
354
355The old way to define a guest watchdog device is -watchdog DEVNAME.
356The new way is -device DEVNAME. For PCI devices, you can add
357bus=PCI-BUS,addr=DEVFN to control the PCI device address, as usual.
358
359=== Host Device Assignment ===
360
361QEMU supports assigning host PCI devices (qemu-kvm only at this time)
Paolo Bonziniab37bfc2017-10-20 10:17:50 +0200362and host USB devices. PCI devices can only be assigned with -device:
Markus Armbruster96560cb2009-12-17 17:19:17 +0100363
Paolo Bonziniab37bfc2017-10-20 10:17:50 +0200364 -device vfio-pci,host=ADDR,id=ID
Markus Armbruster96560cb2009-12-17 17:19:17 +0100365
366The old way to assign a host USB device is
367
368 -usbdevice host:auto:BUS.ADDR:VID:PRID
369
370where any of BUS, ADDR, VID, PRID can be the wildcard *.
371
372The new way is
373
374 -device usb-host,hostbus=BUS,hostaddr=ADDR,vendorid=VID,productid=PRID
375
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200376Omitted options match anything, just like the old way's wildcard.
377
378=== Default Devices ===
379
380QEMU creates a number of devices by default, depending on the machine
381type.
382
383-device DEVNAME... and global DEVNAME... suppress default devices for
384some DEVNAMEs:
385
386 default device suppressing DEVNAMEs
Markus Armbruster7a0bbd52017-05-09 11:41:16 +0200387 CD-ROM ide-cd, ide-drive, ide-hd, scsi-cd, scsi-hd
388 isa-fdc's driveA floppy, isa-fdc
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200389 parallel isa-parallel
390 serial isa-serial
Markus Armbruster7a0bbd52017-05-09 11:41:16 +0200391 VGA VGA, cirrus-vga, isa-vga, isa-cirrus-vga,
392 vmware-svga, qxl-vga, virtio-vga
393 virtioconsole virtio-serial-pci, virtio-serial
Markus Armbruster23bf93b2011-06-07 10:34:31 +0200394
395The default NIC is connected to a default part created along with it.
396It is *not* suppressed by configuring a NIC with -device (you may call
397that a bug). -net and -netdev suppress the default NIC.
398
399-nodefaults suppresses all the default devices mentioned above, plus a
400few other things such as default SD-Card drive and default monitor.