@@ -67,6 +67,16 @@ static bool _sof_en;
6767//--------------------------------------------------------------------
6868// DMA
6969//--------------------------------------------------------------------
70+ // When DMA requires cache synchronization for memory
71+ // Data synchronization: cache to memory
72+ #ifndef dsync_c2m
73+ #define dsync_c2m (_addr , _size )
74+ #endif // dsync_c2m
75+
76+ // Data synchronization: memory to cache
77+ #ifndef dsync_m2c
78+ #define dsync_m2c (_addr , _size )
79+ #endif // dsync_m2c
7080
7181TU_ATTR_ALWAYS_INLINE static inline bool dma_device_enabled (const dwc2_regs_t * dwc2 ) {
7282 (void ) dwc2 ;
@@ -359,7 +369,7 @@ static void edpt_schedule_packets(uint8_t rhport, uint8_t const epnum, uint8_t c
359369
360370 if (dma_device_enabled (dwc2 )) {
361371 dep -> diepdma = (uintptr_t )xfer -> buffer ;
362-
372+ dsync_c2m ( xfer -> buffer , total_bytes );
363373 // For ISO endpoint set correct odd/even bit for next frame.
364374 if ((dep -> diepctl & DIEPCTL_EPTYP ) == DIEPCTL_EPTYP_0 && (XFER_CTL_BASE (epnum , dir ))-> interval == 1 ) {
365375 // Take odd/even bit from frame counter.
@@ -397,6 +407,7 @@ static void edpt_schedule_packets(uint8_t rhport, uint8_t const epnum, uint8_t c
397407
398408 if (dma_device_enabled (dwc2 )) {
399409 dep -> doepdma = (uintptr_t )xfer -> buffer ;
410+ dsync_c2m (xfer -> buffer , total_bytes );
400411 }
401412
402413 dep -> doepctl |= DOEPCTL_EPENA | DOEPCTL_CNAK ;
@@ -775,6 +786,7 @@ static void handle_epout_irq(uint8_t rhport) {
775786
776787 if (dma_device_enabled (dwc2 )) {
777788 dma_setup_prepare (rhport );
789+ dsync_m2c ((uint8_t * ) _setup_packet , sizeof (_setup_packet ));
778790 }
779791
780792 dcd_event_setup_received (rhport , (uint8_t * ) _setup_packet , true);
@@ -801,7 +813,7 @@ static void handle_epout_irq(uint8_t rhport) {
801813 if (epnum == 0 && xfer -> total_len == 0 ) {
802814 dma_setup_prepare (rhport );
803815 }
804-
816+ dsync_m2c ( xfer -> buffer , xfer -> total_len );
805817 dcd_event_xfer_complete (rhport , epnum , xfer -> total_len , XFER_RESULT_SUCCESS , true);
806818 }
807819 } else {
0 commit comments