From: Laurent Vivier <[EMAIL PROTECTED](none)> This patch add the support of SCSI disk and cdrom for PC target, using previously introduced parameters "-disk" and "-cdrom".
For the momemt, it supports only one bus, but more can be added easily. --- hw/lsi53c895a.c | 3 -- hw/pc.c | 16 ++-------- hw/realview.c | 6 ++-- hw/versatilepb.c | 6 ++-- vl.c | 83 +++++++++++++++++++++++++++++++++++++++++++++-------- vl.h | 7 ++++- 6 files changed, 86 insertions(+), 35 deletions(-) diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c index e9866ba..98413d5 100644 --- a/hw/lsi53c895a.c +++ b/hw/lsi53c895a.c @@ -149,9 +149,6 @@ do { fprintf(stderr, "lsi_scsi: error: " fmt , ##args);} while (0) #define PHASE_MI 7 #define PHASE_MASK 7 -/* The HBA is ID 7, so for simplicitly limit to 7 devices. */ -#define LSI_MAX_DEVS 7 - /* Maximum length of MSG IN data. */ #define LSI_MAX_MSGIN_LEN 8 diff --git a/hw/pc.c b/hw/pc.c index c561cbf..a8898eb 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -921,23 +921,15 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, if (i440fx_state) { i440fx_init_memory_mappings(i440fx_state); } -#if 0 - /* ??? Need to figure out some way for the user to - specify SCSI devices. */ + if (pci_enabled) { void *scsi; - BlockDriverState *bdrv; scsi = lsi_scsi_init(pci_bus, -1); - bdrv = bdrv_new("scsidisk"); - bdrv_open(bdrv, "scsi_disk.img", 0); - lsi_scsi_attach(scsi, bdrv, -1); - bdrv = bdrv_new("scsicd"); - bdrv_open(bdrv, "scsi_cd.iso", 0); - bdrv_set_type_hint(bdrv, BDRV_TYPE_CDROM); - lsi_scsi_attach(scsi, bdrv, -1); + for (i = 0; i < LSI_MAX_DEVS; i++) + if (bs_table[MAX_DISKS + i]) + lsi_scsi_attach(scsi, bs_table[MAX_DISKS + i], i); } -#endif } static void pc_init_pci(int ram_size, int vga_ram_size, int boot_device, diff --git a/hw/realview.c b/hw/realview.c index 375f78a..e091cbb 100644 --- a/hw/realview.c +++ b/hw/realview.c @@ -64,9 +64,9 @@ static void realview_init(int ram_size, int vga_ram_size, int boot_device, usb_ohci_init_pci(pci_bus, 3, -1); } scsi_hba = lsi_scsi_init(pci_bus, -1); - for (n = 0; n < MAX_DISKS; n++) { - if (bs_table[n]) { - lsi_scsi_attach(scsi_hba, bs_table[n], n); + for (n = 0; n < LSI_MAX_DEVS; n++) { + if (bs_table[MAX_DISKS + n]) { + lsi_scsi_attach(scsi_hba, bs_table[MAX_DISKS + n], n); } } for(n = 0; n < nb_nics; n++) { diff --git a/hw/versatilepb.c b/hw/versatilepb.c index 2e3dedd..fbbe989 100644 --- a/hw/versatilepb.c +++ b/hw/versatilepb.c @@ -198,9 +198,9 @@ static void versatile_init(int ram_size, int vga_ram_size, int boot_device, usb_ohci_init_pci(pci_bus, 3, -1); } scsi_hba = lsi_scsi_init(pci_bus, -1); - for (n = 0; n < MAX_DISKS; n++) { - if (bs_table[n]) { - lsi_scsi_attach(scsi_hba, bs_table[n], n); + for (n = 0; n < LSI_MAX_DEVS; n++) { + if (bs_table[MAX_DISKS + n]) { + lsi_scsi_attach(scsi_hba, bs_table[MAX_DISKS + n], n); } } diff --git a/vl.c b/vl.c index 8408ce4..d5b0738 100644 --- a/vl.c +++ b/vl.c @@ -149,9 +149,9 @@ char phys_ram_file[1024]; void *ioport_opaque[MAX_IOPORTS]; IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS]; IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS]; -/* Note: bs_table[MAX_DISKS] is a dummy block driver if none available +/* Note: bs_table[MAX_DISKS + LSI_MAX_DEVS] is a dummy block driver if none available to store the VM snapshots */ -BlockDriverState *bs_table[MAX_DISKS + 1], *fd_table[MAX_FD]; +BlockDriverState *bs_table[MAX_DISKS + LSI_MAX_DEVS + 1], *fd_table[MAX_FD]; BlockDriverState *pflash_table[MAX_PFLASH]; BlockDriverState *sd_bdrv; BlockDriverState *mtd_bdrv; @@ -4701,6 +4701,16 @@ void do_info_network(void) } } +#if defined(TARGET_ARM) +#define DEFAULT_DISK_BUS 0 +#define DEFAULT_DISK_UNIT 0 +#define DEFAULT_DISK_IF "scsi" +#else +#define DEFAULT_DISK_BUS 0 +#define DEFAULT_DISK_UNIT 0 +#define DEFAULT_DISK_IF "ide" +#endif + static int disk_init(const char *str, int snapshot) { char buf[16]; @@ -4723,7 +4733,7 @@ static int disk_init(const char *str, int snapshot) bus_id = -1; unit_id = -1; translation = BIOS_ATA_TRANSLATION_AUTO; - pstrcpy(interface, sizeof(interface), "ide"); + pstrcpy(interface, sizeof(interface), DEFAULT_DISK_IF); if (get_param_value(buf, sizeof(buf), "bus", p)) { bus_id = strtol(buf, NULL, 0); @@ -4770,7 +4780,7 @@ static int disk_init(const char *str, int snapshot) } if (strcmp(interface, "ide") == 0) { - static int disk_index = -1; + static int disk_index = DEFAULT_DISK_BUS * 2 + DEFAULT_DISK_UNIT - 1; disk_index++; @@ -4801,7 +4811,33 @@ static int disk_init(const char *str, int snapshot) } return 0; } else if (strcmp(interface, "scsi") == 0) { - /* TODO */ + static int disk_index = DEFAULT_DISK_BUS * LSI_MAX_DEVS + DEFAULT_DISK_UNIT - 1; + + disk_index++; + + if (bus_id == -1) { + bus_id = disk_index / LSI_MAX_DEVS; + if (unit_id == -1) + unit_id = disk_index % LSI_MAX_DEVS; + } else if (unit_id == -1) + unit_id = 0; + + disk_index = bus_id * LSI_MAX_DEVS + unit_id; + + snprintf(buf, sizeof(buf), "sd%c", disk_index + 'a'); + + disk_index += MAX_DISKS; + + bs_table[disk_index] = bdrv_new(buf); + + if (bdrv_open(bs_table[disk_index], file, + snapshot ? BDRV_O_SNAPSHOT : 0) < 0) { + fprintf(stderr, "qemu: could not open hard disk image '%s'\n", + file); + return -1; + } + + return 0; } fprintf(stderr, "unsupported bus type '%s' for cdrom '%s'\n", @@ -4809,12 +4845,18 @@ static int disk_init(const char *str, int snapshot) return -1; } +#if defined(TARGET_PPC) #define MAX_CDROMS 4 -#ifdef TARGET_PPC #define DEFAULT_CDROM_BUS 0 #define DEFAULT_CDROM_UNIT 1 #define DEFAULT_CDROM_IF "ide" +#elif defined(TARGET_ARM) +#define MAX_CDROMS 7 +#define DEFAULT_CDROM_BUS 0 +#define DEFAULT_CDROM_UNIT 3 +#define DEFAULT_CDROM_IF "scsi" #else +#define MAX_CDROMS 4 #define DEFAULT_CDROM_BUS 1 #define DEFAULT_CDROM_UNIT 0 #define DEFAULT_CDROM_IF "ide" @@ -4874,7 +4916,21 @@ static int cdrom_init(const char *str) } return 0; } else if (strcmp(interface, "scsi") == 0) { - /* TODO */ + int cdrom_index = bus_id * LSI_MAX_DEVS + unit_id; + + snprintf(buf, sizeof(buf), "sd%c", cdrom_index + 'a'); + + cdrom_index += MAX_DISKS; + bs_table[cdrom_index] = bdrv_new(buf); + bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM); + + if (bdrv_open(bs_table[cdrom_index], file, 0) < 0) { + fprintf(stderr, "qemu: could not open hard disk image '%s'\n", + file); + return -1; + } + + return 0; } fprintf(stderr, "unsupported bus type '%s' for cdrom '%s'\n", @@ -7855,7 +7911,7 @@ int main(int argc, char **argv) if (r[0] != '-') { hda_index = nb_disks; snprintf(disks[nb_disks], sizeof(disks[0]), - "%s,bus=0,unit=0", argv[optind++]); + "%s,bus=0,unit=0,if=%s", argv[optind++], DEFAULT_DISK_IF); nb_disks++; } else { const QEMUOption *popt; @@ -7923,11 +7979,11 @@ int main(int argc, char **argv) hda_index = nb_disks; if (cyls == 0) snprintf(disks[nb_disks], sizeof(disks[0]), - "%s,bus=0,unit=0", optarg); + "%s,bus=0,unit=0,if=%s", optarg, DEFAULT_DISK_IF); else { snprintf(disks[nb_disks], sizeof(disks[0]), - "%s,bus=0,unit=0,cyls=%d,heads=%d,secs=%d%s", - optarg, cyls, heads, secs, + "%s,bus=0,unit=0,if=%s,cyls=%d,heads=%d,secs=%d%s", + optarg, DEFAULT_DISK_IF, cyls, heads, secs, translation == BIOS_ATA_TRANSLATION_LBA ? ",trans=lba" : translation == BIOS_ATA_TRANSLATION_NONE ? @@ -7946,8 +8002,9 @@ int main(int argc, char **argv) } hd_index = popt->index - QEMU_OPTION_hda; snprintf(disks[nb_disks], sizeof(disks[0]), - "%s,bus=%d,unit=%d", optarg, - hd_index / 2, hd_index % 2); + "%s,bus=%d,unit=%d,if=%s", optarg, + hd_index / 2, hd_index % 2, + DEFAULT_DISK_IF); nb_disks++; } break; diff --git a/vl.h b/vl.h index 681dd91..0646b3c 100644 --- a/vl.h +++ b/vl.h @@ -989,10 +989,15 @@ void do_info_vnc(void); /* x_keymap.c */ extern uint8_t _translate_keycode(const int key); +/* lsi53c895a.c */ + +/* The HBA is ID 7, so for simplicitly limit to 7 devices. */ +#define LSI_MAX_DEVS 7 + /* ide.c */ #define MAX_DISKS 4 -extern BlockDriverState *bs_table[MAX_DISKS + 1]; +extern BlockDriverState *bs_table[MAX_DISKS + LSI_MAX_DEVS + 1]; extern BlockDriverState *sd_bdrv; extern BlockDriverState *mtd_bdrv; -- 1.4.4.4