On Fri, May 28, 2010 at 7:34 PM, Paul Brook <p...@codesourcery.com> wrote: >> Use a qemu_irq to request CPU exit. > > Needing to request a CPU exit at all is just wrong. See previous discussions > about how any use of qemu_bh_schedule_idle is fundamentally broken.
I agree for the device case. Is the attached patch then OK? But what about other uses (with the patch applied): User emulator signal delivery: /src/qemu/darwin-user/signal.c:216: cpu_exit(global_env); /src/qemu/linux-user/signal.c:507: cpu_exit(thread_env); qemu_notify_event(): /src/qemu/cpus.c:286: cpu_exit(env); /src/qemu/cpus.c:289: cpu_exit(next_cpu); Is that broken too and should be removed? cpu_signal(): /src/qemu/cpus.c:531: cpu_exit(cpu_single_env); vm_stop(): /src/qemu/cpus.c:733: cpu_exit(cpu_single_env); KVM IO window exit: /src/qemu/kvm-all.c:859: cpu_exit(env); Some exclusive ARM operation: /src/qemu/linux-user/main.c:152: cpu_exit(other); ARM/m68k semihosting: /src/qemu/gdbstub.c:2296: cpu_exit(s->c_cpu);
From 12940e4bf57af4801ffc209095b6adcc0693320f Mon Sep 17 00:00:00 2001 From: Blue Swirl <blauwirbel@gmail.com> Date: Sat, 29 May 2010 07:59:40 +0000 Subject: [PATCH] dma: remove DMA_schedule and related cpu_request_exit irq It's wrong for devices to request cpu_exit. Remove DMA_schedule and cpu_request_exit irq, thus partially reverting 4556bd8b2514a55d48c15b1adb17537f49657744. Signed-off-by: Blue Swirl <blauwirbel@gmail.com> --- hw/dma.c | 19 ++++--------------- hw/fdc.c | 1 - hw/isa.h | 3 +-- hw/mips_jazz.c | 13 +------------ hw/mips_malta.c | 13 +------------ hw/pc.c | 13 +------------ hw/ppc_prep.c | 13 +------------ hw/sun4m.c | 1 - hw/sun4u.c | 1 - 9 files changed, 9 insertions(+), 68 deletions(-) diff --git a/hw/dma.c b/hw/dma.c index 5b21521..1015b41 100644 --- a/hw/dma.c +++ b/hw/dma.c @@ -57,7 +57,6 @@ static struct dma_cont { uint8_t flip_flop; int dshift; struct dma_regs regs[4]; - qemu_irq *cpu_request_exit; } dma_controllers[2]; enum { @@ -442,14 +441,6 @@ int DMA_write_memory (int nchan, void *buf, int pos, int len) return len; } -/* request the emulator to transfer a new DMA memory block ASAP */ -void DMA_schedule(int nchan) -{ - struct dma_cont *d = &dma_controllers[nchan > 3]; - - qemu_irq_pulse(*d->cpu_request_exit); -} - static void dma_reset(void *opaque) { struct dma_cont *d = opaque; @@ -465,14 +456,12 @@ static int dma_phony_handler (void *opaque, int nchan, int dma_pos, int dma_len) /* dshift = 0: 8 bit DMA, 1 = 16 bit DMA */ static void dma_init2(struct dma_cont *d, int base, int dshift, - int page_base, int pageh_base, - qemu_irq *cpu_request_exit) + int page_base, int pageh_base) { static const int page_port_list[] = { 0x1, 0x2, 0x3, 0x7 }; int i; d->dshift = dshift; - d->cpu_request_exit = cpu_request_exit; for (i = 0; i < 8; i++) { register_ioport_write (base + (i << dshift), 1, 1, write_chan, d); register_ioport_read (base + (i << dshift), 1, 1, read_chan, d); @@ -542,12 +531,12 @@ static const VMStateDescription vmstate_dma = { } }; -void DMA_init(int high_page_enable, qemu_irq *cpu_request_exit) +void DMA_init(int high_page_enable) { dma_init2(&dma_controllers[0], 0x00, 0, 0x80, - high_page_enable ? 0x480 : -1, cpu_request_exit); + high_page_enable ? 0x480 : -1); dma_init2(&dma_controllers[1], 0xc0, 1, 0x88, - high_page_enable ? 0x488 : -1, cpu_request_exit); + high_page_enable ? 0x488 : -1); vmstate_register (0, &vmstate_dma, &dma_controllers[0]); vmstate_register (1, &vmstate_dma, &dma_controllers[1]); diff --git a/hw/fdc.c b/hw/fdc.c index 6306496..d4505b4 100644 --- a/hw/fdc.c +++ b/hw/fdc.c @@ -1174,7 +1174,6 @@ static void fdctrl_start_transfer(FDCtrl *fdctrl, int direction) * recall us... */ DMA_hold_DREQ(fdctrl->dma_chann); - DMA_schedule(fdctrl->dma_chann); return; } else { FLOPPY_ERROR("dma_mode=%d direction=%d\n", dma_mode, direction); diff --git a/hw/isa.h b/hw/isa.h index aaf0272..9681de1 100644 --- a/hw/isa.h +++ b/hw/isa.h @@ -40,8 +40,7 @@ int DMA_read_memory (int nchan, void *buf, int pos, int size); int DMA_write_memory (int nchan, void *buf, int pos, int size); void DMA_hold_DREQ (int nchan); void DMA_release_DREQ (int nchan); -void DMA_schedule(int nchan); -void DMA_init(int high_page_enable, qemu_irq *cpu_request_exit); +void DMA_init(int high_page_enable); void DMA_register_channel (int nchan, DMA_transfer_handler transfer_handler, void *opaque); diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c index ead3a00..6e0ec8f 100644 --- a/hw/mips_jazz.c +++ b/hw/mips_jazz.c @@ -114,15 +114,6 @@ static void audio_init(qemu_irq *pic) #define MAGNUM_BIOS_SIZE_MAX 0x7e000 #define MAGNUM_BIOS_SIZE (BIOS_SIZE < MAGNUM_BIOS_SIZE_MAX ? BIOS_SIZE : MAGNUM_BIOS_SIZE_MAX) -static void cpu_request_exit(void *opaque, int irq, int level) -{ - CPUState *env = cpu_single_env; - - if (env && level) { - cpu_exit(env); - } -} - static void mips_jazz_init (ram_addr_t ram_size, const char *cpu_model, @@ -139,7 +130,6 @@ void mips_jazz_init (ram_addr_t ram_size, PITState *pit; DriveInfo *fds[MAX_FD]; qemu_irq esp_reset; - qemu_irq *cpu_exit_irq; ram_addr_t ram_offset; ram_addr_t bios_offset; @@ -199,8 +189,7 @@ void mips_jazz_init (ram_addr_t ram_size, i8259 = i8259_init(env->irq[4]); isa_bus_new(NULL); isa_bus_irqs(i8259); - cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1); - DMA_init(0, cpu_exit_irq); + DMA_init(0); pit = pit_init(0x40, i8259[0]); pcspk_init(pit); diff --git a/hw/mips_malta.c b/hw/mips_malta.c index a8f9d15..792709b 100644 --- a/hw/mips_malta.c +++ b/hw/mips_malta.c @@ -763,15 +763,6 @@ static void main_cpu_reset(void *opaque) } } -static void cpu_request_exit(void *opaque, int irq, int level) -{ - CPUState *env = cpu_single_env; - - if (env && level) { - cpu_exit(env); - } -} - static void mips_malta_init (ram_addr_t ram_size, const char *boot_device, @@ -790,7 +781,6 @@ void mips_malta_init (ram_addr_t ram_size, FDCtrl *floppy_controller; MaltaFPGAState *malta_fpga; qemu_irq *i8259; - qemu_irq *cpu_exit_irq; int piix4_devfn; uint8_t *eeprom_buf; i2c_bus *smbus; @@ -953,8 +943,7 @@ void mips_malta_init (ram_addr_t ram_size, qdev_init_nofail(eeprom); } pit = pit_init(0x40, isa_reserve_irq(0)); - cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1); - DMA_init(0, cpu_exit_irq); + DMA_init(0); /* Super I/O */ isa_dev = isa_create_simple("i8042"); diff --git a/hw/pc.c b/hw/pc.c index e7f31d3..d2fb9be 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -914,15 +914,6 @@ void pc_vga_init(PCIBus *pci_bus) } } -static void cpu_request_exit(void *opaque, int irq, int level) -{ - CPUState *env = cpu_single_env; - - if (env && level) { - cpu_exit(env); - } -} - void pc_basic_device_init(qemu_irq *isa_irq, FDCtrl **floppy_controller, ISADevice **rtc_state) @@ -932,7 +923,6 @@ void pc_basic_device_init(qemu_irq *isa_irq, PITState *pit; qemu_irq *a20_line; ISADevice *i8042; - qemu_irq *cpu_exit_irq; register_ioport_write(0x80, 1, 1, ioport80_write, NULL); @@ -965,8 +955,7 @@ void pc_basic_device_init(qemu_irq *isa_irq, i8042_setup_a20_line(i8042, a20_line); vmmouse_init(i8042); - cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1); - DMA_init(0, cpu_exit_irq); + DMA_init(0); for(i = 0; i < MAX_FD; i++) { fd[i] = drive_get(IF_FLOPPY, 0, i); diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c index 16c9950..e9c7370 100644 --- a/hw/ppc_prep.c +++ b/hw/ppc_prep.c @@ -547,15 +547,6 @@ static CPUReadMemoryFunc * const PPC_prep_io_read[] = { #define NVRAM_SIZE 0x2000 -static void cpu_request_exit(void *opaque, int irq, int level) -{ - CPUState *env = cpu_single_env; - - if (env && level) { - cpu_exit(env); - } -} - /* PowerPC PREP hardware initialisation */ static void ppc_prep_init (ram_addr_t ram_size, const char *boot_device, @@ -574,7 +565,6 @@ static void ppc_prep_init (ram_addr_t ram_size, uint32_t kernel_base, kernel_size, initrd_base, initrd_size; PCIBus *pci_bus; qemu_irq *i8259; - qemu_irq *cpu_exit_irq; int ppc_boot_device; DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; DriveInfo *fd[MAX_FD]; @@ -730,8 +720,7 @@ static void ppc_prep_init (ram_addr_t ram_size, } isa_create_simple("i8042"); - cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1); - DMA_init(1, cpu_exit_irq); + DMA_init(1); // SB16_init(); diff --git a/hw/sun4m.c b/hw/sun4m.c index 7ba0f76..8e040b8 100644 --- a/hw/sun4m.c +++ b/hw/sun4m.c @@ -151,7 +151,6 @@ int DMA_write_memory (int nchan, void *buf, int pos, int size) } void DMA_hold_DREQ (int nchan) {} void DMA_release_DREQ (int nchan) {} -void DMA_schedule(int nchan) {} void DMA_init(int high_page_enable, qemu_irq *cpu_request_exit) { diff --git a/hw/sun4u.c b/hw/sun4u.c index 40b5f1f..ee81f56 100644 --- a/hw/sun4u.c +++ b/hw/sun4u.c @@ -104,7 +104,6 @@ int DMA_write_memory (int nchan, void *buf, int pos, int size) } void DMA_hold_DREQ (int nchan) {} void DMA_release_DREQ (int nchan) {} -void DMA_schedule(int nchan) {} void DMA_init(int high_page_enable, qemu_irq *cpu_request_exit) { -- 1.5.6.5