Skip to contentSkip to conversation

Splitting vl.h

Qemu-devel Paul Brook 2 participants 3 messages Nov 11, 2007 Kbuild

lore
Share & tools
lore

Paul Brook

author
#0 lore raw

The attached patch starts splitting vl.h up a bit. I've pulled out the i2c, disk and irq code.

Because I picked some of the easier ones, they can also be built once, rather than for every target.

Obviously there's a lot left to do, but my grand plan is to get rid of vl.h altogether. A few files will probably end up effectively including everything, but hopefully most files should disentangle reasonably well. The more gets split out, the better things should get. e.g. scsi-disk.c doesn't need vl.h because I already split out the block API.

I want to check this seems a reasonable approach before I go too much further. Comments?

Paul

Index: Makefile
===================================================================
RCS file: /sources/qemu/qemu/Makefile,v
retrieving revision 1.130

Makefile +6 -0
diff -u -p -r1.130 Makefile
@@ -1,5 +1,7 @@
 # Makefile for QEMU.
 
+VPATH=$(SRC_PATH):$(SRC_PATH)/hw
+
 include config-host.mak
 
 .PHONY: all clean distclean dvi info install install-doc tar tarbin \
@@ -50,6 +52,10 @@ OBJS=$(BLOCK_OBJS)
 OBJS+=readline.o console.o 
 OBJS+=block.o
 
+OBJS+=irq.o
+OBJS+=i2c.o smbus.o smbus_eeprom.o max7310.o max111x.o wm8750.o
+OBJS+=scsi-disk.o cdrom.o
+
 ifdef CONFIG_WIN32
 OBJS+=tap-win32.o
 endif

Index: Makefile.target
===================================================================
RCS file: /sources/qemu/qemu/Makefile.target,v
retrieving revision 1.222

Makefile.target +5 -8
diff -u -p -r1.222 Makefile.target
@@ -399,7 +399,6 @@ endif
 VL_OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o
 # XXX: suppress QEMU_TOOL tests
 VL_OBJS+=block-raw.o
-VL_OBJS+=irq.o
 
 ifdef CONFIG_ALSA
 LIBS += -lasound
@@ -421,10 +420,8 @@ CPPFLAGS += $(CONFIG_VNC_TLS_CFLAGS)
 LIBS += $(CONFIG_VNC_TLS_LIBS)
 endif
 
-VL_OBJS += i2c.o smbus.o
-
 # SCSI layer
-VL_OBJS+= scsi-disk.o cdrom.o lsi53c895a.o
+VL_OBJS+= lsi53c895a.o
 
 # USB layer
 VL_OBJS+= usb.o usb-hub.o usb-linux.o usb-hid.o usb-ohci.o usb-msd.o
@@ -444,7 +441,7 @@ ifeq ($(TARGET_BASE_ARCH), i386)
 VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o
 VL_OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
 VL_OBJS+= cirrus_vga.o apic.o parallel.o acpi.o piix_pci.o
-VL_OBJS+= usb-uhci.o smbus_eeprom.o vmmouse.o vmport.o vmware_vga.o
+VL_OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o
 CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
 endif
 ifeq ($(TARGET_BASE_ARCH), ppc)
@@ -468,7 +465,7 @@ VL_OBJS+= mips_r4k.o mips_malta.o mips_p
 VL_OBJS+= mips_timer.o mips_int.o dma.o vga.o serial.o i8254.o i8259.o
 VL_OBJS+= jazz_led.o
 VL_OBJS+= ide.o gt64xxx.o pckbd.o ps2.o fdc.o mc146818rtc.o usb-uhci.o acpi.o ds1225y.o
-VL_OBJS+= piix_pci.o smbus_eeprom.o parallel.o cirrus_vga.o $(SOUND_HW)
+VL_OBJS+= piix_pci.o parallel.o cirrus_vga.o $(SOUND_HW)
 VL_OBJS+= mipsnet.o
 CPPFLAGS += -DHAS_AUDIO
 endif
@@ -498,8 +495,8 @@ VL_OBJS+= armv7m.o armv7m_nvic.o stellar
 VL_OBJS+= ssd0323.o pl061.o
 VL_OBJS+= arm-semi.o
 VL_OBJS+= pxa2xx.o pxa2xx_pic.o pxa2xx_gpio.o pxa2xx_timer.o pxa2xx_dma.o
-VL_OBJS+= pxa2xx_lcd.o pxa2xx_mmci.o pxa2xx_pcmcia.o max111x.o max7310.o
-VL_OBJS+= spitz.o ads7846.o ide.o serial.o nand.o ecc.o wm8750.o
+VL_OBJS+= pxa2xx_lcd.o pxa2xx_mmci.o pxa2xx_pcmcia.o
+VL_OBJS+= spitz.o ads7846.o ide.o serial.o nand.o ecc.o
 VL_OBJS+= omap.o omap_lcdc.o omap1_clk.o omap_mmc.o omap_i2c.o
 VL_OBJS+= palm.o tsc210x.o
 CPPFLAGS += -DHAS_AUDIO

Index: exec.c
===================================================================
RCS file: /sources/qemu/qemu/exec.c,v
retrieving revision 1.113

exec.c +20 -5
diff -u -p -r1.113 exec.c
@@ -1278,11 +1278,9 @@ int cpu_str_to_log_mask(const char *str)
     return mask;
 }
 
-void cpu_abort(CPUState *env, const char *fmt, ...)
+static void __attribute__((noreturn))
+cpu_abortv(CPUState *env, const char *fmt, va_list ap)
 {
-    va_list ap;
-
-    va_start(ap, fmt);
     fprintf(stderr, "qemu: fatal: ");
     vfprintf(stderr, fmt, ap);
     fprintf(stderr, "\n");
@@ -1308,10 +1306,27 @@ void cpu_abort(CPUState *env, const char
         fflush(logfile);
         fclose(logfile);
     }
-    va_end(ap);
     abort();
 }
 
+void cpu_abort(CPUState *env, const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    cpu_abortv(env, fmt, ap);
+    va_end(ap);
+}
+
+void qemu_abort(CPUState *env, const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    cpu_abortv(env, fmt, ap);
+    va_end(ap);
+}
+
 CPUState *cpu_copy(CPUState *env)
 {
 #if 0

Index: qemu-common.h
===================================================================
RCS file: /sources/qemu/qemu/qemu-common.h,v
retrieving revision 1.1

qemu-common.h +6 -0
diff -u -p -r1.1 qemu-common.h
@@ -80,4 +80,10 @@ int strstart(const char *str, const char
 int stristart(const char *str, const char *val, const char **ptr);
 time_t mktimegm(struct tm *tm);
 
+/* Error handling.  */
+
+void qemu_abort(const char *fmt, ...)
+    __attribute__ ((__format__ (__printf__, 1, 2)))
+    __attribute__ ((__noreturn__));
+
 #endif

Index: vl.h
===================================================================
RCS file: /sources/qemu/qemu/vl.h,v
retrieving revision 1.294

vl.h +6 -120

166 lines not on this page · raw message

Index: hw/board.h
===================================================================
RCS file: hw/board.h

board.h new file +12 -0
diff -N hw/board.h
@@ -0,0 +1,12 @@
+/* Declarations for use by board files for creating devices.  */
+
+#ifndef HW_BOARD_H
+#define HW_BOARD_H
+
+#include "max7310.h"
+
+#include "max111x.h"
+
+#include "wm8750.h"
+
+#endif

Index: hw/cdrom.c
===================================================================
RCS file: /sources/qemu/qemu/hw/cdrom.c,v
retrieving revision 1.3

cdrom.c +2 -1
diff -u -p -r1.3 cdrom.c
@@ -25,7 +25,8 @@
 /* ??? Most of the ATAPI emulation is still in ide.c.  It should be moved
    here.  */
 
-#include <vl.h>
+#include "qemu-common.h"
+#include "cdrom.h"
 
 static void lba_to_msf(uint8_t *buf, int lba)
 {

Index: hw/cdrom.h
===================================================================
RCS file: hw/cdrom.h

cdrom.h new file +4 -0
diff -N hw/cdrom.h
@@ -0,0 +1,4 @@
+/* cdrom.c */
+int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
+int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
+

Index: hw/esp.c
===================================================================
RCS file: /sources/qemu/qemu/hw/esp.c,v
retrieving revision 1.27

esp.c +1 -0
diff -u -p -r1.27 esp.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "vl.h"
+#include "scsi-disk.h"
 
 /* debug ESP card */
 //#define DEBUG_ESP

Index: hw/hw.h
===================================================================
RCS file: hw/hw.h

hw.h new file +92 -0

92 lines not on this page · raw message

Index: hw/i2c.c
===================================================================
RCS file: /sources/qemu/qemu/hw/i2c.c,v
retrieving revision 1.4

i2c.c +3 -2
diff -u -p -r1.4 i2c.c
@@ -7,7 +7,8 @@
  * This code is licenced under the LGPL.
  */
 
-#include "vl.h"
+#include "hw.h"
+#include "i2c.h"
 
 struct i2c_bus
 {
@@ -30,7 +31,7 @@ i2c_slave *i2c_slave_init(i2c_bus *bus, 
     i2c_slave *dev;
 
     if (size < sizeof(i2c_slave))
-        cpu_abort(cpu_single_env, "I2C struct too small");
+        qemu_abort("I2C struct too small");
 
     dev = (i2c_slave *)qemu_mallocz(size);
     dev->address = address;

Index: hw/i2c.h
===================================================================
RCS file: /sources/qemu/qemu/hw/i2c.h,v
retrieving revision 1.4

i2c.h +0 -14
diff -u -p -r1.4 i2c.h
@@ -50,18 +50,4 @@ void i2c_bus_load(QEMUFile *f, i2c_bus *
 void i2c_slave_save(QEMUFile *f, i2c_slave *dev);
 void i2c_slave_load(QEMUFile *f, i2c_slave *dev);
 
-/* max7310.c */
-i2c_slave *max7310_init(i2c_bus *bus);
-void max7310_reset(i2c_slave *i2c);
-qemu_irq *max7310_gpio_in_get(i2c_slave *i2c);
-void max7310_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler);
-
-/* wm8750.c */
-i2c_slave *wm8750_init(i2c_bus *bus, AudioState *audio);
-void wm8750_reset(i2c_slave *i2c);
-void wm8750_data_req_set(i2c_slave *i2c,
-                void (*data_req)(void *, int, int), void *opaque);
-void wm8750_dac_dat(void *opaque, uint32_t sample);
-uint32_t wm8750_adc_dat(void *opaque);
-
 #endif

Index: hw/ide.c
===================================================================
RCS file: /sources/qemu/qemu/hw/ide.c,v
retrieving revision 1.70

ide.c +1 -0
diff -u -p -r1.70 ide.c
@@ -23,6 +23,7 @@
  * THE SOFTWARE.
  */
 #include "vl.h"
+#include "cdrom.h"
 
 /* debug IDE devices */
 //#define DEBUG_IDE

Index: hw/irq.c
===================================================================
RCS file: /sources/qemu/qemu/hw/irq.c,v
retrieving revision 1.3

irq.c +2 -1
diff -u -p -r1.3 irq.c
@@ -21,7 +21,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "vl.h"
+#include "qemu-common.h"
+#include "irq.h"
 
 struct IRQState {
     qemu_irq_handler handler;

Index: hw/lsi53c895a.c
===================================================================
RCS file: /sources/qemu/qemu/hw/lsi53c895a.c,v
retrieving revision 1.10

lsi53c895a.c +1 -0
diff -u -p -r1.10 lsi53c895a.c
@@ -11,6 +11,7 @@
    big-endian targets.  */
 
 #include "vl.h"
+#include "scsi-disk.h"
 
 //#define DEBUG_LSI
 //#define DEBUG_LSI_REG

Index: hw/max111x.c
===================================================================
RCS file: /sources/qemu/qemu/hw/max111x.c,v
retrieving revision 1.2

max111x.c +4 -1
diff -u -p -r1.2 max111x.c
@@ -7,7 +7,10 @@
  * This code is licensed under the GNU GPLv2.
  */
 
-#include <vl.h>
+#include "hw.h"
+#include "i2c.h"
+#include "irq.h"
+#include "max111x.h"
 
 struct max111x_s {
     qemu_irq interrupt;

Index: hw/max111x.h
===================================================================
RCS file: hw/max111x.h

max111x.h new file +8 -0
diff -N hw/max111x.h
@@ -0,0 +1,8 @@
+/* max111x.c */
+struct max111x_s;
+uint32_t max111x_read(void *opaque);
+void max111x_write(void *opaque, uint32_t value);
+struct max111x_s *max1110_init(qemu_irq cb);
+struct max111x_s *max1111_init(qemu_irq cb);
+void max111x_set_input(struct max111x_s *s, int line, uint8_t value);
+

Index: hw/max7310.c
===================================================================
RCS file: /sources/qemu/qemu/hw/max7310.c,v
retrieving revision 1.2

max7310.c +6 -3
diff -u -p -r1.2 max7310.c
@@ -7,7 +7,10 @@
  * This file is licensed under GNU GPL.
  */
 
-#include "vl.h"
+#include "hw.h"
+#include "i2c.h"
+#include "irq.h"
+#include "max7310.h"
 
 struct max7310_s {
     i2c_slave i2c;
@@ -182,7 +185,7 @@ static void max7310_gpio_set(void *opaqu
 {
     struct max7310_s *s = (struct max7310_s *) opaque;
     if (line >= sizeof(s->handler) / sizeof(*s->handler) || line  < 0)
-        cpu_abort(cpu_single_env, "bad GPIO line");
+        qemu_abort("bad GPIO line");
 
     if (level)
         s->level |= s->direction & (1 << line);
@@ -220,7 +223,7 @@ void max7310_gpio_out_set(i2c_slave *i2c
 {
     struct max7310_s *s = (struct max7310_s *) i2c;
     if (line >= sizeof(s->handler) / sizeof(*s->handler) || line  < 0)
-        cpu_abort(cpu_single_env, "bad GPIO line");
+        qemu_abort("bad GPIO line");
 
     s->handler[line] = handler;
 }

Index: hw/max7310.h
===================================================================
RCS file: hw/max7310.h

max7310.h new file +5 -0
diff -N hw/max7310.h
@@ -0,0 +1,5 @@
+/* max7310.c */
+i2c_slave *max7310_init(i2c_bus *bus);
+void max7310_reset(i2c_slave *i2c);
+qemu_irq *max7310_gpio_in_get(i2c_slave *i2c);
+void max7310_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler);

Index: hw/scsi-disk.c
===================================================================
RCS file: /sources/qemu/qemu/hw/scsi-disk.c,v
retrieving revision 1.15

scsi-disk.c +4 -1
diff -u -p -r1.15 scsi-disk.c
@@ -25,7 +25,10 @@ do { printf("scsi-disk: " fmt , ##args);
 #define BADF(fmt, args...) \
 do { fprintf(stderr, "scsi-disk: " fmt , ##args); } while (0)
 
-#include "vl.h"
+#include "qemu-common.h"
+#include "block.h"
+#include "scsi-disk.h"
+#include "cdrom.h"
 
 #define SENSE_NO_SENSE        0
 #define SENSE_NOT_READY       2

Index: hw/scsi-disk.h
===================================================================
RCS file: hw/scsi-disk.h

scsi-disk.h new file +28 -0
diff -N hw/scsi-disk.h
@@ -0,0 +1,28 @@
+#ifndef SCSI_DISK_H
+#define SCSI_DISK_H
+
+enum scsi_reason {
+    SCSI_REASON_DONE, /* Command complete.  */
+    SCSI_REASON_DATA  /* Transfer complete, more data required.  */
+};
+
+typedef struct SCSIDevice SCSIDevice;
+typedef void (*scsi_completionfn)(void *opaque, int reason, uint32_t tag,
+                                  uint32_t arg);
+
+SCSIDevice *scsi_disk_init(BlockDriverState *bdrv,
+                           int tcq,
+                           scsi_completionfn completion,
+                           void *opaque);
+void scsi_disk_destroy(SCSIDevice *s);
+
+int32_t scsi_send_command(SCSIDevice *s, uint32_t tag, uint8_t *buf, int lun);
+/* SCSI data transfers are asynchrnonous.  However, unlike the block IO
+   layer the completion routine may be called directly by
+   scsi_{read,write}_data.  */
+void scsi_read_data(SCSIDevice *s, uint32_t tag);
+int scsi_write_data(SCSIDevice *s, uint32_t tag);
+void scsi_cancel_io(SCSIDevice *s, uint32_t tag);
+uint8_t *scsi_get_buf(SCSIDevice *s, uint32_t tag);
+
+#endif

Index: hw/smbus.c
===================================================================
RCS file: /sources/qemu/qemu/hw/smbus.c,v
retrieving revision 1.3

smbus.c +4 -2
diff -u -p -r1.3 smbus.c
@@ -9,7 +9,9 @@
 
 /* TODO: Implement PEC.  */
 
-#include "vl.h"
+#include "hw.h"
+#include "i2c.h"
+#include "smbus.h"
 
 //#define DEBUG_SMBUS 1
 
@@ -194,7 +196,7 @@ SMBusDevice *smbus_device_init(i2c_bus *
     SMBusDevice *dev;
 
     if (size < sizeof(SMBusDevice))
-        cpu_abort(cpu_single_env, "SMBus struct too small");
+        qemu_abort("SMBus struct too small");
 
     dev = (SMBusDevice *)i2c_slave_init(bus, address, size);
     dev->i2c.event = smbus_i2c_event;

Index: hw/smbus_eeprom.c
===================================================================
RCS file: /sources/qemu/qemu/hw/smbus_eeprom.c,v
retrieving revision 1.4

smbus_eeprom.c +3 -1
diff -u -p -r1.4 smbus_eeprom.c
@@ -22,7 +22,9 @@
  * THE SOFTWARE.
  */
 
-#include "vl.h"
+#include "hw.h"
+#include "i2c.h"
+#include "smbus.h"
 
 //#define DEBUG
 

Index: hw/usb-msd.c
===================================================================
RCS file: /sources/qemu/qemu/hw/usb-msd.c,v
retrieving revision 1.11

usb-msd.c +1 -0
diff -u -p -r1.11 usb-msd.c
@@ -8,6 +8,7 @@
  */
 
 #include "vl.h"
+#include "scsi-disk.h"
 
 //#define DEBUG_MSD
 

Index: hw/wm8750.c
===================================================================
RCS file: /sources/qemu/qemu/hw/wm8750.c,v
retrieving revision 1.2

wm8750.c +4 -1
diff -u -p -r1.2 wm8750.c
@@ -7,7 +7,10 @@
  * This file is licensed under GNU GPL.
  */
 
-#include "vl.h"
+#include "hw.h"
+#include "i2c.h"
+#include "audio/audio.h"
+#include "wm8750.h"
 
 #define IN_PORT_N	3
 #define OUT_PORT_N	3

Index: hw/wm8750.h
===================================================================
RCS file: hw/wm8750.h

wm8750.h new file +7 -0
diff -N hw/wm8750.h
@@ -0,0 +1,7 @@
+/* wm8750.c */
+i2c_slave *wm8750_init(i2c_bus *bus, AudioState *audio);
+void wm8750_reset(i2c_slave *i2c);
+void wm8750_data_req_set(i2c_slave *i2c,
+                void (*data_req)(void *, int, int), void *opaque);
+void wm8750_dac_dat(void *opaque, uint32_t sample);
+uint32_t wm8750_adc_dat(void *opaque);
#1 lore raw
Quoted 6 lines · Paul Brook

The attached patch starts splitting vl.h up a bit. I've pulled out the i2c, disk and irq code.

Because I picked some of the easier ones, they can also be built once, rather than for every target.

Quoted 8 lines

Obviously there's a lot left to do, but my grand plan is to get rid of vl.h altogether. A few files will probably end up effectively including everything, but hopefully most files should disentangle reasonably well. The more gets split out, the better things should get. e.g. scsi-disk.c doesn't need vl.h because I already split out the block API.

I want to check this seems a reasonable approach before I go too much further. Comments?

I understand Fabrice's concern about small files, but I think this is the right direction.

In ide.c and esp.c there are TARGET_ and target_ dependencies, how do you plan to handle those?

author
#2 lore raw
Quoted 5 lines · Blue Swirl
Quoted 1 line · Paul Brook

The attached patch starts splitting vl.h up a bit.

I understand Fabrice's concern about small files, but I think this is the right direction.

Ok, I'll try to keep them to a minimum. e.g. I can combine cdrom.h and scsi-disk.h

Quoted 2 lines

In ide.c and esp.c there are TARGET_ and target_ dependencies, how do you plan to handle those?

Currently I don't, they will still be build per-target. Longer term this is something a generic bus architecture should handle.

Paul