1 /* 2 * USB Mass Storage Device emulation 3 * 4 * Copyright (c) 2006 CodeSourcery. 5 * Written by Paul Brook 6 * 7 * This code is licensed under the LGPL. 8 */ 9 10 #include "qemu/osdep.h" 11 #include "qemu/typedefs.h" 12 #include "qapi/error.h" 13 #include "hw/usb.h" 14 #include "hw/usb/desc.h" 15 #include "hw/usb/msd.h" 16 17 static const struct SCSIBusInfo usb_msd_scsi_info_bot = { 18 .tcq = false, 19 .max_target = 0, 20 .max_lun = 15, 21 22 .transfer_data = usb_msd_transfer_data, 23 .complete = usb_msd_command_complete, 24 .cancel = usb_msd_request_cancelled, 25 .load_request = usb_msd_load_request, 26 }; 27 28 static void usb_msd_bot_realize(USBDevice *dev, Error **errp) 29 { 30 MSDState *s = USB_STORAGE_DEV(dev); 31 DeviceState *d = DEVICE(dev); 32 33 usb_desc_create_serial(dev); 34 usb_desc_init(dev); 35 dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE); 36 if (d->hotplugged) { 37 s->dev.auto_attach = 0; 38 } 39 40 scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev), 41 &usb_msd_scsi_info_bot, NULL); 42 usb_msd_handle_reset(dev); 43 } 44 45 static void usb_msd_class_bot_initfn(ObjectClass *klass, void *data) 46 { 47 USBDeviceClass *uc = USB_DEVICE_CLASS(klass); 48 49 uc->realize = usb_msd_bot_realize; 50 uc->attached_settable = true; 51 } 52 53 static const TypeInfo bot_info = { 54 .name = "usb-bot", 55 .parent = TYPE_USB_STORAGE, 56 .class_init = usb_msd_class_bot_initfn, 57 }; 58 59 static void register_types(void) 60 { 61 type_register_static(&bot_info); 62 } 63 64 type_init(register_types) 65