1 /*
2  * Copyright : (C) 2024 Phytium Information Technology, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Modify History:
7  *  Ver   Who        Date         Changes
8  * ----- ------     --------    --------------------------------------
9  * 1.0   zhugengyu  2024/6/26 first commit
10  */
11 #include "rtthread.h"
12 #include "usbh_core.h"
13 
14 #include "usb_config.h"
15 
16 void usb_hc_setup_xhci_interrupt(uint32_t id);
17 void usb_hc_revoke_xhci_interrupt(uint32_t id);
18 
xhci_mem_malloc(size_t align,size_t size)19 void *xhci_mem_malloc(size_t align, size_t size)
20 {
21     void *result = rt_malloc_align(size, align);
22 
23     if (result)
24     {
25         memset(result, 0U, size);
26     }
27 
28     return result;
29 }
30 
xhci_mem_free(void * ptr)31 void xhci_mem_free(void *ptr)
32 {
33     if (NULL != ptr)
34     {
35         rt_free(ptr);
36     }
37 }
38 
xhci_dcache_sync(void * ptr,size_t len,uint32_t flags)39 void xhci_dcache_sync(void *ptr, size_t len, uint32_t flags)
40 {
41     if (flags & XHCI_DCACHE_FLUSH)
42     {
43         rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, ptr, len);
44     }
45     else if (flags & XHCI_DCACHE_INVALIDATE)
46     {
47         rt_hw_cpu_dcache_ops(RT_HW_CACHE_INVALIDATE, ptr, len);
48     }
49 }
50 
usb_assert(const char * filename,int linenum)51 void usb_assert(const char *filename, int linenum)
52 {
53     rt_assert_handler("", filename, linenum);
54 }
55 
usb_hc_low_level_init(struct usbh_bus * bus)56 void usb_hc_low_level_init(struct usbh_bus *bus)
57 {
58     /* platform XHCI controller */
59     usb_hc_setup_xhci_interrupt(bus->busid);
60 }
61 
usb_hc_low_level_deinit(struct usbh_bus * bus)62 void usb_hc_low_level_deinit(struct usbh_bus *bus)
63 {
64     usb_hc_revoke_xhci_interrupt(bus->busid);
65 }