16494d708SSimon Glass /* 26494d708SSimon Glass * Copyright (c) 2013 Google, Inc 36494d708SSimon Glass * 46494d708SSimon Glass * (C) Copyright 2012 56494d708SSimon Glass * Pavel Herrmann <morpheus.ibis@gmail.com> 66494d708SSimon Glass * 76494d708SSimon Glass * SPDX-License-Identifier: GPL-2.0+ 86494d708SSimon Glass */ 96494d708SSimon Glass 106494d708SSimon Glass #ifndef _DM_ROOT_H_ 116494d708SSimon Glass #define _DM_ROOT_H_ 126494d708SSimon Glass 1354c5d08aSHeiko Schocher struct udevice; 146494d708SSimon Glass 156494d708SSimon Glass /** 166494d708SSimon Glass * dm_root() - Return pointer to the top of the driver tree 176494d708SSimon Glass * 186494d708SSimon Glass * This function returns pointer to the root node of the driver tree, 196494d708SSimon Glass * 206494d708SSimon Glass * @return pointer to root device, or NULL if not inited yet 216494d708SSimon Glass */ 2254c5d08aSHeiko Schocher struct udevice *dm_root(void); 236494d708SSimon Glass 242f11cd91SSimon Glass struct global_data; 252f11cd91SSimon Glass /** 262f11cd91SSimon Glass * dm_fixup_for_gd_move() - Handle global_data moving to a new place 272f11cd91SSimon Glass * 282f11cd91SSimon Glass * The uclass list is part of global_data. Due to the way lists work, moving 292f11cd91SSimon Glass * the list will cause it to become invalid. This function fixes that up so 302f11cd91SSimon Glass * that the uclass list will work correctly. 312f11cd91SSimon Glass */ 322f11cd91SSimon Glass void dm_fixup_for_gd_move(struct global_data *new_gd); 332f11cd91SSimon Glass 346494d708SSimon Glass /** 356494d708SSimon Glass * dm_scan_platdata() - Scan all platform data and bind drivers 366494d708SSimon Glass * 376494d708SSimon Glass * This scans all available platdata and creates drivers for each 386494d708SSimon Glass * 3900606d7eSSimon Glass * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC 4000606d7eSSimon Glass * flag. If false bind all drivers. 416494d708SSimon Glass * @return 0 if OK, -ve on error 426494d708SSimon Glass */ 4300606d7eSSimon Glass int dm_scan_platdata(bool pre_reloc_only); 446494d708SSimon Glass 456494d708SSimon Glass /** 466494d708SSimon Glass * dm_scan_fdt() - Scan the device tree and bind drivers 476494d708SSimon Glass * 480040b944SSimon Glass * This scans the device tree and creates a driver for each node. Only 490040b944SSimon Glass * the top-level subnodes are examined. 506494d708SSimon Glass * 516494d708SSimon Glass * @blob: Pointer to device tree blob 5200606d7eSSimon Glass * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC 5300606d7eSSimon Glass * flag. If false bind all drivers. 546494d708SSimon Glass * @return 0 if OK, -ve on error 556494d708SSimon Glass */ 5600606d7eSSimon Glass int dm_scan_fdt(const void *blob, bool pre_reloc_only); 576494d708SSimon Glass 586494d708SSimon Glass /** 591ca7e206SSimon Glass * dm_scan_fdt_node() - Scan the device tree and bind drivers for a node 601ca7e206SSimon Glass * 611ca7e206SSimon Glass * This scans the subnodes of a device tree node and and creates a driver 621ca7e206SSimon Glass * for each one. 631ca7e206SSimon Glass * 641ca7e206SSimon Glass * @parent: Parent device for the devices that will be created 651ca7e206SSimon Glass * @blob: Pointer to device tree blob 661ca7e206SSimon Glass * @offset: Offset of node to scan 671ca7e206SSimon Glass * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC 681ca7e206SSimon Glass * flag. If false bind all drivers. 691ca7e206SSimon Glass * @return 0 if OK, -ve on error 701ca7e206SSimon Glass */ 711ca7e206SSimon Glass int dm_scan_fdt_node(struct udevice *parent, const void *blob, int offset, 721ca7e206SSimon Glass bool pre_reloc_only); 731ca7e206SSimon Glass 741ca7e206SSimon Glass /** 75bb58503dSSimon Glass * dm_scan_other() - Scan for other devices 76bb58503dSSimon Glass * 77bb58503dSSimon Glass * Some devices may not be visible to Driver Model. This weak function can 78bb58503dSSimon Glass * be provided by boards which wish to create their own devices 79bb58503dSSimon Glass * programmaticaly. They should do this by calling device_bind() on each 80bb58503dSSimon Glass * device. 81bb58503dSSimon Glass * 82bb58503dSSimon Glass * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC 83bb58503dSSimon Glass * flag. If false bind all drivers. 84bb58503dSSimon Glass */ 85bb58503dSSimon Glass int dm_scan_other(bool pre_reloc_only); 86bb58503dSSimon Glass 87bb58503dSSimon Glass /** 88ab7cd627SSimon Glass * dm_init_and_scan() - Initialise Driver Model structures and scan for devices 89ab7cd627SSimon Glass * 90ab7cd627SSimon Glass * This function initialises the roots of the driver tree and uclass trees, 91ab7cd627SSimon Glass * then scans and binds available devices from platform data and the FDT. 92ab7cd627SSimon Glass * This calls dm_init() to set up Driver Model structures. 93ab7cd627SSimon Glass * 94ab7cd627SSimon Glass * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC 95ab7cd627SSimon Glass * flag. If false bind all drivers. 96ab7cd627SSimon Glass * @return 0 if OK, -ve on error 97ab7cd627SSimon Glass */ 98ab7cd627SSimon Glass int dm_init_and_scan(bool pre_reloc_only); 99ab7cd627SSimon Glass 100ab7cd627SSimon Glass /** 101f2bc6fc3SSimon Glass * dm_init() - Initialise Driver Model structures 1026494d708SSimon Glass * 1036494d708SSimon Glass * This function will initialize roots of driver tree and class tree. 1046494d708SSimon Glass * This needs to be called before anything uses the DM 1056494d708SSimon Glass * 1066494d708SSimon Glass * @return 0 if OK, -ve on error 1076494d708SSimon Glass */ 1086494d708SSimon Glass int dm_init(void); 1096494d708SSimon Glass 1109adbd7a1SSimon Glass /** 1119adbd7a1SSimon Glass * dm_uninit - Uninitialise Driver Model structures 1129adbd7a1SSimon Glass * 1139adbd7a1SSimon Glass * All devices will be removed and unbound 1149adbd7a1SSimon Glass * @return 0 if OK, -ve on error 1159adbd7a1SSimon Glass */ 1169adbd7a1SSimon Glass int dm_uninit(void); 1179adbd7a1SSimon Glass 118*bc85aa40SStefan Roese #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) 119*bc85aa40SStefan Roese /** 120*bc85aa40SStefan Roese * dm_remove_devices_flags - Call remove function of all drivers with 121*bc85aa40SStefan Roese * specific removal flags set to selectively 122*bc85aa40SStefan Roese * remove drivers 123*bc85aa40SStefan Roese * 124*bc85aa40SStefan Roese * All devices with the matching flags set will be removed 125*bc85aa40SStefan Roese * 126*bc85aa40SStefan Roese * @flags: Flags for selective device removal 127*bc85aa40SStefan Roese * @return 0 if OK, -ve on error 128*bc85aa40SStefan Roese */ 129*bc85aa40SStefan Roese int dm_remove_devices_flags(uint flags); 130*bc85aa40SStefan Roese #else 131*bc85aa40SStefan Roese static inline int dm_remove_devices_flags(uint flags) { return 0; } 132*bc85aa40SStefan Roese #endif 133*bc85aa40SStefan Roese 1346494d708SSimon Glass #endif 135