[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] How to add emulated hardware module to QEMU
From: |
梁凯源 |
Subject: |
[Qemu-devel] How to add emulated hardware module to QEMU |
Date: |
Mon, 27 Oct 2014 17:02:06 +0800 (GMT+08:00) |
Hello all,
I am a student of Tianjin University, researching emulation of hardware module
in QEMU. Could you give me some suggestions?
In my project, I need to add a virtual hardware to qemu. By code reviewing, I
seemly get the point that devices and peripherals under dir hw/*/* register
themselves by some macro like type_init. Developers need to implement some
common functions and structs like *_reset/init/realize, *_class_init(),
*_register_type(), *_info[], and MemoryRegionOps *ops[] and pass them to macro
as "Callback(?)". And, boards like hw/ppc/virtex_ml507.c will pick up some of
these devices by qdev_create() and allocate memory spaces to devices’ register
(mmio). Above is my understanding right now.
However, the details inside this mechanism is blur for me. For some functions
and structs we must to implement, I don't know the meaning and how precisely
implement them.
Suppose I need to implement a virtual DES (Data Encryption Standard) module
with four registers:
Data-Input,
Data-Output,
Key,
Control-Mode(-generateKey, -encrypt, -dencrypt).
Put plain text to reg Data-Input, key to reg Key, and set Control-Mode to
encrypt mode. Module will encrypt plain text and put result of cipher text to
register Data-Output.
I have written file soc_des.c under hw/misc like this, questions inline:
#include "hw/hw.h"
#include "hw/sysbus.h"
static const MemoryRegionOps soc_des_ops = {
.read = soc_des_read,
.write = soc_des_write,
.endianness = DEVICE_NATIVE_ENDIAN,
//Any others I have to implement here?
};
static void soc_des_read(void *opaque /*What’s meaning of opaque?*/, hwaddr
offset, unsigned size)
{
//I checkout many files under hw/*, hope to find how to read/write virtual
registers, but I didn’t find sample.
}
static void soc_des_write(void *opaque, hwaddr offset, uint64_t value, unsigned
size)
{
}
static void soc_des_realize(DeviceState *dev, Error **errp)
{
//Is this function is requested?
}
static void soc_des_reset(DeviceState *d)
{
//Same question, how to set registers?
}
static Property soc_des_properties[] = {
//Looks like defining registers here. But which things I need to pass into
DEFINE_PROP_UINT64()?
DEFINE_PROP_UINT64("des-key", /*To do here?*/),
DEFINE_PROP_UINT64("des-mode", …),
DEFINE_PROP_UINT64("des-input", …),
DEFINE_PROP_UINT64("des-output", …),
DEFINE_PROP_END_OF_LIST(),
};
static void soc_des_class_init(ObjectClass *klass, void *data)
{
}
static const TypeInfo soc_des_info = {
.name = TYPE_SOC_DES,
.parent = TYPE_SYS_BUS_BEVICE,
.instance_size = sizeof(…), //sizeof what here?
.class_init = soc_des_class_init,
};
static void soc_des_register_types(void)
{
}
type_init(soc_des_register_types)
I know all of them are my business, and I have searched and viewed many docs
about programming QEMU. But I really need some help to deeply comprehend
detailed info. Could you give me some suggestions?
Thanks,
Kaiyuan Liang
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] How to add emulated hardware module to QEMU,
梁凯源 <=