Received: by 10.192.165.148 with SMTP id m20csp892460imm; Fri, 27 Apr 2018 09:08:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqRU7qGzLmKks0+xU9tvjNyAt4eDMbMMP/ZxWNSsnpnQbl9GCyuThxkQ+RTuQoRlisOE3q0 X-Received: by 2002:a63:7345:: with SMTP id d5-v6mr2611003pgn.284.1524845337935; Fri, 27 Apr 2018 09:08:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524845337; cv=none; d=google.com; s=arc-20160816; b=iCkWfIU6Gl8GUX3nGeIj9BQPvnJ76uyGvEgao9RynFnabYI067pwI1yc0+ym5xEfE2 1P/x+vbqzU3D3KdzN1qEXNjXnGJ7JQUSHA0B9yPSnAAUU7C/6lChKIq8pNAE8qRGqbMs CIkJwquZQYwXnAWwWKYU18qD9XshDniz8Yvt5H2Nq/J+H6V6wyzX6XrsX/rDfifGd8AP BXQAT7z2meTYe67RCTvZjxtpSRmU185FKqoRAPAnenMMQN3NYJO+l6fpsJ9p4hTKSUX8 yRF3O+BiI7fCULCIxi4q0M7BqdXrt/6NnxEDGHPUOBi4RBMXZZrBLzJJ9UynAEP4sUsp BD6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=7+zDqK4o5kO45+4WTp7mDHPxEn8fTfWYsxzKm5UDPGI=; b=XtQoT8AxNHlahDkQwOsvI/ncIYBrtS8JDoQCTH/iwRe+cTKUErqHGAlIh4PUlVLOEr Cytdj3KUjhYfgeB+9uWmy5yGzECwdIlwschqwk1IiXaPl8UZDiH/H5WPktokX5CWI4s3 G+iMoZO5hnt9SCkXm5DbCRTY+xsj4wJnXuK5fX94hp30sGffl70KUBSSu3ETYFPMbWvr mHQWE50sBJ6VbIxdCaGYKu7CqVZXe4sQeFhxsIX4zVJ1C+l/o0fg6YSQX8dgfN7YQYZh y8KF23GCKcsEeOxo4MwQ/DzvFY19QjwUGO0aFv+hdUrLMFrkG0rrZF6gY/tWk58tih5S ZWdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=oO5A13IB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j4-v6si1452659pgs.544.2018.04.27.09.08.43; Fri, 27 Apr 2018 09:08:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=oO5A13IB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932933AbeD0QGe (ORCPT + 99 others); Fri, 27 Apr 2018 12:06:34 -0400 Received: from mail-ot0-f196.google.com ([74.125.82.196]:35913 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758635AbeD0QF0 (ORCPT ); Fri, 27 Apr 2018 12:05:26 -0400 Received: by mail-ot0-f196.google.com with SMTP id p2-v6so2601929otf.3 for ; Fri, 27 Apr 2018 09:05:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=7+zDqK4o5kO45+4WTp7mDHPxEn8fTfWYsxzKm5UDPGI=; b=oO5A13IBIuksDrLUhTGMoepvrLkDwEFWrtpL7cpzn4PgYxzEeKNyJ3ZYPemnrCaTKS 3mWKDPHxxL6lqh7tDFjRDAdFxxYGOeYTpoEcN3pKOKUKa/Xx/h1jxTHdxWcX5fjSPS0B UkSszY+eyFh7gGmCOZDUix17rjvf0IPXASTae1s+v2P+V5bM6EqnYjmInYAbxlP/PiJ0 0i1w9RkJLqii9NXaB8wudHym+QbyiiPLTk/TYKOtlyo5afw3JRklnVA3zbAFZlzhopVg bCw2uOIM13ZVx4/XEKst/v3KmhGp7nBenkYmudxuCo2rrP6wUNEryJBxFdg7dW4HKvJf Trrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=7+zDqK4o5kO45+4WTp7mDHPxEn8fTfWYsxzKm5UDPGI=; b=B+Tx8FswucpJMBUnI9F2yuJDkvXlbnghTejqDSsg32frP2yDmjm7totR3A9NNPFXoX epbkZldk5ACBY9xN7v4EuBkz5tMh/UvFgTtOotAZVD3ds7eXpQu27jxhmjqfhCGdXbqJ clDwebZ6yUxpmFqH3kE0dxaDMzhQ50x0W1zeVm2uYzyf7PRBftCMBt4tmdJ5pHjVujag Rfi1g0nN9Lf/Q/c4S1EzpocQyhwhQTwIVP/js6zkC9bDwhxUmS0sezhnuBdoOhhSyVJz pwvCAUY/fZ2lDP5IKqqO6tkd0Xk13xlfVM2HiykWXkz33YxF8q3AN/hJEw7mTf4iUNt1 Rdag== X-Gm-Message-State: ALQs6tDMvyGW5O8PzjrTlm6ZtWylwemmxA6qI0mmRUluxpC/f/hgxsbt S5llBNaasAColJczgRJ8Iezemu/teuhY6MSsXaKKSg== X-Received: by 2002:a9d:1a70:: with SMTP id u45-v6mr2011286otu.9.1524845125951; Fri, 27 Apr 2018 09:05:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.138.0.213 with HTTP; Fri, 27 Apr 2018 09:05:25 -0700 (PDT) In-Reply-To: References: <20180426152920.21569-1-brgl@bgdev.pl> <20180426173151.GJ3094@brightrain.aerifal.cx> <6d1f9114-f1d1-961f-4f36-74adff059dc3@lechnology.com> From: Bartosz Golaszewski Date: Fri, 27 Apr 2018 18:05:25 +0200 Message-ID: Subject: Re: [PATCH RFC PoC 0/2] platform: different approach to early platform drivers To: Arnd Bergmann Cc: Bartosz Golaszewski , David Lechner , Rich Felker , Sekhar Nori , Kevin Hilman , Michael Turquette , Stephen Boyd , Greg Kroah-Hartman , Rob Herring , Mark Rutland , Yoshinori Sato , Frank Rowand , "Rafael J . Wysocki" , Jarkko Sakkinen , Dmitry Torokhov , Arend van Spriel , Heikki Krogerus , Michal Suchanek , Jan Kiszka , Andy Shevchenko , Marc Zyngier , Peter Rosin , Linux ARM , Linux Kernel Mailing List , DTML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-04-27 16:48 GMT+02:00 Arnd Bergmann : > On Fri, Apr 27, 2018 at 4:05 PM, Bartosz Golaszewski > wrote: >> 2018-04-27 14:40 GMT+02:00 Arnd Bergmann : > >>> For timer-ti-dm, it seems like a leftover from old times that can >>> be removed. The other four are shared between arch/sh and >>> arch/arm/mach-shmobile and already have some #ifdef >>> to handle those two cases. >>> >> >> I'm also seeing that we also call early_platform_cleanup() from >> platform_bus_init(). Any ideas for this one? > > My first idea would be to call it immediately after registering all > devices and drivers. It looks like it's only needed to make all > devm_ allocations persistent by removing them from the list, > so we have to call early_platform_cleanup() before getting > to the real platform code, but it could be done much earlier > if we want to, at least after both setup_arch() and sh_late_time_init() > are complete. > >>> I'd rather keep those separate and would prefer not to have >>> that many different ways of getting there instead. DT and >>> board files can already share most of the code through the >>> use of platform_device, especially when you start using >>> device properties instead of platform_data, and the other >>> two are rare corner cases and ideally left that way. >>> >>> The early boot code is always special and instead of making >>> it easier to use, we should focus on using it as little as >>> possible: every line of code that we call before even >>> initializing timers and consoles means it gets harder to >>> debug when something goes wrong. >>> >> >> I'm afraid I don't quite understand your reasoning. I fully agree that >> devices that need to be initialized that early are a rare corner case. >> We should limit any such uses to the absolute minimum. But when we do >> need to go this way, we should do it right. Having a unified mechanism >> for early devices will allow maintainers to enforce good practices >> (using resources for register mapping, devres, reusing driver code for >> reading/writing to registers). Having initialization code in machine >> code will make everybody use different APIs and duplicate solutions. I >> normally assume that code consolidation is always good. >> >> If we add a way for DT-based platform devices to be probed early - it >> would be based on platform device/driver structures anyway. Why would >> we even want to not convert the board code into a simple call to >> early_platform_device_register() if we'll already offer this API for >> device tree? > > I think we first need to define what we really want to achieve here. > It sounds like you still want to recreate a lot of what early_platform > devices do, but it seems more important to me to add the missing > functionality to the OF_DECLARE infrastructure. The most > important pieces that seem to be missing are solved by finding > a way to provide a platform_device pointer with the following > properties: > > - allow being passed into dev_print() > - allow using the pointer as a token for devres unwinding > - access to device_private data that remains persistent > until real a platform_driver gets loaded > > That can probably be done as an extension to the current > infrastructure. > > However, I'd be very cautious about the resource portion: > filling the platform resources (registers, irqs, ...) the way > we do for regular devices is much harder and can introduce > additional (or circular) dependencies on other devices. > OTOH, not using those resources means you have a hard > time passing information from board files. > > Arnd So speaking in pseudo-C we basically have two ways for an imaginary future timer driver: int foo_probe(struct platform_device *pdev) { struct clk *clk; if (probing_early(pdev)) { clk = devm_clk_get(dev, "earlyclock"); /* Do early stuff. */ return 0; } /* Do late stuff. */ return 0; } --- vs --- int foo_probe(struct platform_device *pdev) { /* Do late stuff. */ return 0; } static int foo_init(struct device_node *np) { struct clk *clk; struct device *dev = device_from_device_node(np); /* Do early stuff. */ clk = devm_clk_get(dev, "earlyclock"); return 0; } TIMER_OF_DECLARE(foo, "bar,foo", foo_init); I still believe the first approach is easier to implement and has the added benefit of supporting board files. I'll give it a thought and will be back at it next week. Best regards, Bartosz Golaszewski