2 * Intel MIC Platform Software Stack (MPSS)
4 * Copyright(c) 2014 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
21 #include "../bus/scif_bus.h"
23 static __always_inline
void *
24 scif_alloc_coherent(dma_addr_t
*dma_handle
,
25 struct scif_dev
*scifdev
, size_t size
,
30 if (scifdev_self(scifdev
)) {
31 va
= kmalloc(size
, gfp
);
33 *dma_handle
= virt_to_phys(va
);
35 va
= dma_alloc_coherent(&scifdev
->sdev
->dev
,
36 size
, dma_handle
, gfp
);
37 if (va
&& scifdev_is_p2p(scifdev
))
38 *dma_handle
= *dma_handle
+ scifdev
->base_addr
;
43 static __always_inline
void
44 scif_free_coherent(void *va
, dma_addr_t local
,
45 struct scif_dev
*scifdev
, size_t size
)
47 if (scifdev_self(scifdev
)) {
50 if (scifdev_is_p2p(scifdev
) && local
> scifdev
->base_addr
)
51 local
= local
- scifdev
->base_addr
;
52 dma_free_coherent(&scifdev
->sdev
->dev
,
57 static __always_inline
int
58 scif_map_single(dma_addr_t
*dma_handle
,
59 void *local
, struct scif_dev
*scifdev
, size_t size
)
63 if (scifdev_self(scifdev
)) {
64 *dma_handle
= virt_to_phys((local
));
66 *dma_handle
= dma_map_single(&scifdev
->sdev
->dev
,
67 local
, size
, DMA_BIDIRECTIONAL
);
68 if (dma_mapping_error(&scifdev
->sdev
->dev
, *dma_handle
))
70 else if (scifdev_is_p2p(scifdev
))
71 *dma_handle
= *dma_handle
+ scifdev
->base_addr
;
78 static __always_inline
void
79 scif_unmap_single(dma_addr_t local
, struct scif_dev
*scifdev
,
82 if (!scifdev_self(scifdev
)) {
83 if (scifdev_is_p2p(scifdev
))
84 local
= local
- scifdev
->base_addr
;
85 dma_unmap_single(&scifdev
->sdev
->dev
, local
,
86 size
, DMA_BIDIRECTIONAL
);
90 static __always_inline
void *
91 scif_ioremap(dma_addr_t phys
, size_t size
, struct scif_dev
*scifdev
)
94 struct scif_hw_dev
*sdev
= scifdev
->sdev
;
96 if (scifdev_self(scifdev
))
97 out_virt
= phys_to_virt(phys
);
99 out_virt
= (void __force
*)
100 sdev
->hw_ops
->ioremap(sdev
, phys
, size
);
104 static __always_inline
void
105 scif_iounmap(void *virt
, size_t len
, struct scif_dev
*scifdev
)
107 if (!scifdev_self(scifdev
)) {
108 struct scif_hw_dev
*sdev
= scifdev
->sdev
;
110 sdev
->hw_ops
->iounmap(sdev
, (void __force __iomem
*)virt
);
114 static __always_inline
int
115 scif_map_page(dma_addr_t
*dma_handle
, struct page
*page
,
116 struct scif_dev
*scifdev
)
120 if (scifdev_self(scifdev
)) {
121 *dma_handle
= page_to_phys(page
);
123 struct scif_hw_dev
*sdev
= scifdev
->sdev
;
124 *dma_handle
= dma_map_page(&sdev
->dev
,
125 page
, 0x0, PAGE_SIZE
,
127 if (dma_mapping_error(&sdev
->dev
, *dma_handle
))
129 else if (scifdev_is_p2p(scifdev
))
130 *dma_handle
= *dma_handle
+ scifdev
->base_addr
;
136 #endif /* SCIF_MAP_H */