1. 29 Aug, 2018 1 commit
    • Johan Hovold's avatar
      of: add helper to lookup compatible child node · 36156f92
      Johan Hovold authored
      Add of_get_compatible_child() helper that can be used to lookup
      compatible child nodes.
      Several drivers currently use of_find_compatible_node() to lookup child
      nodes while failing to notice that the of_find_ functions search the
      entire tree depth-first (from a given start node) and therefore can
      match unrelated nodes. The fact that these functions also drop a
      reference to the node they start searching from (e.g. the parent node)
      is typically also overlooked, something which can lead to use-after-free
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
  2. 04 Mar, 2018 1 commit
    • Frank Rowand's avatar
      of: change overlay apply input data from unflattened to FDT · 39a751a4
      Frank Rowand authored
      Move duplicating and unflattening of an overlay flattened devicetree
      (FDT) into the overlay application code.  To accomplish this,
      of_overlay_apply() is replaced by of_overlay_fdt_apply().
      The copy of the FDT (aka "duplicate FDT") now belongs to devicetree
      code, which is thus responsible for freeing the duplicate FDT.  The
      caller of of_overlay_fdt_apply() remains responsible for freeing the
      original FDT.
      The unflattened devicetree now belongs to devicetree code, which is
      thus responsible for freeing the unflattened devicetree.
      These ownership changes prevent early freeing of the duplicated FDT
      or the unflattened devicetree, which could result in use after free
      of_overlay_fdt_apply() is a private function for the anticipated
      overlay loader.
      Update unittest.c to use of_overlay_fdt_apply() instead of
      Move overlay fragments from artificial locations in
      drivers/of/unittest-data/tests-overlay.dtsi into one devicetree
      source file per overlay.  This led to changes in
      drivers/of/unitest-data/Makefile and drivers/of/unitest.c.
        - Add overlay directives to the overlay devicetree source files so
          that dtc will compile them as true overlays into one FDT data
          chunk per overlay.
        - Set CFLAGS for drivers/of/unittest-data/testcases.dts so that
          symbols will be generated for overlay resolution of overlays
          that are no longer artificially contained in testcases.dts
        - Unflatten and apply each unittest overlay FDT using
        - Enable the of_resolve_phandles() check for whether the unflattened
          overlay is detached.  This check was previously disabled because the
          overlays from tests-overlay.dtsi were not unflattened into detached
        - Other changes to unittest.c infrastructure to manage multiple test
          FDTs built into the kernel image (access by name instead of
          arbitrary number).
        - of_unittest_overlay_high_level(): previously unused code to add
          properties from the overlay_base devicetree to the live tree
          was triggered by the restructuring of tests-overlay.dtsi and thus
          testcases.dts.  This exposed two bugs: (1) the need to dup a
          property before adding it, and (2) property 'name' is
          auto-generated in the unflatten code and thus will be a duplicate
          in the __symbols__ node - do not treat this duplicate as an error.
      Signed-off-by: default avatarFrank Rowand <frank.rowand@sony.com>
  3. 12 Feb, 2018 1 commit
    • Stephen Boyd's avatar
      of: Support parsing phandle argument lists through a nexus node · bd6f2fd5
      Stephen Boyd authored
      Platforms like 96boards have a standardized connector/expansion
      slot that exposes signals like GPIOs to expansion boards in an
      SoC agnostic way. We'd like the DT overlays for the expansion
      boards to be written once without knowledge of the SoC on the
      other side of the connector. This avoids the unscalable
      combinatorial explosion of a different DT overlay for each
      expansion board and SoC pair.
      We need a way to describe the GPIOs routed through the connector
      in an SoC agnostic way. Let's introduce nexus property parsing
      into the OF core to do this. This is largely based on the
      interrupt nexus support we already have. This allows us to remap
      a phandle list in a consumer node (e.g. reset-gpios) through a
      connector in a generic way (e.g. via gpio-map). Do this in a
      generic routine so that we can remap any sort of variable length
      phandle list.
      Taking GPIOs as an example, the connector would be a GPIO nexus,
      supporting the remapping of a GPIO specifier space to multiple
      GPIO providers on the SoC. DT would look as shown below, where
      'soc_gpio1' and 'soc_gpio2' are inside the SoC, 'connector' is an
      expansion port where boards can be plugged in, and
      'expansion_device' is a device on the expansion board.
      	soc {
      		soc_gpio1: gpio-controller1 {
      			#gpio-cells = <2>;
      		soc_gpio2: gpio-controller2 {
      			#gpio-cells = <2>;
      	connector: connector {
      		#gpio-cells = <2>;
      		gpio-map = <0 0 &soc_gpio1 1 0>,
      			   <1 0 &soc_gpio2 4 0>,
      			   <2 0 &soc_gpio1 3 0>,
      			   <3 0 &soc_gpio2 2 0>;
      		gpio-map-mask = <0xf 0x0>;
      		gpio-map-pass-thru = <0x0 0x1>
      	expansion_device {
      		reset-gpios = <&connector 2 GPIO_ACTIVE_LOW>;
      The GPIO core would use of_parse_phandle_with_args_map() instead
      of of_parse_phandle_with_args() and arrive at the same type of
      result, a phandle and argument list. The difference is that the
      phandle and arguments will be remapped through the nexus node to
      the underlying SoC GPIO controller node. In the example above,
      we would remap 'reset-gpios' from <&connector 2 GPIO_ACTIVE_LOW>
      to <&soc_gpio1 3 GPIO_ACTIVE_LOW>.
      Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
      Cc: Linus Walleij <linus.walleij@linaro.org>
      Cc: Mark Brown <broonie@kernel.org>
      Signed-off-by: default avatarStephen Boyd <stephen.boyd@linaro.org>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
  4. 08 Jan, 2018 1 commit
  5. 02 Jan, 2018 1 commit
  6. 08 Nov, 2017 1 commit
    • Arnd Bergmann's avatar
      of: add of_property_read_variable_* dummy helpers · 96c623e5
      Arnd Bergmann authored
      Commit a67e9472 ("of: Add array read functions with min/max size
      limits") added a new interface for reading variable-length arrays from
      DT properties. One user was added in dsa recently and this causes a
      build error because that code can be built with CONFIG_OF disabled:
      net/dsa/dsa2.c: In function 'dsa_switch_parse_member_of':
      net/dsa/dsa2.c:678:7: error: implicit declaration of function 'of_property_read_variable_u32_array'; did you mean 'of_property_read_u32_array'? [-Werror=implicit-function-declaration]
      This adds a dummy functions for of_property_read_variable_u32_array()
      and a few others that had been missing here. I decided to move
      of_property_read_string() and of_property_read_string_helper() in the
      process to make it easier to compare the two sets of function prototypes
      to make sure they match.
      Fixes: 975e6e32
       ("net: dsa: rework switch parsing")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Acked-by: default avatarRob Herring <robh@kernel.org>
      Reviewed-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
  7. 18 Oct, 2017 3 commits
    • Frank Rowand's avatar
      of: overlay: avoid race condition between applying multiple overlays · f948d6d8
      Frank Rowand authored
      The process of applying an overlay consists of:
        - unflatten an overlay FDT (flattened device tree) into an
          EDT (expanded device tree)
        - fixup the phandle values in the overlay EDT to fit in a
          range above the phandle values in the live device tree
        - create the overlay changeset to reflect the contents of
          the overlay EDT
        - apply the overlay changeset, to modify the live device tree,
          potentially changing the maximum phandle value in the live
          device tree
      There is currently no protection against two overlay applies
      concurrently determining what range of phandle values are in use
      in the live device tree, and subsequently changing that range.
      Add a mutex to prevent multiple overlay applies from occurring
      Move of_resolve_phandles() into of_overlay_apply() so that it does not
      have to be duplicated by each caller of of_overlay_apply().
      The test in of_resolve_phandles() that the overlay tree is detached is
      temporarily disabled so that old style overlay unittests do not fail.
      Signed-off-by: default avatarFrank Rowand <frank.rowand@sony.com>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
    • Frank Rowand's avatar
      of: overlay: detect cases where device tree may become corrupt · 24789c5c
      Frank Rowand authored
      When an attempt to apply an overlay changeset fails, an effort
      is made to revert any partial application of the changeset.
      When an attempt to remove an overlay changeset fails, an effort
      is made to re-apply any partial reversion of the changeset.
      The existing code does not check for failure to recover a failed
      overlay changeset application or overlay changeset revert.
      Add the missing checks and flag the devicetree as corrupt if the
      state of the devicetree can not be determined.
      Improve and expand the returned errors to more fully reflect the
      result of the effort to undo the partial effects of a failed attempt
      to apply or remove an overlay changeset.
      If the device tree might be corrupt, do not allow further attempts
      to apply or remove an overlay changeset.
      When creating an overlay changeset from an overlay device tree,
      add some additional warnings if the state of the overlay device
      tree is not as expected.
      Signed-off-by: default avatarFrank Rowand <frank.rowand@sony.com>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
    • Frank Rowand's avatar
      of: overlay: rename identifiers to more reflect what they do · 0290c4ca
      Frank Rowand authored
      This patch is aimed primarily at drivers/of/overlay.c, but those
      changes also have a small impact in a few other files.
      overlay.c is difficult to read and maintain.  Improve readability:
        - Rename functions, types and variables to better reflect what
          they do and to be consistent with names in other places,
          such as the device tree overlay FDT (flattened device tree),
          and make the algorithms more clear
        - Use the same names consistently throughout the file
        - Update comments for name changes
        - Fix incorrect comments
      This patch is intended to not introduce any functional change.
      Signed-off-by: default avatarFrank Rowand <frank.rowand@sony.com>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
  8. 16 Oct, 2017 4 commits
  9. 13 Oct, 2017 1 commit
  10. 21 Jul, 2017 1 commit
  11. 22 Jun, 2017 1 commit
  12. 14 Jun, 2017 1 commit
  13. 01 Jun, 2017 2 commits
  14. 03 Apr, 2017 1 commit
  15. 28 Mar, 2017 1 commit
  16. 17 Jan, 2017 1 commit
  17. 09 Dec, 2016 1 commit
  18. 18 Nov, 2016 1 commit
    • Sudeep Holla's avatar
      of: base: add support to get machine model name · e5269794
      Sudeep Holla authored
      Currently platforms/drivers needing to get the machine model name are
      replicating the same snippet of code. In some case, the OF reference
      counting is either missing or incorrect.
      This patch adds support to read the machine model name either using
      the "model" or the "compatible" property in the device tree root node
      to the core OF/DT code.
      This can be used to remove all the duplicate code snippets doing exactly
      same thing later.
      Cc: Rob Herring <robh+dt@kernel.org>
      Cc: Frank Rowand <frowand.list@gmail.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Signed-off-by: Sudeep Holla's avatarSudeep Holla <sudeep.holla@arm.com>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
  19. 10 Nov, 2016 1 commit
    • Alan Tull's avatar
      of/overlay: add of overlay notifications · 39a842e2
      Alan Tull authored
      This patch add of overlay notifications.
      When DT overlays are being added, some drivers/subsystems
      need to see device tree overlays before the changes go into
      the live tree.
      This is distinct from reconfig notifiers that are
      post-apply or post-remove and which issue very granular
      notifications without providing access to the context
      of a whole overlay.
      The following 4 notificatons are issued:
      In the case of pre-apply notification, if the notifier
      returns error, the overlay will be rejected.
      This patch exports two functions for registering/unregistering
        of_overlay_notifier_register(struct notifier_block *nb)
        of_overlay_notifier_unregister(struct notifier_block *nb)
      The of_mutex is held during these notifications. The
      notification data includes pointers to the overlay target
      and the overlay:
      struct of_overlay_notify_data {
             struct device_node *overlay;
             struct device_node *target;
      Signed-off-by: default avatarAlan Tull <atull@opensource.altera.com>
      Acked-by: default avatarRob Herring <robh@kernel.org>
      Acked-by: default avatarMoritz Fischer <moritz.fischer@ettus.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
  20. 15 Sep, 2016 1 commit
    • Richard Fitzgerald's avatar
      of: Add array read functions with min/max size limits · a67e9472
      Richard Fitzgerald authored
      Add a new set of array reading functions that take a minimum and
      maximum size limit and will fail if the property size is not within
      the size limits. This makes it more convenient for drivers that
      use variable-size DT arrays which must be bounded at both ends -
      data must be at least N entries but must not overflow the array
      it is being copied into. It is also more efficient than making this
      functionality out of existing public functions and avoids duplication.
      The existing array functions have been left in the API, since there
      are a very large number of clients of those functions and their
      existing functionality is still useful. This avoids turning a small
      API improvement into a major kernel rework.
      The old functions have been turned into mininmal static inlines calling
      the new functions. The old functions had no upper limit on the actual
      size of the dts entry, to preserve this functionality rather than keeping
      two near-identical implementations, if the new function is called with
      max=0 there is no limit on the size of the dts entry but only the min
      number of elements are read.
      Signed-off-by: default avatarRichard Fitzgerald <rf@opensource.wolfsonmicro.com>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
  21. 20 Jul, 2016 1 commit
  22. 28 Jun, 2016 1 commit
    • Daniel Lezcano's avatar
      of: Add a new macro to declare_of for one parameter function returning a value · c35d9292
      Daniel Lezcano authored
      The macro OF_DECLARE_1 expect a void (*func)(struct device_node *) while the
      OF_DECLARE_2 expect a int (*func)(struct device_node *, struct device_node *).
      The second one allows to pass an init function returning a value, which make
      possible to call the functions in the table and check the return value in order
      to catch at a higher level the errors and handle them from there instead of
      doing a panic in each driver (well at least this is the case for the clkevt).
      Unfortunately the OF_DECLARE_1 does not allow that and that lead to some code
      duplication and crappyness in the drivers.
      The OF_DECLARE_1 is used by all the clk drivers and the clocksource/clockevent
      drivers. It is not possible to do the change in one shot as we have to change
      all the init functions.
      The OF_DECLARE_2 specifies an init function prototype with two parameters with
      the node and its parent. The latter won't be used, ever, in the timer drivers.
      Introduce a OF_DECLARE_1_RET macro to be used, and hopefully we can smoothly
      and iteratively change the users of OF_DECLARE_1 to use the new macro instead.
      Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
      Acked-by: default avatarRob Herring <robh@kernel.org>
  23. 26 Jun, 2016 1 commit
  24. 03 Jun, 2016 1 commit
  25. 27 Apr, 2016 1 commit
  26. 19 Apr, 2016 4 commits
  27. 15 Apr, 2016 1 commit
  28. 03 Mar, 2016 1 commit
  29. 25 Jan, 2016 1 commit
  30. 10 Nov, 2015 1 commit
  31. 25 Aug, 2015 1 commit