Skip to content

Commit c040626

Browse files
committed
Add the virtq_desc elements into queue
1 parent cb98c39 commit c040626

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

queue.h

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef QUEUE_H
22
#define QUEUE_H
33

4+
#include <stddef.h>
5+
46
#if defined(__GNUC__)
57
#define __QUEUE_HAVE_TYPEOF 1
68
#endif
@@ -18,18 +20,41 @@ static inline void INIT_QUEUE_HEAD(struct queue_head *head)
1820
head->prev = head;
1921
}
2022

23+
/* Push the node to the end of queue */
2124
static inline void queue_push(struct queue_head *node, struct queue_head *head)
2225
{
23-
struct queue_head *next = head->next;
26+
struct queue_head *prev = head->prev;
27+
28+
prev->next = node;
29+
node->next = head;
30+
node->prev = prev;
31+
head->prev = node;
32+
}
33+
34+
static inline int head_empty(const struct queue_head *head)
35+
{
36+
return (head->next == head);
37+
}
38+
39+
static inline void queue_del(struct queue_head *node)
40+
{
41+
struct queue_head *next = node->next;
42+
struct queue_head *prev = node->prev;
2443

25-
next->prev = node;
26-
node->next = next;
44+
next->prev = prev;
45+
prev->next = next;
2746

28-
node->prev = head;
29-
head->next = node;
47+
#ifdef LIST_POISONING
48+
node->prev = (struct queue_head *) (0x00100100);
49+
node->next = (struct queue_head *) (0x00200200);
50+
#endif
3051
}
3152

32-
static inline void queue_pop() {}
53+
static inline void queue_del_init(struct queue_head *node)
54+
{
55+
queue_del(node);
56+
INIT_QUEUE_HEAD(node);
57+
}
3358

3459
#ifndef container_of
3560
#ifdef __QUEUE_HAVE_TYPEOF
@@ -52,14 +77,14 @@ static inline void queue_pop() {}
5277
#define queue_last_entry(head, type, member) \
5378
queue_entry((head)->prev, type, member)
5479

55-
#define list_for_each(node, head) \
80+
#define queue_for_each(node, head) \
5681
for (node = (head)->next; node != (head); node = node->next)
5782

58-
#ifdef __LIST_HAVE_TYPEOF
59-
#define list_for_each_entry(entry, head, member) \
60-
for (entry = list_entry((head)->next, __typeof__(*entry), member); \
83+
#ifdef __QUEUE_HAVE_TYPEOF
84+
#define queue_for_each_entry(entry, head, member) \
85+
for (entry = queue_entry((head)->next, __typeof__(*entry), member); \
6186
&entry->member != (head); \
62-
entry = list_entry(entry->member.next, __typeof__(*entry), member))
87+
entry = queue_entry(entry->member.next, __typeof__(*entry), member))
6388
#endif
6489

6590
#endif

virtio-snd.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,6 @@ static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd,
654654

655655
/* Return the device status */
656656
response->code = VIRTIO_SND_S_OK;
657-
//*plen = vq_desc[2].len;
658657

659658
return 0;
660659
}
@@ -663,7 +662,7 @@ static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd,
663662
typedef struct {
664663
struct virtq_desc vq_desc;
665664
struct queue_head q;
666-
} virtq_desc_queue_t;
665+
} virtq_desc_queue_node_t;
667666
static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
668667
const virtio_snd_queue_t *queue,
669668
uint32_t desc_idx,
@@ -678,7 +677,10 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
678677
* Finally, the last descriptors contains:
679678
* (response payload structure)
680679
*/
681-
struct virtq_desc vq_desc[VSND_DESC_CNT];
680+
virtq_desc_queue_node_t *node;
681+
struct queue_head q;
682+
683+
INIT_QUEUE_HEAD(&q);
682684

683685
/* Collect the descriptors */
684686
int i = 0;
@@ -687,11 +689,16 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
687689
const uint32_t *desc = &vsnd->ram[queue->QueueDesc + desc_idx * 4];
688690

689691
/* Retrieve the fields of current descriptor */
690-
if (i < VSND_DESC_CNT) {
692+
/*if (i < VSND_DESC_CNT) {
691693
vq_desc[i].addr = desc[0];
692694
vq_desc[i].len = desc[2];
693695
vq_desc[i].flags = desc[3];
694-
}
696+
}*/
697+
node = (virtq_desc_queue_node_t *) malloc(sizeof(*node));
698+
node->vq_desc.addr = desc[0];
699+
node->vq_desc.len = desc[2];
700+
node->vq_desc.flags = desc[3];
701+
queue_push(&node->q, &q);
695702
desc_idx = desc[3] >> 16; /* vq_desc[desc_cnt].next */
696703

697704
i++;
@@ -704,6 +711,7 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
704711
}
705712
}
706713

714+
#if 0
707715
fprintf(stderr, "TX process header\n");
708716
/* Process the header */
709717
const virtio_snd_pcm_xfer_t *request =
@@ -723,6 +731,13 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
723731
response->status = VIRTIO_SND_S_OK;
724732
response->latency_bytes = 0; /* TODO: show the actual latency bytes */
725733
*plen = vq_desc[1].len + sizeof(*response);
734+
#endif
735+
int idx = 0;
736+
queue_for_each_entry(node, &q, q)
737+
{
738+
printf("node %d\n", idx);
739+
idx++;
740+
}
726741

727742
return 0;
728743
}

0 commit comments

Comments
 (0)