aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/driver.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2005-03-08[PATCH] driver core: clean driver unloadMike Waychison1-7/+6
Get rid of semaphore abuse by converting device_driver->unload_sem semaphore to device_driver->unloaded completion. This should get rid of any confusion as well as save a few bytes in the process. Signed-off-by: Mike Waychison <michael.waychison@sun.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2004-09-23[driver model] Change symbol exports to GPL only in driver.cPatrick Mochel1-8/+8
Signed-off-by: Patrick Mochel <mochel@digitalimplant.org> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2004-07-08[PATCH] Driver core: add driver_find helper to find a driver by its nameDmitry Torokhov1-0/+19
Signed-off-by: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2004-06-09[PATCH] Driver Core: Whitespace fixesDmitry Torokhov1-8/+8
Whitespace and formatting changes (a,b,c -> a, b, c) in drivers/base Signed-off-by: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2004-03-08Driver core: make CONFIG_DEBUG_DRIVER implementation a whole lot cleanerGreg Kroah-Hartman1-4/+0
2004-03-02Driver core: add CONFIG_DEBUG_DRIVER to help track down driver core bugs easier.Greg Kroah-Hartman1-1/+4
2003-06-03[driver model] Update copyrights and license statements. Patrick Mochel1-0/+5
It's a slow afternoon.
2003-04-28driver core: rework driver class structures and logicGreg Kroah-Hartman1-1/+0
Removes the device_class, devclass_attribute, and device_interface structures and replaces them with class, class_device, and class_interface structures. This allows us to have multiple class_device structures per device structures which mirrors the ways things really are within the kernel. It also allows class_device structures to be created later than struct devices as they are naturally created much later in the initialization process of a device.
2003-03-25driver model: Make sure we initialize drivers' class_list.Patrick Mochel1-0/+1
2003-01-09driver model: make sure all debugging defaults to off.Patrick Mochel1-1/+1
2002-11-20driver model: update and clean bus and driver support.Patrick Mochel1-79/+50
This a multi-pronged attack aimed at exploiting the kobject infrastructure mor. - Remove bus_driver_list, in favor of list in bus_subys. - Remove bus_for_each_* and driver_for_each_dev(). They're not being used by anyone, have questionable locking semantics, and really don't provide that much use, as the function returns once the callback fails, with no indication of where it failed. Forget them, at least for now. - Make sure that we return success from bus_match() if device matches, but doesn't have a probe method. - Remove extraneous get_{device,driver}s from bus routines that are serialized by the bus's rwsem. bus_{add,remove}_{device,driver} all take the rwsem, so there is no way we can get a non-existant object when in those functions. - Use the rwsem in the struct subsystem the bus has embedded in it, and kill the separate one in struct bus_type. - Move bulk of driver_register() into bus_add_driver(), which holds the bus's rwsem during the entirety. this will prevent the driver from being unloaded while it's being registered, and two drivers with the same name getting registered at the same time. - Ditto for driver_unregister() and bus_remove_driver(). - Add driver_release() method for the driver bus driver subsystems. (Explained later) - Use only the refcounts in the buses' kobjects, and kill the one in struct bus_type. - Kill struct bus_type::present and struct device_driver::present. These didn't work out the way we intended them to. The idea was to not let a user obtain a rerference count to the object if it was in the process of being unregistered. All the code paths should be fixed now such that their registration is protected with a semaphore, so no partially initialized objects can be removed, and enough infrastructure is moved to the kobject model so that once the object is publically visible, it should be usable by other sources. - Add a bus_sem to serialize bus registration and unregistration. - Add struct device_driver::unload_sem to prevent unloading of drivers with a positive reference count. The driver model has always had a bug that would allow a driver with a positive reference count to be unloaded. It would decrement the reference count and return, letting the module be unloaded, without accounting for the other users of the object. This has been discussed many times, though never resolved cleanly. This should fix the problem in the simplest manner. struct device_driver gets unload_sem, which is initialized to _locked_. When the reference count for the driver reaches 0, the semaphore is unlocked. driver_unregister() blocks on acquiring this lock before it exits. In the normal case that driver_unregister() drops the last reference to the driver, the lock will be acquired immediately, and the module will unload. In the case that someone else is using the driver object, driver_unregister() will not be able to acquire the lock, since the refcount has not reached 0, and the lock has not been released. This means that rmmod(8) will block while drivers' sysfs files are open. There are no sysfs files for drivers yet, but note this when they do have some.
2002-11-18driver model: make sure driver is added to class it belongs to.Patrick Mochel1-0/+4
devclass_{add,remove}_driver() had been implemented, but had never been called.
2002-11-18make sure DEBUG is #undef'd so it's really turned offPatrick Mochel1-1/+1
...since macro using it was changed from #if to #ifdef..
2002-11-16[PATCH] Add some missing includes to drivers/baseMatthew Wilcox1-0/+1
drivers/base relies on device.h pulling in sched.h pulling in the rest of the world. Add some explicit dependencies in preparation for removing sched.h from device.h.
2002-10-30driver model: convert drivers to use kobject and sysfs.Patrick Mochel1-1/+31
- add kobject to struct device_driver and register it when drivers are registered (as member's of their bus's driver subsystem). - convert driverfs callbacks to know about struct kobject. - create links from drivers' directories to devices' directories. - don't even make driverfs directories for drivers anymore.
2002-10-16driver model: protect drivers' device list accesses with bus's rwsem.Patrick Mochel1-16/+13
Drivers must belong to bus, and each bus has an rwsem. Instead of mucking with the device_lock spinlock, and dropping it on each iteration of the loop, we take the bus's lock (read, so multiple drivers can access their list at the same time) around the entire walk of the list.
2002-10-16driver model: simplify device/driver binding. Patrick Mochel1-8/+2
- move list walking and matching to bus.c (since it's a function of the bus driver) - do specialized walks of the bus's lists when binding; no more callbacks being passed to bus_for_each_*. - take rwsem when adding and removing both devices and drivers. lists of each are now fully protected by that rwsem. It's also taken before we walk each list. - move calls of device_{de,at}tach() to bus_{add,remove}_device() and calls of driver_{de,at}tach() to bus_{add,remove}_driver().
2002-10-15driver model: make driver refcounting similar to devices'.Patrick Mochel1-29/+45
In the spirit of devices and buses, change driver refcounting model to match the way that devices and buses are done. struct device_driver gets a ->present field, which is set on registration and cleared in driver_unregister(). get_device() checks the state of this flag and returns NULL if cleared. Note that the horribly wrong remove_driver() is deprecated and simply BUG()s when called. Please convert callers to use driver_unregister(). Updates to callers will be coming soon. Note also that this still doesn't fix the race in which a driver module can be removed while the refcount on a driver > 1. Near future work should help to remedy it, but no solutions are guaranteed..
2002-08-13Update device model lockingPatrick Mochel1-19/+15
Change all iterators of devices to: - use list_for_each - check return of get_device_locked - don't break until we hold the lock if we get an error When a device's reference count hits 0, remove it from all lists, including bus and driver lists. Between the iterator algorithm and the guaranteed removal from the lists, there should never be a device in a list with a reference count of 0. So, whenever we're iterating over the lists, we'll always have a valid device. We don't decrement the refcount until the next iteration of the loop, so we're also guaranteed to get the correct next item in the list.
2002-08-12Update device model locking Patrick Mochel1-14/+11
This updates the device model locking to use device_lock when accessing all lists (the global list, the bus' lists and the drivers' lists). Before the latter two would use their own rwlocks. This also updates get_device() to return a pointer to the struct device if it can successfully increment the reference count. Between these two changes, this should prevent anything gaining an invalid reference to a device that is in the process of being removed: If a device is being removed, it's reference count is 0, but it hasn't necessarily hasn't been removed from its bus's list. If the bus list iterator attempts to access the device, it will take the lock, but will continue on to the next device because the refcount is 0 (and drop the lock). Well, theoretically; the bus iterators still need to be changed, but that's coming next..
2002-08-01driverfs: Move driverfs calls from drivers/base/*.c to drivers/base/fs/*.cPatrick Mochel1-11/+1
This cleans up the drivers/base/ files, so they deal mainly with registration. It also provides a good place to put the glue needed for bus and driver files in driverfs.
2002-06-05Attempt to better locking in device model core: Patrick Mochel1-16/+13
- remove device from driver's list on device_detach - set device's driver to NULL - decrement reference count on driver on device_detach - remove devices from driver's list in driver_detach - use a write_lock instead of read_lock - don't lock around initialization of device fields - assume we have a bus in __remove_driver (we enforce this in driver_register) - do put_bus last in __remove_driver - lock bus around atomic_set in remove_driver and atomic_dec_and_test in put_driver - remove from bus's list while we have it locked
2002-06-05device model updatePatrick Mochel1-2/+2
s/{driver,device}_bind/{driver,device}_attach/ and s/{driver,device}_unbind/{driver,device}_detach/ call bus's match callback instead of bind callback
2002-06-03device model udpate:Patrick Mochel1-9/+26
- make sure drv->devices is initialized on registration (from Peter Osterlund) - add remove_driver for forcing removal of driver There was a potential race with the module unload code. When a pci driver was unloaded, it would call pci_unregister_driver, which would simply call put_driver. If the driver's refcount wasn't 0, it wouldn't unbind it from devices, but the module unload would still continue. If something tried to access the driver later (since everyone thinks its still there), Bad Things would happen. This fixes it until there can be tighter integration between the device model and module unload code.
2002-05-29devicemode: Implement driver_for_each_dev Patrick Mochel1-0/+34
- iterate over all devices a driver has, with proper locking on driver and refcounting on devices
2002-05-28Device Model: Implement centralized device/driver bindingPatrick Mochel1-0/+2
- on device registration, all drivers of bus are iterated over - bus's bind callback is called to match device to driver - if successful, driver's probe callback is called - on device removal, driver's remove callback is called - on driver registration, list of devices is iterated over (and same thing happens)
2002-05-28Beef up centralized driver mgmt:Patrick Mochel1-0/+70
- add name, bus, lock, refcount, bus_list, devices, and dir fields to struct - add release callback to be called when refcount hits 0 - add helpers for registration and refcounting - create directory for driver in bus's directory