DECLARE_MUTEX(device_sem);
-#define to_dev(obj) container_of(obj,struct device,kobj)
-
/*
* sysfs bindings for devices.
*/
+#define to_dev(obj) container_of(obj,struct device,kobj)
#define to_dev_attr(_attr) container_of(_attr,struct device_attribute,attr)
extern struct attribute * dev_default_attrs[];
.default_attrs = dev_default_attrs,
};
+
+static int dev_hotplug_filter(struct kset *kset, struct kobject *kobj)
+{
+ struct kobj_type *ktype = get_ktype(kobj);
+
+ if (ktype == &ktype_device) {
+ struct device *dev = to_dev(kobj);
+ if (dev->bus)
+ return 1;
+ }
+ return 0;
+}
+
+static char *dev_hotplug_name(struct kset *kset, struct kobject *kobj)
+{
+ struct device *dev = to_dev(kobj);
+
+ return dev->bus->name;
+}
+
+static int dev_hotplug(struct kset *kset, struct kobject *kobj, char **envp,
+ int num_envp, char *buffer, int buffer_size)
+{
+ struct device *dev = to_dev(kobj);
+ int retval = 0;
+
+ if (dev->bus->hotplug) {
+ /* have the bus specific function add its stuff */
+ retval = dev->bus->hotplug (dev, envp, num_envp, buffer, buffer_size);
+ if (retval) {
+ pr_debug ("%s - hotplug() returned %d\n",
+ __FUNCTION__, retval);
+ }
+ }
+
+ return retval;
+}
+
+static struct kset_hotplug_ops device_hotplug_ops = {
+ .filter = dev_hotplug_filter,
+ .name = dev_hotplug_name,
+ .hotplug = dev_hotplug,
+};
+
/**
* device_subsys - structure to be registered with kobject core.
*/
-decl_subsys(devices,&ktype_device);
+decl_subsys(devices, &ktype_device, &device_hotplug_ops);
/**
if (platform_notify)
platform_notify(dev);
- /* notify userspace of device entry */
- dev_hotplug(dev, "add");
-
devclass_add_device(dev);
register_done:
if (error && parent)
if (platform_notify_remove)
platform_notify_remove(dev);
- /* notify userspace that this device is about to disappear */
- dev_hotplug (dev, "remove");
-
bus_remove_device(dev);
kobject_del(&dev->kobj);
* drivers/base/hotplug.c - hotplug call code
*
* Copyright (c) 2000-2001 David Brownell
- * Copyright (c) 2002 Greg Kroah-Hartman
- * Copyright (c) 2002 IBM Corp.
+ * Copyright (c) 2002-2003 Greg Kroah-Hartman
+ * Copyright (c) 2002-2003 IBM Corp.
*
* Based off of drivers/usb/core/usb.c:call_agent(), which was
* written by David Brownell.
if (!hotplug_path [0])
return -ENODEV;
- if (in_interrupt ()) {
- pr_debug ("%s - in_interrupt, not allowed!", __FUNCTION__);
- return -EIO;
- }
-
- if (!current->fs->root) {
- /* don't try to do anything unless we have a root partition */
- pr_debug ("%s - %s -- no FS yet\n", __FUNCTION__, action);
- return -EIO;
- }
-
envp = (char **) kmalloc (NUM_ENVP * sizeof (char *), GFP_KERNEL);
if (!envp)
return -ENOMEM;
return retval;
}
-
-/*
- * dev_hotplug - called when any device is added or removed from a bus
- */
-int dev_hotplug (struct device *dev, const char *action)
-{
- pr_debug ("%s\n", __FUNCTION__);
- if (!dev)
- return -ENODEV;
-
- if (!dev->bus)
- return -ENODEV;
-
- return do_hotplug (dev, dev->bus->name, action, dev->bus->hotplug);
-}
-
-
/*
* class_hotplug - called when a class is added or removed from a device
*/