Commit 751c6a17 authored by Gerd Hoffmann's avatar Gerd Hoffmann Committed by Anthony Liguori
Browse files

kill drives_table



First step cleaning up the drives handling.  This one does nothing but
removing drives_table[], still it became seriously big.

drive_get_index() is gone and is replaced by drives_get() which hands
out DriveInfo pointers instead of a table index.  This needs adaption in
*tons* of places all over.

The drives are now maintained as linked list.

Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
parent 8a14daa5
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -28,22 +28,23 @@
#include "block_int.h"
#include "sysemu.h"

int add_init_drive(const char *opts)
DriveInfo *add_init_drive(const char *opts)
{
    int drive_opt_idx, drive_idx;
    int ret = -1;
    int drive_opt_idx;
    int fatal_error;
    DriveInfo *dinfo;

    drive_opt_idx = drive_add(NULL, "%s", opts);
    if (!drive_opt_idx)
        return ret;
        return NULL;

    drive_idx = drive_init(&drives_opt[drive_opt_idx], 0, current_machine);
    if (drive_idx == -1) {
    dinfo = drive_init(&drives_opt[drive_opt_idx], 0, current_machine, &fatal_error);
    if (!dinfo) {
        drive_remove(drive_opt_idx);
        return ret;
        return NULL;
    }

    return drive_idx;
    return dinfo;
}

void destroy_nic(dev_match_fn *match_fn, void *arg)
@@ -64,11 +65,11 @@ void destroy_nic(dev_match_fn *match_fn, void *arg)

void destroy_bdrvs(dev_match_fn *match_fn, void *arg)
{
    int i;
    DriveInfo *dinfo;
    struct BlockDriverState *bs;

    for (i = 0; i <= MAX_DRIVES; i++) {
        bs = drives_table[i].bdrv;
    TAILQ_FOREACH(dinfo, &drives, next) {
        bs = dinfo->bdrv;
        if (bs) {
            if (bs->private && match_fn(bs->private, arg)) {
                drive_uninit(bs);
+3 −2
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ void bareetraxfs_init (ram_addr_t ram_size,
    void *etraxfs_dmac;
    struct etraxfs_dma_client *eth[2] = {NULL, NULL};
    int kernel_size;
    DriveInfo *dinfo;
    int i;
    ram_addr_t phys_ram;
    ram_addr_t phys_flash;
@@ -79,9 +80,9 @@ void bareetraxfs_init (ram_addr_t ram_size,


    phys_flash = qemu_ram_alloc(FLASH_SIZE);
    i = drive_get_index(IF_PFLASH, 0, 0);
    dinfo = drive_get(IF_PFLASH, 0, 0);
    pflash_cfi02_register(0x0, phys_flash,
                          i != -1 ? drives_table[i].bdrv : NULL, (64 * 1024),
                          dinfo ? dinfo->bdrv : NULL, (64 * 1024),
                          FLASH_SIZE >> 16,
                          1, 2, 0x0000, 0x0000, 0x0000, 0x0000,
                          0x555, 0x2aa);
+8 −8
Original line number Diff line number Diff line
@@ -47,22 +47,22 @@ static void connex_init(ram_addr_t ram_size,
                const char *initrd_filename, const char *cpu_model)
{
    PXA2xxState *cpu;
    int index;
    DriveInfo *dinfo;

    uint32_t connex_rom = 0x01000000;
    uint32_t connex_ram = 0x04000000;

    cpu = pxa255_init(connex_ram);

    index = drive_get_index(IF_PFLASH, 0, 0);
    if (index == -1) {
    dinfo = drive_get(IF_PFLASH, 0, 0);
    if (!dinfo) {
        fprintf(stderr, "A flash image must be given with the "
                "'pflash' parameter\n");
        exit(1);
    }

    if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(connex_rom),
            drives_table[index].bdrv, sector_len, connex_rom / sector_len,
            dinfo->bdrv, sector_len, connex_rom / sector_len,
            2, 0, 0, 0, 0)) {
        fprintf(stderr, "qemu: Error registering flash memory.\n");
        exit(1);
@@ -81,22 +81,22 @@ static void verdex_init(ram_addr_t ram_size,
                const char *initrd_filename, const char *cpu_model)
{
    PXA2xxState *cpu;
    int index;
    DriveInfo *dinfo;

    uint32_t verdex_rom = 0x02000000;
    uint32_t verdex_ram = 0x10000000;

    cpu = pxa270_init(verdex_ram, cpu_model ?: "pxa270-c0");

    index = drive_get_index(IF_PFLASH, 0, 0);
    if (index == -1) {
    dinfo = drive_get(IF_PFLASH, 0, 0);
    if (!dinfo) {
        fprintf(stderr, "A flash image must be given with the "
                "'pflash' parameter\n");
        exit(1);
    }

    if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(verdex_rom),
            drives_table[index].bdrv, sector_len, verdex_rom / sector_len,
            dinfo->bdrv, sector_len, verdex_rom / sector_len,
            2, 0, 0, 0, 0)) {
        fprintf(stderr, "qemu: Error registering flash memory.\n");
        exit(1);
+5 −4
Original line number Diff line number Diff line
@@ -77,7 +77,8 @@ static void mainstone_common_init(ram_addr_t ram_size,
    target_phys_addr_t mainstone_flash_base[] = { MST_FLASH_0, MST_FLASH_1 };
    PXA2xxState *cpu;
    qemu_irq *mst_irq;
    int i, index;
    DriveInfo *dinfo;
    int i;

    if (!cpu_model)
        cpu_model = "pxa270-c5";
@@ -92,8 +93,8 @@ static void mainstone_common_init(ram_addr_t ram_size,

    /* There are two 32MiB flash devices on the board */
    for (i = 0; i < 2; i ++) {
        index = drive_get_index(IF_PFLASH, 0, i);
        if (index == -1) {
        dinfo = drive_get(IF_PFLASH, 0, i);
        if (!dinfo) {
            fprintf(stderr, "Two flash images must be given with the "
                    "'pflash' parameter\n");
            exit(1);
@@ -101,7 +102,7 @@ static void mainstone_common_init(ram_addr_t ram_size,

        if (!pflash_cfi01_register(mainstone_flash_base[i],
                                qemu_ram_alloc(MAINSTONE_FLASH),
                                drives_table[index].bdrv, sector_len,
                                dinfo->bdrv, sector_len,
                                MAINSTONE_FLASH / sector_len, 4, 0, 0, 0, 0)) {
            fprintf(stderr, "qemu: Error registering flash memory.\n");
            exit(1);
+2 −5
Original line number Diff line number Diff line
@@ -235,11 +235,8 @@ void mips_jazz_init (ram_addr_t ram_size,
        exit(1);
    }
    for (n = 0; n < MAX_FD; n++) {
        int fd = drive_get_index(IF_FLOPPY, 0, n);
        if (fd != -1)
            fds[n] = drives_table[fd].bdrv;
        else
            fds[n] = NULL;
        DriveInfo *dinfo = drive_get(IF_FLOPPY, 0, n);
        fds[n] = dinfo ? dinfo->bdrv : NULL;
    }
    fdctrl_init(rc4030[1], 0, 1, 0x80003000, fds);

Loading