Re: [RFC PATCH v2 04/15] misc/arm-cla: Probe firmware-described devices
From: Linus Walleij
Date: Sat Nov 21 2026 - 16:16:19 EST
Hi Ryan & Jean-Philippe,
thanks for your patch!
I see this framework is (ab)using platform_device, and Greg has many
times pointed out that he doesn't like that, and I don't like it either,
so I'm gonna complain about that.
On Thu, Oct 15, 2026 at 4:26 PM Ryan Roberts <ryan.roberts@xxxxxxx> wrote:
> +static int cla_of_to_cpu(struct device_node *of_node)
> +{
> + int cpu;
> + int ret;
> + u32 cpu_phandle;
> + struct device_node *cpu_node;
> +
> + if (!of_node)
> + return -ENODEV;
> +
> + ret = of_property_read_u32(of_node, "cpu", &cpu_phandle);
> + if (WARN_ON(ret))
> + return -EINVAL;
> +
> + cpu_node = of_find_node_by_phandle(cpu_phandle);
> + if (WARN_ON(!cpu_node))
> + return -EINVAL;
> +
> + cpu = of_cpu_node_to_id(cpu_node);
> + of_node_put(cpu_node);
> +
> + return cpu;
> +}
> +
> +static struct cla_dev *cla_dev_alloc(struct device *parent, int cpu,
> + void __iomem *regs, phys_addr_t base)
> +{
> + struct cla_dev *dev;
> +
> + dev = devm_kzalloc(parent, sizeof(*dev), GFP_KERNEL);
> + if (!dev)
> + return ERR_PTR(-ENOMEM);
> +
> + dev->pfn = __phys_to_pfn(base);
> + dev->regs = cla_get_regs(regs, cla_kernel_pl);
> + dev->cpu = cpu;
> + dev->dev = parent;
Why is struct cla_dev just a hollow thing without it's own
struct device? This is free-riding on the parent device, which
seems odd to me.
Should you rather have:
struct cla_device {
unsigned int cpu;
void __iomem *regs;
struct device dev;
^ Not a pointer
unsigned long pfn;
unsigned long pg_offset;
struct cla_domain *domain;
};
Instead of first creating platform devices, then spawn this
hollow struct cla_dev from the platform device, what about
just creating struct cla_device directly from the beginning
if the platform_device has no real use?
> +static int cla_probe(struct platform_device *pdev)
Why send in a platform device here at all, just create the
cla_device and pass this in here instead. It does exist
right?
> +{
> + int cpu;
> + void __iomem *reg;
> + size_t reg_size;
> + struct cla_dev *dev;
> + struct resource *res;
> +
> + /*
> + * TODO: the firmware maps this as well to access PL3, and the guest
> + * will map PL1 and PL0. Avoid TLB attr mismatches by only mapping what
> + * we need.
> + */
> + reg = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
And register resource to &cla->dev; etc.
> +static int __init cla_module_init(void)
> +{
> + bool driver_registered = false;
> + int ret;
> +
> + /*
> + * For now, we reject any CLAs discovered via FW tables, whose CPU is
> + * offline during init. This keeps things simple by allowing us to probe
> + * all HW at init time. Keep the online CPU set stable so that the
> + * cpu_online() check in cla_probe() is consistent with the online cpus
> + * when we call cpuhp_setup_state().
> + */
> + scoped_guard(cpus_read_lock) {
> + /*
> + * CPUs may be hotplugged, but all CLAs are described by
> + * firmware so the probe can be synchronous. This only sets up
> + * the resources, and CPUHP callbacks do the actual peeking and
> + * poking. This returns an error when no CLA has an online CPU.
> + */
> + ret = platform_driver_probe(&cla_driver, cla_probe);
Create your own cla_driver for cla_device instead.
Yours,
Linus Walleij