MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / virtio_input_cfg_bits

Function virtio_input_cfg_bits

components/drivers/virtio/virtio_input.c:40–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40static void virtio_input_cfg_bits(struct virtio_input_device *virtio_input_dev,
41 rt_uint8_t select, rt_uint8_t subsel, rt_ubase_t *bits, rt_uint32_t bitcount)
42{
43 int i;
44 rt_uint32_t bit;
45 rt_uint8_t bytes;
46 rt_uint8_t *virtio_bits;
47 void *config_base = virtio_input_dev->config;
48 rt_off_t offset = (rt_size_t)&((struct virtio_input_config *)0)->bitmap;
49
50 bytes = virtio_input_cfg_select(virtio_input_dev, select, subsel);
51
52 if (bytes == 0)
53 {
54 return;
55 }
56
57 if (bitcount > bytes * 8)
58 {
59 bitcount = bytes * 8;
60 }
61
62 /*
63 * Bitmap in virtio config space is a simple stream of bytes,
64 * with the first byte carrying bits 0-7, second bits 8-15 and
65 * so on.
66 */
67 virtio_bits = rt_malloc(bytes);
68
69 if (virtio_bits == RT_NULL)
70 {
71 return;
72 }
73
74 for (i = 0; i < bytes; ++i)
75 {
76 void *buffer = (void *)virtio_bits + i;
77
78 if (virtio_input_dev->virtio_dev.mmio_config->version == 1)
79 {
80 HWREG8(config_base + offset + i) = *((rt_uint8_t *)buffer);
81 }
82 else
83 {
84 rt_memcpy(config_base + offset + i, buffer, sizeof(rt_uint8_t));
85 }
86 }
87
88 for (bit = 0; bit < bitcount; ++bit)
89 {
90 if (virtio_bits[bit / 8] & (1 << (bit % 8)))
91 {
92 _set_bit(bit, bits);
93 }
94 }
95
96 rt_free(virtio_bits);
97

Callers 1

virtio_input_initFunction · 0.85

Calls 5

virtio_input_cfg_selectFunction · 0.85
rt_mallocFunction · 0.85
rt_memcpyFunction · 0.85
_set_bitFunction · 0.85
rt_freeFunction · 0.85

Tested by

no test coverage detected