qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Questions about clocks emulation
@ 2023-12-12 13:05 Arnaud Minier
  2023-12-13 19:13 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 3+ messages in thread
From: Arnaud Minier @ 2023-12-12 13:05 UTC (permalink / raw)
  To: qemu-devel

Hi all,

I tried to implement the RCC (Reset and Clock Control) for the STM32L4x5_SoC but ran into some problems regarding clock emulation in Qemu.
In this SoC, it is possible to change the source of several clocks used for devices like the CPU, the USART, and approximately every other device on the SoC.
This change can be made at runtime by writing into a specific register.
I tried to model this by using the clocks in hw/core/clock.c by I noticed that it is not possible to change a clock's source once it has been assigned (see clock_set_source()).
It prevents me from implementing a clock tree similar to the one on the hardware.

Is this limitation there for some reason or has it simply not been implemented?

Thanks,
Arnaud Minier


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Questions about clocks emulation
  2023-12-12 13:05 Questions about clocks emulation Arnaud Minier
@ 2023-12-13 19:13 ` Philippe Mathieu-Daudé
  2023-12-14  7:45   ` Luc Michel
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-12-13 19:13 UTC (permalink / raw)
  To: Arnaud Minier, qemu-devel; +Cc: Peter Maydell, Luc Michel

Hi Arnaud,

(Cc'ing Peter and Luc)

On 12/12/23 14:05, Arnaud Minier wrote:
> Hi all,
> 
> I tried to implement the RCC (Reset and Clock Control) for the STM32L4x5_SoC but ran into some problems regarding clock emulation in Qemu.
> In this SoC, it is possible to change the source of several clocks used for devices like the CPU, the USART, and approximately every other device on the SoC.
> This change can be made at runtime by writing into a specific register.
> I tried to model this by using the clocks in hw/core/clock.c by I noticed that it is not possible to change a clock's source once it has been assigned (see clock_set_source()).

Ouch.

I thought this was what connect_mux_sources() what doing (see
hw/misc/bcm2835_cprman.c) but it is only called (along the
clock_set_source() calls) from the realize() handler.

> It prevents me from implementing a clock tree similar to the one on the hardware.
> 
> Is this limitation there for some reason or has it simply not been implemented?

There is a /* changing clock source is not supported */ comment in
clock_set_source(), so likely not implemented :)

IIUC the only issue is how to update the src->children qlist.

> Thanks,
> Arnaud Minier
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Questions about clocks emulation
  2023-12-13 19:13 ` Philippe Mathieu-Daudé
@ 2023-12-14  7:45   ` Luc Michel
  0 siblings, 0 replies; 3+ messages in thread
From: Luc Michel @ 2023-12-14  7:45 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: Arnaud Minier, qemu-devel, Peter Maydell

Hi,

On 20:13 Wed 13 Dec     , Philippe Mathieu-Daudé wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
> 
> 
> Hi Arnaud,
> 
> (Cc'ing Peter and Luc)
> 
> On 12/12/23 14:05, Arnaud Minier wrote:
> > Hi all,
> > 
> > I tried to implement the RCC (Reset and Clock Control) for the STM32L4x5_SoC but ran into some problems regarding clock emulation in Qemu.
> > In this SoC, it is possible to change the source of several clocks used for devices like the CPU, the USART, and approximately every other device on the SoC.
> > This change can be made at runtime by writing into a specific register.
> > I tried to model this by using the clocks in hw/core/clock.c by I noticed that it is not possible to change a clock's source once it has been assigned (see clock_set_source()).
> 
> Ouch.
> 
> I thought this was what connect_mux_sources() what doing (see
> hw/misc/bcm2835_cprman.c) but it is only called (along the
> clock_set_source() calls) from the realize() handler.

From a clock user API standpoint, we made the choice to hardwire the
clock tree, as it is in fact hardwired in the chip you are trying to
model (physical connections insides the chip do not "change" when you
write to a register). Things are usually implemented using muxes, clock
dividers and such between PLLs and devices. This is the approach you
should adopt when implementing your clock tree. As Philippe mentioned
you can have a look at hw/misc/bcm2835_cprman.c which is a real world
example of a clock tree implementation (in the Raspberry PI SoC).

> 
> > It prevents me from implementing a clock tree similar to the one on the hardware.
> > 
> > Is this limitation there for some reason or has it simply not been implemented?
> 
> There is a /* changing clock source is not supported */ comment in
> clock_set_source(), so likely not implemented :)
> 
> IIUC the only issue is how to update the src->children qlist.

IIRC from a clock API implementation standpoint, there were some serious
questions about dynamic reconfiguration of the clock tree. But I can't
remember the details (maybe some issues about migration?). But again,
the API in its current form should be enough to catch your need. If you
have a specific pattern you think is not expressible with the current
API, please expose it precisely so we can see how to fix that.

Thanks

-- 
Luc

> 
> > Thanks,
> > Arnaud Minier
> > 
> 

-- 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-14  7:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-12 13:05 Questions about clocks emulation Arnaud Minier
2023-12-13 19:13 ` Philippe Mathieu-Daudé
2023-12-14  7:45   ` Luc Michel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).