Skip to content

Commit d4f8cc0

Browse files
committed
update(port/ehci): add pad for qh & qtd cachemaintain, add CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE for qh&qtd
Signed-off-by: sakumisu <1203593632@qq.com>
1 parent 5140800 commit d4f8cc0

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

port/ehci/usb_hc_ehci.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,18 @@ static void ehci_qh_free(struct usbh_bus *bus, struct ehci_qh_hw *qh)
7676
}
7777
}
7878

79-
#ifdef CONFIG_USB_DCACHE_ENABLE
79+
#if CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE
8080
static inline void usb_ehci_qh_qtd_flush(struct ehci_qh_hw *qh)
8181
{
8282
struct ehci_qtd_hw *qtd;
8383

8484
qtd = EHCI_ADDR2QTD(qh->first_qtd);
8585

8686
while (qtd) {
87-
usb_dcache_clean((uintptr_t)&qtd->hw, USB_ALIGN_UP(SIZEOF_EHCI_QTD, CONFIG_USB_EHCI_ALIGN_SIZE));
88-
89-
if (!qtd->dir_in) {
90-
usb_dcache_clean(qtd->bufaddr, USB_ALIGN_UP(qtd->length, CONFIG_USB_ALIGN_SIZE));
91-
}
87+
usb_dcache_clean((uintptr_t)&qtd->hw, CONFIG_USB_EHCI_ALIGN_SIZE);
9288
qtd = EHCI_ADDR2QTD(qtd->hw.next_qtd);
9389
}
94-
95-
usb_dcache_clean((uintptr_t)&qh->hw, USB_ALIGN_UP(SIZEOF_EHCI_QH, CONFIG_USB_EHCI_ALIGN_SIZE));
90+
usb_dcache_clean((uintptr_t)&qh->hw, CONFIG_USB_EHCI_ALIGN_SIZE);
9691
}
9792
#else
9893
#define usb_ehci_qh_qtd_flush(qh)
@@ -103,9 +98,12 @@ static inline void ehci_qh_add_head(struct ehci_qh_hw *head, struct ehci_qh_hw *
10398
n->hw.hlp = head->hw.hlp;
10499
usb_ehci_qh_qtd_flush(n);
105100

106-
head->hw.hlp = QH_HLP_QH(n);
101+
usb_dcache_flush((uintptr_t)n->urb->transfer_buffer, USB_ALIGN_UP(n->urb->transfer_buffer_length, CONFIG_USB_ALIGN_SIZE));
107102

108-
usb_dcache_clean((uintptr_t)&head->hw, USB_ALIGN_UP(SIZEOF_EHCI_QH, CONFIG_USB_EHCI_ALIGN_SIZE));
103+
head->hw.hlp = QH_HLP_QH(n);
104+
#if CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE
105+
usb_dcache_clean((uintptr_t)&head->hw, CONFIG_USB_EHCI_ALIGN_SIZE);
106+
#endif
109107
}
110108

111109
static inline void ehci_qh_remove(struct ehci_qh_hw *head, struct ehci_qh_hw *n)
@@ -118,7 +116,9 @@ static inline void ehci_qh_remove(struct ehci_qh_hw *head, struct ehci_qh_hw *n)
118116

119117
if (tmp) {
120118
tmp->hw.hlp = n->hw.hlp;
121-
usb_dcache_clean((uintptr_t)&tmp->hw, USB_ALIGN_UP(SIZEOF_EHCI_QH, CONFIG_USB_EHCI_ALIGN_SIZE));
119+
#if CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE
120+
usb_dcache_clean((uintptr_t)&tmp->hw, CONFIG_USB_EHCI_ALIGN_SIZE);
121+
#endif
122122
}
123123
}
124124

@@ -282,7 +282,6 @@ static void ehci_qtd_fill(struct ehci_qtd_hw *qtd, uint32_t bufaddr, size_t bufl
282282
qtd->hw.token = token;
283283

284284
ehci_qtd_bpl_fill(qtd, usb_phyaddr2ramaddr(bufaddr), buflen);
285-
qtd->dir_in = ((token & QTD_TOKEN_PID_MASK) == QTD_TOKEN_PID_IN) ? true : false;
286285
qtd->bufaddr = bufaddr;
287286
qtd->length = buflen;
288287
}
@@ -620,9 +619,6 @@ static void ehci_qh_scan_qtds(struct usbh_bus *bus, struct ehci_qh_hw *qhead, st
620619
qtd = EHCI_ADDR2QTD(qh->first_qtd);
621620

622621
while (qtd) {
623-
if (qtd->dir_in) {
624-
usb_dcache_invalidate(qtd->bufaddr, USB_ALIGN_UP(qtd->length - ((qtd->hw.token & QTD_TOKEN_NBYTES_MASK) >> QTD_TOKEN_NBYTES_SHIFT), CONFIG_USB_ALIGN_SIZE));
625-
}
626622
qtd->urb->actual_length += (qtd->length - ((qtd->hw.token & QTD_TOKEN_NBYTES_MASK) >> QTD_TOKEN_NBYTES_SHIFT));
627623

628624
qh->first_qtd = qtd->hw.next_qtd;
@@ -643,7 +639,9 @@ static void ehci_check_qh(struct usbh_bus *bus, struct ehci_qh_hw *qhead, struct
643639
}
644640

645641
while (qtd) {
646-
usb_dcache_invalidate((uintptr_t)&qtd->hw, USB_ALIGN_UP(SIZEOF_EHCI_QTD, CONFIG_USB_EHCI_ALIGN_SIZE));
642+
#if CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE
643+
usb_dcache_invalidate((uintptr_t)&qtd->hw, CONFIG_USB_EHCI_ALIGN_SIZE);
644+
#endif
647645
token = qtd->hw.token;
648646

649647
if (token & QTD_TOKEN_STATUS_ERRORS) {
@@ -799,9 +797,11 @@ int usb_hc_init(struct usbh_bus *bus)
799797
g_framelist[bus->hcd.hcd_id][i] = QH_HLP_QH(&g_periodic_qh_head[bus->hcd.hcd_id]);
800798
}
801799

802-
usb_dcache_clean((uintptr_t)&g_async_qh_head[bus->hcd.hcd_id].hw, USB_ALIGN_UP(SIZEOF_EHCI_QH, CONFIG_USB_EHCI_ALIGN_SIZE));
803-
usb_dcache_clean((uintptr_t)&g_periodic_qh_head[bus->hcd.hcd_id].hw, USB_ALIGN_UP(SIZEOF_EHCI_QH, CONFIG_USB_EHCI_ALIGN_SIZE));
800+
#if CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE
801+
usb_dcache_clean((uintptr_t)&g_async_qh_head[bus->hcd.hcd_id].hw, CONFIG_USB_EHCI_ALIGN_SIZE);
802+
usb_dcache_clean((uintptr_t)&g_periodic_qh_head[bus->hcd.hcd_id].hw, CONFIG_USB_EHCI_ALIGN_SIZE);
804803
usb_dcache_clean((uintptr_t)g_framelist[bus->hcd.hcd_id], sizeof(uint32_t) * CONFIG_USB_EHCI_FRAME_LIST_SIZE);
804+
#endif
805805

806806
usb_hc_low_level_init(bus);
807807

port/ehci/usb_hc_ehci.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,27 @@
3333
#ifndef CONFIG_USB_EHCI_ALIGN_SIZE
3434
#define CONFIG_USB_EHCI_ALIGN_SIZE 64
3535
#endif
36+
#ifndef CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE
37+
#define CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE 0
38+
#endif
3639

3740
extern uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port);
3841

3942
struct ehci_qtd_hw {
4043
struct ehci_qtd hw;
44+
#if defined(CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE) && (CONFIG_USB_EHCI_ALIGN_SIZE == 64)
45+
uint8_t pad[32];
46+
#endif
4147
struct usbh_urb *urb;
42-
bool dir_in;
4348
uintptr_t bufaddr;
4449
uint32_t length;
4550
} __attribute__((aligned(CONFIG_USB_EHCI_ALIGN_SIZE)));
4651

4752
struct ehci_qh_hw {
4853
struct ehci_qh hw;
54+
#if defined(CONFIG_USB_EHCI_QH_QTD_DCACHE_ENABLE)
55+
uint16_t pad[16];
56+
#endif
4957
struct ehci_qtd_hw qtd_pool[CONFIG_USB_EHCI_QTD_NUM];
5058
uint32_t first_qtd;
5159
struct usbh_urb *urb;

0 commit comments

Comments
 (0)