1. 22 3月, 2018 1 次提交
  2. 16 3月, 2018 1 次提交
  3. 28 2月, 2018 1 次提交
    • L
      driver core: Introduce device links reference counting · ead18c23
      Lukas Wunner 提交于
      If device_link_add() is invoked multiple times with the same supplier
      and consumer combo, it will create the link on first addition and
      return a pointer to the already existing link on all subsequent
      additions.
      
      The semantics for device_link_del() are quite different, it deletes
      the link unconditionally, so multiple invocations are not allowed.
      
      In other words, this snippet ...
      
          struct device *dev1, *dev2;
          struct device_link *link1, *link2;
      
          link1 = device_link_add(dev1, dev2, 0);
          link2 = device_link_add(dev1, dev2, 0);
      
          device_link_del(link1);
          device_link_del(link2);
      
      ... causes the following crash:
      
          WARNING: CPU: 4 PID: 2686 at drivers/base/power/runtime.c:1611 pm_runtime_drop_link+0x40/0x50
          [...]
          list_del corruption, 0000000039b800a4->prev is LIST_POISON2 (00000000ecf79852)
          kernel BUG at lib/list_debug.c:50!
      
      The issue isn't as arbitrary as it may seem:  Imagine a device link
      which is added in both the supplier's and the consumer's ->probe hook.
      The two drivers can't just call device_link_del() in their ->remove hook
      without coordination.
      
      Fix by counting multiple additions and dropping the device link only
      when the last addition is unwound.
      Signed-off-by: NLukas Wunner <lukas@wunner.de>
      [ rjw: Subject ]
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      ead18c23
  4. 04 2月, 2018 1 次提交
    • L
      pinctrl: remove include file from <linux/device.h> · 23c35f48
      Linus Torvalds 提交于
      When pulling the recent pinctrl merge, I was surprised by how a
      pinctrl-only pull request ended up rebuilding basically the whole
      kernel.
      
      The reason for that ended up being that <linux/device.h> included
      <linux/pinctrl/devinfo.h>, so any change to that file ended up causing
      pretty much every driver out there to be rebuilt.
      
      The reason for that was because 'struct device' has this in it:
      
          #ifdef CONFIG_PINCTRL
              struct dev_pin_info     *pins;
          #endif
      
      but we already avoid header includes for these kinds of things in that
      header file, preferring to just use a forward-declaration of the
      structure instead.  Exactly to avoid this kind of header dependency.
      
      Since some drivers seem to expect that <linux/pinctrl/devinfo.h> header
      to come in automatically, move the include to <linux/pinctrl/pinctrl.h>
      instead.  It might be better to just make the includes more targeted,
      but I'm not going to review every driver.
      
      It would definitely be good to have a tool for finding and minimizing
      header dependencies automatically - or at least help with them.  Right
      now we almost certainly end up having way too many of these things, and
      it's hard to test every single configuration.
      
      FWIW, you can get a sense of the "hotness" of a header file with something
      like this after doing a full build:
      
          find . -name '.*.o.cmd' -print0 |
              xargs -0 tail --lines=+2 |
              grep -v 'wildcard ' |
              tr ' \\' '\n' |
              sort | uniq -c | sort -n | less -S
      
      which isn't exact (there are other things in those '*.o.cmd' than just
      the dependencies, and the "--lines=+2" only removes the header), but
      might a useful approximation.
      
      With this patch, <linux/pinctrl/devinfo.h> drops to "only" having 833
      users in the current x86-64 allmodconfig.  In contrast, <linux/device.h>
      has 14857 build files including it directly or indirectly.
      
      Of course, the headers that absolutely _everybody_ includes (things like
      <linux/types.h> etc) get a score of 23000+.
      
      Cc: Linus Walleij <linus.walleij@linaro.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      23c35f48
  5. 23 1月, 2018 1 次提交
  6. 20 12月, 2017 1 次提交
    • C
      gpio: sysfs: change 'value' attribute to prealloc · 7fda9100
      Christophe Leroy 提交于
      The GPIO 'value' attribute is time critical. A small bench with
      'perf record' on the app below shows that 80% of the time spent in
      sysfs_kf_seq_show() is spent in memset() for zeroising the buffer.
      
      |--67.48%--sysfs_kf_seq_show
      |          |
      |          |--54.40%--memset
      |          |
      |          |--11.49%--dev_attr_show
      |          |          |
      |          |          |--10.06%--value_show
      |          |          |          |
      |          |          |          |--4.75%--sprintf
      |          |          |          |          |
      
      This patch changes the attribute type to prealloc, eliminating the
      need to zeroise the buffer at each read. 'perf record' gives the
      following result.
      
      |--42.41%--sysfs_kf_read
      |          |
      |          |--39.73%--dev_attr_show
      |          |          |
      |          |          |--38.23%--value_show
      |          |          |          |
      |          |          |          |--29.22%--sprintf
      |          |          |          |          |
      
      Test done with the following small app:
      
      int main(int argc, char **argv)
      {
      	int fd = open(argv[1], O_RDONLY);
      
      	for (;;) {
      		int buf[512];
      
      		read(fd, buf, 512);
      		lseek(fd, 0, SEEK_SET);
      	}
      	exit(0);
      }
      Signed-off-by: NChristophe Leroy <christophe.leroy@c-s.fr>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      7fda9100
  7. 08 12月, 2017 2 次提交
    • G
      driver core: Remove redundant license text · 32825709
      Greg Kroah-Hartman 提交于
      Now that the SPDX tag is in all driver core files, that identifies the
      license in a specific and legally-defined manner.  So the extra GPL text
      wording can be removed as it is no longer needed at all.
      
      This is done on a quest to remove the 700+ different ways that files in
      the kernel describe the GPL license text.  And there's unneeded stuff
      like the address (sometimes incorrect) for the FSF which is never
      needed.
      
      No copyright headers or other non-license-description text was removed.
      
      Cc: Johannes Berg <johannes@sipsolutions.net>
      Cc: "Luis R. Rodriguez" <mcgrof@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      32825709
    • G
      driver core: add SPDX identifiers to all driver core files · 989d42e8
      Greg Kroah-Hartman 提交于
      It's good to have SPDX identifiers in all files to make it easier to
      audit the kernel tree for correct licenses.
      
      Update the driver core files files with the correct SPDX license
      identifier based on the license text in the file itself.  The SPDX
      identifier is a legally binding shorthand, which can be used instead of
      the full boiler plate text.
      
      This work is based on a script and data from Thomas Gleixner, Philippe
      Ombredanne, and Kate Stewart.
      
      Cc: Johannes Berg <johannes@sipsolutions.net>
      Cc: "Luis R. Rodriguez" <mcgrof@kernel.org>
      Cc: William Breathitt Gray <vilhelm.gray@gmail.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: Philippe Ombredanne <pombredanne@nexb.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      989d42e8
  8. 06 11月, 2017 1 次提交
    • R
      PM / core: Add NEVER_SKIP and SMART_PREPARE driver flags · 08810a41
      Rafael J. Wysocki 提交于
      The motivation for this change is to provide a way to work around
      a problem with the direct-complete mechanism used for avoiding
      system suspend/resume handling for devices in runtime suspend.
      
      The problem is that some middle layer code (the PCI bus type and
      the ACPI PM domain in particular) returns positive values from its
      system suspend ->prepare callbacks regardless of whether the driver's
      ->prepare returns a positive value or 0, which effectively prevents
      drivers from being able to control the direct-complete feature.
      Some drivers need that control, however, and the PCI bus type has
      grown its own flag to deal with this issue, but since it is not
      limited to PCI, it is better to address it by adding driver flags at
      the core level.
      
      To that end, add a driver_flags field to struct dev_pm_info for flags
      that can be set by device drivers at the probe time to inform the PM
      core and/or bus types, PM domains and so on on the capabilities and/or
      preferences of device drivers.  Also add two static inline helpers
      for setting that field and testing it against a given set of flags
      and make the driver core clear it automatically on driver remove
      and probe failures.
      
      Define and document two PM driver flags related to the direct-
      complete feature: NEVER_SKIP and SMART_PREPARE that can be used,
      respectively, to indicate to the PM core that the direct-complete
      mechanism should never be used for the device and to inform the
      middle layer code (bus types, PM domains etc) that it can only
      request the PM core to use the direct-complete mechanism for
      the device (by returning a positive value from its ->prepare
      callback) if it also has been requested by the driver.
      
      While at it, make the core check pm_runtime_suspended() when
      setting power.direct_complete so that it doesn't need to be
      checked by ->prepare callbacks.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Acked-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      08810a41
  9. 19 10月, 2017 1 次提交
    • R
      drivers: flag buses which demand DMA configuration · d89e2378
      Robin Murphy 提交于
      We do not want the common dma_configure() pathway to apply
      indiscriminately to all devices, since there are plenty of buses which
      do not have DMA capability, and if their child devices were used for
      DMA API calls it would only be indicative of a driver bug. However,
      there are a number of buses for which DMA is implicitly expected even
      when not described by firmware - those we whitelist with an automatic
      opt-in to dma_configure(), assuming that the DMA address space and the
      physical address space are equivalent if not otherwise specified.
      
      Commit 72328883 ("of: restrict DMA configuration") introduced a
      short-term fix by comparing explicit bus types, but this approach is far
      from pretty, doesn't scale well, and fails to cope at all with bus
      drivers which may be built as modules, like host1x. Let's refine things
      by making that opt-in a property of the bus type, which neatly addresses
      those problems and lets the decision of whether firmware description of
      DMA capability should be optional or mandatory stay internal to the bus
      drivers themselves.
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Acked-by: NRob Herring <robh@kernel.org>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Acked-by: NThierry Reding <treding@nvidia.com>
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      d89e2378
  10. 26 9月, 2017 1 次提交
  11. 19 9月, 2017 1 次提交
  12. 18 9月, 2017 1 次提交
  13. 29 8月, 2017 1 次提交
  14. 28 8月, 2017 1 次提交
  15. 07 8月, 2017 1 次提交
  16. 22 7月, 2017 3 次提交
  17. 07 7月, 2017 1 次提交
  18. 13 6月, 2017 1 次提交
    • J
      driver core: add helper to reuse a device-tree node · 4e75e1d7
      Johan Hovold 提交于
      Add a helper function to be used when reusing the device-tree node of
      another device.
      
      It is fairly common for drivers to reuse the device-tree node of a
      parent (or other ancestor) device when creating class or bus devices
      (e.g. gpio chips, i2c adapters, iio chips, spi masters, serdev, phys,
      usb root hubs). But reusing a device-tree node may cause problems if the
      new device is later probed as for example driver core would currently
      attempt to reinitialise an already active associated pinmux
      configuration.
      
      Other potential issues include the platform-bus code unconditionally
      dropping the device-tree node reference in its device destructor,
      reinitialisation of other bus-managed resources such as clocks, and the
      recently added DMA-setup in driver core.
      
      Note that for most examples above this is currently not an issue as the
      devices are never probed, but this is a problem for the USB bus which
      has recently gained device-tree support. This was discovered and
      worked-around in a rather ad-hoc fashion by commit dc5878ab ("usb:
      core: move root hub's device node assignment after it is added to bus")
      by not setting the of_node pointer until after the root-hub device has
      been registered.
      
      Instead we can allow devices to reuse a device-tree node by setting a
      flag in their struct device that can be used by core, bus and driver
      code to avoid resources from being over-allocated.
      
      Note that the helper also grabs an extra reference to the device node,
      which specifically balances the unconditional put in the platform-device
      destructor.
      Signed-off-by: NJohan Hovold <johan@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4e75e1d7
  19. 12 6月, 2017 1 次提交
  20. 09 6月, 2017 1 次提交
  21. 07 6月, 2017 1 次提交
  22. 17 3月, 2017 1 次提交
  23. 25 2月, 2017 1 次提交
  24. 25 1月, 2017 1 次提交
  25. 21 1月, 2017 2 次提交
  26. 05 12月, 2016 1 次提交
  27. 30 11月, 2016 1 次提交
  28. 24 11月, 2016 1 次提交
  29. 16 11月, 2016 1 次提交
  30. 01 11月, 2016 2 次提交
    • R
      PM / runtime: Use device links · 21d5c57b
      Rafael J. Wysocki 提交于
      Modify the runtime PM framework to use device links to ensure that
      supplier devices will not be suspended if any of their consumer
      devices are active.
      
      The idea is to reference count suppliers on the consumer's resume
      and drop references to them on its suspend.  The information on
      whether or not the supplier has been reference counted by the
      consumer's (runtime) resume is stored in a new field (rpm_active)
      in the link object for each link.
      
      It may be necessary to clean up those references when the
      supplier is unbinding and that's why the links whose status is
      DEVICE_LINK_SUPPLIER_UNBIND are skipped by the runtime suspend
      and resume code.
      
      The above means that if the consumer device is probed in the
      runtime-active state, the supplier has to be resumed and reference
      counted by device_link_add() so the code works as expected on its
      (runtime) suspend.  There is a new flag, DEVICE_LINK_RPM_ACTIVE,
      to tell device_link_add() about that (in which case the caller
      is responsible for making sure that the consumer really will
      be runtime-active when runtime PM is enabled for it).
      
      The other new link flag, DEVICE_LINK_PM_RUNTIME, tells the core
      whether or not the link should be used for runtime PM at all.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      21d5c57b
    • R
      driver core: Functional dependencies tracking support · 9ed98953
      Rafael J. Wysocki 提交于
      Currently, there is a problem with taking functional dependencies
      between devices into account.
      
      What I mean by a "functional dependency" is when the driver of device
      B needs device A to be functional and (generally) its driver to be
      present in order to work properly.  This has certain consequences
      for power management (suspend/resume and runtime PM ordering) and
      shutdown ordering of these devices.  In general, it also implies that
      the driver of A needs to be working for B to be probed successfully
      and it cannot be unbound from the device before the B's driver.
      
      Support for representing those functional dependencies between
      devices is added here to allow the driver core to track them and act
      on them in certain cases where applicable.
      
      The argument for doing that in the driver core is that there are
      quite a few distinct use cases involving device dependencies, they
      are relatively hard to get right in a driver (if one wants to
      address all of them properly) and it only gets worse if multiplied
      by the number of drivers potentially needing to do it.  Morever, at
      least one case (asynchronous system suspend/resume) cannot be handled
      in a single driver at all, because it requires the driver of A to
      wait for B to suspend (during system suspend) and the driver of B to
      wait for A to resume (during system resume).
      
      For this reason, represent dependencies between devices as "links",
      with the help of struct device_link objects each containing pointers
      to the "linked" devices, a list node for each of them, status
      information, flags, and an RCU head for synchronization.
      
      Also add two new list heads, representing the lists of links to the
      devices that depend on the given one (consumers) and to the devices
      depended on by it (suppliers), and a "driver presence status" field
      (needed for figuring out initial states of device links) to struct
      device.
      
      The entire data structure consisting of all of the lists of link
      objects for all devices is protected by a mutex (for link object
      addition/removal and for list walks during device driver probing
      and removal) and by SRCU (for list walking in other case that will
      be introduced by subsequent change sets).  If CONFIG_SRCU is not
      selected, however, an rwsem is used for protecting the entire data
      structure.
      
      In addition, each link object has an internal status field whose
      value reflects whether or not drivers are bound to the devices
      pointed to by the link or probing/removal of their drivers is in
      progress etc.  That field is only modified under the device links
      mutex, but it may be read outside of it in some cases (introduced by
      subsequent change sets), so modifications of it are annotated with
      WRITE_ONCE().
      
      New links are added by calling device_link_add() which takes three
      arguments: pointers to the devices in question and flags.  In
      particular, if DL_FLAG_STATELESS is set in the flags, the link status
      is not to be taken into account for this link and the driver core
      will not manage it.  In turn, if DL_FLAG_AUTOREMOVE is set in the
      flags, the driver core will remove the link automatically when the
      consumer device driver unbinds from it.
      
      One of the actions carried out by device_link_add() is to reorder
      the lists used for device shutdown and system suspend/resume to
      put the consumer device along with all of its children and all of
      its consumers (and so on, recursively) to the ends of those lists
      in order to ensure the right ordering between all of the supplier
      and consumer devices.
      
      For this reason, it is not possible to create a link between two
      devices if the would-be supplier device already depends on the
      would-be consumer device as either a direct descendant of it or a
      consumer of one of its direct descendants or one of its consumers
      and so on.
      
      There are two types of link objects, persistent and non-persistent.
      The persistent ones stay around until one of the target devices is
      deleted, while the non-persistent ones are removed automatically when
      the consumer driver unbinds from its device (ie. they are assumed to
      be valid only as long as the consumer device has a driver bound to
      it).  Persistent links are created by default and non-persistent
      links are created when the DL_FLAG_AUTOREMOVE flag is passed
      to device_link_add().
      
      Both persistent and non-persistent device links can be deleted
      with an explicit call to device_link_del().
      
      Links created without the DL_FLAG_STATELESS flag set are managed
      by the driver core using a simple state machine.  There are 5 states
      each link can be in: DORMANT (unused), AVAILABLE (the supplier driver
      is present and functional), CONSUMER_PROBE (the consumer driver is
      probing), ACTIVE (both supplier and consumer drivers are present and
      functional), and SUPPLIER_UNBIND (the supplier driver is unbinding).
      The driver core updates the link state automatically depending on
      what happens to the linked devices and for each link state specific
      actions are taken in addition to that.
      
      For example, if the supplier driver unbinds from its device, the
      driver core will also unbind the drivers of all of its consumers
      automatically under the assumption that they cannot function
      properly without the supplier.  Analogously, the driver core will
      only allow the consumer driver to bind to its device if the
      supplier driver is present and functional (ie. the link is in
      the AVAILABLE state).  If that's not the case, it will rely on
      the existing deferred probing mechanism to wait for the supplier
      driver to become available.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9ed98953
  31. 24 10月, 2016 1 次提交
  32. 16 9月, 2016 1 次提交
    • R
      iommu: Introduce iommu_fwspec · 57f98d2f
      Robin Murphy 提交于
      Introduce a common structure to hold the per-device firmware data that
      most IOMMU drivers need to keep track of. This enables us to configure
      much of that data from common firmware code, and consolidate a lot of
      the equivalent implementations, device look-up tables, etc. which are
      currently strewn across IOMMU drivers.
      
      This will also be enable us to address the outstanding "multiple IOMMUs
      on the platform bus" problem by tweaking IOMMU API calls to prefer
      dev->fwspec->ops before falling back to dev->bus->iommu_ops, and thus
      gracefully handle those troublesome systems which we currently cannot.
      
      As the first user, hook up the OF IOMMU configuration mechanism. The
      driver-defined nature of DT cells means that we still need the drivers
      to translate and add the IDs themselves, but future users such as the
      much less free-form ACPI IORT will be much simpler and self-contained.
      
      CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Suggested-by: NWill Deacon <will.deacon@arm.com>
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      57f98d2f
  33. 20 5月, 2016 1 次提交
    • R
      include/linux: apply __malloc attribute · 48a27055
      Rasmus Villemoes 提交于
      Attach the malloc attribute to a few allocation functions.  This helps
      gcc generate better code by telling it that the return value doesn't
      alias any existing pointers (which is even more valuable given the
      pessimizations implied by -fno-strict-aliasing).
      
      A simple example of what this allows gcc to do can be seen by looking at
      the last part of drm_atomic_helper_plane_reset:
      
      	plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);
      
      	if (plane->state) {
      		plane->state->plane = plane;
      		plane->state->rotation = BIT(DRM_ROTATE_0);
      	}
      
      which compiles to
      
          e8 99 bf d6 ff          callq  ffffffff8116d540 <kmem_cache_alloc_trace>
          48 85 c0                test   %rax,%rax
          48 89 83 40 02 00 00    mov    %rax,0x240(%rbx)
          74 11                   je     ffffffff814015c4 <drm_atomic_helper_plane_reset+0x64>
          48 89 18                mov    %rbx,(%rax)
          48 8b 83 40 02 00 00    mov    0x240(%rbx),%rax [*]
          c7 40 40 01 00 00 00    movl   $0x1,0x40(%rax)
      
      With this patch applied, the instruction at [*] is elided, since the
      store to plane->state->plane is known to not alter the value of
      plane->state.
      
      [akpm@linux-foundation.org: coding-style fixes]
      Signed-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      48a27055
  34. 02 5月, 2016 1 次提交
    • A
      driver-core: use 'dev' argument in dev_dbg_ratelimited stub · 1f62ff34
      Arnd Bergmann 提交于
      dev_dbg_ratelimited() is a macro that ignores its first argument when DEBUG is
      not set, which can lead to unused variable warnings:
      
      ethernet/mellanox/mlxsw/pci.c: In function 'mlxsw_pci_cqe_sdq_handle':
      ethernet/mellanox/mlxsw/pci.c:646:18: warning: unused variable 'pdev' [-Wunused-variable]
      ethernet/mellanox/mlxsw/pci.c: In function 'mlxsw_pci_cqe_rdq_handle':
      ethernet/mellanox/mlxsw/pci.c:671:18: warning: unused variable 'pdev' [-Wunused-variable]
      
      The macro already ensures that all its other arguments are silently
      ignored by the compiler without triggering a warning, through the
      use of the no_printk() macro, but the dev argument is not passed into
      that.
      
      This changes the definition to use the same trick as no_printk() with
      an if(0) that leads the compiler to not evaluate the side-effects but
      still see that 'dev' might not be unused.
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Suggested-by: NAndrew Lunn <andrew@lunn.ch>
      Fixes: 6f586e66 ("driver-core: Shut up dev_dbg_reatelimited() without DEBUG")
      Reviewed-by: NDmitry Torokhov <dmitry.torokhov@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1f62ff34
  35. 22 4月, 2016 1 次提交