xref: /openbmc/qemu/hw/usb/dev-storage-bot.c (revision a6caeee8)
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_init(&s->bus, sizeof(s->bus), DEVICE(dev), &usb_msd_scsi_info_bot);
41     usb_msd_handle_reset(dev);
42 }
43 
44 static void usb_msd_class_bot_initfn(ObjectClass *klass, void *data)
45 {
46     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
47 
48     uc->realize = usb_msd_bot_realize;
49     uc->attached_settable = true;
50 }
51 
52 static const TypeInfo bot_info = {
53     .name          = "usb-bot",
54     .parent        = TYPE_USB_STORAGE,
55     .class_init    = usb_msd_class_bot_initfn,
56 };
57 
58 static void register_types(void)
59 {
60     type_register_static(&bot_info);
61 }
62 
63 type_init(register_types)
64