@@ -2859,10 +2859,11 @@ function(dt_num_regs var)
28592859endfunction ()
28602860
28612861# Usage:
2862- # dt_reg_addr(<var> PATH <path> [INDEX <idx>])
2862+ # dt_reg_addr(<var> PATH <path> [INDEX <idx>] [NAME <name>] )
28632863#
2864- # Get the base address of the register block at index <idx>.
2865- # If <idx> is omitted, then the value at index 0 will be returned.
2864+ # Get the base address of the register block at index <idx>, or with
2865+ # name <name>. If <idx> and <name> are both omitted, the value at
2866+ # index 0 will be returned. Do not give both <idx> and <name>.
28662867#
28672868# The value will be returned in the <var> parameter.
28682869#
@@ -2875,14 +2876,15 @@ endfunction()
28752876# Results can be:
28762877# - The base address of the register block
28772878# - <var> will be undefined if node does not exists or does not have a register
2878- # block at the requested index.
2879+ # block at the requested index or with the requested name
28792880#
28802881# <var> : Return variable where the address value will be stored
28812882# PATH <path> : Node path
2882- # INDEX <idx> : Index number
2883+ # INDEX <idx> : Register block index number
2884+ # NAME <name> : Register block name
28832885function (dt_reg_addr var)
28842886 set (req_single_args "PATH" )
2885- set (single_args "INDEX" )
2887+ set (single_args "INDEX;NAME " )
28862888 cmake_parse_arguments (DT_REG "" "${req_single_args} ;${single_args} " "" ${ARGN} )
28872889
28882890 if (${ARGV0} IN_LIST req_single_args)
@@ -2897,8 +2899,16 @@ function(dt_reg_addr var)
28972899 endif ()
28982900 endforeach ()
28992901
2900- if (NOT DEFINED DT_REG_INDEX)
2902+ if (DEFINED DT_REG_INDEX AND DEFINED DT_REG_NAME)
2903+ message (FATAL_ERROR "dt_reg_addr(${ARGV0} ...) given both INDEX and NAME" )
2904+ elseif (NOT DEFINED DT_REG_INDEX AND NOT DEFINED DT_REG_NAME)
29012905 set (DT_REG_INDEX 0)
2906+ elseif (DEFINED DT_REG_NAME)
2907+ dt_reg_index_private(DT_REG_INDEX "${DT_REG_PATH} " "${DT_REG_NAME} " )
2908+ if (DT_REG_INDEX EQUAL "-1" )
2909+ set (${var} PARENT_SCOPE)
2910+ return ()
2911+ endif ()
29022912 endif ()
29032913
29042914 dt_path_internal(canonical "${DT_REG_PATH} " )
@@ -2914,10 +2924,11 @@ function(dt_reg_addr var)
29142924endfunction ()
29152925
29162926# Usage:
2917- # dt_reg_size(<var> PATH <path> [INDEX <idx>])
2927+ # dt_reg_size(<var> PATH <path> [INDEX <idx>] [NAME <name>] )
29182928#
2919- # Get the size of the register block at index <idx>.
2920- # If INDEX is omitted, then the value at index 0 will be returned.
2929+ # Get the size of the register block at index <idx>, or with
2930+ # name <name>. If <idx> and <name> are both omitted, the value at
2931+ # index 0 will be returned. Do not give both <idx> and <name>.
29212932#
29222933# The value will be returned in the <value> parameter.
29232934#
@@ -2929,10 +2940,11 @@ endfunction()
29292940#
29302941# <var> : Return variable where the size value will be stored
29312942# PATH <path> : Node path
2932- # INDEX <idx> : Index number
2943+ # INDEX <idx> : Register block index number
2944+ # NAME <name> : Register block name
29332945function (dt_reg_size var)
29342946 set (req_single_args "PATH" )
2935- set (single_args "INDEX" )
2947+ set (single_args "INDEX;NAME " )
29362948 cmake_parse_arguments (DT_REG "" "${req_single_args} ;${single_args} " "" ${ARGN} )
29372949
29382950 if (${ARGV0} IN_LIST req_single_args)
@@ -2947,8 +2959,16 @@ function(dt_reg_size var)
29472959 endif ()
29482960 endforeach ()
29492961
2950- if (NOT DEFINED DT_REG_INDEX)
2962+ if (DEFINED DT_REG_INDEX AND DEFINED DT_REG_NAME)
2963+ message (FATAL_ERROR "dt_reg_size(${ARGV0} ...) given both INDEX and NAME" )
2964+ elseif (NOT DEFINED DT_REG_INDEX AND NOT DEFINED DT_REG_NAME)
29512965 set (DT_REG_INDEX 0)
2966+ elseif (DEFINED DT_REG_NAME)
2967+ dt_reg_index_private(DT_REG_INDEX "${DT_REG_PATH} " "${DT_REG_NAME} " )
2968+ if (DT_REG_INDEX EQUAL "-1" )
2969+ set (${var} PARENT_SCOPE)
2970+ return ()
2971+ endif ()
29522972 endif ()
29532973
29542974 dt_path_internal(canonical "${DT_REG_PATH} " )
@@ -2963,6 +2983,17 @@ function(dt_reg_size var)
29632983 set (${var} ${${var} } PARENT_SCOPE)
29642984endfunction ()
29652985
2986+ # Internal helper for dt_reg_addr/dt_reg_size; not meant to be used directly
2987+ function (dt_reg_index_private var path name )
2988+ dt_prop(reg_names PATH "${path} " PROPERTY "reg-names" )
2989+ if (NOT DEFINED reg_names)
2990+ set (index "-1" )
2991+ else ()
2992+ list (FIND reg_names "${name} " index)
2993+ endif ()
2994+ set (${var} "${index} " PARENT_SCOPE)
2995+ endfunction ()
2996+
29662997# Usage:
29672998# dt_has_chosen(<var> PROPERTY <prop>)
29682999#
0 commit comments