From 873733188a019acdb7fa253011cbdc0a8afd97f3 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 12 Sep 2006 17:00:10 +0200 Subject: Driver core: convert pcmcia code to use struct device Converts from using struct "class_device" to "struct device" making everything show up properly in /sys/devices/ with symlinks from the /sys/class directory. Cc: Signed-off-by: Greg Kroah-Hartman --- include/pcmcia/ss.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/pcmcia/ss.h b/include/pcmcia/ss.h index 623a0fc0dae..6e84258b94d 100644 --- a/include/pcmcia/ss.h +++ b/include/pcmcia/ss.h @@ -284,7 +284,7 @@ struct pcmcia_socket { #endif /* socket device */ - struct class_device dev; + struct device dev; void *driver_data; /* data internal to the socket driver */ }; -- cgit v1.2.3 From 2943ecf2ed32632473c06f1975db47a7aa98c10f Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 22 Jan 2007 13:45:38 -0800 Subject: Driver core: convert SPI code to use struct device Converts from using struct "class_device" to "struct device" making everything show up properly in /sys/devices/ with symlinks from the /sys/class directory. Cc: Signed-off-by: Greg Kroah-Hartman --- include/linux/spi/spi.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 176f6e36dbf..8c2edd82a07 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -170,7 +170,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) * message's completion function when the transaction completes. */ struct spi_master { - struct class_device cdev; + struct device dev; /* other than negative (== assign one dynamically), bus_num is fully * board-specific. usually that simplifies to being SOC-specific. @@ -216,17 +216,17 @@ struct spi_master { static inline void *spi_master_get_devdata(struct spi_master *master) { - return class_get_devdata(&master->cdev); + return dev_get_drvdata(&master->dev); } static inline void spi_master_set_devdata(struct spi_master *master, void *data) { - class_set_devdata(&master->cdev, data); + dev_set_drvdata(&master->dev, data); } static inline struct spi_master *spi_master_get(struct spi_master *master) { - if (!master || !class_device_get(&master->cdev)) + if (!master || !get_device(&master->dev)) return NULL; return master; } @@ -234,7 +234,7 @@ static inline struct spi_master *spi_master_get(struct spi_master *master) static inline void spi_master_put(struct spi_master *master) { if (master) - class_device_put(&master->cdev); + put_device(&master->dev); } -- cgit v1.2.3 From 43cb76d91ee85f579a69d42bc8efc08bac560278 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 9 Apr 2002 12:14:34 -0700 Subject: Network: convert network devices to use struct device instead of class_device This lets the network core have the ability to handle suspend/resume issues, if it wants to. Thanks to Frederik Deweerdt for the arm driver fixes. Signed-off-by: Greg Kroah-Hartman --- include/linux/netdevice.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index fea0d9db684..2e37f501278 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -529,10 +529,11 @@ struct net_device struct net_bridge_port *br_port; /* class/net/name entry */ - struct class_device class_dev; + struct device dev; /* space for optional statistics and wireless sysfs groups */ struct attribute_group *sysfs_groups[3]; }; +#define to_net_dev(d) container_of(d, struct net_device, dev) #define NETDEV_ALIGN 32 #define NETDEV_ALIGN_CONST (NETDEV_ALIGN - 1) @@ -548,7 +549,7 @@ static inline void *netdev_priv(struct net_device *dev) /* Set the sysfs physical device reference for the network logical device * if set prior to registration will cause a symlink during initialization. */ -#define SET_NETDEV_DEV(net, pdev) ((net)->class_dev.dev = (pdev)) +#define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev)) struct packet_type { __be16 type; /* This is really htons(ether_type). */ -- cgit v1.2.3 From f30c53a873d0d227493197064b8886af2d57bbd6 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 15 Jan 2007 20:22:02 +0100 Subject: MODULES: add the module name for built in kernel drivers Signed-off-by: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- include/linux/device.h | 1 + include/linux/module.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/device.h b/include/linux/device.h index f44247fe813..da722191311 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -126,6 +126,7 @@ struct device_driver { struct klist_node knode_bus; struct module * owner; + const char * mod_name; /* used for built-in modules */ int (*probe) (struct device * dev); int (*remove) (struct device * dev); diff --git a/include/linux/module.h b/include/linux/module.h index 10f771a4999..90dc2542978 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -58,6 +58,7 @@ struct module_kobject { struct kobject kobj; struct module *mod; + struct kobject *drivers_dir; }; /* These are either module local, or the kernel's dummy ones. */ @@ -263,7 +264,6 @@ struct module struct module_attribute *modinfo_attrs; const char *version; const char *srcversion; - struct kobject *drivers_dir; /* Exported symbols */ const struct kernel_symbol *syms; -- cgit v1.2.3 From 725522b5453dd680412f2b6463a988e4fd148757 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 15 Jan 2007 11:50:02 -0800 Subject: PCI: add the sysfs driver name to all modules This adds the module name to all PCI drivers, if they are built into the kernel or not. It will show up in /sys/modules/MODULE_NAME/drivers/ It also fixes up the IDE core, which was calling __pci_register_driver() directly. Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- include/linux/ide.h | 4 ++-- include/linux/pci.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/linux/ide.h b/include/linux/ide.h index e26a03981a9..827688f41d6 100644 --- a/include/linux/ide.h +++ b/include/linux/ide.h @@ -1192,8 +1192,8 @@ void ide_init_disk(struct gendisk *, ide_drive_t *); extern int ideprobe_init(void); extern void ide_scan_pcibus(int scan_direction) __init; -extern int __ide_pci_register_driver(struct pci_driver *driver, struct module *owner); -#define ide_pci_register_driver(d) __ide_pci_register_driver(d, THIS_MODULE) +extern int __ide_pci_register_driver(struct pci_driver *driver, struct module *owner, const char *mod_name); +#define ide_pci_register_driver(d) __ide_pci_register_driver(d, THIS_MODULE, KBUILD_MODNAME) void ide_pci_setup_ports(struct pci_dev *, struct ide_pci_device_s *, int, ata_index_t *); extern void ide_setup_pci_noise (struct pci_dev *dev, struct ide_pci_device_s *d); diff --git a/include/linux/pci.h b/include/linux/pci.h index f3c617eabd8..cb899eb95d3 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -573,10 +573,11 @@ int __must_check pci_bus_alloc_resource(struct pci_bus *bus, void pci_enable_bridges(struct pci_bus *bus); /* Proper probing supporting hot-pluggable devices */ -int __must_check __pci_register_driver(struct pci_driver *, struct module *); +int __must_check __pci_register_driver(struct pci_driver *, struct module *, + const char *mod_name); static inline int __must_check pci_register_driver(struct pci_driver *driver) { - return __pci_register_driver(driver, THIS_MODULE); + return __pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME); } void pci_unregister_driver(struct pci_driver *); -- cgit v1.2.3 From 4b315627e6b894156e235ac905786e7d46aab2e6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 15 Jan 2007 11:50:02 -0800 Subject: SERIO: add the sysfs driver name to all modules This adds the module name to all SERIO drivers, if they are built into the kernel or not. It will show up in /sys/modules/MODULE_NAME/drivers/ Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- include/linux/serio.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/linux/serio.h b/include/linux/serio.h index 0f478a8791a..ac2c70e7f76 100644 --- a/include/linux/serio.h +++ b/include/linux/serio.h @@ -86,6 +86,11 @@ static inline void serio_register_port(struct serio *serio) void serio_unregister_port(struct serio *serio); void serio_unregister_child_port(struct serio *serio); +int __serio_register_driver(struct serio_driver *drv, struct module *owner, const char *mod_name); +static inline int serio_register_driver(struct serio_driver *drv) +{ + return __serio_register_driver(drv, THIS_MODULE, KBUILD_MODNAME); +} int serio_register_driver(struct serio_driver *drv); void serio_unregister_driver(struct serio_driver *drv); -- cgit v1.2.3 From 80f745fb1b0fb11383cbb8df2c36aaaa0399b6e6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 15 Jan 2007 11:50:02 -0800 Subject: USB: add the sysfs driver name to all modules This adds the module name to all USB drivers, if they are built into the kernel or not. It will show up in /sys/modules/MODULE_NAME/drivers/ Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- include/linux/usb.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/linux/usb.h b/include/linux/usb.h index aab5b1b7202..733f38de497 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -868,10 +868,11 @@ struct usb_class_driver { * use these in module_init()/module_exit() * and don't forget MODULE_DEVICE_TABLE(usb, ...) */ -extern int usb_register_driver(struct usb_driver *, struct module *); +extern int usb_register_driver(struct usb_driver *, struct module *, + const char *); static inline int usb_register(struct usb_driver *driver) { - return usb_register_driver(driver, THIS_MODULE); + return usb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME); } extern void usb_deregister(struct usb_driver *); -- cgit v1.2.3 From 270a6c4cad809e92d7b81adde92d0b3d94eeb8ee Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Thu, 18 Jan 2007 13:26:15 +0100 Subject: /sys/modules/*/holders /sys/module/usbcore/ |-- drivers | |-- usb:hub -> ../../../subsystem/usb/drivers/hub | |-- usb:usb -> ../../../subsystem/usb/drivers/usb | `-- usb:usbfs -> ../../../subsystem/usb/drivers/usbfs |-- holders | |-- ehci_hcd -> ../../../module/ehci_hcd | |-- uhci_hcd -> ../../../module/uhci_hcd | |-- usb_storage -> ../../../module/usb_storage | `-- usbhid -> ../../../module/usbhid |-- initstate Signed-off-by: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- include/linux/module.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/linux/module.h b/include/linux/module.h index 90dc2542978..419d3ef293d 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -264,6 +264,7 @@ struct module struct module_attribute *modinfo_attrs; const char *version; const char *srcversion; + struct kobject *holders_dir; /* Exported symbols */ const struct kernel_symbol *syms; -- cgit v1.2.3 From bf0acc330229554c695e4f95e5aa2d2c4f12de1f Mon Sep 17 00:00:00 2001 From: Frank Haverkamp Date: Wed, 17 Jan 2007 17:51:18 +0100 Subject: SYSFS: Fix missing include of list.h in sysfs.h Sysfs.h uses definitions (e.g. struct list_head s_sibling) from list.h but does not include it. Signed-off-by: Frank Haverkamp Signed-off-by: Greg Kroah-Hartman --- include/linux/sysfs.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 2129d1b6c87..eee485957c0 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -11,6 +11,7 @@ #define _SYSFS_H_ #include +#include #include struct kobject; -- cgit v1.2.3 From f9f852df2faf76a2667949ddb4947d4b8f99f02f Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 7 Oct 2006 21:54:55 +0200 Subject: Driver core: add device_type to struct device This allows us to add type specific attributes, uevent vars and release funtions. A subsystem can carry different types of devices like the "block" subsys has disks and partitions. Both types create a different set of attributes, but belong to the same subsystem. This corresponds to the low level objects: kobject -> device (object/device data) kobj_type -> device_type (type of object/device we are embedded in) kset -> class/bus (list of objects/devices of a subsystem) Signed-off-by: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- include/linux/device.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/linux/device.h b/include/linux/device.h index da722191311..e1e164f81ee 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -328,6 +328,13 @@ extern struct class_device *class_device_create(struct class *cls, __attribute__((format(printf,5,6))); extern void class_device_destroy(struct class *cls, dev_t devt); +struct device_type { + struct device_attribute *attrs; + int (*uevent)(struct device *dev, char **envp, int num_envp, + char *buffer, int buffer_size); + void (*release)(struct device *dev); +}; + /* interface for exporting device attributes */ struct device_attribute { struct attribute attr; @@ -356,6 +363,7 @@ struct device { struct kobject kobj; char bus_id[BUS_ID_SIZE]; /* position on parent bus */ + struct device_type *type; unsigned is_registered:1; struct device_attribute uevent_attr; struct device_attribute *devt_attr; -- cgit v1.2.3 From b7a3e813fb84624166f034e25234f98de5846bfc Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 7 Oct 2006 21:54:55 +0200 Subject: Driver core: allow to delay the uevent at device creation time For the block subsystem, we want to delay all uevents until the disk has been scanned and allpartitons are already created before the first event is sent out. Signed-off-by: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- include/linux/device.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/device.h b/include/linux/device.h index e1e164f81ee..5ca1cdba563 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -399,9 +399,10 @@ struct device { /* class_device migration path */ struct list_head node; - struct class *class; /* optional*/ + struct class *class; dev_t devt; /* dev_t, creates the sysfs "dev" */ struct attribute_group **groups; /* optional groups */ + int uevent_suppress; void (*release)(struct device * dev); }; -- cgit v1.2.3 From b592fcfe7f06c15ec11774b5be7ce0de3aa86e73 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Wed, 24 Jan 2007 12:35:52 -0700 Subject: sysfs: Shadow directory support The problem. When implementing a network namespace I need to be able to have multiple network devices with the same name. Currently this is a problem for /sys/class/net/*. What I want is a separate /sys/class/net directory in sysfs for each network namespace, and I want to name each of them /sys/class/net. I looked and the VFS actually allows that. All that is needed is for /sys/class/net to implement a follow link method to redirect lookups to the real directory you want. Implementing a follow link method that is sensitive to the current network namespace turns out to be 3 lines of code so it looks like a clean approach. Modifying sysfs so it doesn't get in my was is a bit trickier. I am calling the concept of multiple directories all at the same path in the filesystem shadow directories. With the directory entry really at that location the shadow master. The following patch modifies sysfs so it can handle a directory structure slightly different from the kobject tree so I can implement the shadow directories for handling /sys/class/net/. Signed-off-by: Eric W. Biederman Cc: Maneesh Soni Signed-off-by: Greg Kroah-Hartman --- include/linux/kobject.h | 4 ++++ include/linux/sysfs.h | 23 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 76538fcf2c4..b850e031053 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -74,9 +74,13 @@ extern void kobject_init(struct kobject *); extern void kobject_cleanup(struct kobject *); extern int __must_check kobject_add(struct kobject *); +extern int __must_check kobject_shadow_add(struct kobject *, struct dentry *); extern void kobject_del(struct kobject *); extern int __must_check kobject_rename(struct kobject *, const char *new_name); +extern int __must_check kobject_shadow_rename(struct kobject *kobj, + struct dentry *new_parent, + const char *new_name); extern int __must_check kobject_move(struct kobject *, struct kobject *); extern int __must_check kobject_register(struct kobject *); diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index eee485957c0..192de3afa96 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -16,6 +16,7 @@ struct kobject; struct module; +struct nameidata; struct attribute { const char * name; @@ -89,13 +90,13 @@ struct sysfs_dirent { #ifdef CONFIG_SYSFS extern int __must_check -sysfs_create_dir(struct kobject *); +sysfs_create_dir(struct kobject *, struct dentry *); extern void sysfs_remove_dir(struct kobject *); extern int __must_check -sysfs_rename_dir(struct kobject *, const char *new_name); +sysfs_rename_dir(struct kobject *, struct dentry *, const char *new_name); extern int __must_check sysfs_move_dir(struct kobject *, struct kobject *); @@ -127,11 +128,17 @@ int __must_check sysfs_create_group(struct kobject *, void sysfs_remove_group(struct kobject *, const struct attribute_group *); void sysfs_notify(struct kobject * k, char *dir, char *attr); + +extern int sysfs_make_shadowed_dir(struct kobject *kobj, + void * (*follow_link)(struct dentry *, struct nameidata *)); +extern struct dentry *sysfs_create_shadow_dir(struct kobject *kobj); +extern void sysfs_remove_shadow_dir(struct dentry *dir); + extern int __must_check sysfs_init(void); #else /* CONFIG_SYSFS */ -static inline int sysfs_create_dir(struct kobject * k) +static inline int sysfs_create_dir(struct kobject * k, struct dentry *shadow) { return 0; } @@ -141,7 +148,9 @@ static inline void sysfs_remove_dir(struct kobject * k) ; } -static inline int sysfs_rename_dir(struct kobject * k, const char *new_name) +static inline int sysfs_rename_dir(struct kobject * k, + struct dentry *new_parent, + const char *new_name) { return 0; } @@ -205,6 +214,12 @@ static inline void sysfs_notify(struct kobject * k, char *dir, char *attr) { } +static inline int sysfs_make_shadowed_dir(struct kobject *kobj, + void * (*follow_link)(struct dentry *, struct nameidata *)) +{ + return 0; +} + static inline int __must_check sysfs_init(void) { return 0; -- cgit v1.2.3