1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Intel MIC Platform Software Stack (MPSS)
5 * Copyright(c) 2014 Intel Corporation.
12 #include "../bus/scif_bus.h"
14 static __always_inline
void *
15 scif_alloc_coherent(dma_addr_t
*dma_handle
,
16 struct scif_dev
*scifdev
, size_t size
,
21 if (scifdev_self(scifdev
)) {
22 va
= kmalloc(size
, gfp
);
24 *dma_handle
= virt_to_phys(va
);
26 va
= dma_alloc_coherent(&scifdev
->sdev
->dev
,
27 size
, dma_handle
, gfp
);
28 if (va
&& scifdev_is_p2p(scifdev
))
29 *dma_handle
= *dma_handle
+ scifdev
->base_addr
;
34 static __always_inline
void
35 scif_free_coherent(void *va
, dma_addr_t local
,
36 struct scif_dev
*scifdev
, size_t size
)
38 if (scifdev_self(scifdev
)) {
41 if (scifdev_is_p2p(scifdev
) && local
> scifdev
->base_addr
)
42 local
= local
- scifdev
->base_addr
;
43 dma_free_coherent(&scifdev
->sdev
->dev
,
48 static __always_inline
int
49 scif_map_single(dma_addr_t
*dma_handle
,
50 void *local
, struct scif_dev
*scifdev
, size_t size
)
54 if (scifdev_self(scifdev
)) {
55 *dma_handle
= virt_to_phys((local
));
57 *dma_handle
= dma_map_single(&scifdev
->sdev
->dev
,
58 local
, size
, DMA_BIDIRECTIONAL
);
59 if (dma_mapping_error(&scifdev
->sdev
->dev
, *dma_handle
))
61 else if (scifdev_is_p2p(scifdev
))
62 *dma_handle
= *dma_handle
+ scifdev
->base_addr
;
69 static __always_inline
void
70 scif_unmap_single(dma_addr_t local
, struct scif_dev
*scifdev
,
73 if (!scifdev_self(scifdev
)) {
74 if (scifdev_is_p2p(scifdev
))
75 local
= local
- scifdev
->base_addr
;
76 dma_unmap_single(&scifdev
->sdev
->dev
, local
,
77 size
, DMA_BIDIRECTIONAL
);
81 static __always_inline
void *
82 scif_ioremap(dma_addr_t phys
, size_t size
, struct scif_dev
*scifdev
)
85 struct scif_hw_dev
*sdev
= scifdev
->sdev
;
87 if (scifdev_self(scifdev
))
88 out_virt
= phys_to_virt(phys
);
90 out_virt
= (void __force
*)
91 sdev
->hw_ops
->remap(sdev
, phys
, size
);
95 static __always_inline
void
96 scif_iounmap(void *virt
, size_t len
, struct scif_dev
*scifdev
)
98 if (!scifdev_self(scifdev
)) {
99 struct scif_hw_dev
*sdev
= scifdev
->sdev
;
101 sdev
->hw_ops
->unmap(sdev
, (void __force __iomem
*)virt
);
105 static __always_inline
int
106 scif_map_page(dma_addr_t
*dma_handle
, struct page
*page
,
107 struct scif_dev
*scifdev
)
111 if (scifdev_self(scifdev
)) {
112 *dma_handle
= page_to_phys(page
);
114 struct scif_hw_dev
*sdev
= scifdev
->sdev
;
115 *dma_handle
= dma_map_page(&sdev
->dev
,
116 page
, 0x0, PAGE_SIZE
,
118 if (dma_mapping_error(&sdev
->dev
, *dma_handle
))
120 else if (scifdev_is_p2p(scifdev
))
121 *dma_handle
= *dma_handle
+ scifdev
->base_addr
;
127 #endif /* SCIF_MAP_H */