From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1InGBL-0004wA-8t for qemu-devel@nongnu.org; Wed, 31 Oct 2007 12:12:39 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1InGBJ-0004ve-Ml for qemu-devel@nongnu.org; Wed, 31 Oct 2007 12:12:38 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1InGBJ-0004vZ-FK for qemu-devel@nongnu.org; Wed, 31 Oct 2007 12:12:37 -0400 Received: from ecfrec.frec.bull.fr ([129.183.4.8]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1InFrh-00043O-GN for qemu-devel@nongnu.org; Wed, 31 Oct 2007 11:52:22 -0400 Received: from localhost (localhost [127.0.0.1]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id 5492719D97C for ; Wed, 31 Oct 2007 16:52:14 +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 25387-05 for ; Wed, 31 Oct 2007 16:52:10 +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 5A24319D90E for ; Wed, 31 Oct 2007 16:52:10 +0100 (CET) In-Reply-To: <11938459102678@bull.net> Date: Wed, 31 Oct 2007 16:51:52 +0100 Message-Id: <11938459121657@bull.net> Mime-Version: 1.0 From: Laurent Vivier Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Subject: [Qemu-devel] [PATCH 2/7] Add scsi support for the target PC Reply-To: Laurent Vivier , qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Laurent.Vivier@bull.net This patch adds the SCSI support for the target PC. It allows to initalize SCSI interface in the PC init machine. it adds a new interface type "scsi" to "-disk" interface. "-disk file,if=3Dscsi,bus=3D0,unit=3D6" allows to connect the disk image fi= le to the 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=20 "realview", "SS-5", "SS-10", "versatilepb", "versatileab" to keep old behavior, where "-hda" is a SCSI disk. -- hw/esp.c | 4 +- hw/pc.c | 30 ++++++++------- hw/realview.c | 6 +-- hw/sun4m.c | 6 +-- hw/versatilepb.c | 6 +-- monitor.c | 7 +++ vl.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++-= ----- vl.h | 9 ++++ 8 files changed, 139 insertions(+), 37 deletions(-) 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-10-31 14:13:20.000000000 +0100 +++ qemu/hw/pc.c 2007-10-31 14:23:52.000000000 +0100 @@ -927,23 +927,25 @@ 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; + void *scsi[SCSI_MAX_BUS]; + int max_bus =3D -1; + + for (i =3D 0; i < MAX_SCSI_DISKS; i++) + if (sd_table[i]) + max_bus =3D i / SCSI_MAX_DEVS + 1; + + for (i =3D 0; i < max_bus; i++) + scsi[i] =3D lsi_scsi_init(pci_bus, -1); =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); + for (i =3D 0; i < MAX_SCSI_DISKS; i++) { + if (sd_table[i]) { + lsi_scsi_attach(scsi[i / SCSI_MAX_DEVS], + sd_table[i], i % SCSI_MAX_DEVS); + } + } } -#endif } =20 static void pc_init_pci(int ram_size, int vga_ram_size, const char *boot_d= evice, 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-10-31 14:12:40.000000000 +0100 +++ qemu/hw/realview.c 2007-10-31 14:23:52.000000000 +0100 @@ -65,9 +65,9 @@ usb_ohci_init_pci(pci_bus, 3, -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 < SCSI_MAX_DEVS; n++) { + if (sd_table[n]) { + lsi_scsi_attach(scsi_hba, sd_table[n], n); } } for(n =3D 0; n < nb_nics; n++) { 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-10-31 14:12:40.000000000 +0100 +++ qemu/hw/versatilepb.c 2007-10-31 14:23:52.000000000 +0100 @@ -199,9 +199,9 @@ usb_ohci_init_pci(pci_bus, 3, -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 < SCSI_MAX_DEVS; n++) { + if (sd_table[n]) { + lsi_scsi_attach(scsi_hba, sd_table[n], n); } } =20 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-10-31 14:18:25.000000000 +0100 +++ qemu/vl.c 2007-10-31 14:23:52.000000000 +0100 @@ -152,6 +152,7 @@ /* Note: bs_table[MAX_IDE_DISKS] is a dummy block driver if none available to store the VM snapshots */ BlockDriverState *bs_table[MAX_IDE_DISKS + 1], *fd_table[MAX_FD]; +BlockDriverState *sd_table[MAX_SCSI_DISKS + 1]; BlockDriverState *pflash_table[MAX_PFLASH]; BlockDriverState *sd_bdrv; BlockDriverState *mtd_bdrv; @@ -1752,6 +1753,10 @@ if (bs_table[i]) bdrv_commit(bs_table[i]); } + for (i =3D 0; i < MAX_SCSI_DISKS; i++) { + if (sd_table[i]) + bdrv_commit(sd_table[i]); + } if (mtd_bdrv) bdrv_commit(mtd_bdrv); } @@ -4714,7 +4719,7 @@ #define CDROM_ALIAS ",index=3D2,media=3Dcdrom" #endif =20 -static int disk_init(const char *str, int snapshot) +static int disk_init(const char *str, int snapshot, QEMUMachine *machine) { char buf[16]; enum { IF_IDE, IF_SCSI } interface; @@ -4739,7 +4744,16 @@ unit_id =3D -1; disk_index =3D -1; translation =3D BIOS_ATA_TRANSLATION_AUTO; - interface =3D IF_IDE; + + if (!strcmp(machine->name, "realview") || + !strcmp(machine->name, "SS-5") || + !strcmp(machine->name, "SS-10") || + !strcmp(machine->name, "versatilepb") || + !strcmp(machine->name, "versatileab")) { + interface =3D IF_SCSI; + } else { + interface =3D IF_IDE; + } media =3D MEDIA_DISK; =20 /* extract parameters */ @@ -4899,8 +4913,59 @@ } break; case IF_SCSI: - /* TODO */ - break; + + if (bus_id >=3D SCSI_MAX_BUS) { + fprintf(stderr, "qemu: bus id too big\n"); + return -1; + } + + if (unit_id >=3D SCSI_MAX_DEVS) { + fprintf(stderr, "qemu: unit id too big\n"); + return -1; + } + + if (bus_id !=3D -1 && unit_id !=3D -1) + disk_index =3D bus_id * SCSI_MAX_DEVS + unit_id; + else { + if (bus_id !=3D -1) + disk_index =3D bus_id * SCSI_MAX_DEVS; + else + disk_index =3D 0; + while (sd_table[disk_index] && disk_index < SCSI_MAX_DEVS) + disk_index++; + } + if (disk_index >=3D MAX_SCSI_DISKS) { + fprintf(stderr, "qemu: too many disks\n"); + return -1; + } + + if (!sd_table[disk_index]) { + switch(media) { + case MEDIA_DISK: + snprintf(buf, sizeof(buf), "sd%c", disk_index + 'a'); + sd_table[disk_index] =3D bdrv_new(buf); + break; + case MEDIA_CDROM: + snprintf(buf, sizeof(buf), "sr%c", disk_index + '0'); + sd_table[disk_index] =3D bdrv_new(buf); + bdrv_set_type_hint(sd_table[disk_index], BDRV_TYPE_CDROM); + break; + } + + if (file[0] && bdrv_open(sd_table[disk_index], file, + snapshot ? BDRV_O_SNAPSHOT : 0) < 0) { + fprintf(stderr, "qemu: could not open hard disk image '%s'= \n", + file); + return -1; + } + + if (cyls !=3D 0) { + bdrv_set_geometry_hint(sd_table[disk_index], + cyls, heads, secs); + bdrv_set_translation_hint(sd_table[disk_index], translatio= n); + } + } + break; } return 0; } @@ -5693,6 +5758,11 @@ if (bdrv_can_snapshot(bs)) goto ok; } + for(i =3D 0; i <=3D MAX_SCSI_DISKS; i++) { + bs =3D sd_table[i]; + if (bdrv_can_snapshot(bs)) + goto ok; + } return NULL; ok: bs_snapshots =3D bs; @@ -5797,8 +5867,11 @@ =20 /* create the snapshots */ =20 - for(i =3D 0; i < MAX_IDE_DISKS; i++) { - bs1 =3D bs_table[i]; + for(i =3D 0; i < MAX_IDE_DISKS + MAX_SCSI_DISKS; i++) { + if (i < MAX_IDE_DISKS) + bs1 =3D bs_table[i]; + else + bs1 =3D sd_table[i - MAX_IDE_DISKS]; if (bdrv_has_snapshot(bs1)) { if (must_delete) { ret =3D bdrv_snapshot_delete(bs1, old_sn->id_str); @@ -5840,8 +5913,11 @@ saved_vm_running =3D vm_running; vm_stop(0); =20 - for(i =3D 0; i <=3D MAX_IDE_DISKS; i++) { - bs1 =3D bs_table[i]; + for(i =3D 0; i <=3D MAX_IDE_DISKS + MAX_SCSI_DISKS; i++) { + if (i < MAX_IDE_DISKS) + bs1 =3D bs_table[i]; + else + bs1 =3D sd_table[i - MAX_IDE_DISKS]; if (bdrv_has_snapshot(bs1)) { ret =3D bdrv_snapshot_goto(bs1, name); if (ret < 0) { @@ -5901,8 +5977,11 @@ return; } =20 - for(i =3D 0; i <=3D MAX_IDE_DISKS; i++) { - bs1 =3D bs_table[i]; + for(i =3D 0; i <=3D MAX_IDE_DISKS + MAX_SCSI_DISKS; i++) { + if (i < MAX_IDE_DISKS) + bs1 =3D bs_table[i]; + else + bs1 =3D sd_table[i - MAX_IDE_DISKS]; if (bdrv_has_snapshot(bs1)) { ret =3D bdrv_snapshot_delete(bs1, name); if (ret < 0) { @@ -5937,6 +6016,13 @@ term_printf(" %s", bdrv_get_device_name(bs1)); } } + for(i =3D 0; i <=3D MAX_SCSI_DISKS; i++) { + bs1 =3D sd_table[i]; + if (bdrv_has_snapshot(bs1)) { + if (bs =3D=3D bs1) + term_printf(" %s", bdrv_get_device_name(bs1)); + } + } term_printf("\n"); =20 nb_sns =3D bdrv_snapshot_list(bs, &sn_tab); @@ -8523,7 +8609,7 @@ /* open the virtual block devices */ =20 for(i =3D 0; i < nb_disks; i++) - if (disk_init(disks[i], snapshot) =3D=3D -1) + if (disk_init(disks[i], snapshot, machine) =3D=3D -1) exit(1); =20 /* we always create at least one floppy disk */ Index: qemu/vl.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/vl.h 2007-10-31 14:13:20.000000000 +0100 +++ qemu/vl.h 2007-10-31 14:23:52.000000000 +0100 @@ -983,14 +983,21 @@ /* x_keymap.c */ extern uint8_t _translate_keycode(const int key); =20 +/* lsi53c895a.c */ + +#define SCSI_MAX_DEVS 7 +#define SCSI_MAX_BUS 4 +#define MAX_SCSI_DISKS (SCSI_MAX_BUS * SCSI_MAX_DEVS) + /* ide.c */ #define MAX_IDE_BUS 2 #define MAX_IDE_DEVS 2 #define MAX_IDE_DISKS (MAX_IDE_BUS * MAX_IDE_DEVS) =20 -#define MAX_DISKS (MAX_IDE_DISKS) +#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS) =20 extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1]; +extern BlockDriverState *sd_table[MAX_SCSI_DISKS + 1]; extern BlockDriverState *sd_bdrv; extern BlockDriverState *mtd_bdrv; =20 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-10-31 14:12:40.000000000 +0100 +++ qemu/hw/sun4m.c 2007-10-31 14:23:52.000000000 +0100 @@ -394,9 +394,9 @@ main_esp =3D esp_init(bs_table, 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 < MAX_SCSI_DISKS; i++) { + if (sd_table[i]) { + esp_scsi_attach(main_esp, sd_table[i], i); } } =20 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-10-31 14:13:20.000000000 +0100 +++ qemu/monitor.c 2007-10-31 14:23:52.000000000 +0100 @@ -211,6 +211,13 @@ bdrv_commit(bs_table[i]); } } + for (i =3D 0; i < MAX_SCSI_DISKS; i++) { + if (sd_table[i]) { + if (all_devices || + !strcmp(bdrv_get_device_name(sd_table[i]), device)) + bdrv_commit(sd_table[i]); + } + } if (mtd_bdrv) if (all_devices || !strcmp(bdrv_get_device_name(mtd_bdrv), device)) bdrv_commit(mtd_bdrv); 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-10-31 14:12:18.000000000 +0100 +++ qemu/hw/esp.c 2007-10-31 14:23:52.000000000 +0100 @@ -60,7 +60,7 @@ uint8_t ti_buf[TI_BUFSZ]; int sense; int dma; - SCSIDevice *scsi_dev[MAX_DISKS]; + SCSIDevice *scsi_dev[SCSI_MAX_DEVS]; SCSIDevice *current_dev; uint8_t cmdbuf[TI_BUFSZ]; int cmdlen; @@ -122,7 +122,7 @@ s->async_len =3D 0; } =20 - if (target >=3D MAX_DISKS || !s->scsi_dev[target]) { + if (target >=3D SCSI_MAX_DEVS || !s->scsi_dev[target]) { // No such drive s->rregs[4] =3D STAT_IN; s->rregs[5] =3D INTR_DC;