Skip to contentSkip to conversation

system: Absorb globals-target.c within common globals.c

PATCH In review Philippe Mathieu-Daudé 2 participants 14 messages Feb 16 – Feb 22 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v2 cover system: Absorb globals-target.c within common globals.c

Missing review: #7

Since v1:
- Inlined PPC code in patch #7 (Mark)

Slightly rework how the graphic dimension variables for the M68k / PPC / SPARC targets are initialized, removing the need for the target-specific globals-target.c file.

Previous discussion:
https://lore.kernel.org/qemu-devel/[email protected]/

Philippe Mathieu-Daudé (8):
hw/display/macfb: Constify macfb_sense_table[] array hw/display/macfb: Constify macfb_mode_table[] array hw/m68k/q800: Use MacFbMode fields in q800_machine_init() hw/m68k/q800: Set MACFB_DISPLAY_APPLE_21_COLOR within MacFrameBuffer hw/m68k: Set graphic display dimensions generically hw/sparc: Set graphic display dimensions generically hw/ppc: Set graphic display dimensions generically system/globals: Build as common code

 include/hw/display/macfb.h |  2 +-
 hw/display/macfb.c         | 18 +++++++++++-------
 hw/m68k/q800.c             | 17 ++++++-----------
 hw/ppc/mac_newworld.c      |  9 +++++++++
 hw/ppc/mac_oldworld.c      |  9 +++++++++
 hw/ppc/prep.c              |  9 +++++++++
 hw/ppc/spapr.c             |  9 +++++++++
 hw/sparc/sun4m.c           |  9 +++++++++
 hw/sparc64/sun4u.c         | 10 ++++++++++
 system/globals-target.c    | 24 ------------------------
 system/globals.c           |  3 +++
 system/meson.build         |  4 ----
 12 files changed, 76 insertions(+), 47 deletions(-)
 delete mode 100644 system/globals-target.c
Signature · 1 line
2.52.0
#1 lore raw

PATCH v2 1/8 hw/display/macfb: Constify macfb_sense_table[] array

macfb_sense_table[] is only read, never updated, so can be const.

Update the single call site, macfb_sense_read().

---
 hw/display/macfb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/display/macfb.c +2 -2
index 388f8de5070..57ad8ad5587 100644
@@ -82,7 +82,7 @@ typedef struct MacFbSense {
     uint8_t ext_sense;
 } MacFbSense;
 
-static MacFbSense macfb_sense_table[] = {
+static const MacFbSense macfb_sense_table[] = {
     { MACFB_DISPLAY_APPLE_21_COLOR, 0x0, 0 },
     { MACFB_DISPLAY_APPLE_PORTRAIT, 0x1, 0 },
     { MACFB_DISPLAY_APPLE_12_RGB, 0x2, 0 },
@@ -342,7 +342,7 @@ static void macfb_invalidate_display(void *opaque)
 
 static uint32_t macfb_sense_read(MacfbState *s)
 {
-    MacFbSense *macfb_sense;
+    const MacFbSense *macfb_sense;
     uint8_t sense;
 
     assert(s->type < ARRAY_SIZE(macfb_sense_table));
Signature · 1 line
2.52.0
Reviewed-by on v2 1/8
#2 lore raw

Re: [PATCH v2 1/8] hw/display/macfb: Constify macfb_sense_table[] array

Quoted 10 lines · Philippe Mathieu-Daudé

macfb_sense_table[] is only read, never updated, so can be const.

Update the single call site, macfb_sense_read().

---
  hw/display/macfb.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

r~

#3 lore raw

PATCH v2 2/8 hw/display/macfb: Constify macfb_mode_table[] array

In reply to Philippe Mathieu-Daudé

macfb_mode_table[] is only read, never updated, so can be const.

Update the call sites accordingly.
Make the MacfbState::mode pointer to const.

---
 include/hw/display/macfb.h |  2 +-
 hw/display/macfb.c         | 10 +++++-----
 hw/m68k/q800.c             |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
include/hw/display/macfb.h +1 -1
index 495dead44b5..cb7aac7a4dd 100644
@@ -66,7 +66,7 @@ typedef struct MacfbState {
     uint8_t type;
 
     uint32_t regs[MACFB_NUM_REGS];
-    MacFbMode *mode;
+    const MacFbMode *mode;
 
     QEMUTimer *vbl_timer;
     qemu_irq irq;
hw/display/macfb.c +5 -5
index 57ad8ad5587..8ef174dc6df 100644
@@ -100,7 +100,7 @@ static const MacFbSense macfb_sense_table[] = {
     { MACFB_DISPLAY_SVGA, 0x7, 0x5 },
 };
 
-static MacFbMode macfb_mode_table[] = {
+static const MacFbMode macfb_mode_table[] = {
     { MACFB_DISPLAY_VGA, 1, 0x100, 0x71e, 640, 480, 0x400, 0x1000 },
     { MACFB_DISPLAY_VGA, 2, 0x100, 0x70e, 640, 480, 0x400, 0x1000 },
     { MACFB_DISPLAY_VGA, 4, 0x100, 0x706, 640, 480, 0x400, 0x1000 },
@@ -397,7 +397,7 @@ static void macfb_update_mode(MacfbState *s)
 
 static void macfb_mode_write(MacfbState *s)
 {
-    MacFbMode *macfb_mode;
+    const MacFbMode *macfb_mode;
     int i;
 
     for (i = 0; i < ARRAY_SIZE(macfb_mode_table); i++) {
@@ -418,11 +418,11 @@ static void macfb_mode_write(MacfbState *s)
     }
 }
 
-static MacFbMode *macfb_find_mode(MacfbDisplayType display_type,
+static const MacFbMode *macfb_find_mode(MacfbDisplayType display_type,
                                   uint16_t width, uint16_t height,
                                   uint8_t depth)
 {
-    MacFbMode *macfb_mode;
+    const MacFbMode *macfb_mode;
     int i;
 
     for (i = 0; i < ARRAY_SIZE(macfb_mode_table); i++) {
@@ -440,7 +440,7 @@ static MacFbMode *macfb_find_mode(MacfbDisplayType display_type,
 static gchar *macfb_mode_list(void)
 {
     GString *list = g_string_new("");
-    MacFbMode *macfb_mode;
+    const MacFbMode *macfb_mode;
     int i;
 
     for (i = 0; i < ARRAY_SIZE(macfb_mode_table); i++) {
hw/m68k/q800.c +1 -1
index 25ddddb5d9f..4767eb4298f 100644
@@ -255,7 +255,7 @@ static void q800_machine_init(MachineState *machine)
     int32_t initrd_size;
     uint8_t *prom;
     int i, checksum;
-    MacFbMode *macfb_mode;
+    const MacFbMode *macfb_mode;
     ram_addr_t ram_size = machine->ram_size;
     const char *kernel_filename = machine->kernel_filename;
     const char *initrd_filename = machine->initrd_filename;
Signature · 1 line
2.52.0
Reviewed-by on v2 2/8
#4 lore raw

Re: [PATCH v2 2/8] hw/display/macfb: Constify macfb_mode_table[] array

Quoted 5 lines · Philippe Mathieu-Daudé

macfb_mode_table[] is only read, never updated, so can be const.

Update the call sites accordingly.
Make theMacfbState::mode pointer to const.

Quoted 8 lines
---
  include/hw/display/macfb.h |  2 +-
  hw/display/macfb.c         | 10 +++++-----
  hw/m68k/q800.c             |  2 +-
  3 files changed, 7 insertions(+), 7 deletions(-)

r~

#5 lore raw

PATCH v2 3/8 hw/m68k/q800: Use MacFbMode fields in q800_machine_init()

In reply to Philippe Mathieu-Daudé

Once the Mac Frame Buffer device is realized on the NuBus, its MacFbMode might be different of the global graphic_depth and graphic_width globals. Prefer the device MacFbMode fields to initialize the BootInfo structure.

---
 hw/m68k/q800.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/m68k/q800.c +2 -2
index 4767eb4298f..b55c03a90bf 100644
@@ -605,9 +605,9 @@ static void q800_machine_init(MachineState *machine)
         BOOTINFO2(param_ptr, BI_MEMCHUNK, 0, ram_size);
         BOOTINFO1(param_ptr, BI_MAC_VADDR,
                   VIDEO_BASE + macfb_mode->offset);
-        BOOTINFO1(param_ptr, BI_MAC_VDEPTH, graphic_depth);
+        BOOTINFO1(param_ptr, BI_MAC_VDEPTH, macfb_mode->depth);
         BOOTINFO1(param_ptr, BI_MAC_VDIM,
-                  (graphic_height << 16) | graphic_width);
+                  (graphic_height << 16) | macfb_mode->width);
         BOOTINFO1(param_ptr, BI_MAC_VROW, macfb_mode->stride);
         BOOTINFO1(param_ptr, BI_MAC_SCCBASE, SCC_BASE);
 
Signature · 1 line
2.52.0
#6 lore raw

PATCH v2 4/8 hw/m68k/q800: Set MACFB_DISPLAY_APPLE_21_COLOR within MacFrameBuffer

In reply to Philippe Mathieu-Daudé

The MACFB_DISPLAY_APPLE_21_COLOR mode is not specific to the Q800 machine. Check and set it once in the MacFB DeviceRealize handler.

No need to explicitly set the MACFB_DISPLAY_VGA mode since this is the default value.

---
 hw/display/macfb.c | 4 ++++
 hw/m68k/q800.c     | 5 -----
 2 files changed, 4 insertions(+), 5 deletions(-)
hw/display/macfb.c +4 -0
index 8ef174dc6df..b8115c2be13 100644
@@ -645,6 +645,10 @@ static bool macfb_common_realize(DeviceState *dev, MacfbState *s, Error **errp)
 {
     DisplaySurface *surface;
 
+    if (s->width == 1152 && s->height == 870) {
+        s->type = MACFB_DISPLAY_APPLE_21_COLOR;
+    }
+
     s->mode = macfb_find_mode(s->type, s->width, s->height, s->depth);
     if (!s->mode) {
         gchar *list;
hw/m68k/q800.c +0 -5
index b55c03a90bf..ba32da2fa45 100644
@@ -563,11 +563,6 @@ static void q800_machine_init(MachineState *machine)
     qdev_prop_set_uint32(dev, "width", graphic_width);
     qdev_prop_set_uint32(dev, "height", graphic_height);
     qdev_prop_set_uint8(dev, "depth", graphic_depth);
-    if (graphic_width == 1152 && graphic_height == 870) {
-        qdev_prop_set_uint8(dev, "display", MACFB_DISPLAY_APPLE_21_COLOR);
-    } else {
-        qdev_prop_set_uint8(dev, "display", MACFB_DISPLAY_VGA);
-    }
     qdev_realize(dev, BUS(nubus), &error_fatal);
 
     macfb_mode = (NUBUS_MACFB(dev)->macfb).mode;
Signature · 1 line
2.52.0
#7 lore raw

PATCH v2 5/8 hw/m68k: Set graphic display dimensions generically

In reply to Philippe Mathieu-Daudé

If a dimension is not set, have the machine init code (q800_machine_init) set the default values.

---
 hw/m68k/q800.c          | 6 +++---
 system/globals-target.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
hw/m68k/q800.c +3 -3
index ba32da2fa45..ded531394e6 100644
@@ -560,9 +560,9 @@ static void q800_machine_init(MachineState *machine)
                             TYPE_NUBUS_MACFB);
     dev = DEVICE(&m->macfb);
     qdev_prop_set_uint32(dev, "slot", 9);
-    qdev_prop_set_uint32(dev, "width", graphic_width);
-    qdev_prop_set_uint32(dev, "height", graphic_height);
-    qdev_prop_set_uint8(dev, "depth", graphic_depth);
+    qdev_prop_set_uint32(dev, "width", graphic_width ?: 800);
+    qdev_prop_set_uint32(dev, "height", graphic_height ?: 600);
+    qdev_prop_set_uint8(dev, "depth", graphic_depth ?: 8);
     qdev_realize(dev, BUS(nubus), &error_fatal);
 
     macfb_mode = (NUBUS_MACFB(dev)->macfb).mode;
system/globals-target.c +3 -3
index 989720591e7..e3f7d846ac0 100644
@@ -14,9 +14,9 @@ int graphic_width = 1024;
 int graphic_height = 768;
 int graphic_depth = 8;
 #elif defined(TARGET_M68K)
-int graphic_width = 800;
-int graphic_height = 600;
-int graphic_depth = 8;
+int graphic_width;
+int graphic_height;
+int graphic_depth;
 #else
 int graphic_width = 800;
 int graphic_height = 600;
Signature · 1 line
2.52.0
#8 lore raw

PATCH v2 6/8 hw/sparc: Set graphic display dimensions generically

In reply to Philippe Mathieu-Daudé

If a dimension is not set, have the machine init code set the default values.

---
 hw/sparc/sun4m.c        |  9 +++++++++
 hw/sparc64/sun4u.c      | 10 ++++++++++
 system/globals-target.c |  6 +-----
 3 files changed, 20 insertions(+), 5 deletions(-)
hw/sparc/sun4m.c +9 -0
index 0c0d658d301..a17bdb36927 100644
@@ -892,6 +892,15 @@ static void sun4m_hw_init(MachineState *machine)
                      hwdef->esp_base, slavio_irq[18],
                      hwdef->le_base, slavio_irq[16], &hostid);
 
+    if (!graphic_width) {
+        graphic_width = 1024;
+    }
+    if (!graphic_height) {
+        graphic_height = 768;
+    }
+    if (!graphic_depth) {
+        graphic_depth = 8;
+    }
     if (graphic_depth != 8 && graphic_depth != 24) {
         error_report("Unsupported depth: %d", graphic_depth);
         exit (1);
hw/sparc64/sun4u.c +10 -0
index 5d7787fc1a5..b8bda1eb816 100644
@@ -666,6 +666,16 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
                                 sysbus_mmio_get_region(s, 0));
     nvram = NVRAM(dev);
  
+    if (!graphic_width) {
+        graphic_width = 1024;
+    }
+    if (!graphic_height) {
+        graphic_height = 768;
+    }
+    if (!graphic_depth) {
+        graphic_depth = 8;
+    }
+
     initrd_size = 0;
     initrd_addr = 0;
     kernel_size = sun4u_load_kernel(machine->kernel_filename,
system/globals-target.c +1 -5
index e3f7d846ac0..17a27a06218 100644
@@ -9,11 +9,7 @@
 #include "qemu/osdep.h"
 #include "system/system.h"
 
-#ifdef TARGET_SPARC
-int graphic_width = 1024;
-int graphic_height = 768;
-int graphic_depth = 8;
-#elif defined(TARGET_M68K)
+#if defined(TARGET_SPARC) || defined(TARGET_M68K)
 int graphic_width;
 int graphic_height;
 int graphic_depth;
Signature · 1 line
2.52.0
#9 lore raw

PATCH v2 7/8 hw/ppc: Set graphic display dimensions generically

In reply to Philippe Mathieu-Daudé

If a dimension is not set, have the machine init code set the default values.

---
 hw/ppc/mac_newworld.c   | 9 +++++++++
 hw/ppc/mac_oldworld.c   | 9 +++++++++
 hw/ppc/prep.c           | 9 +++++++++
 hw/ppc/spapr.c          | 9 +++++++++
 system/globals-target.c | 6 ------
 5 files changed, 36 insertions(+), 6 deletions(-)
hw/ppc/mac_newworld.c +9 -0
index 7275563a155..3680d96ed39 100644
@@ -432,6 +432,15 @@ static void ppc_core99_init(MachineState *machine)
 
     pci_vga_init(pci_bus);
 
+    if (!graphic_width) {
+        graphic_width = 800;
+    }
+    if (!graphic_height) {
+        graphic_height = 600;
+    }
+    if (!graphic_depth) {
+        graphic_depth = 32;
+    }
     if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) {
         graphic_depth = 15;
     }
hw/ppc/mac_oldworld.c +9 -0
index e679d338985..24d9f2e3d5c 100644
@@ -288,6 +288,15 @@ static void ppc_heathrow_init(MachineState *machine)
         pci_create_simple(pci_bus, -1, "pci-ohci");
     }
 
+    if (!graphic_width) {
+        graphic_width = 800;
+    }
+    if (!graphic_height) {
+        graphic_height = 600;
+    }
+    if (!graphic_depth) {
+        graphic_depth = 32;
+    }
     if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) {
         graphic_depth = 15;
     }
hw/ppc/prep.c +9 -0
index c4efd1d3908..e973b340992 100644
@@ -412,6 +412,15 @@ static void ibm_40p_init(MachineState *machine)
     fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)machine->ram_size);
     fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_PREP);
 
+    if (!graphic_width) {
+        graphic_width = 800;
+    }
+    if (!graphic_height) {
+        graphic_height = 600;
+    }
+    if (!graphic_depth) {
+        graphic_depth = 32;
+    }
     fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width);
     fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height);
     fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth);
hw/ppc/spapr.c +9 -0
index 274f38785f2..0ab39dfea6b 100644
@@ -1177,6 +1177,15 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
         if (machine->boot_config.has_menu && machine->boot_config.menu) {
             _FDT((fdt_setprop_cell(fdt, chosen, "qemu,boot-menu", true)));
         }
+        if (!graphic_width) {
+            graphic_width = 800;
+        }
+        if (!graphic_height) {
+            graphic_height = 600;
+        }
+        if (!graphic_depth) {
+            graphic_depth = 32;
+        }
         _FDT(fdt_setprop_cell(fdt, chosen, "qemu,graphic-width", graphic_width));
         _FDT(fdt_setprop_cell(fdt, chosen, "qemu,graphic-height", graphic_height));
         _FDT(fdt_setprop_cell(fdt, chosen, "qemu,graphic-depth", graphic_depth));
system/globals-target.c +0 -6
index 17a27a06218..ffa6c308b59 100644
@@ -9,12 +9,6 @@
 #include "qemu/osdep.h"
 #include "system/system.h"
 
-#if defined(TARGET_SPARC) || defined(TARGET_M68K)
 int graphic_width;
 int graphic_height;
 int graphic_depth;
-#else
-int graphic_width = 800;
-int graphic_height = 600;
-int graphic_depth = 32;
-#endif
Signature · 1 line
2.52.0
Reviewed-by on v2 7/8
#10 lore raw

Re: [PATCH v2 7/8] hw/ppc: Set graphic display dimensions generically

Quoted 11 lines · Philippe Mathieu-Daudé

If a dimension is not set, have the machine init code set the default values.

---
  hw/ppc/mac_newworld.c   | 9 +++++++++
  hw/ppc/mac_oldworld.c   | 9 +++++++++
  hw/ppc/prep.c           | 9 +++++++++
  hw/ppc/spapr.c          | 9 +++++++++
  system/globals-target.c | 6 ------
  5 files changed, 36 insertions(+), 6 deletions(-)

r~

#11 lore raw

PATCH v2 8/8 system/globals: Build as common code

In reply to Philippe Mathieu-Daudé

Now that all targets have the graphic dimension variables initialized the same way, we can move them to the common file unit, having them built once. Remove the now empty globals-target.c file. The command line '-g WxH[xD]' option is not changed and behaves the same.

---
 system/globals-target.c | 14 --------------
 system/globals.c        |  3 +++
 system/meson.build      |  4 ----
 3 files changed, 3 insertions(+), 18 deletions(-)
 delete mode 100644 system/globals-target.c
system/globals-target.c deleted +0 -14
deleted file mode 100644
index ffa6c308b59..00000000000
@@ -1,14 +0,0 @@
-/*
- * Global variables that should not exist (target specific)
- *
- * Copyright (c) 2003-2008 Fabrice Bellard
- *
- * SPDX-License-Identifier: MIT
- */
-
-#include "qemu/osdep.h"
-#include "system/system.h"
-
-int graphic_width;
-int graphic_height;
-int graphic_depth;
system/globals.c +3 -0
index c33f6ed3902..34fd3ce9c72 100644
@@ -49,6 +49,9 @@ bool enable_cpu_pm;
 int autostart = 1;
 int vga_interface_type = VGA_NONE;
 bool vga_interface_created;
+int graphic_width;
+int graphic_height;
+int graphic_depth;
 Chardev *parallel_hds[MAX_PARALLEL_PORTS];
 QEMUOptionRom option_rom[MAX_OPTION_ROMS];
 int nb_option_roms;
system/meson.build +0 -4
index d91703d3dcc..579e8353d53 100644
@@ -1,7 +1,3 @@
-specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
-  'globals-target.c',
-)])
-
 system_ss.add(files(
   'vl.c',
 ), sdl, libpmem, libdaxctl)
Signature · 1 line
2.52.0
Reviewed-by on v2 8/8
#12 lore raw

Re: [PATCH v2 8/8] system/globals: Build as common code

Quoted 6 lines · Philippe Mathieu-Daudé

Now that all targets have the graphic dimension variables initialized the same way, we can move them to the common file unit, having them built once. Remove the now empty globals-target.c file. The command line '-g WxH[xD]' option is not changed and behaves the same.

Quoted 8 lines
---
  system/globals-target.c | 14 --------------
  system/globals.c        |  3 +++
  system/meson.build      |  4 ----
  3 files changed, 3 insertions(+), 18 deletions(-)

delete mode 100644 system/globals-target.c

r~

#13 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Philippe Mathieu-Daudé (8):
hw/display/macfb: Constify macfb_sense_table[] array hw/display/macfb: Constify macfb_mode_table[] array hw/m68k/q800: Use MacFbMode fields in q800_machine_init() hw/m68k/q800: Set MACFB_DISPLAY_APPLE_21_COLOR within MacFrameBuffer hw/m68k: Set graphic display dimensions generically hw/sparc: Set graphic display dimensions generically hw/ppc: Set graphic display dimensions generically system/globals: Build as common code

Series queued, thanks.