The paddr parameter needs to be 0 in the naive_mmap function.

This commit is contained in:
songyanguang 2024-08-21 17:22:54 +08:00
parent 2f03186b0b
commit 083277e500
5 changed files with 30 additions and 3 deletions

View File

@ -336,6 +336,7 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
/* g_hub_buf allocate virtual address and physical address*/
vaddr = USB_MEM_VIRADDR_ALLOC;
paddr = 0;
hub->g_hub_buf = (uint8_t *)vaddr;
rc = naive_mmap(&vaddr, &paddr, 32, true);
if(rc != 0){
@ -343,6 +344,7 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
return -ENOMEM;
}
hub->g_hub_buf_phy = (uint8_t *)paddr;
USB_LOG_DBG("usbh_hub_connect hub->g_hub_buf=%lx hub->g_hub_buf_phy=%08lx\n", hub->g_hub_buf, hub->g_hub_buf_phy);
hport->config.intf[intf].priv = hub;

View File

@ -149,6 +149,7 @@ void usbh_rndis_run(struct usbh_rndis *rndis_class)
s_rndis_class_ptr = rndis_class;
vaddr = USB_MEM_VIRADDR_ALLOC;
paddr = 0;
tx_buffer = (uint8_t *)vaddr;
ret = naive_mmap(&vaddr, &paddr, RNDIS_ETH_BUFFER_LEN, true);
if(ret != 0){
@ -156,8 +157,10 @@ void usbh_rndis_run(struct usbh_rndis *rndis_class)
return;
}
tx_buffer_phy = (uint8_t *)paddr;
USB_LOG_DBG("usbh_rndis_run tx_buffer=%lx tx_buffer_phy=%08lx\n", tx_buffer, tx_buffer_phy);
vaddr = USB_MEM_VIRADDR_ALLOC;
paddr = 0;
rx_buffer = (uint8_t *)vaddr;
ret = naive_mmap(&vaddr, &paddr, RNDIS_RXETH_BUFFER_LEN, true);
if(ret != 0){
@ -165,6 +168,7 @@ void usbh_rndis_run(struct usbh_rndis *rndis_class)
return;
}
rx_buffer_phy = (uint8_t *)paddr;
USB_LOG_DBG("usbh_rndis_run rx_buffer=%lx rx_buffer_phy=%08lx\n", rx_buffer, rx_buffer_phy);
mutex_sem_handle = usb_osal_sem_create(0);
if (NULL == mutex_sem_handle) {

View File

@ -292,6 +292,7 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
/* allocate virtual address and physical address*/
vaddr = USB_MEM_VIRADDR_ALLOC;
paddr = 0;
g_rndis_buf = (uint8_t *)vaddr;
ret = naive_mmap(&vaddr, &paddr, 4096, true);
if(ret != 0){
@ -299,8 +300,10 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
return -ENOMEM;
}
g_rndis_buf_phy = (uint8_t *)paddr;
USB_LOG_DBG("usbh_rndis_connect g_rndis_buf=%lx g_rndis_buf_phy=%08lx\n", g_rndis_buf, g_rndis_buf_phy);
vaddr = USB_MEM_VIRADDR_ALLOC;
paddr = 0;
g_rndis_keepalive_buf = (uint8_t *)vaddr;
ret = naive_mmap(&vaddr, &paddr, 4096, true);
if(ret != 0){
@ -308,6 +311,7 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
return -ENOMEM;
}
g_rndis_keepalive_buf_phy = (uint8_t *)paddr;
USB_LOG_DBG("usbh_rndis_connect g_rndis_keepalive_buf=%lx g_rndis_keepalive_buf_phy=%08lx\n", g_rndis_keepalive_buf, g_rndis_keepalive_buf_phy);
hport->config.intf[intf].priv = rndis_class;
hport->config.intf[intf + 1].priv = NULL;

View File

@ -851,6 +851,7 @@ int usbh_initialize(uint32_t id, struct usbh_bus *usb)
/* ep0_request_buffer allocate virtual address and physical address*/
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);
if(rc != 0){
@ -858,6 +859,7 @@ int usbh_initialize(uint32_t id, struct usbh_bus *usb)
return -ENOMEM;
}
usb->ep0_request_buffer_phy = (uint8_t *)paddr;
USB_LOG_DBG("usbh_initialize ep0_request_buffer=%lx ep0_request_buffer_phy=%08lx\n", usb->ep0_request_buffer, usb->ep0_request_buffer_phy);
usb_slist_add_tail(&usb_buses, &(usb->list));
usbh_hub_initialize(usb);

View File

@ -697,6 +697,7 @@ static int xhci_dcbaa_alloc ( struct xhci_host *xhci ) {
xhci->dcbaa.context = NULL;
dcbaap_addr = USB_MEM_VIRADDR_ALLOC;
dcbaap_phy = 0;
xhci->dcbaa_addr = dcbaap_addr;
rc = naive_mmap(&dcbaap_addr, &dcbaap_phy, len, true);
@ -708,6 +709,7 @@ static int xhci_dcbaa_alloc ( struct xhci_host *xhci ) {
xhci->dcbaa_phy = dcbaap_phy;
xhci->dcbaa.context = (void *)xhci->dcbaa_addr;
USB_LOG_DBG("xhci_dcbaa_alloc xhci->dcbaa_addr=%lx xhci->dcbaa_phy=%08lx\n", xhci->dcbaa_addr, xhci->dcbaa_phy);
#if 0
if ( ! xhci->dcbaa.context ) {
@ -729,7 +731,7 @@ static int xhci_dcbaa_alloc ( struct xhci_host *xhci ) {
USB_LOG_DBG("XHCI %s DCBAA at [%08lx,%08lx)\n", xhci->name,
( xhci->dcbaa.context ),
( ( xhci->dcbaa.context ) + len ) );
( ( (uintptr_t)xhci->dcbaa.context ) + len ) );
return 0;
err_writeq:
@ -764,6 +766,7 @@ static int xhci_scratchpad_alloc ( struct xhci_host *xhci ) {
/* Allocate buffer to store */
array_len = scratch->count * sizeof ( scratch->array[0] );
vir_addr = USB_MEM_VIRADDR_ALLOC;
phy_addr = 0;
scratch->array_addr = (void *)vir_addr;
rc = naive_mmap(&vir_addr, &phy_addr, array_len, true);
@ -773,11 +776,11 @@ static int xhci_scratchpad_alloc ( struct xhci_host *xhci ) {
rc = -ENOMEM;
goto err_alloc;
}
USB_LOG_DBG("xhci_scratchpad_alloc vir_addr=%lx phy_addr=%08lx\n", vir_addr, phy_addr);
memset(scratch->array_addr, 0, array_len);
scratch->array_phy = phy_addr;
/*
* Allocate memory for storing all virtual address of physical pages allocated to xHCI as scratchpad buffer.
*/
@ -795,6 +798,7 @@ static int xhci_scratchpad_alloc ( struct xhci_host *xhci ) {
*/
for(i = 0; i < scratch->count; i++){
vir_page_addr = USB_MEM_VIRADDR_ALLOC;
phy_page_addr = 0;
scratch->sp_buffers[i] = (void *)vir_page_addr;
rc = naive_mmap(&vir_page_addr, &phy_page_addr, xhci->pagesize, true);
@ -805,6 +809,7 @@ static int xhci_scratchpad_alloc ( struct xhci_host *xhci ) {
goto err_alloc_array_vir;
}
scratch->array_addr[i] = phy_page_addr;
USB_LOG_DBG("xhci_scratchpad_alloc i=%d scratch->sp_buffers=%lx scratch->array_addr=%08lx\n", i, scratch->sp_buffers[i], scratch->array_addr[i]);
}
/*
@ -892,6 +897,7 @@ static int xhci_command_alloc ( struct xhci_host *xhci ) {
len = sizeof(*xhci->cmds);
cmds_addr = USB_MEM_VIRADDR_ALLOC;
cmds_phy = 0;
xhci->cmds_addr = cmds_addr;
rc = naive_mmap(&cmds_addr, &cmds_phy, len, true);
@ -901,6 +907,7 @@ static int xhci_command_alloc ( struct xhci_host *xhci ) {
rc = -ENOMEM;
goto err_ring_alloc;
}
USB_LOG_DBG("xhci_command_alloc cmds_addr=%lx cmds_phy=%08lx\n", cmds_addr, cmds_phy);
xhci->cmds_phy = cmds_phy;
@ -960,6 +967,7 @@ static int xhci_event_alloc ( struct xhci_host *xhci ) {
/* Allocate event ring */
len = sizeof(*xhci->evts);
evts_addr = USB_MEM_VIRADDR_ALLOC;
evts_phy = 0;
xhci->evts_addr = evts_addr;
rc = naive_mmap(&evts_addr, &evts_phy, len, true);
@ -979,6 +987,7 @@ static int xhci_event_alloc ( struct xhci_host *xhci ) {
}
#endif
xhci->evts_phy = evts_phy;
USB_LOG_DBG("xhci_event_alloc xhci->evts_addr=%lx xhci->evts_phy=%08lx\n", xhci->evts_addr, xhci->evts_phy);
xhci->evts = (struct xhci_ring *)xhci->evts_addr;
memset(xhci->evts, 0U, sizeof(*xhci->evts));
@ -987,6 +996,7 @@ static int xhci_event_alloc ( struct xhci_host *xhci ) {
len = sizeof(*xhci->eseg);
eseg_addr = USB_MEM_VIRADDR_ALLOC;
eseg_phy = 0;
xhci->eseg_addr = eseg_addr;
rc = naive_mmap(&eseg_addr, &eseg_phy, len, true);
if(rc != 0){
@ -1004,6 +1014,7 @@ static int xhci_event_alloc ( struct xhci_host *xhci ) {
#endif
xhci->eseg_phy = eseg_phy;
USB_LOG_DBG("xhci_event_alloc xhci->eseg_addr=%lx xhci->eseg_phy=%08lx\n", xhci->eseg_addr, xhci->eseg_phy);
xhci->eseg = (struct xhci_er_seg *)xhci->eseg_addr;
@ -1824,14 +1835,16 @@ static int xhci_context ( struct xhci_host *xhci, struct xhci_slot *slot,
}
#endif
input_vir = USB_MEM_VIRADDR_ALLOC;
input_phy = 0;
input = (void *)input_vir;
memset ( input, 0, len );
rc = naive_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;
goto err_alloc;
}
USB_LOG_DBG("xhci_context input_vir=%lx input_phy=%08lx\n", input_vir, input_phy);
memset ( input, 0, len );
/* Populate input context */
populate ( xhci, slot, ep, input );
@ -2089,6 +2102,7 @@ int xhci_device_open ( struct xhci_host *xhci, struct xhci_endpoint *ep, int *sl
}
#endif
context_vir = USB_MEM_VIRADDR_ALLOC;
context_phy = 0;
slot->context_vir = context_vir;
rc = naive_mmap(&context_vir, &context_phy, len, true);
if(rc != 0){
@ -2097,6 +2111,7 @@ int xhci_device_open ( struct xhci_host *xhci, struct xhci_endpoint *ep, int *sl
goto err_alloc;
}
slot->context_phy = context_phy;
USB_LOG_DBG("xhci_device_open slot->context_vir=%lx slot->context_phy=%08lx\n", slot->context_vir, slot->context_phy);
slot->context = (struct xhci_slot_context *)slot->context_vir;
memset ( slot->context, 0, len );