Skip to content

Commit 5774dca

Browse files
authored
[bsp/qemu-virt64-aarch64] Fixup VirtIO queue align size (RT-Thread#6096)
1 parent f41cb56 commit 5774dca

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

bsp/qemu-virt64-aarch64/applications/graphic.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ static rt_uint32_t cur_range[2];
2323
static rt_uint32_t cur_points[2];
2424
static rt_uint32_t cur_last_points[2];
2525
static rt_bool_t cur_event_sync;
26+
static rt_uint32_t color[2] = { 0xff0000, 0x0000ff };
2627

2728
void tablet_event_handler(struct virtio_input_event event)
2829
{
30+
static rt_bool_t cur_btn_down = RT_FALSE;
31+
2932
if (event.type == EV_ABS)
3033
{
3134
if (event.code == 0)
@@ -37,6 +40,24 @@ void tablet_event_handler(struct virtio_input_event event)
3740
cur_points[1] = (cur_max[1] * (event.value - cur_min[1]) + cur_range[1] / 2) / cur_range[1];
3841
}
3942
}
43+
else if (event.type == EV_KEY)
44+
{
45+
if (event.code == BTN_LEFT)
46+
{
47+
if (cur_btn_down && event.value == 0)
48+
{
49+
color[0] ^= color[1];
50+
color[1] ^= color[0];
51+
color[0] ^= color[1];
52+
cur_btn_down = RT_FALSE;
53+
cur_event_sync = RT_TRUE;
54+
}
55+
else
56+
{
57+
cur_btn_down = RT_TRUE;
58+
}
59+
}
60+
}
4061
else if (event.type == EV_SYN)
4162
{
4263
cur_event_sync = RT_TRUE;
@@ -52,8 +73,6 @@ void graphic_thread(void *param)
5273
rt_device_t tablet_dev = RT_NULL;
5374
struct virtio_input_config tablet_config;
5475

55-
rt_uint32_t red = 0xff0000;
56-
rt_uint32_t blue = 0x0000ff;
5776
rt_uint32_t white = 0xffffff;
5877
rt_device_t gpu_dev = RT_NULL;
5978
struct rt_device_rect_info rect_info;
@@ -87,15 +106,13 @@ void graphic_thread(void *param)
87106
cur_last_points[0] = graphic_info.width / 2;
88107
cur_last_points[1] = graphic_info.height / 2;
89108

90-
virtio_gpu_graphic_ops->draw_hline((char *)&red, 0, graphic_info.width, cur_last_points[1]);
91-
virtio_gpu_graphic_ops->draw_vline((char *)&blue, cur_last_points[0], 0, graphic_info.height);
109+
virtio_gpu_graphic_ops->draw_hline((char *)&color[0], 0, graphic_info.width, cur_last_points[1]);
110+
virtio_gpu_graphic_ops->draw_vline((char *)&color[1], cur_last_points[0], 0, graphic_info.height);
92111

93112
rt_device_control(device, RTGRAPHIC_CTRL_RECT_UPDATE, &rect_info);
94113

95114
gpu_dev = device;
96115
}
97-
98-
rt_device_close(device);
99116
}
100117

101118
/* Keyboard, Mouse, Tablet */
@@ -153,8 +170,8 @@ void graphic_thread(void *param)
153170
cur_last_points[0] = cur_points[0];
154171
cur_last_points[1] = cur_points[1];
155172

156-
virtio_gpu_graphic_ops->draw_hline((char *)&red, 0, graphic_info.width, cur_last_points[1]);
157-
virtio_gpu_graphic_ops->draw_vline((char *)&blue, cur_last_points[0], 0, graphic_info.height);
173+
virtio_gpu_graphic_ops->draw_hline((char *)&color[0], 0, graphic_info.width, cur_last_points[1]);
174+
virtio_gpu_graphic_ops->draw_vline((char *)&color[1], cur_last_points[0], 0, graphic_info.height);
158175

159176
rt_device_control(gpu_dev, RTGRAPHIC_CTRL_RECT_UPDATE, &rect_info);
160177

bsp/qemu-virt64-aarch64/driver/virtio/virtio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ rt_err_t virtio_queue_init(struct virtio_device *dev, rt_uint32_t queue_index, r
7272

7373
queue = &dev->queues[queue_index];
7474
pages_total_size = VIRTIO_PAGE_ALIGN(
75-
VIRTQ_DESC_TOTAL_SIZE(ring_size) + VIRTQ_AVAIL_TOTAL_SIZE(ring_size) + VIRTQ_USED_TOTAL_SIZE(ring_size));
75+
VIRTQ_DESC_TOTAL_SIZE(ring_size) + VIRTQ_AVAIL_TOTAL_SIZE(ring_size)) + VIRTQ_USED_TOTAL_SIZE(ring_size);
7676

7777
pages = rt_malloc_align(pages_total_size, VIRTIO_PAGE_SIZE);
7878

0 commit comments

Comments
 (0)