dm: core: Add macros to access the new linker lists

Add macros which work with instantiated devices and uclasses, as created
at build time by dtoc. Include variants that can be used in data
structures.

These are mostly used by dtoc but it is worth documenting them fully for
the occasional case where they might come up in user code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2021-03-15 17:25:14 +13:00
parent 851144350b
commit 607f9bcb0d
5 changed files with 179 additions and 2 deletions

View file

@ -114,6 +114,37 @@ struct uclass_driver {
#define UCLASS_DRIVER(__name) \
ll_entry_declare(struct uclass_driver, __name, uclass_driver)
/*
* These two macros DM_UCLASS_DRIVER_REF and DM_UCLASS_DRIVER_REF are only
* allowed in code generated by dtoc, because the ordering is important and if
* other instances creep in then they may mess up the ordering expected by dtoc.
*
* It is OK to use them with 'extern' though, since that does not actually
* add a new record to the linker_list.
*/
/**
* DM_UCLASS_DRIVER_REF() - Get a reference to a uclass driver
*
* This is useful in data structures and code for referencing a uclass_driver at
* build time. Before this is used, an extern UCLASS_DRIVER() must have been
* declared.
*
* For example:
*
* extern UCLASS_DRIVER(clk);
*
* struct uclass_driver *drvs[] = {
* DM_UCLASS_DRIVER_REF(clk),
* };
*
* @_name: Name of the uclass_driver. This must be a valid C identifier, used by
* the linker_list.
* @returns struct uclass_driver * for the uclass driver
*/
#define DM_UCLASS_DRIVER_REF(_name) \
ll_entry_ref(struct uclass_driver, _name, uclass_driver)
/**
* uclass_get_priv() - Get the private data for a uclass
*