There's already such a barrier in usbd_transfer() code-path, but this
one is called when the frames are queued to the HC ring. The audio
samples are stored in memory by userland later, *after* the frames are
scheduled (but before they are sent on the wire) so a barrier is
needed there. Without this change, the data produced by userland may
stay in the CPU caches and is not "seen" by the HC's DMA engine, in
turn the device plays noise on certain arm64 machines (RPI4, for
instance).
Fix mostly from Luca Castagnini with few tweaks from me. OK patrick@
-/* $OpenBSD: uaudio.c,v 1.160 2020/06/11 16:00:10 ratchov Exp $ */
+/* $OpenBSD: uaudio.c,v 1.161 2021/05/18 10:02:00 ratchov Exp $ */
/*
* Copyright (c) 2018 Alexandre Ratchov <alex@caoua.org>
*
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdivar.h>
+#include <dev/usb/usb_mem.h>
#ifdef UAUDIO_DEBUG
#define DPRINTF(...) \
}
s->ubuf_pos += count;
if (s->ubuf_pos == xfer->size) {
+ usb_syncmem(&xfer->usb_xfer->dmabuf, 0, xfer->size,
+ BUS_DMASYNC_PREWRITE);
s->ubuf_pos = 0;
#ifdef DIAGNOSTIC
if (s->ubuf_xfer == s->nxfers) {