aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-12-02 04:51:10 +0000
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-12-02 04:51:10 +0000
commite4bcb14c79fb63a35aef3eb39e02c16c19b8b28d (patch)
tree06bee4b9dbf4c7b50e20c9996924d7d132cdfec2
parent7233b355571ad2a8e7aec7eb19db5f530e81f052 (diff)
Add -drive parameter, by Laurent Vivier.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3759 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--hw/esp.c10
-rw-r--r--hw/gumstix.c12
-rw-r--r--hw/integratorcp.c8
-rw-r--r--hw/lsi53c895a.c3
-rw-r--r--hw/mainstone.c37
-rw-r--r--hw/mips_malta.c30
-rw-r--r--hw/mips_pica61.c29
-rw-r--r--hw/mips_r4k.c22
-rw-r--r--hw/nand.c8
-rw-r--r--hw/omap.c9
-rw-r--r--hw/pc.c70
-rw-r--r--hw/pci.h1
-rw-r--r--hw/ppc405_boards.c29
-rw-r--r--hw/ppc_chrp.c21
-rw-r--r--hw/ppc_oldworld.c35
-rw-r--r--hw/ppc_prep.c32
-rw-r--r--hw/pxa2xx.c20
-rw-r--r--hw/realview.c21
-rw-r--r--hw/spitz.c9
-rw-r--r--hw/stellaris.c4
-rw-r--r--hw/sun4m.c29
-rw-r--r--hw/sun4m.h3
-rw-r--r--hw/sun4u.c29
-rw-r--r--hw/versatilepb.c22
-rw-r--r--monitor.c11
-rw-r--r--sysemu.h29
-rw-r--r--vl.c655
27 files changed, 873 insertions, 315 deletions
diff --git a/hw/esp.c b/hw/esp.c
index b6c58ff711..d6af3f61f0 100644
--- a/hw/esp.c
+++ b/hw/esp.c
@@ -50,14 +50,11 @@ do { printf("ESP: " fmt , ##args); } while (0)
#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
typedef struct ESPState ESPState;
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;
@@ -172,7 +169,7 @@ static int get_cmd(ESPState *s, uint8_t *buf)
s->async_len = 0;
}
- if (target >= MAX_DISKS || !s->scsi_dev[target]) {
+ if (target >= ESP_MAX_DEVS || !s->scsi_dev[target]) {
// No such drive
s->rregs[ESP_RSTAT] = STAT_IN;
s->rregs[ESP_RINTR] = INTR_DC;
@@ -621,7 +618,7 @@ void esp_scsi_attach(void *opaque, BlockDriverState *bd, int id)
s->scsi_dev[id] = scsi_disk_init(bd, 0, esp_command_complete, s);
}
-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;
@@ -631,7 +628,6 @@ void *esp_init(BlockDriverState **bd, target_phys_addr_t espaddr,
if (!s)
return NULL;
- s->bd = bd;
s->irq = irq;
s->dma_opaque = dma_opaque;
diff --git a/hw/gumstix.c b/hw/gumstix.c
index 15562b7b01..21325177c5 100644
--- a/hw/gumstix.c
+++ b/hw/gumstix.c
@@ -47,6 +47,7 @@ static void connex_init(int ram_size, int vga_ram_size,
const char *initrd_filename, const char *cpu_model)
{
struct pxa2xx_state_s *cpu;
+ int index;
uint32_t connex_rom = 0x01000000;
uint32_t connex_ram = 0x04000000;
@@ -59,14 +60,15 @@ static void connex_init(int ram_size, int vga_ram_size,
cpu = pxa255_init(connex_ram, ds);
- if (pflash_table[0] == NULL) {
+ index = drive_get_index(IF_PFLASH, 0, 0);
+ if (index == -1) {
fprintf(stderr, "A flash image must be given with the "
"'pflash' parameter\n");
exit(1);
}
if (!pflash_register(0x00000000, qemu_ram_alloc(connex_rom),
- pflash_table[0], sector_len, connex_rom / sector_len,
+ drives_table[index].bdrv, sector_len, connex_rom / sector_len,
2, 0, 0, 0, 0)) {
fprintf(stderr, "qemu: Error registering flash memory.\n");
exit(1);
@@ -85,6 +87,7 @@ static void verdex_init(int ram_size, int vga_ram_size,
const char *initrd_filename, const char *cpu_model)
{
struct pxa2xx_state_s *cpu;
+ int index;
uint32_t verdex_rom = 0x02000000;
uint32_t verdex_ram = 0x10000000;
@@ -97,14 +100,15 @@ static void verdex_init(int ram_size, int vga_ram_size,
cpu = pxa270_init(verdex_ram, ds, cpu_model ?: "pxa270-c0");
- if (pflash_table[0] == NULL) {
+ index = drive_get_index(IF_PFLASH, 0, 0);
+ if (index == -1) {
fprintf(stderr, "A flash image must be given with the "
"'pflash' parameter\n");
exit(1);
}
if (!pflash_register(0x00000000, qemu_ram_alloc(verdex_rom),
- pflash_table[0], sector_len, verdex_rom / sector_len,
+ drives_table[index].bdrv, sector_len, verdex_rom / sector_len,
2, 0, 0, 0, 0)) {
fprintf(stderr, "qemu: Error registering flash memory.\n");
exit(1);
diff --git a/hw/integratorcp.c b/hw/integratorcp.c
index f1d71ff873..549cc25df8 100644
--- a/hw/integratorcp.c
+++ b/hw/integratorcp.c
@@ -478,6 +478,7 @@ static void integratorcp_init(int ram_size, int vga_ram_size,
uint32_t bios_offset;
qemu_irq *pic;
qemu_irq *cpu_pic;
+ int sd;
if (!cpu_model)
cpu_model = "arm926";
@@ -506,7 +507,12 @@ static void integratorcp_init(int ram_size, int vga_ram_size,
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 = drive_get_index(IF_SD, 0, 0);
+ if (sd == -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 == NULL
|| strcmp(nd_table[0].model, "smc91c111") == 0) {
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index c841db1846..dbf67cb0c1 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -151,9 +151,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/mainstone.c b/hw/mainstone.c
index 13f72b3504..354015202f 100644
--- a/hw/mainstone.c
+++ b/hw/mainstone.c
@@ -29,6 +29,7 @@ static void mainstone_common_init(int ram_size, int vga_ram_size,
uint32_t mainstone_rom = 0x00800000;
struct pxa2xx_state_s *cpu;
qemu_irq *mst_irq;
+ int index;
if (!cpu_model)
cpu_model = "pxa270-c5";
@@ -47,18 +48,32 @@ static void mainstone_common_init(int ram_size, int vga_ram_size,
/* Setup initial (reset) machine state */
cpu->env->regs[15] = PXA2XX_SDRAM_BASE;
- /* There are two 32MiB flash devices on the board */
- if (!pflash_register(MST_FLASH_0, mainstone_ram + PXA2XX_INTERNAL_SIZE,
- pflash_table[0], 256 * 1024, 128, 4, 0, 0, 0, 0)) {
- fprintf(stderr, "qemu: Error register flash memory.\n");
- exit(1);
- }
+ /* There are two 32MiB flash devices on the board */
+ index = drive_get_index(IF_PFLASH, 0, 0);
+ if (index == -1) {
+ fprintf(stderr, "Two flash images must be given with the "
+ "'pflash' parameter\n");
+ exit(1);
+ }
+ if (!pflash_register(MST_FLASH_0, mainstone_ram + PXA2XX_INTERNAL_SIZE,
+ drives_table[index].bdrv,
+ 256 * 1024, 128, 4, 0, 0, 0, 0)) {
+ fprintf(stderr, "qemu: Error registering flash memory.\n");
+ exit(1);
+ }
- if (!pflash_register(MST_FLASH_1, mainstone_ram + PXA2XX_INTERNAL_SIZE,
- pflash_table[1], 256 * 1024, 128, 4, 0, 0, 0, 0)) {
- fprintf(stderr, "qemu: Error register flash memory.\n");
- exit(1);
- }
+ index = drive_get_index(IF_PFLASH, 0, 1);
+ if (index == -1) {
+ fprintf(stderr, "Two flash images must be given with the "
+ "'pflash' parameter\n");
+ exit(1);
+ }
+ if (!pflash_register(MST_FLASH_1, mainstone_ram + PXA2XX_INTERNAL_SIZE,
+ drives_table[index].bdrv,
+ 256 * 1024, 128, 4, 0, 0, 0, 0)) {
+ fprintf(stderr, "qemu: Error registering flash memory.\n");
+ exit(1);
+ }
mst_irq = mst_irq_init(cpu, MST_FPGA_PHYS, PXA2XX_PIC_GPIO_0);
smc91c111_init(&nd_table[0], MST_ETH_PHYS, mst_irq[ETHERNET_IRQ]);
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index ac6800f65f..6af5e52dc4 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -53,6 +53,8 @@
#define ENVP_NB_ENTRIES 16
#define ENVP_ENTRY_SIZE 256
+#define MAX_IDE_BUS 2
+
extern FILE *logfile;
typedef struct {
@@ -776,6 +778,9 @@ void mips_malta_init (int ram_size, int vga_ram_size,
uint8_t *eeprom_buf;
i2c_bus *smbus;
int i;
+ int index;
+ BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
+ BlockDriverState *fd[MAX_FD];
/* init CPUs */
if (cpu_model == NULL) {
@@ -862,8 +867,22 @@ void mips_malta_init (int ram_size, int vga_ram_size,
pci_bus = pci_gt64120_init(i8259);
/* Southbridge */
+
+ if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
+ fprintf(stderr, "qemu: too many IDE bus\n");
+ exit(1);
+ }
+
+ for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
+ index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
+ if (index != -1)
+ hd[i] = drives_table[index].bdrv;
+ else
+ hd[i] = NULL;
+ }
+
piix4_devfn = 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 = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100);
eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
@@ -883,7 +902,14 @@ void mips_malta_init (int ram_size, int vga_ram_size,
serial_init(0x2f8, i8259[3], serial_hds[1]);
if (parallel_hds[0])
parallel_init(0x378, i8259[7], parallel_hds[0]);
- floppy_controller = fdctrl_init(i8259[6], 2, 0, 0x3f0, fd_table);
+ for(i = 0; i < MAX_FD; i++) {
+ index = drive_get_index(IF_FLOPPY, 0, i);
+ if (index != -1)
+ fd[i] = drives_table[index].bdrv;
+ else
+ fd[i] = NULL;
+ }
+ floppy_controller = fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
/* Sound card */
#ifdef HAS_AUDIO
diff --git a/hw/mips_pica61.c b/hw/mips_pica61.c
index 2a358d53ef..ced0e55671 100644
--- a/hw/mips_pica61.c
+++ b/hw/mips_pica61.c
@@ -44,6 +44,9 @@
#define VIRT_TO_PHYS_ADDEND (-((int64_t)(int32_t)0x80000000))
+#define MAX_IDE_BUS 2
+#define MAX_FD 2
+
static const int ide_iobase[2] = { 0x1f0, 0x170 };
static const int ide_iobase2[2] = { 0x3f6, 0x376 };
static const int ide_irq[2] = { 14, 15 };
@@ -72,6 +75,8 @@ void mips_pica61_init (int ram_size, int vga_ram_size,
int i;
int available_ram;
qemu_irq *i8259;
+ int index;
+ BlockDriverState *fd[MAX_FD];
/* init CPUs */
if (cpu_model == NULL) {
@@ -141,9 +146,20 @@ void mips_pica61_init (int ram_size, int vga_ram_size,
i8042_mm_init(i8259[6], i8259[7], 0x80005060, 0);
/* IDE controller */
- for(i = 0; i < 2; i++)
+
+ if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
+ fprintf(stderr, "qemu: too many IDE bus\n");
+ exit(1);
+ }
+
+ for(i = 0; i < MAX_IDE_BUS; i++) {
+ int hd0, hd1;
+ hd0 = drive_get_index(IF_IDE, i, 0);
+ hd1 = 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 == -1 ? NULL : drives_table[hd0].bdrv,
+ hd1 == -1 ? NULL : drives_table[hd1].bdrv);
+ }
/* Network controller */
/* FIXME: missing NS SONIC DP83932 */
@@ -152,7 +168,14 @@ void mips_pica61_init (int ram_size, int vga_ram_size,
/* FIXME: missing NCR 53C94 */
/* ISA devices (floppy, serial, parallel) */
- fdctrl_init(i8259[1], 1, 1, 0x80003000, fd_table);
+
+ for (i = 0; i < MAX_FD; i++) {
+ index = drive_get_index(IF_FLOPPY, 0, i);
+ if (index == -1)
+ continue;
+ fd[i] = drives_table[index].bdrv;
+ }
+ fdctrl_init(i8259[1], 1, 1, 0x80003000, fd);
for(i = 0; i < MAX_SERIAL_PORTS; i++) {
if (serial_hds[i]) {
serial_mm_init(serial_base[i], 0, i8259[serial_irq[i]], serial_hds[i], 1);
diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
index d090a2a1cc..b1c0433f65 100644
--- a/hw/mips_r4k.c
+++ b/hw/mips_r4k.c
@@ -25,6 +25,8 @@
#define VIRT_TO_PHYS_ADDEND (-((int64_t)(int32_t)0x80000000))
+#define MAX_IDE_BUS 2
+
static const int ide_iobase[2] = { 0x1f0, 0x170 };
static const int ide_iobase2[2] = { 0x3f6, 0x376 };
static const int ide_irq[2] = { 14, 15 };
@@ -155,6 +157,8 @@ void mips_r4k_init (int ram_size, int vga_ram_size,
RTCState *rtc_state;
int i;
qemu_irq *i8259;
+ int index;
+ BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
/* init CPUs */
if (cpu_model == NULL) {
@@ -245,9 +249,23 @@ void mips_r4k_init (int ram_size, int vga_ram_size,
}
}
- for(i = 0; i < 2; i++)
+ if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
+ fprintf(stderr, "qemu: too many IDE bus\n");
+ exit(1);
+ }
+
+ for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
+ index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
+ if (index != -1)
+ hd[i] = drives_table[index].bdrv;
+ else
+ hd[i] = NULL;
+ }
+
+ for(i = 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]);
i8042_init(i8259[1], i8259[12], 0x60);
ds1225y_init(0x9000, "nvram");
diff --git a/hw/nand.c b/hw/nand.c
index 925583ae45..ea353ed957 100644
--- a/hw/nand.c
+++ b/hw/nand.c
@@ -444,14 +444,20 @@ struct nand_flash_s *nand_init(int manf_id, int chip_id)
{
int pagesize;
struct nand_flash_s *s;
+ int index;
if (nand_flash_ids[chip_id].size == 0) {
cpu_abort(cpu_single_env, "%s: Unsupported NAND chip ID.\n",
__FUNCTION__);
}
+ index = drive_get_index(IF_MTD, 0, 0);
+ if (index == -1) {
+ cpu_abort(cpu_single_env, "%s: missing MTD device\n",
+ __FUNCTION__);
+ }
s = (struct nand_flash_s *) qemu_mallocz(sizeof(struct nand_flash_s));
- s->bdrv = mtd_bdrv;
+ s->bdrv = drives_table[index].bdrv;
s->manf_id = manf_id;
s->chip_id = chip_id;
s->size = nand_flash_ids[s->chip_id].size << 20;
diff --git a/hw/omap.c b/hw/omap.c
index c8d5064f63..c56cd2423d 100644
--- a/hw/omap.c
+++ b/hw/omap.c
@@ -4901,6 +4901,7 @@ struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size,
struct omap_mpu_state_s *s = (struct omap_mpu_state_s *)
qemu_mallocz(sizeof(struct omap_mpu_state_s));
ram_addr_t imif_base, emiff_base;
+ int index;
if (!core)
core = "ti925t";
@@ -4997,7 +4998,13 @@ struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size,
omap_dpll_init(&s->dpll[1], 0xfffed000, omap_findclk(s, "dpll2"));
omap_dpll_init(&s->dpll[2], 0xfffed100, omap_findclk(s, "dpll3"));
- s->mmc = omap_mmc_init(0xfffb7800, sd_bdrv, s->irq[1][OMAP_INT_OQN],
+ index = drive_get_index(IF_SD, 0, 0);
+ if (index == -1) {
+ fprintf(stderr, "qemu: missing SecureDigital device\n");
+ exit(1);
+ }
+ s->mmc = 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"));
s->mpuio = omap_mpuio_init(0xfffb5000,
diff --git a/hw/pc.c b/hw/pc.c
index 7049c44a12..5f79cda98f 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -42,6 +42,8 @@
/* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. */
#define ACPI_DATA_SIZE 0x10000
+#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 gpr[8], uint16_t segs[6], uint16_t ip)
{
uint8_t bootsect[512], *p;
int i;
+ int hda;
- if (bs_table[0] == NULL) {
+ hda = drive_get_index(IF_IDE, 0, 0);
+ if (hda == -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 gpr[8], uint16_t segs[6], uint16_t ip)
memset(bootsect, 0, sizeof(bootsect));
/* Copy the MSDOS partition table if possible */
- bdrv_read(bs_table[0], 0, bootsect, 1);
+ bdrv_read(drives_table[hda].bdrv, 0, bootsect, 1);
/* Make sure we have a partition signature */
bootsect[510] = 0x55;
@@ -428,7 +432,7 @@ static void generate_bootsect(uint32_t gpr[8], uint16_t segs[6], uint16_t ip)
*p++ = segs[1]; /* CS */
*p++ = segs[1] >> 8;
- bdrv_set_boot_sector(bs_table[0], bootsect, sizeof(bootsect));
+ bdrv_set_boot_sector(drives_table[hda].bdrv, bootsect, sizeof(bootsect));
}
static int load_kernel(const char *filename, uint8_t *addr,
@@ -709,6 +713,9 @@ static void pc_init1(int ram_size, int vga_ram_size,
NICInfo *nd;
qemu_irq *cpu_irq;
qemu_irq *i8259;
+ int index;
+ BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
+ BlockDriverState *fd[MAX_FD];
linux_boot = (kernel_filename != NULL);
@@ -926,12 +933,25 @@ static void pc_init1(int ram_size, int vga_ram_size,
}
}
+ if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
+ fprintf(stderr, "qemu: too many IDE bus\n");
+ exit(1);
+ }
+
+ for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
+ index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
+ if (index != -1)
+ hd[i] = drives_table[index].bdrv;
+ else
+ hd[i] = 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 = 0; i < 2; i++) {
+ for(i = 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]);
}
}
@@ -941,9 +961,16 @@ static void pc_init1(int ram_size, int vga_ram_size,
audio_init(pci_enabled ? pci_bus : NULL, i8259);
#endif
- floppy_controller = fdctrl_init(i8259[6], 2, 0, 0x3f0, fd_table);
+ for(i = 0; i < MAX_FD; i++) {
+ index = drive_get_index(IF_FLOPPY, 0, i);
+ if (index != -1)
+ fd[i] = drives_table[index].bdrv;
+ else
+ fd[i] = NULL;
+ }
+ floppy_controller = fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
- cmos_init(ram_size, boot_device, bs_table);
+ cmos_init(ram_size, boot_device, hd);
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 vga_ram_size,
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;
- 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);
+ max_bus = drive_get_max_bus(IF_SCSI);
+
+ for (bus = 0; bus <= max_bus; bus++) {
+ scsi = lsi_scsi_init(pci_bus, -1);
+ for (unit = 0; unit < LSI_MAX_DEVS; unit++) {
+ index = drive_get_index(IF_SCSI, bus, unit);
+ if (index == -1)
+ continue;
+ lsi_scsi_attach(scsi, drives_table[index].bdrv, unit);
+ }
+ }
}
-#endif
}
static void pc_init_pci(int ram_size, int vga_ram_size,
diff --git a/hw/pci.h b/hw/pci.h
index 075754514a..96bb2136de 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -97,6 +97,7 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint32_t id,
pci_map_irq_fn map_irq, const char *name);
/* 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);
diff --git a/hw/ppc405_boards.c b/hw/ppc405_boards.c
index 91fecc877b..597f9b58a6 100644
--- a/hw/ppc405_boards.c
+++ b/hw/ppc405_boards.c
@@ -197,6 +197,7 @@ static void ref405ep_init (int ram_size, int vga_ram_size,
int linux_boot;
int fl_idx, fl_sectors, len;
int ppc_boot_device = boot_device[0];
+ int index;
/* XXX: fix this */
ram_bases[0] = 0x00000000;
@@ -223,17 +224,18 @@ static void ref405ep_init (int ram_size, int vga_ram_size,
bios_offset = sram_offset + sram_size;
fl_idx = 0;
#ifdef USE_FLASH_BIOS
- if (pflash_table[fl_idx] != NULL) {
- bios_size = bdrv_getlength(pflash_table[fl_idx]);
+ index = drive_get_index(IF_PFLASH, 0, fl_idx);
+ if (index != -1) {
+ bios_size = bdrv_getlength(drives_table[index].bdrv);
fl_sectors = (bios_size + 65535) >> 16;
#ifdef DEBUG_BOARD_INIT
printf("Register parallel flash %d size " ADDRX " at offset %08lx "
" 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_sectors);
#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_size, int vga_ram_size,
int linux_boot;
int fl_idx, fl_sectors;
int ppc_boot_device = boot_device[0];
+ int index;
/* RAM is soldered to the board so the size cannot be changed */
ram_bases[0] = 0x00000000;
@@ -536,8 +539,9 @@ static void taihu_405ep_init(int ram_size, int vga_ram_size,
#endif
fl_idx = 0;
#if defined(USE_FLASH_BIOS)
- if (pflash_table[fl_idx] != NULL) {
- bios_size = bdrv_getlength(pflash_table[fl_idx]);
+ index = drive_get_index(IF_PFLASH, 0, fl_idx);
+ if (index != -1) {
+ bios_size = bdrv_getlength(drives_table[index].bdrv);
/* XXX: should check that size is 2MB */
// bios_size = 2 * 1024 * 1024;
fl_sectors = (bios_size + 65535) >> 16;
@@ -545,10 +549,10 @@ static void taihu_405ep_init(int ram_size, int vga_ram_size,
printf("Register parallel flash %d size " ADDRX " at offset %08lx "
" 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_sectors);
#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_size, int vga_ram_size,
}
bios_offset += bios_size;
/* Register Linux flash */
- if (pflash_table[fl_idx] != NULL) {
- bios_size = bdrv_getlength(pflash_table[fl_idx]);
+ index = drive_get_index(IF_PFLASH, 0, fl_idx);
+ if (index != -1) {
+ bios_size = bdrv_getlength(drives_table[index].bdrv);
/* XXX: should check that size is 32MB */
bios_size = 32 * 1024 * 1024;
fl_sectors = (bios_size + 65535) >> 16;
@@ -580,9 +585,9 @@ static void taihu_405ep_init(int ram_size, int vga_ram_size,
printf("Register parallel flash %d size " ADDRX " at offset %08lx "
" 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].bdrv,
65536, fl_sectors, 4,
0x0001, 0x22DA, 0x0000, 0x0000);
fl_idx++;
diff --git a/hw/ppc_chrp.c b/hw/ppc_chrp.c
index 1e3e6c4f6c..4437a1038e 100644
--- a/hw/ppc_chrp.c
+++ b/hw/ppc_chrp.c
@@ -32,6 +32,8 @@
#include "sysemu.h"
#include "boards.h"
+#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_size, int vga_ram_size,
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];
linux_boot = (kernel_filename != NULL);
@@ -266,11 +270,22 @@ static void ppc_core99_init (int ram_size, int vga_ram_size,
nd_table[i].model = "ne2k_pci";
pci_nic_init(pci_bus, &nd_table[i], -1);
}
+ if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
+ fprintf(stderr, "qemu: too many IDE bus\n");
+ exit(1);
+ }
+ for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
+ index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
+ if (index != -1)
+ hd[i] = drives_table[index].bdrv;
+ else
+ hd[i] = NULL;
+ }
#if 1
- ide_mem_index[0] = pmac_ide_init(&bs_table[0], pic[0x13]);
- ide_mem_index[1] = pmac_ide_init(&bs_table[2], pic[0x14]);
+ ide_mem_index[0] = pmac_ide_init(&hd[0], pic[0x13]);
+ ide_mem_index[1] = 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]);
diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c
index 53edcd5c66..6b4f202d01 100644
--- a/hw/ppc_oldworld.c
+++ b/hw/ppc_oldworld.c
@@ -33,6 +33,8 @@
#include "pci.h"
#include "boards.h"
+#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 */
@@ -123,6 +125,8 @@ static void ppc_heathrow_init (int ram_size, int vga_ram_size,
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;
linux_boot = (kernel_filename != NULL);
@@ -292,10 +296,37 @@ static void ppc_heathrow_init (int ram_size, int vga_ram_size,
}
/* 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) >= MAX_IDE_BUS) {
+ fprintf(stderr, "qemu: too many IDE bus\n");
+ exit(1);
+ }
+ index = drive_get_index(IF_IDE, 0, 0);
+ if (index == -1)
+ hd[0] = NULL;
+ else
+ hd[0] = drives_table[index].bdrv;
+ index = drive_get_index(IF_IDE, 0, 1);
+ if (index == -1)
+ hd[1] = NULL;
+ else
+ hd[1] = drives_table[index].bdrv;
+ hd[3] = hd[2] = NULL;
+ pci_cmd646_ide_init(pci_bus, hd, 0);
+
/* Second IDE channel is a MAC IDE on the MacIO bus */
+ index = drive_get_index(IF_IDE, 1, 0);
+ if (index == -1)
+ hd[0] = NULL;
+ else
+ hd[0] = drives_table[index].bdrv;
+ index = drive_get_index(IF_IDE, 1, 1);
+ if (index == -1)
+ hd[1] = NULL;
+ else
+ hd[1] = drives_table[index].bdrv;
ide_mem_index[0] = -1;
- ide_mem_index[1] = pmac_ide_init(&bs_table[2], pic[0x0D]);
+ ide_mem_index[1] = pmac_ide_init(hd, pic[0x0D]);
/* cuda also initialize ADB */
cuda_init(&cuda_mem_index, pic[0x12]);
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index 8e939760d3..c42688e427 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -38,6 +38,8 @@
/* SMP is not enabled, for now */
#define MAX_CPUS 1
+#define MAX_IDE_BUS 2
+
#define BIOS_FILENAME "ppc_rom.bin"
#define KERNEL_LOAD_ADDR 0x01000000
#define INITRD_LOAD_ADDR 0x01800000
@@ -551,6 +553,9 @@ static void ppc_prep_init (int ram_size, int vga_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];
sysctrl = qemu_mallocz(sizeof(sysctrl_t));
if (sysctrl == NULL)
@@ -675,16 +680,37 @@ static void ppc_prep_init (int ram_size, int vga_ram_size,
}
}
- for(i = 0; i < 2; i++) {
+ if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
+ fprintf(stderr, "qemu: too many IDE bus\n");
+ exit(1);
+ }
+
+ for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
+ index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
+ if (index != -1)
+ hd[i] = drives_table[index].bdrv;
+ else
+ hd[i] = NULL;
+ }
+
+ for(i = 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();
- fdctrl_init(i8259[6], 2, 0, 0x3f0, fd_table);
+ for(i = 0; i < MAX_FD; i++) {
+ index = drive_get_index(IF_FLOPPY, 0, i);
+ if (index != -1)
+ fd[i] = drives_table[index].bdrv;
+ else
+ fd[i] = NULL;
+ }
+ fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
/* Register speaker port */
register_ioport_read(0x61, 1, 1, speaker_ioport_read, NULL);
diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
index 00cb2370ae..a67ffefd0d 100644
--- a/hw/pxa2xx.c
+++ b/hw/pxa2xx.c
@@ -2036,6 +2036,7 @@ struct pxa2xx_state_s *pxa270_init(unsigned int sdram_size,
struct pxa2xx_state_s *s;
struct pxa2xx_ssp_s *ssp;
int iomemtype, i;
+ int index;
s = (struct pxa2xx_state_s *) qemu_mallocz(sizeof(struct pxa2xx_state_s));
if (revision && strncmp(revision, "pxa27", 5)) {
@@ -2070,8 +2071,13 @@ struct pxa2xx_state_s *pxa270_init(unsigned int sdram_size,
s->gpio = pxa2xx_gpio_init(0x40e00000, s->env, s->pic, 121);
- s->mmc = pxa2xx_mmci_init(0x41100000, sd_bdrv, s->pic[PXA2XX_PIC_MMC],
- s->dma);
+ index = drive_get_index(IF_SD, 0, 0);
+ if (index == -1) {
+ fprintf(stderr, "qemu: missing SecureDigital device\n");
+ exit(1);
+ }
+ s->mmc = pxa2xx_mmci_init(0x41100000, drives_table[index].bdrv,
+ s->pic[PXA2XX_PIC_MMC], s->dma);
for (i = 0; pxa270_serial[i].io_base; i ++)
if (serial_hds[i])
@@ -2160,6 +2166,7 @@ struct pxa2xx_state_s *pxa255_init(unsigned int sdram_size,
struct pxa2xx_state_s *s;
struct pxa2xx_ssp_s *ssp;
int iomemtype, i;
+ int index;
s = (struct pxa2xx_state_s *) qemu_mallocz(sizeof(struct pxa2xx_state_s));
@@ -2187,8 +2194,13 @@ struct pxa2xx_state_s *pxa255_init(unsigned int sdram_size,
s->gpio = pxa2xx_gpio_init(0x40e00000, s->env, s->pic, 85);
- s->mmc = pxa2xx_mmci_init(0x41100000, sd_bdrv, s->pic[PXA2XX_PIC_MMC],
- s->dma);
+ index = drive_get_index(IF_SD, 0, 0);
+ if (index == -1) {
+ fprintf(stderr, "qemu: missing SecureDigital device\n");
+ exit(1);
+ }
+ s->mmc = pxa2xx_mmci_init(0x41100000, drives_table[index].bdrv,
+ s->pic[PXA2XX_PIC_MMC], s->dma);
for (i = 0; pxa255_serial[i].io_base; i ++)
if (serial_hds[i])
diff --git a/hw/realview.c b/hw/realview.c
index 7e8586f4a3..29579d87b0 100644
--- a/hw/realview.c
+++ b/hw/realview.c
@@ -32,6 +32,7 @@ static void realview_init(int ram_size, int vga_ram_size,
int done_smc = 0;
qemu_irq cpu_irq[4];
int ncpu;
+ int index;
if (!cpu_model)
cpu_model = "arm926";
@@ -89,7 +90,12 @@ static void realview_init(int ram_size, int vga_ram_size,
pl110_init(ds, 0x10020000, pic[23], 1);
- pl181_init(0x10005000, sd_bdrv, pic[17], pic[18]);
+ index = drive_get_index(IF_SD, 0, 0);
+ if (index == -1) {
+ fprintf(stderr, "qemu: missing SecureDigital card\n");
+ exit(1);
+ }
+ pl181_init(0x10005000, drives_table[index].bdrv, pic[17], pic[18]);
pl031_init(0x10017000, pic[10]);
@@ -97,11 +103,16 @@ static void realview_init(int ram_size, int vga_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 = 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++) {
+ index = drive_get_index(IF_SCSI, 0, n);
+ if (index == -1)
+ continue;
+ lsi_scsi_attach(scsi_hba, drives_table[index].bdrv, n);
}
for(n = 0; n < nb_nics; n++) {
nd = &nd_table[n];
diff --git a/hw/spitz.c b/hw/spitz.c
index 461a60dd83..159c633789 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -940,9 +940,14 @@ static void spitz_ssp_attach(struct pxa2xx_state_s *cpu)
static void spitz_microdrive_attach(struct pxa2xx_state_s *cpu)
{
struct pcmcia_card_s *md;
- BlockDriverState *bs = bs_table[0];
+ int index;
+ BlockDriverState *bs;
- if (bs && bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) {
+ index = drive_get_index(IF_IDE, 0, 0);
+ if (index == -1)
+ return;
+ bs = drives_table[index].bdrv;
+ if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) {
md = dscm1xxxx_init(bs);
pxa2xx_pcmcia_attach(cpu->pcmcia[1], md);
}
diff --git a/hw/stellaris.c b/hw/stellaris.c
index 5f06388a94..2fb927b614 100644
--- a/hw/stellaris.c
+++ b/hw/stellaris.c
@@ -1133,9 +1133,11 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
void * oled;
void * sd;
void *ssi_bus;
+ int index;
oled = ssd0323_init(ds, &gpio_out[GPIO_C][7]);
- sd = ssi_sd_init(sd_bdrv);
+ index = drive_get_index(IF_SD, 0, 0);
+ sd = ssi_sd_init(drives_table[index].bdrv);
ssi_bus = stellaris_ssi_bus_init(&gpio_out[GPIO_D][0],
ssi_sd_xfer, sd,
diff --git a/hw/sun4m.c b/hw/sun4m.c
index 1f78ff8935..428519a5a5 100644
--- a/hw/sun4m.c
+++ b/hw/sun4m.c
@@ -338,6 +338,8 @@ static void sun4m_hw_init(const struct hwdef *hwdef, int RAM_size,
unsigned long prom_offset, kernel_size;
int ret;
char buf[1024];
+ BlockDriverState *fd[MAX_FD];
+ int index;
/* init CPUs */
if (!cpu_model)
@@ -440,16 +442,29 @@ static void sun4m_hw_init(const struct hwdef *hwdef, int RAM_size,
slavio_serial_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
serial_hds[1], serial_hds[0]);
- if (hwdef->fd_base != (target_phys_addr_t)-1)
- sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd_table);
+ if (hwdef->fd_base != (target_phys_addr_t)-1) {
+ /* there is zero or one floppy drive */
+ fd[1] = fd[0] = NULL;
+ index = drive_get_index(IF_FLOPPY, 0, 0);
+ if (index != -1)
+ fd[0] = drives_table[index].bdrv;
- main_esp = 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 = esp_init(hwdef->esp_base, espdma, *espdma_irq,
esp_reset);
- for (i = 0; i < MAX_DISKS; i++) {
- if (bs_table[i]) {
- esp_scsi_attach(main_esp, bs_table[i], i);
- }
+ for (i = 0; i < ESP_MAX_DEVS; i++) {
+ index = drive_get_index(IF_SCSI, 0, i);
+ if (index == -1)
+ continue;
+ esp_scsi_attach(main_esp, drives_table[index].bdrv, i);
}
slavio_misc = slavio_misc_init(hwdef->slavio_base, hwdef->power_base,
diff --git a/hw/sun4m.h b/hw/sun4m.h
index 12fa83223b..e0ae5faf97 100644
--- a/hw/sun4m.h
+++ b/hw/sun4m.h
@@ -49,8 +49,9 @@ void *slavio_misc_init(target_phys_addr_t base, target_phys_addr_t power_base,
void slavio_set_power_fail(void *opaque, int power_failing);
/* 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);
/* cs4231.c */
diff --git a/hw/sun4u.c b/hw/sun4u.c
index 6fb7faeb38..183f64a5ac 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -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
/* TSC handling */
@@ -240,6 +241,9 @@ static void sun4u_init(int ram_size, int vga_ram_size,
PCIBus *pci_bus;
QEMUBH *bh;
qemu_irq *irq;
+ int index;
+ BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
+ BlockDriverState *fd[MAX_FD];
linux_boot = (kernel_filename != NULL);
@@ -342,11 +346,30 @@ static void sun4u_init(int ram_size, int vga_ram_size,
}
irq = 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) >= MAX_IDE_BUS) {
+ fprintf(stderr, "qemu: too many IDE bus\n");
+ exit(1);
+ }
+ for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
+ index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
+ if (index != -1)
+ hd[i] = drives_table[index].bdrv;
+ else
+ hd[i] = 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 = fdctrl_init(NULL/*6*/, 2, 0, 0x3f0, fd_table);
+ for(i = 0; i < MAX_FD; i++) {
+ index = drive_get_index(IF_FLOPPY, 0, i);
+ if (index != -1)
+ fd[i] = drives_table[index].bdrv;
+ else
+ fd[i] = NULL;
+ }
+ floppy_controller = fdctrl_init(NULL/*6*/, 2, 0, 0x3f0, fd);
nvram = m48t59_init(NULL/*8*/, 0, 0x0074, NVRAM_SIZE, 59);
sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", ram_size, boot_devices,
KERNEL_LOAD_ADDR, kernel_size,
diff --git a/hw/versatilepb.c b/hw/versatilepb.c
index 66e11bf735..da6e4ec330 100644
--- a/hw/versatilepb.c
+++ b/hw/versatilepb.c
@@ -171,6 +171,7 @@ static void versatile_init(int ram_size, int vga_ram_size,
NICInfo *nd;
int n;
int done_smc = 0;
+ int index;
if (!cpu_model)
cpu_model = "arm926";
@@ -206,11 +207,16 @@ static void versatile_init(int ram_size, int vga_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 = 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++) {
+ index = drive_get_index(IF_SCSI, 0, n);
+ if (index == -1)
+ continue;
+ lsi_scsi_attach(scsi_hba, drives_table[index].bdrv, n);
}
pl011_init(0x101f1000, pic[12], serial_hds[0], PL011_ARM);
@@ -226,7 +232,13 @@ static void versatile_init(int ram_size, int vga_ram_size,
that includes hardware cursor support from the PL111. */
pl110_init(ds, 0x10120000, pic[16], 1);
- pl181_init(0x10005000, sd_bdrv, sic[22], sic[1]);
+ index = drive_get_index(IF_SD, 0, 0);
+ if (index == -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);
diff --git a/monitor.c b/monitor.c
index dd85f847d7..bb05ca6baf 100644
--- a/monitor.c
+++ b/monitor.c
@@ -215,16 +215,11 @@ static void do_commit(const char *device)
int i, all_devices;
all_devices = !strcmp(device, "all");
- for (i = 0; i < MAX_DISKS; i++) {
- if (bs_table[i]) {
+ for (i = 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), device))
+ bdrv_commit(drives_table[i].bdrv);
}
- if (mtd_bdrv)
- if (all_devices || !strcmp(bdrv_get_device_name(mtd_bdrv), device))
- bdrv_commit(mtd_bdrv);
}
static void do_info(const char *item)
diff --git a/sysemu.h b/sysemu.h
index d54f115aa2..8bb88b12cd 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -116,15 +116,26 @@ extern unsigned int nb_prom_envs;
#define BIOS_SIZE (4 * 1024 * 1024)
#endif
-#define MAX_DISKS 4
-
-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];
+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
+
+int nb_drives;
+DriveInfo drives_table[MAX_DRIVES+1];
+
+extern int drive_get_index(BlockInterfaceType interface, int bus, int unit);
+extern int drive_get_max_bus(BlockInterfaceType interface);
/* serial ports */
diff --git a/vl.c b/vl.c
index f24c9670ac..3a694c4730 100644
--- a/vl.c
+++ b/vl.c
@@ -163,12 +163,10 @@ const char *bios_name = NULL;
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 available
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;
@@ -232,6 +230,8 @@ int alt_grab = 0;
unsigned int nb_prom_envs = 0;
const char *prom_envs[MAX_PROM_ENVS];
#endif
+int nb_drives_opt;
+char drives_opt[MAX_DRIVES][1024];
#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
@@ -1758,12 +1758,9 @@ static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch)
case 's':
{
int i;
- for (i = 0; i < MAX_DISKS; i++) {
- if (bs_table[i])
- bdrv_commit(bs_table[i]);
+ for (i = 0; i < nb_drives; i++) {
+ bdrv_commit(drives_table[i].bdrv);
}
- if (mtd_bdrv)
- bdrv_commit(mtd_bdrv);
}
break;
case 'b':
@@ -4554,38 +4551,51 @@ static int net_socket_mcast_init(VLANState *vlan, const char *host_str)
}
+static const char *get_word(char *buf, int buf_size, const char *p)
+{
+ char *q;
+ int substring;
+
+ substring = 0;
+ q = buf;
+ while (*p != '\0') {
+ if (*p == '\\') {
+ p++;
+ if (*p == '\0')
+ break;
+ } else if (*p == '\"') {
+ substring = !substring;
+ p++;
+ continue;
+ } else if (!substring && (*p == ',' || *p == '='))
+ break;
+ if (q && (q - buf) < buf_size - 1)
+ *q++ = *p;
+ p++;
+ }
+ if (q)
+ *q = '\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];
p = str;
for(;;) {
- q = option;
- while (*p != '\0' && *p != '=') {
- if ((q - option) < sizeof(option) - 1)
- *q++ = *p;
- p++;
- }
- *q = '\0';
+ p = get_word(option, sizeof(option), p);
if (*p != '=')
break;
p++;
if (!strcmp(tag, option)) {
- q = buf;
- while (*p != '\0' && *p != ',') {
- if ((q - buf) < buf_size - 1)
- *q++ = *p;
- p++;
- }
- *q = '\0';
- return q - buf;
+ (void)get_word(buf, buf_size, p);
+ return strlen(buf);
} else {
- while (*p != '\0' && *p != ',') {
- p++;
- }
+ p = get_word(NULL, 0, p);
}
if (*p != ',')
break;
@@ -4594,6 +4604,32 @@ static int get_param_value(char *buf, int buf_size,
return 0;
}
+static int check_params(char *buf, int buf_size,
+ char **params, const char *str)
+{
+ const char *p;
+ int i;
+
+ p = str;
+ for(;;) {
+ p = get_word(buf, buf_size, p);
+ if (*p != '=')
+ return -1;
+ p++;
+ for(i = 0; params[i] != NULL; i++)
+ if (!strcmp(params[i], buf))
+ break;
+ if (params[i] == NULL)
+ return -1;
+ p = get_word(NULL, 0, p);
+ if (*p != ',')
+ break;
+ p++;
+ }
+ return 0;
+}
+
+
static int net_client_init(const char *str)
{
const char *p;
@@ -4744,6 +4780,323 @@ void do_info_network(void)
}
}
+#define HD_ALIAS "file=\"%s\",index=%d,media=disk"
+#ifdef TARGET_PPC
+#define CDROM_ALIAS "index=1,media=cdrom"
+#else
+#define CDROM_ALIAS "index=2,media=cdrom"
+#endif
+#define FD_ALIAS "index=%d,if=floppy"
+#define PFLASH_ALIAS "file=\"%s\",if=pflash"
+#define MTD_ALIAS "file=\"%s\",if=mtd"
+#define SD_ALIAS "file=\"%s\",if=sd"
+
+static int drive_add(const char *fmt, ...)
+{
+ va_list ap;
+
+ if (nb_drives_opt >= 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 = 0; index < nb_drives; index++)
+ if (drives_table[index].interface == interface &&
+ drives_table[index].bus == bus &&
+ drives_table[index].unit == unit)
+ return index;
+
+ return -1;
+}
+
+int drive_get_max_bus(BlockInterfaceType interface)
+{
+ int max_bus;
+ int index;
+
+ max_bus = -1;
+ for (index = 0; index < nb_drives; index++) {
+ if(drives_table[index].interface == interface &&
+ drives_table[index].bus > max_bus)
+ max_bus = drives_table[index].bus;
+ }
+ return max_bus;
+}
+
+static int drive_init(const char *str, int snapshot, QEMUMachine *machine)
+{
+ 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[] = { "bus", "unit", "if", "index", "cyls", "heads",
+ "secs", "trans", "media", "snapshot", "file", NULL };
+
+ if (check_params(buf, sizeof(buf), params, str) < 0) {
+ fprintf(stderr, "qemu: unknowm parameter '%s' in '%s'\n",
+ buf, str);
+ return -1;
+ }
+
+ file[0] = 0;
+ cyls = heads = secs = 0;
+ bus_id = 0;
+ unit_id = -1;
+ translation = BIOS_ATA_TRANSLATION_AUTO;
+ index = -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 = IF_SCSI;
+ max_devs = MAX_SCSI_DEVS;
+ } else {
+ interface = IF_IDE;
+ max_devs = MAX_IDE_DEVS;
+ }
+ media = MEDIA_DISK;
+
+ /* extract parameters */
+
+ if (get_param_value(buf, sizeof(buf), "bus", str)) {
+ bus_id = 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 = 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 = IF_IDE;
+ max_devs = MAX_IDE_DEVS;
+ } else if (!strcmp(buf, "scsi")) {
+ interface = IF_SCSI;
+ max_devs = MAX_SCSI_DEVS;
+ } else if (!strcmp(buf, "floppy")) {
+ interface = IF_FLOPPY;
+ max_devs = 0;
+ } else if (!strcmp(buf, "pflash")) {
+ interface = IF_PFLASH;
+ max_devs = 0;
+ } else if (!strcmp(buf, "mtd")) {
+ interface = IF_MTD;
+ max_devs = 0;
+ } else if (!strcmp(buf, "sd")) {
+ interface = IF_SD;
+ max_devs = 0;
+ } else {
+ fprintf(stderr, "qemu: '%s' unsupported bus type '%s'\n", str, buf);
+ return -1;
+ }
+ }
+
+ if (get_param_value(buf, sizeof(buf), "index", str)) {
+ index = 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 = strtol(buf, NULL, 0);
+ }
+
+ if (get_param_value(buf, sizeof(buf), "heads", str)) {
+ heads = strtol(buf, NULL, 0);
+ }
+
+ if (get_param_value(buf, sizeof(buf), "secs", str)) {
+ secs = 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 secs\n",
+ str);
+ return -1;
+ }
+ if (!strcmp(buf, "none"))
+ translation = BIOS_ATA_TRANSLATION_NONE;
+ else if (!strcmp(buf, "lba"))
+ translation = BIOS_ATA_TRANSLATION_LBA;
+ else if (!strcmp(buf, "auto"))
+ translation = 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 = MEDIA_DISK;
+ } else if (!strcmp(buf, "cdrom")) {
+ if (cyls || secs || heads) {
+ fprintf(stderr,
+ "qemu: '%s' invalid physical CHS format\n", str);
+ return -1;
+ }
+ media = 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 = 1;
+ else if (!strcmp(buf, "off"))
+ snapshot = 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 != -1) {
+ if (bus_id != 0 || unit_id != -1) {
+ fprintf(stderr,
+ "qemu: '%s' index cannot be used with bus and unit\n", str);
+ return -1;
+ }
+ if (max_devs == 0)
+ {
+ unit_id = index;
+ bus_id = 0;
+ } else {
+ unit_id = index % max_devs;
+ bus_id = index / max_devs;
+ }
+ }
+
+ /* if user doesn't specify a unit_id,
+ * try to find the first free
+ */
+
+ if (unit_id == -1) {
+ unit_id = 0;
+ while (drive_get_index(interface, bus_id, unit_id) != -1) {
+ unit_id++;
+ if (max_devs && unit_id >= max_devs) {
+ unit_id -= max_devs;
+ bus_id++;
+ }
+ }
+ }
+
+ /* check unit id */
+
+ if (max_devs && unit_id >= 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) != -1)
+ return 0;
+
+ /* init */
+
+ snprintf(buf, sizeof(buf), "drive%d", nb_drives);
+ bdrv = bdrv_new(buf);
+ drives_table[nb_drives].bdrv = bdrv;
+ drives_table[nb_drives].interface = interface;
+ drives_table[nb_drives].bus = bus_id;
+ drives_table[nb_drives].unit = unit_id;
+ nb_drives++;
+
+ switch(interface) {
+ case IF_IDE:
+ case IF_SCSI:
+ switch(media) {
+ case MEDIA_DISK:
+ if (cyls != 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 */
@@ -5526,8 +5879,8 @@ static BlockDriverState *get_bs_snapshots(void)
if (bs_snapshots)
return bs_snapshots;
- for(i = 0; i <= MAX_DISKS; i++) {
- bs = bs_table[i];
+ for(i = 0; i <= nb_drives; i++) {
+ bs = drives_table[i].bdrv;
if (bdrv_can_snapshot(bs))
goto ok;
}
@@ -5635,8 +5988,8 @@ void do_savevm(const char *name)
/* create the snapshots */
- for(i = 0; i < MAX_DISKS; i++) {
- bs1 = bs_table[i];
+ for(i = 0; i < nb_drives; i++) {
+ bs1 = drives_table[i].bdrv;
if (bdrv_has_snapshot(bs1)) {
if (must_delete) {
ret = bdrv_snapshot_delete(bs1, old_sn->id_str);
@@ -5678,8 +6031,8 @@ void do_loadvm(const char *name)
saved_vm_running = vm_running;
vm_stop(0);
- for(i = 0; i <= MAX_DISKS; i++) {
- bs1 = bs_table[i];
+ for(i = 0; i <= nb_drives; i++) {
+ bs1 = drives_table[i].bdrv;
if (bdrv_has_snapshot(bs1)) {
ret = bdrv_snapshot_goto(bs1, name);
if (ret < 0) {
@@ -5739,8 +6092,8 @@ void do_delvm(const char *name)
return;
}
- for(i = 0; i <= MAX_DISKS; i++) {
- bs1 = bs_table[i];
+ for(i = 0; i <= nb_drives; i++) {
+ bs1 = drives_table[i].bdrv;
if (bdrv_has_snapshot(bs1)) {
ret = bdrv_snapshot_delete(bs1, name);
if (ret < 0) {
@@ -5768,8 +6121,8 @@ void do_info_snapshots(void)
return;
}
term_printf("Snapshot devices:");
- for(i = 0; i <= MAX_DISKS; i++) {
- bs1 = bs_table[i];
+ for(i = 0; i <= nb_drives; i++) {
+ bs1 = drives_table[i].bdrv;
if (bdrv_has_snapshot(bs1)) {
if (bs == bs1)
term_printf(" %s", bdrv_get_device_name(bs1));
@@ -6519,15 +6872,14 @@ static void ram_save(QEMUFile *f, void *opaque)
/* find if the memory block is available on a virtual
block device */
sector_num = -1;
- for(j = 0; j < MAX_DISKS; j++) {
- if (bs_table[j]) {
- sector_num = bdrv_hash_find(bs_table[j],
- phys_ram_base + i, BDRV_HASH_BLOCK_SIZE);
- if (sector_num >= 0)
- break;
- }
+ for(j = 0; j < nb_drives; j++) {
+ sector_num = bdrv_hash_find(drives_table[j].bdrv,
+ phys_ram_base + i,
+ BDRV_HASH_BLOCK_SIZE);
+ if (sector_num >= 0)
+ break;
}
- if (j == MAX_DISKS)
+ if (j == nb_drives)
goto normal_compress;
buf[0] = 1;
buf[1] = j;
@@ -6578,11 +6930,12 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
ram_decompress_buf(s, buf + 1, 9);
bs_index = buf[1];
sector_num = be64_to_cpupu((const uint64_t *)(buf + 2));
- if (bs_index >= MAX_DISKS || bs_table[bs_index] == NULL) {
+ if (bs_index >= nb_drives) {
fprintf(stderr, "Invalid block device index %d\n", bs_index);
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);
@@ -7079,6 +7432,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=file][,if=type][,bus=n][,unit=m][,media=d][index=i]\n"
+ " [,cyls=c,heads=h,secs=s[,trans=t]][snapshot=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"
@@ -7224,6 +7580,7 @@ enum {
QEMU_OPTION_hdb,
QEMU_OPTION_hdc,
QEMU_OPTION_hdd,
+ QEMU_OPTION_drive,
QEMU_OPTION_cdrom,
QEMU_OPTION_mtdblock,
QEMU_OPTION_sd,
@@ -7313,6 +7670,7 @@ const QEMUOption qemu_options[] = {
{ "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 },
@@ -7425,16 +7783,9 @@ int qemu_key_check(BlockDriverState *bs, const char *name)
static BlockDriverState *get_bdrv(int index)
{
- BlockDriverState *bs;
-
- if (index < 4) {
- bs = bs_table[index];
- } else if (index < 6) {
- bs = fd_table[index - 4];
- } else {
- bs = NULL;
- }
- return bs;
+ if (index > nb_drives)
+ return NULL;
+ return drives_table[index].bdrv;
}
static void read_passwords(void)
@@ -7637,19 +7988,16 @@ int main(int argc, char **argv)
const char *gdbstub_port;
#endif
uint32_t boot_devices_bitmap = 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 = "";
DisplayState *ds = &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;
@@ -7702,15 +8050,6 @@ int main(int argc, char **argv)
machine = first_machine;
cpu_model = NULL;
initrd_filename = NULL;
- for(i = 0; i < MAX_FD; i++)
- fd_filename[i] = NULL;
- for(i = 0; i < MAX_DISKS; i++)
- hd_filename[i] = NULL;
- for(i = 0; i < MAX_PFLASH; i++)
- pflash_filename[i] = NULL;
- pflash_index = 0;
- sd_filename = NULL;
- mtd_filename = NULL;
ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
vga_ram_size = VGA_RAM_SIZE;
#ifdef CONFIG_GDBSTUB
@@ -7721,11 +8060,6 @@ int main(int argc, char **argv)
nographic = 0;
kernel_filename = NULL;
kernel_cmdline = "";
-#ifdef TARGET_PPC
- cdrom_index = 1;
-#else
- cdrom_index = 2;
-#endif
cyls = heads = secs = 0;
translation = BIOS_ATA_TRANSLATION_AUTO;
pstrcpy(monitor_device, sizeof(monitor_device), "vc");
@@ -7743,6 +8077,9 @@ int main(int argc, char **argv)
usb_devices_index = 0;
nb_net_clients = 0;
+ nb_drives = 0;
+ nb_drives_opt = 0;
+ hda_index = -1;
nb_nics = 0;
/* default mac address of the first network interface */
@@ -7753,7 +8090,7 @@ int main(int argc, char **argv)
break;
r = argv[optind];
if (r[0] != '-') {
- hd_filename[0] = argv[optind++];
+ hda_index = drive_add(HD_ALIAS, argv[optind++], 0);
} else {
const QEMUOption *popt;
@@ -7813,29 +8150,33 @@ int main(int argc, char **argv)
initrd_filename = optarg;
break;
case QEMU_OPTION_hda:
+ if (cyls == 0)
+ hda_index = drive_add(HD_ALIAS, optarg, 0);
+ else
+ hda_index = drive_add(HD_ALIAS
+ ",cyls=%d,heads=%d,secs=%d%s",
+ optarg, 0, cyls, heads, secs,
+ translation == BIOS_ATA_TRANSLATION_LBA ?
+ ",trans=lba" :
+ translation == BIOS_ATA_TRANSLATION_NONE ?
+ ",trans=none" : "");
+ break;
case QEMU_OPTION_hdb:
case QEMU_OPTION_hdc:
case QEMU_OPTION_hdd:
- {
- int hd_index;
- hd_index = popt->index - QEMU_OPTION_hda;
- hd_filename[hd_index] = optarg;
- if (hd_index == cdrom_index)
- cdrom_index = -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 = optarg;
+ drive_add(MTD_ALIAS, optarg);
break;
case QEMU_OPTION_sd:
- sd_filename = optarg;
+ drive_add(SD_ALIAS, optarg);
break;
case QEMU_OPTION_pflash:
- if (pflash_index >= MAX_PFLASH) {
- fprintf(stderr, "qemu: too many parallel flash images\n");
- exit(1);
- }
- pflash_filename[pflash_index++] = optarg;
+ drive_add(PFLASH_ALIAS, optarg);
break;
case QEMU_OPTION_snapshot:
snapshot = 1;
@@ -7874,6 +8215,17 @@ int main(int argc, char **argv)
fprintf(stderr, "qemu: invalid physical CHS format\n");
exit(1);
}
+ if (hda_index != -1)
+ snprintf(drives_opt[hda_index] +
+ strlen(drives_opt[hda_index]),
+ sizeof(drives_opt[0]) -
+ strlen(drives_opt[hda_index]),
+ ",cyls=%d,heads=%d,secs=%d%s",
+ cyls, heads, secs,
+ translation == BIOS_ATA_TRANSLATION_LBA ?
+ ",trans=lba" :
+ translation == BIOS_ATA_TRANSLATION_NONE ?
+ ",trans=none" : "");
}
break;
case QEMU_OPTION_nographic:
@@ -7892,9 +8244,7 @@ int main(int argc, char **argv)
kernel_cmdline = optarg;
break;
case QEMU_OPTION_cdrom:
- if (cdrom_index >= 0) {
- hd_filename[cdrom_index] = optarg;
- }
+ drive_add("file=\"%s\"," CDROM_ALIAS, optarg);
break;
case QEMU_OPTION_boot:
boot_devices = optarg;
@@ -7928,10 +8278,9 @@ int main(int argc, char **argv)
}
break;
case QEMU_OPTION_fda:
- fd_filename[0] = optarg;
- break;
case QEMU_OPTION_fdb:
- fd_filename[1] = optarg;
+ drive_add("file=\"%s\"," FD_ALIAS, optarg,
+ popt->index - QEMU_OPTION_fda);
break;
#ifdef TARGET_I386
case QEMU_OPTION_no_fd_bootchk:
@@ -8312,20 +8661,12 @@ int main(int argc, char **argv)
/* XXX: this should not be: some embedded targets just have flash */
if (!linux_boot && net_boot == 0 &&
- hd_filename[0] == NULL &&
- (cdrom_index >= 0 && hd_filename[cdrom_index] == NULL) &&
- fd_filename[0] == NULL &&
- pflash_filename[0] == NULL)
+ nb_drives_opt == 0)
help(1);
/* boot to floppy or the default cd if no hard disk defined yet */
if (!boot_devices[0]) {
- if (hd_filename[0] != NULL)
- boot_devices = "c";
- else if (fd_filename[0] != NULL)
- boot_devices = "a";
- else
- boot_devices = "d";
+ boot_devices = "cad";
}
setvbuf(stdout, NULL, _IOLBF, 0);
@@ -8402,97 +8743,23 @@ int main(int argc, char **argv)
exit(1);
}
- /* we always create the cdrom drive, even if no disk is there */
bdrv_init();
- if (cdrom_index >= 0) {
- bs_table[cdrom_index] = bdrv_new("cdrom");
- bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM);
- }
- /* open the virtual block devices */
- for(i = 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] = 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 == 0 && cyls != 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 */
- /* we always create at least one floppy disk */
- fd_table[0] = bdrv_new("fda");
- bdrv_set_type_hint(fd_table[0], BDRV_TYPE_FLOPPY);
+ if (nb_drives_opt < MAX_DRIVES)
+ drive_add(CDROM_ALIAS);
- for(i = 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] = bdrv_new(buf);
- bdrv_set_type_hint(fd_table[i], BDRV_TYPE_FLOPPY);
- }
- if (fd_filename[i][0] != '\0') {
- if (bdrv_open(fd_table[i], fd_filename[i],
- snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
- fprintf(stderr, "qemu: could not open floppy disk image '%s'\n",
- fd_filename[i]);
- exit(1);
- }
- }
- }
- }
+ /* we always create at least on floppy */
- /* Open the virtual parallel flash block devices */
- for(i = 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] = 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);
- }
- }
- }
+ if (nb_drives_opt < MAX_DRIVES)
+ drive_add(FD_ALIAS, 0);
- sd_bdrv = 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 (mtd_filename) {
- mtd_bdrv = 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 = 0;
- }
- }
+ /* open the virtual block devices */
+
+ for(i = 0; i < nb_drives_opt; i++)
+ if (drive_init(drives_opt[i], snapshot, machine) == -1)
+ exit(1);
register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
register_savevm("ram", 0, 2, ram_save, ram_load, NULL);