1 /* 2 * QEMU AHCI Emulation (MMIO-mapped devices) 3 * 4 * Copyright (c) 2010 qiaochong@loongson.cn 5 * Copyright (c) 2010 Roland Elek <elek.roland@gmail.com> 6 * Copyright (c) 2010 Sebastian Herbszt <herbszt@gmx.de> 7 * Copyright (c) 2010 Alexander Graf <agraf@suse.de> 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public 11 * License as published by the Free Software Foundation; either 12 * version 2.1 of the License, or (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this library; if not, see <http://www.gnu.org/licenses/>. 21 * 22 */ 23 24 #include "qemu/osdep.h" 25 #include "exec/address-spaces.h" 26 #include "hw/qdev-properties.h" 27 #include "migration/vmstate.h" 28 29 #include "hw/ide/ahci-sysbus.h" 30 #include "ahci-internal.h" 31 32 static const VMStateDescription vmstate_sysbus_ahci = { 33 .name = "sysbus-ahci", 34 .fields = (const VMStateField[]) { 35 VMSTATE_AHCI(ahci, SysbusAHCIState), 36 VMSTATE_END_OF_LIST() 37 }, 38 }; 39 40 static void sysbus_ahci_reset(DeviceState *dev) 41 { 42 SysbusAHCIState *s = SYSBUS_AHCI(dev); 43 44 ahci_reset(&s->ahci); 45 } 46 47 static void sysbus_ahci_init(Object *obj) 48 { 49 SysbusAHCIState *s = SYSBUS_AHCI(obj); 50 SysBusDevice *sbd = SYS_BUS_DEVICE(obj); 51 52 ahci_init(&s->ahci, DEVICE(obj)); 53 54 sysbus_init_mmio(sbd, &s->ahci.mem); 55 sysbus_init_irq(sbd, &s->ahci.irq); 56 } 57 58 static void sysbus_ahci_realize(DeviceState *dev, Error **errp) 59 { 60 SysbusAHCIState *s = SYSBUS_AHCI(dev); 61 62 ahci_realize(&s->ahci, dev, &address_space_memory); 63 } 64 65 static const Property sysbus_ahci_properties[] = { 66 DEFINE_PROP_UINT32("num-ports", SysbusAHCIState, ahci.ports, 1), 67 }; 68 69 static void sysbus_ahci_class_init(ObjectClass *klass, void *data) 70 { 71 DeviceClass *dc = DEVICE_CLASS(klass); 72 73 dc->realize = sysbus_ahci_realize; 74 dc->vmsd = &vmstate_sysbus_ahci; 75 device_class_set_props(dc, sysbus_ahci_properties); 76 device_class_set_legacy_reset(dc, sysbus_ahci_reset); 77 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); 78 } 79 80 static const TypeInfo sysbus_ahci_types[] = { 81 { 82 .name = TYPE_SYSBUS_AHCI, 83 .parent = TYPE_SYS_BUS_DEVICE, 84 .instance_size = sizeof(SysbusAHCIState), 85 .instance_init = sysbus_ahci_init, 86 .class_init = sysbus_ahci_class_init, 87 }, 88 }; 89 90 DEFINE_TYPES(sysbus_ahci_types) 91