forked from HRex39/rtl8852be
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform_mips_98d_pci.c
192 lines (175 loc) · 5.23 KB
/
platform_mips_98d_pci.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/******************************************************************************
*
* Copyright(c) 2019 - Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#include "drv_types.h"
#if 1
void pci_cache_wback(struct pci_dev *hwdev,
dma_addr_t *bus_addr, size_t size, int direction)
{
if (NULL != hwdev && NULL != bus_addr)
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)
pci_dma_sync_single_for_device(hwdev, *bus_addr, size,
direction);
#else
dma_sync_single_for_device(&hwdev->dev, *bus_addr, size,
(enum dma_data_direction)direction);
#endif
else
RTW_ERR("pcie hwdev handle or bus addr is NULL!\n");
}
void pci_cache_inv(struct pci_dev *hwdev,
dma_addr_t *bus_addr, size_t size, int direction)
{
if (NULL != hwdev && NULL != bus_addr)
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)
pci_dma_sync_single_for_cpu(hwdev, *bus_addr, size, direction);
#else
dma_sync_single_for_cpu(&hwdev->dev, *bus_addr, size, (enum dma_data_direction)direction);
#endif
else
RTW_ERR("pcie hwdev handle or bus addr is NULL!\n");
}
void pci_get_bus_addr(struct pci_dev *hwdev,
void *vir_addr, dma_addr_t *bus_addr,
size_t size, int direction)
{
if (NULL != hwdev) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)
*bus_addr = pci_map_single(hwdev, vir_addr, size, direction);
#else
*bus_addr = dma_map_single(&hwdev->dev, vir_addr, size, (enum dma_data_direction)direction);
#endif
} else {
RTW_ERR("pcie hwdev handle is NULL!\n");
*bus_addr = (dma_addr_t)virt_to_phys(vir_addr);
/*RTW_ERR("Get bus_addr: %x by virt_to_phys()\n", bus_addr);*/
}
}
void pci_unmap_bus_addr(struct pci_dev *hwdev,
dma_addr_t *bus_addr, size_t size, int direction)
{
if (NULL != hwdev && NULL != bus_addr)
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)
pci_unmap_single(hwdev, *bus_addr, size, direction);
#else
dma_unmap_single(&hwdev->dev, *bus_addr, size, (enum dma_data_direction)direction);
#endif
else
RTW_ERR("pcie hwdev handle or bus addr is NULL!\n");
}
void *pci_alloc_cache_mem(struct pci_dev *pdev,
dma_addr_t *bus_addr, size_t size, int direction)
{
void *vir_addr = NULL;
vir_addr = rtw_zmalloc(size);
if (!vir_addr)
bus_addr = NULL;
else
pci_get_bus_addr(pdev, vir_addr, bus_addr, size, direction);
return vir_addr;
}
void *pci_alloc_noncache_mem(struct pci_dev *pdev,
dma_addr_t *bus_addr, size_t size)
{
void *vir_addr = NULL;
if (NULL != pdev)
vir_addr = pci_alloc_consistent(pdev, size, bus_addr);
if (!vir_addr)
bus_addr = NULL;
else
bus_addr = (dma_addr_t *)((((SIZE_PTR)bus_addr + 3) / 4) * 4);
return vir_addr;
}
void pci_free_cache_mem(struct pci_dev *pdev,
void *vir_addr, dma_addr_t *bus_addr,
size_t size, int direction)
{
pci_unmap_bus_addr(pdev, bus_addr, size, direction);
rtw_mfree(vir_addr, size);
vir_addr = NULL;
}
void pci_free_noncache_mem(struct pci_dev *pdev,
void *vir_addr, dma_addr_t *bus_addr, size_t size)
{
if (NULL != pdev)
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)
pci_free_consistent(pdev, size, vir_addr, *bus_addr);
#else
dma_free_coherent(pdev->dev, size, vir_addr, *bus_addr);
#endif
vir_addr = NULL;
}
#endif
#if 0
void pci_cache_wback(struct pci_dev *hwdev,
dma_addr_t *bus_addr, size_t size, int direction)
{
pci_dma_sync_single_for_device(hwdev, *bus_addr, size, direction);
}
void pci_cache_inv(struct pci_dev *hwdev,
dma_addr_t *bus_addr, size_t size, int direction)
{
pci_dma_sync_single_for_cpu(hwdev, *bus_addr, size, direction);
}
void pci_get_bus_addr(struct pci_dev *hwdev,
void *vir_addr, dma_addr_t *bus_addr,
size_t size, int direction)
{
*bus_addr = (dma_addr_t)virt_to_phys(vir_addr);
return bus_addr;
}
void pci_unmap_bus_addr(struct pci_dev *hwdev,
dma_addr_t *bus_addr, size_t size, int direction)
{
/* pci_unmap_single(hwdev, *bus_addr, size, direction); */
}
void *pci_alloc_cache_mem(struct pci_dev *pdev,
dma_addr_t *bus_addr, size_t size, int direction)
{
void *vir_addr = NULL;
vir_addr = rtw_zmalloc(size);
if (!vir_addr) {
bus_addr = NULL;
}
else {
pci_get_bus_addr(pdev, vir_addr, bus_addr, size,
direction);
}
return vir_addr;
}
void *pci_alloc_noncache_mem(struct pci_dev *pdev,
dma_addr_t *bus_addr, size_t size)
{
void *vir_addr = NULL;
vir_addr = pci_alloc_consistent(pdev, size, bus_addr);
if (!vir_addr)
bus_addr = NULL;
else
bus_addr = (dma_addr_t *)((((SIZE_PTR)bus_addr + 3) / 4) * 4);
return vir_addr;
}
void pci_free_cache_mem(struct pci_dev *pdev, void *vir_addr,
dma_addr_t *bus_addr, size_t size, int direction)
{
platform_mips_98d_unmap_bus_addr(pdev, bus_addr, size, direction);
rtw_mfree(vir_addr, size);
vir_addr = NULL;
}
void pci_free_noncache_mem(struct pci_dev *pdev, void *vir_addr,
dma_addr_t *bus_addr, size_t size)
{
pci_free_consistent(pdev, size, vir_addr, *bus_addr);
vir_addr = NULL;
}
#endif