|
|
1.1 ! root 1: /* ! 2: * ide bus support for qdev. ! 3: * ! 4: * Copyright (c) 2009 Gerd Hoffmann <[email protected]> ! 5: * ! 6: * This library is free software; you can redistribute it and/or ! 7: * modify it under the terms of the GNU Lesser General Public ! 8: * License as published by the Free Software Foundation; either ! 9: * version 2 of the License, or (at your option) any later version. ! 10: * ! 11: * This library is distributed in the hope that it will be useful, ! 12: * but WITHOUT ANY WARRANTY; without even the implied warranty of ! 13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! 14: * Lesser General Public License for more details. ! 15: * ! 16: * You should have received a copy of the GNU Lesser General Public ! 17: * License along with this library; if not, see <http://www.gnu.org/licenses/>. ! 18: */ ! 19: #include <hw/hw.h> ! 20: #include "sysemu.h" ! 21: #include "dma.h" ! 22: ! 23: #include <hw/ide/internal.h> ! 24: ! 25: /* --------------------------------- */ ! 26: ! 27: static struct BusInfo ide_bus_info = { ! 28: .name = "IDE", ! 29: .size = sizeof(IDEBus), ! 30: }; ! 31: ! 32: void ide_bus_new(IDEBus *idebus, DeviceState *dev) ! 33: { ! 34: qbus_create_inplace(&idebus->qbus, &ide_bus_info, dev, NULL); ! 35: } ! 36: ! 37: static int ide_qdev_init(DeviceState *qdev, DeviceInfo *base) ! 38: { ! 39: IDEDevice *dev = DO_UPCAST(IDEDevice, qdev, qdev); ! 40: IDEDeviceInfo *info = DO_UPCAST(IDEDeviceInfo, qdev, base); ! 41: IDEBus *bus = DO_UPCAST(IDEBus, qbus, qdev->parent_bus); ! 42: ! 43: if (!dev->dinfo) { ! 44: fprintf(stderr, "%s: no drive specified\n", qdev->info->name); ! 45: goto err; ! 46: } ! 47: if (dev->unit == -1) { ! 48: dev->unit = bus->master ? 1 : 0; ! 49: } ! 50: switch (dev->unit) { ! 51: case 0: ! 52: if (bus->master) { ! 53: fprintf(stderr, "ide: tried to assign master twice\n"); ! 54: goto err; ! 55: } ! 56: bus->master = dev; ! 57: break; ! 58: case 1: ! 59: if (bus->slave) { ! 60: fprintf(stderr, "ide: tried to assign slave twice\n"); ! 61: goto err; ! 62: } ! 63: bus->slave = dev; ! 64: break; ! 65: default: ! 66: goto err; ! 67: } ! 68: return info->init(dev); ! 69: ! 70: err: ! 71: return -1; ! 72: } ! 73: ! 74: static void ide_qdev_register(IDEDeviceInfo *info) ! 75: { ! 76: info->qdev.init = ide_qdev_init; ! 77: info->qdev.bus_info = &ide_bus_info; ! 78: qdev_register(&info->qdev); ! 79: } ! 80: ! 81: IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive) ! 82: { ! 83: DeviceState *dev; ! 84: ! 85: dev = qdev_create(&bus->qbus, "ide-drive"); ! 86: qdev_prop_set_uint32(dev, "unit", unit); ! 87: qdev_prop_set_drive(dev, "drive", drive); ! 88: if (qdev_init(dev) < 0) ! 89: return NULL; ! 90: return DO_UPCAST(IDEDevice, qdev, dev); ! 91: } ! 92: ! 93: /* --------------------------------- */ ! 94: ! 95: typedef struct IDEDrive { ! 96: IDEDevice dev; ! 97: } IDEDrive; ! 98: ! 99: static int ide_drive_initfn(IDEDevice *dev) ! 100: { ! 101: IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus); ! 102: ide_init_drive(bus->ifs + dev->unit, dev->dinfo); ! 103: return 0; ! 104: } ! 105: ! 106: static IDEDeviceInfo ide_drive_info = { ! 107: .qdev.name = "ide-drive", ! 108: .qdev.size = sizeof(IDEDrive), ! 109: .init = ide_drive_initfn, ! 110: .qdev.props = (Property[]) { ! 111: DEFINE_PROP_UINT32("unit", IDEDrive, dev.unit, -1), ! 112: DEFINE_PROP_DRIVE("drive", IDEDrive, dev.dinfo), ! 113: DEFINE_PROP_END_OF_LIST(), ! 114: } ! 115: }; ! 116: ! 117: static void ide_drive_register(void) ! 118: { ! 119: ide_qdev_register(&ide_drive_info); ! 120: } ! 121: device_init(ide_drive_register);
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.