Skip to content

Commit 4c002c9

Browse files
committed
device.h: move 'struct driver' stuff out to device/driver.h
device.h has everything and the kitchen sink when it comes to struct device things, so split out the struct driver 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 a8ae608 commit 4c002c9

File tree

4 files changed

+295
-272
lines changed

4 files changed

+295
-272
lines changed

drivers/base/driver.c

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

11+
#include <linux/device/driver.h>
1112
#include <linux/device.h>
1213
#include <linux/module.h>
1314
#include <linux/errno.h>

include/linux/device.h

Lines changed: 1 addition & 271 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/overflow.h>
2929
#include <linux/device/bus.h>
3030
#include <linux/device/class.h>
31+
#include <linux/device/driver.h>
3132
#include <asm/device.h>
3233

3334
struct device;
@@ -45,227 +46,6 @@ struct iommu_fwspec;
4546
struct dev_pin_info;
4647
struct iommu_param;
4748

48-
/**
49-
* enum probe_type - device driver probe type to try
50-
* Device drivers may opt in for special handling of their
51-
* respective probe routines. This tells the core what to
52-
* expect and prefer.
53-
*
54-
* @PROBE_DEFAULT_STRATEGY: Used by drivers that work equally well
55-
* whether probed synchronously or asynchronously.
56-
* @PROBE_PREFER_ASYNCHRONOUS: Drivers for "slow" devices which
57-
* probing order is not essential for booting the system may
58-
* opt into executing their probes asynchronously.
59-
* @PROBE_FORCE_SYNCHRONOUS: Use this to annotate drivers that need
60-
* their probe routines to run synchronously with driver and
61-
* device registration (with the exception of -EPROBE_DEFER
62-
* handling - re-probing always ends up being done asynchronously).
63-
*
64-
* Note that the end goal is to switch the kernel to use asynchronous
65-
* probing by default, so annotating drivers with
66-
* %PROBE_PREFER_ASYNCHRONOUS is a temporary measure that allows us
67-
* to speed up boot process while we are validating the rest of the
68-
* drivers.
69-
*/
70-
enum probe_type {
71-
PROBE_DEFAULT_STRATEGY,
72-
PROBE_PREFER_ASYNCHRONOUS,
73-
PROBE_FORCE_SYNCHRONOUS,
74-
};
75-
76-
/**
77-
* struct device_driver - The basic device driver structure
78-
* @name: Name of the device driver.
79-
* @bus: The bus which the device of this driver belongs to.
80-
* @owner: The module owner.
81-
* @mod_name: Used for built-in modules.
82-
* @suppress_bind_attrs: Disables bind/unbind via sysfs.
83-
* @probe_type: Type of the probe (synchronous or asynchronous) to use.
84-
* @of_match_table: The open firmware table.
85-
* @acpi_match_table: The ACPI match table.
86-
* @probe: Called to query the existence of a specific device,
87-
* whether this driver can work with it, and bind the driver
88-
* to a specific device.
89-
* @sync_state: Called to sync device state to software state after all the
90-
* state tracking consumers linked to this device (present at
91-
* the time of late_initcall) have successfully bound to a
92-
* driver. If the device has no consumers, this function will
93-
* be called at late_initcall_sync level. If the device has
94-
* consumers that are never bound to a driver, this function
95-
* will never get called until they do.
96-
* @remove: Called when the device is removed from the system to
97-
* unbind a device from this driver.
98-
* @shutdown: Called at shut-down time to quiesce the device.
99-
* @suspend: Called to put the device to sleep mode. Usually to a
100-
* low power state.
101-
* @resume: Called to bring a device from sleep mode.
102-
* @groups: Default attributes that get created by the driver core
103-
* automatically.
104-
* @dev_groups: Additional attributes attached to device instance once the
105-
* it is bound to the driver.
106-
* @pm: Power management operations of the device which matched
107-
* this driver.
108-
* @coredump: Called when sysfs entry is written to. The device driver
109-
* is expected to call the dev_coredump API resulting in a
110-
* uevent.
111-
* @p: Driver core's private data, no one other than the driver
112-
* core can touch this.
113-
*
114-
* The device driver-model tracks all of the drivers known to the system.
115-
* The main reason for this tracking is to enable the driver core to match
116-
* up drivers with new devices. Once drivers are known objects within the
117-
* system, however, a number of other things become possible. Device drivers
118-
* can export information and configuration variables that are independent
119-
* of any specific device.
120-
*/
121-
struct device_driver {
122-
const char *name;
123-
struct bus_type *bus;
124-
125-
struct module *owner;
126-
const char *mod_name; /* used for built-in modules */
127-
128-
bool suppress_bind_attrs; /* disables bind/unbind via sysfs */
129-
enum probe_type probe_type;
130-
131-
const struct of_device_id *of_match_table;
132-
const struct acpi_device_id *acpi_match_table;
133-
134-
int (*probe) (struct device *dev);
135-
void (*sync_state)(struct device *dev);
136-
int (*remove) (struct device *dev);
137-
void (*shutdown) (struct device *dev);
138-
int (*suspend) (struct device *dev, pm_message_t state);
139-
int (*resume) (struct device *dev);
140-
const struct attribute_group **groups;
141-
const struct attribute_group **dev_groups;
142-
143-
const struct dev_pm_ops *pm;
144-
void (*coredump) (struct device *dev);
145-
146-
struct driver_private *p;
147-
};
148-
149-
150-
extern int __must_check driver_register(struct device_driver *drv);
151-
extern void driver_unregister(struct device_driver *drv);
152-
153-
extern struct device_driver *driver_find(const char *name,
154-
struct bus_type *bus);
155-
extern int driver_probe_done(void);
156-
extern void wait_for_device_probe(void);
157-
158-
/* sysfs interface for exporting driver attributes */
159-
160-
struct driver_attribute {
161-
struct attribute attr;
162-
ssize_t (*show)(struct device_driver *driver, char *buf);
163-
ssize_t (*store)(struct device_driver *driver, const char *buf,
164-
size_t count);
165-
};
166-
167-
#define DRIVER_ATTR_RW(_name) \
168-
struct driver_attribute driver_attr_##_name = __ATTR_RW(_name)
169-
#define DRIVER_ATTR_RO(_name) \
170-
struct driver_attribute driver_attr_##_name = __ATTR_RO(_name)
171-
#define DRIVER_ATTR_WO(_name) \
172-
struct driver_attribute driver_attr_##_name = __ATTR_WO(_name)
173-
174-
extern int __must_check driver_create_file(struct device_driver *driver,
175-
const struct driver_attribute *attr);
176-
extern void driver_remove_file(struct device_driver *driver,
177-
const struct driver_attribute *attr);
178-
179-
extern int __must_check driver_for_each_device(struct device_driver *drv,
180-
struct device *start,
181-
void *data,
182-
int (*fn)(struct device *dev,
183-
void *));
184-
struct device *driver_find_device(struct device_driver *drv,
185-
struct device *start, const void *data,
186-
int (*match)(struct device *dev, const void *data));
187-
188-
/**
189-
* driver_find_device_by_name - device iterator for locating a particular device
190-
* of a specific name.
191-
* @drv: the driver we're iterating
192-
* @name: name of the device to match
193-
*/
194-
static inline struct device *driver_find_device_by_name(struct device_driver *drv,
195-
const char *name)
196-
{
197-
return driver_find_device(drv, NULL, name, device_match_name);
198-
}
199-
200-
/**
201-
* driver_find_device_by_of_node- device iterator for locating a particular device
202-
* by of_node pointer.
203-
* @drv: the driver we're iterating
204-
* @np: of_node pointer to match.
205-
*/
206-
static inline struct device *
207-
driver_find_device_by_of_node(struct device_driver *drv,
208-
const struct device_node *np)
209-
{
210-
return driver_find_device(drv, NULL, np, device_match_of_node);
211-
}
212-
213-
/**
214-
* driver_find_device_by_fwnode- device iterator for locating a particular device
215-
* by fwnode pointer.
216-
* @drv: the driver we're iterating
217-
* @fwnode: fwnode pointer to match.
218-
*/
219-
static inline struct device *
220-
driver_find_device_by_fwnode(struct device_driver *drv,
221-
const struct fwnode_handle *fwnode)
222-
{
223-
return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
224-
}
225-
226-
/**
227-
* driver_find_device_by_devt- device iterator for locating a particular device
228-
* by devt.
229-
* @drv: the driver we're iterating
230-
* @devt: devt pointer to match.
231-
*/
232-
static inline struct device *driver_find_device_by_devt(struct device_driver *drv,
233-
dev_t devt)
234-
{
235-
return driver_find_device(drv, NULL, &devt, device_match_devt);
236-
}
237-
238-
static inline struct device *driver_find_next_device(struct device_driver *drv,
239-
struct device *start)
240-
{
241-
return driver_find_device(drv, start, NULL, device_match_any);
242-
}
243-
244-
#ifdef CONFIG_ACPI
245-
/**
246-
* driver_find_device_by_acpi_dev : device iterator for locating a particular
247-
* device matching the ACPI_COMPANION device.
248-
* @drv: the driver we're iterating
249-
* @adev: ACPI_COMPANION device to match.
250-
*/
251-
static inline struct device *
252-
driver_find_device_by_acpi_dev(struct device_driver *drv,
253-
const struct acpi_device *adev)
254-
{
255-
return driver_find_device(drv, NULL, adev, device_match_acpi_dev);
256-
}
257-
#else
258-
static inline struct device *
259-
driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev)
260-
{
261-
return NULL;
262-
}
263-
#endif
264-
265-
void driver_deferred_probe_add(struct device *dev);
266-
int driver_deferred_probe_check_state(struct device *dev);
267-
int driver_deferred_probe_check_state_continue(struct device *dev);
268-
26949
/**
27050
* struct subsys_interface - interfaces to device functions
27151
* @name: name of the device function
@@ -1018,8 +798,6 @@ static inline struct device_node *dev_of_node(struct device *dev)
1018798
return dev->of_node;
1019799
}
1020800

1021-
void driver_init(void);
1022-
1023801
/*
1024802
* High level routines for use by the bus drivers
1025803
*/
@@ -1193,52 +971,4 @@ extern long sysfs_deprecated;
1193971
#define sysfs_deprecated 0
1194972
#endif
1195973

1196-
/**
1197-
* module_driver() - Helper macro for drivers that don't do anything
1198-
* special in module init/exit. This eliminates a lot of boilerplate.
1199-
* Each module may only use this macro once, and calling it replaces
1200-
* module_init() and module_exit().
1201-
*
1202-
* @__driver: driver name
1203-
* @__register: register function for this driver type
1204-
* @__unregister: unregister function for this driver type
1205-
* @...: Additional arguments to be passed to __register and __unregister.
1206-
*
1207-
* Use this macro to construct bus specific macros for registering
1208-
* drivers, and do not use it on its own.
1209-
*/
1210-
#define module_driver(__driver, __register, __unregister, ...) \
1211-
static int __init __driver##_init(void) \
1212-
{ \
1213-
return __register(&(__driver) , ##__VA_ARGS__); \
1214-
} \
1215-
module_init(__driver##_init); \
1216-
static void __exit __driver##_exit(void) \
1217-
{ \
1218-
__unregister(&(__driver) , ##__VA_ARGS__); \
1219-
} \
1220-
module_exit(__driver##_exit);
1221-
1222-
/**
1223-
* builtin_driver() - Helper macro for drivers that don't do anything
1224-
* special in init and have no exit. This eliminates some boilerplate.
1225-
* Each driver may only use this macro once, and calling it replaces
1226-
* device_initcall (or in some cases, the legacy __initcall). This is
1227-
* meant to be a direct parallel of module_driver() above but without
1228-
* the __exit stuff that is not used for builtin cases.
1229-
*
1230-
* @__driver: driver name
1231-
* @__register: register function for this driver type
1232-
* @...: Additional arguments to be passed to __register
1233-
*
1234-
* Use this macro to construct bus specific macros for registering
1235-
* drivers, and do not use it on its own.
1236-
*/
1237-
#define builtin_driver(__driver, __register, ...) \
1238-
static int __init __driver##_init(void) \
1239-
{ \
1240-
return __register(&(__driver) , ##__VA_ARGS__); \
1241-
} \
1242-
device_initcall(__driver##_init);
1243-
1244974
#endif /* _DEVICE_H_ */

0 commit comments

Comments
 (0)