Lines Matching refs:vrh
38 static inline int __vringh_get_head(const struct vringh *vrh, in __vringh_get_head() argument
39 int (*getu16)(const struct vringh *vrh, in __vringh_get_head() argument
46 err = getu16(vrh, &avail_idx, &vrh->vring.avail->idx); in __vringh_get_head()
49 &vrh->vring.avail->idx); in __vringh_get_head()
54 return vrh->vring.num; in __vringh_get_head()
57 virtio_rmb(vrh->weak_barriers); in __vringh_get_head()
59 i = *last_avail_idx & (vrh->vring.num - 1); in __vringh_get_head()
61 err = getu16(vrh, &head, &vrh->vring.avail->ring[i]); in __vringh_get_head()
64 *last_avail_idx, &vrh->vring.avail->ring[i]); in __vringh_get_head()
68 if (head >= vrh->vring.num) { in __vringh_get_head()
70 head, vrh->vring.num); in __vringh_get_head()
107 static inline ssize_t vringh_iov_xfer(struct vringh *vrh, in vringh_iov_xfer() argument
110 int (*xfer)(const struct vringh *vrh, in vringh_iov_xfer() argument
120 err = xfer(vrh, iov->iov[iov->i].iov_base, ptr, partlen); in vringh_iov_xfer()
133 static inline bool range_check(struct vringh *vrh, u64 addr, size_t *len, in range_check() argument
139 if (!getrange(vrh, addr, range)) in range_check()
167 static inline bool no_range_check(struct vringh *vrh, u64 addr, size_t *len, in no_range_check() argument
176 static int move_to_indirect(const struct vringh *vrh, in move_to_indirect() argument
189 len = vringh32_to_cpu(vrh, desc->len); in move_to_indirect()
196 if (desc->flags & cpu_to_vringh16(vrh, VRING_DESC_F_NEXT)) in move_to_indirect()
197 *up_next = vringh16_to_cpu(vrh, desc->next); in move_to_indirect()
235 static u16 __cold return_from_indirect(const struct vringh *vrh, int *up_next, in return_from_indirect() argument
241 *descs = vrh->vring.desc; in return_from_indirect()
242 *desc_max = vrh->vring.num; in return_from_indirect()
246 static int slow_copy(struct vringh *vrh, void *dst, const void *src, in slow_copy() argument
247 bool (*rcheck)(struct vringh *vrh, u64 addr, size_t *len, in slow_copy() argument
249 bool (*getrange)(struct vringh *vrh, in slow_copy() argument
252 bool (*getrange)(struct vringh *vrh, in slow_copy()
256 int (*copy)(const struct vringh *vrh, in slow_copy() argument
268 if (!rcheck(vrh, addr, &part, range, getrange)) in slow_copy()
271 err = copy(vrh, dst, src, part); in slow_copy()
283 __vringh_iov(struct vringh *vrh, u16 i, in __vringh_iov() argument
286 bool (*rcheck)(struct vringh *vrh, u64 addr, size_t *len, in __vringh_iov() argument
292 int (*copy)(const struct vringh *vrh, in __vringh_iov() argument
301 descs = vrh->vring.desc; in __vringh_iov()
302 desc_max = vrh->vring.num; in __vringh_iov()
320 err = slow_copy(vrh, &desc, &descs[i], rcheck, getrange, in __vringh_iov()
323 err = copy(vrh, &desc, &descs[i], sizeof(desc)); in __vringh_iov()
328 cpu_to_vringh16(vrh, VRING_DESC_F_INDIRECT))) { in __vringh_iov()
329 u64 a = vringh64_to_cpu(vrh, desc.addr); in __vringh_iov()
332 len = vringh32_to_cpu(vrh, desc.len); in __vringh_iov()
333 if (!rcheck(vrh, a, &len, &range, getrange)) { in __vringh_iov()
338 if (unlikely(len != vringh32_to_cpu(vrh, desc.len))) { in __vringh_iov()
345 err = move_to_indirect(vrh, &up_next, &i, addr, &desc, in __vringh_iov()
352 if (count++ == vrh->vring.num) { in __vringh_iov()
358 if (desc.flags & cpu_to_vringh16(vrh, VRING_DESC_F_WRITE)) in __vringh_iov()
379 len = vringh32_to_cpu(vrh, desc.len); in __vringh_iov()
380 if (!rcheck(vrh, vringh64_to_cpu(vrh, desc.addr), &len, &range, in __vringh_iov()
385 addr = (void *)(unsigned long)(vringh64_to_cpu(vrh, desc.addr) + in __vringh_iov()
398 if (unlikely(len != vringh32_to_cpu(vrh, desc.len))) { in __vringh_iov()
399 desc.len = cpu_to_vringh32(vrh, in __vringh_iov()
400 vringh32_to_cpu(vrh, desc.len) - len); in __vringh_iov()
401 desc.addr = cpu_to_vringh64(vrh, in __vringh_iov()
402 vringh64_to_cpu(vrh, desc.addr) + len); in __vringh_iov()
406 if (desc.flags & cpu_to_vringh16(vrh, VRING_DESC_F_NEXT)) { in __vringh_iov()
407 i = vringh16_to_cpu(vrh, desc.next); in __vringh_iov()
411 i = return_from_indirect(vrh, &up_next, in __vringh_iov()
431 static inline int __vringh_complete(struct vringh *vrh, in __vringh_complete() argument
434 int (*putu16)(const struct vringh *vrh, in __vringh_complete() argument
436 int (*putused)(const struct vringh *vrh, in __vringh_complete() argument
445 used_ring = vrh->vring.used; in __vringh_complete()
446 used_idx = vrh->last_used_idx + vrh->completed; in __vringh_complete()
448 off = used_idx % vrh->vring.num; in __vringh_complete()
451 if (num_used > 1 && unlikely(off + num_used >= vrh->vring.num)) { in __vringh_complete()
452 u16 part = vrh->vring.num - off; in __vringh_complete()
453 err = putused(vrh, &used_ring->ring[off], used, part); in __vringh_complete()
455 err = putused(vrh, &used_ring->ring[0], used + part, in __vringh_complete()
458 err = putused(vrh, &used_ring->ring[off], used, num_used); in __vringh_complete()
467 virtio_wmb(vrh->weak_barriers); in __vringh_complete()
469 err = putu16(vrh, &vrh->vring.used->idx, used_idx + num_used); in __vringh_complete()
472 &vrh->vring.used->idx); in __vringh_complete()
476 vrh->completed += num_used; in __vringh_complete()
481 static inline int __vringh_need_notify(struct vringh *vrh, in __vringh_need_notify() argument
482 int (*getu16)(const struct vringh *vrh, in __vringh_need_notify() argument
493 virtio_mb(vrh->weak_barriers); in __vringh_need_notify()
496 if (!vrh->event_indices) { in __vringh_need_notify()
498 err = getu16(vrh, &flags, &vrh->vring.avail->flags); in __vringh_need_notify()
501 &vrh->vring.avail->flags); in __vringh_need_notify()
508 err = getu16(vrh, &used_event, &vring_used_event(&vrh->vring)); in __vringh_need_notify()
511 &vring_used_event(&vrh->vring)); in __vringh_need_notify()
516 if (unlikely(vrh->completed > 0xffff)) in __vringh_need_notify()
520 vrh->last_used_idx + vrh->completed, in __vringh_need_notify()
521 vrh->last_used_idx); in __vringh_need_notify()
523 vrh->last_used_idx += vrh->completed; in __vringh_need_notify()
524 vrh->completed = 0; in __vringh_need_notify()
528 static inline bool __vringh_notify_enable(struct vringh *vrh, in __vringh_notify_enable() argument
529 int (*getu16)(const struct vringh *vrh, in __vringh_notify_enable() argument
531 int (*putu16)(const struct vringh *vrh, in __vringh_notify_enable() argument
536 if (!vrh->event_indices) { in __vringh_notify_enable()
538 if (putu16(vrh, &vrh->vring.used->flags, 0) != 0) { in __vringh_notify_enable()
540 &vrh->vring.used->flags); in __vringh_notify_enable()
544 if (putu16(vrh, &vring_avail_event(&vrh->vring), in __vringh_notify_enable()
545 vrh->last_avail_idx) != 0) { in __vringh_notify_enable()
547 &vring_avail_event(&vrh->vring)); in __vringh_notify_enable()
554 virtio_mb(vrh->weak_barriers); in __vringh_notify_enable()
556 if (getu16(vrh, &avail, &vrh->vring.avail->idx) != 0) { in __vringh_notify_enable()
558 &vrh->vring.avail->idx); in __vringh_notify_enable()
565 return avail == vrh->last_avail_idx; in __vringh_notify_enable()
568 static inline void __vringh_notify_disable(struct vringh *vrh, in __vringh_notify_disable() argument
569 int (*putu16)(const struct vringh *vrh, in __vringh_notify_disable() argument
572 if (!vrh->event_indices) { in __vringh_notify_disable()
574 if (putu16(vrh, &vrh->vring.used->flags, in __vringh_notify_disable()
577 &vrh->vring.used->flags); in __vringh_notify_disable()
583 static inline int getu16_user(const struct vringh *vrh, u16 *val, const __virtio16 *p) in getu16_user() argument
587 *val = vringh16_to_cpu(vrh, v); in getu16_user()
591 static inline int putu16_user(const struct vringh *vrh, __virtio16 *p, u16 val) in putu16_user() argument
593 __virtio16 v = cpu_to_vringh16(vrh, val); in putu16_user()
597 static inline int copydesc_user(const struct vringh *vrh, in copydesc_user() argument
604 static inline int putused_user(const struct vringh *vrh, in putused_user() argument
613 static inline int xfer_from_user(const struct vringh *vrh, void *src, in xfer_from_user() argument
620 static inline int xfer_to_user(const struct vringh *vrh, in xfer_to_user() argument
640 int vringh_init_user(struct vringh *vrh, u64 features, in vringh_init_user() argument
652 vrh->little_endian = (features & (1ULL << VIRTIO_F_VERSION_1)); in vringh_init_user()
653 vrh->event_indices = (features & (1 << VIRTIO_RING_F_EVENT_IDX)); in vringh_init_user()
654 vrh->weak_barriers = weak_barriers; in vringh_init_user()
655 vrh->completed = 0; in vringh_init_user()
656 vrh->last_avail_idx = 0; in vringh_init_user()
657 vrh->last_used_idx = 0; in vringh_init_user()
658 vrh->vring.num = num; in vringh_init_user()
660 vrh->vring.desc = (__force struct vring_desc *)desc; in vringh_init_user()
661 vrh->vring.avail = (__force struct vring_avail *)avail; in vringh_init_user()
662 vrh->vring.used = (__force struct vring_used *)used; in vringh_init_user()
687 int vringh_getdesc_user(struct vringh *vrh, in vringh_getdesc_user() argument
690 bool (*getrange)(struct vringh *vrh, in vringh_getdesc_user() argument
696 *head = vrh->vring.num; in vringh_getdesc_user()
697 err = __vringh_get_head(vrh, getu16_user, &vrh->last_avail_idx); in vringh_getdesc_user()
702 if (err == vrh->vring.num) in vringh_getdesc_user()
726 err = __vringh_iov(vrh, *head, (struct vringh_kiov *)riov, in vringh_getdesc_user()
775 void vringh_abandon_user(struct vringh *vrh, unsigned int num) in vringh_abandon_user() argument
779 vrh->last_avail_idx -= num; in vringh_abandon_user()
792 int vringh_complete_user(struct vringh *vrh, u16 head, u32 len) in vringh_complete_user() argument
796 used.id = cpu_to_vringh32(vrh, head); in vringh_complete_user()
797 used.len = cpu_to_vringh32(vrh, len); in vringh_complete_user()
798 return __vringh_complete(vrh, &used, 1, putu16_user, putused_user); in vringh_complete_user()
811 int vringh_complete_multi_user(struct vringh *vrh, in vringh_complete_multi_user() argument
815 return __vringh_complete(vrh, used, num_used, in vringh_complete_multi_user()
827 bool vringh_notify_enable_user(struct vringh *vrh) in vringh_notify_enable_user() argument
829 return __vringh_notify_enable(vrh, getu16_user, putu16_user); in vringh_notify_enable_user()
840 void vringh_notify_disable_user(struct vringh *vrh) in vringh_notify_disable_user() argument
842 __vringh_notify_disable(vrh, putu16_user); in vringh_notify_disable_user()
852 int vringh_need_notify_user(struct vringh *vrh) in vringh_need_notify_user() argument
854 return __vringh_need_notify(vrh, getu16_user); in vringh_need_notify_user()
859 static inline int getu16_kern(const struct vringh *vrh, in getu16_kern() argument
862 *val = vringh16_to_cpu(vrh, READ_ONCE(*p)); in getu16_kern()
866 static inline int putu16_kern(const struct vringh *vrh, __virtio16 *p, u16 val) in putu16_kern() argument
868 WRITE_ONCE(*p, cpu_to_vringh16(vrh, val)); in putu16_kern()
872 static inline int copydesc_kern(const struct vringh *vrh, in copydesc_kern() argument
879 static inline int putused_kern(const struct vringh *vrh, in putused_kern() argument
888 static inline int xfer_kern(const struct vringh *vrh, void *src, in xfer_kern() argument
895 static inline int kern_xfer(const struct vringh *vrh, void *dst, in kern_xfer() argument
914 int vringh_init_kern(struct vringh *vrh, u64 features, in vringh_init_kern() argument
926 vrh->little_endian = (features & (1ULL << VIRTIO_F_VERSION_1)); in vringh_init_kern()
927 vrh->event_indices = (features & (1 << VIRTIO_RING_F_EVENT_IDX)); in vringh_init_kern()
928 vrh->weak_barriers = weak_barriers; in vringh_init_kern()
929 vrh->completed = 0; in vringh_init_kern()
930 vrh->last_avail_idx = 0; in vringh_init_kern()
931 vrh->last_used_idx = 0; in vringh_init_kern()
932 vrh->vring.num = num; in vringh_init_kern()
933 vrh->vring.desc = desc; in vringh_init_kern()
934 vrh->vring.avail = avail; in vringh_init_kern()
935 vrh->vring.used = used; in vringh_init_kern()
960 int vringh_getdesc_kern(struct vringh *vrh, in vringh_getdesc_kern() argument
968 err = __vringh_get_head(vrh, getu16_kern, &vrh->last_avail_idx); in vringh_getdesc_kern()
973 if (err == vrh->vring.num) in vringh_getdesc_kern()
977 err = __vringh_iov(vrh, *head, riov, wiov, no_range_check, NULL, in vringh_getdesc_kern()
1023 void vringh_abandon_kern(struct vringh *vrh, unsigned int num) in vringh_abandon_kern() argument
1027 vrh->last_avail_idx -= num; in vringh_abandon_kern()
1040 int vringh_complete_kern(struct vringh *vrh, u16 head, u32 len) in vringh_complete_kern() argument
1044 used.id = cpu_to_vringh32(vrh, head); in vringh_complete_kern()
1045 used.len = cpu_to_vringh32(vrh, len); in vringh_complete_kern()
1047 return __vringh_complete(vrh, &used, 1, putu16_kern, putused_kern); in vringh_complete_kern()
1058 bool vringh_notify_enable_kern(struct vringh *vrh) in vringh_notify_enable_kern() argument
1060 return __vringh_notify_enable(vrh, getu16_kern, putu16_kern); in vringh_notify_enable_kern()
1071 void vringh_notify_disable_kern(struct vringh *vrh) in vringh_notify_disable_kern() argument
1073 __vringh_notify_disable(vrh, putu16_kern); in vringh_notify_disable_kern()
1083 int vringh_need_notify_kern(struct vringh *vrh) in vringh_need_notify_kern() argument
1085 return __vringh_need_notify(vrh, getu16_kern); in vringh_need_notify_kern()
1091 static int iotlb_translate(const struct vringh *vrh, in iotlb_translate() argument
1096 struct vhost_iotlb *iotlb = vrh->iotlb; in iotlb_translate()
1100 spin_lock(vrh->iotlb_lock); in iotlb_translate()
1131 spin_unlock(vrh->iotlb_lock); in iotlb_translate()
1136 static inline int copy_from_iotlb(const struct vringh *vrh, void *dst, in copy_from_iotlb() argument
1143 ret = iotlb_translate(vrh, (u64)(uintptr_t)src, in copy_from_iotlb()
1155 static inline int copy_to_iotlb(const struct vringh *vrh, void *dst, in copy_to_iotlb() argument
1162 ret = iotlb_translate(vrh, (u64)(uintptr_t)dst, in copy_to_iotlb()
1172 static inline int getu16_iotlb(const struct vringh *vrh, in getu16_iotlb() argument
1180 ret = iotlb_translate(vrh, (u64)(uintptr_t)p, sizeof(*p), in getu16_iotlb()
1187 *val = vringh16_to_cpu(vrh, READ_ONCE(*(__virtio16 *)from)); in getu16_iotlb()
1193 static inline int putu16_iotlb(const struct vringh *vrh, in putu16_iotlb() argument
1201 ret = iotlb_translate(vrh, (u64)(uintptr_t)p, sizeof(*p), in putu16_iotlb()
1208 WRITE_ONCE(*(__virtio16 *)to, cpu_to_vringh16(vrh, val)); in putu16_iotlb()
1214 static inline int copydesc_iotlb(const struct vringh *vrh, in copydesc_iotlb() argument
1219 ret = copy_from_iotlb(vrh, dst, (void *)src, len); in copydesc_iotlb()
1226 static inline int xfer_from_iotlb(const struct vringh *vrh, void *src, in xfer_from_iotlb() argument
1231 ret = copy_from_iotlb(vrh, dst, src, len); in xfer_from_iotlb()
1238 static inline int xfer_to_iotlb(const struct vringh *vrh, in xfer_to_iotlb() argument
1243 ret = copy_to_iotlb(vrh, dst, src, len); in xfer_to_iotlb()
1250 static inline int putused_iotlb(const struct vringh *vrh, in putused_iotlb() argument
1258 ret = copy_to_iotlb(vrh, dst, (void *)src, num * sizeof(*dst)); in putused_iotlb()
1277 int vringh_init_iotlb(struct vringh *vrh, u64 features, in vringh_init_iotlb() argument
1283 return vringh_init_kern(vrh, features, num, weak_barriers, in vringh_init_iotlb()
1294 void vringh_set_iotlb(struct vringh *vrh, struct vhost_iotlb *iotlb, in vringh_set_iotlb() argument
1297 vrh->iotlb = iotlb; in vringh_set_iotlb()
1298 vrh->iotlb_lock = iotlb_lock; in vringh_set_iotlb()
1323 int vringh_getdesc_iotlb(struct vringh *vrh, in vringh_getdesc_iotlb() argument
1331 err = __vringh_get_head(vrh, getu16_iotlb, &vrh->last_avail_idx); in vringh_getdesc_iotlb()
1336 if (err == vrh->vring.num) in vringh_getdesc_iotlb()
1340 err = __vringh_iov(vrh, *head, riov, wiov, no_range_check, NULL, in vringh_getdesc_iotlb()
1358 ssize_t vringh_iov_pull_iotlb(struct vringh *vrh, in vringh_iov_pull_iotlb() argument
1362 return vringh_iov_xfer(vrh, riov, dst, len, xfer_from_iotlb); in vringh_iov_pull_iotlb()
1375 ssize_t vringh_iov_push_iotlb(struct vringh *vrh, in vringh_iov_push_iotlb() argument
1379 return vringh_iov_xfer(vrh, wiov, (void *)src, len, xfer_to_iotlb); in vringh_iov_push_iotlb()
1391 void vringh_abandon_iotlb(struct vringh *vrh, unsigned int num) in vringh_abandon_iotlb() argument
1396 vrh->last_avail_idx -= num; in vringh_abandon_iotlb()
1409 int vringh_complete_iotlb(struct vringh *vrh, u16 head, u32 len) in vringh_complete_iotlb() argument
1413 used.id = cpu_to_vringh32(vrh, head); in vringh_complete_iotlb()
1414 used.len = cpu_to_vringh32(vrh, len); in vringh_complete_iotlb()
1416 return __vringh_complete(vrh, &used, 1, putu16_iotlb, putused_iotlb); in vringh_complete_iotlb()
1427 bool vringh_notify_enable_iotlb(struct vringh *vrh) in vringh_notify_enable_iotlb() argument
1429 return __vringh_notify_enable(vrh, getu16_iotlb, putu16_iotlb); in vringh_notify_enable_iotlb()
1440 void vringh_notify_disable_iotlb(struct vringh *vrh) in vringh_notify_disable_iotlb() argument
1442 __vringh_notify_disable(vrh, putu16_iotlb); in vringh_notify_disable_iotlb()
1452 int vringh_need_notify_iotlb(struct vringh *vrh) in vringh_need_notify_iotlb() argument
1454 return __vringh_need_notify(vrh, getu16_iotlb); in vringh_need_notify_iotlb()