Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
| 4 | * |
| 5 | * (C) Copyright 2012 |
| 6 | * Pavel Herrmann <morpheus.ibis@gmail.com> |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _DM_ROOT_H_ |
| 10 | #define _DM_ROOT_H_ |
| 11 | |
Simon Glass | 0dfda34 | 2022-05-08 04:39:25 -0600 | [diff] [blame] | 12 | #include <dm/tag.h> |
| 13 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 14 | struct udevice; |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 15 | |
Simon Glass | 3fa9f55 | 2021-03-15 17:25:16 +1300 | [diff] [blame] | 16 | /* Head of the uclass list if CONFIG_OF_PLATDATA_INST is enabled */ |
| 17 | extern struct list_head uclass_head; |
| 18 | |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 19 | /** |
Simon Glass | 0dfda34 | 2022-05-08 04:39:25 -0600 | [diff] [blame] | 20 | * 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 | */ |
| 38 | struct 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 Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 56 | * 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 Delaunay | 0cdd7de | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 60 | * Return: pointer to root device, or NULL if not inited yet |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 61 | */ |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 62 | struct udevice *dm_root(void); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 63 | |
Simon Glass | 2f11cd9 | 2016-11-13 14:21:58 -0700 | [diff] [blame] | 64 | struct global_data; |
| 65 | /** |
| 66 | * dm_fixup_for_gd_move() - Handle global_data moving to a new place |
| 67 | * |
Patrick Delaunay | 0cdd7de | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 68 | * @new_gd: Pointer to the new global data |
| 69 | * |
Simon Glass | 2f11cd9 | 2016-11-13 14:21:58 -0700 | [diff] [blame] | 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. |
| 73 | */ |
| 74 | void dm_fixup_for_gd_move(struct global_data *new_gd); |
| 75 | |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 76 | /** |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 77 | * dm_scan_plat() - Scan all platform data and bind drivers |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 78 | * |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 79 | * This scans all available plat and creates drivers for each |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 80 | * |
Simon Glass | 00606d7 | 2014-07-23 06:55:03 -0600 | [diff] [blame] | 81 | * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC |
| 82 | * flag. If false bind all drivers. |
Patrick Delaunay | 0cdd7de | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 83 | * Return: 0 if OK, -ve on error |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 84 | */ |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 85 | int dm_scan_plat(bool pre_reloc_only); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * dm_scan_fdt() - Scan the device tree and bind drivers |
| 89 | * |
Simon Glass | 0040b94 | 2014-07-23 06:55:17 -0600 | [diff] [blame] | 90 | * This scans the device tree and creates a driver for each node. Only |
| 91 | * the top-level subnodes are examined. |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 92 | * |
Bin Meng | 6244fc6 | 2018-10-10 22:06:59 -0700 | [diff] [blame] | 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. |
Patrick Delaunay | 0cdd7de | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 95 | * Return: 0 if OK, -ve on error |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 96 | */ |
Simon Glass | 725e4fc | 2020-11-28 17:50:09 -0700 | [diff] [blame] | 97 | int dm_scan_fdt(bool pre_reloc_only); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 98 | |
| 99 | /** |
Simon Glass | 8ee05b5 | 2020-11-28 17:50:10 -0700 | [diff] [blame] | 100 | * dm_extended_scan() - Scan the device tree and bind drivers |
Patrice Chotard | e81c986 | 2017-09-04 14:55:56 +0200 | [diff] [blame] | 101 | * |
| 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 Meng | 6244fc6 | 2018-10-10 22:06:59 -0700 | [diff] [blame] | 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. |
Patrick Delaunay | 0cdd7de | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 108 | * Return: 0 if OK, -ve on error |
Patrice Chotard | e81c986 | 2017-09-04 14:55:56 +0200 | [diff] [blame] | 109 | */ |
Simon Glass | 8ee05b5 | 2020-11-28 17:50:10 -0700 | [diff] [blame] | 110 | int dm_extended_scan(bool pre_reloc_only); |
Patrice Chotard | e81c986 | 2017-09-04 14:55:56 +0200 | [diff] [blame] | 111 | |
| 112 | /** |
Simon Glass | bb58503 | 2014-07-23 06:55:23 -0600 | [diff] [blame] | 113 | * 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 Meng | 6244fc6 | 2018-10-10 22:06:59 -0700 | [diff] [blame] | 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. |
Patrick Delaunay | 0cdd7de | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 122 | * Return: 0 if OK, -ve on error |
Simon Glass | bb58503 | 2014-07-23 06:55:23 -0600 | [diff] [blame] | 123 | */ |
| 124 | int dm_scan_other(bool pre_reloc_only); |
| 125 | |
| 126 | /** |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 127 | * 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 Meng | 6244fc6 | 2018-10-10 22:06:59 -0700 | [diff] [blame] | 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. |
Patrick Delaunay | 0cdd7de | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 135 | * Return: 0 if OK, -ve on error |
Simon Glass | ab7cd62 | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 136 | */ |
| 137 | int dm_init_and_scan(bool pre_reloc_only); |
| 138 | |
| 139 | /** |
Simon Glass | f2bc6fc | 2014-06-11 23:29:54 -0600 | [diff] [blame] | 140 | * dm_init() - Initialise Driver Model structures |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 141 | * |
| 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 Glass | 19c8205 | 2017-05-18 20:09:08 -0600 | [diff] [blame] | 145 | * @of_live: Enable live device tree |
Patrick Delaunay | 0cdd7de | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 146 | * Return: 0 if OK, -ve on error |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 147 | */ |
Simon Glass | 19c8205 | 2017-05-18 20:09:08 -0600 | [diff] [blame] | 148 | int dm_init(bool of_live); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 149 | |
Simon Glass | 9adbd7a | 2014-07-23 06:55:01 -0600 | [diff] [blame] | 150 | /** |
| 151 | * dm_uninit - Uninitialise Driver Model structures |
| 152 | * |
| 153 | * All devices will be removed and unbound |
Patrick Delaunay | 0cdd7de | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 154 | * Return: 0 if OK, -ve on error |
Simon Glass | 9adbd7a | 2014-07-23 06:55:01 -0600 | [diff] [blame] | 155 | */ |
| 156 | int dm_uninit(void); |
| 157 | |
Stefan Roese | bc85aa4 | 2017-03-27 10:58:53 +0200 | [diff] [blame] | 158 | #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 Delaunay | 0cdd7de | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 167 | * Return: 0 if OK, -ve on error |
Stefan Roese | bc85aa4 | 2017-03-27 10:58:53 +0200 | [diff] [blame] | 168 | */ |
| 169 | int dm_remove_devices_flags(uint flags); |
| 170 | #else |
| 171 | static inline int dm_remove_devices_flags(uint flags) { return 0; } |
| 172 | #endif |
| 173 | |
Simon Glass | 6476c4d | 2021-12-16 20:59:32 -0700 | [diff] [blame] | 174 | /** |
| 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 | */ |
| 180 | void dm_get_stats(int *device_countp, int *uclass_countp); |
| 181 | |
Simon Glass | 0dfda34 | 2022-05-08 04:39:25 -0600 | [diff] [blame] | 182 | /** |
| 183 | * dm_get_mem() - Get stats on memory usage in driver model |
| 184 | * |
Simon Glass | 2cb4ddb | 2022-05-08 04:39:26 -0600 | [diff] [blame] | 185 | * @stats: Place to put the information |
Simon Glass | 0dfda34 | 2022-05-08 04:39:25 -0600 | [diff] [blame] | 186 | */ |
| 187 | void dm_get_mem(struct dm_stats *stats); |
| 188 | |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 189 | #endif |