xref: /openbmc/qemu/hw/usb/dev-storage-bot.c (revision 8c6631e6)
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 "qapi/error.h"
12 #include "hw/usb.h"
13 #include "hw/usb/desc.h"
14 #include "hw/usb/msd.h"
15 
16 static const struct SCSIBusInfo usb_msd_scsi_info_bot = {
17     .tcq = false,
18     .max_target = 0,
19     .max_lun = 15,
20 
21     .transfer_data = usb_msd_transfer_data,
22     .complete = usb_msd_command_complete,
23     .cancel = usb_msd_request_cancelled,
24     .load_request = usb_msd_load_request,
25 };
26 
27 static void usb_msd_bot_realize(USBDevice *dev, Error **errp)
28 {
29     MSDState *s = USB_STORAGE_DEV(dev);
30     DeviceState *d = DEVICE(dev);
31 
32     usb_desc_create_serial(dev);
33     usb_desc_init(dev);
34     dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
35     if (d->hotplugged) {
36         s->dev.auto_attach = 0;
37     }
38 
39     scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(dev), &usb_msd_scsi_info_bot);
40     usb_msd_handle_reset(dev);
41 }
42 
43 static void usb_msd_class_bot_initfn(ObjectClass *klass, void *data)
44 {
45     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
46 
47     uc->realize = usb_msd_bot_realize;
48     uc->attached_settable = true;
49 }
50 
51 static const TypeInfo bot_info = {
52     .name          = "usb-bot",
53     .parent        = TYPE_USB_STORAGE,
54     .class_init    = usb_msd_class_bot_initfn,
55 };
56 
57 static void register_types(void)
58 {
59     type_register_static(&bot_info);
60 }
61 
62 type_init(register_types)
63