11b26146eSBernhard Beschow /*
21b26146eSBernhard Beschow * QEMU AHCI Emulation (MMIO-mapped devices)
31b26146eSBernhard Beschow *
41b26146eSBernhard Beschow * Copyright (c) 2010 qiaochong@loongson.cn
51b26146eSBernhard Beschow * Copyright (c) 2010 Roland Elek <elek.roland@gmail.com>
61b26146eSBernhard Beschow * Copyright (c) 2010 Sebastian Herbszt <herbszt@gmx.de>
71b26146eSBernhard Beschow * Copyright (c) 2010 Alexander Graf <agraf@suse.de>
81b26146eSBernhard Beschow *
91b26146eSBernhard Beschow * This library is free software; you can redistribute it and/or
101b26146eSBernhard Beschow * modify it under the terms of the GNU Lesser General Public
111b26146eSBernhard Beschow * License as published by the Free Software Foundation; either
121b26146eSBernhard Beschow * version 2.1 of the License, or (at your option) any later version.
131b26146eSBernhard Beschow *
141b26146eSBernhard Beschow * This library is distributed in the hope that it will be useful,
151b26146eSBernhard Beschow * but WITHOUT ANY WARRANTY; without even the implied warranty of
161b26146eSBernhard Beschow * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
171b26146eSBernhard Beschow * Lesser General Public License for more details.
181b26146eSBernhard Beschow *
191b26146eSBernhard Beschow * You should have received a copy of the GNU Lesser General Public
201b26146eSBernhard Beschow * License along with this library; if not, see <http://www.gnu.org/licenses/>.
211b26146eSBernhard Beschow *
221b26146eSBernhard Beschow */
231b26146eSBernhard Beschow
241b26146eSBernhard Beschow #include "qemu/osdep.h"
251b26146eSBernhard Beschow #include "exec/address-spaces.h"
261b26146eSBernhard Beschow #include "hw/qdev-properties.h"
271b26146eSBernhard Beschow #include "migration/vmstate.h"
281b26146eSBernhard Beschow
291b26146eSBernhard Beschow #include "hw/ide/ahci-sysbus.h"
301b26146eSBernhard Beschow #include "ahci-internal.h"
311b26146eSBernhard Beschow
321b26146eSBernhard Beschow static const VMStateDescription vmstate_sysbus_ahci = {
331b26146eSBernhard Beschow .name = "sysbus-ahci",
341b26146eSBernhard Beschow .fields = (const VMStateField[]) {
351b26146eSBernhard Beschow VMSTATE_AHCI(ahci, SysbusAHCIState),
361b26146eSBernhard Beschow VMSTATE_END_OF_LIST()
371b26146eSBernhard Beschow },
381b26146eSBernhard Beschow };
391b26146eSBernhard Beschow
sysbus_ahci_reset(DeviceState * dev)401b26146eSBernhard Beschow static void sysbus_ahci_reset(DeviceState *dev)
411b26146eSBernhard Beschow {
421b26146eSBernhard Beschow SysbusAHCIState *s = SYSBUS_AHCI(dev);
431b26146eSBernhard Beschow
441b26146eSBernhard Beschow ahci_reset(&s->ahci);
451b26146eSBernhard Beschow }
461b26146eSBernhard Beschow
sysbus_ahci_init(Object * obj)471b26146eSBernhard Beschow static void sysbus_ahci_init(Object *obj)
481b26146eSBernhard Beschow {
491b26146eSBernhard Beschow SysbusAHCIState *s = SYSBUS_AHCI(obj);
501b26146eSBernhard Beschow SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
511b26146eSBernhard Beschow
521b26146eSBernhard Beschow ahci_init(&s->ahci, DEVICE(obj));
531b26146eSBernhard Beschow
541b26146eSBernhard Beschow sysbus_init_mmio(sbd, &s->ahci.mem);
551b26146eSBernhard Beschow sysbus_init_irq(sbd, &s->ahci.irq);
561b26146eSBernhard Beschow }
571b26146eSBernhard Beschow
sysbus_ahci_realize(DeviceState * dev,Error ** errp)581b26146eSBernhard Beschow static void sysbus_ahci_realize(DeviceState *dev, Error **errp)
591b26146eSBernhard Beschow {
601b26146eSBernhard Beschow SysbusAHCIState *s = SYSBUS_AHCI(dev);
611b26146eSBernhard Beschow
621b26146eSBernhard Beschow ahci_realize(&s->ahci, dev, &address_space_memory);
631b26146eSBernhard Beschow }
641b26146eSBernhard Beschow
65*06be938aSRichard Henderson static const Property sysbus_ahci_properties[] = {
661b26146eSBernhard Beschow DEFINE_PROP_UINT32("num-ports", SysbusAHCIState, ahci.ports, 1),
671b26146eSBernhard Beschow };
681b26146eSBernhard Beschow
sysbus_ahci_class_init(ObjectClass * klass,void * data)691b26146eSBernhard Beschow static void sysbus_ahci_class_init(ObjectClass *klass, void *data)
701b26146eSBernhard Beschow {
711b26146eSBernhard Beschow DeviceClass *dc = DEVICE_CLASS(klass);
721b26146eSBernhard Beschow
731b26146eSBernhard Beschow dc->realize = sysbus_ahci_realize;
741b26146eSBernhard Beschow dc->vmsd = &vmstate_sysbus_ahci;
751b26146eSBernhard Beschow device_class_set_props(dc, sysbus_ahci_properties);
761b26146eSBernhard Beschow device_class_set_legacy_reset(dc, sysbus_ahci_reset);
771b26146eSBernhard Beschow set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
781b26146eSBernhard Beschow }
791b26146eSBernhard Beschow
801b26146eSBernhard Beschow static const TypeInfo sysbus_ahci_types[] = {
811b26146eSBernhard Beschow {
821b26146eSBernhard Beschow .name = TYPE_SYSBUS_AHCI,
831b26146eSBernhard Beschow .parent = TYPE_SYS_BUS_DEVICE,
841b26146eSBernhard Beschow .instance_size = sizeof(SysbusAHCIState),
851b26146eSBernhard Beschow .instance_init = sysbus_ahci_init,
861b26146eSBernhard Beschow .class_init = sysbus_ahci_class_init,
871b26146eSBernhard Beschow },
881b26146eSBernhard Beschow };
891b26146eSBernhard Beschow
901b26146eSBernhard Beschow DEFINE_TYPES(sysbus_ahci_types)
91