#ifndef _UAPI_LINUX_VIRTIO_RING_H #define _UAPI_LINUX_VIRTIO_RING_H /* An interface for efficient virtio implementation, currently for use by KVM, *buthopefullyotherssoon.DoNOTchangethissinceitwill *breakexistingserversandclients. * *ThisheaderisBSDlicensedsoanyonecanusethedefinitionstoimplement *compatibledrivers/servers. * *Redistributionanduseinsourceandbinaryforms,withorwithout *modification,arepermittedprovidedthatthefollowingconditions *aremet: *1.Redistributionsofsourcecodemustretaintheabovecopyright *notice,thislistofconditionsandthefollowingdisclaimer. *2.Redistributionsinbinaryformmustreproducetheabovecopyright *notice,thislistofconditionsandthefollowingdisclaimerinthe *documentationand/orothermaterialsprovidedwiththedistribution. *3.NeitherthenameofIBMnorthenamesofitscontributors *maybeusedtoendorseorpromoteproductsderivedfromthissoftware *withoutspecificpriorwrittenpermission. *THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS``ASIS''AND *ANYEXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THE *IMPLIEDWARRANTIESOFMERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSE *AREDISCLAIMED.INNOEVENTSHALLIBMORCONTRIBUTORSBELIABLE *FORANYDIRECT,INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,ORCONSEQUENTIAL *DAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENTOFSUBSTITUTEGOODS *ORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION) *HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICT *LIABILITY,ORTORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAY *OUTOFTHEUSEOFTHISSOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOF *SUCHDAMAGE. *
* Copyright Rusty Russell IBM Corporation 2007. */ #ifndef __KERNEL__ #include <stdint.h> #endif #include <linux/types.h> #include <linux/virtio_types.h>
/* This marks a buffer as continuing via the next field. */ #define VRING_DESC_F_NEXT 1 /* This marks a buffer as write-only (otherwise read-only). */ #define VRING_DESC_F_WRITE 2 /* This means the buffer contains a list of buffer descriptors. */ #define VRING_DESC_F_INDIRECT 4
/* The Host uses this in used->flags to advise the Guest: don't kick me when *youaddabuffer.It'sunreliable,soit'ssimplyanoptimization.Guest
* will still kick if it's out of buffers. */ #define VRING_USED_F_NO_NOTIFY 1 /* The Guest uses this in avail->flags to advise the Host: don't interrupt me *whenyouconsumeabuffer.It'sunreliable,soit'ssimplyan
* optimization. */ #define VRING_AVAIL_F_NO_INTERRUPT 1
/* We support indirect buffer descriptors */ #define VIRTIO_RING_F_INDIRECT_DESC 28
/* The Guest publishes the used index for which it expects an interrupt
* at the end of the avail ring. Host should ignore the avail->flags field. */ /* The Host publishes the avail index for which it expects a kick
* at the end of the used ring. Guest should ignore the used->flags field. */ #define VIRTIO_RING_F_EVENT_IDX 29
/* u32 is used here for ids for padding reasons. */ struct vring_used_elem { /* Index of start of used descriptor chain. */
__virtio32 id; /* Total length of the descriptor chain which was used (written to) */
__virtio32 len;
};
/* The standard layout for the ring is a continuous chunk of memory which looks *likethis.Weassumenumisapowerof2. * *structvring *{ *// The actual descriptors (16 bytes each) *structvring_descdesc[num]; * *// A ring of available descriptor heads with free-running index. *__virtio16avail_flags; *__virtio16avail_idx; *__virtio16available[num]; *__virtio16used_event_idx; * *// Padding to the next align boundary. *charpad[]; * *// A ring of used descriptor heads with free-running index. *__virtio16used_flags; *__virtio16used_idx; *structvring_used_elemused[num]; *__virtio16avail_event_idx; *};
*/ /* We publish the used event index at the end of the available ring, and vice
* versa. They are at the end for backwards compatibility. */ #define vring_used_event(vr) ((vr)->avail->ring[(vr)->num]) #define vring_avail_event(vr) (*(__virtio16 *)&(vr)->used->ring[(vr)->num])
/* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */ /* Assuming a given event_idx value from the other side, if *wehavejustincrementedindexfromoldtonew_idx,
* should we trigger an event? */ staticinlineint vring_need_event(__u16 event_idx, __u16 new_idx, __u16 old)
{ /* Note: Xen has similar logic for notification hold-off *ininclude/xen/interface/io/ring.hwithreq_eventandreq_prod *correspondingtoevent_idx+1andnew_idxrespectively. *Notealsothatreq_eventandreq_prodinXenstartat1,
* event indexes in virtio start at 0. */ return (__u16)(new_idx - event_idx - 1) < (__u16)(new_idx - old);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.