Skip to content

Commit 3316122

Browse files
gmarullcarlescufi
authored andcommitted
device: s/dev_name/dev_id
The usage of dev_name is misleading, since it does not represent the device name (struct device name field) but the name given to the defined struct device. In practice, it is used as a kind of unique device identtifier, so let's rename it to dev_id. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 8ddd429 commit 3316122

File tree

7 files changed

+136
-140
lines changed

7 files changed

+136
-140
lines changed

include/zephyr/device.h

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ typedef int16_t device_handle_t;
8383
* @brief Expands to the name of a global device object.
8484
*
8585
* @details Return the full name of a device object symbol created by
86-
* DEVICE_DEFINE(), using the dev_name provided to DEVICE_DEFINE().
86+
* DEVICE_DEFINE(), using the dev_id provided to DEVICE_DEFINE().
8787
* This is the name of the global variable storing the device
8888
* structure, not a pointer to the string in the device's @p name
8989
* field.
@@ -95,15 +95,15 @@ typedef int16_t device_handle_t;
9595
* code. In other situations, you are probably looking for
9696
* device_get_binding().
9797
*
98-
* @param name The same @p dev_name token given to DEVICE_DEFINE()
98+
* @param name The same @p dev_id token given to DEVICE_DEFINE()
9999
*
100100
* @return The full name of the device object defined by DEVICE_DEFINE()
101101
*/
102102
#define DEVICE_NAME_GET(name) _CONCAT(__device_, name)
103103

104104
/* Node paths can exceed the maximum size supported by
105105
* device_get_binding() in user mode; this macro synthesizes a unique
106-
* dev_name from a devicetree node while staying within this maximum
106+
* dev_id from a devicetree node while staying within this maximum
107107
* size.
108108
*
109109
* The ordinal used in this name can be mapped to the path by
@@ -121,7 +121,7 @@ typedef int16_t device_handle_t;
121121
* device from a devicetree node, use DEVICE_DT_DEFINE() or
122122
* DEVICE_DT_INST_DEFINE() instead.
123123
*
124-
* @param dev_name A unique token which is used in the name of the
124+
* @param dev_id A unique token which is used in the name of the
125125
* global device structure as a C identifier.
126126
*
127127
* @param drv_name A string name for the device, which will be stored
@@ -152,13 +152,12 @@ typedef int16_t device_handle_t;
152152
*
153153
* @param api_ptr Pointer to the device's API structure. Can be NULL.
154154
*/
155-
#define DEVICE_DEFINE(dev_name, drv_name, init_fn, pm_device, \
156-
data_ptr, cfg_ptr, level, prio, api_ptr) \
157-
Z_DEVICE_STATE_DEFINE(DT_INVALID_NODE, dev_name); \
158-
Z_DEVICE_DEFINE(DT_INVALID_NODE, dev_name, drv_name, init_fn, \
159-
pm_device, \
160-
data_ptr, cfg_ptr, level, prio, api_ptr, \
161-
&Z_DEVICE_STATE_NAME(dev_name))
155+
#define DEVICE_DEFINE(dev_id, drv_name, init_fn, pm_device, data_ptr, cfg_ptr, \
156+
level, prio, api_ptr) \
157+
Z_DEVICE_STATE_DEFINE(DT_INVALID_NODE, dev_id); \
158+
Z_DEVICE_DEFINE(DT_INVALID_NODE, dev_id, drv_name, init_fn, pm_device, \
159+
data_ptr, cfg_ptr, level, prio, api_ptr, \
160+
&Z_DEVICE_STATE_NAME(dev_id))
162161

163162
/**
164163
* @brief Return a string name for a devicetree node.
@@ -215,16 +214,13 @@ typedef int16_t device_handle_t;
215214
*
216215
* @param api_ptr Pointer to the device's API structure. Can be NULL.
217216
*/
218-
#define DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \
219-
data_ptr, cfg_ptr, level, prio, \
220-
api_ptr, ...) \
221-
Z_DEVICE_STATE_DEFINE(node_id, Z_DEVICE_DT_DEV_NAME(node_id)); \
222-
Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_NAME(node_id), \
223-
DEVICE_DT_NAME(node_id), init_fn, \
224-
pm_device, \
225-
data_ptr, cfg_ptr, level, prio, \
226-
api_ptr, \
227-
&Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_NAME(node_id)), \
217+
#define DEVICE_DT_DEFINE(node_id, init_fn, pm_device, data_ptr, cfg_ptr, level,\
218+
prio, api_ptr, ...) \
219+
Z_DEVICE_STATE_DEFINE(node_id, Z_DEVICE_DT_DEV_NAME(node_id)); \
220+
Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_NAME(node_id), \
221+
DEVICE_DT_NAME(node_id), init_fn, pm_device, data_ptr, \
222+
cfg_ptr, level, prio, api_ptr, \
223+
&Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_NAME(node_id)), \
228224
__VA_ARGS__)
229225

230226
/**
@@ -348,9 +344,9 @@ typedef int16_t device_handle_t;
348344
* @brief Obtain a pointer to a device object by name
349345
*
350346
* @details Return the address of a device object created by
351-
* DEVICE_DEFINE(), using the dev_name provided to DEVICE_DEFINE().
347+
* DEVICE_DEFINE(), using the dev_id provided to DEVICE_DEFINE().
352348
*
353-
* @param name The same as dev_name provided to DEVICE_DEFINE()
349+
* @param name The same as dev_id provided to DEVICE_DEFINE()
354350
*
355351
* @return A pointer to the device object created by DEVICE_DEFINE()
356352
*/
@@ -384,7 +380,7 @@ typedef int16_t device_handle_t;
384380
/**
385381
* @brief Get a <tt>const struct init_entry*</tt> from a device by name
386382
*
387-
* @param name The same as dev_name provided to DEVICE_DEFINE()
383+
* @param name The same as dev_id provided to DEVICE_DEFINE()
388384
*
389385
* @return A pointer to the init_entry object created for that device
390386
*/
@@ -804,32 +800,32 @@ static inline bool z_impl_device_is_ready(const struct device *dev)
804800

805801
/**
806802
* @brief Synthesize a unique name for the device state associated with
807-
* dev_name.
803+
* dev_id.
808804
*/
809-
#define Z_DEVICE_STATE_NAME(dev_name) _CONCAT(__devstate_, dev_name)
805+
#define Z_DEVICE_STATE_NAME(dev_id) _CONCAT(__devstate_, dev_id)
810806

811807
/**
812808
* @brief Utility macro to define and initialize the device state.
813809
*
814810
* @param node_id Devicetree node id of the device.
815-
* @param dev_name Device name.
811+
* @param dev_id Device identifier.
816812
*/
817-
#define Z_DEVICE_STATE_DEFINE(node_id, dev_name) \
818-
static struct device_state Z_DEVICE_STATE_NAME(dev_name) \
813+
#define Z_DEVICE_STATE_DEFINE(node_id, dev_id) \
814+
static struct device_state Z_DEVICE_STATE_NAME(dev_id) \
819815
__attribute__((__section__(".z_devstate")))
820816

821817
/**
822818
* @brief Synthesize the name of the object that holds device ordinal and
823819
* dependency data.
824820
*
825821
* @param node_id Devicetree node id of the device.
826-
* @param dev_name Device name.
822+
* @param dev_id Device identifier.
827823
*/
828-
#define Z_DEVICE_HANDLE_NAME(node_id, dev_name) \
824+
#define Z_DEVICE_HANDLE_NAME(node_id, dev_id) \
829825
_CONCAT(__devicehdl_, \
830826
COND_CODE_1(DT_NODE_EXISTS(node_id), \
831827
(node_id), \
832-
(dev_name)))
828+
(dev_id)))
833829

834830
/**
835831
* @brief Expand extra handles with a comma in between.
@@ -881,14 +877,14 @@ static inline bool z_impl_device_is_ready(const struct device *dev)
881877
* `gen_handles.py` must be updated.
882878
*/
883879
BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
884-
#define Z_DEVICE_HANDLES_DEFINE(node_id, dev_name, ...) \
880+
#define Z_DEVICE_HANDLES_DEFINE(node_id, dev_id, ...) \
885881
extern Z_DEVICE_HANDLES_CONST device_handle_t \
886-
Z_DEVICE_HANDLE_NAME(node_id, dev_name)[]; \
882+
Z_DEVICE_HANDLE_NAME(node_id, dev_id)[]; \
887883
Z_DEVICE_HANDLES_CONST device_handle_t \
888884
__aligned(sizeof(device_handle_t)) \
889885
__attribute__((__weak__, \
890886
__section__(".__device_handles_pass1"))) \
891-
Z_DEVICE_HANDLE_NAME(node_id, dev_name)[] = { \
887+
Z_DEVICE_HANDLE_NAME(node_id, dev_id)[] = { \
892888
COND_CODE_1(DT_NODE_EXISTS(node_id), ( \
893889
DT_DEP_ORD(node_id), \
894890
DT_REQUIRES_DEP_ORDS(node_id) \
@@ -961,11 +957,11 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
961957
*
962958
* @param node_id Devicetree node id for the device (DT_INVALID_NODE if a
963959
* software device).
964-
* @param dev_name Name of the defined struct device variable.
960+
* @param dev_id Device identifier (used to name the defined struct device).
965961
* @param drv_name Name of the device.
966962
* @param init_fn Device init function.
967963
* @param pm_device Reference to struct pm_device associated with the device.
968-
* (optional).
964+
* (optional).
969965
* @param data_ptr Reference to device data.
970966
* @param cfg_ptr Reference to device config.
971967
* @param level Initialization level.
@@ -974,21 +970,21 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
974970
* @param state_ptr Reference to device state.
975971
* @param ... Optional dependencies, manually specified.
976972
*/
977-
#define Z_DEVICE_DEFINE(node_id, dev_name, drv_name, init_fn, pm_device, \
973+
#define Z_DEVICE_DEFINE(node_id, dev_id, drv_name, init_fn, pm_device, \
978974
data_ptr, cfg_ptr, level, prio, api_ptr, state_ptr, \
979975
...) \
980-
Z_DEVICE_NAME_CHECK(drv_name); \
976+
Z_DEVICE_NAME_CHECK(name); \
981977
\
982-
Z_DEVICE_HANDLES_DEFINE(node_id, dev_name, __VA_ARGS__); \
978+
Z_DEVICE_HANDLES_DEFINE(node_id, dev_id, __VA_ARGS__); \
983979
\
984980
COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \
985-
const Z_DECL_ALIGN(struct device) DEVICE_NAME_GET(dev_name) \
986-
Z_DEVICE_SECTION(level, prio) __used = Z_DEVICE_INIT( \
987-
drv_name, pm_device, data_ptr, cfg_ptr, api_ptr, \
988-
state_ptr, Z_DEVICE_HANDLE_NAME(node_id, dev_name)); \
981+
const Z_DECL_ALIGN(struct device) DEVICE_NAME_GET(dev_id) \
982+
Z_DEVICE_SECTION(level, prio) __used = \
983+
Z_DEVICE_INIT(name, pm, data, config, api, state, \
984+
Z_DEVICE_HANDLE_NAME(node_id, dev_id)); \
989985
\
990-
Z_INIT_ENTRY_DEFINE(DEVICE_NAME_GET(dev_name), init_fn, \
991-
(&DEVICE_NAME_GET(dev_name)), level, prio)
986+
Z_INIT_ENTRY_DEFINE(DEVICE_NAME_GET(dev_id), init_fn, \
987+
(&DEVICE_NAME_GET(dev_id)), level, prio)
992988

993989
#if defined(CONFIG_HAS_DTS) || defined(__DOXYGEN__)
994990
/**

include/zephyr/drivers/can.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ struct can_device_state {
559559
/**
560560
* @brief Define a statically allocated and section assigned CAN device state
561561
*/
562-
#define Z_CAN_DEVICE_STATE_DEFINE(node_id, dev_name) \
563-
static struct can_device_state Z_DEVICE_STATE_NAME(dev_name) \
562+
#define Z_CAN_DEVICE_STATE_DEFINE(node_id, dev_id) \
563+
static struct can_device_state Z_DEVICE_STATE_NAME(dev_id) \
564564
__attribute__((__section__(".z_devstate")))
565565

566566
/**
@@ -569,8 +569,8 @@ struct can_device_state {
569569
* This does device instance specific initialization of common data (such as stats)
570570
* and calls the given init_fn
571571
*/
572-
#define Z_CAN_INIT_FN(dev_name, init_fn) \
573-
static inline int UTIL_CAT(dev_name, _init)(const struct device *dev) \
572+
#define Z_CAN_INIT_FN(dev_id, init_fn) \
573+
static inline int UTIL_CAT(dev_id, _init)(const struct device *dev) \
574574
{ \
575575
struct can_device_state *state = \
576576
CONTAINER_OF(dev->state, struct can_device_state, devstate); \

include/zephyr/drivers/i2c.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,8 @@ static inline void i2c_xfer_stats(const struct device *dev, struct i2c_msg *msgs
457457
/**
458458
* @brief Define a statically allocated and section assigned i2c device state
459459
*/
460-
#define Z_I2C_DEVICE_STATE_DEFINE(node_id, dev_name) \
461-
static struct i2c_device_state Z_DEVICE_STATE_NAME(dev_name) \
460+
#define Z_I2C_DEVICE_STATE_DEFINE(node_id, dev_id) \
461+
static struct i2c_device_state Z_DEVICE_STATE_NAME(dev_id) \
462462
__attribute__((__section__(".z_devstate")))
463463

464464
/**
@@ -467,8 +467,8 @@ static inline void i2c_xfer_stats(const struct device *dev, struct i2c_msg *msgs
467467
* This does device instance specific initialization of common data (such as stats)
468468
* and calls the given init_fn
469469
*/
470-
#define Z_I2C_INIT_FN(dev_name, init_fn) \
471-
static inline int UTIL_CAT(dev_name, _init)(const struct device *dev) \
470+
#define Z_I2C_INIT_FN(dev_id, init_fn) \
471+
static inline int UTIL_CAT(dev_id, _init)(const struct device *dev) \
472472
{ \
473473
struct i2c_device_state *state = \
474474
CONTAINER_OF(dev->state, struct i2c_device_state, devstate); \

include/zephyr/net/ethernet.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -835,20 +835,20 @@ static inline bool net_eth_get_vlan_status(struct net_if *iface)
835835
#endif
836836

837837
#if defined(CONFIG_NET_VLAN)
838-
#define Z_ETH_NET_DEVICE_INIT(node_id, dev_name, drv_name, init_fn, \
838+
#define Z_ETH_NET_DEVICE_INIT(node_id, dev_id, drv_name, init_fn, \
839839
pm_action_cb, data, cfg, prio, api, mtu) \
840-
Z_DEVICE_STATE_DEFINE(node_id, dev_name); \
841-
Z_DEVICE_DEFINE(node_id, dev_name, drv_name, init_fn, \
840+
Z_DEVICE_STATE_DEFINE(node_id, dev_id); \
841+
Z_DEVICE_DEFINE(node_id, dev_id, drv_name, init_fn, \
842842
pm_action_cb, data, cfg, POST_KERNEL, \
843-
prio, api, &Z_DEVICE_STATE_NAME(dev_name)); \
844-
NET_L2_DATA_INIT(dev_name, 0, NET_L2_GET_CTX_TYPE(ETHERNET_L2));\
845-
NET_IF_INIT(dev_name, 0, ETHERNET_L2, mtu, NET_VLAN_MAX_COUNT)
843+
prio, api, &Z_DEVICE_STATE_NAME(dev_id)); \
844+
NET_L2_DATA_INIT(dev_id, 0, NET_L2_GET_CTX_TYPE(ETHERNET_L2)); \
845+
NET_IF_INIT(dev_id, 0, ETHERNET_L2, mtu, NET_VLAN_MAX_COUNT)
846846

847847
#else /* CONFIG_NET_VLAN */
848848

849-
#define Z_ETH_NET_DEVICE_INIT(node_id, dev_name, drv_name, init_fn, \
849+
#define Z_ETH_NET_DEVICE_INIT(node_id, dev_id, drv_name, init_fn, \
850850
pm_action_cb, data, cfg, prio, api, mtu) \
851-
Z_NET_DEVICE_INIT(node_id, dev_name, drv_name, init_fn, \
851+
Z_NET_DEVICE_INIT(node_id, dev_id, drv_name, init_fn, \
852852
pm_action_cb, data, cfg, prio, api, \
853853
ETHERNET_L2, NET_L2_GET_CTX_TYPE(ETHERNET_L2),\
854854
mtu)
@@ -857,7 +857,7 @@ static inline bool net_eth_get_vlan_status(struct net_if *iface)
857857
/**
858858
* @brief Create an Ethernet network interface and bind it to network device.
859859
*
860-
* @param dev_name Network device name.
860+
* @param dev_id Network device id.
861861
* @param drv_name The name this instance of the driver exposes to
862862
* the system.
863863
* @param init_fn Address to the init function of the driver.
@@ -871,9 +871,9 @@ static inline bool net_eth_get_vlan_status(struct net_if *iface)
871871
* used by the driver. Can be NULL.
872872
* @param mtu Maximum transfer unit in bytes for this network interface.
873873
*/
874-
#define ETH_NET_DEVICE_INIT(dev_name, drv_name, init_fn, pm_action_cb, \
874+
#define ETH_NET_DEVICE_INIT(dev_id, drv_name, init_fn, pm_action_cb, \
875875
data, cfg, prio, api, mtu) \
876-
Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_name, drv_name, \
876+
Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, drv_name, \
877877
init_fn, pm_action_cb, data, cfg, prio, \
878878
api, mtu)
879879

0 commit comments

Comments
 (0)