descriptor.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package virtqueue
  2. // descriptorFlag is a flag that describes a [Descriptor].
  3. type descriptorFlag uint16
  4. const (
  5. // descriptorFlagHasNext marks a descriptor chain as continuing via the next
  6. // field.
  7. descriptorFlagHasNext descriptorFlag = 1 << iota
  8. // descriptorFlagWritable marks a buffer as device write-only (otherwise
  9. // device read-only).
  10. descriptorFlagWritable
  11. // descriptorFlagIndirect means the buffer contains a list of buffer
  12. // descriptors to provide an additional layer of indirection.
  13. // Only allowed when the [virtio.FeatureIndirectDescriptors] feature was
  14. // negotiated.
  15. descriptorFlagIndirect
  16. )
  17. // descriptorSize is the number of bytes needed to store a [Descriptor] in
  18. // memory.
  19. const descriptorSize = 16
  20. // Descriptor describes (a part of) a buffer which is either read-only for the
  21. // device or write-only for the device (depending on [descriptorFlagWritable]).
  22. // Multiple descriptors can be chained to produce a "descriptor chain" that can
  23. // contain both device-readable and device-writable buffers. Device-readable
  24. // descriptors always come first in a chain. A single, large buffer may be
  25. // split up by chaining multiple similar descriptors that reference different
  26. // memory pages. This is required, because buffers may exceed a single page size
  27. // and the memory accessed by the device is expected to be continuous.
  28. type Descriptor struct {
  29. // address is the address to the continuous memory holding the data for this
  30. // descriptor.
  31. address uintptr
  32. // length is the amount of bytes stored at address.
  33. length uint32
  34. // flags that describe this descriptor.
  35. flags descriptorFlag
  36. // next contains the index of the next descriptor continuing this descriptor
  37. // chain when the [descriptorFlagHasNext] flag is set.
  38. next uint16
  39. }