2 * Device's clock input and output
4 * Copyright GreenSocs 2016-2020
10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
11 * See the COPYING file in the top-level directory.
21 * @dev: the device to add an input clock to
22 * @name: the name of the clock (can't be NULL).
23 * @callback: optional callback to be called on update or NULL.
24 * @opaque: argument for the callback
25 * @returns: a pointer to the newly added clock
27 * Add an input clock to device @dev as a clock named @name.
28 * This adds a child<> property.
29 * The callback will be called with @opaque as opaque parameter.
31 Clock
*qdev_init_clock_in(DeviceState
*dev
, const char *name
,
32 ClockCallback
*callback
, void *opaque
);
35 * qdev_init_clock_out:
36 * @dev: the device to add an output clock to
37 * @name: the name of the clock (can't be NULL).
38 * @returns: a pointer to the newly added clock
40 * Add an output clock to device @dev as a clock named @name.
41 * This adds a child<> property.
43 Clock
*qdev_init_clock_out(DeviceState
*dev
, const char *name
);
47 * @dev: the device which has the clock
48 * @name: the name of the clock (can't be NULL).
49 * @returns: a pointer to the clock
51 * Get the input clock @name from @dev or NULL if does not exist.
53 Clock
*qdev_get_clock_in(DeviceState
*dev
, const char *name
);
57 * @dev: the device which has the clock
58 * @name: the name of the clock (can't be NULL).
59 * @returns: a pointer to the clock
61 * Get the output clock @name from @dev or NULL if does not exist.
63 Clock
*qdev_get_clock_out(DeviceState
*dev
, const char *name
);
66 * qdev_connect_clock_in:
68 * @name: the name of an input clock in @dev
69 * @source: the source clock (an output clock of another device for example)
71 * Set the source clock of input clock @name of device @dev to @source.
72 * @source period update will be propagated to @name clock.
74 * Must be called before @dev is realized.
76 void qdev_connect_clock_in(DeviceState
*dev
, const char *name
, Clock
*source
);
80 * @dev: the device which has the clock
81 * @name: the name of the clock in @dev (can't be NULL)
82 * @alias_dev: the device to add the clock
83 * @alias_name: the name of the clock in @container
84 * @returns: a pointer to the clock
86 * Add a clock @alias_name in @alias_dev which is an alias of the clock @name
87 * in @dev. The direction _in_ or _out_ will the same as the original.
88 * An alias clock must not be modified or used by @alias_dev and should
89 * typically be only only for device composition purpose.
91 Clock
*qdev_alias_clock(DeviceState
*dev
, const char *name
,
92 DeviceState
*alias_dev
, const char *alias_name
);
95 * qdev_finalize_clocklist:
96 * @dev: the device being finalized
98 * Clear the clocklist from @dev. Only used internally in qdev.
100 void qdev_finalize_clocklist(DeviceState
*dev
);
104 * @name: name of the clock (can't be NULL)
105 * @output: indicates whether the clock is input or output
106 * @callback: for inputs, optional callback to be called on clock's update
107 * with device as opaque
108 * @offset: optional offset to store the ClockIn or ClockOut pointer in device
109 * state structure (0 means unused)
111 struct ClockPortInitElem
{
114 ClockCallback
*callback
;
118 #define clock_offset_value(devstate, field) \
119 (offsetof(devstate, field) + \
120 type_check(Clock *, typeof_field(devstate, field)))
122 #define QDEV_CLOCK(out_not_in, devstate, field, cb) { \
123 .name = (stringify(field)), \
124 .is_output = out_not_in, \
126 .offset = clock_offset_value(devstate, field), \
130 * QDEV_CLOCK_(IN|OUT):
131 * @devstate: structure type. @dev argument of qdev_init_clocks below must be
132 * a pointer to that same type.
133 * @field: a field in @_devstate (must be Clock*)
134 * @callback: (for input only) callback (or NULL) to be called with the device
137 * The name of the clock will be derived from @field
139 #define QDEV_CLOCK_IN(devstate, field, callback) \
140 QDEV_CLOCK(false, devstate, field, callback)
142 #define QDEV_CLOCK_OUT(devstate, field) \
143 QDEV_CLOCK(true, devstate, field, NULL)
145 #define QDEV_CLOCK_END { .name = NULL }
147 typedef struct ClockPortInitElem ClockPortInitArray
[];
151 * @dev: the device to add clocks to
152 * @clocks: a QDEV_CLOCK_END-terminated array which contains the
153 * clocks information.
155 void qdev_init_clocks(DeviceState
*dev
, const ClockPortInitArray clocks
);
157 #endif /* QDEV_CLOCK_H */