1. 25 1月, 2008 3 次提交
    • G
      Driver core: clean up debugging messages · 7dc72b28
      Greg Kroah-Hartman 提交于
      The driver core debugging messages are a mess.  This provides a unified
      message that makes them actually useful.
      
      The format for new kobject debug messages should be:
      	driver/bus/class: 'OBJECT_NAME': FUNCTION_NAME: message.\n
      
      Note, the class code is not changed in this patch due to pending patches
      in my queue that this would conflict with.  A later patch will clean
      them up.
      
      Cc: Kay Sievers <kay.sievers@vrfy.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      7dc72b28
    • G
      Driver core: move the static kobject out of struct driver · e5dd1278
      Greg Kroah-Hartman 提交于
      This patch removes the kobject, and a few other driver-core-only fields
      out of struct driver and into the driver core only.  Now drivers can be
      safely create on the stack or statically (like they currently are.)
      
      Cc: Kay Sievers <kay.sievers@vrfy.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      e5dd1278
    • G
      driver core: remove fields from struct bus_type · c6f7e72a
      Greg Kroah-Hartman 提交于
      struct bus_type is static everywhere in the kernel.  This moves the
      kobject in the structure out of it, and a bunch of other private only to
      the driver core fields are now moved to a private structure.  This lets
      us dynamically create the backing kobject properly and gives us the
      chance to be able to document to users exactly how to use the struct
      bus_type as there are no fields they can improperly access.
      
      Thanks to Kay for the build fixes on this patch.
      
      Cc: Kay Sievers <kay.sievers@vrfy.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      c6f7e72a
  2. 12 7月, 2007 2 次提交
  3. 09 6月, 2007 1 次提交
  4. 03 5月, 2007 1 次提交
  5. 28 4月, 2007 2 次提交
  6. 10 2月, 2007 1 次提交
    • T
      devres: device resource management · 9ac7849e
      Tejun Heo 提交于
      Implement device resource management, in short, devres.  A device
      driver can allocate arbirary size of devres data which is associated
      with a release function.  On driver detach, release function is
      invoked on the devres data, then, devres data is freed.
      
      devreses are typed by associated release functions.  Some devreses are
      better represented by single instance of the type while others need
      multiple instances sharing the same release function.  Both usages are
      supported.
      
      devreses can be grouped using devres group such that a device driver
      can easily release acquired resources halfway through initialization
      or selectively release resources (e.g. resources for port 1 out of 4
      ports).
      
      This patch adds devres core including documentation and the following
      managed interfaces.
      
      * alloc/free	: devm_kzalloc(), devm_kzfree()
      * IO region	: devm_request_region(), devm_release_region()
      * IRQ		: devm_request_irq(), devm_free_irq()
      * DMA		: dmam_alloc_coherent(), dmam_free_coherent(),
      		  dmam_declare_coherent_memory(), dmam_pool_create(),
      		  dmam_pool_destroy()
      * PCI		: pcim_enable_device(), pcim_pin_device(), pci_is_managed()
      * iomap		: devm_ioport_map(), devm_ioport_unmap(), devm_ioremap(),
      		  devm_ioremap_nocache(), devm_iounmap(), pcim_iomap_table(),
      		  pcim_iomap(), pcim_iounmap()
      Signed-off-by: NTejun Heo <htejun@gmail.com>
      Signed-off-by: NJeff Garzik <jeff@garzik.org>
      9ac7849e
  7. 08 2月, 2007 2 次提交
  8. 02 12月, 2006 2 次提交
    • K
      Driver core: fix "driver" symlink timing · 1901fb26
      Kay Sievers 提交于
      Create the "driver" link before the child device may be created by
      the probing logic. This makes it possible for userspace (udev), to
      determine the driver property of the parent device, at the time the
      child device is created.
      Signed-off-by: NKay Sievers <kay.sievers@novell.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      1901fb26
    • B
      Driver core: add notification of bus events · 116af378
      Benjamin Herrenschmidt 提交于
      I finally did as you suggested and added the notifier to the struct
      bus_type itself. There are still problems to be expected is something
      attaches to a bus type where the code can hook in different struct
      device sub-classes (which is imho a big bogosity but I won't even try to
      argue that case now) but it will solve nicely a number of issues I've
      had so far.
      
      That also means that clients interested in registering for such
      notifications have to do it before devices are added and after bus types
      are registered. Fortunately, most bus types that matter for the various
      usage scenarios I have in mind are registerd at postcore_initcall time,
      which means I have a really nice spot at arch_initcall time to add my
      notifiers.
      
      There are 4 notifications provided. Device being added (before hooked to
      the bus) and removed (failure of previous case or after being unhooked
      from the bus), along with driver being bound to a device and about to be
      unbound.
      
      The usage I have for these are:
      
       - The 2 first ones are used to maintain a struct device_ext that is
      hooked to struct device.firmware_data. This structure contains for now a
      pointer to the Open Firmware node related to the device (if any), the
      NUMA node ID (for quick access to it) and the DMA operations pointers &
      iommu table instance for DMA to/from this device. For bus types I own
      (like IBM VIO or EBUS), I just maintain that structure directly from the
      bus code when creating the devices. But for bus types managed by generic
      code like PCI or platform (actually, of_platform which is a variation of
      platform linked to Open Firmware device-tree), I need this notifier.
      
       - The other two ones have a completely different usage scenario. I have
      cases where multiple devices and their drivers depend on each other. For
      example, the IBM EMAC network driver needs to attach to a MAL DMA engine
      which is a separate device, and a PHY interface which is also a separate
      device. They are all of_platform_device's (well, about to be with my
      upcoming patches) but there is no say in what precise order the core
      will "probe" them and instanciate the various modules. The solution I
      found for that is to have the drivers for emac to use multithread_probe,
      and wait for a driver to be bound to the target MAL and PHY control
      devices (the device-tree contains reference to the MAL and PHY interface
      nodes, which I can then match to of_platform_devices). Right now, I've
      been polling, but with that notifier, I can more cleanly wait (with a
      timeout of course).
      Signed-off-by: NBenjamin Herrenschmidt <benh@kernel.crashing.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      116af378
  9. 28 10月, 2006 1 次提交
    • A
      [PATCH] drivers: wait for threaded probes between initcall levels · 735a7ffb
      Andrew Morton 提交于
      The multithreaded-probing code has a problem: after one initcall level (eg,
      core_initcall) has been processed, we will then start processing the next
      level (postcore_initcall) while the kernel threads which are handling
      core_initcall are still executing.  This breaks the guarantees which the
      layered initcalls previously gave us.
      
      IOW, we want to be multithreaded _within_ an initcall level, but not between
      different levels.
      
      Fix that up by causing the probing code to wait for all outstanding probes at
      one level to complete before we start processing the next level.
      
      Cc: Greg KH <greg@kroah.com>
      Signed-off-by: NAndrew Morton <akpm@osdl.org>
      Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
      735a7ffb
  10. 19 10月, 2006 2 次提交
  11. 26 9月, 2006 3 次提交
    • A
      Driver core: Fix potential deadlock in driver core · f2eaae19
      Alan Stern 提交于
      There is a potential deadlock in the driver core.  It boils down to
      the fact that bus_remove_device() calls klist_remove() instead of
      klist_del(), thereby waiting until the reference count of the
      klist_node in the bus's klist of devices drops to 0.  The refcount
      can't reach 0 so long as a modprobe process is trying to bind a new
      driver to the device being removed, by calling __driver_attach().  The
      problem is that __driver_attach() tries to acquire the device's
      parent's semaphore, but the caller of bus_remove_device() is quite
      likely to own that semaphore already.
      
      It isn't sufficient just to replace klist_remove() with klist_del().
      Doing so runs the risk that the device would remain on the bus's klist
      of devices for some time, and so could be bound to another driver even
      after it was unregistered.  What's needed is a new way to distinguish
      whether or not a device is registered, based on a criterion other than
      whether its klist_node is linked into the bus's klist of devices.  That
      way driver binding can fail when the device is unregistered, even if
      it is still linked into the klist.
      
      This patch (as782) implements the solution, by adding a new bitflag to
      indiate when a struct device is registered, by testing the flag before
      allowing a driver to bind a device, and by changing the definition of
      the device_is_registered() inline.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      f2eaae19
    • G
      Driver Core: add ability for drivers to do a threaded probe · d779249e
      Greg Kroah-Hartman 提交于
      This adds the infrastructure for drivers to do a threaded probe, and
      waits at init time for all currently outstanding probes to complete.
      
      A new kernel thread will be created when the probe() function for the
      driver is called, if the multithread_probe bit is set in the driver
      saying it can support this kind of operation.
      
      I have tested this with USB and PCI, and it works, and shaves off a lot
      of time in the boot process, but there are issues with finding root boot
      disks, and some USB drivers assume that this can never happen, so it is
      currently not enabled for any bus type.  Individual drivers can enable
      this right now if they wish, and bus authors can selectivly turn it on
      as well, once they determine that their subsystem will work properly
      with it.
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      d779249e
    • A
      drivers/base: check errors · f86db396
      Andrew Morton 提交于
      Add lots of return-value checking.
      
      <pcornelia.huck@de.ibm.com>: fix bus_rescan_devices()]
      Cc: "Randy.Dunlap" <rdunlap@xenotime.net>
      Signed-off-by: NCornelia Huck <cornelia.huck@de.ibm.com>
      Signed-off-by: NAndrew Morton <akpm@osdl.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      f86db396
  12. 15 4月, 2006 1 次提交
  13. 14 1月, 2006 1 次提交
  14. 05 1月, 2006 1 次提交
    • A
      [PATCH] Hold the device's parent's lock during probe and remove · bf74ad5b
      Alan Stern 提交于
      This patch (as604) makes the driver core hold a device's parent's lock
      as well as the device's lock during calls to the probe and remove
      methods in a driver.  This facility is needed by USB device drivers,
      owing to the peculiar way USB devices work:
      
      	A device provides multiple interfaces, and drivers are bound
      	to interfaces rather than to devices;
      
      	Nevertheless a reset, reset-configuration, suspend, or resume
      	affects the entire device and requires the caller to hold the
      	lock for the device, not just a lock for one of the interfaces.
      
      Since a USB driver's probe method is always called with the interface
      lock held, the locking order rules (always lock parent before child)
      prevent these methods from acquiring the device lock.  The solution
      provided here is to call all probe and remove methods, for all devices
      (not just USB), with the parent lock already acquired.
      
      Although currently only the USB subsystem requires these changes, people
      have mentioned in prior discussion that the overhead of acquiring an
      extra semaphore in all the prove/remove sequences is not overly large.
      
      Up to now, the USB core has been using its own set of private
      semaphores.  A followup patch will remove them, relying entirely on the
      device semaphores provided by the driver core.
      
      The code paths affected by this patch are:
      
      	device_add and device_del: The USB core already holds the parent
      	lock, so no actual change is needed.
      
      	driver_register and driver_unregister: The driver core will now
      	lock both the parent and the device before probing or removing.
      
      	driver_bind and driver_unbind (in sysfs): These routines will
      	now lock both the parent and the device before binding or
      	unbinding.
      
      	bus_rescan_devices: The helper routine will lock the parent
      	before probing a device.
      
      I have not tested this patch for conflicts with other subsystems.  As
      far as I can see, the only possibility of conflict would lie in the
      bus_rescan_devices pathway, and it seems pretty remote.  Nevertheless,
      it would be good for this to get a lot of testing in -mm.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      bf74ad5b
  15. 24 11月, 2005 1 次提交
  16. 22 9月, 2005 1 次提交
    • D
      [PATCH] Driver Core: fis bus rescan devices race · 4c898c7f
      Daniel Ritz 提交于
      bus_rescan_devices_helper() does not hold the dev->sem when it checks for
      !dev->driver().  device_attach() holds the sem, but calls again
      device_bind_driver() even when dev->driver is set.
      
      What happens is that a first device_attach() call (module insertion time)
      is on the way binding the device to a driver.  Another thread calls
      bus_rescan_devices().  Now when bus_rescan_devices_helper() checks for
      dev->driver it is still NULL 'cos the the prior device_attach() is not yet
      finished.  But as soon as the first one releases the dev->sem the second
      device_attach() tries to rebind the already bound device again.
      device_bind_driver() does this blindly which leads to a corrupt
      driver->klist_devices list (the device links itself, the head points to the
      device).  Later a call to device_release_driver() sets dev->driver to NULL
      and breaks the link it has to itself on knode_driver.  Rmmoding the driver
      later calls driver_detach() which leads to an endless loop 'cos the list
      head in klist_devices still points to the device.  And since dev->driver is
      NULL it's stuck with the same device forever.  Boom.  And rmmod hangs.
      
      Very easy to reproduce with new-style pcmcia and a 16bit card.  Just loop
      modprobe <pcmcia-modules> ;cardctl eject; rmmod <card driver, pcmcia
      modules>.
      
      Easiest fix is to check if the device is already bound to a driver in
      device_bind_driver().  This avoids the double binding.
      Signed-off-by: NDaniel Ritz <daniel.ritz@gmx.ch>
      Signed-off-by: NAndrew Morton <akpm@osdl.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
      4c898c7f
  17. 06 9月, 2005 1 次提交
  18. 30 6月, 2005 1 次提交
    • G
      [PATCH] driver core: Add the ability to bind drivers to devices from userspace · afdce75f
      Greg Kroah-Hartman 提交于
      This adds a single file, "bind", to the sysfs directory of every driver
      registered with the driver core.  To bind a device to a driver, write
      the bus id of the device you wish to bind to that specific driver to the
      "bind" file (remember to not add a trailing \n).  If that bus id matches
      a device on that bus, and it does not currently have a driver bound to
      it, the probe sequence will be initiated with that driver and device.
      
      Note, this requires that the driver itself be willing and able to accept
      that device (usually through a device id type table).  This patch does
      not make it possible to override the driver's id table.
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      afdce75f
  19. 21 6月, 2005 8 次提交
    • H
      [PATCH] driver core: fix error handling in bus_add_device · ca2b94ba
      Hannes Reinecke 提交于
      The error handling in bus_add_device() and device_attach() is simply
      non-existing. This patch propagates any error from device_attach to
      the upper layers to allow for a proper recovery.
      
      From: Hannes Reinecke <hare@suse.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      ca2b94ba
    • A
      [PATCH] driver core: Fix races in driver_detach() · c95a6b05
      Alan Stern 提交于
      This patch is intended for your "driver" tree.  It fixes several subtle
      races in driver_detach() and device_release_driver() in the driver-model
      core.
      
      The major change is to use klist_remove() rather than klist_del() when
      taking a device off its driver's list.  There's no other way to guarantee
      that the list pointers will be updated before some other driver binds to
      the device.  For this to work driver_detach() can't use a klist iterator,
      so the loop over the devices must be written out in full.  In addition the
      patch protects against the possibility that, when a driver and a device
      are unregistered at the same time, one may be unloaded from memory before
      the other is finished using it.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      c95a6b05
    • P
      [PATCH] Driver Core: fix bk-driver-core kills ppc64 · 0d3e5a2e
      Patrick Mochel 提交于
      There's no check to see if the device is already bound to a driver, which
      could do bad things.  The first thing to go wrong is that it will try to match
      a driver with a device already bound to one.  In some cases (it appears with
      USB with drivers/usb/core/usb.c::usb_match_id()), some drivers will match a
      device based on the class type, so it would be common (especially for HID
      devices) to match a device that is already bound.
      
      The fun comes when ->probe() is called, it fails, then
      driver_probe_device() does this:
      
      	dev->driver = NULL;
      
      Later on, that pointer could be be dereferenced without checking and cause
      hell to break loose.
      
      This problem could be nasty. It's very hardware dependent, since some
      devices could have a different set of matching qualifiers than others.
      
      Now, I don't quite see exactly where/how you were getting that crash.
      You're dereferencing bad memory, but I'm not sure which pointer was bad
      and where it came from, but it could have come from a couple of different
      places.
      
      The patch below will hopefully fix it all up for you. It's against
      2.6.12-rc2-mm1, and does the following:
      
      - Move logic to driver_probe_device() and comments uncommon returns:
        1 - If device is bound
        0 - If device not bound, and no error
        error - If there was an error.
      
      - Move locking to caller of that function, since we want to lock a
        device for the entire time we're trying to bind it to a driver (to
        prevent against a driver being loaded at the same time).
      
      - Update __device_attach() and __driver_attach() to do that locking.
      
      - Check if device is already bound in __driver_attach()
      
      - Update the converse device_release_driver() so it locks the device
        around all of the operations.
      
      - Mark driver_probe_device() as static and remove export. It's an
        internal function, it should stay that way, and there are no other
        callers. If there is ever a need to export it, we can audit it as
        necessary.
      Signed-off-by: NAndrew Morton <akpm@osdl.org>
      0d3e5a2e
    • G
      [PATCH] Driver core: Fix up the driver and device iterators to be quieter · b86c1df1
      gregkh@suse.de 提交于
      Also stops looping over the lists when a match is found.
      
      Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de
      b86c1df1
    • M
      [PATCH] Call klist_del() instead of klist_remove(). · 0956af53
      mochel@digitalimplant.org 提交于
      - Can't wait on removing the current item in the list (the positive refcount *because*
        we are using it causes it to deadlock).
      Signed-off-by: NPatrick Mochel <mochel@digitalimplant.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      0956af53
    • M
      [PATCH] Use bus_for_each_{dev,drv} for driver binding. · 2287c322
      mochel@digitalimplant.org 提交于
      - Now possible, since the lists are locked using the klist lock and not the
        global rwsem.
      Signed-off-by: NPatrick Mochel <mochel@digitalimplant.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      2287c322
    • M
      [PATCH] Add a klist to struct device_driver for the devices bound to it. · 94e7b1c5
      mochel@digitalimplant.org 提交于
      - Use it in driver_for_each_device() instead of the regular list_head and stop using
        the bus's rwsem for protection.
      - Use driver_for_each_device() in driver_detach() so we don't deadlock on the
        bus's rwsem.
      - Remove ->devices.
      - Move klist access and sysfs link access out from under device's semaphore, since
        they're synchronized through other means.
      Signed-off-by: NPatrick Mochel <mochel@digitalimplant.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      94e7b1c5
    • M
      [PATCH] Move device/driver code to drivers/base/dd.c · 07e4a3e2
      mochel@digitalimplant.org 提交于
      This relocates the driver binding/unbinding code to drivers/base/dd.c. This is done
      for two reasons: One, it's not code related to the bus_type itself; it uses some from
      that, some from devices, and some from drivers. And Two, it will make it easier to do
      some of the upcoming lock removal on that code..
      Signed-off-by: NPatrick Mochel <mochel@digitalimplant.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      07e4a3e2