Skip to content

Commit 6ac269a

Browse files
bingbucaogregkh
authored andcommitted
media: ipu6: not override the dma_ops of device in driver
[ Upstream commit daabc5c ] DMA ops are a helper for architectures and not for drivers to override the DMA implementation. Driver should not override the DMA implementation. This patch removes the dma_ops override from auxiliary device and adds driver-internal helpers that use the actual DMA mapping APIs. Fixes: 9163d83 ("media: intel/ipu6: add IPU6 DMA mapping API and MMU table") Signed-off-by: Bingbu Cao <bingbu.cao@intel.com> Reviewed-by: Christoph Hellwig <hch@lst.de> [Sakari Ailus: Fix the commit message a little.] Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b0cd515 commit 6ac269a

6 files changed

Lines changed: 156 additions & 132 deletions

File tree

drivers/media/pci/intel/ipu6/ipu6-bus.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ ipu6_bus_initialize_device(struct pci_dev *pdev, struct device *parent,
9494
if (!adev)
9595
return ERR_PTR(-ENOMEM);
9696

97-
adev->dma_mask = DMA_BIT_MASK(isp->secure_mode ? IPU6_MMU_ADDR_BITS :
98-
IPU6_MMU_ADDR_BITS_NON_SECURE);
9997
adev->isp = isp;
10098
adev->ctrl = ctrl;
10199
adev->pdata = pdata;
@@ -106,10 +104,6 @@ ipu6_bus_initialize_device(struct pci_dev *pdev, struct device *parent,
106104

107105
auxdev->dev.parent = parent;
108106
auxdev->dev.release = ipu6_bus_release;
109-
auxdev->dev.dma_ops = &ipu6_dma_ops;
110-
auxdev->dev.dma_mask = &adev->dma_mask;
111-
auxdev->dev.dma_parms = pdev->dev.dma_parms;
112-
auxdev->dev.coherent_dma_mask = adev->dma_mask;
113107

114108
ret = auxiliary_device_init(auxdev);
115109
if (ret < 0) {

drivers/media/pci/intel/ipu6/ipu6-buttress.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "ipu6.h"
2626
#include "ipu6-bus.h"
27+
#include "ipu6-dma.h"
2728
#include "ipu6-buttress.h"
2829
#include "ipu6-platform-buttress-regs.h"
2930

@@ -553,6 +554,7 @@ int ipu6_buttress_map_fw_image(struct ipu6_bus_device *sys,
553554
const struct firmware *fw, struct sg_table *sgt)
554555
{
555556
bool is_vmalloc = is_vmalloc_addr(fw->data);
557+
struct pci_dev *pdev = sys->isp->pdev;
556558
struct page **pages;
557559
const void *addr;
558560
unsigned long n_pages;
@@ -588,14 +590,20 @@ int ipu6_buttress_map_fw_image(struct ipu6_bus_device *sys,
588590
goto out;
589591
}
590592

591-
ret = dma_map_sgtable(&sys->auxdev.dev, sgt, DMA_TO_DEVICE, 0);
592-
if (ret < 0) {
593-
ret = -ENOMEM;
593+
ret = dma_map_sgtable(&pdev->dev, sgt, DMA_TO_DEVICE, 0);
594+
if (ret) {
595+
sg_free_table(sgt);
596+
goto out;
597+
}
598+
599+
ret = ipu6_dma_map_sgtable(sys, sgt, DMA_TO_DEVICE, 0);
600+
if (ret) {
601+
dma_unmap_sgtable(&pdev->dev, sgt, DMA_TO_DEVICE, 0);
594602
sg_free_table(sgt);
595603
goto out;
596604
}
597605

598-
dma_sync_sgtable_for_device(&sys->auxdev.dev, sgt, DMA_TO_DEVICE);
606+
ipu6_dma_sync_sgtable(sys, sgt);
599607

600608
out:
601609
kfree(pages);
@@ -607,7 +615,10 @@ EXPORT_SYMBOL_NS_GPL(ipu6_buttress_map_fw_image, INTEL_IPU6);
607615
void ipu6_buttress_unmap_fw_image(struct ipu6_bus_device *sys,
608616
struct sg_table *sgt)
609617
{
610-
dma_unmap_sgtable(&sys->auxdev.dev, sgt, DMA_TO_DEVICE, 0);
618+
struct pci_dev *pdev = sys->isp->pdev;
619+
620+
ipu6_dma_unmap_sgtable(sys, sgt, DMA_TO_DEVICE, 0);
621+
dma_unmap_sgtable(&pdev->dev, sgt, DMA_TO_DEVICE, 0);
611622
sg_free_table(sgt);
612623
}
613624
EXPORT_SYMBOL_NS_GPL(ipu6_buttress_unmap_fw_image, INTEL_IPU6);

drivers/media/pci/intel/ipu6/ipu6-cpd.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "ipu6.h"
1616
#include "ipu6-bus.h"
1717
#include "ipu6-cpd.h"
18+
#include "ipu6-dma.h"
1819

1920
/* 15 entries + header*/
2021
#define MAX_PKG_DIR_ENT_CNT 16
@@ -162,7 +163,6 @@ int ipu6_cpd_create_pkg_dir(struct ipu6_bus_device *adev, const void *src)
162163
{
163164
dma_addr_t dma_addr_src = sg_dma_address(adev->fw_sgt.sgl);
164165
const struct ipu6_cpd_ent *ent, *man_ent, *met_ent;
165-
struct device *dev = &adev->auxdev.dev;
166166
struct ipu6_device *isp = adev->isp;
167167
unsigned int man_sz, met_sz;
168168
void *pkg_dir_pos;
@@ -175,8 +175,8 @@ int ipu6_cpd_create_pkg_dir(struct ipu6_bus_device *adev, const void *src)
175175
met_sz = met_ent->len;
176176

177177
adev->pkg_dir_size = PKG_DIR_SIZE + man_sz + met_sz;
178-
adev->pkg_dir = dma_alloc_attrs(dev, adev->pkg_dir_size,
179-
&adev->pkg_dir_dma_addr, GFP_KERNEL, 0);
178+
adev->pkg_dir = ipu6_dma_alloc(adev, adev->pkg_dir_size,
179+
&adev->pkg_dir_dma_addr, GFP_KERNEL, 0);
180180
if (!adev->pkg_dir)
181181
return -ENOMEM;
182182

@@ -198,8 +198,8 @@ int ipu6_cpd_create_pkg_dir(struct ipu6_bus_device *adev, const void *src)
198198
met_ent->len);
199199
if (ret) {
200200
dev_err(&isp->pdev->dev, "Failed to parse module data\n");
201-
dma_free_attrs(dev, adev->pkg_dir_size,
202-
adev->pkg_dir, adev->pkg_dir_dma_addr, 0);
201+
ipu6_dma_free(adev, adev->pkg_dir_size,
202+
adev->pkg_dir, adev->pkg_dir_dma_addr, 0);
203203
return ret;
204204
}
205205

@@ -211,17 +211,17 @@ int ipu6_cpd_create_pkg_dir(struct ipu6_bus_device *adev, const void *src)
211211
pkg_dir_pos += man_sz;
212212
memcpy(pkg_dir_pos, src + met_ent->offset, met_sz);
213213

214-
dma_sync_single_range_for_device(dev, adev->pkg_dir_dma_addr,
215-
0, adev->pkg_dir_size, DMA_TO_DEVICE);
214+
ipu6_dma_sync_single(adev, adev->pkg_dir_dma_addr,
215+
adev->pkg_dir_size);
216216

217217
return 0;
218218
}
219219
EXPORT_SYMBOL_NS_GPL(ipu6_cpd_create_pkg_dir, INTEL_IPU6);
220220

221221
void ipu6_cpd_free_pkg_dir(struct ipu6_bus_device *adev)
222222
{
223-
dma_free_attrs(&adev->auxdev.dev, adev->pkg_dir_size, adev->pkg_dir,
224-
adev->pkg_dir_dma_addr, 0);
223+
ipu6_dma_free(adev, adev->pkg_dir_size, adev->pkg_dir,
224+
adev->pkg_dir_dma_addr, 0);
225225
}
226226
EXPORT_SYMBOL_NS_GPL(ipu6_cpd_free_pkg_dir, INTEL_IPU6);
227227

0 commit comments

Comments
 (0)