122851890Sopenharmony_ci/*
222851890Sopenharmony_ci * This header was generated from the Linux kernel headers by update_headers.py,
322851890Sopenharmony_ci * to provide necessary information from kernel to userspace, such as constants,
422851890Sopenharmony_ci * structures, and macros, and thus, contains no copyrightable information.
522851890Sopenharmony_ci */
622851890Sopenharmony_ci#ifndef _UAPI_LINUX_VIRTIO_RING_H
722851890Sopenharmony_ci#define _UAPI_LINUX_VIRTIO_RING_H
822851890Sopenharmony_ci#ifndef __KERNEL__
922851890Sopenharmony_ci#include <stdint.h>
1022851890Sopenharmony_ci#endif
1122851890Sopenharmony_ci#include <linux/types.h>
1222851890Sopenharmony_ci#include <linux/virtio_types.h>
1322851890Sopenharmony_ci#define VRING_DESC_F_NEXT	1
1422851890Sopenharmony_ci#define VRING_DESC_F_WRITE	2
1522851890Sopenharmony_ci#define VRING_DESC_F_INDIRECT	4
1622851890Sopenharmony_ci#define VRING_USED_F_NO_NOTIFY	1
1722851890Sopenharmony_ci#define VRING_AVAIL_F_NO_INTERRUPT	1
1822851890Sopenharmony_ci#define VIRTIO_RING_F_INDIRECT_DESC	28
1922851890Sopenharmony_ci#define VIRTIO_RING_F_EVENT_IDX		29
2022851890Sopenharmony_cistruct vring_desc {
2122851890Sopenharmony_ci
2222851890Sopenharmony_ci	__virtio64 addr;
2322851890Sopenharmony_ci
2422851890Sopenharmony_ci	__virtio32 len;
2522851890Sopenharmony_ci
2622851890Sopenharmony_ci	__virtio16 flags;
2722851890Sopenharmony_ci
2822851890Sopenharmony_ci	__virtio16 next;
2922851890Sopenharmony_ci};
3022851890Sopenharmony_cistruct vring_avail {
3122851890Sopenharmony_ci	__virtio16 flags;
3222851890Sopenharmony_ci	__virtio16 idx;
3322851890Sopenharmony_ci	__virtio16 ring[];
3422851890Sopenharmony_ci};
3522851890Sopenharmony_cistruct vring_used_elem {
3622851890Sopenharmony_ci
3722851890Sopenharmony_ci	__virtio32 id;
3822851890Sopenharmony_ci
3922851890Sopenharmony_ci	__virtio32 len;
4022851890Sopenharmony_ci};
4122851890Sopenharmony_cistruct vring_used {
4222851890Sopenharmony_ci	__virtio16 flags;
4322851890Sopenharmony_ci	__virtio16 idx;
4422851890Sopenharmony_ci	struct vring_used_elem ring[];
4522851890Sopenharmony_ci};
4622851890Sopenharmony_cistruct vring {
4722851890Sopenharmony_ci	unsigned int num;
4822851890Sopenharmony_ci	struct vring_desc *desc;
4922851890Sopenharmony_ci	struct vring_avail *avail;
5022851890Sopenharmony_ci	struct vring_used *used;
5122851890Sopenharmony_ci};
5222851890Sopenharmony_ci#define VRING_AVAIL_ALIGN_SIZE 2
5322851890Sopenharmony_ci#define VRING_USED_ALIGN_SIZE 4
5422851890Sopenharmony_ci#define VRING_DESC_ALIGN_SIZE 16
5522851890Sopenharmony_ci#define vring_used_event(vr) ((vr)->avail->ring[(vr)->num])
5622851890Sopenharmony_ci#define vring_avail_event(vr) (*(__virtio16 *)&(vr)->used->ring[(vr)->num])
5722851890Sopenharmony_cistatic inline void vring_init(struct vring *vr, unsigned int num, void *p,
5822851890Sopenharmony_ci			      unsigned long align)
5922851890Sopenharmony_ci{
6022851890Sopenharmony_ci	vr->num = num;
6122851890Sopenharmony_ci	vr->desc = p;
6222851890Sopenharmony_ci	vr->avail = p + num*sizeof(struct vring_desc);
6322851890Sopenharmony_ci	vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(__virtio16)
6422851890Sopenharmony_ci		+ align-1) & ~(align - 1));
6522851890Sopenharmony_ci}
6622851890Sopenharmony_cistatic inline unsigned vring_size(unsigned int num, unsigned long align)
6722851890Sopenharmony_ci{
6822851890Sopenharmony_ci	return ((sizeof(struct vring_desc) * num + sizeof(__virtio16) * (3 + num)
6922851890Sopenharmony_ci		 + align - 1) & ~(align - 1))
7022851890Sopenharmony_ci		+ sizeof(__virtio16) * 3 + sizeof(struct vring_used_elem) * num;
7122851890Sopenharmony_ci}
7222851890Sopenharmony_cistatic inline int vring_need_event(__u16 event_idx, __u16 new_idx, __u16 old)
7322851890Sopenharmony_ci{
7422851890Sopenharmony_ci
7522851890Sopenharmony_ci	return (__u16)(new_idx - event_idx - 1) < (__u16)(new_idx - old);
7622851890Sopenharmony_ci}
7722851890Sopenharmony_ci#endif
78