hw/block/pflash: Add DeviceReset() handlers
cover hw/block/pflash: Add DeviceReset() handlers
The pflash device lacks a reset() function. When a machine is resetted, the flash might be in an inconsistent state, leading to unexpected behavior:
https://bugzilla.redhat.com/show_bug.cgi?id=1678713
Resolve this issue by adding a DeviceReset() handler.
Both CFI01/CFI02 devices are fixed by this series.
Regards,
Phil.
Philippe Mathieu-Daudé (5):
hw/block/pflash_cfi01: Removed an unused timer hw/block/pflash_cfi01: Extract the pflash_reset() code hw/block/pflash_cfi01: Add the DeviceReset() handler hw/block/pflash_cfi02: Extract the pflash_reset() code hw/block/pflash_cfi02: Add the DeviceReset() handler
hw/block/pflash_cfi01.c | 31 ++++++++++++------------------- hw/block/pflash_cfi02.c | 31 +++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 29 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/5 hw/block/pflash_cfi01: Removed an unused timer
The 'CFI01' NOR flash was introduced in commit 29133e9a0fff, with timing modelled. One year later, the CFI02 model was introduced (commit 05ee37ebf630) based on the CFI01 model. As noted in the header, "It does not support timings". 12 years later, we never had to model the device timings. Time to remove the unused timer, we can still add it back if required.
---
Yes, I plan to model those timings later. Actually I have a series working, but I'd rather first
1/ refactor common code between the both CFI implementations, 2/ discuss on list whether or not use timings for the Virt flash.
--- hw/block/pflash_cfi01.c | 15 --------------- 1 file changed, 15 deletions(-)
hw/block/pflash_cfi01.c +0 -15
@@ -42,7 +42,6 @@#include "hw/block/flash.h" #include "sysemu/block-backend.h" #include "qapi/error.h" -#include "qemu/timer.h" #include "qemu/bitops.h" #include "qemu/host-utils.h" #include "qemu/log.h"
@@ -86,7 +85,6 @@ struct PFlashCFI01 {uint8_t cfi_table[0x52 ];uint64_t counter;unsigned int writeblock_size; -QEMUTimer *timer;MemoryRegion mem;char *name;void *storage;
@@ -110,18 +108,6 @@ static const VMStateDescription vmstate_pflash = { } }; -static void pflash_timer (void *opaque) -{ -PFlashCFI01 *pfl = opaque; - -trace_pflash_timer_expired (pfl->cmd); -/* Reset flash */ - pfl->status ^=0x80 ; -memory_region_rom_device_set_romd (&pfl->mem, true); - pfl->wcycle =0 ; - pfl->cmd =0 ; -} -/* Perform a CFI query based on the bank width of the flash. * If this code is called we know we have a device_width set for * this flash.
@@ -771,7 +757,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->max_device_width = pfl->device_width; } - pfl->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , pflash_timer, pfl); pfl->wcycle =0 ; pfl->cmd =0 ; pfl->status =0 ;
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH 1/5] hw/block/pflash_cfi01: Removed an unused timer
Quoted 9 lines · Philippe Mathieu-Daudé
The 'CFI01' NOR flash was introduced in commit
29133e9a0fff, with timing modelled. One year later, the CFI02 model was introduced (commit05ee37ebf630) based on the CFI01 model. As noted in the header, "It does not support timings". 12 years later, we never had to model the device timings. Time to remove the unused timer, we can still add it back if required.Suggested-by Laszlo Ersek <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 58 lines
---
Yes, I plan to model those timings later. Actually I have a series working, but I'd rather first
1/ refactor common code between the both CFI implementations, 2/ discuss on list whether or not use timings for the Virt flash.
---hw/block/pflash_cfi01.c| 15 ---------------1 file changed, 15 deletions(-)hw/block/pflash_cfi01.c +0
-15@@ -42,7 +42,6 @@#include "hw/block/flash.h" #include "sysemu/block-backend.h" #include "qapi/error.h" -#include "qemu/timer.h" #include "qemu/bitops.h" #include "qemu/host-utils.h" #include "qemu/log.h" @@ -86,7 +85,6 @@ struct PFlashCFI01 {uint8_t cfi_table[0x52 ];uint64_t counter;unsigned int writeblock_size; -QEMUTimer *timer;MemoryRegion mem;char *name;void *storage;@@ -110,18 +108,6 @@ static const VMStateDescription vmstate_pflash = { } }; -static void pflash_timer (void *opaque) -{ -PFlashCFI01 *pfl = opaque; - -trace_pflash_timer_expired (pfl->cmd); -/* Reset flash */ - pfl->status ^=0x80 ; -memory_region_rom_device_set_romd (&pfl->mem, true); - pfl->wcycle =0 ; - pfl->cmd =0 ; -} -/* Perform a CFI query based on the bank width of the flash. * If this code is called we know we have a device_width set for * this flash. @@ -771,7 +757,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->max_device_width = pfl->device_width; } - pfl->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , pflash_timer, pfl); pfl->wcycle =0 ; pfl->cmd =0 ; pfl->status =0 ;Signature · 1 line
2.20.1
Signature · 2 lines
Wei Yang Help you, Help me
Re: [Qemu-devel] [PATCH 1/5] hw/block/pflash_cfi01: Removed an unused timer
In reply to Philippe Mathieu-DaudéQuoted 3 lines · Philippe Mathieu-Daudé
The 'CFI01' NOR flash was introduced in commit
29133e9a0fff, with timing modelled. One year later, the CFI02 model was introduced (commit05ee37ebf630) based on the CFI01 model. As noted in the
You got those commit references backwards, I believe:
* Commit 29133e9a0fff ("AMD NOR flash device support (initial patch by Jocelyn Mayer)", 2006-06-25) introduced "hw/pflash_cfi02.c".
* Commit 05ee37ebf630 ("Gumstix 'connex' board support by Thorsten Zitterell.", 2007-11-17) introduced "hw/pflash_cfi01.c".
Quoted 10 lines
header, "It does not support timings". 12 years later, we never had to model the device timings. Time to remove the unused timer, we can still add it back if required.
Suggested-by Laszlo Ersek <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Yes, I plan to model those timings later. Actually I have a series working, but I'd rather first
1/ refactor common code between the both CFI implementations,
Good idea.
Quoted 1 line
2/ discuss on list whether or not use timings for the Virt flash.
What would the timer buy us (specifically wrt. cfi01 / OVMF / ArmVirt)?
Being faithful to actual hardware is always good... except when it runs a significant risk of regressions. :) By that I don't mean "programming errors"; I mean that guest code would now have to conform to various timeouts, and that always makes me a bit concerned.
For this patch, with the commit references fixed:
Thanks,
Laszlo
Quoted 52 lines
--- hw/block/pflash_cfi01.c | 15 --------------- 1 file changed, 15 deletions(-)hw/block/pflash_cfi01.c +0
-15@@ -42,7 +42,6 @@#include "hw/block/flash.h" #include "sysemu/block-backend.h" #include "qapi/error.h" -#include "qemu/timer.h" #include "qemu/bitops.h" #include "qemu/host-utils.h" #include "qemu/log.h" @@ -86,7 +85,6 @@ struct PFlashCFI01 {uint8_t cfi_table[0x52 ];uint64_t counter;unsigned int writeblock_size; -QEMUTimer *timer;MemoryRegion mem;char *name;void *storage;@@ -110,18 +108,6 @@ static const VMStateDescription vmstate_pflash = { } }; -static void pflash_timer (void *opaque) -{ -PFlashCFI01 *pfl = opaque; - -trace_pflash_timer_expired (pfl->cmd); -/* Reset flash */ - pfl->status ^=0x80 ; -memory_region_rom_device_set_romd (&pfl->mem, true); - pfl->wcycle =0 ; - pfl->cmd =0 ; -} -/* Perform a CFI query based on the bank width of the flash. * If this code is called we know we have a device_width set for * this flash. @@ -771,7 +757,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->max_device_width = pfl->device_width; } - pfl->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , pflash_timer, pfl); pfl->wcycle =0 ; pfl->cmd =0 ; pfl->status =0 ;
Re: [Qemu-devel] [PATCH 1/5] hw/block/pflash_cfi01: Removed an unused timer
Quoted 5 lines · Laszlo Ersek
Quoted 3 lines · Philippe Mathieu-Daudé
The 'CFI01' NOR flash was introduced in commit
29133e9a0fff, with timing modelled. One year later, the CFI02 model was introduced (commit05ee37ebf630) based on the CFI01 model. As noted in the
Quoted 7 lines
You got those commit references backwards, I believe:
* Commit
29133e9a0fff("AMD NOR flash device support (initial patch by Jocelyn Mayer)", 2006-06-25) introduced "hw/pflash_cfi02.c".* Commit
05ee37ebf630("Gumstix 'connex' board support by Thorsten Zitterell.", 2007-11-17) introduced "hw/pflash_cfi01.c".
Argh yes, thank you!
Quoted 13 lines
Quoted 10 lines
header, "It does not support timings". 12 years later, we never had to model the device timings. Time to remove the unused timer, we can still add it back if required.
Suggested-by Laszlo Ersek <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Yes, I plan to model those timings later. Actually I have a series working, but I'd rather first
1/ refactor common code between the both CFI implementations,Good idea.
Quoted 8 lines
Quoted 1 line
2/ discuss on list whether or not use timings for the Virt flash.
What would the timer buy us (specifically wrt. cfi01 / OVMF / ArmVirt)?
Being faithful to actual hardware is always good... except when it runs a significant risk of regressions. :) By that I don't mean "programming errors"; I mean that guest code would now have to conform to various timeouts, and that always makes me a bit concerned.
I'm glat you feel concerned :)
My goal is to model enough of the device to be able to run 'Capsule Based Firmware Updates' [*], but I haven't investigated much yet. Embedded firmware usually care about such timings. Anyway if this is implemented as a feature, it would be disabled by default for the Virt flash (I name the Virt flash the one used by the Virt X86/Aarch64 machines).
Quoted 4 lines
For this patch, with the commit references fixed:
Reviewed-by Laszlo Ersek <[email protected]>
Will do, thanks!
Quoted 57 lines
Thanks,
LaszloQuoted 52 lines
--- hw/block/pflash_cfi01.c | 15 --------------- 1 file changed, 15 deletions(-)hw/block/pflash_cfi01.c +0
-15@@ -42,7 +42,6 @@#include "hw/block/flash.h" #include "sysemu/block-backend.h" #include "qapi/error.h" -#include "qemu/timer.h" #include "qemu/bitops.h" #include "qemu/host-utils.h" #include "qemu/log.h" @@ -86,7 +85,6 @@ struct PFlashCFI01 {uint8_t cfi_table[0x52 ];uint64_t counter;unsigned int writeblock_size; -QEMUTimer *timer;MemoryRegion mem;char *name;void *storage;@@ -110,18 +108,6 @@ static const VMStateDescription vmstate_pflash = { } }; -static void pflash_timer (void *opaque) -{ -PFlashCFI01 *pfl = opaque; - -trace_pflash_timer_expired (pfl->cmd); -/* Reset flash */ - pfl->status ^=0x80 ; -memory_region_rom_device_set_romd (&pfl->mem, true); - pfl->wcycle =0 ; - pfl->cmd =0 ; -} -/* Perform a CFI query based on the bank width of the flash. * If this code is called we know we have a device_width set for * this flash. @@ -771,7 +757,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->max_device_width = pfl->device_width; } - pfl->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , pflash_timer, pfl); pfl->wcycle =0 ; pfl->cmd =0 ; pfl->status =0 ;
PATCH 2/5 hw/block/pflash_cfi01: Extract the pflash_reset() code
In reply to Philippe Mathieu-DaudéThe reset() code is used in various places, refactor it.
--- hw/block/pflash_cfi01.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
hw/block/pflash_cfi01.c +12 -9
@@ -108,6 +108,15 @@ static const VMStateDescription vmstate_pflash = { } }; +static void pflash_reset (PFlashCFI01 *pfl) +{ +trace_pflash_reset (); + pfl->wcycle =0 ; + pfl->cmd =0 ; + pfl->status =0 ; +memory_region_rom_device_set_romd (&pfl->mem, true); +} +/* Perform a CFI query based on the bank width of the flash. * If this code is called we know we have a device_width set for * this flash.
@@ -275,8 +284,7 @@ static uint32_t pflash_read(PFlashCFI01 *pfl, hwaddr offset,default :/* This should never happen : reset state & treat it as a read */ DPRINTF ("%s: unknown command state: %x\n" , __func__, pfl->cmd); - pfl->wcycle =0 ; - pfl->cmd =0 ; +pflash_reset (pfl);/* fall through to read code */ case 0x00 :/* Flash area read */
@@ -639,10 +647,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset, "\n", __func__, offset, pfl->wcycle, pfl->cmd, value); reset_flash: -trace_pflash_reset (); -memory_region_rom_device_set_romd (&pfl->mem, true); - pfl->wcycle =0 ; - pfl->cmd =0 ; +pflash_reset (pfl); }
@@ -757,9 +762,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->max_device_width = pfl->device_width; } - pfl->wcycle =0 ; - pfl->cmd =0 ; - pfl->status =0 ; +pflash_reset (pfl);/* Hardcoded CFI table */ /* Standard "QRY" string */ pfl->cfi_table[0x10 ] ='Q' ;
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH 2/5] hw/block/pflash_cfi01: Extract the pflash_reset() code
Quoted 3 lines · Philippe Mathieu-Daudé
The
reset()code is used in various places, refactor it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 59 lines
---
hw/block/pflash_cfi01.c| 21 ++++++++++++---------1 file changed, 12 insertions(+), 9 deletions(-)hw/block/pflash_cfi01.c +12
-9@@ -108,6 +108,15 @@ static const VMStateDescription vmstate_pflash = { } }; +static void pflash_reset (PFlashCFI01 *pfl) +{ +trace_pflash_reset (); + pfl->wcycle =0 ; + pfl->cmd =0 ; + pfl->status =0 ; +memory_region_rom_device_set_romd (&pfl->mem, true); +} +/* Perform a CFI query based on the bank width of the flash. * If this code is called we know we have a device_width set for * this flash. @@ -275,8 +284,7 @@ static uint32_t pflash_read(PFlashCFI01 *pfl, hwaddr offset,default :/* This should never happen : reset state & treat it as a read */ DPRINTF ("%s: unknown command state: %x\n" , __func__, pfl->cmd); - pfl->wcycle =0 ; - pfl->cmd =0 ; +pflash_reset (pfl);/* fall through to read code */ case 0x00 :/* Flash area read */ @@ -639,10 +647,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset, "\n", __func__, offset, pfl->wcycle, pfl->cmd, value); reset_flash: -trace_pflash_reset (); -memory_region_rom_device_set_romd (&pfl->mem, true); - pfl->wcycle =0 ; - pfl->cmd =0 ; +pflash_reset (pfl); }@@ -757,9 +762,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->max_device_width = pfl->device_width; } - pfl->wcycle =0 ; - pfl->cmd =0 ; - pfl->status =0 ; +pflash_reset (pfl);/* Hardcoded CFI table */ /* Standard "QRY" string */ pfl->cfi_table[0x10 ] ='Q' ;Signature · 1 line
2.20.1
Signature · 2 lines
Wei Yang Help you, Help me
Re: [Qemu-devel] [PATCH 2/5] hw/block/pflash_cfi01: Extract the pflash_reset() code
In reply to Philippe Mathieu-DaudéQuoted 28 lines · Philippe Mathieu-Daudé
The
reset()code is used in various places, refactor it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/block/pflash_cfi01.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)hw/block/pflash_cfi01.c +9
-0@@ -108,6 +108,15 @@ static const VMStateDescription vmstate_pflash = { } }; +static void pflash_reset (PFlashCFI01 *pfl) +{ +trace_pflash_reset (); + pfl->wcycle =0 ; + pfl->cmd =0 ; + pfl->status =0 ; +memory_region_rom_device_set_romd (&pfl->mem, true); +} +/* Perform a CFI query based on the bank width of the flash. * If this code is called we know we have a device_width set for * this flash.
hw/block/pflash_cfi01.c static uint32_t pflash_read(PFlashCFI01 *pfl, hwaddr offset, · line 290
Quoted 9 lines
hw/block/pflash_cfi01.c +1
-2@@ -275,8 +284,7 @@ static uint32_t pflash_read(PFlashCFI01 *pfl, hwaddr offset,default :/* This should never happen : reset state & treat it as a read */ DPRINTF ("%s: unknown command state: %x\n" , __func__, pfl->cmd); - pfl->wcycle =0 ; - pfl->cmd =0 ; +pflash_reset (pfl);/* fall through to read code */ case 0x00 :/* Flash area read */
This change introduces two new actions:
- zeroing "status"
- flipping the chip to romd mode (unless it's already in romd mode)
hw/block/pflash_cfi01.c static void pflash_write(PFlashCFI01 *pfl, hwaddr offset, · line 651
Quoted 10 lines
hw/block/pflash_cfi01.c +1
-4@@ -639,10 +647,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset, "\n", __func__, offset, pfl->wcycle, pfl->cmd, value); reset_flash: -trace_pflash_reset (); -memory_region_rom_device_set_romd (&pfl->mem, true); - pfl->wcycle =0 ; - pfl->cmd =0 ; +pflash_reset (pfl); }
This change introduces a new action:
- zeroing "status"
hw/block/pflash_cfi01.c static void pflash_cfi01_realize(DeviceState *dev, Error **errp) · line 765
Quoted 10 lines
hw/block/pflash_cfi01.c +1
-3@@ -757,9 +762,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->max_device_width = pfl->device_width; } - pfl->wcycle =0 ; - pfl->cmd =0 ; - pfl->status =0 ; +pflash_reset (pfl);
This change introduces a new action:
- flipping the chip to romd mode (unless it's already in romd mode)
hw/block/pflash_cfi01.c static void pflash_cfi01_realize(DeviceState *dev, Error **errp) · line 768
Quoted 4 lines
hw/block/pflash_cfi01.c +0
-0/* Hardcoded CFI table */ /* Standard "QRY" string */ pfl->cfi_table[0x10 ] ='Q' ;
Therefore, this patch is not *obviously* a refactoring patch. (IOW, it may be a pure refactoring patch, but it's not very easy to see.) I suggest:
- either documenting the new actions in the commit message (and why they are justified),
- or prepending a separate patch that first unifies the behavior in all the separate reset locations, and then this patch could indeed become an "obvious" refactoring / code exctraction.
(Clearly, I'm asking for this with an eye towards git-bisect.)
Thanks
Laszlo
Re: [Qemu-devel] [PATCH 2/5] hw/block/pflash_cfi01: Extract the pflash_reset() code
In reply to Philippe Mathieu-DaudéQuoted 6 lines · Philippe Mathieu-Daudé
The
reset()code is used in various places, refactor it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/block/pflash_cfi01.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
BTW: you didn't add an explicit "Cc: stable" tag here, so I almost missed it -- but, mainly, is this really suitable material for stable? We haven't really noticed (or at least pin-pointed) the lack of the reset handlers in 12 years, correct?
Thanks
Laszlo
Quoted 55 lines
hw/block/pflash_cfi01.c +12
-9@@ -108,6 +108,15 @@ static const VMStateDescription vmstate_pflash = { } }; +static void pflash_reset (PFlashCFI01 *pfl) +{ +trace_pflash_reset (); + pfl->wcycle =0 ; + pfl->cmd =0 ; + pfl->status =0 ; +memory_region_rom_device_set_romd (&pfl->mem, true); +} +/* Perform a CFI query based on the bank width of the flash. * If this code is called we know we have a device_width set for * this flash. @@ -275,8 +284,7 @@ static uint32_t pflash_read(PFlashCFI01 *pfl, hwaddr offset,default :/* This should never happen : reset state & treat it as a read */ DPRINTF ("%s: unknown command state: %x\n" , __func__, pfl->cmd); - pfl->wcycle =0 ; - pfl->cmd =0 ; +pflash_reset (pfl);/* fall through to read code */ case 0x00 :/* Flash area read */ @@ -639,10 +647,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset, "\n", __func__, offset, pfl->wcycle, pfl->cmd, value); reset_flash: -trace_pflash_reset (); -memory_region_rom_device_set_romd (&pfl->mem, true); - pfl->wcycle =0 ; - pfl->cmd =0 ; +pflash_reset (pfl); }@@ -757,9 +762,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->max_device_width = pfl->device_width; } - pfl->wcycle =0 ; - pfl->cmd =0 ; - pfl->status =0 ; +pflash_reset (pfl);/* Hardcoded CFI table */ /* Standard "QRY" string */ pfl->cfi_table[0x10 ] ='Q' ;
PATCH 3/5 hw/block/pflash_cfi01: Add the DeviceReset() handler
In reply to Philippe Mathieu-DaudéThe pflash device is a child of TYPE_DEVICE, so it can implement the DeviceReset handler. Actually it has to implement it, else on machine reset it might stay in an incoherent state, as it has been reported in the buglink listed below.
Add the DeviceReset handler and remove its call from the realize() function.
--- hw/block/pflash_cfi01.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/block/pflash_cfi01.c +6 -1
@@ -762,7 +762,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->max_device_width = pfl->device_width; } -pflash_reset (pfl);/* Hardcoded CFI table */ /* Standard "QRY" string */ pfl->cfi_table[0x10 ] ='Q' ;
@@ -850,6 +849,11 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->cfi_table[0x3f ] =0x01 ;/* Number of protection fields */ } +static void pflash_cfi01_reset (DeviceState *dev) +{ +pflash_reset (PFLASH_CFI01 (dev)); +} +static Property pflash_cfi01_properties[] = {DEFINE_PROP_DRIVE ("drive" , PFlashCFI01, blk),/* num-blocks is the number of blocks actually visible to the guest,
@@ -894,6 +898,7 @@ static void pflash_cfi01_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass); + dc->reset = pflash_cfi01_reset; dc->realize = pflash_cfi01_realize; dc->props = pflash_cfi01_properties; dc->vmsd = &vmstate_pflash;
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH 3/5] hw/block/pflash_cfi01: Add the DeviceReset() handler
Quoted 11 lines · Philippe Mathieu-Daudé
The pflash device is a child of
TYPE_DEVICE, so it can implement the DeviceReset handler. Actually it has to implement it, else on machine reset it might stay in an incoherent state, as it has been reported in the buglink listed below.Add the DeviceReset handler and remove its call from the
realize()function.Reported-by Laszlo Ersek <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 2 lines
Wei Yang Help you, Help me
Re: [Qemu-devel] [PATCH 3/5] hw/block/pflash_cfi01: Add the DeviceReset() handler
In reply to Philippe Mathieu-DaudéQuoted 41 lines · Philippe Mathieu-Daudé
The pflash device is a child of
TYPE_DEVICE, so it can implement the DeviceReset handler. Actually it has to implement it, else on machine reset it might stay in an incoherent state, as it has been reported in the buglink listed below.Add the DeviceReset handler and remove its call from the
realize()function.Reported-by Laszlo Ersek <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/block/pflash_cfi01.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)hw/block/pflash_cfi01.c +5
-1@@ -762,7 +762,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->max_device_width = pfl->device_width; } -pflash_reset (pfl);/* Hardcoded CFI table */ /* Standard "QRY" string */ pfl->cfi_table[0x10 ] ='Q' ;@@ -850,6 +849,11 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) pfl->cfi_table[0x3f ] =0x01 ;/* Number of protection fields */ } +static void pflash_cfi01_reset (DeviceState *dev) +{ +pflash_reset (PFLASH_CFI01 (dev)); +} +static Property pflash_cfi01_properties[] = {DEFINE_PROP_DRIVE ("drive" , PFlashCFI01, blk),/* num-blocks is the number of blocks actually visible to the guest,
hw/block/pflash_cfi01.c static void pflash_cfi01_class_init(ObjectClass *klass, void *data) · line 904
Quoted 7 lines
hw/block/pflash_cfi01.c +1
-0@@ -894,6 +898,7 @@ static void pflash_cfi01_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass); + dc->reset = pflash_cfi01_reset; dc->realize = pflash_cfi01_realize; dc->props = pflash_cfi01_properties; dc->vmsd = &vmstate_pflash;
(Hopefully I'm not missing anything obvious, while writing the below:)
Sometimes the object model is really nice.
Thanks
Laszlo
PATCH 4/5 hw/block/pflash_cfi02: Extract the pflash_reset() code
In reply to Philippe Mathieu-DaudéThe reset() code is used in various places, refactor it.
--- hw/block/pflash_cfi02.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
hw/block/pflash_cfi02.c +15 -10
@@ -120,6 +120,17 @@ static void pflash_register_memory(PFlashCFI02 *pfl, int rom_mode) pfl->rom_mode = rom_mode; } +static void pflash_reset (PFlashCFI02 *pfl) +{ +trace_pflash_reset (); +timer_del (&pfl->timer); + pfl->bypass =0 ; + pfl->wcycle =0 ; + pfl->cmd =0 ; + pfl->status =0 ; +pflash_register_memory (pfl,1 ); +} +static void pflash_timer (void *opaque) {PFlashCFI02 *pfl = opaque;
@@ -129,11 +140,10 @@ static void pflash_timer (void *opaque) pfl->status ^=0x80 ;if (pfl->bypass) { pfl->wcycle =2 ; + pfl->cmd =0 ; }else { -pflash_register_memory (pfl,1 ); - pfl->wcycle =0 ; +pflash_reset (pfl); } - pfl->cmd =0 ; } static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr offset,
@@ -481,10 +491,7 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offset,/* Reset flash */ reset_flash: -trace_pflash_reset (); - pfl->bypass =0 ; - pfl->wcycle =0 ; - pfl->cmd =0 ; +pflash_reset (pfl);return ; do_bypass:
@@ -588,9 +595,7 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)sysbus_init_mmio (SYS_BUS_DEVICE (dev), &pfl->mem);timer_init_ns (&pfl->timer,QEMU_CLOCK_VIRTUAL , pflash_timer, pfl); - pfl->wcycle =0 ; - pfl->cmd =0 ; - pfl->status =0 ; +pflash_reset (pfl);/* Hardcoded CFI table (mostly from SG29 Spansion flash) */ /* Standard "QRY" string */ pfl->cfi_table[0x10 ] ='Q' ;
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH 4/5] hw/block/pflash_cfi02: Extract the pflash_reset() code
Quoted 3 lines · Philippe Mathieu-Daudé
The
reset()code is used in various places, refactor it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 65 lines
---
hw/block/pflash_cfi02.c| 25 +++++++++++++++----------1 file changed, 15 insertions(+), 10 deletions(-)hw/block/pflash_cfi02.c +15
-10@@ -120,6 +120,17 @@ static void pflash_register_memory(PFlashCFI02 *pfl, int rom_mode) pfl->rom_mode = rom_mode; } +static void pflash_reset (PFlashCFI02 *pfl) +{ +trace_pflash_reset (); +timer_del (&pfl->timer); + pfl->bypass =0 ; + pfl->wcycle =0 ; + pfl->cmd =0 ; + pfl->status =0 ; +pflash_register_memory (pfl,1 ); +} +static void pflash_timer (void *opaque) {PFlashCFI02 *pfl = opaque;@@ -129,11 +140,10 @@ static void pflash_timer (void *opaque) pfl->status ^=0x80 ;if (pfl->bypass) { pfl->wcycle =2 ; + pfl->cmd =0 ; }else { -pflash_register_memory (pfl,1 ); - pfl->wcycle =0 ; +pflash_reset (pfl); } - pfl->cmd =0 ; } static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr offset,@@ -481,10 +491,7 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offset,/* Reset flash */ reset_flash: -trace_pflash_reset (); - pfl->bypass =0 ; - pfl->wcycle =0 ; - pfl->cmd =0 ; +pflash_reset (pfl);return ; do_bypass:@@ -588,9 +595,7 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)sysbus_init_mmio (SYS_BUS_DEVICE (dev), &pfl->mem);timer_init_ns (&pfl->timer,QEMU_CLOCK_VIRTUAL , pflash_timer, pfl); - pfl->wcycle =0 ; - pfl->cmd =0 ; - pfl->status =0 ; +pflash_reset (pfl);/* Hardcoded CFI table (mostly from SG29 Spansion flash) */ /* Standard "QRY" string */ pfl->cfi_table[0x10 ] ='Q' ;Signature · 1 line
2.20.1
Signature · 2 lines
Wei Yang Help you, Help me
Re: [Qemu-devel] [PATCH 4/5] hw/block/pflash_cfi02: Extract the pflash_reset() code
In reply to Philippe Mathieu-DaudéQuoted 57 lines · Philippe Mathieu-Daudé
The
reset()code is used in various places, refactor it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/block/pflash_cfi02.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)hw/block/pflash_cfi02.c +14
-7@@ -120,6 +120,17 @@ static void pflash_register_memory(PFlashCFI02 *pfl, int rom_mode) pfl->rom_mode = rom_mode; } +static void pflash_reset (PFlashCFI02 *pfl) +{ +trace_pflash_reset (); +timer_del (&pfl->timer); + pfl->bypass =0 ; + pfl->wcycle =0 ; + pfl->cmd =0 ; + pfl->status =0 ; +pflash_register_memory (pfl,1 ); +} +static void pflash_timer (void *opaque) {PFlashCFI02 *pfl = opaque;@@ -129,11 +140,10 @@ static void pflash_timer (void *opaque) pfl->status ^=0x80 ;if (pfl->bypass) { pfl->wcycle =2 ; + pfl->cmd =0 ; }else { -pflash_register_memory (pfl,1 ); - pfl->wcycle =0 ; +pflash_reset (pfl); } - pfl->cmd =0 ; } static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr offset,@@ -481,10 +491,7 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offset,/* Reset flash */ reset_flash: -trace_pflash_reset (); - pfl->bypass =0 ; - pfl->wcycle =0 ; - pfl->cmd =0 ; +pflash_reset (pfl);return ; do_bypass:
hw/block/pflash_cfi02.c static void pflash_cfi02_realize(DeviceState *dev, Error **errp) · line 601
Quoted 10 lines
hw/block/pflash_cfi02.c +1
-3@@ -588,9 +595,7 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)sysbus_init_mmio (SYS_BUS_DEVICE (dev), &pfl->mem);timer_init_ns (&pfl->timer,QEMU_CLOCK_VIRTUAL , pflash_timer, pfl); - pfl->wcycle =0 ; - pfl->cmd =0 ; - pfl->status =0 ; +pflash_reset (pfl);/* Hardcoded CFI table (mostly from SG29 Spansion flash) */ /* Standard "QRY" string */ pfl->cfi_table[0x10 ] ='Q' ;
I don't have a vested interest in the pflash_cfi02 device model, but I guess my earlier (cfi01) comments would apply -- unify first, extract second. (Or at least document why these changes are unobservable from the behavior POV.)
Thanks
Laszlo
Re: [Qemu-devel] [PATCH 4/5] hw/block/pflash_cfi02: Extract the pflash_reset() code
Quoted 59 lines · Laszlo Ersek
Quoted 58 lines · Philippe Mathieu-Daudé
The
reset()code is used in various places, refactor it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/block/pflash_cfi02.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)hw/block/pflash_cfi02.c +14
-7@@ -120,6 +120,17 @@ static void pflash_register_memory(PFlashCFI02 *pfl, int rom_mode) pfl->rom_mode = rom_mode; } +static void pflash_reset (PFlashCFI02 *pfl) +{ +trace_pflash_reset (); +timer_del (&pfl->timer); + pfl->bypass =0 ; + pfl->wcycle =0 ; + pfl->cmd =0 ; + pfl->status =0 ; +pflash_register_memory (pfl,1 ); +} +static void pflash_timer (void *opaque) {PFlashCFI02 *pfl = opaque;@@ -129,11 +140,10 @@ static void pflash_timer (void *opaque) pfl->status ^=0x80 ;if (pfl->bypass) { pfl->wcycle =2 ; + pfl->cmd =0 ; }else { -pflash_register_memory (pfl,1 ); - pfl->wcycle =0 ; +pflash_reset (pfl); } - pfl->cmd =0 ; } static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr offset,@@ -481,10 +491,7 @@ static void pflash_write(PFlashCFI02 *pfl, hwaddr offset,/* Reset flash */ reset_flash: -trace_pflash_reset (); - pfl->bypass =0 ; - pfl->wcycle =0 ; - pfl->cmd =0 ; +pflash_reset (pfl);return ; do_bypass:@@ -588,9 +595,7 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)sysbus_init_mmio (SYS_BUS_DEVICE (dev), &pfl->mem);
Quoted 14 lines
hw/block/pflash_cfi02.c static void pflash_cfi02_realize(DeviceState *dev, Error **errp) · line 601
Quoted 9 lines
hw/block/pflash_cfi02.c +1
-3timer_init_ns (&pfl->timer,QEMU_CLOCK_VIRTUAL , pflash_timer, pfl); - pfl->wcycle =0 ; - pfl->cmd =0 ; - pfl->status =0 ; +pflash_reset (pfl);/* Hardcoded CFI table (mostly from SG29 Spansion flash) */ /* Standard "QRY" string */ pfl->cfi_table[0x10 ] ='Q' ;I don't have a vested interest in the
pflash_cfi02device model, but I guess my earlier (cfi01) comments would apply -- unify first, extract second. (Or at least document why these changes are unobservable from the behavior POV.)
Ah sorry I forgot to add "Laszlo, please only review patches 1-3" in the cover :( I use git-publish that send all the patches of the series to all the list. I might start to add 'Cc:' tags in my patches.
Quoted 3 lines
Thanks
Laszlo
PATCH 5/5 hw/block/pflash_cfi02: Add the DeviceReset() handler
In reply to Philippe Mathieu-DaudéThe pflash device is a child of TYPE_DEVICE, so it can implement the DeviceReset handler. Actually it has to implement it, else on machine reset it might stay in an incoherent state, as it has been reported in the buglink listed below.
Add the DeviceReset handler and remove its call from the realize() function.
--- hw/block/pflash_cfi02.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/block/pflash_cfi02.c +6 -0
@@ -674,6 +674,11 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp) pfl->cfi_table[0x3c ] =0x00 ; } +static void pflash_cfi02_reset (DeviceState *dev) +{ +pflash_reset (PFLASH_CFI02 (dev)); +} +static Property pflash_cfi02_properties[] = {DEFINE_PROP_DRIVE ("drive" , PFlashCFI02, blk),DEFINE_PROP_UINT32 ("num-blocks" , PFlashCFI02, nb_blocs,0 ),
@@ -701,6 +706,7 @@ static void pflash_cfi02_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass); + dc->reset = pflash_cfi02_reset; dc->realize = pflash_cfi02_realize; dc->unrealize = pflash_cfi02_unrealize; dc->props = pflash_cfi02_properties;
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH 5/5] hw/block/pflash_cfi02: Add the DeviceReset() handler
Quoted 11 lines · Philippe Mathieu-Daudé
The pflash device is a child of
TYPE_DEVICE, so it can implement the DeviceReset handler. Actually it has to implement it, else on machine reset it might stay in an incoherent state, as it has been reported in the buglink listed below.Add the DeviceReset handler and remove its call from the
realize()function.Reported-by Laszlo Ersek <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 2 lines
Wei Yang Help you, Help me
Re: [Qemu-devel] [PATCH 5/5] hw/block/pflash_cfi02: Add the DeviceReset() handler
In reply to Philippe Mathieu-DaudéQuoted 10 lines · Philippe Mathieu-Daudé
The pflash device is a child of
TYPE_DEVICE, so it can implement the DeviceReset handler. Actually it has to implement it, else on machine reset it might stay in an incoherent state, as it has been reported in the buglink listed below.Add the DeviceReset handler and remove its call from the
realize()function.
- IMO, the above two tags should be dropped from the commit message, as they are specific to CFI01.
- Additionally, the commit message references the realize() function (correctly), but the patch doesn't change that function. That is, the patch doesn't remove the pflash_reset() call from pflash_cfi02_realize() that was introduced in the last patch.
Thanks
Laszlo
Quoted 30 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/block/pflash_cfi02.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/block/pflash_cfi02.c +6
-0@@ -674,6 +674,11 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp) pfl->cfi_table[0x3c ] =0x00 ; } +static void pflash_cfi02_reset (DeviceState *dev) +{ +pflash_reset (PFLASH_CFI02 (dev)); +} +static Property pflash_cfi02_properties[] = {DEFINE_PROP_DRIVE ("drive" , PFlashCFI02, blk),DEFINE_PROP_UINT32 ("num-blocks" , PFlashCFI02, nb_blocs,0 ),@@ -701,6 +706,7 @@ static void pflash_cfi02_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass); + dc->reset = pflash_cfi02_reset; dc->realize = pflash_cfi02_realize; dc->unrealize = pflash_cfi02_unrealize; dc->props = pflash_cfi02_properties;
Re: [Qemu-devel] [PATCH 5/5] hw/block/pflash_cfi02: Add the DeviceReset() handler
Quoted 6 lines · Laszlo Ersek
Quoted 5 lines · Philippe Mathieu-Daudé
The pflash device is a child of
TYPE_DEVICE, so it can implement the DeviceReset handler. Actually it has to implement it, else on machine reset it might stay in an incoherent state, as it has been reported in the buglink listed below.
Quoted 8 lines
Quoted 5 lines
Add the DeviceReset handler and remove its call from the
realize()function.- IMO, the above two tags should be dropped from the commit message, as they are specific to CFI01.
OK.
Quoted 4 lines
- Additionally, the commit message references the
realize()function (correctly), but the patch doesn't change that function. That is, the patch doesn't remove thepflash_reset()call frompflash_cfi02_realize()that was introduced in the last patch.
You found a bug, having your reviewing CFI02 is useful :) I had it correct in a staged branch, then messed while rebasing.
Thanks for noticing this,
Phil.
Quoted 35 lines
Thanks
LaszloQuoted 30 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/block/pflash_cfi02.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/block/pflash_cfi02.c +6
-0@@ -674,6 +674,11 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp) pfl->cfi_table[0x3c ] =0x00 ; } +static void pflash_cfi02_reset (DeviceState *dev) +{ +pflash_reset (PFLASH_CFI02 (dev)); +} +static Property pflash_cfi02_properties[] = {DEFINE_PROP_DRIVE ("drive" , PFlashCFI02, blk),DEFINE_PROP_UINT32 ("num-blocks" , PFlashCFI02, nb_blocs,0 ),@@ -701,6 +706,7 @@ static void pflash_cfi02_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass); + dc->reset = pflash_cfi02_reset; dc->realize = pflash_cfi02_realize; dc->unrealize = pflash_cfi02_unrealize; dc->props = pflash_cfi02_properties;