From 7c743917546761185c0d1e66cdcc27e502536f56 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Tue, 15 Feb 2022 00:14:14 +0200 Subject: [PATCH] bdk: bpmp: do not use full maintenance Instead use proper clean/invalidation of dcache. --- bdk/sec/se.c | 9 ++++++--- bdk/storage/sdmmc_driver.c | 7 ++++--- bdk/usb/usbd.c | 6 +++--- bdk/usb/xusbd.c | 14 +++++++++----- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/bdk/sec/se.c b/bdk/sec/se.c index 711bd86..da10786 100644 --- a/bdk/sec/se.c +++ b/bdk/sec/se.c @@ -144,7 +144,8 @@ static int _se_execute(u32 op, void *dst, u32 dst_size, const void *src, u32 src SE(SE_ERR_STATUS_REG) = SE(SE_ERR_STATUS_REG); SE(SE_INT_STATUS_REG) = SE(SE_INT_STATUS_REG); - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY, false); + // Flush data before starting OP. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLEAN_WAY, false); SE(SE_OPERATION_REG) = op; @@ -152,7 +153,8 @@ static int _se_execute(u32 op, void *dst, u32 dst_size, const void *src, u32 src { int res = _se_wait(); - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY, false); + // Invalidate data after OP is done. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY, false); if (src) { @@ -175,7 +177,8 @@ static int _se_execute_finalize() { int res = _se_wait(); - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY, false); + // Invalidate data after OP is done. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY, false); if (ll_src) { diff --git a/bdk/storage/sdmmc_driver.c b/bdk/storage/sdmmc_driver.c index f31271e..65590e2 100644 --- a/bdk/storage/sdmmc_driver.c +++ b/bdk/storage/sdmmc_driver.c @@ -983,6 +983,7 @@ static int _sdmmc_update_dma(sdmmc_t *sdmmc) sdmmc->dma_addr_next += 0x80000; } } + if (result != SDMMC_MASKINT_NOERROR) { #ifdef ERROR_EXTRA_PRINTING @@ -1017,7 +1018,7 @@ static int _sdmmc_execute_cmd_inner(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_ } // Flush cache before starting the transfer. - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY, false); + bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLEAN_WAY, false); is_data_present = true; } @@ -1066,8 +1067,8 @@ DPRINTF("rsp(%d): %08X, %08X, %08X, %08X\n", result, { if (req) { - // Flush cache after transfer. - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY, false); + // Invalidate cache after transfer. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY, false); if (blkcnt_out) *blkcnt_out = blkcnt; diff --git a/bdk/usb/usbd.c b/bdk/usb/usbd.c index 81d719a..223cfa7 100644 --- a/bdk/usb/usbd.c +++ b/bdk/usb/usbd.c @@ -787,7 +787,7 @@ static int _usbd_ep_operation(usb_ep_t endpoint, u8 *buf, u32 len, u32 sync_time if (direction == USB_DIR_IN) { prime_bit = USB2D_ENDPT_STATUS_TX_OFFSET << actual_ep; - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY, false); + bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLEAN_WAY, false); } else prime_bit = USB2D_ENDPT_STATUS_RX_OFFSET << actual_ep; @@ -826,7 +826,7 @@ out: res = USB_ERROR_XFER_ERROR; if (direction == USB_DIR_OUT) - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY, false); + bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY, false); } return res; @@ -1470,7 +1470,7 @@ int usb_device_ep1_out_reading_finish(u32 *pending_bytes, u32 sync_timeout) *pending_bytes = _usbd_get_ep1_out_bytes_read(); - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY, false); + bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY, false); if (ep_status == USB_EP_STATUS_IDLE) return USB_RES_OK; diff --git a/bdk/usb/xusbd.c b/bdk/usb/xusbd.c index 8556ee5..394d5c2 100644 --- a/bdk/usb/xusbd.c +++ b/bdk/usb/xusbd.c @@ -993,7 +993,8 @@ static int _xusb_queue_trb(u32 ep_idx, void *trb, bool ring_doorbell) // Ring doorbell. if (ring_doorbell) { - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY, false); + // Flush data before transfer. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLEAN_WAY, false); u32 target_id = (ep_idx << 8) & 0xFFFF; if (ep_idx == XUSB_EP_CTRL_IN) target_id |= usbd_xotg->ctrl_seq_num << 16; @@ -1947,10 +1948,11 @@ int xusb_device_ep1_out_read(u8 *buf, u32 len, u32 *bytes_read, u32 sync_tries) if (bytes_read) *bytes_read = res ? 0 : usbd_xotg->tx_bytes[USB_DIR_OUT]; - - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY, false); } + // Invalidate data after transfer. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY, false); + return res; } @@ -1988,7 +1990,8 @@ int xusb_device_ep1_out_reading_finish(u32 *pending_bytes, u32 sync_tries) if (pending_bytes) *pending_bytes = res ? 0 : usbd_xotg->tx_bytes[USB_DIR_OUT]; - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY, false); + // Invalidate data after transfer. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY, false); return res; } @@ -1998,7 +2001,8 @@ int xusb_device_ep1_in_write(u8 *buf, u32 len, u32 *bytes_written, u32 sync_trie if (len > USB_EP_BUFFER_MAX_SIZE) len = USB_EP_BUFFER_MAX_SIZE; - bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLN_INV_WAY, false); + // Flush data before transfer. + bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLEAN_WAY, false); int res = USB_RES_OK; usbd_xotg->tx_count[USB_DIR_IN] = 0;