vfio-helpers.c (521b97cd4e5f4a636f56515057084b1a86552b0b) vfio-helpers.c (71e3038c1500e2d6075b306f26d565f982287756)
1/*
2 * VFIO utility
3 *
4 * Copyright 2016 - 2018 Red Hat, Inc.
5 *
6 * Authors:
7 * Fam Zheng <famz@redhat.com>
8 *

--- 707 unchanged lines hidden (view full) ---

716 *iova = s->high_water_mark - size;
717 s->high_water_mark = *iova;
718 return 0;
719 }
720 }
721 return -ENOMEM;
722}
723
1/*
2 * VFIO utility
3 *
4 * Copyright 2016 - 2018 Red Hat, Inc.
5 *
6 * Authors:
7 * Fam Zheng <famz@redhat.com>
8 *

--- 707 unchanged lines hidden (view full) ---

716 *iova = s->high_water_mark - size;
717 s->high_water_mark = *iova;
718 return 0;
719 }
720 }
721 return -ENOMEM;
722}
723
724/**
725 * qemu_vfio_water_mark_reached:
726 *
727 * Returns %true if high watermark has been reached, %false otherwise.
728 */
729static bool qemu_vfio_water_mark_reached(QEMUVFIOState *s, size_t size,
730 Error **errp)
731{
732 if (s->high_water_mark - s->low_water_mark + 1 < size) {
733 error_setg(errp, "iova exhausted (water mark reached)");
734 return true;
735 }
736 return false;
737}
738
724/* Map [host, host + size) area into a contiguous IOVA address space, and store
725 * the result in @iova if not NULL. The caller need to make sure the area is
726 * aligned to page size, and mustn't overlap with existing mapping areas (split
727 * mapping status within this area is not allowed).
728 */
729int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
730 bool temporary, uint64_t *iova, Error **errp)
731{

--- 5 unchanged lines hidden (view full) ---

737 assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size));
738 assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
739 trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
740 QEMU_LOCK_GUARD(&s->lock);
741 mapping = qemu_vfio_find_mapping(s, host, &index);
742 if (mapping) {
743 iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
744 } else {
739/* Map [host, host + size) area into a contiguous IOVA address space, and store
740 * the result in @iova if not NULL. The caller need to make sure the area is
741 * aligned to page size, and mustn't overlap with existing mapping areas (split
742 * mapping status within this area is not allowed).
743 */
744int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
745 bool temporary, uint64_t *iova, Error **errp)
746{

--- 5 unchanged lines hidden (view full) ---

752 assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size));
753 assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
754 trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
755 QEMU_LOCK_GUARD(&s->lock);
756 mapping = qemu_vfio_find_mapping(s, host, &index);
757 if (mapping) {
758 iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
759 } else {
745 if (s->high_water_mark - s->low_water_mark + 1 < size) {
760 if (qemu_vfio_water_mark_reached(s, size, errp)) {
746 ret = -ENOMEM;
747 goto out;
748 }
749 if (!temporary) {
750 if (qemu_vfio_find_fixed_iova(s, size, &iova0)) {
751 ret = -ENOMEM;
752 goto out;
753 }

--- 92 unchanged lines hidden ---
761 ret = -ENOMEM;
762 goto out;
763 }
764 if (!temporary) {
765 if (qemu_vfio_find_fixed_iova(s, size, &iova0)) {
766 ret = -ENOMEM;
767 goto out;
768 }

--- 92 unchanged lines hidden ---