Skip to contentSkip to conversation

hw/display/tcx: Mark the VRAM dirty upon reset

PATCH In review Philippe Mathieu-Daudé via 4 participants 7 messages Feb 3, 2022 – Sep 25, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hw/display/tcx: Mark the VRAM dirty upon reset

When resetting we don't want to *reset* the dirty bitmap, we want to *set* it to mark the entire VRAM dirty due to the memset() call.

Replace memory_region_reset_dirty() by tcx_set_dirty() which conveniently set the correct ranges dirty.

---
Supersedes: <[email protected]>

---
 hw/display/tcx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/display/tcx.c +1 -2
index d4d09d0df8..90e2975e35 100644
@@ -371,8 +371,7 @@ static void tcx_reset(DeviceState *d)
     s->r[258] = s->g[258] = s->b[258] = 255;
     update_palette_entries(s, 0, 260);
     memset(s->vram, 0, MAXX*MAXY);
-    memory_region_reset_dirty(&s->vram_mem, 0, MAXX * MAXY * (1 + 4 + 4),
-                              DIRTY_MEMORY_VGA);
+    tcx_set_dirty(s, 0, MAXX * MAXY);
     s->dac_index = 0;
     s->dac_state = 0;
     s->cursx = 0xf000; /* Put cursor off screen */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 20 lines · Philippe Mathieu-Daudé via

When resetting we don't want to *reset* the dirty bitmap, we want to *set* it to mark the entire VRAM dirty due to the memset() call.

Replace memory_region_reset_dirty() by tcx_set_dirty() which conveniently set the correct ranges dirty.

---
Supersedes: <[email protected]>

---
  hw/display/tcx.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
hw/display/tcx.c +0 -0
index d4d09d0df8..90e2975e35 100644

hw/display/tcx.c static void tcx_reset(DeviceState *d) · line 377

Quoted 9 lines
hw/display/tcx.c +1 -2
@@ -371,8 +371,7 @@ static void tcx_reset(DeviceState *d)
      s->r[258] = s->g[258] = s->b[258] = 255;
      update_palette_entries(s, 0, 260);
      memset(s->vram, 0, MAXX*MAXY);
-    memory_region_reset_dirty(&s->vram_mem, 0, MAXX * MAXY * (1 + 4 + 4),
-                              DIRTY_MEMORY_VGA);
+    tcx_set_dirty(s, 0, MAXX * MAXY);
      s->dac_index = 0;
      s->dac_state = 0;
      s->cursx = 0xf000; /* Put cursor off screen */

I don't think the size calculation of MAXX * MAXY is correct when comparing with above? I think it's easiest just to use the same approach as update_palette_entries() here e.g.

    tcx_set_dirty(s, 0, memory_region_size(&s->vram_mem));

ATB,

Mark.

#2 lore raw
Quoted 17 lines · Mark Cave-Ayland
Quoted 15 lines · Philippe Mathieu-Daudé via

When resetting we don't want to *reset* the dirty bitmap, we want to *set* it to mark the entire VRAM dirty due to the memset() call.

Replace memory_region_reset_dirty() by tcx_set_dirty() which conveniently set the correct ranges dirty.

---
Supersedes: <[email protected]>

---
  hw/display/tcx.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 8 lines

hw/display/tcx.c static void tcx_reset(DeviceState *d) · line 373

Quoted 8 lines
hw/display/tcx.c +0 -0
index d4d09d0df8..90e2975e35 100644
@@ -371,8 +371,7 @@ static void tcx_reset(DeviceState *d)
      s->r[258] = s->g[258] = s->b[258] = 255;
      update_palette_entries(s, 0, 260);
      memset(s->vram, 0, MAXX*MAXY);

Should checkpatch complain about missing spaces around * here?

Quoted 8 lines

hw/display/tcx.c static void tcx_reset(DeviceState *d) · line 377

Quoted 6 lines
hw/display/tcx.c +1 -2
-    memory_region_reset_dirty(&s->vram_mem, 0, MAXX * MAXY * (1 + 4 + 4),
-                              DIRTY_MEMORY_VGA);
+    tcx_set_dirty(s, 0, MAXX * MAXY);
      s->dac_index = 0;
      s->dac_state = 0;
      s->cursx = 0xf000; /* Put cursor off screen */

I don't think the size calculation of MAXX * MAXY is correct when comparing with above? I think it's easiest just to use the same approach as

Xonsidering that the memset has the same length it should be correct as that's what has been changed (assuming tcx_set_dirty works correctly), but maybe there's some trick here I don't know about.

Quoted 3 lines

update_palette_entries() here e.g.

   tcx_set_dirty(s, 0, memory_region_size(&s->vram_mem));

This may be an overkill. Although probably does not matter but it's still cleaner to only set dirty what has been changed otherwise you've just disabled dirty tracking. On the other hand, if this is a reset routine do you only want to clear the displayable part of vram or the whole vram?

Regards,
BALATON Zoltan

#3 lore raw
Quoted 21 lines · BALATON Zoltan
Quoted 19 lines · Mark Cave-Ayland
Quoted 16 lines · Philippe Mathieu-Daudé via

When resetting we don't want to *reset* the dirty bitmap, we want to *set* it to mark the entire VRAM dirty due to the memset() call.

Replace memory_region_reset_dirty() by tcx_set_dirty() which conveniently set the correct ranges dirty.

hw/display/tcx.c +1 -2
-    memory_region_reset_dirty(&s->vram_mem, 0, MAXX * MAXY * (1 + 4 + 4),
-                              DIRTY_MEMORY_VGA);
+    tcx_set_dirty(s, 0, MAXX * MAXY);
      s->dac_index = 0;
      s->dac_state = 0;
      s->cursx = 0xf000; /* Put cursor off screen */
Quoted 6 lines
Quoted 2 lines

I don't think the size calculation of MAXX * MAXY is correct when comparing with above? I think it's easiest just to use the same approach as

Xonsidering that the memset has the same length it should be correct as that's what has been changed (assuming tcx_set_dirty works correctly), but maybe there's some trick here I don't know about.

The memset chosen size seems odd -- MAXX and MAXY are constants, but the size of the memory block here is s->vram_size * 9, which might be smaller than MAXX * MAXY...

Quoted 8 lines
Quoted 3 lines

update_palette_entries() here e.g.

   tcx_set_dirty(s, 0, memory_region_size(&s->vram_mem));

This may be an overkill. Although probably does not matter but it's still cleaner to only set dirty what has been changed otherwise you've just disabled dirty tracking. On the other hand, if this is a reset routine do you only want to clear the displayable part of vram or the whole vram?

I think we should clear the whole of the vram -- it ought to go back to the same state as when the device was completed. If I'm reading the sun4m board code correctly, the other parts of the vram are mapped into the guest address space too.

So I would go for

    memset(s->vram, 0, memory_region_size(&s->vram_mem));
    memory_region_set_dirty(&s->vram_mem, 0, memory_region_size(&s->vram_mem),
                            DIRTY_MEMORY_VGA);

We can then delete the MAXX and MAXY defines, which were previously used only in these two lines and which don't actually have any relationship to the maximum size of the framebuffer.

The handling of the vram buffer seems weird in this device overall, though -- the memory block is divided into three parts
* main vram, one byte per pixel
* vram24, four bytes per pixel
* cplane, four bytes per pixel

As far as I can see, only if depth=24 (fixed at device creation time) do we use the vram24 and cplane parts. But we create the memory block at the same size regardless of depth and we expose the vram24 and cplane parts to the guest as sysbus MMIO regions that are mapped into guest memory regardless of depth...

-- PMM

#4 lore raw
Quoted 47 lines · Peter Maydell
Quoted 21 lines · BALATON Zoltan
Quoted 19 lines · Mark Cave-Ayland
Quoted 16 lines · Philippe Mathieu-Daudé via

When resetting we don't want to *reset* the dirty bitmap, we want to *set* it to mark the entire VRAM dirty due to the memset() call.

Replace memory_region_reset_dirty() by tcx_set_dirty() which conveniently set the correct ranges dirty.

hw/display/tcx.c +1 -2
-    memory_region_reset_dirty(&s->vram_mem, 0, MAXX * MAXY * (1 + 4 + 4),
-                              DIRTY_MEMORY_VGA);
+    tcx_set_dirty(s, 0, MAXX * MAXY);
       s->dac_index = 0;
       s->dac_state = 0;
       s->cursx = 0xf000; /* Put cursor off screen */
Quoted 6 lines
Quoted 2 lines

I don't think the size calculation of MAXX * MAXY is correct when comparing with above? I think it's easiest just to use the same approach as

Xonsidering that the memset has the same length it should be correct as that's what has been changed (assuming tcx_set_dirty works correctly), but maybe there's some trick here I don't know about.

The memset chosen size seems odd -- MAXX and MAXY are constants, but the size of the memory block here is s->vram_size * 9, which might be smaller than MAXX * MAXY...

Quoted 8 lines
Quoted 3 lines

update_palette_entries() here e.g.

    tcx_set_dirty(s, 0, memory_region_size(&s->vram_mem));

This may be an overkill. Although probably does not matter but it's still cleaner to only set dirty what has been changed otherwise you've just disabled dirty tracking. On the other hand, if this is a reset routine do you only want to clear the displayable part of vram or the whole vram?

I think we should clear the whole of the vram -- it ought to go back to the same state as when the device was completed. If I'm reading the sun4m board code correctly, the other parts of the vram are mapped into the guest address space too.

Quoted 8 lines

So I would go for

     memset(s->vram, 0, memory_region_size(&s->vram_mem));
     memory_region_set_dirty(&s->vram_mem, 0, memory_region_size(&s->vram_mem),
                             DIRTY_MEMORY_VGA);

We can then delete the MAXX and MAXY defines, which were previously used only in these two lines and which don't actually have any relationship to the maximum size of the framebuffer.

That makes sense to me. My guess is that MAXX and MAXY were originally used for calculations on the original 8-bit framebuffer and the size calculation wasn't updated when 24-bit support was added.

Quoted 11 lines

The handling of the vram buffer seems weird in this device overall, though -- the memory block is divided into three parts
* main vram, one byte per pixel
* vram24, four bytes per pixel
* cplane, four bytes per pixel

As far as I can see, only if depth=24 (fixed at device creation time) do we use the vram24 and cplane parts. But we create the memory block at the same size regardless of depth and we expose the vram24 and cplane parts to the guest as sysbus MMIO regions that are mapped into guest memory regardless of depth...

(goes and looks)

It does look a bit odd certainly. Without Blue Swirl being around all I can only guess as to why everything is configured to use an alias onto a single VRAM memory region :/

As for exposing the vram24 and cplane parts, I don't think it matters since 24-bit mode is clearly designed to be backwards compatible with 8-bit mode. During initialisation OpenBIOS reads the colour depth using the fw_cfg interface and adds the registers for that mode into the DT as required so the correct information is exposed to the guest.

ATB,

Mark.

#5 lore raw
Quoted 20 lines · Mark Cave-Ayland
Quoted 11 lines · Peter Maydell

The handling of the vram buffer seems weird in this device overall, though -- the memory block is divided into three parts
* main vram, one byte per pixel
* vram24, four bytes per pixel
* cplane, four bytes per pixel

As far as I can see, only if depth=24 (fixed at device creation time) do we use the vram24 and cplane parts. But we create the memory block at the same size regardless of depth and we expose the vram24 and cplane parts to the guest as sysbus MMIO regions that are mapped into guest memory regardless of depth...

(goes and looks)

It does look a bit odd certainly. Without Blue Swirl being around all I can only guess as to why everything is configured to use an alias onto a single VRAM memory region :/

Quoted 5 lines

As for exposing the vram24 and cplane parts, I don't think it matters since 24-bit mode is clearly designed to be backwards compatible with 8-bit mode. During initialisation OpenBIOS reads the colour depth using the fw_cfg interface and adds the registers for that mode into the DT as required so the correct information is exposed to the guest.

A guest won't notice if we expose stuff to it that it doesn't expect to be there -- but if the 8-bit-only device is not supposed to have those memory regions we shouldn't be creating them...

-- PMM

#6 lore raw
Quoted 29 lines · Peter Maydell
Quoted 20 lines · Mark Cave-Ayland
Quoted 11 lines · Peter Maydell

The handling of the vram buffer seems weird in this device overall, though -- the memory block is divided into three parts
* main vram, one byte per pixel
* vram24, four bytes per pixel
* cplane, four bytes per pixel

As far as I can see, only if depth=24 (fixed at device creation time) do we use the vram24 and cplane parts. But we create the memory block at the same size regardless of depth and we expose the vram24 and cplane parts to the guest as sysbus MMIO regions that are mapped into guest memory regardless of depth...

(goes and looks)

It does look a bit odd certainly. Without Blue Swirl being around all I can only guess as to why everything is configured to use an alias onto a single VRAM memory region :/

Quoted 5 lines

As for exposing the vram24 and cplane parts, I don't think it matters since 24-bit mode is clearly designed to be backwards compatible with 8-bit mode. During initialisation OpenBIOS reads the colour depth using the fw_cfg interface and adds the registers for that mode into the DT as required so the correct information is exposed to the guest.

Quoted 3 lines

A guest won't notice if we expose stuff to it that it doesn't expect to be there -- but if the 8-bit-only device is not supposed to have those memory regions we shouldn't be creating them...

I guess I'll go with your code suggestion as a first step, and we can figure out whether this MR is pointless and remove it later.