Skip to content

Commit 377a22d

Browse files
Stanimir Varbanovmchehab
authored andcommitted
media: venus: don't abuse dma_alloc for non-DMA allocations
In venus_boot(), we pass a pointer to a phys_addr_t into dmam_alloc_coherent, which the compiler warns about: platform/qcom/venus/firmware.c: In function 'venus_boot': platform/qcom/venus/firmware.c:63:49: error: passing argument 3 of 'dmam_alloc_coherent' from incompatible pointer type [-Werror=incompatible-pointer-types] To avoid the error refactor venus_boot function by discard dma_alloc_coherent invocation because we don't want to map the memory for the device. Something more, the usage of DMA mapping API is actually wrong and the current implementation relies on several bugs in DMA mapping code. When these bugs are fixed that will break firmware loading, so fix this now to avoid future troubles. The meaning of venus_boot is to copy the content of the firmware buffer into reserved (and memblock removed) block of memory and pass that physical address to the trusted zone for authentication and mapping through iommu form the secure world. After iommu mapping is done the iova is passed as ane entry point to the remote processor. After this change memory-region property is parsed manually and the physical address is memremap to CPU, call mdt_load to load firmware segments into proper places and unmap reserved memory. Fixes: af2c383 ("[media] media: venus: adding core part and helper functions") Signed-off-by: Stanimir Varbanov <stanimir.varbanov@linaro.org> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
1 parent 3e7caae commit 377a22d

4 files changed

Lines changed: 39 additions & 51 deletions

File tree

‎drivers/media/platform/qcom/venus/core.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ static void venus_sys_error_handler(struct work_struct *work)
7676
hfi_core_deinit(core, true);
7777
hfi_destroy(core);
7878
mutex_lock(&core->lock);
79-
venus_shutdown(&core->dev_fw);
79+
venus_shutdown(core->dev);
8080

8181
pm_runtime_put_sync(core->dev);
8282

8383
ret |= hfi_create(core, &venus_core_ops);
8484

8585
pm_runtime_get_sync(core->dev);
8686

87-
ret |= venus_boot(core->dev, &core->dev_fw, core->res->fwname);
87+
ret |= venus_boot(core->dev, core->res->fwname);
8888

8989
ret |= hfi_core_resume(core, true);
9090

@@ -207,7 +207,7 @@ static int venus_probe(struct platform_device *pdev)
207207
if (ret < 0)
208208
goto err_runtime_disable;
209209

210-
ret = venus_boot(dev, &core->dev_fw, core->res->fwname);
210+
ret = venus_boot(dev, core->res->fwname);
211211
if (ret)
212212
goto err_runtime_disable;
213213

@@ -238,7 +238,7 @@ static int venus_probe(struct platform_device *pdev)
238238
err_core_deinit:
239239
hfi_core_deinit(core, false);
240240
err_venus_shutdown:
241-
venus_shutdown(&core->dev_fw);
241+
venus_shutdown(dev);
242242
err_runtime_disable:
243243
pm_runtime_set_suspended(dev);
244244
pm_runtime_disable(dev);
@@ -259,7 +259,7 @@ static int venus_remove(struct platform_device *pdev)
259259
WARN_ON(ret);
260260

261261
hfi_destroy(core);
262-
venus_shutdown(&core->dev_fw);
262+
venus_shutdown(dev);
263263
of_platform_depopulate(dev);
264264

265265
pm_runtime_put_sync(dev);

‎drivers/media/platform/qcom/venus/core.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ struct venus_core {
101101
struct device *dev;
102102
struct device *dev_dec;
103103
struct device *dev_enc;
104-
struct device dev_fw;
105104
struct mutex lock;
106105
struct list_head instances;
107106
atomic_t insts_count;

‎drivers/media/platform/qcom/venus/firmware.c‎

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,27 @@
1212
*
1313
*/
1414

15-
#include <linux/dma-mapping.h>
15+
#include <linux/device.h>
1616
#include <linux/firmware.h>
1717
#include <linux/kernel.h>
18+
#include <linux/io.h>
1819
#include <linux/of.h>
19-
#include <linux/of_reserved_mem.h>
20-
#include <linux/slab.h>
20+
#include <linux/of_address.h>
2121
#include <linux/qcom_scm.h>
22+
#include <linux/sizes.h>
2223
#include <linux/soc/qcom/mdt_loader.h>
2324

2425
#include "firmware.h"
2526

2627
#define VENUS_PAS_ID 9
27-
#define VENUS_FW_MEM_SIZE SZ_8M
28+
#define VENUS_FW_MEM_SIZE (6 * SZ_1M)
2829

29-
static void device_release_dummy(struct device *dev)
30-
{
31-
of_reserved_mem_device_release(dev);
32-
}
33-
34-
int venus_boot(struct device *parent, struct device *fw_dev, const char *fwname)
30+
int venus_boot(struct device *dev, const char *fwname)
3531
{
3632
const struct firmware *mdt;
33+
struct device_node *node;
3734
phys_addr_t mem_phys;
35+
struct resource r;
3836
ssize_t fw_size;
3937
size_t mem_size;
4038
void *mem_va;
@@ -43,66 +41,58 @@ int venus_boot(struct device *parent, struct device *fw_dev, const char *fwname)
4341
if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) || !qcom_scm_is_available())
4442
return -EPROBE_DEFER;
4543

46-
fw_dev->parent = parent;
47-
fw_dev->release = device_release_dummy;
44+
node = of_parse_phandle(dev->of_node, "memory-region", 0);
45+
if (!node) {
46+
dev_err(dev, "no memory-region specified\n");
47+
return -EINVAL;
48+
}
4849

49-
ret = dev_set_name(fw_dev, "%s:%s", dev_name(parent), "firmware");
50+
ret = of_address_to_resource(node, 0, &r);
5051
if (ret)
5152
return ret;
5253

53-
ret = device_register(fw_dev);
54-
if (ret < 0)
55-
return ret;
54+
mem_phys = r.start;
55+
mem_size = resource_size(&r);
5656

57-
ret = of_reserved_mem_device_init_by_idx(fw_dev, parent->of_node, 0);
58-
if (ret)
59-
goto err_unreg_device;
57+
if (mem_size < VENUS_FW_MEM_SIZE)
58+
return -EINVAL;
6059

61-
mem_size = VENUS_FW_MEM_SIZE;
62-
63-
mem_va = dmam_alloc_coherent(fw_dev, mem_size, &mem_phys, GFP_KERNEL);
60+
mem_va = memremap(r.start, mem_size, MEMREMAP_WC);
6461
if (!mem_va) {
65-
ret = -ENOMEM;
66-
goto err_unreg_device;
62+
dev_err(dev, "unable to map memory region: %pa+%zx\n",
63+
&r.start, mem_size);
64+
return -ENOMEM;
6765
}
6866

69-
ret = request_firmware(&mdt, fwname, fw_dev);
67+
ret = request_firmware(&mdt, fwname, dev);
7068
if (ret < 0)
71-
goto err_unreg_device;
69+
goto err_unmap;
7270

7371
fw_size = qcom_mdt_get_size(mdt);
7472
if (fw_size < 0) {
7573
ret = fw_size;
7674
release_firmware(mdt);
77-
goto err_unreg_device;
75+
goto err_unmap;
7876
}
7977

80-
ret = qcom_mdt_load(fw_dev, mdt, fwname, VENUS_PAS_ID, mem_va, mem_phys,
78+
ret = qcom_mdt_load(dev, mdt, fwname, VENUS_PAS_ID, mem_va, mem_phys,
8179
mem_size);
8280

8381
release_firmware(mdt);
8482

8583
if (ret)
86-
goto err_unreg_device;
84+
goto err_unmap;
8785

8886
ret = qcom_scm_pas_auth_and_reset(VENUS_PAS_ID);
8987
if (ret)
90-
goto err_unreg_device;
91-
92-
return 0;
88+
goto err_unmap;
9389

94-
err_unreg_device:
95-
device_unregister(fw_dev);
90+
err_unmap:
91+
memunmap(mem_va);
9692
return ret;
9793
}
9894

99-
int venus_shutdown(struct device *fw_dev)
95+
int venus_shutdown(struct device *dev)
10096
{
101-
int ret;
102-
103-
ret = qcom_scm_pas_shutdown(VENUS_PAS_ID);
104-
device_unregister(fw_dev);
105-
memset(fw_dev, 0, sizeof(*fw_dev));
106-
107-
return ret;
97+
return qcom_scm_pas_shutdown(VENUS_PAS_ID);
10898
}

‎drivers/media/platform/qcom/venus/firmware.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
struct device;
1818

19-
int venus_boot(struct device *parent, struct device *fw_dev,
20-
const char *fwname);
21-
int venus_shutdown(struct device *fw_dev);
19+
int venus_boot(struct device *dev, const char *fwname);
20+
int venus_shutdown(struct device *dev);
2221

2322
#endif

0 commit comments

Comments
 (0)