1647
1648 /**
1649 * vringh_init_iomem - initialize a vringh for a vring on io-memory.
1650 * @vrh: the vringh to initialize.
1651 * @features: the feature bits for this ring.
1652 * @num: the number of elements.
1653 * @weak_barriers: true if we only need memory barriers, not I/O.
1654 * @desc: the userspace descriptor pointer.
1655 * @avail: the userspace avail pointer.
1656 * @used: the userspace used pointer.
1657 *
1658 * Returns an error if num is invalid: you should check pointers
1659 * yourself!
1660 */
1661 int vringh_init_iomem(struct vringh *vrh, u64 features, unsigned int num,
1662 bool weak_barriers, struct vring_desc *desc,
1663 struct vring_avail *avail, struct vring_used *used)
1664 {
1665 return vringh_init_kern(vrh, features, num, weak_barriers, desc, avail,
1666 used);
1667 }
1668 EXPORT_SYMBOL(vringh_init_iomem);
1669
1670 /**
1671 * vringh_getdesc_iomem - get next available descriptor from vring on io-memory.
1672 * @vrh: the vring on io-memory.
1673 * @riov: where to put the readable descriptors (or NULL)
1674 * @wiov: where to put the writable descriptors (or NULL)
1675 * @head: head index we received, for passing to vringh_complete_iomem().
1676 * @gfp: flags for allocating larger riov/wiov.
1677 *
1678 * Returns 0 if there was no descriptor, 1 if there was, or -errno.
1679 *
1680 * There some notes, and those are same with vringh_getdesc_kern(). Please see
1681 * it.
1682 */
1683 int vringh_getdesc_iomem(struct vringh *vrh, struct vringh_kiov *riov,
1684 struct vringh_kiov *wiov, u16 *head, gfp_t gfp)
1685 {
1686 int err;
1687
1688 err = __vringh_get_head(vrh, getu16_iomem, &vrh->last_avail_idx);
1689 if (err < 0)
1690 return err;
1691
1692 /* Empty... */
1693 if (err == vrh->vring.num)
1694 return 0;
1695
1696 *head = err;
1697 err = __vringh_iov(vrh, *head, riov, wiov, no_range_check, NULL, gfp,
1698 copydesc_iomem);
1699 if (err)
1700 return err;
1701
1702 return 1;
1703 }
1704 EXPORT_SYMBOL(vringh_getdesc_iomem);
1705
1706 /**
1707 * vringh_iov_pull_iomem - copy bytes from vring_iov.
1708 * @riov: the riov as passed to vringh_getdesc_iomem() (updated as we consume)
1709 * @dst: the place to copy.
1710 * @len: the maximum length to copy.
1711 *
1712 * Returns the bytes copied <= len or a negative errno.
1713 */
1714 ssize_t vringh_iov_pull_iomem(struct vringh *vrh, struct vringh_kiov *riov,
1715 void *dst, size_t len)
1716 {
1717 return vringh_iov_xfer(vrh, riov, dst, len, xfer_from_iomem);
1718 }
1719 EXPORT_SYMBOL(vringh_iov_pull_iomem);
1720
1721 /**
1722 * vringh_iov_push_iomem - copy bytes into vring_iov.
1723 * @wiov: the wiov as passed to vringh_getdesc_iomem() (updated as we consume)
1724 * @src: the place to copy from.
1725 * @len: the maximum length to copy.
1726 *
1727 * Returns the bytes copied <= len or a negative errno.
1728 */
1729 ssize_t vringh_iov_push_iomem(struct vringh *vrh, struct vringh_kiov *wiov,
1730 const void *src, size_t len)
1731 {
1732 return vringh_iov_xfer(vrh, wiov, (void *)src, len, xfer_to_iomem);
1733 }
1734 EXPORT_SYMBOL(vringh_iov_push_iomem);
1735
1736 /**
1737 * vringh_abandon_iomem - we've decided not to handle the descriptor(s).
1738 * @vrh: the vring.
1739 * @num: the number of descriptors to put back (ie. num
1740 * vringh_getdesc_iomem() to undo).
1741 *
1742 * The next vringh_get_kern() will return the old descriptor(s) again.
1743 */
1744 void vringh_abandon_iomem(struct vringh *vrh, unsigned int num)
1745 {
1746 vringh_abandon_kern(vrh, num);
1747 }
1748 EXPORT_SYMBOL(vringh_abandon_iomem);
1749
1750 /**
1751 * vringh_complete_iomem - we've finished with descriptor, publish it.
1752 * @vrh: the vring.
1753 * @head: the head as filled in by vringh_getdesc_iomem().
1754 * @len: the length of data we have written.
1755 *
1756 * You should check vringh_need_notify_iomem() after one or more calls
1757 * to this function.
1758 */
1759 int vringh_complete_iomem(struct vringh *vrh, u16 head, u32 len)
1760 {
1761 struct vring_used_elem used;
1762
1763 used.id = cpu_to_vringh32(vrh, head);
1764 used.len = cpu_to_vringh32(vrh, len);
1765
1766 return __vringh_complete(vrh, &used, 1, putu16_iomem, putused_iomem);
1767 }
1768 EXPORT_SYMBOL(vringh_complete_iomem);
1769
1770 /**
1771 * vringh_notify_enable_iomem - we want to know if something changes.
1772 * @vrh: the vring.
1773 *
1774 * This always enables notifications, but returns false if there are
1775 * now more buffers available in the vring.
1776 */
1777 bool vringh_notify_enable_iomem(struct vringh *vrh)
1778 {
1779 return __vringh_notify_enable(vrh, getu16_iomem, putu16_iomem);
1780 }
1781 EXPORT_SYMBOL(vringh_notify_enable_iomem);
1782
1783 /**
1784 * vringh_notify_disable_iomem - don't tell us if something changes.
1785 * @vrh: the vring.
1786 *
1787 * This is our normal running state: we disable and then only enable when
1788 * we're going to sleep.
1789 */
1790 void vringh_notify_disable_iomem(struct vringh *vrh)
1791 {
1792 __vringh_notify_disable(vrh, putu16_iomem);
1793 }
1794 EXPORT_SYMBOL(vringh_notify_disable_iomem);
1795
1796 /**
1797 * vringh_need_notify_iomem - must we tell the other side about used buffers?
1798 * @vrh: the vring we've called vringh_complete_iomem() on.
1799 *
1800 * Returns -errno or 0 if we don't need to tell the other side, 1 if we do.
1801 */
1802 int vringh_need_notify_iomem(struct vringh *vrh)
1803 {
1804 return __vringh_need_notify(vrh, getu16_iomem);
1805 }
1806 EXPORT_SYMBOL(vringh_need_notify_iomem);
1807
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki