Skip to content

Commit b51238e

Browse files
committed
qdev: Move doc comments from qdev.c to qdev-core.h
The doc-comments which document the qdev API are split between the header file and the C source files, because as a project we haven't been consistent about where we put them. Move all the doc-comments in qdev.c to the header files, so that users of the APIs don't have to look at the implementation files for this information. In the process, unify them into our doc-comment format and expand on them in some cases to clarify expected use cases. Signed-off-by: Peter Maydell <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Message-id: [email protected]
1 parent 8edbca5 commit b51238e

File tree

3 files changed

+70
-33
lines changed

3 files changed

+70
-33
lines changed

hw/core/qdev.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
128128
}
129129
}
130130

131-
/*
132-
* Create a device on the heap.
133-
* A type @name must exist.
134-
* This only initializes the device state structure and allows
135-
* properties to be set. The device still needs to be realized. See
136-
* qdev-core.h.
137-
*/
138131
DeviceState *qdev_new(const char *name)
139132
{
140133
if (!object_class_by_name(name)) {
@@ -143,11 +136,6 @@ DeviceState *qdev_new(const char *name)
143136
return DEVICE(object_new(name));
144137
}
145138

146-
/*
147-
* Try to create a device on the heap.
148-
* This is like qdev_new(), except it returns %NULL when type @name
149-
* does not exist.
150-
*/
151139
DeviceState *qdev_try_new(const char *name)
152140
{
153141
if (!module_object_class_by_name(name)) {
@@ -378,14 +366,6 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
378366
qdev_unrealize(dev);
379367
}
380368

381-
/*
382-
* Realize @dev.
383-
* @dev must not be plugged into a bus.
384-
* If @bus, plug @dev into @bus. This takes a reference to @dev.
385-
* If @dev has no QOM parent, make one up, taking another reference.
386-
* On success, return true.
387-
* On failure, store an error through @errp and return false.
388-
*/
389369
bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
390370
{
391371
assert(!dev->realized && !dev->parent_bus);
@@ -399,16 +379,6 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
399379
return object_property_set_bool(OBJECT(dev), "realized", true, errp);
400380
}
401381

402-
/*
403-
* Realize @dev and drop a reference.
404-
* This is like qdev_realize(), except the caller must hold a
405-
* (private) reference, which is dropped on return regardless of
406-
* success or failure. Intended use:
407-
* dev = qdev_new();
408-
* [...]
409-
* qdev_realize_and_unref(dev, bus, errp);
410-
* Now @dev can go away without further ado.
411-
*/
412382
bool qdev_realize_and_unref(DeviceState *dev, BusState *bus, Error **errp)
413383
{
414384
bool ret;
@@ -814,9 +784,6 @@ static void qdev_class_add_property(DeviceClass *klass, Property *prop)
814784
prop->info->description);
815785
}
816786

817-
/* @qdev_alias_all_properties - Add alias properties to the source object for
818-
* all qdev properties on the target DeviceState.
819-
*/
820787
void qdev_alias_all_properties(DeviceState *target, Object *source)
821788
{
822789
ObjectClass *class;

include/hw/qdev-core.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,66 @@ compat_props_add(GPtrArray *arr,
320320

321321
/*** Board API. This should go away once we have a machine config file. ***/
322322

323+
/**
324+
* qdev_new: Create a device on the heap
325+
* @name: device type to create (we assert() that this type exists)
326+
*
327+
* This only allocates the memory and initializes the device state
328+
* structure, ready for the caller to set properties if they wish.
329+
* The device still needs to be realized.
330+
* The returned object has a reference count of 1.
331+
*/
323332
DeviceState *qdev_new(const char *name);
333+
/**
334+
* qdev_try_new: Try to create a device on the heap
335+
* @name: device type to create
336+
*
337+
* This is like qdev_new(), except it returns %NULL when type @name
338+
* does not exist, rather than asserting.
339+
*/
324340
DeviceState *qdev_try_new(const char *name);
341+
/**
342+
* qdev_realize: Realize @dev.
343+
* @dev: device to realize
344+
* @bus: bus to plug it into (may be NULL)
345+
* @errp: pointer to error object
346+
*
347+
* "Realize" the device, i.e. perform the second phase of device
348+
* initialization.
349+
* @dev must not be plugged into a bus already.
350+
* If @bus, plug @dev into @bus. This takes a reference to @dev.
351+
* If @dev has no QOM parent, make one up, taking another reference.
352+
* On success, return true.
353+
* On failure, store an error through @errp and return false.
354+
*
355+
* If you created @dev using qdev_new(), you probably want to use
356+
* qdev_realize_and_unref() instead.
357+
*/
325358
bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp);
359+
/**
360+
* qdev_realize_and_unref: Realize @dev and drop a reference
361+
* @dev: device to realize
362+
* @bus: bus to plug it into (may be NULL)
363+
* @errp: pointer to error object
364+
*
365+
* Realize @dev and drop a reference.
366+
* This is like qdev_realize(), except the caller must hold a
367+
* (private) reference, which is dropped on return regardless of
368+
* success or failure. Intended use::
369+
*
370+
* dev = qdev_new();
371+
* [...]
372+
* qdev_realize_and_unref(dev, bus, errp);
373+
*
374+
* Now @dev can go away without further ado.
375+
*
376+
* If you are embedding the device into some other QOM device and
377+
* initialized it via some variant on object_initialize_child() then
378+
* do not use this function, because that family of functions arrange
379+
* for the only reference to the child device to be held by the parent
380+
* via the child<> property, and so the reference-count-drop done here
381+
* would be incorrect. For that use case you want qdev_realize().
382+
*/
326383
bool qdev_realize_and_unref(DeviceState *dev, BusState *bus, Error **errp);
327384
void qdev_unrealize(DeviceState *dev);
328385
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,

include/hw/qdev-properties.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
282282
*/
283283
void qdev_property_add_static(DeviceState *dev, Property *prop);
284284

285+
/**
286+
* qdev_alias_all_properties: Create aliases on source for all target properties
287+
* @target: Device which has properties to be aliased
288+
* @source: Object to add alias properties to
289+
*
290+
* Add alias properties to the @source object for all qdev properties on
291+
* the @target DeviceState.
292+
*
293+
* This is useful when @target is an internal implementation object
294+
* owned by @source, and you want to expose all the properties of that
295+
* implementation object as properties on the @source object so that users
296+
* of @source can set them.
297+
*/
285298
void qdev_alias_all_properties(DeviceState *target, Object *source);
286299

287300
/**

0 commit comments

Comments
 (0)