Skip to content

Commit

Permalink
pci epc mem use virtual mem
Browse files Browse the repository at this point in the history
Signed-off-by: lipengfei28 <[email protected]>
  • Loading branch information
lipengfei28 authored and xiaoxiang781216 committed Sep 27, 2024
1 parent aa3568f commit 9d425eb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
30 changes: 18 additions & 12 deletions drivers/pci/pci_epc_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*
* Input Parameters:
* epc - The EPC device
* phys_addr - Physical address alloced to be matched
* phys_addr - Virtual address alloced to be matched
*
* Returned Value:
* Memory window alloced if success, NULL if failed
Expand Down Expand Up @@ -119,6 +119,7 @@ int pci_epc_mem_multi_init(FAR struct pci_epc_ctrl_s *epc,
goto err;
}

epc->mem[i].virt_base = windows[i].virt_base;
epc->mem[i].phys_base = windows[i].phys_base;
epc->mem[i].size = windows[i].size;
epc->mem[i].page_size = windows[i].page_size;
Expand Down Expand Up @@ -152,20 +153,22 @@ int pci_epc_mem_multi_init(FAR struct pci_epc_ctrl_s *epc,
*
* Input Parameters:
* epc - PCI EPC device
* base - The physical base address of the PCI address window
* virt - The virtual base address of the PCI address window
* phys - The phys base address of the PCI address window
* size - The PCI window size
* page_size - Size of each window page
*
* Returned Value:
* 0 if success, negative if failed
****************************************************************************/

int pci_epc_mem_init(FAR struct pci_epc_ctrl_s *epc, uintptr_t base,
size_t size, size_t page_size)
int pci_epc_mem_init(FAR struct pci_epc_ctrl_s *epc, FAR void *virt,
uintptr_t phys, size_t size, size_t page_size)
{
struct pci_epc_mem_window_s window;

window.phys_base = base;
window.virt_base = virt;
window.phys_base = phys;
window.size = size;
window.page_size = page_size;

Expand Down Expand Up @@ -218,14 +221,16 @@ void pci_epc_mem_exit(FAR struct pci_epc_ctrl_s *epc)
* is usually done to map the remote RC address into the local system.
*
* Input Parameters:
* epc - The EPC device on which memory has to be allocated
* size - The size of the address space that has to be allocated
* epc - The EPC device on which memory has to be allocated
* phys - The virtual addr
* size - The size of the address space that has to be allocated
*
* Returned Value:
* The memory address alloced if success, 0 if failed
* The memory address alloced if success, NULL if failed
****************************************************************************/

uintptr_t pci_epc_mem_alloc_addr(FAR struct pci_epc_ctrl_s *epc, size_t size)
FAR void *pci_epc_mem_alloc_addr(FAR struct pci_epc_ctrl_s *epc,
FAR uintptr_t *phys, size_t size)
{
unsigned int i;

Expand All @@ -241,11 +246,12 @@ uintptr_t pci_epc_mem_alloc_addr(FAR struct pci_epc_ctrl_s *epc, size_t size)

if (pageno != mem->pages)
{
return mem->phys_base + pageno * mem->page_size;
*phys = mem->phys_base + pageno * mem->page_size;
return mem->virt_base + pageno * mem->page_size;
}
}

return 0;
return NULL;
}

/****************************************************************************
Expand All @@ -258,7 +264,7 @@ uintptr_t pci_epc_mem_alloc_addr(FAR struct pci_epc_ctrl_s *epc, size_t size)
*
* Input Parameters:
* epc - The EPC device on which memory was allocated
* phys_addr - The allocated physical address
* phys_addr - The allocated virtual address
* size - The size of the allocated address space
*
* Returned Value:
Expand Down
22 changes: 14 additions & 8 deletions include/nuttx/pci/pci_epc.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,23 @@ struct pci_epc_ops_s

/* struct pci_epc_mem_window_s - Address window of the endpoint controller
*
* virt_base: Virtual base address of the PCI address window
* phys_base: Physical base address of the PCI address window
* size: The size of the PCI address window
* page_size: Size of each page
*/

struct pci_epc_mem_window_s
{
FAR void *virt_base;
uintptr_t phys_base;
size_t size;
size_t page_size;
};

/* struct pci_epc_mem_s - Address space of the endpoint controller
*
* virt_base: Virtual base address of the PCI address window
* phys_base: Physical base address of the PCI address window
* size: The size of the PCI address window
* page_size: Size of each page
Expand All @@ -155,6 +158,7 @@ struct pci_epc_mem_window_s

struct pci_epc_mem_s
{
FAR void *virt_base;
uintptr_t phys_base;
size_t size;
size_t page_size;
Expand Down Expand Up @@ -745,16 +749,17 @@ int pci_epc_mem_multi_init(FAR struct pci_epc_ctrl_s *epc,
*
* Input Parameters:
* epc - PCI EPC device
* base - The physical base address of the PCI address window
* virt - The virtual addr
* phys - The physical base address of the PCI address window
* size - The PCI window size
* page_size - Size of each window page
*
* Returned Value:
* 0 if success, negative if failed
****************************************************************************/

int pci_epc_mem_init(FAR struct pci_epc_ctrl_s *epc, uintptr_t base,
size_t size, size_t page_size);
int pci_epc_mem_init(FAR struct pci_epc_ctrl_s *epc, FAR void *virt,
uintptr_t phys, size_t size, size_t page_size);

/****************************************************************************
* Name: pci_epc_mem_exit
Expand Down Expand Up @@ -784,15 +789,16 @@ void pci_epc_mem_exit(FAR struct pci_epc_ctrl_s *epc);
* is usually done to map the remote RC address into the local system.
*
* Input Parameters:
* epc - The EPC device on which memory has to be allocated
* size - The size of the address space that has to be allocated
* epc - The EPC device on which memory has to be allocated
* phys - The Physical addr
* size - The size of the address space that has to be allocated
*
* Returned Value:
* The memory address alloced if success, 0 if failed
* The memory address alloced if success, NULL if failed
****************************************************************************/

uintptr_t pci_epc_mem_alloc_addr(FAR struct pci_epc_ctrl_s *epc,
size_t size);
FAR void *pci_epc_mem_alloc_addr(FAR struct pci_epc_ctrl_s *epc,
FAR uintptr_t *phys, size_t size);

/****************************************************************************
* Name: pci_epc_mem_free_addr
Expand Down

0 comments on commit 9d425eb

Please sign in to comment.