Skip to content

Commit cc0e755

Browse files
committed
Succeed to initialize virtio-snd
1 parent 842a58d commit cc0e755

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

virtio-snd.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,29 +246,24 @@ static void virtio_snd_update_status(virtio_snd_state_t *vsnd, uint32_t status)
246246
}
247247

248248
static void virtio_snd_read_jack_info_handler(
249-
struct virtq_desc *vq_desc,
249+
virtio_snd_jack_info_t *info,
250250
const virtio_snd_query_info_t *query)
251251
{
252-
uint32_t cnt = query->count;
253-
virtio_snd_jack_info_t *info = malloc(sizeof(virtio_snd_jack_info_t) * cnt);
254-
for (uint32_t i = 0; i < cnt; i++) {
252+
for (uint32_t i = 0; i < query->count; i++) {
255253
info[i].hdr.hda_fn_nid = 0;
256254
info[i].features = 0;
257255
info[i].hda_reg_defconf = 0;
258256
info[i].hda_reg_caps = 0;
259257
info[i].connected = 1;
260258
memset(&info[i].padding, 0, sizeof(info[i].padding));
261259
}
262-
vq_desc[2].addr = (uintptr_t) info;
263260
}
264261

265262
static void virtio_snd_read_pcm_info_handler(
266-
struct virtq_desc *vq_desc,
263+
virtio_snd_pcm_info_t *info,
267264
const virtio_snd_query_info_t *query)
268265
{
269-
uint32_t cnt = query->count;
270-
virtio_snd_pcm_info_t *info = malloc(sizeof(virtio_snd_pcm_info_t) * cnt);
271-
for (uint32_t i = 0; i < cnt; i++) {
266+
for (uint32_t i = 0; i < query->count; i++) {
272267
info[i].hdr.hda_fn_nid = 0;
273268
info[i].features = 0;
274269
info[i].formats = (1 << VIRTIO_SND_PCM_FMT_S16);
@@ -278,23 +273,18 @@ static void virtio_snd_read_pcm_info_handler(
278273
info[i].channels_max = 1;
279274
memset(&info[i].padding, 0, sizeof(info[i].padding));
280275
}
281-
vq_desc[2].addr = (uintptr_t) info;
282276
}
283277

284278
static void virtio_snd_read_chmap_info_handler(
285-
struct virtq_desc *vq_desc,
279+
virtio_snd_chmap_info_t *info,
286280
const virtio_snd_query_info_t *query)
287281
{
288-
uint32_t cnt = query->count;
289-
virtio_snd_chmap_info_t *info =
290-
malloc(sizeof(virtio_snd_chmap_info_t) * cnt);
291282
for (uint32_t i = 0; i < query->count; i++) {
292283
info[i].hdr.hda_fn_nid = 0;
293284
info[i].direction = VIRTIO_SND_D_OUTPUT;
294285
info[i].channels = 1;
295286
info[i].positions[0] = VIRTIO_SND_CHMAP_MONO;
296287
}
297-
vq_desc[2].addr = (uintptr_t) info;
298288
}
299289

300290
static void virtio_snd_read_pcm_set_params(struct virtq_desc *vq_desc,
@@ -438,17 +428,18 @@ static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd,
438428
(virtio_snd_hdr_t *) ((uintptr_t) vsnd->ram + vq_desc[1].addr);
439429
const virtio_snd_query_info_t *query =
440430
(virtio_snd_query_info_t *) ((uintptr_t) vsnd->ram + vq_desc[0].addr);
431+
void *info = (void *) (uintptr_t) vsnd->ram + vq_desc[2].addr;
441432

442433
/* Process the data */
443434
switch (type) {
444435
case VIRTIO_SND_R_JACK_INFO:
445-
virtio_snd_read_jack_info_handler(vq_desc, query);
436+
virtio_snd_read_jack_info_handler(info, query);
446437
break;
447438
case VIRTIO_SND_R_PCM_INFO:
448-
virtio_snd_read_pcm_info_handler(vq_desc, query);
439+
virtio_snd_read_pcm_info_handler(info, query);
449440
break;
450441
case VIRTIO_SND_R_CHMAP_INFO:
451-
virtio_snd_read_chmap_info_handler(vq_desc, query);
442+
virtio_snd_read_chmap_info_handler(info, query);
452443
break;
453444
case VIRTIO_SND_R_PCM_SET_PARAMS:
454445
virtio_snd_read_pcm_set_params(vq_desc, query);

0 commit comments

Comments
 (0)