25 #include <linux/pci.h>
27 #include <linux/export.h>
28 #include <linux/list.h>
30 #define STA2X11_SWIOTLB_SIZE (4*1024*1024)
37 #define STA2X11_NR_EP 4
38 #define STA2X11_NR_FUNCS 8
39 #define STA2X11_AMBA_SIZE (512 << 20)
60 static void sta2x11_new_instance(
struct pci_dev *pdev)
64 instance = kzalloc(
sizeof(*instance),
GFP_ATOMIC);
70 if (list_empty(&sta2x11_instance_list)) {
73 dev_info(&pdev->
dev,
"Using SWIOTLB (size %i)\n", size);
75 dev_emerg(&pdev->
dev,
"init swiotlb failed\n");
77 list_add(&instance->
list, &sta2x11_instance_list);
90 ep = pdev->
bus->number - instance->
bus0;
97 static int sta2x11_pdev_to_ep(
struct pci_dev *pdev)
101 instance = sta2x11_pdev_to_instance(pdev);
105 return pdev->
bus->number - instance->
bus0;
113 instance = sta2x11_pdev_to_instance(pdev);
116 ep = sta2x11_pdev_to_ep(pdev);
117 return instance->
map + ep;
123 return sta2x11_pdev_to_instance(pdev);
139 map = sta2x11_pdev_to_mapping(pdev);
155 map = sta2x11_pdev_to_mapping(pdev);
168 static void *sta2x11_swiotlb_alloc_coherent(
struct device *
dev,
179 *dma_handle = p2a(*dma_handle,
to_pci_dev(dev));
185 .alloc = sta2x11_swiotlb_alloc_coherent,
196 .dma_supported =
NULL,
200 static void sta2x11_setup_pdev(
struct pci_dev *pdev)
208 pdev->
dev.archdata.dma_ops = &sta2x11_dma_ops;
228 if (dev->
archdata.dma_ops != &sta2x11_dma_ops) {
231 return addr + size - 1 <= *dev->
dma_mask;
234 map = sta2x11_pdev_to_mapping(
to_pci_dev(dev));
252 if (dev->
archdata.dma_ops != &sta2x11_dma_ops)
264 if (dev->
archdata.dma_ops != &sta2x11_dma_ops)
275 #define AHB_MAPB 0xCA4
276 #define AHB_CRW(i) (AHB_MAPB + 0 + (i) * 0x10)
277 #define AHB_CRW_SZMASK 0xfffffc00UL
278 #define AHB_CRW_ENABLE (1 << 0)
279 #define AHB_CRW_WTYPE_MEM (2 << 1)
280 #define AHB_CRW_ROE (1UL << 3)
281 #define AHB_CRW_NSE (1UL << 4)
282 #define AHB_BASE(i) (AHB_MAPB + 4 + (i) * 0x10)
283 #define AHB_PEXLBASE(i) (AHB_MAPB + 8 + (i) * 0x10)
284 #define AHB_PEXHBASE(i) (AHB_MAPB + 12 + (i) * 0x10)
287 static void sta2x11_map_ep(
struct pci_dev *pdev)
304 pci_write_config_dword(pdev,
AHB_CRW(i), 0);
307 "sta2x11: Map EP %i: AMBA address %#8x-%#8x\n",
308 sta2x11_pdev_to_ep(pdev), map->
amba_base,
315 static void suspend_mapping(
struct pci_dev *pdev)
334 pci_read_config_dword(pdev,
AHB_CRW(i), ®s->
crw);
339 static void resume_mapping(
struct pci_dev *pdev)
359 pci_write_config_dword(pdev,
AHB_CRW(i), regs->
crw);