Function usb_mmap instead of naive_mmap

This commit is contained in:
songyanguang 2024-11-05 10:34:24 +08:00
parent 8ad7409aae
commit 57ceab57e6
8 changed files with 23 additions and 17 deletions

View File

@ -340,7 +340,7 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
vaddr = USB_MEM_VIRADDR_ALLOC;
paddr = 0;
hub->g_hub_buf = (uint8_t *)vaddr;
rc = naive_mmap(&vaddr, &paddr, 32, true);
rc = usb_mmap(&vaddr, &paddr, 32, true);
if(rc != 0){
USB_LOG_ERR("g_hub_buf allocate error, ret: %d\n", rc);
return -ENOMEM;

View File

@ -151,7 +151,7 @@ void usbh_rndis_run(struct usbh_rndis *rndis_class)
vaddr = USB_MEM_VIRADDR_ALLOC;
paddr = 0;
tx_buffer = (uint8_t *)vaddr;
ret = naive_mmap(&vaddr, &paddr, RNDIS_ETH_BUFFER_LEN, true);
ret = usb_mmap(&vaddr, &paddr, RNDIS_ETH_BUFFER_LEN, true);
if(ret != 0){
USB_LOG_ERR("tx_buf_ptr allocate error, ret: %d\n", ret);
return;
@ -162,7 +162,7 @@ void usbh_rndis_run(struct usbh_rndis *rndis_class)
vaddr = USB_MEM_VIRADDR_ALLOC;
paddr = 0;
rx_buffer = (uint8_t *)vaddr;
ret = naive_mmap(&vaddr, &paddr, RNDIS_RXETH_BUFFER_LEN, true);
ret = usb_mmap(&vaddr, &paddr, RNDIS_RXETH_BUFFER_LEN, true);
if(ret != 0){
USB_LOG_ERR("rx_buf_ptr allocate error, ret: %d\n", ret);
return;

View File

@ -294,7 +294,7 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
vaddr = USB_MEM_VIRADDR_ALLOC;
paddr = 0;
g_rndis_buf = (uint8_t *)vaddr;
ret = naive_mmap(&vaddr, &paddr, 4096, true);
ret = usb_mmap(&vaddr, &paddr, 4096, true);
if(ret != 0){
USB_LOG_ERR("g_rndis_buf allocate error, ret: %d\n", ret);
return -ENOMEM;
@ -305,7 +305,7 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
vaddr = USB_MEM_VIRADDR_ALLOC;
paddr = 0;
g_rndis_keepalive_buf = (uint8_t *)vaddr;
ret = naive_mmap(&vaddr, &paddr, 4096, true);
ret = usb_mmap(&vaddr, &paddr, 4096, true);
if(ret != 0){
USB_LOG_ERR("g_rndis_keepalive_buf allocate error, ret: %d\n", ret);
return -ENOMEM;

View File

@ -854,7 +854,7 @@ int usbh_initialize(uint32_t id, struct usbh_bus *usb)
vaddr = USB_MEM_VIRADDR_ALLOC;
paddr = 0;
usb->ep0_request_buffer = (uint8_t *)vaddr;
rc = naive_mmap(&vaddr, &paddr, CONFIG_USBHOST_REQUEST_BUFFER_LEN, true);
rc = usb_mmap(&vaddr, &paddr, CONFIG_USBHOST_REQUEST_BUFFER_LEN, true);
if(rc != 0){
USB_LOG_ERR("ep0_request_buffer allocate error, ret: %d\n", rc);
return -ENOMEM;

View File

@ -62,6 +62,11 @@ void usb_hc_free(void* ptr){
free(ptr);
}
int usb_mmap(uintptr_t* vaddr, uintptr_t* paddr, int len, bool is_dev)
{
return naive_mmap(vaddr, paddr, len, false);
}
int usb_mem_data_pool_init(){
int rc, count;
uintptr_t phy_addr, vir_addr;
@ -73,7 +78,7 @@ int usb_mem_data_pool_init(){
vir_addr = USB_MEM_VIRADDR_ALLOC;
usb_mem_data_pool.pages[count].vir_addr = vir_addr;
rc = naive_mmap(&vir_addr, &phy_addr, 4096, true);
rc = usb_mmap(&vir_addr, &phy_addr, 4096, true);
if(rc != 0)
goto mmap_error;

View File

@ -40,6 +40,7 @@ extern uintptr_t usb_mem_base_viraddr;
void *usb_hc_malloc(size_t size);
void usb_hc_free();
void *usb_hc_malloc_align(size_t align, size_t size);
int usb_mmap(uintptr_t* vaddr, uintptr_t* paddr, int len, bool is_dev);
#define usb_malloc(size) usb_hc_malloc(size)
#define usb_free(ptr) usb_hc_free(ptr)

View File

@ -432,7 +432,7 @@ int dwc3_alloc_scratch_buffers(struct dwc3 *dwc){
phy_addr = 0;
dwc->scratchbuf = (void *)vir_addr;
ret = naive_mmap(&vir_addr, &phy_addr, len, true);
ret = usb_mmap(&vir_addr, &phy_addr, len, true);
if(ret != 0){
USB_LOG_ERR("could not allocate DWC3 scratch buffers!\n");
@ -536,7 +536,7 @@ struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, unsigned
phy_addr = 0;
evt->buf = (void *)vir_addr;
ret = naive_mmap(&vir_addr, &phy_addr, length, true);
ret = usb_mmap(&vir_addr, &phy_addr, length, true);
if(ret != 0){
USB_LOG_ERR("could not allocate DWC3 event buffers!\n");

View File

@ -699,7 +699,7 @@ static int xhci_dcbaa_alloc ( struct xhci_host *xhci ) {
dcbaap_addr = USB_MEM_VIRADDR_ALLOC;
dcbaap_phy = 0;
xhci->dcbaa_addr = dcbaap_addr;
rc = naive_mmap(&dcbaap_addr, &dcbaap_phy, len, true);
rc = usb_mmap(&dcbaap_addr, &dcbaap_phy, len, true);
if(rc != 0){
USB_LOG_ERR("XHCI %s could not allocate DCBAA\n", xhci->name );
@ -769,7 +769,7 @@ static int xhci_scratchpad_alloc ( struct xhci_host *xhci ) {
phy_addr = 0;
scratch->array_addr = (void *)vir_addr;
rc = naive_mmap(&vir_addr, &phy_addr, array_len, true);
rc = usb_mmap(&vir_addr, &phy_addr, array_len, true);
if(rc != 0){
USB_LOG_ERR("XHCI %s could not allocate scratch buffer\n", xhci->name );
@ -801,7 +801,7 @@ static int xhci_scratchpad_alloc ( struct xhci_host *xhci ) {
phy_page_addr = 0;
scratch->sp_buffers[i] = (void *)vir_page_addr;
rc = naive_mmap(&vir_page_addr, &phy_page_addr, xhci->pagesize, true);
rc = usb_mmap(&vir_page_addr, &phy_page_addr, xhci->pagesize, true);
if(rc != 0){
USB_LOG_ERR("XHCI %s could not allocate scratchpad buffers\n",
@ -900,7 +900,7 @@ static int xhci_command_alloc ( struct xhci_host *xhci ) {
cmds_phy = 0;
xhci->cmds_addr = cmds_addr;
rc = naive_mmap(&cmds_addr, &cmds_phy, len, true);
rc = usb_mmap(&cmds_addr, &cmds_phy, len, true);
if(rc != 0){
USB_LOG_ERR("XHCI %s could not allocate CMD RING\n", xhci->name );
@ -970,7 +970,7 @@ static int xhci_event_alloc ( struct xhci_host *xhci ) {
evts_phy = 0;
xhci->evts_addr = evts_addr;
rc = naive_mmap(&evts_addr, &evts_phy, len, true);
rc = usb_mmap(&evts_addr, &evts_phy, len, true);
if(rc != 0){
USB_LOG_ERR("XHCI %s could not allocate Event RING\n", xhci->name );
@ -998,7 +998,7 @@ static int xhci_event_alloc ( struct xhci_host *xhci ) {
eseg_addr = USB_MEM_VIRADDR_ALLOC;
eseg_phy = 0;
xhci->eseg_addr = eseg_addr;
rc = naive_mmap(&eseg_addr, &eseg_phy, len, true);
rc = usb_mmap(&eseg_addr, &eseg_phy, len, true);
if(rc != 0){
USB_LOG_ERR("XHCI %s could not allocate Event Segment\n", xhci->name );
rc = -ENOMEM;
@ -1880,7 +1880,7 @@ static int xhci_context ( struct xhci_host *xhci, struct xhci_slot *slot,
input_vir = USB_MEM_VIRADDR_ALLOC;
input_phy = 0;
input = (void *)input_vir;
rc = naive_mmap(&input_vir, &input_phy, len, true);
rc = usb_mmap(&input_vir, &input_phy, len, true);
if(rc != 0){
USB_LOG_ERR("XHCI %s could not allocate xhci context\n", xhci->name );
rc = -ENOMEM;
@ -2147,7 +2147,7 @@ int xhci_device_open ( struct xhci_host *xhci, struct xhci_endpoint *ep, int *sl
context_vir = USB_MEM_VIRADDR_ALLOC;
context_phy = 0;
slot->context_vir = context_vir;
rc = naive_mmap(&context_vir, &context_phy, len, true);
rc = usb_mmap(&context_vir, &context_phy, len, true);
if(rc != 0){
USB_LOG_ERR("XHCI %s could not allocate xhci device context\n", xhci->name );
rc = -ENOMEM;