1/* SPDX-License-Identifier: GPL-2.0+ */ 2/* 3 * Copyright (c) 2013 Google, Inc 4 * 5 * (C) Copyright 2012 6 * Pavel Herrmann <morpheus.ibis@gmail.com> 7 */ 8 9#ifndef _DM_ROOT_H_ 10#define _DM_ROOT_H_ 11 12#include <dm/tag.h> 13 14struct udevice; 15 16/* Head of the uclass list if CONFIG_OF_PLATDATA_INST is enabled */ 17extern struct list_head uclass_head; 18 19/** 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 */ 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/** 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 * 60 * Return: pointer to root device, or NULL if not inited yet 61 */ 62struct udevice *dm_root(void); 63 64struct global_data; 65/** 66 * dm_fixup_for_gd_move() - Handle global_data moving to a new place 67 * 68 * @new_gd: Pointer to the new global data 69 * 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 */ 74void dm_fixup_for_gd_move(struct global_data *new_gd); 75 76/** 77 * dm_scan_plat() - Scan all platform data and bind drivers 78 * 79 * This scans all available plat and creates drivers for each 80 * 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 84 */ 85int dm_scan_plat(bool pre_reloc_only); 86 87/** 88 * dm_scan_fdt() - Scan the device tree and bind drivers 89 * 90 * This scans the device tree and creates a driver for each node. Only 91 * the top-level subnodes are examined. 92 * 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 96 */ 97int dm_scan_fdt(bool pre_reloc_only); 98 99/** 100 * dm_extended_scan() - Scan the device tree and bind drivers 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 * 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 109 */ 110int dm_extended_scan(bool pre_reloc_only); 111 112/** 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 * 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 123 */ 124int dm_scan_other(bool pre_reloc_only); 125 126/** 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 * 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 136 */ 137int dm_init_and_scan(bool pre_reloc_only); 138 139/** 140 * dm_init() - Initialise Driver Model structures 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 * 145 * @of_live: Enable live device tree 146 * Return: 0 if OK, -ve on error 147 */ 148int dm_init(bool of_live); 149 150/** 151 * dm_uninit - Uninitialise Driver Model structures 152 * 153 * All devices will be removed and unbound 154 * Return: 0 if OK, -ve on error 155 */ 156int dm_uninit(void); 157 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 167 * Return: 0 if OK, -ve on error 168 */ 169int dm_remove_devices_flags(uint flags); 170#else 171static inline int dm_remove_devices_flags(uint flags) { return 0; } 172#endif 173 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 */ 180void dm_get_stats(int *device_countp, int *uclass_countp); 181 182/** 183 * dm_get_mem() - Get stats on memory usage in driver model 184 * 185 * @stats: Place to put the information 186 */ 187void dm_get_mem(struct dm_stats *stats); 188 189#endif 190