From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Iu1zn-0006f4-LT for qemu-devel@nongnu.org; Mon, 19 Nov 2007 03:28:44 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Iu1zh-0006dG-4n for qemu-devel@nongnu.org; Mon, 19 Nov 2007 03:28:41 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Iu1zf-0006cY-GG for qemu-devel@nongnu.org; Mon, 19 Nov 2007 03:28:35 -0500 Received: from mx20.gnu.org ([199.232.41.8]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Iu1ze-0002Ak-BG for qemu-devel@nongnu.org; Mon, 19 Nov 2007 03:28:35 -0500 Received: from ecfrec.frec.bull.fr ([129.183.4.8]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Iu1xe-0001lp-3R for qemu-devel@nongnu.org; Mon, 19 Nov 2007 03:26:31 -0500 Received: from localhost (localhost [127.0.0.1]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id 4AAF119D975 for ; Mon, 19 Nov 2007 09:24:49 +0100 (CET) Received: from ecfrec.frec.bull.fr ([127.0.0.1]) by localhost (ecfrec.frec.bull.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 30358-10 for ; Mon, 19 Nov 2007 09:24:44 +0100 (CET) Received: from ecn002.frec.bull.fr (ecn002.frec.bull.fr [129.183.4.6]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id 7FFCA19D948 for ; Mon, 19 Nov 2007 09:24:44 +0100 (CET) In-Reply-To: Date: Mon, 19 Nov 2007 09:24:26 +0100 Message-Id: <11954606662783@bull.net> Mime-Version: 1.0 From: Laurent Vivier Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH][UPDATE3] Add -drive parameter Reply-To: Laurent Vivier , qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org This is an update with Qemu CVS tree and comments from Blue Swirl. This patch introduces a new parameter allowing to define drives. The new parameter is "-drive": -drive [file=3Dfile][,if=3Dtype][,bus=3Dn][,unit=3Dm][,media=3Dd][ind= ex=3Di][,cyls=3Dc,heads=3Dh,secs=3Ds[,trans=3Dt]][snapshot=3Don|off] where: file is the disk image type is the interface type (ide, scsi, sd, mtd, floppy, pflash) n is the bus number of the given type m is the unit number on the given bus d is the type of the media (disk, cdrom) c,h,s,t are the parameters usually given by -hdachs snapshot allows to enable or not the snapshot for this disk i is an index number within the given type (replace bus,unit) "-cdrom file" is an alias for "-drive file=3Dfile,index=3D2,media=3Dcdrom= " "-hda file" is an alias for "-drive file=3Dfile,index=3D0,media=3Ddisk" "-hdb file" is an alias for "-drive file=3Dfile,index=3D1,media=3Ddisk" "-hdc file" is an alias for "-drive file=3Dfile,index=3D2,media=3Ddisk" "-hdd file" is an alias for "-drive file=3Dfile,index=3D3,media=3Ddisk" "-hda file -hdachs a,b,c" is an alias for=20 "-drive file=3Dfile,index=3D0,cyls=3Da,heads=3Db,secs=3D= c" You can also define a cdrom on the slace of ide0 with: "-drive file=3Dfile,if=3Dide,index=3D1,media=3Dcdrom" You can define an empty cdrom: "-drive if=3Dide,index=3D1,media=3Dcdrom" "-drive file=3Dfile,if=3Dscsi,bus=3D0,unit=3D6" allows to connect the dis= k image file=20 to the scsi bus 0 with the unit id 6. if there is no SCSI disk, the SCSI interface is not created. It also defines the default interface type to "scsi" for targets "realview", "SS-5", "SS-10", "versatilepb", "versatileab" to keep old behavior, where "-hda" is a SCSI disk. "-fda file" is an alias for "-drive file=3Dfile,index=3D0,if=3Dfloppy" "-fdb file" is an alias for "-drive file=3Dfile,index=3D1,if=3Dfloppy" "-pflash file" is an alias for "-drive file=3Dfile,if=3Dpflash" "-mtdblock file" is an alias for "-drive file=3Dfile,if=3Dmtd" "-sd file" becomes the alias of "-drive file=3Dfile,if=3Dsd" "-drive file=3Da -drive file=3Db" will be interpreted like "-hda a -hdb b= " --- hw/esp.c | 10 - hw/integratorcp.c | 8 hw/lsi53c895a.c | 3 hw/mips_malta.c | 15 + hw/mips_pica61.c | 21 +- hw/mips_r4k.c | 17 + hw/nand.c | 2 hw/omap_mmc.c | 2 hw/pc.c | 65 ++++-- hw/ppc405_boards.c | 29 +- hw/ppc_chrp.c | 17 + hw/ppc_oldworld.c | 31 ++- hw/ppc_prep.c | 27 ++ hw/pxa2xx_mmci.c | 3 hw/realview.c | 17 + hw/spitz.c | 9 hw/esp.c | 10=20 hw/gumstix.c | 6=20 hw/integratorcp.c | 8=20 hw/lsi53c895a.c | 3=20 hw/mips_malta.c | 20 + hw/mips_pica61.c | 29 ++ hw/mips_r4k.c | 22 + hw/nand.c | 8=20 hw/omap.c | 9=20 hw/pc.c | 70 +++-- hw/pci.h | 1=20 hw/ppc405_boards.c | 29 +- hw/ppc_chrp.c | 21 + hw/ppc_oldworld.c | 35 ++ hw/ppc_prep.c | 32 ++ hw/pxa2xx.c | 20 + hw/realview.c | 21 + hw/spitz.c | 9=20 hw/sun4m.c | 29 +- hw/sun4m.h | 3=20 hw/sun4u.c | 29 ++ hw/versatilepb.c | 22 + monitor.c | 11=20 sysemu.h | 27 +- vl.c | 655 +++++++++++++++++++++++++++++++++++++---------= ------- 25 files changed, 830 insertions(+), 299 deletions(-) Index: qemu/vl.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/vl.c 2007-11-19 09:00:41.000000000 +0100 +++ qemu/vl.c 2007-11-19 09:01:01.000000000 +0100 @@ -164,12 +164,10 @@ 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: drives_table[MAX_DRIVES] is a dummy block driver if none availa= ble to store the VM snapshots */ -BlockDriverState *bs_table[MAX_DISKS + 1], *fd_table[MAX_FD]; -BlockDriverState *pflash_table[MAX_PFLASH]; -BlockDriverState *sd_bdrv; -BlockDriverState *mtd_bdrv; +DriveInfo drives_table[MAX_DRIVES+1]; +int nb_drives; /* point to the block driver where the snapshots are managed */ BlockDriverState *bs_snapshots; int vga_ram_size; @@ -233,6 +231,8 @@ int alt_grab =3D 0; unsigned int nb_prom_envs =3D 0; const char *prom_envs[MAX_PROM_ENVS]; #endif +int nb_drives_opt; +char drives_opt[MAX_DRIVES][1024]; =20 #define TFR(expr) do { if ((expr) !=3D -1) break; } while (errno =3D=3D = EINTR) =20 @@ -1749,12 +1749,9 @@ static int mux_proc_byte(CharDriverState case 's': { int i; - for (i =3D 0; i < MAX_DISKS; i++) { - if (bs_table[i]) - bdrv_commit(bs_table[i]); + for (i =3D 0; i < nb_drives; i++) { + bdrv_commit(drives_table[i].bdrv); } - if (mtd_bdrv) - bdrv_commit(mtd_bdrv); } break; case 'b': @@ -4518,38 +4515,51 @@ static int net_socket_mcast_init(VLANSta =20 } =20 +static const char *get_word(char *buf, int buf_size, const char *p) +{ + char *q; + int substring; + + substring =3D 0; + q =3D buf; + while (*p !=3D '\0') { + if (*p =3D=3D '\\') { + p++; + if (*p =3D=3D '\0') + break; + } else if (*p =3D=3D '\"') { + substring =3D !substring; + p++; + continue; + } else if (!substring && (*p =3D=3D ',' || *p =3D=3D '=3D')) + break; + if (q && (q - buf) < buf_size - 1) + *q++ =3D *p; + p++; + } + if (q) + *q =3D '\0'; + + return p; +} + static int get_param_value(char *buf, int buf_size, const char *tag, const char *str) { const char *p; - char *q; char option[128]; =20 p =3D str; for(;;) { - q =3D option; - while (*p !=3D '\0' && *p !=3D '=3D') { - if ((q - option) < sizeof(option) - 1) - *q++ =3D *p; - p++; - } - *q =3D '\0'; + p =3D get_word(option, sizeof(option), p); if (*p !=3D '=3D') break; p++; if (!strcmp(tag, option)) { - q =3D buf; - while (*p !=3D '\0' && *p !=3D ',') { - if ((q - buf) < buf_size - 1) - *q++ =3D *p; - p++; - } - *q =3D '\0'; - return q - buf; + (void)get_word(buf, buf_size, p); + return strlen(buf); } else { - while (*p !=3D '\0' && *p !=3D ',') { - p++; - } + p =3D get_word(NULL, 0, p); } if (*p !=3D ',') break; @@ -4558,6 +4568,32 @@ static int get_param_value(char *buf, in return 0; } =20 +static int check_params(char *buf, int buf_size, + char **params, const char *str) +{ + const char *p; + int i; + + p =3D str; + for(;;) { + p =3D get_word(buf, buf_size, p); + if (*p !=3D '=3D') + return -1; + p++; + for(i =3D 0; params[i] !=3D NULL; i++) + if (!strcmp(params[i], buf)) + break; + if (params[i] =3D=3D NULL) + return -1; + p =3D get_word(NULL, 0, p); + if (*p !=3D ',') + break; + p++; + } + return 0; +} + + static int net_client_init(const char *str) { const char *p; @@ -4708,6 +4744,323 @@ void do_info_network(void) } } =20 +#define HD_ALIAS "file=3D\"%s\",index=3D%d,media=3Ddisk" +#ifdef TARGET_PPC +#define CDROM_ALIAS "index=3D1,media=3Dcdrom" +#else +#define CDROM_ALIAS "index=3D2,media=3Dcdrom" +#endif +#define FD_ALIAS "index=3D%d,if=3Dfloppy" +#define PFLASH_ALIAS "file=3D\"%s\",if=3Dpflash" +#define MTD_ALIAS "file=3D\"%s\",if=3Dmtd" +#define SD_ALIAS "file=3D\"%s\",if=3Dsd" + +static int drive_add(const char *fmt, ...) +{ + va_list ap; + + if (nb_drives_opt >=3D MAX_DRIVES) { + fprintf(stderr, "qemu: too many drives\n"); + exit(1); + } + + va_start(ap, fmt); + vsnprintf(drives_opt[nb_drives_opt], sizeof(drives_opt[0]), fmt, ap)= ; + va_end(ap); + + return nb_drives_opt++; +} + +int drive_get_index(BlockInterfaceType interface, int bus, int unit) +{ + int index; + + /* seek interface, bus and unit */ + + for (index =3D 0; index < nb_drives; index++) + if (drives_table[index].interface =3D=3D interface && + drives_table[index].bus =3D=3D bus && + drives_table[index].unit =3D=3D unit) + return index; + + return -1; +} + +int drive_get_max_bus(BlockInterfaceType interface) +{ + int max_bus; + int index; + + max_bus =3D -1; + for (index =3D 0; index < nb_drives; index++) { + if(drives_table[index].interface =3D=3D interface && + drives_table[index].bus > max_bus) + max_bus =3D drives_table[index].bus; + } + return max_bus; +} + +static int drive_init(const char *str, int snapshot, QEMUMachine *machin= e) +{ + char buf[128]; + char file[1024]; + BlockInterfaceType interface; + enum { MEDIA_DISK, MEDIA_CDROM } media; + int bus_id, unit_id; + int cyls, heads, secs, translation; + BlockDriverState *bdrv; + int max_devs; + int index; + char *params[] =3D { "bus", "unit", "if", "index", "cyls", "heads", + "secs", "trans", "media", "snapshot", "file", NUL= L }; + + if (check_params(buf, sizeof(buf), params, str) < 0) { + fprintf(stderr, "qemu: unknowm parameter '%s' in '%s'\n", + buf, str); + return -1; + } + + file[0] =3D 0; + cyls =3D heads =3D secs =3D 0; + bus_id =3D 0; + unit_id =3D -1; + translation =3D BIOS_ATA_TRANSLATION_AUTO; + index =3D -1; + + if (!strcmp(machine->name, "realview") || + !strcmp(machine->name, "SS-5") || + !strcmp(machine->name, "SS-10") || + !strcmp(machine->name, "SS-600MP") || + !strcmp(machine->name, "versatilepb") || + !strcmp(machine->name, "versatileab")) { + interface =3D IF_SCSI; + max_devs =3D MAX_SCSI_DEVS; + } else { + interface =3D IF_IDE; + max_devs =3D MAX_IDE_DEVS; + } + media =3D MEDIA_DISK; + + /* extract parameters */ + + if (get_param_value(buf, sizeof(buf), "bus", str)) { + bus_id =3D strtol(buf, NULL, 0); + if (bus_id < 0) { + fprintf(stderr, "qemu: '%s' invalid bus id\n", str); + return -1; + } + } + + if (get_param_value(buf, sizeof(buf), "unit", str)) { + unit_id =3D strtol(buf, NULL, 0); + if (unit_id < 0) { + fprintf(stderr, "qemu: '%s' invalid unit id\n", str); + return -1; + } + } + + if (get_param_value(buf, sizeof(buf), "if", str)) { + if (!strcmp(buf, "ide")) { + interface =3D IF_IDE; + max_devs =3D MAX_IDE_DEVS; + } else if (!strcmp(buf, "scsi")) { + interface =3D IF_SCSI; + max_devs =3D MAX_SCSI_DEVS; + } else if (!strcmp(buf, "floppy")) { + interface =3D IF_FLOPPY; + max_devs =3D 0; + } else if (!strcmp(buf, "pflash")) { + interface =3D IF_PFLASH; + max_devs =3D 0; + } else if (!strcmp(buf, "mtd")) { + interface =3D IF_MTD; + max_devs =3D 0; + } else if (!strcmp(buf, "sd")) { + interface =3D IF_SD; + max_devs =3D 0; + } else { + fprintf(stderr, "qemu: '%s' unsupported bus type '%s'\n", st= r, buf); + return -1; + } + } + + if (get_param_value(buf, sizeof(buf), "index", str)) { + index =3D strtol(buf, NULL, 0); + if (index < 0) { + fprintf(stderr, "qemu: '%s' invalid index\n", str); + return -1; + } + } + + if (get_param_value(buf, sizeof(buf), "cyls", str)) { + cyls =3D strtol(buf, NULL, 0); + } + + if (get_param_value(buf, sizeof(buf), "heads", str)) { + heads =3D strtol(buf, NULL, 0); + } + + if (get_param_value(buf, sizeof(buf), "secs", str)) { + secs =3D strtol(buf, NULL, 0); + } + + if (cyls || heads || secs) { + if (cyls < 1 || cyls > 16383) { + fprintf(stderr, "qemu: '%s' invalid physical cyls number\n",= str); + return -1; + } + if (heads < 1 || heads > 16) { + fprintf(stderr, "qemu: '%s' invalid physical heads number\n"= , str); + return -1; + } + if (secs < 1 || secs > 63) { + fprintf(stderr, "qemu: '%s' invalid physical secs number\n",= str); + return -1; + } + } + + if (get_param_value(buf, sizeof(buf), "trans", str)) { + if (!cyls) { + fprintf(stderr, + "qemu: '%s' trans must be used with cyls,heads and s= ecs\n", + str); + return -1; + } + if (!strcmp(buf, "none")) + translation =3D BIOS_ATA_TRANSLATION_NONE; + else if (!strcmp(buf, "lba")) + translation =3D BIOS_ATA_TRANSLATION_LBA; + else if (!strcmp(buf, "auto")) + translation =3D BIOS_ATA_TRANSLATION_AUTO; + else { + fprintf(stderr, "qemu: '%s' invalid translation type\n", str= ); + return -1; + } + } + + if (get_param_value(buf, sizeof(buf), "media", str)) { + if (!strcmp(buf, "disk")) { + media =3D MEDIA_DISK; + } else if (!strcmp(buf, "cdrom")) { + if (cyls || secs || heads) { + fprintf(stderr, + "qemu: '%s' invalid physical CHS format\n", str)= ; + return -1; + } + media =3D MEDIA_CDROM; + } else { + fprintf(stderr, "qemu: '%s' invalid media\n", str); + return -1; + } + } + + if (get_param_value(buf, sizeof(buf), "snapshot", str)) { + if (!strcmp(buf, "on")) + snapshot =3D 1; + else if (!strcmp(buf, "off")) + snapshot =3D 0; + else { + fprintf(stderr, "qemu: '%s' invalid snapshot option\n", str); + return -1; + } + } + + get_param_value(file, sizeof(file), "file", str); + + /* compute bus and unit according index */ + + if (index !=3D -1) { + if (bus_id !=3D 0 || unit_id !=3D -1) { + fprintf(stderr, + "qemu: '%s' index cannot be used with bus and unit\n= ", str); + return -1; + } + if (max_devs =3D=3D 0) + { + unit_id =3D index; + bus_id =3D 0; + } else { + unit_id =3D index % max_devs; + bus_id =3D index / max_devs; + } + } + + /* if user doesn't specify a unit_id, + * try to find the first free + */ + + if (unit_id =3D=3D -1) { + unit_id =3D 0; + while (drive_get_index(interface, bus_id, unit_id) !=3D -1) { + unit_id++; + if (max_devs && unit_id >=3D max_devs) { + unit_id -=3D max_devs; + bus_id++; + } + } + } + + /* check unit id */ + + if (max_devs && unit_id >=3D max_devs) { + fprintf(stderr, "qemu: '%s' unit %d too big (max is %d)\n", + str, unit_id, max_devs - 1); + return -1; + } + + /* + * ignore multiple definitions + */ + + if (drive_get_index(interface, bus_id, unit_id) !=3D -1) + return 0; + + /* init */ + + snprintf(buf, sizeof(buf), "drive%d", nb_drives); + bdrv =3D bdrv_new(buf); + drives_table[nb_drives].bdrv =3D bdrv; + drives_table[nb_drives].interface =3D interface; + drives_table[nb_drives].bus =3D bus_id; + drives_table[nb_drives].unit =3D unit_id; + nb_drives++; + + switch(interface) { + case IF_IDE: + case IF_SCSI: + switch(media) { + case MEDIA_DISK: + if (cyls !=3D 0) { + bdrv_set_geometry_hint(bdrv, cyls, heads, secs); + bdrv_set_translation_hint(bdrv, translation); + } + break; + case MEDIA_CDROM: + bdrv_set_type_hint(bdrv, BDRV_TYPE_CDROM); + break; + } + break; + case IF_SD: + /* FIXME: This isn't really a floppy, but it's a reasonable + approximation. */ + case IF_FLOPPY: + bdrv_set_type_hint(bdrv, BDRV_TYPE_FLOPPY); + break; + case IF_PFLASH: + case IF_MTD: + break; + } + if (!file[0]) + return 0; + if (bdrv_open(bdrv, file, snapshot ? BDRV_O_SNAPSHOT : 0) < 0 || + qemu_key_check(bdrv, file)) { + fprintf(stderr, "qemu: could not open disk image %s\n", + file); + return -1; + } + return 0; +} + /***********************************************************/ /* USB devices */ =20 @@ -5490,8 +5843,8 @@ static BlockDriverState *get_bs_snapshot =20 if (bs_snapshots) return bs_snapshots; - for(i =3D 0; i <=3D MAX_DISKS; i++) { - bs =3D bs_table[i]; + for(i =3D 0; i <=3D nb_drives; i++) { + bs =3D drives_table[i].bdrv; if (bdrv_can_snapshot(bs)) goto ok; } @@ -5599,8 +5952,8 @@ void do_savevm(const char *name) =20 /* create the snapshots */ =20 - for(i =3D 0; i < MAX_DISKS; i++) { - bs1 =3D bs_table[i]; + for(i =3D 0; i < nb_drives; i++) { + bs1 =3D drives_table[i].bdrv; if (bdrv_has_snapshot(bs1)) { if (must_delete) { ret =3D bdrv_snapshot_delete(bs1, old_sn->id_str); @@ -5642,8 +5995,8 @@ void do_loadvm(const char *name) saved_vm_running =3D vm_running; vm_stop(0); =20 - for(i =3D 0; i <=3D MAX_DISKS; i++) { - bs1 =3D bs_table[i]; + for(i =3D 0; i <=3D nb_drives; i++) { + bs1 =3D drives_table[i].bdrv; if (bdrv_has_snapshot(bs1)) { ret =3D bdrv_snapshot_goto(bs1, name); if (ret < 0) { @@ -5703,8 +6056,8 @@ void do_delvm(const char *name) return; } =20 - for(i =3D 0; i <=3D MAX_DISKS; i++) { - bs1 =3D bs_table[i]; + for(i =3D 0; i <=3D nb_drives; i++) { + bs1 =3D drives_table[i].bdrv; if (bdrv_has_snapshot(bs1)) { ret =3D bdrv_snapshot_delete(bs1, name); if (ret < 0) { @@ -5732,8 +6085,8 @@ void do_info_snapshots(void) return; } term_printf("Snapshot devices:"); - for(i =3D 0; i <=3D MAX_DISKS; i++) { - bs1 =3D bs_table[i]; + for(i =3D 0; i <=3D nb_drives; i++) { + bs1 =3D drives_table[i].bdrv; if (bdrv_has_snapshot(bs1)) { if (bs =3D=3D bs1) term_printf(" %s", bdrv_get_device_name(bs1)); @@ -6483,15 +6836,14 @@ static void ram_save(QEMUFile *f, void * /* find if the memory block is available on a virtual block device */ sector_num =3D -1; - for(j =3D 0; j < MAX_DISKS; j++) { - if (bs_table[j]) { - sector_num =3D bdrv_hash_find(bs_table[j], - phys_ram_base + i, BDRV_= HASH_BLOCK_SIZE); - if (sector_num >=3D 0) - break; - } + for(j =3D 0; j < nb_drives; j++) { + sector_num =3D bdrv_hash_find(drives_table[j].bdrv, + phys_ram_base + i, + BDRV_HASH_BLOCK_SIZE); + if (sector_num >=3D 0) + break; } - if (j =3D=3D MAX_DISKS) + if (j =3D=3D nb_drives) goto normal_compress; buf[0] =3D 1; buf[1] =3D j; @@ -6542,11 +6894,12 @@ static int ram_load(QEMUFile *f, void *o ram_decompress_buf(s, buf + 1, 9); bs_index =3D buf[1]; sector_num =3D be64_to_cpupu((const uint64_t *)(buf + 2)); - if (bs_index >=3D MAX_DISKS || bs_table[bs_index] =3D=3D NUL= L) { + if (bs_index >=3D nb_drives) { fprintf(stderr, "Invalid block device index %d\n", bs_in= dex); goto error; } - if (bdrv_read(bs_table[bs_index], sector_num, phys_ram_base = + i, + if (bdrv_read(drives_table[bs_index].bdrv, sector_num, + phys_ram_base + i, BDRV_HASH_BLOCK_SIZE / 512) < 0) { fprintf(stderr, "Error while reading sector %d:%" PRId64= "\n", bs_index, sector_num); @@ -7043,6 +7396,9 @@ static void help(int exitcode) "-hda/-hdb file use 'file' as IDE hard disk 0/1 image\n" "-hdc/-hdd file use 'file' as IDE hard disk 2/3 image\n" "-cdrom file use 'file' as IDE cdrom image (cdrom is ide1= master)\n" + "-drive [file=3Dfile][,if=3Dtype][,bus=3Dn][,unit=3Dm][,media=3Dd][i= ndex=3Di]\n" + " [,cyls=3Dc,heads=3Dh,secs=3Ds[,trans=3Dt]][snapshot=3D= on|off]\n" + " use 'file' as a drive image\n" "-mtdblock file use 'file' as on-board Flash memory image\n" "-sd file use 'file' as SecureDigital card image\n" "-pflash file use 'file' as a parallel flash image\n" @@ -7188,6 +7544,7 @@ enum { QEMU_OPTION_hdb, QEMU_OPTION_hdc, QEMU_OPTION_hdd, + QEMU_OPTION_drive, QEMU_OPTION_cdrom, QEMU_OPTION_mtdblock, QEMU_OPTION_sd, @@ -7277,6 +7634,7 @@ const QEMUOption qemu_options[] =3D { { "hdb", HAS_ARG, QEMU_OPTION_hdb }, { "hdc", HAS_ARG, QEMU_OPTION_hdc }, { "hdd", HAS_ARG, QEMU_OPTION_hdd }, + { "drive", HAS_ARG, QEMU_OPTION_drive }, { "cdrom", HAS_ARG, QEMU_OPTION_cdrom }, { "mtdblock", HAS_ARG, QEMU_OPTION_mtdblock }, { "sd", HAS_ARG, QEMU_OPTION_sd }, @@ -7389,16 +7747,9 @@ int qemu_key_check(BlockDriverState *bs, =20 static BlockDriverState *get_bdrv(int index) { - BlockDriverState *bs; - - if (index < 4) { - bs =3D bs_table[index]; - } else if (index < 6) { - bs =3D fd_table[index - 4]; - } else { - bs =3D NULL; - } - return bs; + if (index > nb_drives) + return NULL; + return drives_table[index].bdrv; } =20 static void read_passwords(void) @@ -7599,19 +7950,16 @@ int main(int argc, char **argv) const char *gdbstub_port; #endif uint32_t boot_devices_bitmap =3D 0; - int i, cdrom_index, pflash_index; + int i; int snapshot, linux_boot, net_boot; const char *initrd_filename; - const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD]; - const char *pflash_filename[MAX_PFLASH]; - const char *sd_filename; - const char *mtd_filename; const char *kernel_filename, *kernel_cmdline; const char *boot_devices =3D ""; DisplayState *ds =3D &display_state; int cyls, heads, secs, translation; char net_clients[MAX_NET_CLIENTS][256]; int nb_net_clients; + int hda_index; int optind; const char *r, *optarg; CharDriverState *monitor_hd; @@ -7664,15 +8012,6 @@ int main(int argc, char **argv) machine =3D first_machine; cpu_model =3D NULL; initrd_filename =3D NULL; - for(i =3D 0; i < MAX_FD; i++) - fd_filename[i] =3D NULL; - for(i =3D 0; i < MAX_DISKS; i++) - hd_filename[i] =3D NULL; - for(i =3D 0; i < MAX_PFLASH; i++) - pflash_filename[i] =3D NULL; - pflash_index =3D 0; - sd_filename =3D NULL; - mtd_filename =3D NULL; ram_size =3D DEFAULT_RAM_SIZE * 1024 * 1024; vga_ram_size =3D VGA_RAM_SIZE; #ifdef CONFIG_GDBSTUB @@ -7683,11 +8022,6 @@ int main(int argc, char **argv) nographic =3D 0; kernel_filename =3D NULL; kernel_cmdline =3D ""; -#ifdef TARGET_PPC - cdrom_index =3D 1; -#else - cdrom_index =3D 2; -#endif cyls =3D heads =3D secs =3D 0; translation =3D BIOS_ATA_TRANSLATION_AUTO; pstrcpy(monitor_device, sizeof(monitor_device), "vc"); @@ -7705,6 +8039,9 @@ int main(int argc, char **argv) usb_devices_index =3D 0; =20 nb_net_clients =3D 0; + nb_drives =3D 0; + nb_drives_opt =3D 0; + hda_index =3D -1; =20 nb_nics =3D 0; /* default mac address of the first network interface */ @@ -7715,7 +8052,7 @@ int main(int argc, char **argv) break; r =3D argv[optind]; if (r[0] !=3D '-') { - hd_filename[0] =3D argv[optind++]; + hda_index =3D drive_add(HD_ALIAS, argv[optind++], 0); } else { const QEMUOption *popt; =20 @@ -7775,29 +8112,33 @@ int main(int argc, char **argv) initrd_filename =3D optarg; break; case QEMU_OPTION_hda: + if (cyls =3D=3D 0) + hda_index =3D drive_add(HD_ALIAS, optarg, 0); + else + hda_index =3D drive_add(HD_ALIAS + ",cyls=3D%d,heads=3D%d,secs=3D%d%s", + optarg, 0, cyls, heads, secs, + translation =3D=3D BIOS_ATA_TRANSLATION_LBA= ? + ",trans=3Dlba" : + translation =3D=3D BIOS_ATA_TRANSLATION_NON= E ? + ",trans=3Dnone" : ""); + break; case QEMU_OPTION_hdb: case QEMU_OPTION_hdc: case QEMU_OPTION_hdd: - { - int hd_index; - hd_index =3D popt->index - QEMU_OPTION_hda; - hd_filename[hd_index] =3D optarg; - if (hd_index =3D=3D cdrom_index) - cdrom_index =3D -1; - } + drive_add(HD_ALIAS, optarg, popt->index - QEMU_OPTION_hda); break; + case QEMU_OPTION_drive: + drive_add("%s", optarg); + break; case QEMU_OPTION_mtdblock: - mtd_filename =3D optarg; + drive_add(MTD_ALIAS, optarg); break; case QEMU_OPTION_sd: - sd_filename =3D optarg; + drive_add(SD_ALIAS, optarg); break; case QEMU_OPTION_pflash: - if (pflash_index >=3D MAX_PFLASH) { - fprintf(stderr, "qemu: too many parallel flash image= s\n"); - exit(1); - } - pflash_filename[pflash_index++] =3D optarg; + drive_add(PFLASH_ALIAS, optarg); break; case QEMU_OPTION_snapshot: snapshot =3D 1; @@ -7836,6 +8177,17 @@ int main(int argc, char **argv) fprintf(stderr, "qemu: invalid physical CHS form= at\n"); exit(1); } + if (hda_index !=3D -1) + snprintf(drives_opt[hda_index] + + strlen(drives_opt[hda_index]), + sizeof(drives_opt[0]) - + strlen(drives_opt[hda_index]), + ",cyls=3D%d,heads=3D%d,secs=3D%d%s", + cyls, heads, secs, + translation =3D=3D BIOS_ATA_TRANSLATION_LBA ? + ",trans=3Dlba" : + translation =3D=3D BIOS_ATA_TRANSLATION_NONE ? + ",trans=3Dnone" : ""); } break; case QEMU_OPTION_nographic: @@ -7854,9 +8206,7 @@ int main(int argc, char **argv) kernel_cmdline =3D optarg; break; case QEMU_OPTION_cdrom: - if (cdrom_index >=3D 0) { - hd_filename[cdrom_index] =3D optarg; - } + drive_add("file=3D\"%s\"," CDROM_ALIAS, optarg); break; case QEMU_OPTION_boot: boot_devices =3D optarg; @@ -7890,10 +8240,9 @@ int main(int argc, char **argv) } break; case QEMU_OPTION_fda: - fd_filename[0] =3D optarg; - break; case QEMU_OPTION_fdb: - fd_filename[1] =3D optarg; + drive_add("file=3D\"%s\"," FD_ALIAS, optarg, + popt->index - QEMU_OPTION_fda); break; #ifdef TARGET_I386 case QEMU_OPTION_no_fd_bootchk: @@ -8274,20 +8623,12 @@ int main(int argc, char **argv) =20 /* XXX: this should not be: some embedded targets just have flash */ if (!linux_boot && net_boot =3D=3D 0 && - hd_filename[0] =3D=3D NULL && - (cdrom_index >=3D 0 && hd_filename[cdrom_index] =3D=3D NULL) && - fd_filename[0] =3D=3D NULL && - pflash_filename[0] =3D=3D NULL) + nb_drives_opt =3D=3D 0) help(1); =20 /* boot to floppy or the default cd if no hard disk defined yet */ if (!boot_devices[0]) { - if (hd_filename[0] !=3D NULL) - boot_devices =3D "c"; - else if (fd_filename[0] !=3D NULL) - boot_devices =3D "a"; - else - boot_devices =3D "d"; + boot_devices =3D "cad"; } setvbuf(stdout, NULL, _IOLBF, 0); =20 @@ -8364,97 +8705,23 @@ int main(int argc, char **argv) exit(1); } =20 - /* we always create the cdrom drive, even if no disk is there */ bdrv_init(); - if (cdrom_index >=3D 0) { - bs_table[cdrom_index] =3D bdrv_new("cdrom"); - bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM); - } =20 - /* open the virtual block devices */ - for(i =3D 0; i < MAX_DISKS; i++) { - if (hd_filename[i]) { - if (!bs_table[i]) { - char buf[64]; - snprintf(buf, sizeof(buf), "hd%c", i + 'a'); - bs_table[i] =3D bdrv_new(buf); - } - if (bdrv_open(bs_table[i], hd_filename[i], snapshot ? BDRV_O= _SNAPSHOT : 0) < 0) { - fprintf(stderr, "qemu: could not open hard disk image '%= s'\n", - hd_filename[i]); - exit(1); - } - if (i =3D=3D 0 && cyls !=3D 0) { - bdrv_set_geometry_hint(bs_table[i], cyls, heads, secs); - bdrv_set_translation_hint(bs_table[i], translation); - } - } - } + /* we always create the cdrom drive, even if no disk is there */ =20 - /* we always create at least one floppy disk */ - fd_table[0] =3D bdrv_new("fda"); - bdrv_set_type_hint(fd_table[0], BDRV_TYPE_FLOPPY); - - for(i =3D 0; i < MAX_FD; i++) { - if (fd_filename[i]) { - if (!fd_table[i]) { - char buf[64]; - snprintf(buf, sizeof(buf), "fd%c", i + 'a'); - fd_table[i] =3D bdrv_new(buf); - bdrv_set_type_hint(fd_table[i], BDRV_TYPE_FLOPPY); - } - if (fd_filename[i][0] !=3D '\0') { - if (bdrv_open(fd_table[i], fd_filename[i], - snapshot ? BDRV_O_SNAPSHOT : 0) < 0) { - fprintf(stderr, "qemu: could not open floppy disk im= age '%s'\n", - fd_filename[i]); - exit(1); - } - } - } - } + if (nb_drives_opt < MAX_DRIVES) + drive_add(CDROM_ALIAS); =20 - /* Open the virtual parallel flash block devices */ - for(i =3D 0; i < MAX_PFLASH; i++) { - if (pflash_filename[i]) { - if (!pflash_table[i]) { - char buf[64]; - snprintf(buf, sizeof(buf), "fl%c", i + 'a'); - pflash_table[i] =3D bdrv_new(buf); - } - if (bdrv_open(pflash_table[i], pflash_filename[i], - snapshot ? BDRV_O_SNAPSHOT : 0) < 0) { - fprintf(stderr, "qemu: could not open flash image '%s'\n= ", - pflash_filename[i]); - exit(1); - } - } - } + /* we always create at least on floppy */ =20 - sd_bdrv =3D bdrv_new ("sd"); - /* FIXME: This isn't really a floppy, but it's a reasonable - approximation. */ - bdrv_set_type_hint(sd_bdrv, BDRV_TYPE_FLOPPY); - if (sd_filename) { - if (bdrv_open(sd_bdrv, sd_filename, - snapshot ? BDRV_O_SNAPSHOT : 0) < 0) { - fprintf(stderr, "qemu: could not open SD card image %s\n", - sd_filename); - } else - qemu_key_check(sd_bdrv, sd_filename); - } + if (nb_drives_opt < MAX_DRIVES) + drive_add(FD_ALIAS, 0); =20 - if (mtd_filename) { - mtd_bdrv =3D bdrv_new ("mtd"); - if (bdrv_open(mtd_bdrv, mtd_filename, - snapshot ? BDRV_O_SNAPSHOT : 0) < 0 || - qemu_key_check(mtd_bdrv, mtd_filename)) { - fprintf(stderr, "qemu: could not open Flash image %s\n", - mtd_filename); - bdrv_delete(mtd_bdrv); - mtd_bdrv =3D 0; - } - } + /* open the virtual block devices */ + + for(i =3D 0; i < nb_drives_opt; i++) + if (drive_init(drives_opt[i], snapshot, machine) =3D=3D -1) + exit(1); =20 register_savevm("timer", 0, 2, timer_save, timer_load, NULL); register_savevm("ram", 0, 2, ram_save, ram_load, NULL); Index: qemu/monitor.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/monitor.c 2007-11-19 09:00:26.000000000 +0100 +++ qemu/monitor.c 2007-11-19 09:01:01.000000000 +0100 @@ -215,16 +215,11 @@ static void do_commit(const char *device int i, all_devices; =20 all_devices =3D !strcmp(device, "all"); - for (i =3D 0; i < MAX_DISKS; i++) { - if (bs_table[i]) { + for (i =3D 0; i < nb_drives; i++) { if (all_devices || - !strcmp(bdrv_get_device_name(bs_table[i]), device)) - bdrv_commit(bs_table[i]); - } + !strcmp(bdrv_get_device_name(drives_table[i].bdrv), devi= ce)) + bdrv_commit(drives_table[i].bdrv); } - if (mtd_bdrv) - if (all_devices || !strcmp(bdrv_get_device_name(mtd_bdrv), devic= e)) - bdrv_commit(mtd_bdrv); } =20 static void do_info(const char *item) Index: qemu/hw/mips_pica61.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/mips_pica61.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/mips_pica61.c 2007-11-19 09:01:01.000000000 +0100 @@ -44,6 +44,9 @@ =20 #define VIRT_TO_PHYS_ADDEND (-((int64_t)(int32_t)0x80000000)) =20 +#define MAX_IDE_BUS 2 +#define MAX_FD 2 + static const int ide_iobase[2] =3D { 0x1f0, 0x170 }; static const int ide_iobase2[2] =3D { 0x3f6, 0x376 }; static const int ide_irq[2] =3D { 14, 15 }; @@ -72,6 +75,8 @@ void mips_pica61_init (int ram_size, int int i; int available_ram; qemu_irq *i8259; + int index; + BlockDriverState *fd[MAX_FD]; =20 /* init CPUs */ if (cpu_model =3D=3D NULL) { @@ -141,9 +146,20 @@ void mips_pica61_init (int ram_size, int i8042_mm_init(i8259[6], i8259[7], 0x80005060, 0); =20 /* IDE controller */ - for(i =3D 0; i < 2; i++) + + if (drive_get_max_bus(IF_IDE) >=3D MAX_IDE_BUS) { + fprintf(stderr, "qemu: too many IDE bus\n"); + exit(1); + } + + for(i =3D 0; i < MAX_IDE_BUS; i++) { + int hd0, hd1; + hd0 =3D drive_get_index(IF_IDE, i, 0); + hd1 =3D drive_get_index(IF_IDE, i, 1); isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]], - bs_table[2 * i], bs_table[2 * i + 1]); + hd0 =3D=3D -1 ? NULL : drives_table[hd0].bdrv, + hd1 =3D=3D -1 ? NULL : drives_table[hd1].bdrv); + } =20 /* Network controller */ /* FIXME: missing NS SONIC DP83932 */ @@ -152,7 +168,14 @@ void mips_pica61_init (int ram_size, int /* FIXME: missing NCR 53C94 */ =20 /* ISA devices (floppy, serial, parallel) */ - fdctrl_init(i8259[1], 1, 1, 0x80003000, fd_table); + + for (i =3D 0; i < MAX_FD; i++) { + index =3D drive_get_index(IF_FLOPPY, 0, i); + if (index =3D=3D -1) + continue; + fd[i] =3D drives_table[index].bdrv; + } + fdctrl_init(i8259[1], 1, 1, 0x80003000, fd); for(i =3D 0; i < MAX_SERIAL_PORTS; i++) { if (serial_hds[i]) { serial_mm_init(serial_base[i], 0, i8259[serial_irq[i]], seri= al_hds[i], 1); Index: qemu/hw/mips_r4k.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/mips_r4k.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/mips_r4k.c 2007-11-19 09:01:01.000000000 +0100 @@ -25,6 +25,8 @@ =20 #define VIRT_TO_PHYS_ADDEND (-((int64_t)(int32_t)0x80000000)) =20 +#define MAX_IDE_BUS 2 + static const int ide_iobase[2] =3D { 0x1f0, 0x170 }; static const int ide_iobase2[2] =3D { 0x3f6, 0x376 }; static const int ide_irq[2] =3D { 14, 15 }; @@ -155,6 +157,8 @@ void mips_r4k_init (int ram_size, int vg RTCState *rtc_state; int i; qemu_irq *i8259; + int index; + BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; =20 /* init CPUs */ if (cpu_model =3D=3D NULL) { @@ -245,9 +249,23 @@ void mips_r4k_init (int ram_size, int vg } } =20 - for(i =3D 0; i < 2; i++) + if (drive_get_max_bus(IF_IDE) >=3D MAX_IDE_BUS) { + fprintf(stderr, "qemu: too many IDE bus\n"); + exit(1); + } + + for(i =3D 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { + index =3D drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_= DEVS); + if (index !=3D -1) + hd[i] =3D drives_table[index].bdrv; + else + hd[i] =3D NULL; + } + + for(i =3D 0; i < MAX_IDE_BUS; i++) isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]], - bs_table[2 * i], bs_table[2 * i + 1]); + hd[MAX_IDE_DEVS * i], + hd[MAX_IDE_DEVS * i + 1]); =20 i8042_init(i8259[1], i8259[12], 0x60); ds1225y_init(0x9000, "nvram"); Index: qemu/hw/pc.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/pc.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/pc.c 2007-11-19 09:01:01.000000000 +0100 @@ -42,6 +42,8 @@ /* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. = */ #define ACPI_DATA_SIZE 0x10000 =20 +#define MAX_IDE_BUS 2 + static fdctrl_t *floppy_controller; static RTCState *rtc_state; static PITState *pit; @@ -381,8 +383,10 @@ static void generate_bootsect(uint32_t g { uint8_t bootsect[512], *p; int i; + int hda; =20 - if (bs_table[0] =3D=3D NULL) { + hda =3D drive_get_index(IF_IDE, 0, 0); + if (hda =3D=3D -1) { fprintf(stderr, "A disk image must be given for 'hda' when booting " "a Linux kernel\n"); exit(1); @@ -391,7 +395,7 @@ static void generate_bootsect(uint32_t g memset(bootsect, 0, sizeof(bootsect)); =20 /* Copy the MSDOS partition table if possible */ - bdrv_read(bs_table[0], 0, bootsect, 1); + bdrv_read(drives_table[hda].bdrv, 0, bootsect, 1); =20 /* Make sure we have a partition signature */ bootsect[510] =3D 0x55; @@ -428,7 +432,7 @@ static void generate_bootsect(uint32_t g *p++ =3D segs[1]; /* CS */ *p++ =3D segs[1] >> 8; =20 - bdrv_set_boot_sector(bs_table[0], bootsect, sizeof(bootsect)); + bdrv_set_boot_sector(drives_table[hda].bdrv, bootsect, sizeof(bootse= ct)); } =20 static int load_kernel(const char *filename, uint8_t *addr, @@ -709,6 +713,9 @@ static void pc_init1(int ram_size, int v NICInfo *nd; qemu_irq *cpu_irq; qemu_irq *i8259; + int index; + BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; + BlockDriverState *fd[MAX_FD]; =20 linux_boot =3D (kernel_filename !=3D NULL); =20 @@ -926,12 +933,25 @@ static void pc_init1(int ram_size, int v } } =20 + if (drive_get_max_bus(IF_IDE) >=3D MAX_IDE_BUS) { + fprintf(stderr, "qemu: too many IDE bus\n"); + exit(1); + } + + for(i =3D 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { + index =3D drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_= DEVS); + if (index !=3D -1) + hd[i] =3D drives_table[index].bdrv; + else + hd[i] =3D NULL; + } + if (pci_enabled) { - pci_piix3_ide_init(pci_bus, bs_table, piix3_devfn + 1, i8259); + pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1, i8259); } else { - for(i =3D 0; i < 2; i++) { + for(i =3D 0; i < MAX_IDE_BUS; i++) { isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]= ], - bs_table[2 * i], bs_table[2 * i + 1]); + hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]); } } =20 @@ -941,9 +961,16 @@ static void pc_init1(int ram_size, int v audio_init(pci_enabled ? pci_bus : NULL, i8259); #endif =20 - floppy_controller =3D fdctrl_init(i8259[6], 2, 0, 0x3f0, fd_table); + for(i =3D 0; i < MAX_FD; i++) { + index =3D drive_get_index(IF_FLOPPY, 0, i); + if (index !=3D -1) + fd[i] =3D drives_table[index].bdrv; + else + fd[i] =3D NULL; + } + floppy_controller =3D fdctrl_init(i8259[6], 2, 0, 0x3f0, fd); =20 - cmos_init(ram_size, boot_device, bs_table); + cmos_init(ram_size, boot_device, hd); =20 if (pci_enabled && usb_enabled) { usb_uhci_piix3_init(pci_bus, piix3_devfn + 2); @@ -963,23 +990,24 @@ static void pc_init1(int ram_size, int v 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) { + int max_bus; + int bus, unit; void *scsi; - BlockDriverState *bdrv; =20 - scsi =3D lsi_scsi_init(pci_bus, -1); - bdrv =3D bdrv_new("scsidisk"); - bdrv_open(bdrv, "scsi_disk.img", 0); - lsi_scsi_attach(scsi, bdrv, -1); - bdrv =3D bdrv_new("scsicd"); - bdrv_open(bdrv, "scsi_cd.iso", 0); - bdrv_set_type_hint(bdrv, BDRV_TYPE_CDROM); - lsi_scsi_attach(scsi, bdrv, -1); + max_bus =3D drive_get_max_bus(IF_SCSI); + + for (bus =3D 0; bus <=3D max_bus; bus++) { + scsi =3D lsi_scsi_init(pci_bus, -1); + for (unit =3D 0; unit < LSI_MAX_DEVS; unit++) { + index =3D drive_get_index(IF_SCSI, bus, unit); + if (index =3D=3D -1) + continue; + lsi_scsi_attach(scsi, drives_table[index].bdrv, unit); + } + } } -#endif } =20 static void pc_init_pci(int ram_size, int vga_ram_size, Index: qemu/hw/ppc_prep.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/ppc_prep.c 2007-11-19 09:00:42.000000000 +0100 +++ qemu/hw/ppc_prep.c 2007-11-19 09:01:01.000000000 +0100 @@ -38,6 +38,8 @@ /* SMP is not enabled, for now */ #define MAX_CPUS 1 =20 +#define MAX_IDE_BUS 2 + #define BIOS_FILENAME "ppc_rom.bin" #define KERNEL_LOAD_ADDR 0x01000000 #define INITRD_LOAD_ADDR 0x01800000 @@ -548,6 +550,9 @@ static void ppc_prep_init (int ram_size, PCIBus *pci_bus; qemu_irq *i8259; int ppc_boot_device; + int index; + BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; + BlockDriverState *fd[MAX_FD]; =20 sysctrl =3D qemu_mallocz(sizeof(sysctrl_t)); if (sysctrl =3D=3D NULL) @@ -672,16 +677,37 @@ static void ppc_prep_init (int ram_size, } } =20 - for(i =3D 0; i < 2; i++) { + if (drive_get_max_bus(IF_IDE) >=3D MAX_IDE_BUS) { + fprintf(stderr, "qemu: too many IDE bus\n"); + exit(1); + } + + for(i =3D 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { + index =3D drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_= DEVS); + if (index !=3D -1) + hd[i] =3D drives_table[index].bdrv; + else + hd[i] =3D NULL; + } + + for(i =3D 0; i < MAX_IDE_BUS; i++) { isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]], - bs_table[2 * i], bs_table[2 * i + 1]); + hd[2 * i], + hd[2 * i + 1]); } i8042_init(i8259[1], i8259[12], 0x60); DMA_init(1); // AUD_init(); // SB16_init(); =20 - fdctrl_init(i8259[6], 2, 0, 0x3f0, fd_table); + for(i =3D 0; i < MAX_FD; i++) { + index =3D drive_get_index(IF_FLOPPY, 0, i); + if (index !=3D -1) + fd[i] =3D drives_table[index].bdrv; + else + fd[i] =3D NULL; + } + fdctrl_init(i8259[6], 2, 0, 0x3f0, fd); =20 /* Register speaker port */ register_ioport_read(0x61, 1, 1, speaker_ioport_read, NULL); Index: qemu/hw/esp.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/esp.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/esp.c 2007-11-19 09:01:01.000000000 +0100 @@ -50,14 +50,11 @@ do { printf("ESP: " fmt , ##args); } whi #define ESP_REGS 16 #define ESP_SIZE (ESP_REGS * 4) #define TI_BUFSZ 32 -/* The HBA is ID 7, so for simplicitly limit to 7 devices. */ -#define ESP_MAX_DEVS 7 =20 typedef struct ESPState ESPState; =20 struct ESPState { qemu_irq irq; - BlockDriverState **bd; uint8_t rregs[ESP_REGS]; uint8_t wregs[ESP_REGS]; int32_t ti_size; @@ -65,7 +62,7 @@ struct ESPState { uint8_t ti_buf[TI_BUFSZ]; int sense; int dma; - SCSIDevice *scsi_dev[MAX_DISKS]; + SCSIDevice *scsi_dev[ESP_MAX_DEVS]; SCSIDevice *current_dev; uint8_t cmdbuf[TI_BUFSZ]; int cmdlen; @@ -127,7 +124,7 @@ static int get_cmd(ESPState *s, uint8_t=20 s->async_len =3D 0; } =20 - if (target >=3D MAX_DISKS || !s->scsi_dev[target]) { + if (target >=3D ESP_MAX_DEVS || !s->scsi_dev[target]) { // No such drive s->rregs[4] =3D STAT_IN; s->rregs[5] =3D INTR_DC; @@ -579,7 +576,7 @@ void esp_scsi_attach(void *opaque, Block s->scsi_dev[id] =3D scsi_disk_init(bd, 0, esp_command_complete, s); } =20 -void *esp_init(BlockDriverState **bd, target_phys_addr_t espaddr, +void *esp_init(target_phys_addr_t espaddr, void *dma_opaque, qemu_irq irq, qemu_irq *reset) { ESPState *s; @@ -589,7 +586,6 @@ void *esp_init(BlockDriverState **bd, ta if (!s) return NULL; =20 - s->bd =3D bd; s->irq =3D irq; s->dma_opaque =3D dma_opaque; =20 Index: qemu/hw/realview.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/realview.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/realview.c 2007-11-19 09:01:01.000000000 +0100 @@ -32,6 +32,7 @@ static void realview_init(int ram_size,=20 int done_smc =3D 0; qemu_irq cpu_irq[4]; int ncpu; + int index; =20 if (!cpu_model) cpu_model =3D "arm926"; @@ -89,7 +90,12 @@ static void realview_init(int ram_size,=20 =20 pl110_init(ds, 0x10020000, pic[23], 1); =20 - pl181_init(0x10005000, sd_bdrv, pic[17], pic[18]); + index =3D drive_get_index(IF_SD, 0, 0); + if (index =3D=3D -1) { + fprintf(stderr, "qemu: missing SecureDigital card\n"); + exit(1); + } + pl181_init(0x10005000, drives_table[index].bdrv, pic[17], pic[18]); =20 pl031_init(0x10017000, pic[10]); =20 @@ -97,11 +103,16 @@ static void realview_init(int ram_size,=20 if (usb_enabled) { usb_ohci_init_pci(pci_bus, 3, -1); } + if (drive_get_max_bus(IF_SCSI) > 0) { + fprintf(stderr, "qemu: too many SCSI bus\n"); + exit(1); + } scsi_hba =3D lsi_scsi_init(pci_bus, -1); - for (n =3D 0; n < MAX_DISKS; n++) { - if (bs_table[n]) { - lsi_scsi_attach(scsi_hba, bs_table[n], n); - } + for (n =3D 0; n < LSI_MAX_DEVS; n++) { + index =3D drive_get_index(IF_SCSI, 0, n); + if (index =3D=3D -1) + continue; + lsi_scsi_attach(scsi_hba, drives_table[index].bdrv, n); } for(n =3D 0; n < nb_nics; n++) { nd =3D &nd_table[n]; Index: qemu/hw/sun4m.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/sun4m.c 2007-11-19 09:00:26.000000000 +0100 +++ qemu/hw/sun4m.c 2007-11-19 09:01:01.000000000 +0100 @@ -283,6 +283,8 @@ static void *sun4m_hw_init(const struct=20 qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq, *espdma_irq, *ledma_irq; qemu_irq *esp_reset, *le_reset; + BlockDriverState *fd[MAX_FD]; + int index; =20 /* init CPUs */ =20 @@ -355,16 +357,29 @@ static void *sun4m_hw_init(const struct=20 slavio_serial_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq], serial_hds[1], serial_hds[0]); =20 - if (hwdef->fd_base !=3D (target_phys_addr_t)-1) - sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd_= table); + if (hwdef->fd_base !=3D (target_phys_addr_t)-1) { + /* there is zero or one floppy drive */ + fd[1] =3D fd[0] =3D NULL; + index =3D drive_get_index(IF_FLOPPY, 0, 0); + if (index !=3D -1) + fd[0] =3D drives_table[index].bdrv; =20 - main_esp =3D esp_init(bs_table, hwdef->esp_base, espdma, *espdma_irq= , + sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd)= ; + } + + if (drive_get_max_bus(IF_SCSI) > 0) { + fprintf(stderr, "qemu: too many SCSI bus\n"); + exit(1); + } + + main_esp =3D esp_init(hwdef->esp_base, espdma, *espdma_irq, esp_reset); =20 - for (i =3D 0; i < MAX_DISKS; i++) { - if (bs_table[i]) { - esp_scsi_attach(main_esp, bs_table[i], i); - } + for (i =3D 0; i < ESP_MAX_DEVS; i++) { + index =3D drive_get_index(IF_SCSI, 0, i); + if (index =3D=3D -1) + continue; + esp_scsi_attach(main_esp, drives_table[index].bdrv, i); } =20 slavio_misc =3D slavio_misc_init(hwdef->slavio_base, hwdef->power_ba= se, Index: qemu/hw/versatilepb.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/versatilepb.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/versatilepb.c 2007-11-19 09:01:01.000000000 +0100 @@ -171,6 +171,7 @@ static void versatile_init(int ram_size, NICInfo *nd; int n; int done_smc =3D 0; + int index; =20 if (!cpu_model) cpu_model =3D "arm926"; @@ -206,11 +207,16 @@ static void versatile_init(int ram_size, if (usb_enabled) { usb_ohci_init_pci(pci_bus, 3, -1); } + if (drive_get_max_bus(IF_SCSI) > 0) { + fprintf(stderr, "qemu: too many SCSI bus\n"); + exit(1); + } scsi_hba =3D lsi_scsi_init(pci_bus, -1); - for (n =3D 0; n < MAX_DISKS; n++) { - if (bs_table[n]) { - lsi_scsi_attach(scsi_hba, bs_table[n], n); - } + for (n =3D 0; n < LSI_MAX_DEVS; n++) { + index =3D drive_get_index(IF_SCSI, 0, n); + if (index =3D=3D -1) + continue; + lsi_scsi_attach(scsi_hba, drives_table[index].bdrv, n); } =20 pl011_init(0x101f1000, pic[12], serial_hds[0], PL011_ARM); @@ -226,7 +232,13 @@ static void versatile_init(int ram_size, that includes hardware cursor support from the PL111. */ pl110_init(ds, 0x10120000, pic[16], 1); =20 - pl181_init(0x10005000, sd_bdrv, sic[22], sic[1]); + index =3D drive_get_index(IF_SD, 0, 0); + if (index =3D=3D -1) { + fprintf(stderr, "qemu: missing SecureDigital card\n"); + exit(1); + } + + pl181_init(0x10005000, drives_table[index].bdrv, sic[22], sic[1]); #if 0 /* Disabled because there's no way of specifying a block device. */ pl181_init(0x1000b000, NULL, sic, 23, 2); Index: qemu/hw/integratorcp.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/integratorcp.c 2007-11-19 09:00:26.000000000 +0100 +++ qemu/hw/integratorcp.c 2007-11-19 09:01:01.000000000 +0100 @@ -478,6 +478,7 @@ static void integratorcp_init(int ram_si uint32_t bios_offset; qemu_irq *pic; qemu_irq *cpu_pic; + int sd; =20 if (!cpu_model) cpu_model =3D "arm926"; @@ -506,7 +507,12 @@ static void integratorcp_init(int ram_si icp_control_init(0xcb000000); pl050_init(0x18000000, pic[3], 0); pl050_init(0x19000000, pic[4], 1); - pl181_init(0x1c000000, sd_bdrv, pic[23], pic[24]); + sd =3D drive_get_index(IF_SD, 0, 0); + if (sd =3D=3D -1) { + fprintf(stderr, "qemu: missing SecureDigital card\n"); + exit(1); + } + pl181_init(0x1c000000, drives_table[sd].bdrv, pic[23], pic[24]); if (nd_table[0].vlan) { if (nd_table[0].model =3D=3D NULL || strcmp(nd_table[0].model, "smc91c111") =3D=3D 0) { Index: qemu/hw/lsi53c895a.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/lsi53c895a.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/lsi53c895a.c 2007-11-19 09:01:01.000000000 +0100 @@ -151,9 +151,6 @@ do { fprintf(stderr, "lsi_scsi: error: " #define PHASE_MI 7 #define PHASE_MASK 7 =20 -/* 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 =20 Index: qemu/hw/nand.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/nand.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/nand.c 2007-11-19 09:01:01.000000000 +0100 @@ -444,14 +444,20 @@ struct nand_flash_s *nand_init(int manf_ { int pagesize; struct nand_flash_s *s; + int index; =20 if (nand_flash_ids[chip_id].size =3D=3D 0) { cpu_abort(cpu_single_env, "%s: Unsupported NAND chip ID.\n", __FUNCTION__); } + index =3D drive_get_index(IF_MTD, 0, 0); + if (index =3D=3D -1) { + cpu_abort(cpu_single_env, "%s: missing MTD device\n", + __FUNCTION__); + } =20 s =3D (struct nand_flash_s *) qemu_mallocz(sizeof(struct nand_flash_= s)); - s->bdrv =3D mtd_bdrv; + s->bdrv =3D drives_table[index].bdrv; s->manf_id =3D manf_id; s->chip_id =3D chip_id; s->size =3D nand_flash_ids[s->chip_id].size << 20; Index: qemu/hw/ppc405_boards.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/ppc405_boards.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/ppc405_boards.c 2007-11-19 09:01:01.000000000 +0100 @@ -197,6 +197,7 @@ static void ref405ep_init (int ram_size, int linux_boot; int fl_idx, fl_sectors, len; int ppc_boot_device =3D boot_device[0]; + int index; =20 /* XXX: fix this */ ram_bases[0] =3D 0x00000000; @@ -223,17 +224,18 @@ static void ref405ep_init (int ram_size, bios_offset =3D sram_offset + sram_size; fl_idx =3D 0; #ifdef USE_FLASH_BIOS - if (pflash_table[fl_idx] !=3D NULL) { - bios_size =3D bdrv_getlength(pflash_table[fl_idx]); + index =3D drive_get_index(IF_PFLASH, 0, fl_idx); + if (index !=3D -1) { + bios_size =3D bdrv_getlength(drives_table[index].bdrv); fl_sectors =3D (bios_size + 65535) >> 16; #ifdef DEBUG_BOARD_INIT printf("Register parallel flash %d size " ADDRX " at offset %08l= x " " addr " ADDRX " '%s' %d\n", fl_idx, bios_size, bios_offset, -bios_size, - bdrv_get_device_name(pflash_table[fl_idx]), fl_sectors); + bdrv_get_device_name(drives_table[index].bdrv), fl_sector= s); #endif pflash_register((uint32_t)(-bios_size), bios_offset, - pflash_table[fl_idx], 65536, fl_sectors, 2, + drives_table[index].bdrv, 65536, fl_sectors, 2, 0x0001, 0x22DA, 0x0000, 0x0000); fl_idx++; } else @@ -519,6 +521,7 @@ static void taihu_405ep_init(int ram_siz int linux_boot; int fl_idx, fl_sectors; int ppc_boot_device =3D boot_device[0]; + int index; =20 /* RAM is soldered to the board so the size cannot be changed */ ram_bases[0] =3D 0x00000000; @@ -536,8 +539,9 @@ static void taihu_405ep_init(int ram_siz #endif fl_idx =3D 0; #if defined(USE_FLASH_BIOS) - if (pflash_table[fl_idx] !=3D NULL) { - bios_size =3D bdrv_getlength(pflash_table[fl_idx]); + index =3D drive_get_index(IF_PFLASH, 0, fl_idx); + if (index !=3D -1) { + bios_size =3D bdrv_getlength(drives_table[index].bdrv); /* XXX: should check that size is 2MB */ // bios_size =3D 2 * 1024 * 1024; fl_sectors =3D (bios_size + 65535) >> 16; @@ -545,10 +549,10 @@ static void taihu_405ep_init(int ram_siz printf("Register parallel flash %d size " ADDRX " at offset %08l= x " " addr " ADDRX " '%s' %d\n", fl_idx, bios_size, bios_offset, -bios_size, - bdrv_get_device_name(pflash_table[fl_idx]), fl_sectors); + bdrv_get_device_name(drives_table[index].bdrv), fl_sector= s); #endif pflash_register((uint32_t)(-bios_size), bios_offset, - pflash_table[fl_idx], 65536, fl_sectors, 4, + drives_table[index].bdrv, 65536, fl_sectors, 4, 0x0001, 0x22DA, 0x0000, 0x0000); fl_idx++; } else @@ -571,8 +575,9 @@ static void taihu_405ep_init(int ram_siz } bios_offset +=3D bios_size; /* Register Linux flash */ - if (pflash_table[fl_idx] !=3D NULL) { - bios_size =3D bdrv_getlength(pflash_table[fl_idx]); + index =3D drive_get_index(IF_PFLASH, 0, fl_idx); + if (index !=3D -1) { + bios_size =3D bdrv_getlength(drives_table[index].bdrv); /* XXX: should check that size is 32MB */ bios_size =3D 32 * 1024 * 1024; fl_sectors =3D (bios_size + 65535) >> 16; @@ -580,9 +585,9 @@ static void taihu_405ep_init(int ram_siz printf("Register parallel flash %d size " ADDRX " at offset %08l= x " " addr " ADDRX " '%s'\n", fl_idx, bios_size, bios_offset, (target_ulong)0xfc000000, - bdrv_get_device_name(pflash_table[fl_idx])); + bdrv_get_device_name(drives_table[index].bdrv)); #endif - pflash_register(0xfc000000, bios_offset, pflash_table[fl_idx], + pflash_register(0xfc000000, bios_offset, drives_table[index].bdr= v, 65536, fl_sectors, 4, 0x0001, 0x22DA, 0x0000, 0x0000); fl_idx++; Index: qemu/hw/ppc_chrp.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/ppc_chrp.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/ppc_chrp.c 2007-11-19 09:01:01.000000000 +0100 @@ -32,6 +32,8 @@ #include "sysemu.h" #include "boards.h" =20 +#define MAX_IDE_BUS 2 + /* UniN device */ static void unin_writel (void *opaque, target_phys_addr_t addr, uint32_t= value) { @@ -81,6 +83,8 @@ static void ppc_core99_init (int ram_siz int pic_mem_index, dbdma_mem_index, cuda_mem_index; int ide_mem_index[2]; int ppc_boot_device; + int index; + BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; =20 linux_boot =3D (kernel_filename !=3D NULL); =20 @@ -266,11 +270,22 @@ static void ppc_core99_init (int ram_siz nd_table[i].model =3D "ne2k_pci"; pci_nic_init(pci_bus, &nd_table[i], -1); } + if (drive_get_max_bus(IF_IDE) >=3D MAX_IDE_BUS) { + fprintf(stderr, "qemu: too many IDE bus\n"); + exit(1); + } + for(i =3D 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { + index =3D drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_= DEVS); + if (index !=3D -1) + hd[i] =3D drives_table[index].bdrv; + else + hd[i] =3D NULL; + } #if 1 - ide_mem_index[0] =3D pmac_ide_init(&bs_table[0], pic[0x13]); - ide_mem_index[1] =3D pmac_ide_init(&bs_table[2], pic[0x14]); + ide_mem_index[0] =3D pmac_ide_init(&hd[0], pic[0x13]); + ide_mem_index[1] =3D pmac_ide_init(&hd[2], pic[0x14]); #else - pci_cmd646_ide_init(pci_bus, &bs_table[0], 0); + pci_cmd646_ide_init(pci_bus, &hd[0], 0); #endif /* cuda also initialize ADB */ cuda_init(&cuda_mem_index, pic[0x19]); Index: qemu/hw/spitz.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/spitz.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/spitz.c 2007-11-19 09:01:01.000000000 +0100 @@ -940,9 +940,14 @@ static void spitz_ssp_attach(struct pxa2 static void spitz_microdrive_attach(struct pxa2xx_state_s *cpu) { struct pcmcia_card_s *md; - BlockDriverState *bs =3D bs_table[0]; + int index; + BlockDriverState *bs; =20 - if (bs && bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) { + index =3D drive_get_index(IF_IDE, 0, 0); + if (index =3D=3D -1) + return; + bs =3D drives_table[index].bdrv; + if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) { md =3D dscm1xxxx_init(bs); pxa2xx_pcmcia_attach(cpu->pcmcia[1], md); } Index: qemu/hw/mips_malta.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/mips_malta.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/mips_malta.c 2007-11-19 09:01:01.000000000 +0100 @@ -52,6 +52,8 @@ #define ENVP_NB_ENTRIES 16 #define ENVP_ENTRY_SIZE 256 =20 +#define MAX_IDE_BUS 2 + extern FILE *logfile; =20 typedef struct { @@ -775,6 +777,8 @@ void mips_malta_init (int ram_size, int=20 uint8_t *eeprom_buf; i2c_bus *smbus; int i; + int index; + BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; =20 /* init CPUs */ if (cpu_model =3D=3D NULL) { @@ -861,8 +865,22 @@ void mips_malta_init (int ram_size, int=20 pci_bus =3D pci_gt64120_init(i8259); =20 /* Southbridge */ + + if (drive_get_max_bus(IF_IDE) >=3D MAX_IDE_BUS) { + fprintf(stderr, "qemu: too many IDE bus\n"); + exit(1); + } + + for(i =3D 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { + index =3D drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_= DEVS); + if (index !=3D -1) + hd[i] =3D drives_table[index].bdrv; + else + hd[i] =3D NULL; + } + piix4_devfn =3D piix4_init(pci_bus, 80); - pci_piix4_ide_init(pci_bus, bs_table, piix4_devfn + 1, i8259); + pci_piix4_ide_init(pci_bus, hd, piix4_devfn + 1, i8259); usb_uhci_piix4_init(pci_bus, piix4_devfn + 2); smbus =3D piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100); eeprom_buf =3D qemu_mallocz(8 * 256); /* XXX: make this persistent *= / Index: qemu/hw/sun4u.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/sun4u.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/sun4u.c 2007-11-19 09:01:01.000000000 +0100 @@ -43,6 +43,7 @@ #define VGA_BASE (APB_MEM_BASE + 0x400000ULL) #define PROM_FILENAME "openbios-sparc64" #define NVRAM_SIZE 0x2000 +#define MAX_IDE_BUS 2 =20 /* TSC handling */ =20 @@ -240,6 +241,9 @@ static void sun4u_init(int ram_size, int PCIBus *pci_bus; QEMUBH *bh; qemu_irq *irq; + int index; + BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; + BlockDriverState *fd[MAX_FD]; =20 linux_boot =3D (kernel_filename !=3D NULL); =20 @@ -342,11 +346,30 @@ static void sun4u_init(int ram_size, int } =20 irq =3D qemu_allocate_irqs(dummy_cpu_set_irq, NULL, 32); - // XXX pci_cmd646_ide_init(pci_bus, bs_table, 1); - pci_piix3_ide_init(pci_bus, bs_table, -1, irq); + if (drive_get_max_bus(IF_IDE) >=3D MAX_IDE_BUS) { + fprintf(stderr, "qemu: too many IDE bus\n"); + exit(1); + } + for(i =3D 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { + index =3D drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_= DEVS); + if (index !=3D -1) + hd[i] =3D drives_table[index].bdrv; + else + hd[i] =3D NULL; + } + + // XXX pci_cmd646_ide_init(pci_bus, hd, 1); + pci_piix3_ide_init(pci_bus, hd, -1, irq); /* FIXME: wire up interrupts. */ i8042_init(NULL/*1*/, NULL/*12*/, 0x60); - floppy_controller =3D fdctrl_init(NULL/*6*/, 2, 0, 0x3f0, fd_table); + for(i =3D 0; i < MAX_FD; i++) { + index =3D drive_get_index(IF_FLOPPY, 0, i); + if (index !=3D -1) + fd[i] =3D drives_table[index].bdrv; + else + fd[i] =3D NULL; + } + floppy_controller =3D fdctrl_init(NULL/*6*/, 2, 0, 0x3f0, fd); nvram =3D m48t59_init(NULL/*8*/, 0, 0x0074, NVRAM_SIZE, 59); sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", ram_size, boot_de= vices, KERNEL_LOAD_ADDR, kernel_size, Index: qemu/hw/ppc_oldworld.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/ppc_oldworld.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/ppc_oldworld.c 2007-11-19 09:01:01.000000000 +0100 @@ -33,6 +33,8 @@ #include "pci.h" #include "boards.h" =20 +#define MAX_IDE_BUS 2 + /* temporary frame buffer OSI calls for the video.x driver. The right solution is to modify the driver to use VGA PCI I/Os */ /* XXX: to be removed. This is no way related to emulation */ @@ -122,6 +124,8 @@ static void ppc_heathrow_init (int ram_s int pic_mem_index, nvram_mem_index, dbdma_mem_index, cuda_mem_index; int ide_mem_index[2]; int ppc_boot_device; + BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; + int index; =20 linux_boot =3D (kernel_filename !=3D NULL); =20 @@ -291,10 +295,37 @@ static void ppc_heathrow_init (int ram_s } =20 /* First IDE channel is a CMD646 on the PCI bus */ - pci_cmd646_ide_init(pci_bus, &bs_table[0], 0); + + if (drive_get_max_bus(IF_IDE) >=3D MAX_IDE_BUS) { + fprintf(stderr, "qemu: too many IDE bus\n"); + exit(1); + } + index =3D drive_get_index(IF_IDE, 0, 0); + if (index =3D=3D -1) + hd[0] =3D NULL; + else + hd[0] =3D drives_table[index].bdrv; + index =3D drive_get_index(IF_IDE, 0, 1); + if (index =3D=3D -1) + hd[1] =3D NULL; + else + hd[1] =3D drives_table[index].bdrv; + hd[3] =3D hd[2] =3D NULL; + pci_cmd646_ide_init(pci_bus, hd, 0); + /* Second IDE channel is a MAC IDE on the MacIO bus */ + index =3D drive_get_index(IF_IDE, 1, 0); + if (index =3D=3D -1) + hd[0] =3D NULL; + else + hd[0] =3D drives_table[index].bdrv; + index =3D drive_get_index(IF_IDE, 1, 1); + if (index =3D=3D -1) + hd[1] =3D NULL; + else + hd[1] =3D drives_table[index].bdrv; ide_mem_index[0] =3D -1; - ide_mem_index[1] =3D pmac_ide_init(&bs_table[2], pic[0x0D]); + ide_mem_index[1] =3D pmac_ide_init(hd, pic[0x0D]); =20 /* cuda also initialize ADB */ cuda_init(&cuda_mem_index, pic[0x12]); Index: qemu/hw/gumstix.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/gumstix.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/gumstix.c 2007-11-19 09:01:01.000000000 +0100 @@ -25,6 +25,7 @@ static void gumstix_common_init(int ram_ const char *cpu_model, enum gumstix_model_e model) { struct pxa2xx_state_s *cpu; + int index; =20 uint32_t gumstix_rom =3D 0x02000000; uint32_t gumstix_ram =3D 0x08000000; @@ -37,14 +38,15 @@ static void gumstix_common_init(int ram_ =20 cpu =3D pxa255_init(gumstix_ram, ds); =20 - if (pflash_table[0] =3D=3D NULL) { + index =3D drive_get_index(IF_PFLASH, 0, 0); + if (index =3D=3D -1) { fprintf(stderr, "A flash image must be given with the " "'pflash' parameter\n"); exit(1); } =20 if (!pflash_register(0x00000000, gumstix_ram + PXA2XX_INTERNAL_SIZE, - pflash_table[0], 128 * 1024, 128, 2, 0, 0, 0, 0)) { + drives_table[index].bdrv, 128 * 1024, 128, 2, 0, 0, 0, 0)) { fprintf(stderr, "qemu: Error register flash memory.\n"); exit(1); } Index: qemu/hw/pxa2xx.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/pxa2xx.c 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/pxa2xx.c 2007-11-19 09:01:01.000000000 +0100 @@ -2036,6 +2036,7 @@ struct pxa2xx_state_s *pxa270_init(unsig struct pxa2xx_state_s *s; struct pxa2xx_ssp_s *ssp; int iomemtype, i; + int index; s =3D (struct pxa2xx_state_s *) qemu_mallocz(sizeof(struct pxa2xx_st= ate_s)); =20 if (revision && strncmp(revision, "pxa27", 5)) { @@ -2070,8 +2071,13 @@ struct pxa2xx_state_s *pxa270_init(unsig =20 s->gpio =3D pxa2xx_gpio_init(0x40e00000, s->env, s->pic, 121); =20 - s->mmc =3D pxa2xx_mmci_init(0x41100000, sd_bdrv, s->pic[PXA2XX_PIC_M= MC], - s->dma); + index =3D drive_get_index(IF_SD, 0, 0); + if (index =3D=3D -1) { + fprintf(stderr, "qemu: missing SecureDigital device\n"); + exit(1); + } + s->mmc =3D pxa2xx_mmci_init(0x41100000, drives_table[index].bdrv, + s->pic[PXA2XX_PIC_MMC], s->dma); =20 for (i =3D 0; pxa270_serial[i].io_base; i ++) if (serial_hds[i]) @@ -2160,6 +2166,7 @@ struct pxa2xx_state_s *pxa255_init(unsig struct pxa2xx_state_s *s; struct pxa2xx_ssp_s *ssp; int iomemtype, i; + int index; =20 s =3D (struct pxa2xx_state_s *) qemu_mallocz(sizeof(struct pxa2xx_st= ate_s)); =20 @@ -2187,8 +2194,13 @@ struct pxa2xx_state_s *pxa255_init(unsig =20 s->gpio =3D pxa2xx_gpio_init(0x40e00000, s->env, s->pic, 85); =20 - s->mmc =3D pxa2xx_mmci_init(0x41100000, sd_bdrv, s->pic[PXA2XX_PIC_M= MC], - s->dma); + index =3D drive_get_index(IF_SD, 0, 0); + if (index =3D=3D -1) { + fprintf(stderr, "qemu: missing SecureDigital device\n"); + exit(1); + } + s->mmc =3D pxa2xx_mmci_init(0x41100000, drives_table[index].bdrv, + s->pic[PXA2XX_PIC_MMC], s->dma); =20 for (i =3D 0; pxa255_serial[i].io_base; i ++) if (serial_hds[i]) Index: qemu/hw/omap.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/omap.c 2007-11-19 09:00:41.000000000 +0100 +++ qemu/hw/omap.c 2007-11-19 09:01:01.000000000 +0100 @@ -4721,6 +4721,7 @@ struct omap_mpu_state_s *omap310_mpu_ini struct omap_mpu_state_s *s =3D (struct omap_mpu_state_s *) qemu_mallocz(sizeof(struct omap_mpu_state_s)); ram_addr_t imif_base, emiff_base; + int index; =20 if (!core) core =3D "ti925t"; @@ -4817,7 +4818,13 @@ struct omap_mpu_state_s *omap310_mpu_ini omap_dpll_init(&s->dpll[1], 0xfffed000, omap_findclk(s, "dpll2")); omap_dpll_init(&s->dpll[2], 0xfffed100, omap_findclk(s, "dpll3")); =20 - s->mmc =3D omap_mmc_init(0xfffb7800, sd_bdrv, s->irq[1][OMAP_INT_OQN= ], + index =3D drive_get_index(IF_SD, 0, 0); + if (index =3D=3D -1) { + fprintf(stderr, "qemu: missing SecureDigital device\n"); + exit(1); + } + s->mmc =3D omap_mmc_init(0xfffb7800, drives_table[index].bdrv, + s->irq[1][OMAP_INT_OQN], &s->drq[OMAP_DMA_MMC_TX], omap_findclk(s, "mmc_ck"))= ; =20 s->mpuio =3D omap_mpuio_init(0xfffb5000, Index: qemu/sysemu.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/sysemu.h 2007-11-19 09:00:26.000000000 +0100 +++ qemu/sysemu.h 2007-11-19 09:01:01.000000000 +0100 @@ -116,15 +116,26 @@ extern unsigned int nb_prom_envs; #define BIOS_SIZE (4 * 1024 * 1024) #endif =20 -#define MAX_DISKS 4 +typedef enum { + IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD +} BlockInterfaceType; + +typedef struct DriveInfo { + BlockDriverState *bdrv; + BlockInterfaceType interface; + int bus; + int unit; +} DriveInfo; + +#define MAX_IDE_DEVS 2 +#define MAX_SCSI_DEVS 7 +#define MAX_DRIVES 32 =20 -extern BlockDriverState *bs_table[MAX_DISKS + 1]; -extern BlockDriverState *sd_bdrv; -extern BlockDriverState *mtd_bdrv; - -/* NOR flash devices */ -#define MAX_PFLASH 4 -extern BlockDriverState *pflash_table[MAX_PFLASH]; +int nb_drives; +DriveInfo drives_table[MAX_DRIVES+1]; + +extern int drive_get_index(BlockInterfaceType interface, int bus, int un= it); +extern int drive_get_max_bus(BlockInterfaceType interface); =20 /* serial ports */ =20 Index: qemu/hw/pci.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/pci.h 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/pci.h 2007-11-19 09:01:01.000000000 +0100 @@ -97,6 +97,7 @@ PCIBus *pci_bridge_init(PCIBus *bus, int pci_map_irq_fn map_irq, const char *name); =20 /* lsi53c895a.c */ +#define LSI_MAX_DEVS 7 void lsi_scsi_attach(void *opaque, BlockDriverState *bd, int id); void *lsi_scsi_init(PCIBus *bus, int devfn); =20 Index: qemu/hw/sun4m.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/hw/sun4m.h 2007-11-19 09:00:27.000000000 +0100 +++ qemu/hw/sun4m.h 2007-11-19 09:01:01.000000000 +0100 @@ -49,8 +49,9 @@ void *slavio_misc_init(target_phys_addr_ void slavio_set_power_fail(void *opaque, int power_failing); =20 /* esp.c */ +#define ESP_MAX_DEVS 7 void esp_scsi_attach(void *opaque, BlockDriverState *bd, int id); -void *esp_init(BlockDriverState **bd, target_phys_addr_t espaddr, +void *esp_init(target_phys_addr_t espaddr, void *dma_opaque, qemu_irq irq, qemu_irq *reset); =20 /* cs4231.c */