Skip to content

Commit a8ae608

Browse files
committed
device.h: move 'struct class' stuff out to device/class.h
device.h has everything and the kitchen sink when it comes to struct device things, so split out the struct class things things to a separate .h file to make things easier to maintain and manage over time. Cc: "Rafael J. Wysocki" <[email protected]> Cc: Suzuki K Poulose <[email protected]> Cc: Saravana Kannan <[email protected]> Cc: Heikki Krogerus <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5aee2bf commit a8ae608

File tree

3 files changed

+268
-240
lines changed

3 files changed

+268
-240
lines changed

drivers/base/class.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Copyright (c) 2003-2004 IBM Corp.
99
*/
1010

11+
#include <linux/device/class.h>
1112
#include <linux/device.h>
1213
#include <linux/module.h>
1314
#include <linux/init.h>

include/linux/device.h

Lines changed: 1 addition & 240 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/gfp.h>
2828
#include <linux/overflow.h>
2929
#include <linux/device/bus.h>
30+
#include <linux/device/class.h>
3031
#include <asm/device.h>
3132

3233
struct device;
@@ -294,246 +295,6 @@ int subsys_system_register(struct bus_type *subsys,
294295
int subsys_virtual_register(struct bus_type *subsys,
295296
const struct attribute_group **groups);
296297

297-
/**
298-
* struct class - device classes
299-
* @name: Name of the class.
300-
* @owner: The module owner.
301-
* @class_groups: Default attributes of this class.
302-
* @dev_groups: Default attributes of the devices that belong to the class.
303-
* @dev_kobj: The kobject that represents this class and links it into the hierarchy.
304-
* @dev_uevent: Called when a device is added, removed from this class, or a
305-
* few other things that generate uevents to add the environment
306-
* variables.
307-
* @devnode: Callback to provide the devtmpfs.
308-
* @class_release: Called to release this class.
309-
* @dev_release: Called to release the device.
310-
* @shutdown_pre: Called at shut-down time before driver shutdown.
311-
* @ns_type: Callbacks so sysfs can detemine namespaces.
312-
* @namespace: Namespace of the device belongs to this class.
313-
* @get_ownership: Allows class to specify uid/gid of the sysfs directories
314-
* for the devices belonging to the class. Usually tied to
315-
* device's namespace.
316-
* @pm: The default device power management operations of this class.
317-
* @p: The private data of the driver core, no one other than the
318-
* driver core can touch this.
319-
*
320-
* A class is a higher-level view of a device that abstracts out low-level
321-
* implementation details. Drivers may see a SCSI disk or an ATA disk, but,
322-
* at the class level, they are all simply disks. Classes allow user space
323-
* to work with devices based on what they do, rather than how they are
324-
* connected or how they work.
325-
*/
326-
struct class {
327-
const char *name;
328-
struct module *owner;
329-
330-
const struct attribute_group **class_groups;
331-
const struct attribute_group **dev_groups;
332-
struct kobject *dev_kobj;
333-
334-
int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
335-
char *(*devnode)(struct device *dev, umode_t *mode);
336-
337-
void (*class_release)(struct class *class);
338-
void (*dev_release)(struct device *dev);
339-
340-
int (*shutdown_pre)(struct device *dev);
341-
342-
const struct kobj_ns_type_operations *ns_type;
343-
const void *(*namespace)(struct device *dev);
344-
345-
void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid);
346-
347-
const struct dev_pm_ops *pm;
348-
349-
struct subsys_private *p;
350-
};
351-
352-
struct class_dev_iter {
353-
struct klist_iter ki;
354-
const struct device_type *type;
355-
};
356-
357-
extern struct kobject *sysfs_dev_block_kobj;
358-
extern struct kobject *sysfs_dev_char_kobj;
359-
extern int __must_check __class_register(struct class *class,
360-
struct lock_class_key *key);
361-
extern void class_unregister(struct class *class);
362-
363-
/* This is a #define to keep the compiler from merging different
364-
* instances of the __key variable */
365-
#define class_register(class) \
366-
({ \
367-
static struct lock_class_key __key; \
368-
__class_register(class, &__key); \
369-
})
370-
371-
struct class_compat;
372-
struct class_compat *class_compat_register(const char *name);
373-
void class_compat_unregister(struct class_compat *cls);
374-
int class_compat_create_link(struct class_compat *cls, struct device *dev,
375-
struct device *device_link);
376-
void class_compat_remove_link(struct class_compat *cls, struct device *dev,
377-
struct device *device_link);
378-
379-
extern void class_dev_iter_init(struct class_dev_iter *iter,
380-
struct class *class,
381-
struct device *start,
382-
const struct device_type *type);
383-
extern struct device *class_dev_iter_next(struct class_dev_iter *iter);
384-
extern void class_dev_iter_exit(struct class_dev_iter *iter);
385-
386-
extern int class_for_each_device(struct class *class, struct device *start,
387-
void *data,
388-
int (*fn)(struct device *dev, void *data));
389-
extern struct device *class_find_device(struct class *class,
390-
struct device *start, const void *data,
391-
int (*match)(struct device *, const void *));
392-
393-
/**
394-
* class_find_device_by_name - device iterator for locating a particular device
395-
* of a specific name.
396-
* @class: class type
397-
* @name: name of the device to match
398-
*/
399-
static inline struct device *class_find_device_by_name(struct class *class,
400-
const char *name)
401-
{
402-
return class_find_device(class, NULL, name, device_match_name);
403-
}
404-
405-
/**
406-
* class_find_device_by_of_node : device iterator for locating a particular device
407-
* matching the of_node.
408-
* @class: class type
409-
* @np: of_node of the device to match.
410-
*/
411-
static inline struct device *
412-
class_find_device_by_of_node(struct class *class, const struct device_node *np)
413-
{
414-
return class_find_device(class, NULL, np, device_match_of_node);
415-
}
416-
417-
/**
418-
* class_find_device_by_fwnode : device iterator for locating a particular device
419-
* matching the fwnode.
420-
* @class: class type
421-
* @fwnode: fwnode of the device to match.
422-
*/
423-
static inline struct device *
424-
class_find_device_by_fwnode(struct class *class,
425-
const struct fwnode_handle *fwnode)
426-
{
427-
return class_find_device(class, NULL, fwnode, device_match_fwnode);
428-
}
429-
430-
/**
431-
* class_find_device_by_devt : device iterator for locating a particular device
432-
* matching the device type.
433-
* @class: class type
434-
* @devt: device type of the device to match.
435-
*/
436-
static inline struct device *class_find_device_by_devt(struct class *class,
437-
dev_t devt)
438-
{
439-
return class_find_device(class, NULL, &devt, device_match_devt);
440-
}
441-
442-
#ifdef CONFIG_ACPI
443-
struct acpi_device;
444-
/**
445-
* class_find_device_by_acpi_dev : device iterator for locating a particular
446-
* device matching the ACPI_COMPANION device.
447-
* @class: class type
448-
* @adev: ACPI_COMPANION device to match.
449-
*/
450-
static inline struct device *
451-
class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
452-
{
453-
return class_find_device(class, NULL, adev, device_match_acpi_dev);
454-
}
455-
#else
456-
static inline struct device *
457-
class_find_device_by_acpi_dev(struct class *class, const void *adev)
458-
{
459-
return NULL;
460-
}
461-
#endif
462-
463-
struct class_attribute {
464-
struct attribute attr;
465-
ssize_t (*show)(struct class *class, struct class_attribute *attr,
466-
char *buf);
467-
ssize_t (*store)(struct class *class, struct class_attribute *attr,
468-
const char *buf, size_t count);
469-
};
470-
471-
#define CLASS_ATTR_RW(_name) \
472-
struct class_attribute class_attr_##_name = __ATTR_RW(_name)
473-
#define CLASS_ATTR_RO(_name) \
474-
struct class_attribute class_attr_##_name = __ATTR_RO(_name)
475-
#define CLASS_ATTR_WO(_name) \
476-
struct class_attribute class_attr_##_name = __ATTR_WO(_name)
477-
478-
extern int __must_check class_create_file_ns(struct class *class,
479-
const struct class_attribute *attr,
480-
const void *ns);
481-
extern void class_remove_file_ns(struct class *class,
482-
const struct class_attribute *attr,
483-
const void *ns);
484-
485-
static inline int __must_check class_create_file(struct class *class,
486-
const struct class_attribute *attr)
487-
{
488-
return class_create_file_ns(class, attr, NULL);
489-
}
490-
491-
static inline void class_remove_file(struct class *class,
492-
const struct class_attribute *attr)
493-
{
494-
return class_remove_file_ns(class, attr, NULL);
495-
}
496-
497-
/* Simple class attribute that is just a static string */
498-
struct class_attribute_string {
499-
struct class_attribute attr;
500-
char *str;
501-
};
502-
503-
/* Currently read-only only */
504-
#define _CLASS_ATTR_STRING(_name, _mode, _str) \
505-
{ __ATTR(_name, _mode, show_class_attr_string, NULL), _str }
506-
#define CLASS_ATTR_STRING(_name, _mode, _str) \
507-
struct class_attribute_string class_attr_##_name = \
508-
_CLASS_ATTR_STRING(_name, _mode, _str)
509-
510-
extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr,
511-
char *buf);
512-
513-
struct class_interface {
514-
struct list_head node;
515-
struct class *class;
516-
517-
int (*add_dev) (struct device *, struct class_interface *);
518-
void (*remove_dev) (struct device *, struct class_interface *);
519-
};
520-
521-
extern int __must_check class_interface_register(struct class_interface *);
522-
extern void class_interface_unregister(struct class_interface *);
523-
524-
extern struct class * __must_check __class_create(struct module *owner,
525-
const char *name,
526-
struct lock_class_key *key);
527-
extern void class_destroy(struct class *cls);
528-
529-
/* This is a #define to keep the compiler from merging different
530-
* instances of the __key variable */
531-
#define class_create(owner, name) \
532-
({ \
533-
static struct lock_class_key __key; \
534-
__class_create(owner, name, &__key); \
535-
})
536-
537298
/*
538299
* The type of device, "struct device" is embedded in. A class
539300
* or bus can contain devices of different types

0 commit comments

Comments
 (0)