1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2013 Google, Inc
16 /* Head of the uclass list if CONFIG_OF_PLATDATA_INST is enabled */
17 extern struct list_head uclass_head;
20 * struct dm_stats - Information about driver model memory usage
22 * @total_size: All data
23 * @dev_count: Number of devices
24 * @dev_size: Size of all devices (just the struct udevice)
25 * @dev_name_size: Bytes used by device names
26 * @uc_count: Number of uclasses
27 * @uc_size: Size of all uclasses (just the struct uclass)
28 * @tag_count: Number of tags
29 * @tag_size: Bytes used by all tags
30 * @uc_attach_count: Number of uclasses with attached data (priv)
31 * @uc_attach_size: Total size of that attached data
32 * @attach_count_total: Total number of attached data items for all udevices and
34 * @attach_size_total: Total number of bytes of attached data
35 * @attach_count: Number of devices with attached, for each type
36 * @attach_size: Total number of bytes of attached data, for each type
49 int attach_count_total;
50 int attach_size_total;
51 int attach_count[DM_TAG_ATTACH_COUNT];
52 int attach_size[DM_TAG_ATTACH_COUNT];
56 * dm_root() - Return pointer to the top of the driver tree
58 * This function returns pointer to the root node of the driver tree,
60 * Return: pointer to root device, or NULL if not inited yet
62 struct udevice *dm_root(void);
66 * dm_fixup_for_gd_move() - Handle global_data moving to a new place
68 * @new_gd: Pointer to the new global data
70 * The uclass list is part of global_data. Due to the way lists work, moving
71 * the list will cause it to become invalid. This function fixes that up so
72 * that the uclass list will work correctly.
74 void dm_fixup_for_gd_move(struct global_data *new_gd);
77 * dm_scan_plat() - Scan all platform data and bind drivers
79 * This scans all available plat and creates drivers for each
81 * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC
82 * flag. If false bind all drivers.
83 * Return: 0 if OK, -ve on error
85 int dm_scan_plat(bool pre_reloc_only);
88 * dm_scan_fdt() - Scan the device tree and bind drivers
90 * This scans the device tree and creates a driver for each node. Only
91 * the top-level subnodes are examined.
93 * @pre_reloc_only: If true, bind only nodes with special devicetree properties,
94 * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers.
95 * Return: 0 if OK, -ve on error
97 int dm_scan_fdt(bool pre_reloc_only);
100 * dm_extended_scan() - Scan the device tree and bind drivers
102 * This calls dm_scna_dft() which scans the device tree and creates a driver
103 * for each node. the top-level subnodes are examined and also all sub-nodes
106 * @pre_reloc_only: If true, bind only nodes with special devicetree properties,
107 * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers.
108 * Return: 0 if OK, -ve on error
110 int dm_extended_scan(bool pre_reloc_only);
113 * dm_scan_other() - Scan for other devices
115 * Some devices may not be visible to Driver Model. This weak function can
116 * be provided by boards which wish to create their own devices
117 * programmaticaly. They should do this by calling device_bind() on each
120 * @pre_reloc_only: If true, bind only nodes with special devicetree properties,
121 * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers.
122 * Return: 0 if OK, -ve on error
124 int dm_scan_other(bool pre_reloc_only);
127 * dm_init_and_scan() - Initialise Driver Model structures and scan for devices
129 * This function initialises the roots of the driver tree and uclass trees,
130 * then scans and binds available devices from platform data and the FDT.
131 * This calls dm_init() to set up Driver Model structures.
133 * @pre_reloc_only: If true, bind only nodes with special devicetree properties,
134 * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers.
135 * Return: 0 if OK, -ve on error
137 int dm_init_and_scan(bool pre_reloc_only);
140 * dm_init() - Initialise Driver Model structures
142 * This function will initialize roots of driver tree and class tree.
143 * This needs to be called before anything uses the DM
145 * @of_live: Enable live device tree
146 * Return: 0 if OK, -ve on error
148 int dm_init(bool of_live);
151 * dm_uninit - Uninitialise Driver Model structures
153 * All devices will be removed and unbound
154 * Return: 0 if OK, -ve on error
158 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
160 * dm_remove_devices_flags - Call remove function of all drivers with
161 * specific removal flags set to selectively
164 * All devices with the matching flags set will be removed
166 * @flags: Flags for selective device removal
167 * Return: 0 if OK, -ve on error
169 int dm_remove_devices_flags(uint flags);
172 * dm_remove_devices_active - Call remove function of all active drivers heeding
173 * device dependencies as far as know, i.e. removing
174 * devices marked with DM_FLAG_VITAL last.
176 * All active devices will be removed
178 void dm_remove_devices_active(void);
180 static inline int dm_remove_devices_flags(uint flags) { return 0; }
181 static inline void dm_remove_devices_active(void) { }
185 * dm_get_stats() - Get some stats for driver mode
187 * @device_countp: Returns total number of devices that are bound
188 * @uclass_countp: Returns total number of uclasses in use
190 void dm_get_stats(int *device_countp, int *uclass_countp);
193 * dm_get_mem() - Get stats on memory usage in driver model
195 * @stats: Place to put the information
197 void dm_get_mem(struct dm_stats *stats);