Skip to content

Commit 9d425eb

Browse files
lipengfei28xiaoxiang781216
authored andcommitted
pci epc mem use virtual mem
Signed-off-by: lipengfei28 <[email protected]>
1 parent aa3568f commit 9d425eb

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

drivers/pci/pci_epc_mem.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*
4646
* Input Parameters:
4747
* epc - The EPC device
48-
* phys_addr - Physical address alloced to be matched
48+
* phys_addr - Virtual address alloced to be matched
4949
*
5050
* Returned Value:
5151
* Memory window alloced if success, NULL if failed
@@ -119,6 +119,7 @@ int pci_epc_mem_multi_init(FAR struct pci_epc_ctrl_s *epc,
119119
goto err;
120120
}
121121

122+
epc->mem[i].virt_base = windows[i].virt_base;
122123
epc->mem[i].phys_base = windows[i].phys_base;
123124
epc->mem[i].size = windows[i].size;
124125
epc->mem[i].page_size = windows[i].page_size;
@@ -152,20 +153,22 @@ int pci_epc_mem_multi_init(FAR struct pci_epc_ctrl_s *epc,
152153
*
153154
* Input Parameters:
154155
* epc - PCI EPC device
155-
* base - The physical base address of the PCI address window
156+
* virt - The virtual base address of the PCI address window
157+
* phys - The phys base address of the PCI address window
156158
* size - The PCI window size
157159
* page_size - Size of each window page
158160
*
159161
* Returned Value:
160162
* 0 if success, negative if failed
161163
****************************************************************************/
162164

163-
int pci_epc_mem_init(FAR struct pci_epc_ctrl_s *epc, uintptr_t base,
164-
size_t size, size_t page_size)
165+
int pci_epc_mem_init(FAR struct pci_epc_ctrl_s *epc, FAR void *virt,
166+
uintptr_t phys, size_t size, size_t page_size)
165167
{
166168
struct pci_epc_mem_window_s window;
167169

168-
window.phys_base = base;
170+
window.virt_base = virt;
171+
window.phys_base = phys;
169172
window.size = size;
170173
window.page_size = page_size;
171174

@@ -218,14 +221,16 @@ void pci_epc_mem_exit(FAR struct pci_epc_ctrl_s *epc)
218221
* is usually done to map the remote RC address into the local system.
219222
*
220223
* Input Parameters:
221-
* epc - The EPC device on which memory has to be allocated
222-
* size - The size of the address space that has to be allocated
224+
* epc - The EPC device on which memory has to be allocated
225+
* phys - The virtual addr
226+
* size - The size of the address space that has to be allocated
223227
*
224228
* Returned Value:
225-
* The memory address alloced if success, 0 if failed
229+
* The memory address alloced if success, NULL if failed
226230
****************************************************************************/
227231

228-
uintptr_t pci_epc_mem_alloc_addr(FAR struct pci_epc_ctrl_s *epc, size_t size)
232+
FAR void *pci_epc_mem_alloc_addr(FAR struct pci_epc_ctrl_s *epc,
233+
FAR uintptr_t *phys, size_t size)
229234
{
230235
unsigned int i;
231236

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

242247
if (pageno != mem->pages)
243248
{
244-
return mem->phys_base + pageno * mem->page_size;
249+
*phys = mem->phys_base + pageno * mem->page_size;
250+
return mem->virt_base + pageno * mem->page_size;
245251
}
246252
}
247253

248-
return 0;
254+
return NULL;
249255
}
250256

251257
/****************************************************************************
@@ -258,7 +264,7 @@ uintptr_t pci_epc_mem_alloc_addr(FAR struct pci_epc_ctrl_s *epc, size_t size)
258264
*
259265
* Input Parameters:
260266
* epc - The EPC device on which memory was allocated
261-
* phys_addr - The allocated physical address
267+
* phys_addr - The allocated virtual address
262268
* size - The size of the allocated address space
263269
*
264270
* Returned Value:

include/nuttx/pci/pci_epc.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,23 @@ struct pci_epc_ops_s
131131

132132
/* struct pci_epc_mem_window_s - Address window of the endpoint controller
133133
*
134+
* virt_base: Virtual base address of the PCI address window
134135
* phys_base: Physical base address of the PCI address window
135136
* size: The size of the PCI address window
136137
* page_size: Size of each page
137138
*/
138139

139140
struct pci_epc_mem_window_s
140141
{
142+
FAR void *virt_base;
141143
uintptr_t phys_base;
142144
size_t size;
143145
size_t page_size;
144146
};
145147

146148
/* struct pci_epc_mem_s - Address space of the endpoint controller
147149
*
150+
* virt_base: Virtual base address of the PCI address window
148151
* phys_base: Physical base address of the PCI address window
149152
* size: The size of the PCI address window
150153
* page_size: Size of each page
@@ -155,6 +158,7 @@ struct pci_epc_mem_window_s
155158

156159
struct pci_epc_mem_s
157160
{
161+
FAR void *virt_base;
158162
uintptr_t phys_base;
159163
size_t size;
160164
size_t page_size;
@@ -745,16 +749,17 @@ int pci_epc_mem_multi_init(FAR struct pci_epc_ctrl_s *epc,
745749
*
746750
* Input Parameters:
747751
* epc - PCI EPC device
748-
* base - The physical base address of the PCI address window
752+
* virt - The virtual addr
753+
* phys - The physical base address of the PCI address window
749754
* size - The PCI window size
750755
* page_size - Size of each window page
751756
*
752757
* Returned Value:
753758
* 0 if success, negative if failed
754759
****************************************************************************/
755760

756-
int pci_epc_mem_init(FAR struct pci_epc_ctrl_s *epc, uintptr_t base,
757-
size_t size, size_t page_size);
761+
int pci_epc_mem_init(FAR struct pci_epc_ctrl_s *epc, FAR void *virt,
762+
uintptr_t phys, size_t size, size_t page_size);
758763

759764
/****************************************************************************
760765
* Name: pci_epc_mem_exit
@@ -784,15 +789,16 @@ void pci_epc_mem_exit(FAR struct pci_epc_ctrl_s *epc);
784789
* is usually done to map the remote RC address into the local system.
785790
*
786791
* Input Parameters:
787-
* epc - The EPC device on which memory has to be allocated
788-
* size - The size of the address space that has to be allocated
792+
* epc - The EPC device on which memory has to be allocated
793+
* phys - The Physical addr
794+
* size - The size of the address space that has to be allocated
789795
*
790796
* Returned Value:
791-
* The memory address alloced if success, 0 if failed
797+
* The memory address alloced if success, NULL if failed
792798
****************************************************************************/
793799

794-
uintptr_t pci_epc_mem_alloc_addr(FAR struct pci_epc_ctrl_s *epc,
795-
size_t size);
800+
FAR void *pci_epc_mem_alloc_addr(FAR struct pci_epc_ctrl_s *epc,
801+
FAR uintptr_t *phys, size_t size);
796802

797803
/****************************************************************************
798804
* Name: pci_epc_mem_free_addr

0 commit comments

Comments
 (0)