diff options
Diffstat (limited to 'hw/ide')
-rw-r--r-- | hw/ide/cmd646.c | 4 | ||||
-rw-r--r-- | hw/ide/core.c | 108 | ||||
-rw-r--r-- | hw/ide/internal.h | 13 | ||||
-rw-r--r-- | hw/ide/isa.c | 2 | ||||
-rw-r--r-- | hw/ide/macio.c | 2 | ||||
-rw-r--r-- | hw/ide/microdrive.c | 3 | ||||
-rw-r--r-- | hw/ide/mmio.c | 2 | ||||
-rw-r--r-- | hw/ide/piix.c | 4 | ||||
-rw-r--r-- | hw/ide/qdev.c | 21 |
9 files changed, 95 insertions, 64 deletions
diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c index cdcc9bf1aa..559147ff43 100644 --- a/hw/ide/cmd646.c +++ b/hw/ide/cmd646.c @@ -260,8 +260,8 @@ static int pci_cmd646_ide_initfn(PCIDevice *dev) irq = qemu_allocate_irqs(cmd646_set_irq, d, 2); ide_bus_new(&d->bus[0], &d->dev.qdev); ide_bus_new(&d->bus[1], &d->dev.qdev); - ide_init2(&d->bus[0], NULL, NULL, irq[0]); - ide_init2(&d->bus[1], NULL, NULL, irq[1]); + ide_init2(&d->bus[0], irq[0]); + ide_init2(&d->bus[1], irq[1]); vmstate_register(0, &vmstate_ide_pci, d); qemu_register_reset(cmd646_reset, d); diff --git a/hw/ide/core.c b/hw/ide/core.c index 066fecb0c0..045d18db2b 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -26,8 +26,6 @@ #include <hw/pc.h> #include <hw/pci.h> #include <hw/scsi.h> -#include "block.h" -#include "block_int.h" #include "qemu-timer.h" #include "sysemu.h" #include "dma.h" @@ -98,6 +96,7 @@ static void ide_identify(IDEState *s) { uint16_t *p; unsigned int oldsize; + IDEDevice *dev; if (s->identify_set) { memcpy(s->io_buffer, s->identify_data, sizeof(s->identify_data)); @@ -165,8 +164,9 @@ static void ide_identify(IDEState *s) put_le16(p + 101, s->nb_sectors >> 16); put_le16(p + 102, s->nb_sectors >> 32); put_le16(p + 103, s->nb_sectors >> 48); - if (s->conf && s->conf->physical_block_size) - put_le16(p + 106, 0x6000 | get_physical_block_exp(s->conf)); + dev = s->unit ? s->bus->slave : s->bus->master; + if (dev && dev->conf.physical_block_size) + put_le16(p + 106, 0x6000 | get_physical_block_exp(&dev->conf)); memcpy(s->identify_data, p, sizeof(s->identify_data)); s->identify_set = 1; @@ -2594,39 +2594,35 @@ void ide_bus_reset(IDEBus *bus) ide_clear_hob(bus); } -void ide_init_drive(IDEState *s, DriveInfo *dinfo, BlockConf *conf, - const char *version) +void ide_init_drive(IDEState *s, DriveInfo *dinfo, + const char *version, const char *serial) { int cylinders, heads, secs; uint64_t nb_sectors; - if (dinfo && dinfo->bdrv) { - s->bs = dinfo->bdrv; - bdrv_get_geometry(s->bs, &nb_sectors); - bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs); - s->cylinders = cylinders; - s->heads = heads; - s->sectors = secs; - s->nb_sectors = nb_sectors; - /* The SMART values should be preserved across power cycles - but they aren't. */ - s->smart_enabled = 1; - s->smart_autosave = 1; - s->smart_errors = 0; - s->smart_selftest_count = 0; - if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) { - s->is_cdrom = 1; - bdrv_set_change_cb(s->bs, cdrom_change_cb, s); - } - strncpy(s->drive_serial_str, drive_get_serial(s->bs), - sizeof(s->drive_serial_str)); - if (conf) { - s->conf = conf; - } + s->bs = dinfo->bdrv; + bdrv_get_geometry(s->bs, &nb_sectors); + bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs); + s->cylinders = cylinders; + s->heads = heads; + s->sectors = secs; + s->nb_sectors = nb_sectors; + /* The SMART values should be preserved across power cycles + but they aren't. */ + s->smart_enabled = 1; + s->smart_autosave = 1; + s->smart_errors = 0; + s->smart_selftest_count = 0; + if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) { + s->is_cdrom = 1; + bdrv_set_change_cb(s->bs, cdrom_change_cb, s); } - if (strlen(s->drive_serial_str) == 0) + if (serial && *serial) { + strncpy(s->drive_serial_str, serial, sizeof(s->drive_serial_str)); + } else { snprintf(s->drive_serial_str, sizeof(s->drive_serial_str), "QM%05d", s->drive_serial); + } if (version) { pstrcpy(s->version, sizeof(s->version), version); } else { @@ -2635,27 +2631,47 @@ void ide_init_drive(IDEState *s, DriveInfo *dinfo, BlockConf *conf, ide_reset(s); } -void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1, - qemu_irq irq) +static void ide_init1(IDEBus *bus, int unit) { - IDEState *s; static int drive_serial = 1; + IDEState *s = &bus->ifs[unit]; + + s->bus = bus; + s->unit = unit; + s->drive_serial = drive_serial++; + s->io_buffer = qemu_blockalign(s->bs, IDE_DMA_BUF_SECTORS*512 + 4); + s->io_buffer_total_len = IDE_DMA_BUF_SECTORS*512 + 4; + s->smart_selftest_data = qemu_blockalign(s->bs, 512); + s->sector_write_timer = qemu_new_timer(vm_clock, + ide_sector_write_timer_cb, s); +} + +void ide_init2(IDEBus *bus, qemu_irq irq) +{ int i; for(i = 0; i < 2; i++) { - s = bus->ifs + i; - s->bus = bus; - s->unit = i; - s->drive_serial = drive_serial++; - s->io_buffer = qemu_blockalign(s->bs, IDE_DMA_BUF_SECTORS*512 + 4); - s->io_buffer_total_len = IDE_DMA_BUF_SECTORS*512 + 4; - s->smart_selftest_data = qemu_blockalign(s->bs, 512); - s->sector_write_timer = qemu_new_timer(vm_clock, - ide_sector_write_timer_cb, s); - if (i == 0) - ide_init_drive(s, hd0, NULL, NULL); - if (i == 1) - ide_init_drive(s, hd1, NULL, NULL); + ide_init1(bus, i); + ide_reset(&bus->ifs[i]); + } + bus->irq = irq; +} + +/* TODO convert users to qdev and remove */ +void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, + DriveInfo *hd1, qemu_irq irq) +{ + int i; + DriveInfo *dinfo; + + for(i = 0; i < 2; i++) { + dinfo = i == 0 ? hd0 : hd1; + ide_init1(bus, i); + if (dinfo) { + ide_init_drive(&bus->ifs[i], dinfo, NULL, dinfo->serial); + } else { + ide_reset(&bus->ifs[i]); + } } bus->irq = irq; } diff --git a/hw/ide/internal.h b/hw/ide/internal.h index 2efc7846bc..eef1ee141d 100644 --- a/hw/ide/internal.h +++ b/hw/ide/internal.h @@ -398,7 +398,6 @@ struct IDEState { /* set for lba48 access */ uint8_t lba48; BlockDriverState *bs; - BlockConf *conf; char version[9]; /* ATAPI specific */ uint8_t sense_key; @@ -458,14 +457,13 @@ struct IDEDevice { uint32_t unit; BlockConf conf; char *version; + char *serial; }; typedef int (*ide_qdev_initfn)(IDEDevice *dev); struct IDEDeviceInfo { DeviceInfo qdev; ide_qdev_initfn init; - uint32_t unit; - DriveInfo *drive; }; #define BM_STATUS_DMAING 0x01 @@ -557,10 +555,11 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr); void ide_data_writel(void *opaque, uint32_t addr, uint32_t val); uint32_t ide_data_readl(void *opaque, uint32_t addr); -void ide_init_drive(IDEState *s, DriveInfo *dinfo, BlockConf *conf, - const char *version); -void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1, - qemu_irq irq); +void ide_init_drive(IDEState *s, DriveInfo *dinfo, + const char *version, const char *serial); +void ide_init2(IDEBus *bus, qemu_irq irq); +void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, + DriveInfo *hd1, qemu_irq irq); void ide_init_ioport(IDEBus *bus, int iobase, int iobase2); /* hw/ide/qdev.c */ diff --git a/hw/ide/isa.c b/hw/ide/isa.c index dff7c796f7..b6c6347289 100644 --- a/hw/ide/isa.c +++ b/hw/ide/isa.c @@ -70,7 +70,7 @@ static int isa_ide_initfn(ISADevice *dev) ide_bus_new(&s->bus, &s->dev.qdev); ide_init_ioport(&s->bus, s->iobase, s->iobase2); isa_init_irq(dev, &s->irq, s->isairq); - ide_init2(&s->bus, NULL, NULL, s->irq); + ide_init2(&s->bus, s->irq); vmstate_register(0, &vmstate_ide_isa, s); return 0; }; diff --git a/hw/ide/macio.c b/hw/ide/macio.c index 639f3f6a65..f76c0fa31c 100644 --- a/hw/ide/macio.c +++ b/hw/ide/macio.c @@ -314,7 +314,7 @@ int pmac_ide_init (DriveInfo **hd_table, qemu_irq irq, int pmac_ide_memory; d = qemu_mallocz(sizeof(MACIOIDEState)); - ide_init2(&d->bus, hd_table[0], hd_table[1], irq); + ide_init2_with_non_qdev_drives(&d->bus, hd_table[0], hd_table[1], irq); if (dbdma) DBDMA_register_channel(dbdma, channel, dma_irq, pmac_ide_transfer, pmac_ide_flush, d); diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c index bfdb8c8b05..a7beac552a 100644 --- a/hw/ide/microdrive.c +++ b/hw/ide/microdrive.c @@ -539,7 +539,8 @@ PCMCIACardState *dscm1xxxx_init(DriveInfo *bdrv) md->card.cis = dscm1xxxx_cis; md->card.cis_len = sizeof(dscm1xxxx_cis); - ide_init2(&md->bus, bdrv, NULL, qemu_allocate_irqs(md_set_irq, md, 1)[0]); + ide_init2_with_non_qdev_drives(&md->bus, bdrv, NULL, + qemu_allocate_irqs(md_set_irq, md, 1)[0]); md->bus.ifs[0].is_cf = 1; md->bus.ifs[0].mdata_size = METADATA_SIZE; md->bus.ifs[0].mdata_storage = (uint8_t *) qemu_mallocz(METADATA_SIZE); diff --git a/hw/ide/mmio.c b/hw/ide/mmio.c index cca883f613..e75cccf56e 100644 --- a/hw/ide/mmio.c +++ b/hw/ide/mmio.c @@ -125,7 +125,7 @@ void mmio_ide_init (target_phys_addr_t membase, target_phys_addr_t membase2, MMIOState *s = qemu_mallocz(sizeof(MMIOState)); int mem1, mem2; - ide_init2(&s->bus, hd0, hd1, irq); + ide_init2_with_non_qdev_drives(&s->bus, hd0, hd1, irq); s->shift = shift; diff --git a/hw/ide/piix.c b/hw/ide/piix.c index 4fa38519ef..dad6e86ff6 100644 --- a/hw/ide/piix.c +++ b/hw/ide/piix.c @@ -135,8 +135,8 @@ static int pci_piix_ide_initfn(PCIIDEState *d) ide_init_ioport(&d->bus[0], 0x1f0, 0x3f6); ide_init_ioport(&d->bus[1], 0x170, 0x376); - ide_init2(&d->bus[0], NULL, NULL, isa_reserve_irq(14)); - ide_init2(&d->bus[1], NULL, NULL, isa_reserve_irq(15)); + ide_init2(&d->bus[0], isa_reserve_irq(14)); + ide_init2(&d->bus[1], isa_reserve_irq(15)); return 0; } diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index b18693d945..0f9f22e30f 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -17,7 +17,6 @@ * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #include <hw/hw.h> -#include "sysemu.h" #include "dma.h" #include <hw/ide/internal.h> @@ -99,8 +98,23 @@ typedef struct IDEDrive { static int ide_drive_initfn(IDEDevice *dev) { IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus); - ide_init_drive(bus->ifs + dev->unit, dev->conf.dinfo, &dev->conf, - dev->version); + IDEState *s = bus->ifs + dev->unit; + const char *serial; + + serial = dev->serial; + if (!serial) { + /* try to fall back to value set with legacy -drive serial=... */ + serial = dev->conf.dinfo->serial; + } + + ide_init_drive(s, dev->conf.dinfo, dev->version, serial); + + if (!dev->version) { + dev->version = qemu_strdup(s->version); + } + if (!dev->serial) { + dev->serial = qemu_strdup(s->drive_serial_str); + } return 0; } @@ -112,6 +126,7 @@ static IDEDeviceInfo ide_drive_info = { DEFINE_PROP_UINT32("unit", IDEDrive, dev.unit, -1), DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), DEFINE_PROP_STRING("ver", IDEDrive, dev.version), + DEFINE_PROP_STRING("serial", IDEDrive, dev.serial), DEFINE_PROP_END_OF_LIST(), } }; |