The branch main has been updated by aokblast:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=776e26f56832cb25dc70713acfb579bda6105024

commit 776e26f56832cb25dc70713acfb579bda6105024
Author:     ShengYi Hung <aokbl...@freebsd.org>
AuthorDate: 2025-07-09 08:11:34 +0000
Commit:     ShengYi Hung <aokbl...@freebsd.org>
CommitDate: 2025-07-21 06:16:07 +0000

    libusb: implement libusb_dev_mem_{alloc,free}
    
    libusb provides an API to create DMA buffers for USB packets from the
    kernel. However, this feature is only available on Linux. On unsupported
    platforms, the allocation function returns NULL, and the free function
    returns 'not supported'.
    
    Approved by:    markj (mentor), lwhsu(mentor)
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D51222
---
 lib/libusb/libusb.3   | 19 ++++++++++++++++++-
 lib/libusb/libusb.h   |  3 +++
 lib/libusb/libusb10.c | 13 +++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/lib/libusb/libusb.3 b/lib/libusb/libusb.3
index 2e2ac8b1e98b..9dc752f0fd7b 100644
--- a/lib/libusb/libusb.3
+++ b/lib/libusb/libusb.3
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd June 13, 2025
+.Dd July 9, 2025
 .Dt LIBUSB 3
 .Os
 .Sh NAME
@@ -366,6 +366,23 @@ argument is non-zero the feature is enabled.
 Else disabled.
 Returns 0 on success and a LIBUSB_ERROR code on
 failure.
+.Pp
+.Ft unsigned char *
+.Fn libusb_dev_mem_alloc "libusb_device_handle *devh"
+This function attempts to allocate a DMA memory block from the given
+.Fa devh
+so that we can enjoy the zero-copy transfer from kernel.
+This function is provided for compatibility and is currently unimplemented and 
always returns NULL.
+.Pp
+.Ft int
+.Fn libusb_dev_mem_free "libusb_device_handle *devh" "unsigned char *buffer" 
"size_t size"
+This function frees the DMA memory in
+.Fa devh
+from the given
+.Fa buffer
+with
+.Fa size .
+This function is unimplemented and always returns LIBUSB_ERROR_NOT_SUPPORTED.
 .Sh USB DESCRIPTORS
 .Ft int
 .Fn libusb_get_device_descriptor "libusb_device *dev" 
"libusb_device_descriptor *desc"
diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h
index 520b81da3a75..57478c1787ee 100644
--- a/lib/libusb/libusb.h
+++ b/lib/libusb/libusb.h
@@ -513,6 +513,9 @@ int         
libusb_detach_kernel_driver(libusb_device_handle * devh, int interface);
 int    libusb_attach_kernel_driver(libusb_device_handle * devh, int interface);
 int    libusb_set_auto_detach_kernel_driver(libusb_device_handle *dev, int 
enable);
 int    libusb_set_interface_alt_setting(libusb_device_handle * devh, int 
interface_number, int alternate_setting);
+unsigned char *libusb_dev_mem_alloc(libusb_device_handle *devh);
+int    libusb_dev_mem_free(libusb_device_handle *devh, unsigned char *buffer,
+    size_t size);
 
 /* USB Descriptors */
 
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c
index 6f1ca877fc28..6bfc01eb8c4e 100644
--- a/lib/libusb/libusb10.c
+++ b/lib/libusb/libusb10.c
@@ -1904,3 +1904,16 @@ libusb_setlocale(const char *locale)
 
        return (LIBUSB_ERROR_INVALID_PARAM);
 }
+
+unsigned char *
+libusb_dev_mem_alloc(libusb_device_handle *devh)
+{
+       return (NULL);
+}
+
+int
+libusb_dev_mem_free(libusb_device_handle *devh, unsigned char *buffer,
+    size_t size)
+{
+       return (LIBUSB_ERROR_NOT_SUPPORTED);
+}

Reply via email to