[RFC PATCH-for-6.2?] hw/misc/sifive_u_otp: Do not reset OTP content on hardware reset

Philippe Mathieu-Daudé posted 1 patch 2 years, 5 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20211119104757.331579-1-f4bug@amsat.org
hw/misc/sifive_u_otp.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
[RFC PATCH-for-6.2?] hw/misc/sifive_u_otp: Do not reset OTP content on hardware reset
Posted by Philippe Mathieu-Daudé 2 years, 5 months ago
Once a "One Time Programmable" is programmed, it shouldn't be reset.

Do not re-initialize the OTP content in the DeviceReset handler,
initialize it once in the DeviceRealize one.

Fixes: 9fb45c62ae8 ("riscv: sifive: Implement a model for SiFive FU540 OTP")
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/misc/sifive_u_otp.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
index 18aa0bd55d8..b5adcfa7cb4 100644
--- a/hw/misc/sifive_u_otp.c
+++ b/hw/misc/sifive_u_otp.c
@@ -235,14 +235,10 @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp)
 
             if (blk_pread(s->blk, 0, s->fuse, filesize) != filesize) {
                 error_setg(errp, "failed to read the initial flash content");
+                return;
             }
         }
     }
-}
-
-static void sifive_u_otp_reset(DeviceState *dev)
-{
-    SiFiveUOTPState *s = SIFIVE_U_OTP(dev);
 
     /* Initialize all fuses' initial value to 0xFFs */
     memset(s->fuse, 0xff, sizeof(s->fuse));
@@ -259,13 +255,15 @@ static void sifive_u_otp_reset(DeviceState *dev)
         serial_data = s->serial;
         if (blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD,
                        &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
-            error_report("write error index<%d>", index);
+            error_setg(errp, "failed to write index<%d>", index);
+            return;
         }
 
         serial_data = ~(s->serial);
         if (blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD,
                        &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
-            error_report("write error index<%d>", index + 1);
+            error_setg(errp, "failed to write index<%d>", index + 1);
+            return;
         }
     }
 
@@ -279,7 +277,6 @@ static void sifive_u_otp_class_init(ObjectClass *klass, void *data)
 
     device_class_set_props(dc, sifive_u_otp_properties);
     dc->realize = sifive_u_otp_realize;
-    dc->reset = sifive_u_otp_reset;
 }
 
 static const TypeInfo sifive_u_otp_info = {
-- 
2.31.1

Re: [RFC PATCH-for-6.2?] hw/misc/sifive_u_otp: Do not reset OTP content on hardware reset
Posted by Alistair Francis 2 years, 5 months ago
On Fri, Nov 19, 2021 at 8:48 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> Once a "One Time Programmable" is programmed, it shouldn't be reset.
>
> Do not re-initialize the OTP content in the DeviceReset handler,
> initialize it once in the DeviceRealize one.
>
> Fixes: 9fb45c62ae8 ("riscv: sifive: Implement a model for SiFive FU540 OTP")
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
>  hw/misc/sifive_u_otp.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
> index 18aa0bd55d8..b5adcfa7cb4 100644
> --- a/hw/misc/sifive_u_otp.c
> +++ b/hw/misc/sifive_u_otp.c
> @@ -235,14 +235,10 @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp)
>
>              if (blk_pread(s->blk, 0, s->fuse, filesize) != filesize) {
>                  error_setg(errp, "failed to read the initial flash content");
> +                return;
>              }
>          }
>      }
> -}
> -
> -static void sifive_u_otp_reset(DeviceState *dev)
> -{
> -    SiFiveUOTPState *s = SIFIVE_U_OTP(dev);
>
>      /* Initialize all fuses' initial value to 0xFFs */
>      memset(s->fuse, 0xff, sizeof(s->fuse));
> @@ -259,13 +255,15 @@ static void sifive_u_otp_reset(DeviceState *dev)
>          serial_data = s->serial;
>          if (blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD,
>                         &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
> -            error_report("write error index<%d>", index);
> +            error_setg(errp, "failed to write index<%d>", index);
> +            return;
>          }
>
>          serial_data = ~(s->serial);
>          if (blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD,
>                         &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
> -            error_report("write error index<%d>", index + 1);
> +            error_setg(errp, "failed to write index<%d>", index + 1);
> +            return;
>          }
>      }
>
> @@ -279,7 +277,6 @@ static void sifive_u_otp_class_init(ObjectClass *klass, void *data)
>
>      device_class_set_props(dc, sifive_u_otp_properties);
>      dc->realize = sifive_u_otp_realize;
> -    dc->reset = sifive_u_otp_reset;
>  }
>
>  static const TypeInfo sifive_u_otp_info = {
> --
> 2.31.1
>
>

Re: [RFC PATCH-for-6.2?] hw/misc/sifive_u_otp: Do not reset OTP content on hardware reset
Posted by Alistair Francis 2 years, 5 months ago
On Fri, Nov 19, 2021 at 8:48 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> Once a "One Time Programmable" is programmed, it shouldn't be reset.
>
> Do not re-initialize the OTP content in the DeviceReset handler,
> initialize it once in the DeviceRealize one.
>
> Fixes: 9fb45c62ae8 ("riscv: sifive: Implement a model for SiFive FU540 OTP")
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  hw/misc/sifive_u_otp.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
> index 18aa0bd55d8..b5adcfa7cb4 100644
> --- a/hw/misc/sifive_u_otp.c
> +++ b/hw/misc/sifive_u_otp.c
> @@ -235,14 +235,10 @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp)
>
>              if (blk_pread(s->blk, 0, s->fuse, filesize) != filesize) {
>                  error_setg(errp, "failed to read the initial flash content");
> +                return;
>              }
>          }
>      }
> -}
> -
> -static void sifive_u_otp_reset(DeviceState *dev)
> -{
> -    SiFiveUOTPState *s = SIFIVE_U_OTP(dev);
>
>      /* Initialize all fuses' initial value to 0xFFs */
>      memset(s->fuse, 0xff, sizeof(s->fuse));
> @@ -259,13 +255,15 @@ static void sifive_u_otp_reset(DeviceState *dev)
>          serial_data = s->serial;
>          if (blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD,
>                         &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
> -            error_report("write error index<%d>", index);
> +            error_setg(errp, "failed to write index<%d>", index);
> +            return;
>          }
>
>          serial_data = ~(s->serial);
>          if (blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD,
>                         &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
> -            error_report("write error index<%d>", index + 1);
> +            error_setg(errp, "failed to write index<%d>", index + 1);
> +            return;
>          }
>      }
>
> @@ -279,7 +277,6 @@ static void sifive_u_otp_class_init(ObjectClass *klass, void *data)
>
>      device_class_set_props(dc, sifive_u_otp_properties);
>      dc->realize = sifive_u_otp_realize;
> -    dc->reset = sifive_u_otp_reset;
>  }
>
>  static const TypeInfo sifive_u_otp_info = {
> --
> 2.31.1
>
>