/home/qemutest/qemu-1.7.1/include/hw/pci
#define PCI_DEVICE_ID_VIRTIO_MYDEVICE 0x1006 //cocotion modify
virtio-pci.c 有改 ==> 現在再改
./hw/virtio/virtio-pci.h 有改
/home/qemutest/qemu-1.7.1/hw/virtio/virtio-pci.c
改了這些:
mydevice_pci_stats_get_all
mydevice_pci_stats_get_poll_interval
mydevice_pci_stats_set_poll_interval
Property virtio_mydevice_pci_properties[]
virtio_mydevice_pci_init
virtio_mydevice_pci_class_init
virtio_mydevice_pci_instance_init
TypeInfo virtio_mydevice_pci_info
新增
/home/qemutest/qemu-1.7.1/hw/virtio/virtio-mydevice.c
此檔為balloon的copy, 之後開始來trace他
===========================================
改./include/hw/virtio/virtio-mydevice.h
typedef struct VirtIOmydevice {
VirtIODevice parent_obj;
VirtQueue *ivq, *dvq, *svq;
uint32_t num_pages;
uint32_t actual;
uint64_t stats[VIRTIO_MYDEVICE_S_NR];
VirtQueueElement stats_vq_elem;
size_t stats_vq_offset;
QEMUTimer *stats_timer;
int64_t stats_last_update;
int64_t stats_poll_interval;
} VirtIOmydevice;
原本的VirtIODevice 放在./include/hw/virtio/virtio.h
struct VirtIODevice
{
DeviceState parent_obj;
const char *name;
uint8_t status;
uint8_t isr;
uint16_t queue_sel;
uint32_t guest_features;
size_t config_len;
void *config;
uint16_t config_vector;
int nvectors;
VirtQueue *vq;
uint16_t device_id;
bool vm_running;
VMChangeStateEntry *vmstate;
char *bus_name;
};
以及operation:
typedef struct VirtioDeviceClass {
/* This is what a VirtioDevice must implement */
DeviceClass parent;
int (*init)(VirtIODevice *vdev);
void (*exit)(VirtIODevice *vdev);
uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
uint32_t (*bad_features)(VirtIODevice *vdev);
void (*set_features)(VirtIODevice *vdev, uint32_t val);
void (*get_config)(VirtIODevice *vdev, uint8_t *config);
void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
void (*reset)(VirtIODevice *vdev);
void (*set_status)(VirtIODevice *vdev, uint8_t val);
/* Test and clear event pending status.
* Should be called after unmask to avoid losing events.
* If backend does not support masking,
* must check in frontend instead.
*/
bool (*guest_notifier_pending)(VirtIODevice *vdev, int n);
/* Mask/unmask events from this vq. Any events reported
* while masked will become pending.
* If backend does not support masking,
* must mask in frontend instead.
*/
void (*guest_notifier_mask)(VirtIODevice *vdev, int n, bool mask);
} VirtioDeviceClass;
VIRTIOQUEUE 相關:
typedef struct VirtQueueElement
{
unsigned int index;
unsigned int out_num;
unsigned int in_num;
hwaddr in_addr[VIRTQUEUE_MAX_SIZE];
hwaddr out_addr[VIRTQUEUE_MAX_SIZE];
struct iovec in_sg[VIRTQUEUE_MAX_SIZE];
struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
} VirtQueueElement;
之後在./hw/virtio/virtio-mydevice.c
讓自己產生的device operation指向VirtioDeviceClass 以及相關class, 像是繼承:
static void virtio_mydevice_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
dc->props = virtio_mydevice_properties;
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
vdc->init = virtio_mydevice_device_init;
vdc->exit = virtio_mydevice_device_exit;
vdc->get_config = virtio_mydevice_get_config;
vdc->set_config = virtio_mydevice_set_config;
vdc->get_features = virtio_mydevice_get_features;
}
另外在./include/hw/virtio/virtio-mydevice.h改了virtio_mydevice_config:
struct virtio_mydevice_config
{
int config; //cocotion test
/* Number of pages host wants Guest to give up. */
uint32_t num_pages;
/* Number of pages we've actually got in balloon. */
uint32_t actual;
};