usb_alloc_noncoherent(9)
π usb_alloc_noncoherent (Kernel API Manual, bestie!!) π
okay so picture this: you're deep in the kernel, you need a DMA buffer that the hardware is not allowed to assume is cache-coherent, and you need the whole thing to be tracked properly so the USB core can do the sync dance for you. that's literally this function. it lives in the Kernel API Manual and it's a whole vibe π
β¨ SYNOPSIS β¨
void * usb_alloc_noncoherent (struct usb_device *dev , size_t size ,
gfp_t mem_flags , dma_addr_t *dma , enum dma_data_direction dir , struct
sg_table **table );
like, it hands you back a void * β either your shiny new buffer or null β and that's it, no cap π«Ά
π ARGUMENTS π
devβ the device this buffer is gonna be used with. yes, that one. πsizeβ how big you want the buffer. the requested buffer size, that's the whole thing.mem_flagsβ these affect whether the allocation is allowed to block. so like, choose wisely, bestie.dmaβ you pass a pointer, and it gets filled in with the DMA address of the buffer. output parameter energy β¨dirβ the DMA transfer direction. which way the bytes are flowing, iykyk.tableβ pointer-shaped, and it comes back holding thesg_tableof the allocated memory. π¦
πΈ DESCRIPTION πΈ
so here's the tea: to explicitly manage memory ownership for the kernel vs the device by USB core, you the user need to save that sg_table to urb->sgt. then USB core will do the DMA sync for CPU and device properly. that's the deal. that's how it works. periodt. π
and when the buffer is no longer used?? free it with usb_free_noncoherent. do not be out here leaking, i'm begging π
β RETURN β
either null (which means no buffer could be allocated, sad, we've all been there) β or the cpu-space pointer to a buffer that may be used to perform DMA to the specified device. such cpu-space buffers are returned along with the DMA address (through the pointer provided). so you get both at once, iconic behaviour honestly π
π SEE ALSO π
okay the whole squad is here, kernel file ./drivers/usb/core/usb.c, plus:
usb_find_common_endpoints(9)usb_find_common_endpoints_reverse(9)usb_find_endpoint(9)usb_check_bulk_endpoints(9)usb_check_int_endpoints(9)usb_find_alt_setting(9)usb_ifnum_to_if(9)usb_altnum_to_altsetting(9)usb_find_interface(9)usb_for_each_dev(9)usb_release_dev(9)usb_alloc_dev(9)usb_get_dev(9)usb_put_dev(9)usb_get_intf(9)usb_put_intf(9)usb_intf_get_dma_device(9)usb_lock_device_for_reset(9)usb_get_current_frame_number(9)usb_alloc_coherent(9)usb_free_coherent(9)usb_free_noncoherent(9)usb_endpoint_max_periodic_payload(9)usb_endpoint_is_hs_isoc_double(9)
and that's the page!! mwah π this one's from ./drivers/usb/core, dated October 2026 β go forth and allocate noncoherently, bestie, you've got this ππ«Ά
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms