2023-01-22 12:18:33

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [RFC PATCH v2 30/31] kvx: Add power controller driver

On 20/01/2023 15:10, Yann Sionneau wrote:
> From: Jules Maselbas <[email protected]>
>
> The Power Controller (pwr-ctrl) control cores reset and wake-up
> procedure.


> +
> +static struct device_node * __init get_pwr_ctrl_node(void)
> +{
> + const phandle *ph;
> + struct device_node *cpu;
> + struct device_node *node;
> +
> + cpu = of_get_cpu_node(raw_smp_processor_id(), NULL);
> + if (!cpu) {
> + pr_err("Failed to get CPU node\n");
> + return NULL;
> + }
> +
> + ph = of_get_property(cpu, "power-controller", NULL);
> + if (!ph) {
> + pr_err("Failed to get power-controller phandle\n");
> + return NULL;
> + }
> +
> + node = of_find_node_by_phandle(be32_to_cpup(ph));
> + if (!node) {
> + pr_err("Failed to get power-controller node\n");
> + return NULL;
> + }
> +
> + return node;
> +}
> +
> +int __init kvx_pwr_ctrl_probe(void)
> +{
> + struct device_node *ctrl;
> +
> + ctrl = get_pwr_ctrl_node();
> + if (!ctrl) {
> + pr_err("Failed to get power controller node\n");
> + return -EINVAL;
> + }
> +
> + if (!of_device_is_compatible(ctrl, "kalray,kvx-pwr-ctrl")) {
> + pr_err("Failed to get power controller node\n");

No. Drivers go to drivers, not to arch directory. This should be a
proper driver instead of some fake stub doing its own driver matching.
You need to rework this.

Best regards,
Krzysztof


2024-04-15 14:15:17

by Yann Sionneau

[permalink] [raw]
Subject: Re: [RFC PATCH v2 30/31] kvx: Add power controller driver

Hello Krzysztof, Arnd, all,

On 1/22/23 12:54, Krzysztof Kozlowski wrote:
> On 20/01/2023 15:10, Yann Sionneau wrote:
>> From: Jules Maselbas <[email protected]>
>>
>> The Power Controller (pwr-ctrl) control cores reset and wake-up
>> procedure.
>> +
>> +int __init kvx_pwr_ctrl_probe(void)
>> +{
>> + struct device_node *ctrl;
>> +
>> + ctrl = get_pwr_ctrl_node();
>> + if (!ctrl) {
>> + pr_err("Failed to get power controller node\n");
>> + return -EINVAL;
>> + }
>> +
>> + if (!of_device_is_compatible(ctrl, "kalray,kvx-pwr-ctrl")) {
>> + pr_err("Failed to get power controller node\n");
> No. Drivers go to drivers, not to arch directory. This should be a
> proper driver instead of some fake stub doing its own driver matching.
> You need to rework this.

I am working on a v3 patchset, therefore I am working on a solution for
this "pwr-ctrl" driver that needs to go somewhere else than arch/kvx/.

The purpose of this "driver" is just to expose a void
kvx_pwr_ctrl_cpu_poweron(unsigned int cpu) function, used by
kernel/smpboot.c function __cpu_up() in order to start secondary CPUs in
SMP config.

Doing this, on our SoC, requires writing 3 registers in a memory-mapped
device named "power controller".

I made some researches in drivers/ but I am not sure yet what's a good
place that fits what our device is doing (booting secondary CPUs).

* drivers/power/reset seems to be for resetting the entire SoC

* drivers/power/supply seems to be to control power supplies ICs/periph.

* drivers/reset seems to be for device reset

* drivers/pmdomain maybe ?

* drivers/soc ?

* drivers/platform ?

* drivers/misc ?

What do you think?

Thanks.

Regards,

--

Yann






2024-04-15 15:31:09

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [RFC PATCH v2 30/31] kvx: Add power controller driver

On Mon, Apr 15, 2024, at 16:08, Yann Sionneau wrote:
> On 1/22/23 12:54, Krzysztof Kozlowski wrote:
>> On 20/01/2023 15:10, Yann Sionneau wrote:
>>> From: Jules Maselbas <[email protected]>
>>>
>>> The Power Controller (pwr-ctrl) control cores reset and wake-up
>>> procedure.
>>> +
>>> +int __init kvx_pwr_ctrl_probe(void)
>>> +{
>>> + struct device_node *ctrl;
>>> +
>>> + ctrl = get_pwr_ctrl_node();
>>> + if (!ctrl) {
>>> + pr_err("Failed to get power controller node\n");
>>> + return -EINVAL;
>>> + }
>>> +
>>> + if (!of_device_is_compatible(ctrl, "kalray,kvx-pwr-ctrl")) {
>>> + pr_err("Failed to get power controller node\n");
>> No. Drivers go to drivers, not to arch directory. This should be a
>> proper driver instead of some fake stub doing its own driver matching.
>> You need to rework this.
>
> I am working on a v3 patchset, therefore I am working on a solution for
> this "pwr-ctrl" driver that needs to go somewhere else than arch/kvx/.
>
> The purpose of this "driver" is just to expose a void
> kvx_pwr_ctrl_cpu_poweron(unsigned int cpu) function, used by
> kernel/smpboot.c function __cpu_up() in order to start secondary CPUs in
> SMP config.
>
> Doing this, on our SoC, requires writing 3 registers in a memory-mapped
> device named "power controller".
>
> I made some researches in drivers/ but I am not sure yet what's a good
> place that fits what our device is doing (booting secondary CPUs).
>
> * drivers/power/reset seems to be for resetting the entire SoC
>
> * drivers/power/supply seems to be to control power supplies ICs/periph.
>
> * drivers/reset seems to be for device reset
>
> * drivers/pmdomain maybe ?

Right, I don't think any of the above are appropriate

> * drivers/soc ?
>
> * drivers/platform ?
>
> * drivers/misc ?

Not drivers/misc, that is mainly for things with a user-space
interface.

drivers/soc is mainly for drivers used by other drivers, but
this would work, especially if you expect to have multiple
SoC variants that all use the same architecture code but
incompatible register layouts

drivers/platform is really for things outside of the SoC
that are used for managing the system, especially across
architectures, so I don't think that is a good fit.

Traditionally we had this code in arch/{arm,mips,powerpc,sh,x86}
and we never created a drier subsystem for it since newer
targets (arm64, riscv, newer arm, most x86) all use a method
that is specified as part of the ISA or firmware interface.

The question what you expect to see with future hardware
iterations: if you think all arch/kvx/ hardware will use the
same code for maybe at least the next five years, I would
suggest you keep it in arch/kvx/kernel/smp.c, but if you
know or expect other implementations to be needed, I can
merge it as a driver through drivers/soc/.

Arnd