qdev: integrate with QEMU Object Model (v2)
This is a very shallow integration. We register a TYPE_DEVICE but only use QOM as basically a memory allocator. This will make all devices show up as QOM objects but they will all carry the TYPE_DEVICE. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> --- v1 -> v2 - update for new location of object.h
This commit is contained in:
		
							parent
							
								
									2f28d2ff9d
								
							
						
					
					
						commit
						32fea4025b
					
				
							
								
								
									
										27
									
								
								hw/qdev.c
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								hw/qdev.c
									
									
									
									
									
								
							@ -47,9 +47,17 @@ static BusState *qbus_find(const char *path);
 | 
				
			|||||||
/* Register a new device type.  */
 | 
					/* Register a new device type.  */
 | 
				
			||||||
void qdev_register(DeviceInfo *info)
 | 
					void qdev_register(DeviceInfo *info)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    TypeInfo type_info = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert(info->size >= sizeof(DeviceState));
 | 
					    assert(info->size >= sizeof(DeviceState));
 | 
				
			||||||
    assert(!info->next);
 | 
					    assert(!info->next);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    type_info.name = info->name;
 | 
				
			||||||
 | 
					    type_info.parent = TYPE_DEVICE;
 | 
				
			||||||
 | 
					    type_info.instance_size = info->size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    type_register_static(&type_info);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    info->next = device_info_list;
 | 
					    info->next = device_info_list;
 | 
				
			||||||
    device_info_list = info;
 | 
					    device_info_list = info;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -93,7 +101,7 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
 | 
				
			|||||||
    Property *prop;
 | 
					    Property *prop;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert(bus->info == info->bus_info);
 | 
					    assert(bus->info == info->bus_info);
 | 
				
			||||||
    dev = g_malloc0(info->size);
 | 
					    dev = DEVICE(object_new(info->name));
 | 
				
			||||||
    dev->info = info;
 | 
					    dev->info = info;
 | 
				
			||||||
    dev->parent_bus = bus;
 | 
					    dev->parent_bus = bus;
 | 
				
			||||||
    qdev_prop_set_defaults(dev, dev->info->props);
 | 
					    qdev_prop_set_defaults(dev, dev->info->props);
 | 
				
			||||||
@ -519,7 +527,7 @@ void qdev_free(DeviceState *dev)
 | 
				
			|||||||
    if (dev->ref != 0) {
 | 
					    if (dev->ref != 0) {
 | 
				
			||||||
        qerror_report(QERR_DEVICE_IN_USE, dev->id?:"");
 | 
					        qerror_report(QERR_DEVICE_IN_USE, dev->id?:"");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    g_free(dev);
 | 
					    object_delete(OBJECT(dev));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void qdev_machine_creation_done(void)
 | 
					void qdev_machine_creation_done(void)
 | 
				
			||||||
@ -1572,3 +1580,18 @@ void qdev_machine_init(void)
 | 
				
			|||||||
    qdev_get_peripheral_anon();
 | 
					    qdev_get_peripheral_anon();
 | 
				
			||||||
    qdev_get_peripheral();
 | 
					    qdev_get_peripheral();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static TypeInfo device_type_info = {
 | 
				
			||||||
 | 
					    .name = TYPE_DEVICE,
 | 
				
			||||||
 | 
					    .parent = TYPE_OBJECT,
 | 
				
			||||||
 | 
					    .instance_size = sizeof(DeviceState),
 | 
				
			||||||
 | 
					    .abstract = true,
 | 
				
			||||||
 | 
					    .class_size = sizeof(DeviceClass),
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void init_qdev(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    type_register_static(&device_type_info);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					device_init(init_qdev);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								hw/qdev.h
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								hw/qdev.h
									
									
									
									
									
								
							@ -6,6 +6,7 @@
 | 
				
			|||||||
#include "qemu-char.h"
 | 
					#include "qemu-char.h"
 | 
				
			||||||
#include "qemu-option.h"
 | 
					#include "qemu-option.h"
 | 
				
			||||||
#include "qapi/qapi-visit-core.h"
 | 
					#include "qapi/qapi-visit-core.h"
 | 
				
			||||||
 | 
					#include "qemu/object.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct Property Property;
 | 
					typedef struct Property Property;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -66,9 +67,18 @@ typedef struct DeviceProperty
 | 
				
			|||||||
    QTAILQ_ENTRY(DeviceProperty) node;
 | 
					    QTAILQ_ENTRY(DeviceProperty) node;
 | 
				
			||||||
} DeviceProperty;
 | 
					} DeviceProperty;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define TYPE_DEVICE "device"
 | 
				
			||||||
 | 
					#define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct DeviceClass {
 | 
				
			||||||
 | 
					    ObjectClass parent_class;
 | 
				
			||||||
 | 
					} DeviceClass;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* This structure should not be accessed directly.  We declare it here
 | 
					/* This structure should not be accessed directly.  We declare it here
 | 
				
			||||||
   so that it can be embedded in individual device state structures.  */
 | 
					   so that it can be embedded in individual device state structures.  */
 | 
				
			||||||
struct DeviceState {
 | 
					struct DeviceState {
 | 
				
			||||||
 | 
					    Object parent_obj;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const char *id;
 | 
					    const char *id;
 | 
				
			||||||
    enum DevState state;
 | 
					    enum DevState state;
 | 
				
			||||||
    QemuOpts *opts;
 | 
					    QemuOpts *opts;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user