History

driver core: Add sync_state driver/bus callback

This sync_state driver/bus callback is called once all the consumers of a supplier have probed successfully. This allows the supplier device's driver/bus to sync the supplier device's state to the software state with the guarantee that all the consumers are actively managing the resources provided by the supplier device. To maintain backwards compatibility and ease transition from existing frameworks and resource cleanup schemes, late_initcall_sync is the earliest when the sync_state callback might be called. There is no upper bound on the time by which the sync_state callback has to be called. This is because if a consumer device never probes, the supplier has to maintain its resources in the state left by the bootloader. For example, if the bootloader leaves the display backlight at a fixed voltage and the backlight driver is never probed, you don't want the backlight to ever be turned off after boot up. Also, when multiple devices are added after kernel init, some suppliers could be added before their consumer devices get added. In these instances, the supplier devices could get their sync_state callback called right after they probe because the consumers devices haven't had a chance to create device links to the suppliers. To handle this correctly, this change also provides APIs to pause/resume sync state callbacks so that when multiple devices are added, their sync_state callback evaluation can be postponed to happen after all of them are added. kbuild test robot reported missing documentation for device.state_synced Reported-by: kbuild test robot <lkp@intel.com> Signed-off-by: Saravana Kannan <saravanak@google.com> Link: https://lore.kernel.org/r/20190731221721.187713-5-saravanak@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Saravana Kannan committed 7 years ago

Commit 8f8184d1 parent 690ff782 files · +91 −0Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/device.h+26−0
@@ -84,6 +84,8 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); · 83 unmodified lines
8484 * available at the time this function is called. As in, the
8585 * function should NOT stop at the first failed device link if
8686 * other unlinked supplier devices are present in the system.
87+ * This is necessary for the sync_state() callback to work
88+ * correctly.
8789 *
8890 * Return 0 if device links have been successfully created to all
8991 * the suppliers of this device. Return an error if some of the
@@ -91,6 +93,13 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); · 1 unmodified line
9193 * reattempted in the future.
9294 * @probe: Called when a new device or driver add to this bus, and callback
9395 * the specific driver's probe to initial the matched device.
96+ * @sync_state: Called to sync device state to software state after all the
97+ * state tracking consumers linked to this device (present at
98+ * the time of late_initcall) have successfully bound to a
99+ * driver. If the device has no consumers, this function will
100+ * be called at late_initcall_sync level. If the device has
101+ * consumers that are never bound to a driver, this function
102+ * will never get called until they do.
94103 * @remove: Called when a device removed from this bus.
95104 * @shutdown: Called at shut-down time to quiesce the device.
96105 *
@@ -135,6 +144,7 @@ struct bus_type { · 38 unmodified lines
135144 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
136145 int (*add_links)(struct device *dev);
137146 int (*probe)(struct device *dev);
147+ void (*sync_state)(struct device *dev);
138148 int (*remove)(struct device *dev);
139149 void (*shutdown)(struct device *dev);
140150
@@ -366,6 +376,13 @@ enum probe_type { · 225 unmodified lines
366376 * @probe: Called to query the existence of a specific device,
367377 * whether this driver can work with it, and bind the driver
368378 * to a specific device.
379+ * @sync_state: Called to sync device state to software state after all the
380+ * state tracking consumers linked to this device (present at
381+ * the time of late_initcall) have successfully bound to a
382+ * driver. If the device has no consumers, this function will
383+ * be called at late_initcall_sync level. If the device has
384+ * consumers that are never bound to a driver, this function
385+ * will never get called until they do.
369386 * @remove: Called when the device is removed from the system to
370387 * unbind a device from this driver.
371388 * @shutdown: Called at shut-down time to quiesce the device.
@@ -404,6 +421,7 @@ struct device_driver { · 32 unmodified lines
404421
405422 int (*edit_links)(struct device *dev);
406423 int (*probe) (struct device *dev);
424+ void (*sync_state)(struct device *dev);
407425 int (*remove) (struct device *dev);
408426 void (*shutdown) (struct device *dev);
409427 int (*suspend) (struct device *dev, pm_message_t state);
@@ -1156,12 +1174,14 @@ enum dl_dev_state { · 746 unmodified lines
11561174 * @suppliers: List of links to supplier devices.
11571175 * @consumers: List of links to consumer devices.
11581176 * @needs_suppliers: Hook to global list of devices waiting for suppliers.
1177+ * @defer_sync: Hook to global list of devices that have deferred sync_state.
11591178 * @status: Driver status information.
11601179 */
11611180 struct dev_links_info {
11621181 struct list_head suppliers;
11631182 struct list_head consumers;
11641183 struct list_head needs_suppliers;
1184+ struct list_head defer_sync;
11651185 enum dl_dev_state status;
11661186 };
11671187
@@ -1237,6 +1257,9 @@ struct dev_links_info { · 69 unmodified lines
12371257 * device.
12381258 * @has_edit_links: This device has a driver than is capable of
12391259 * editing the device links created by driver core.
1260+ * @state_synced: The hardware state of this device has been synced to match
1261+ * the software state of this device by calling the driver/bus
1262+ * sync_state() callback.
12401263 * @dma_coherent: this particular device is dma coherent, even if the
12411264 * architecture supports non-coherent devices.
12421265 *
@@ -1331,6 +1354,7 @@ struct device { · 88 unmodified lines
13311354 bool offline:1;
13321355 bool of_node_reused:1;
13331356 bool has_edit_links:1;
1357+ bool state_synced:1;
13341358 #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
13351359 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
13361360 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
@@ -1674,6 +1698,8 @@ struct device_link *device_link_add(struct device *consumer, · 337 unmodified lines
16741698 void device_link_del(struct device_link *link);
16751699 void device_link_remove(void *consumer, struct device *supplier);
16761700 void device_link_remove_from_wfs(struct device *consumer);
1701+void device_links_supplier_sync_state_pause(void);
1702+void device_links_supplier_sync_state_resume(void);
16771703
16781704 #ifndef dev_fmt
16791705 #define dev_fmt(fmt) fmt

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t