From patchwork Fri May 11 16:20:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 912063 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="z+IRlvgk"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40jFhn1BRTz9s2L for ; Sat, 12 May 2018 02:21:29 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752070AbeEKQV1 (ORCPT ); Fri, 11 May 2018 12:21:27 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:39116 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752015AbeEKQVZ (ORCPT ); Fri, 11 May 2018 12:21:25 -0400 Received: by mail-wm0-f66.google.com with SMTP id f8-v6so4241289wmc.4 for ; Fri, 11 May 2018 09:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=J2WjFW/lWQkQ00ToInaGWbWlNr+YPuZqrs55hLZ9LAU=; b=z+IRlvgkCPzmjGRGtwtvHGZ7r3EQ47B/g32wd+riZI2GWhyq2vf8ozSwRde36bC0LG cG94vj/fKCzbyEd6+0BzkW3OLrRIDiTRFfnvmTJPx8LGToIlxozw7S4jvA+UL+Yt3KOw 07thwwwoSJOrcU92DnaPeiP2guOD5zTUBTzNtAf1J74VatCD4zyoikELWlg7JRD15n4s y2+fmU/ePIDhYAwkdKakc5bZIrWWVrLzxhDl/W1gtiVh4m5JzDKzdTTUGqFBHXWpEMS7 3Gcmsik228faNKVKpdhJNjm8Ux/QU65mEbTzieM1bz6BSYGHUKjwbFRXyAX36lIre06i pSrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=J2WjFW/lWQkQ00ToInaGWbWlNr+YPuZqrs55hLZ9LAU=; b=hUXw1DYFGvY17njHhdTLou0wqiSkrMqmNTkDqX0HfXuwS008ZzAU01yTAuPbP1BBxs L1d0nDThKWUDuhzb5BZ0lamWnDADkFFtCLAu4SNqKcNSiGR509TdTgOh7jvsBqWTMhsM zlNZRC05bAUh9+p0HxGrfxk1jTZJHEFhf+DrQT4lD1kTq5Mr0ahAscp33SHeqJRww5hH zjFykZZvpaiywsckQn3fHLpnVPV2vl66KGXDaiaUMybTNP+R9p5zBF1XrmIxwY4Lf2wM TC8gsOUM1HKksbJVS1AYVDdP1YHjptrpxBpG2gFx1SQXuAr0/3RtDmRLuohyHi8ul1XO 6w7g== X-Gm-Message-State: ALKqPwddYEIEhzChrn5Czj/6NPz3bQg9fsawpGko9a0qs7Dgd++P/fZB t7C3PboMlPiM70jDS2NOP/BImQ== X-Google-Smtp-Source: AB8JxZrEYtZRezWYV/8lxeirTfsHwp57OvK1v70029VNCklj3U+ZmFY1VCxTx6DXtO95pO3eywli3w== X-Received: by 2002:a1c:1c55:: with SMTP id c82-v6mr2457510wmc.69.1526055684211; Fri, 11 May 2018 09:21:24 -0700 (PDT) Received: from brgl-bgdev.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id q17-v6sm1429523wmf.3.2018.05.11.09.21.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 May 2018 09:21:23 -0700 (PDT) From: Bartosz Golaszewski To: Sekhar Nori , Kevin Hilman , David Lechner , Michael Turquette , Stephen Boyd , Arnd Bergmann , Greg Kroah-Hartman , Mark Rutland , Yoshinori Sato , Rich Felker , Andy Shevchenko , Marc Zyngier , "Rafael J . Wysocki" , Peter Rosin , Jiri Slaby , Thomas Gleixner , Daniel Lezcano , Geert Uytterhoeven , Magnus Damm , Johan Hovold , Rob Herring , Frank Rowand Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 00/12] introduce support for early platform drivers Date: Fri, 11 May 2018 18:20:16 +0200 Message-Id: <20180511162028.20616-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.17.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This series is a follow-up to the RFC[1] posted a couple days ago. NOTE: this series applies on top of my recent patches[2] that move the previous implementation of early platform devices to arch/sh. Problem: Certain class of devices, such as timers, certain clock drivers and irq chip drivers need to be probed early in the boot sequence. The currently preferred approach is using one of the OF_DECLARE() macros. This however does not create a platform device which has many drawbacks - such as not being able to use devres routines, dev_ log functions or no way of deferring the init OF function if some other resources are missing. For drivers that use both platform drivers and OF_DECLARE the situation is even more complicated as the code needs to take into account that there can possibly be no struct device present. For a specific use case that we're having problems with, please refer to the recent DaVinci common-clock conversion patches and the nasty workaround that this problem implies[3]. We also used to have an early platform drivers implementation but they were not integrated with the linux device model at all - they merely used the same data structures. The users could not use devres, defer probe and the early devices never became actual platform devices later on. Proposed solution: This series aims at solving this problem by (re-)introducing the concept of early platform drivers and devices - this time however in a way that seamlessly integrates with the existing platform drivers and also offers device-tree support. The idea is to provide a way for users to probe devices early, while already being able to use devres, devices resources and properties and also deferred probing. New structures are introduced: the early platform driver contains the early_probe callback which has the same signature as regular platform_device probe. This callback is called early on. The user can have both the early and regular probe speficied or only one of them and they both receive the same platform device object as argument. Any device data allocated early will be carried over to the normal probe. The architecture code is responsible for calling early_platform_start() in which the early drivers will be registered and devices populated from DT. Once the device and kobject mechanisms are ready, all early drivers and devices will be converted into real platform drivers and devices. Also: if any of the early platform registration functions will be called once early initialization is done, these functions will work like regular platform_device/driver ones. Patches 1-9/12 introduce changes to existing code that are necessary before adding support for early drivers. Patch 10/12 contains the new framwork in an isolated file which can be compiled only if needed by the architecture. Patch 11/12 contains a dummy early platform driver that serves as a code example and can be used for simple testing. The last patch finally makes the of/platform code aware of early platform drivers. If accepted, this new mechanism could potentially lead to consolidation of the code currently used by users of OF_DECLARE, since they could be converted to actual platform drivers. [1] https://lkml.org/lkml/2018/4/26/657 [2] https://lkml.org/lkml/2018/4/30/547 [3] https://lkml.org/lkml/2018/4/26/1094 Bartosz Golaszewski (12): platform/early: add a new field to struct device platform/early: don't WARN() on non-empty devres list for early devices platform/early: export platform_match() locally platform: provide a separate function for initializing platform devices platform: export platform_device_release() locally of: add a new flag for OF device nodes of/platform: provide a separate routine for setting up device resources of/platform: provide a separate routine for device initialization platform/early: add an init section for early driver data platform/early: implement support for early platform drivers misc: implement a dummy early platform driver of/platform: make the OF code aware of early platform drivers drivers/base/Kconfig | 3 + drivers/base/Makefile | 1 + drivers/base/base.h | 4 + drivers/base/dd.c | 2 +- drivers/base/early.c | 332 ++++++++++++++++++++++++++++++ drivers/base/platform.c | 28 ++- drivers/misc/Kconfig | 8 + drivers/misc/Makefile | 2 + drivers/misc/dummy-early.c | 82 ++++++++ drivers/of/platform.c | 85 +++++--- include/asm-generic/vmlinux.lds.h | 11 + include/linux/device.h | 1 + include/linux/early_platform.h | 75 +++++++ include/linux/of.h | 1 + include/linux/of_platform.h | 2 + include/linux/platform_device.h | 2 + 16 files changed, 604 insertions(+), 35 deletions(-) create mode 100644 drivers/base/early.c create mode 100644 drivers/misc/dummy-early.c create mode 100644 include/linux/early_platform.h Reviewed-by: Geert Uytterhoeven Reviewed-by: Geert Uytterhoeven Reviewed-by: Geert Uytterhoeven Reviewed-by: Geert Uytterhoeven Reviewed-by: Geert Uytterhoeven