9 static PCIDevice
*qemu_system_hot_add_nic(const char *opts
, int bus_nr
)
15 pci_bus
= pci_find_bus (bus_nr
);
17 term_printf ("Can't find pci_bus %d\n", bus_nr
);
21 memset (buf
, 0, sizeof (buf
));
24 strncat (buf
, opts
, sizeof (buf
) - strlen (buf
) - 1);
26 ret
= net_client_init (buf
);
27 if (ret
< 0 || !nd_table
[ret
].model
)
29 return pci_nic_init (pci_bus
, &nd_table
[ret
], -1);
32 static int add_init_drive(const char *opts
)
34 int drive_opt_idx
, drive_idx
;
37 drive_opt_idx
= drive_add(NULL
, "%s", opts
);
41 drive_idx
= drive_init(&drives_opt
[drive_opt_idx
], 0, current_machine
);
42 if (drive_idx
== -1) {
43 drive_remove(drive_opt_idx
);
50 void drive_hot_add(int pcibus
, const char *devfn_string
, const char *opts
)
52 int drive_idx
, type
, bus
;
57 devfn
= strtoul(devfn_string
, NULL
, 0);
59 dev
= pci_find_device(pcibus
, PCI_SLOT(devfn
));
61 term_printf("no pci device with devfn %d (slot %d)\n", devfn
,
66 drive_idx
= add_init_drive(opts
);
69 type
= drives_table
[drive_idx
].type
;
70 bus
= drive_get_max_bus (type
);
75 lsi_scsi_attach (dev
, drives_table
[drive_idx
].bdrv
,
76 drives_table
[drive_idx
].unit
);
79 term_printf("Can't hot-add drive to type %d\n", type
);
83 term_printf("OK bus %d, unit %d\n", drives_table
[drive_idx
].bus
,
84 drives_table
[drive_idx
].unit
);
88 static PCIDevice
*qemu_system_hot_add_storage(const char *opts
, int bus_nr
)
92 int type
= -1, drive_idx
= -1;
95 pci_bus
= pci_find_bus(bus_nr
);
97 term_printf("Can't find pci_bus %d\n", bus_nr
);
101 if (get_param_value(buf
, sizeof(buf
), "if", opts
)) {
102 if (!strcmp(buf
, "scsi"))
104 else if (!strcmp(buf
, "virtio")) {
108 term_printf("no if= specified\n");
112 if (get_param_value(buf
, sizeof(buf
), "file", opts
)) {
113 drive_idx
= add_init_drive(opts
);
116 } else if (type
== IF_VIRTIO
) {
117 term_printf("virtio requires a backing file/device.\n");
123 opaque
= lsi_scsi_init (pci_bus
, -1);
125 lsi_scsi_attach (opaque
, drives_table
[drive_idx
].bdrv
,
126 drives_table
[drive_idx
].unit
);
129 opaque
= virtio_blk_init (pci_bus
, 0x1AF4, 0x1001,
130 drives_table
[drive_idx
].bdrv
);
133 term_printf ("type %s not a hotpluggable PCI device.\n", buf
);
139 void device_hot_add(int pcibus
, const char *type
, const char *opts
)
141 PCIDevice
*dev
= NULL
;
143 if (strcmp(type
, "nic") == 0)
144 dev
= qemu_system_hot_add_nic(opts
, pcibus
);
145 else if (strcmp(type
, "storage") == 0)
146 dev
= qemu_system_hot_add_storage(opts
, pcibus
);
148 term_printf("invalid type: %s\n", type
);
151 qemu_system_device_hot_add(PCI_SLOT(dev
->devfn
), 1);
152 term_printf("OK bus %d, slot %d, function %d (devfn %d)\n",
153 pci_bus_num(dev
->bus
), PCI_SLOT(dev
->devfn
),
154 PCI_FUNC(dev
->devfn
), dev
->devfn
);
156 term_printf("failed to add %s\n", opts
);