Revision 1f56e32a
b/hw/ide/core.c | ||
---|---|---|
1592 | 1592 |
bus->dma->ops->reset(bus->dma); |
1593 | 1593 |
} |
1594 | 1594 |
|
1595 |
int ide_init_drive(IDEState *s, BlockDriverState *bs, |
|
1595 |
int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
|
|
1596 | 1596 |
const char *version, const char *serial) |
1597 | 1597 |
{ |
1598 | 1598 |
int cylinders, heads, secs; |
1599 | 1599 |
uint64_t nb_sectors; |
1600 | 1600 |
|
1601 | 1601 |
s->bs = bs; |
1602 |
s->drive_kind = kind; |
|
1603 |
|
|
1602 | 1604 |
bdrv_get_geometry(bs, &nb_sectors); |
1603 | 1605 |
bdrv_guess_geometry(bs, &cylinders, &heads, &secs); |
1604 | 1606 |
if (cylinders < 1 || cylinders > 16383) { |
... | ... | |
1623 | 1625 |
s->smart_autosave = 1; |
1624 | 1626 |
s->smart_errors = 0; |
1625 | 1627 |
s->smart_selftest_count = 0; |
1626 |
if (bdrv_get_type_hint(bs) == BDRV_TYPE_CDROM) { |
|
1627 |
s->drive_kind = IDE_CD; |
|
1628 |
if (kind == IDE_CD) { |
|
1628 | 1629 |
bdrv_set_change_cb(bs, cdrom_change_cb, s); |
1629 | 1630 |
bs->buffer_alignment = 2048; |
1630 | 1631 |
} else { |
... | ... | |
1729 | 1730 |
dinfo = i == 0 ? hd0 : hd1; |
1730 | 1731 |
ide_init1(bus, i); |
1731 | 1732 |
if (dinfo) { |
1732 |
if (ide_init_drive(&bus->ifs[i], dinfo->bdrv, NULL, |
|
1733 |
if (ide_init_drive(&bus->ifs[i], dinfo->bdrv, |
|
1734 |
bdrv_get_type_hint(dinfo->bdrv) == BDRV_TYPE_CDROM ? IDE_CD : IDE_HD, |
|
1735 |
NULL, |
|
1733 | 1736 |
*dinfo->serial ? dinfo->serial : NULL) < 0) { |
1734 | 1737 |
error_report("Can't set up IDE drive %s", dinfo->id); |
1735 | 1738 |
exit(1); |
b/hw/ide/internal.h | ||
---|---|---|
558 | 558 |
void ide_data_writel(void *opaque, uint32_t addr, uint32_t val); |
559 | 559 |
uint32_t ide_data_readl(void *opaque, uint32_t addr); |
560 | 560 |
|
561 |
int ide_init_drive(IDEState *s, BlockDriverState *bs, |
|
561 |
int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
|
|
562 | 562 |
const char *version, const char *serial); |
563 | 563 |
void ide_init2(IDEBus *bus, qemu_irq irq); |
564 | 564 |
void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, |
b/hw/ide/qdev.c | ||
---|---|---|
98 | 98 |
{ |
99 | 99 |
DeviceState *dev; |
100 | 100 |
|
101 |
dev = qdev_create(&bus->qbus, "ide-drive"); |
|
101 |
dev = qdev_create(&bus->qbus, |
|
102 |
bdrv_get_type_hint(drive->bdrv) == BDRV_TYPE_CDROM |
|
103 |
? "ide-cd" : "ide-hd"); |
|
102 | 104 |
qdev_prop_set_uint32(dev, "unit", unit); |
103 | 105 |
qdev_prop_set_drive_nofail(dev, "drive", drive->bdrv); |
104 | 106 |
qdev_init_nofail(dev); |
... | ... | |
118 | 120 |
IDEDevice dev; |
119 | 121 |
} IDEDrive; |
120 | 122 |
|
121 |
static int ide_drive_initfn(IDEDevice *dev)
|
|
123 |
static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
|
|
122 | 124 |
{ |
123 | 125 |
IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus); |
124 | 126 |
IDEState *s = bus->ifs + dev->unit; |
... | ... | |
134 | 136 |
} |
135 | 137 |
} |
136 | 138 |
|
137 |
if (ide_init_drive(s, dev->conf.bs, dev->version, serial) < 0) { |
|
139 |
if (ide_init_drive(s, dev->conf.bs, kind, dev->version, serial) < 0) {
|
|
138 | 140 |
return -1; |
139 | 141 |
} |
140 | 142 |
|
... | ... | |
151 | 153 |
return 0; |
152 | 154 |
} |
153 | 155 |
|
154 |
static IDEDeviceInfo ide_drive_info = { |
|
155 |
.qdev.name = "ide-drive", |
|
156 |
.qdev.fw_name = "drive", |
|
157 |
.qdev.size = sizeof(IDEDrive), |
|
158 |
.init = ide_drive_initfn, |
|
159 |
.qdev.props = (Property[]) { |
|
160 |
DEFINE_PROP_UINT32("unit", IDEDrive, dev.unit, -1), |
|
161 |
DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), |
|
162 |
DEFINE_PROP_STRING("ver", IDEDrive, dev.version), |
|
163 |
DEFINE_PROP_STRING("serial", IDEDrive, dev.serial), |
|
164 |
DEFINE_PROP_END_OF_LIST(), |
|
156 |
static int ide_hd_initfn(IDEDevice *dev) |
|
157 |
{ |
|
158 |
return ide_dev_initfn(dev, IDE_HD); |
|
159 |
} |
|
160 |
|
|
161 |
static int ide_cd_initfn(IDEDevice *dev) |
|
162 |
{ |
|
163 |
return ide_dev_initfn(dev, IDE_CD); |
|
164 |
} |
|
165 |
|
|
166 |
static int ide_drive_initfn(IDEDevice *dev) |
|
167 |
{ |
|
168 |
return ide_dev_initfn(dev, |
|
169 |
bdrv_get_type_hint(dev->conf.bs) == BDRV_TYPE_CDROM |
|
170 |
? IDE_CD : IDE_HD); |
|
171 |
} |
|
172 |
|
|
173 |
#define DEFINE_IDE_DEV_PROPERTIES() \ |
|
174 |
DEFINE_PROP_UINT32("unit", IDEDrive, dev.unit, -1), \ |
|
175 |
DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \ |
|
176 |
DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \ |
|
177 |
DEFINE_PROP_STRING("serial", IDEDrive, dev.serial) |
|
178 |
|
|
179 |
static IDEDeviceInfo ide_dev_info[] = { |
|
180 |
{ |
|
181 |
.qdev.name = "ide-hd", |
|
182 |
.qdev.fw_name = "drive", |
|
183 |
.qdev.desc = "virtual IDE disk", |
|
184 |
.qdev.size = sizeof(IDEDrive), |
|
185 |
.init = ide_hd_initfn, |
|
186 |
.qdev.props = (Property[]) { |
|
187 |
DEFINE_IDE_DEV_PROPERTIES(), |
|
188 |
DEFINE_PROP_END_OF_LIST(), |
|
189 |
} |
|
190 |
},{ |
|
191 |
.qdev.name = "ide-cd", |
|
192 |
.qdev.fw_name = "drive", |
|
193 |
.qdev.desc = "virtual IDE CD-ROM", |
|
194 |
.qdev.size = sizeof(IDEDrive), |
|
195 |
.init = ide_cd_initfn, |
|
196 |
.qdev.props = (Property[]) { |
|
197 |
DEFINE_IDE_DEV_PROPERTIES(), |
|
198 |
DEFINE_PROP_END_OF_LIST(), |
|
199 |
} |
|
200 |
},{ |
|
201 |
.qdev.name = "ide-drive", /* legacy -device ide-drive */ |
|
202 |
.qdev.fw_name = "drive", |
|
203 |
.qdev.desc = "virtual IDE disk or CD-ROM (legacy)", |
|
204 |
.qdev.size = sizeof(IDEDrive), |
|
205 |
.init = ide_drive_initfn, |
|
206 |
.qdev.props = (Property[]) { |
|
207 |
DEFINE_IDE_DEV_PROPERTIES(), |
|
208 |
DEFINE_PROP_END_OF_LIST(), |
|
209 |
} |
|
165 | 210 |
} |
166 | 211 |
}; |
167 | 212 |
|
168 |
static void ide_drive_register(void)
|
|
213 |
static void ide_dev_register(void)
|
|
169 | 214 |
{ |
170 |
ide_qdev_register(&ide_drive_info); |
|
215 |
int i; |
|
216 |
|
|
217 |
for (i = 0; i < ARRAY_SIZE(ide_dev_info); i++) { |
|
218 |
ide_qdev_register(&ide_dev_info[i]); |
|
219 |
} |
|
171 | 220 |
} |
172 |
device_init(ide_drive_register); |
|
221 |
device_init(ide_dev_register); |
Also available in: Unified diff