@@ -225,6 +225,8 @@ bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
225
225
#endif
226
226
}
227
227
228
+ hcd_dcache_clean (& ohci_data , sizeof (ohci_data ));
229
+
228
230
// reset controller
229
231
OHCI_REG -> command_status_bit .controller_reset = 1 ;
230
232
while ( OHCI_REG -> command_status_bit .controller_reset ) {} // should not take longer than 10 us
@@ -506,12 +508,15 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
506
508
ohci_ed_t * ed = & ohci_data .control [dev_addr ].ed ;
507
509
ohci_gtd_t * qtd = & ohci_data .control [dev_addr ].gtd ;
508
510
511
+ hcd_dcache_clean (setup_packet , 8 );
512
+
509
513
gtd_init (qtd , (uint8_t * )(uintptr_t ) setup_packet , 8 );
510
514
gtd_get_extra_data (qtd )-> dev_addr = dev_addr ;
511
515
gtd_get_extra_data (qtd )-> ep_addr = tu_edpt_addr (0 , TUSB_DIR_OUT );
512
516
qtd -> pid = PID_SETUP ;
513
517
qtd -> data_toggle = GTD_DT_DATA0 ;
514
518
qtd -> delay_interrupt = OHCI_INT_ON_COMPLETE_YES ;
519
+ hcd_dcache_clean (qtd , sizeof (ohci_gtd_t ));
515
520
516
521
//------------- Attach TDs list to Control Endpoint -------------//
517
522
ed -> td_head .address = (uint32_t ) _phys_addr (qtd );
@@ -528,6 +533,13 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
528
533
uint8_t const epnum = tu_edpt_number (ep_addr );
529
534
uint8_t const dir = tu_edpt_dir (ep_addr );
530
535
536
+ // IN transfer: invalidate buffer, OUT transfer: clean buffer
537
+ if (dir ) {
538
+ hcd_dcache_invalidate (buffer , buflen );
539
+ } else {
540
+ hcd_dcache_clean (buffer , buflen );
541
+ }
542
+
531
543
if ( epnum == 0 )
532
544
{
533
545
ohci_ed_t * ed = & ohci_data .control [dev_addr ].ed ;
@@ -540,6 +552,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
540
552
gtd -> pid = dir ? PID_IN : PID_OUT ;
541
553
gtd -> data_toggle = GTD_DT_DATA1 ; // Both Data and Ack stage start with DATA1
542
554
gtd -> delay_interrupt = OHCI_INT_ON_COMPLETE_YES ;
555
+ hcd_dcache_clean (gtd , sizeof (ohci_gtd_t ));
543
556
544
557
ed -> td_head .address = (uint32_t ) _phys_addr (gtd );
545
558
@@ -559,6 +572,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
559
572
TU_ASSERT (new_gtd );
560
573
561
574
gtd -> next = (uint32_t )_phys_addr (new_gtd );
575
+ hcd_dcache_clean (gtd , sizeof (ohci_gtd_t ));
562
576
563
577
hcd_dcache_uncached (ed -> td_tail ) = (uint32_t )_phys_addr (new_gtd );
564
578
@@ -603,6 +617,12 @@ static ohci_td_item_t* list_reverse(ohci_td_item_t* td_head)
603
617
while (td_head != NULL )
604
618
{
605
619
td_head = _virt_addr (td_head );
620
+ // FIXME: This is not the correct object size.
621
+ // However, because we have hardcoded the assumption that
622
+ // a cache line is at least 32 bytes (in ohci.h), and
623
+ // because both types of TD structs are <= 32 bytes, this
624
+ // nonetheless still works without error.
625
+ hcd_dcache_invalidate (td_head , sizeof (ohci_td_item_t ));
606
626
uint32_t next = td_head -> next ;
607
627
608
628
// make current's item become reverse's first item
0 commit comments