Skip to content

Commit e4f4ad5

Browse files
committed
use weak local for dcache function to skip if()
1 parent a3e017b commit e4f4ad5

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

src/portable/ehci/ehci.c

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,25 @@ static void qtd_init (ehci_qtd_t* qtd, void const* buffer, uint16_t total_bytes)
164164
static inline void list_insert (ehci_link_t *current, ehci_link_t *new, uint8_t new_type);
165165
static inline ehci_link_t* list_next (ehci_link_t *p_link_pointer);
166166

167+
TU_ATTR_WEAK void hcd_dcache_clean(void* addr, uint32_t data_size) {
168+
(void) addr;
169+
(void) data_size;
170+
}
171+
172+
// invalidate data cache: mark cache as invalid, next read will read from memory
173+
// Required BOTH before and after an DMA RX transfer
174+
TU_ATTR_WEAK void hcd_dcache_invalidate(void* addr, uint32_t data_size) {
175+
(void) addr;
176+
(void) data_size;
177+
}
178+
179+
// clean and invalidate data cache
180+
// Required before an DMA transfer where memory is both read/write by DMA
181+
TU_ATTR_WEAK void hcd_dcache_clean_invalidate(void* addr, uint32_t data_size) {
182+
(void) addr;
183+
(void) data_size;
184+
}
185+
167186
//--------------------------------------------------------------------+
168187
// HCD API
169188
//--------------------------------------------------------------------+
@@ -342,9 +361,7 @@ bool ehci_init(uint8_t rhport, uint32_t capability_reg, uint32_t operatial_reg)
342361

343362
regs->periodic_list_base = (uint32_t) framelist;
344363

345-
if(hcd_dcache_clean) {
346-
hcd_dcache_clean(&ehci_data, sizeof(ehci_data_t));
347-
}
364+
hcd_dcache_clean(&ehci_data, sizeof(ehci_data_t));
348365

349366
//------------- TT Control (NXP only) -------------//
350367
regs->nxp_tt_control = 0;
@@ -429,10 +446,8 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
429446
// TODO might need to disable async/period list
430447
list_insert(list_head, (ehci_link_t*) p_qhd, EHCI_QTYPE_QHD);
431448

432-
if(hcd_dcache_clean) {
433-
hcd_dcache_clean(p_qhd, sizeof(ehci_qhd_t));
434-
hcd_dcache_clean(list_head, sizeof(ehci_link_t));
435-
}
449+
hcd_dcache_clean(p_qhd, sizeof(ehci_qhd_t));
450+
hcd_dcache_clean(list_head, sizeof(ehci_link_t));
436451

437452
return true;
438453
}
@@ -447,10 +462,8 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
447462
qtd_init(td, setup_packet, 8);
448463
td->pid = EHCI_PID_SETUP;
449464

450-
if (hcd_dcache_clean && hcd_dcache_clean_invalidate) {
451-
hcd_dcache_clean((void *) setup_packet, 8);
452-
hcd_dcache_clean_invalidate(td, sizeof(ehci_qtd_t));
453-
}
465+
hcd_dcache_clean((void *) setup_packet, 8);
466+
hcd_dcache_clean_invalidate(td, sizeof(ehci_qtd_t));
454467

455468
// sw region
456469
qhd->p_qtd_list_head = td;
@@ -459,9 +472,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
459472
// attach TD
460473
qhd->qtd_overlay.next.address = (uint32_t) td;
461474

462-
if (hcd_dcache_clean_invalidate) {
463-
hcd_dcache_clean_invalidate(qhd, sizeof(ehci_qhd_t));
464-
}
475+
hcd_dcache_clean_invalidate(qhd, sizeof(ehci_qhd_t));
465476

466477
return true;
467478
}
@@ -496,15 +507,13 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
496507
qtd->pid = qhd->pid;
497508
}
498509

499-
if (hcd_dcache_clean && hcd_dcache_clean_invalidate) {
500-
// IN transfer: invalidate buffer, OUT transfer: clean buffer
501-
if (dir) {
502-
hcd_dcache_invalidate(buffer, buflen);
503-
}else {
504-
hcd_dcache_clean(buffer, buflen);
505-
}
506-
hcd_dcache_clean_invalidate(qtd, sizeof(ehci_qtd_t));
510+
// IN transfer: invalidate buffer, OUT transfer: clean buffer
511+
if (dir) {
512+
hcd_dcache_invalidate(buffer, buflen);
513+
}else {
514+
hcd_dcache_clean(buffer, buflen);
507515
}
516+
hcd_dcache_clean_invalidate(qtd, sizeof(ehci_qtd_t));
508517

509518
// Software: assign TD to QHD
510519
qhd->p_qtd_list_head = qtd;
@@ -513,9 +522,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
513522
// attach TD to QHD start transferring
514523
qhd->qtd_overlay.next.address = (uint32_t) qtd;
515524

516-
if (hcd_dcache_clean_invalidate) {
517-
hcd_dcache_clean_invalidate(qhd, sizeof(ehci_qhd_t));
518-
}
525+
hcd_dcache_clean_invalidate(qhd, sizeof(ehci_qhd_t));
519526

520527
return true;
521528
}
@@ -570,9 +577,7 @@ static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd)
570577
{
571578
ehci_qtd_t * volatile qtd = (ehci_qtd_t * volatile) p_qhd->p_qtd_list_head;
572579

573-
if (hcd_dcache_invalidate) {
574-
hcd_dcache_invalidate(qtd, sizeof(ehci_qtd_t));
575-
}
580+
hcd_dcache_invalidate(qtd, sizeof(ehci_qtd_t));
576581

577582
bool const is_ioc = (qtd->int_on_complete != 0);
578583
uint8_t const ep_addr = tu_edpt_addr(p_qhd->ep_number, qtd->pid == EHCI_PID_IN ? 1 : 0);
@@ -596,9 +601,7 @@ static void async_list_xfer_complete_isr(ehci_qhd_t * const async_head)
596601
ehci_qhd_t *p_qhd = async_head;
597602
do
598603
{
599-
if (hcd_dcache_invalidate) {
600-
hcd_dcache_invalidate(p_qhd, sizeof(ehci_qhd_t));
601-
}
604+
hcd_dcache_invalidate(p_qhd, sizeof(ehci_qhd_t));
602605

603606
// halted or error is processed in error isr
604607
if ( !p_qhd->qtd_overlay.halted ) {

0 commit comments

Comments
 (0)