diff mbox series

[RFC,09/13] i386/fw_cfg: move hpet_cfg definition to hpet.c

Message ID 20241205060714.256270-10-zhao1.liu@intel.com (mailing list archive)
State New
Headers show
Series rust: Reinvent the wheel for HPET timer in Rust | expand

Commit Message

Zhao Liu Dec. 5, 2024, 6:07 a.m. UTC
HPET device needs to access and update hpet_cfg variable, but now it is
defined in hw/i386/fw_cfg.c and Rust code can't access it.

Move hpet_cfg definition to hpet.c (and rename it to hpet_fw_cfg). This
allows Rust HPET device implements its own global hpet_fw_cfg variable,
and will further reduce the use of unsafe C code access and calls in the
Rust HPET implementation.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 hw/i386/fw_cfg.c        |  4 +---
 hw/timer/hpet.c         | 16 +++++++++-------
 include/hw/timer/hpet.h |  2 +-
 3 files changed, 11 insertions(+), 11 deletions(-)

Comments

Philippe Mathieu-Daudé Dec. 5, 2024, 12:04 p.m. UTC | #1
On 5/12/24 07:07, Zhao Liu wrote:
> HPET device needs to access and update hpet_cfg variable, but now it is
> defined in hw/i386/fw_cfg.c and Rust code can't access it.
> 
> Move hpet_cfg definition to hpet.c (and rename it to hpet_fw_cfg). This
> allows Rust HPET device implements its own global hpet_fw_cfg variable,
> and will further reduce the use of unsafe C code access and calls in the
> Rust HPET implementation.
> 
> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> ---
>   hw/i386/fw_cfg.c        |  4 +---
>   hw/timer/hpet.c         | 16 +++++++++-------
>   include/hw/timer/hpet.h |  2 +-
>   3 files changed, 11 insertions(+), 11 deletions(-)


> diff --git a/include/hw/timer/hpet.h b/include/hw/timer/hpet.h
> index d17a8d43199e..dbf709251a8f 100644
> --- a/include/hw/timer/hpet.h
> +++ b/include/hw/timer/hpet.h
> @@ -74,7 +74,7 @@ struct hpet_fw_config
>       struct hpet_fw_entry hpet[8];
>   } QEMU_PACKED;
>   
> -extern struct hpet_fw_config hpet_cfg;
> +extern struct hpet_fw_config hpet_fw_cfg;

Could this field belong to the (yet unexisting) HPETClass?

>   
>   #define TYPE_HPET "hpet"
>
Zhao Liu Dec. 5, 2024, 12:46 p.m. UTC | #2
Hi Philippe,

On Thu, Dec 05, 2024 at 01:04:58PM +0100, Philippe Mathieu-Daudé wrote:
> Date: Thu, 5 Dec 2024 13:04:58 +0100
> From: Philippe Mathieu-Daudé <philmd@linaro.org>
> Subject: Re: [RFC 09/13] i386/fw_cfg: move hpet_cfg definition to hpet.c
> 
> On 5/12/24 07:07, Zhao Liu wrote:
> > HPET device needs to access and update hpet_cfg variable, but now it is
> > defined in hw/i386/fw_cfg.c and Rust code can't access it.
> > 
> > Move hpet_cfg definition to hpet.c (and rename it to hpet_fw_cfg). This
> > allows Rust HPET device implements its own global hpet_fw_cfg variable,
> > and will further reduce the use of unsafe C code access and calls in the
> > Rust HPET implementation.
> > 
> > Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> > ---
> >   hw/i386/fw_cfg.c        |  4 +---
> >   hw/timer/hpet.c         | 16 +++++++++-------
> >   include/hw/timer/hpet.h |  2 +-
> >   3 files changed, 11 insertions(+), 11 deletions(-)
> 
> 
> > diff --git a/include/hw/timer/hpet.h b/include/hw/timer/hpet.h
> > index d17a8d43199e..dbf709251a8f 100644
> > --- a/include/hw/timer/hpet.h
> > +++ b/include/hw/timer/hpet.h
> > @@ -74,7 +74,7 @@ struct hpet_fw_config
> >       struct hpet_fw_entry hpet[8];
> >   } QEMU_PACKED;
> > -extern struct hpet_fw_config hpet_cfg;
> > +extern struct hpet_fw_config hpet_fw_cfg;
> 
> Could this field belong to the (yet unexisting) HPETClass?

Several instances would share the same class, so HPETClass could manage
multiple HPETState info.

But in fw_cfg.c, do you have idea about how to get the HPETClass?

Regards,
Zhao
Paolo Bonzini Dec. 5, 2024, 3:30 p.m. UTC | #3
On 12/5/24 07:07, Zhao Liu wrote:
> HPET device needs to access and update hpet_cfg variable, but now it is
> defined in hw/i386/fw_cfg.c and Rust code can't access it.
> 
> Move hpet_cfg definition to hpet.c (and rename it to hpet_fw_cfg). This
> allows Rust HPET device implements its own global hpet_fw_cfg variable,
> and will further reduce the use of unsafe C code access and calls in the
> Rust HPET implementation.
> 
> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> ---
>   hw/i386/fw_cfg.c        |  4 +---
>   hw/timer/hpet.c         | 16 +++++++++-------
>   include/hw/timer/hpet.h |  2 +-
>   3 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/i386/fw_cfg.c b/hw/i386/fw_cfg.c
> index 0e4494627c21..965e6306838a 100644
> --- a/hw/i386/fw_cfg.c
> +++ b/hw/i386/fw_cfg.c
> @@ -26,8 +26,6 @@
>   #include CONFIG_DEVICES
>   #include "target/i386/cpu.h"
>   
> -struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX};

This breaks if you disable HPET, which is why fw_cfg.c defines it.

You can do something like

diff --git a/include/hw/timer/hpet-fw-cfg.h b/include/hw/timer/hpet-fw-cfg.h
new file mode 100644
index 00000000000..234a49fc92e
--- /dev/null
+++ b/include/hw/timer/hpet-fw-cfg.h
@@ -0,0 +1,16 @@
+struct hpet_fw_entry
+{
+    uint32_t event_timer_block_id;
+    uint64_t address;
+    uint16_t min_tick;
+    uint8_t page_prot;
+} QEMU_PACKED;
+
+struct hpet_fw_config
+{
+    uint8_t count;
+    struct hpet_fw_entry hpet[8];
+} QEMU_PACKED;
+
+extern struct hpet_fw_config hpet_fw_cfg;
+
diff --git a/include/hw/timer/hpet.h b/include/hw/timer/hpet.h
index d17a8d43199..6f7fcbc3c60 100644
--- a/include/hw/timer/hpet.h
+++ b/include/hw/timer/hpet.h
@@ -60,26 +60,12 @@
  #define HPET_TN_INT_ROUTE_CAP_SHIFT 32
  #define HPET_TN_CFG_BITS_READONLY_OR_RESERVED 0xffff80b1U
  
-struct hpet_fw_entry
-{
-    uint32_t event_timer_block_id;
-    uint64_t address;
-    uint16_t min_tick;
-    uint8_t page_prot;
-} QEMU_PACKED;
-
-struct hpet_fw_config
-{
-    uint8_t count;
-    struct hpet_fw_entry hpet[8];
-} QEMU_PACKED;
-
-extern struct hpet_fw_config hpet_cfg;
-
  #define TYPE_HPET "hpet"
  
  #define HPET_INTCAP "hpet-intcap"
  
+#include "hw/timer/hpet-fw-cfg.h"
+
  static inline bool hpet_find(void)
  {
      return object_resolve_path_type("", TYPE_HPET, NULL);
diff --git a/rust/wrapper.h b/rust/wrapper.h
index 285d0eb6ad0..82381e43472 100644
--- a/rust/wrapper.h
+++ b/rust/wrapper.h
@@ -62,3 +62,4 @@ typedef enum memory_order {
  #include "qapi/error.h"
  #include "migration/vmstate.h"
  #include "chardev/char-serial.h"
+#include "hw/timer/hpet-fw-cfg.h"


but you will have to use unsafe to access it since it's a "static mut".

Paolo
Philippe Mathieu-Daudé Dec. 5, 2024, 9:17 p.m. UTC | #4
On 5/12/24 13:46, Zhao Liu wrote:
> Hi Philippe,
> 
> On Thu, Dec 05, 2024 at 01:04:58PM +0100, Philippe Mathieu-Daudé wrote:
>> Date: Thu, 5 Dec 2024 13:04:58 +0100
>> From: Philippe Mathieu-Daudé <philmd@linaro.org>
>> Subject: Re: [RFC 09/13] i386/fw_cfg: move hpet_cfg definition to hpet.c
>>
>> On 5/12/24 07:07, Zhao Liu wrote:
>>> HPET device needs to access and update hpet_cfg variable, but now it is
>>> defined in hw/i386/fw_cfg.c and Rust code can't access it.
>>>
>>> Move hpet_cfg definition to hpet.c (and rename it to hpet_fw_cfg). This
>>> allows Rust HPET device implements its own global hpet_fw_cfg variable,
>>> and will further reduce the use of unsafe C code access and calls in the
>>> Rust HPET implementation.
>>>
>>> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
>>> ---
>>>    hw/i386/fw_cfg.c        |  4 +---
>>>    hw/timer/hpet.c         | 16 +++++++++-------
>>>    include/hw/timer/hpet.h |  2 +-
>>>    3 files changed, 11 insertions(+), 11 deletions(-)
>>
>>
>>> diff --git a/include/hw/timer/hpet.h b/include/hw/timer/hpet.h
>>> index d17a8d43199e..dbf709251a8f 100644
>>> --- a/include/hw/timer/hpet.h
>>> +++ b/include/hw/timer/hpet.h
>>> @@ -74,7 +74,7 @@ struct hpet_fw_config
>>>        struct hpet_fw_entry hpet[8];
>>>    } QEMU_PACKED;
>>> -extern struct hpet_fw_config hpet_cfg;
>>> +extern struct hpet_fw_config hpet_fw_cfg;
>>
>> Could this field belong to the (yet unexisting) HPETClass?
> 
> Several instances would share the same class, so HPETClass could manage
> multiple HPETState info.
> 
> But in fw_cfg.c, do you have idea about how to get the HPETClass?

Have hpet_find() return an Object and call object_get_class()?

> Regards,
> Zhao
>
Paolo Bonzini Dec. 5, 2024, 9:19 p.m. UTC | #5
On Thu, Dec 5, 2024 at 10:18 PM Philippe Mathieu-Daudé
<philmd@linaro.org> wrote:
>
> On 5/12/24 13:46, Zhao Liu wrote:
> > Hi Philippe,
> >
> > On Thu, Dec 05, 2024 at 01:04:58PM +0100, Philippe Mathieu-Daudé wrote:
> >> Date: Thu, 5 Dec 2024 13:04:58 +0100
> >> From: Philippe Mathieu-Daudé <philmd@linaro.org>
> >> Subject: Re: [RFC 09/13] i386/fw_cfg: move hpet_cfg definition to hpet.c
> >>
> >> On 5/12/24 07:07, Zhao Liu wrote:
> >>> HPET device needs to access and update hpet_cfg variable, but now it is
> >>> defined in hw/i386/fw_cfg.c and Rust code can't access it.
> >>>
> >>> Move hpet_cfg definition to hpet.c (and rename it to hpet_fw_cfg). This
> >>> allows Rust HPET device implements its own global hpet_fw_cfg variable,
> >>> and will further reduce the use of unsafe C code access and calls in the
> >>> Rust HPET implementation.
> >>>
> >>> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> >>> ---
> >>>    hw/i386/fw_cfg.c        |  4 +---
> >>>    hw/timer/hpet.c         | 16 +++++++++-------
> >>>    include/hw/timer/hpet.h |  2 +-
> >>>    3 files changed, 11 insertions(+), 11 deletions(-)
> >>
> >>
> >>> diff --git a/include/hw/timer/hpet.h b/include/hw/timer/hpet.h
> >>> index d17a8d43199e..dbf709251a8f 100644
> >>> --- a/include/hw/timer/hpet.h
> >>> +++ b/include/hw/timer/hpet.h
> >>> @@ -74,7 +74,7 @@ struct hpet_fw_config
> >>>        struct hpet_fw_entry hpet[8];
> >>>    } QEMU_PACKED;
> >>> -extern struct hpet_fw_config hpet_cfg;
> >>> +extern struct hpet_fw_config hpet_fw_cfg;
> >>
> >> Could this field belong to the (yet unexisting) HPETClass?
> >
> > Several instances would share the same class, so HPETClass could manage
> > multiple HPETState info.
> >
> > But in fw_cfg.c, do you have idea about how to get the HPETClass?
>
> Have hpet_find() return an Object and call object_get_class()?

That would work, but anyhow this patch breaks compilation without HPET
so the question is a bit moot. :)

Paolo
Philippe Mathieu-Daudé Dec. 7, 2024, 9:16 a.m. UTC | #6
On 5/12/24 22:19, Paolo Bonzini wrote:
> On Thu, Dec 5, 2024 at 10:18 PM Philippe Mathieu-Daudé
> <philmd@linaro.org> wrote:
>>
>> On 5/12/24 13:46, Zhao Liu wrote:
>>> Hi Philippe,
>>>
>>> On Thu, Dec 05, 2024 at 01:04:58PM +0100, Philippe Mathieu-Daudé wrote:
>>>> Date: Thu, 5 Dec 2024 13:04:58 +0100
>>>> From: Philippe Mathieu-Daudé <philmd@linaro.org>
>>>> Subject: Re: [RFC 09/13] i386/fw_cfg: move hpet_cfg definition to hpet.c
>>>>
>>>> On 5/12/24 07:07, Zhao Liu wrote:
>>>>> HPET device needs to access and update hpet_cfg variable, but now it is
>>>>> defined in hw/i386/fw_cfg.c and Rust code can't access it.
>>>>>
>>>>> Move hpet_cfg definition to hpet.c (and rename it to hpet_fw_cfg). This
>>>>> allows Rust HPET device implements its own global hpet_fw_cfg variable,
>>>>> and will further reduce the use of unsafe C code access and calls in the
>>>>> Rust HPET implementation.
>>>>>
>>>>> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
>>>>> ---
>>>>>     hw/i386/fw_cfg.c        |  4 +---
>>>>>     hw/timer/hpet.c         | 16 +++++++++-------
>>>>>     include/hw/timer/hpet.h |  2 +-
>>>>>     3 files changed, 11 insertions(+), 11 deletions(-)
>>>>
>>>>
>>>>> diff --git a/include/hw/timer/hpet.h b/include/hw/timer/hpet.h
>>>>> index d17a8d43199e..dbf709251a8f 100644
>>>>> --- a/include/hw/timer/hpet.h
>>>>> +++ b/include/hw/timer/hpet.h
>>>>> @@ -74,7 +74,7 @@ struct hpet_fw_config
>>>>>         struct hpet_fw_entry hpet[8];
>>>>>     } QEMU_PACKED;
>>>>> -extern struct hpet_fw_config hpet_cfg;
>>>>> +extern struct hpet_fw_config hpet_fw_cfg;
>>>>
>>>> Could this field belong to the (yet unexisting) HPETClass?
>>>
>>> Several instances would share the same class, so HPETClass could manage
>>> multiple HPETState info.
>>>
>>> But in fw_cfg.c, do you have idea about how to get the HPETClass?
>>
>> Have hpet_find() return an Object and call object_get_class()?

Implemented as 
https://lore.kernel.org/qemu-devel/20241206191124.9195-1-philmd@linaro.org/, 
hoping it simplifies the Rust model integration.

> 
> That would work, but anyhow this patch breaks compilation without HPET
> so the question is a bit moot. :)
> 
> Paolo
>
Zhao Liu Dec. 7, 2024, 3:28 p.m. UTC | #7
Hi Paolo,

Sorry for late reply,

On Thu, Dec 05, 2024 at 04:30:15PM +0100, Paolo Bonzini wrote:
> Date: Thu, 5 Dec 2024 16:30:15 +0100
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: Re: [RFC 09/13] i386/fw_cfg: move hpet_cfg definition to hpet.c
> 
> On 12/5/24 07:07, Zhao Liu wrote:
> > HPET device needs to access and update hpet_cfg variable, but now it is
> > defined in hw/i386/fw_cfg.c and Rust code can't access it.
> > 
> > Move hpet_cfg definition to hpet.c (and rename it to hpet_fw_cfg). This
> > allows Rust HPET device implements its own global hpet_fw_cfg variable,
> > and will further reduce the use of unsafe C code access and calls in the
> > Rust HPET implementation.
> > 
> > Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> > ---
> >   hw/i386/fw_cfg.c        |  4 +---
> >   hw/timer/hpet.c         | 16 +++++++++-------
> >   include/hw/timer/hpet.h |  2 +-
> >   3 files changed, 11 insertions(+), 11 deletions(-)
> > 
> > diff --git a/hw/i386/fw_cfg.c b/hw/i386/fw_cfg.c
> > index 0e4494627c21..965e6306838a 100644
> > --- a/hw/i386/fw_cfg.c
> > +++ b/hw/i386/fw_cfg.c
> > @@ -26,8 +26,6 @@
> >   #include CONFIG_DEVICES
> >   #include "target/i386/cpu.h"
> > -struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX};
> 
> This breaks if you disable HPET, which is why fw_cfg.c defines it.

Thanks! I did miss this case.

> You can do something like
> 
> diff --git a/include/hw/timer/hpet-fw-cfg.h b/include/hw/timer/hpet-fw-cfg.h
> new file mode 100644
> index 00000000000..234a49fc92e
> --- /dev/null
> +++ b/include/hw/timer/hpet-fw-cfg.h
> @@ -0,0 +1,16 @@
> +struct hpet_fw_entry
> +{
> +    uint32_t event_timer_block_id;
> +    uint64_t address;
> +    uint16_t min_tick;
> +    uint8_t page_prot;
> +} QEMU_PACKED;
> +
> +struct hpet_fw_config
> +{
> +    uint8_t count;
> +    struct hpet_fw_entry hpet[8];
> +} QEMU_PACKED;
> +
> +extern struct hpet_fw_config hpet_fw_cfg;
> +
> diff --git a/include/hw/timer/hpet.h b/include/hw/timer/hpet.h
> index d17a8d43199..6f7fcbc3c60 100644
> --- a/include/hw/timer/hpet.h
> +++ b/include/hw/timer/hpet.h
> @@ -60,26 +60,12 @@
>  #define HPET_TN_INT_ROUTE_CAP_SHIFT 32
>  #define HPET_TN_CFG_BITS_READONLY_OR_RESERVED 0xffff80b1U
> -struct hpet_fw_entry
> -{
> -    uint32_t event_timer_block_id;
> -    uint64_t address;
> -    uint16_t min_tick;
> -    uint8_t page_prot;
> -} QEMU_PACKED;
> -
> -struct hpet_fw_config
> -{
> -    uint8_t count;
> -    struct hpet_fw_entry hpet[8];
> -} QEMU_PACKED;
> -
> -extern struct hpet_fw_config hpet_cfg;
> -
>  #define TYPE_HPET "hpet"
>  #define HPET_INTCAP "hpet-intcap"
> +#include "hw/timer/hpet-fw-cfg.h"
> +
>  static inline bool hpet_find(void)
>  {
>      return object_resolve_path_type("", TYPE_HPET, NULL);
> diff --git a/rust/wrapper.h b/rust/wrapper.h
> index 285d0eb6ad0..82381e43472 100644
> --- a/rust/wrapper.h
> +++ b/rust/wrapper.h
> @@ -62,3 +62,4 @@ typedef enum memory_order {
>  #include "qapi/error.h"
>  #include "migration/vmstate.h"
>  #include "chardev/char-serial.h"
> +#include "hw/timer/hpet-fw-cfg.h"
> 

Thank you very much for this example!

> but you will have to use unsafe to access it since it's a "static mut".

I also noticed Philippe's version. And I prefer Phillippe's version,
although his version requires more changes to the rust version, it
provides an opportunity to add more field to the QOM class, so I feel
it's good to check current rust qom class support.

Regrads,
Zhao
Zhao Liu Dec. 7, 2024, 3:36 p.m. UTC | #8
On Sat, Dec 07, 2024 at 10:16:03AM +0100, Philippe Mathieu-Daudé wrote:
> Date: Sat, 7 Dec 2024 10:16:03 +0100
> From: Philippe Mathieu-Daudé <philmd@linaro.org>
> Subject: Re: [RFC 09/13] i386/fw_cfg: move hpet_cfg definition to hpet.c
> 
> On 5/12/24 22:19, Paolo Bonzini wrote:
> > On Thu, Dec 5, 2024 at 10:18 PM Philippe Mathieu-Daudé
> > <philmd@linaro.org> wrote:
> > > 
> > > On 5/12/24 13:46, Zhao Liu wrote:
> > > > Hi Philippe,
> > > > 
> > > > On Thu, Dec 05, 2024 at 01:04:58PM +0100, Philippe Mathieu-Daudé wrote:
> > > > > Date: Thu, 5 Dec 2024 13:04:58 +0100
> > > > > From: Philippe Mathieu-Daudé <philmd@linaro.org>
> > > > > Subject: Re: [RFC 09/13] i386/fw_cfg: move hpet_cfg definition to hpet.c
> > > > > 
> > > > > On 5/12/24 07:07, Zhao Liu wrote:
> > > > > > HPET device needs to access and update hpet_cfg variable, but now it is
> > > > > > defined in hw/i386/fw_cfg.c and Rust code can't access it.
> > > > > > 
> > > > > > Move hpet_cfg definition to hpet.c (and rename it to hpet_fw_cfg). This
> > > > > > allows Rust HPET device implements its own global hpet_fw_cfg variable,
> > > > > > and will further reduce the use of unsafe C code access and calls in the
> > > > > > Rust HPET implementation.
> > > > > > 
> > > > > > Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> > > > > > ---
> > > > > >     hw/i386/fw_cfg.c        |  4 +---
> > > > > >     hw/timer/hpet.c         | 16 +++++++++-------
> > > > > >     include/hw/timer/hpet.h |  2 +-
> > > > > >     3 files changed, 11 insertions(+), 11 deletions(-)
> > > > > 
> > > > > 
> > > > > > diff --git a/include/hw/timer/hpet.h b/include/hw/timer/hpet.h
> > > > > > index d17a8d43199e..dbf709251a8f 100644
> > > > > > --- a/include/hw/timer/hpet.h
> > > > > > +++ b/include/hw/timer/hpet.h
> > > > > > @@ -74,7 +74,7 @@ struct hpet_fw_config
> > > > > >         struct hpet_fw_entry hpet[8];
> > > > > >     } QEMU_PACKED;
> > > > > > -extern struct hpet_fw_config hpet_cfg;
> > > > > > +extern struct hpet_fw_config hpet_fw_cfg;
> > > > > 
> > > > > Could this field belong to the (yet unexisting) HPETClass?
> > > > 
> > > > Several instances would share the same class, so HPETClass could manage
> > > > multiple HPETState info.
> > > > 
> > > > But in fw_cfg.c, do you have idea about how to get the HPETClass?
> > > 
> > > Have hpet_find() return an Object and call object_get_class()?
> 
> Implemented as
> https://lore.kernel.org/qemu-devel/20241206191124.9195-1-philmd@linaro.org/,
> hoping it simplifies the Rust model integration.
> 

Hi Philli, thank you very much!

This approach is very helpful for more “rich” QOM class attempts, and if
Paolo feels the same way, I'll move to your approach for the next
version!

Regards,
Zhao
diff mbox series

Patch

diff --git a/hw/i386/fw_cfg.c b/hw/i386/fw_cfg.c
index 0e4494627c21..965e6306838a 100644
--- a/hw/i386/fw_cfg.c
+++ b/hw/i386/fw_cfg.c
@@ -26,8 +26,6 @@ 
 #include CONFIG_DEVICES
 #include "target/i386/cpu.h"
 
-struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX};
-
 const char *fw_cfg_arch_key_name(uint16_t key)
 {
     static const struct {
@@ -149,7 +147,7 @@  FWCfgState *fw_cfg_arch_create(MachineState *ms,
 #endif
     fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, 1);
 
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_HPET, &hpet_cfg, sizeof(hpet_cfg));
+    fw_cfg_add_bytes(fw_cfg, FW_CFG_HPET, &hpet_fw_cfg, sizeof(hpet_fw_cfg));
     /* allocate memory for the NUMA channel: one (64bit) word for the number
      * of nodes, one word for each VCPU->node and one word for each node to
      * hold the amount of memory.
diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index 5399f1b2a3f7..d8bd51b7e202 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -40,6 +40,8 @@ 
 #include "qom/object.h"
 #include "trace.h"
 
+struct hpet_fw_config hpet_fw_cfg = {.count = UINT8_MAX};
+
 #define HPET_MSI_SUPPORT        0
 
 OBJECT_DECLARE_SIMPLE_TYPE(HPETState, HPET)
@@ -278,7 +280,7 @@  static int hpet_post_load(void *opaque, int version_id)
     /* Push number of timers into capability returned via HPET_ID */
     s->capability &= ~HPET_ID_NUM_TIM_MASK;
     s->capability |= (s->num_timers - 1) << HPET_ID_NUM_TIM_SHIFT;
-    hpet_cfg.hpet[s->hpet_id].event_timer_block_id = (uint32_t)s->capability;
+    hpet_fw_cfg.hpet[s->hpet_id].event_timer_block_id = (uint32_t)s->capability;
 
     /* Derive HPET_MSI_SUPPORT from the capability of the first timer. */
     s->flags &= ~(1 << HPET_MSI_SUPPORT);
@@ -665,8 +667,8 @@  static void hpet_reset(DeviceState *d)
     s->hpet_counter = 0ULL;
     s->hpet_offset = 0ULL;
     s->config = 0ULL;
-    hpet_cfg.hpet[s->hpet_id].event_timer_block_id = (uint32_t)s->capability;
-    hpet_cfg.hpet[s->hpet_id].address = sbd->mmio[0].addr;
+    hpet_fw_cfg.hpet[s->hpet_id].event_timer_block_id = (uint32_t)s->capability;
+    hpet_fw_cfg.hpet[s->hpet_id].address = sbd->mmio[0].addr;
 
     /* to document that the RTC lowers its output on reset as well */
     s->rtc_irq_level = 0;
@@ -708,17 +710,17 @@  static void hpet_realize(DeviceState *dev, Error **errp)
     if (!s->intcap) {
         warn_report("Hpet's intcap not initialized");
     }
-    if (hpet_cfg.count == UINT8_MAX) {
+    if (hpet_fw_cfg.count == UINT8_MAX) {
         /* first instance */
-        hpet_cfg.count = 0;
+        hpet_fw_cfg.count = 0;
     }
 
-    if (hpet_cfg.count == 8) {
+    if (hpet_fw_cfg.count == 8) {
         error_setg(errp, "Only 8 instances of HPET is allowed");
         return;
     }
 
-    s->hpet_id = hpet_cfg.count++;
+    s->hpet_id = hpet_fw_cfg.count++;
 
     for (i = 0; i < HPET_NUM_IRQ_ROUTES; i++) {
         sysbus_init_irq(sbd, &s->irqs[i]);
diff --git a/include/hw/timer/hpet.h b/include/hw/timer/hpet.h
index d17a8d43199e..dbf709251a8f 100644
--- a/include/hw/timer/hpet.h
+++ b/include/hw/timer/hpet.h
@@ -74,7 +74,7 @@  struct hpet_fw_config
     struct hpet_fw_entry hpet[8];
 } QEMU_PACKED;
 
-extern struct hpet_fw_config hpet_cfg;
+extern struct hpet_fw_config hpet_fw_cfg;
 
 #define TYPE_HPET "hpet"