blob: b2f30a842f515d70982ec8af7599a86d12002176 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass6494d702014-02-26 15:59:18 -07002/*
3 * Copyright (c) 2013 Google, Inc
4 *
5 * (C) Copyright 2012
6 * Pavel Herrmann <morpheus.ibis@gmail.com>
Simon Glass6494d702014-02-26 15:59:18 -07007 */
8
9#ifndef _DM_ROOT_H_
10#define _DM_ROOT_H_
11
Simon Glass0dfda342022-05-08 04:39:25 -060012#include <dm/tag.h>
13
Heiko Schocher54c5d082014-05-22 12:43:05 +020014struct udevice;
Simon Glass6494d702014-02-26 15:59:18 -070015
Simon Glass3fa9f552021-03-15 17:25:16 +130016/* Head of the uclass list if CONFIG_OF_PLATDATA_INST is enabled */
17extern struct list_head uclass_head;
18
Simon Glass6494d702014-02-26 15:59:18 -070019/**
Simon Glass0dfda342022-05-08 04:39:25 -060020 * struct dm_stats - Information about driver model memory usage
21 *
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
33 * uclasses
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
37 */
38struct dm_stats {
39 int total_size;
40 int dev_count;
41 int dev_size;
42 int dev_name_size;
43 int uc_count;
44 int uc_size;
45 int tag_count;
46 int tag_size;
47 int uc_attach_count;
48 int uc_attach_size;
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];
53};
54
55/**
Simon Glass6494d702014-02-26 15:59:18 -070056 * dm_root() - Return pointer to the top of the driver tree
57 *
58 * This function returns pointer to the root node of the driver tree,
59 *
Patrick Delaunay0cdd7de2022-01-12 10:53:43 +010060 * Return: pointer to root device, or NULL if not inited yet
Simon Glass6494d702014-02-26 15:59:18 -070061 */
Heiko Schocher54c5d082014-05-22 12:43:05 +020062struct udevice *dm_root(void);
Simon Glass6494d702014-02-26 15:59:18 -070063
Simon Glass2f11cd92016-11-13 14:21:58 -070064struct global_data;
65/**
66 * dm_fixup_for_gd_move() - Handle global_data moving to a new place
67 *
Patrick Delaunay0cdd7de2022-01-12 10:53:43 +010068 * @new_gd: Pointer to the new global data
69 *
Simon Glass2f11cd92016-11-13 14:21:58 -070070 * 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.
73 */
74void dm_fixup_for_gd_move(struct global_data *new_gd);
75
Simon Glass6494d702014-02-26 15:59:18 -070076/**
Simon Glass8a8d24b2020-12-03 16:55:23 -070077 * dm_scan_plat() - Scan all platform data and bind drivers
Simon Glass6494d702014-02-26 15:59:18 -070078 *
Simon Glasscaa4daa2020-12-03 16:55:18 -070079 * This scans all available plat and creates drivers for each
Simon Glass6494d702014-02-26 15:59:18 -070080 *
Simon Glass00606d72014-07-23 06:55:03 -060081 * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC
82 * flag. If false bind all drivers.
Patrick Delaunay0cdd7de2022-01-12 10:53:43 +010083 * Return: 0 if OK, -ve on error
Simon Glass6494d702014-02-26 15:59:18 -070084 */
Simon Glass8a8d24b2020-12-03 16:55:23 -070085int dm_scan_plat(bool pre_reloc_only);
Simon Glass6494d702014-02-26 15:59:18 -070086
87/**
88 * dm_scan_fdt() - Scan the device tree and bind drivers
89 *
Simon Glass0040b942014-07-23 06:55:17 -060090 * This scans the device tree and creates a driver for each node. Only
91 * the top-level subnodes are examined.
Simon Glass6494d702014-02-26 15:59:18 -070092 *
Bin Meng6244fc62018-10-10 22:06:59 -070093 * @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.
Patrick Delaunay0cdd7de2022-01-12 10:53:43 +010095 * Return: 0 if OK, -ve on error
Simon Glass6494d702014-02-26 15:59:18 -070096 */
Simon Glass725e4fc2020-11-28 17:50:09 -070097int dm_scan_fdt(bool pre_reloc_only);
Simon Glass6494d702014-02-26 15:59:18 -070098
99/**
Simon Glass8ee05b52020-11-28 17:50:10 -0700100 * dm_extended_scan() - Scan the device tree and bind drivers
Patrice Chotarde81c9862017-09-04 14:55:56 +0200101 *
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
104 * of "clocks" node.
105 *
Bin Meng6244fc62018-10-10 22:06:59 -0700106 * @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.
Patrick Delaunay0cdd7de2022-01-12 10:53:43 +0100108 * Return: 0 if OK, -ve on error
Patrice Chotarde81c9862017-09-04 14:55:56 +0200109 */
Simon Glass8ee05b52020-11-28 17:50:10 -0700110int dm_extended_scan(bool pre_reloc_only);
Patrice Chotarde81c9862017-09-04 14:55:56 +0200111
112/**
Simon Glassbb585032014-07-23 06:55:23 -0600113 * dm_scan_other() - Scan for other devices
114 *
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
118 * device.
119 *
Bin Meng6244fc62018-10-10 22:06:59 -0700120 * @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.
Patrick Delaunay0cdd7de2022-01-12 10:53:43 +0100122 * Return: 0 if OK, -ve on error
Simon Glassbb585032014-07-23 06:55:23 -0600123 */
124int dm_scan_other(bool pre_reloc_only);
125
126/**
Simon Glassab7cd622014-07-23 06:55:04 -0600127 * dm_init_and_scan() - Initialise Driver Model structures and scan for devices
128 *
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.
132 *
Bin Meng6244fc62018-10-10 22:06:59 -0700133 * @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.
Patrick Delaunay0cdd7de2022-01-12 10:53:43 +0100135 * Return: 0 if OK, -ve on error
Simon Glassab7cd622014-07-23 06:55:04 -0600136 */
137int dm_init_and_scan(bool pre_reloc_only);
138
139/**
Simon Glassf2bc6fc2014-06-11 23:29:54 -0600140 * dm_init() - Initialise Driver Model structures
Simon Glass6494d702014-02-26 15:59:18 -0700141 *
142 * This function will initialize roots of driver tree and class tree.
143 * This needs to be called before anything uses the DM
144 *
Simon Glass19c82052017-05-18 20:09:08 -0600145 * @of_live: Enable live device tree
Patrick Delaunay0cdd7de2022-01-12 10:53:43 +0100146 * Return: 0 if OK, -ve on error
Simon Glass6494d702014-02-26 15:59:18 -0700147 */
Simon Glass19c82052017-05-18 20:09:08 -0600148int dm_init(bool of_live);
Simon Glass6494d702014-02-26 15:59:18 -0700149
Simon Glass9adbd7a2014-07-23 06:55:01 -0600150/**
151 * dm_uninit - Uninitialise Driver Model structures
152 *
153 * All devices will be removed and unbound
Patrick Delaunay0cdd7de2022-01-12 10:53:43 +0100154 * Return: 0 if OK, -ve on error
Simon Glass9adbd7a2014-07-23 06:55:01 -0600155 */
156int dm_uninit(void);
157
Stefan Roesebc85aa42017-03-27 10:58:53 +0200158#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
159/**
160 * dm_remove_devices_flags - Call remove function of all drivers with
161 * specific removal flags set to selectively
162 * remove drivers
163 *
164 * All devices with the matching flags set will be removed
165 *
166 * @flags: Flags for selective device removal
Patrick Delaunay0cdd7de2022-01-12 10:53:43 +0100167 * Return: 0 if OK, -ve on error
Stefan Roesebc85aa42017-03-27 10:58:53 +0200168 */
169int dm_remove_devices_flags(uint flags);
170#else
171static inline int dm_remove_devices_flags(uint flags) { return 0; }
172#endif
173
Simon Glass6476c4d2021-12-16 20:59:32 -0700174/**
175 * dm_get_stats() - Get some stats for driver mode
176 *
177 * @device_countp: Returns total number of devices that are bound
178 * @uclass_countp: Returns total number of uclasses in use
179 */
180void dm_get_stats(int *device_countp, int *uclass_countp);
181
Simon Glass0dfda342022-05-08 04:39:25 -0600182/**
183 * dm_get_mem() - Get stats on memory usage in driver model
184 *
Simon Glass2cb4ddb2022-05-08 04:39:26 -0600185 * @stats: Place to put the information
Simon Glass0dfda342022-05-08 04:39:25 -0600186 */
187void dm_get_mem(struct dm_stats *stats);
188
Simon Glass6494d702014-02-26 15:59:18 -0700189#endif