@@ -132,6 +132,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)
{
struct mtk_drm_private *private = drm->dev_private;
struct platform_device *pdev;
+ struct device_node *np;
int ret;
if (!iommu_present(&platform_bus_type))
@@ -177,6 +178,18 @@ static int mtk_drm_kms_init(struct drm_device *drm)
if (ret < 0)
goto err_component_unbind;
+ /* Use OVL device for all DMA memory allocations */
+ np = private->comp_node[mtk_ddp_main[0]] ?:
+ private->comp_node[mtk_ddp_ext[0]];
+ pdev = of_find_device_by_node(np);
+ if (!pdev) {
+ ret = -ENODEV;
+ dev_err(drm->dev, "Need at least one OVL device\n");
+ goto err_component_unbind;
+ }
+
+ private->dma_dev = &pdev->dev;
+
/*
* We don't use the drm_irq_install() helpers provided by the DRM
* core, so we need to set this manually in order to allow the
@@ -30,6 +30,7 @@ struct regmap;
struct mtk_drm_private {
struct drm_device *drm;
+ struct device *dma_dev;
struct drm_crtc *crtc[MAX_CRTC];
unsigned int num_pipes;
@@ -15,6 +15,7 @@
#include <drm/drm_gem.h>
#include <linux/dma-buf.h>
+#include "mtk_drm_drv.h"
#include "mtk_drm_gem.h"
static struct mtk_drm_gem_obj *mtk_drm_gem_init(struct drm_device *dev,
@@ -42,6 +43,7 @@ static struct mtk_drm_gem_obj *mtk_drm_gem_init(struct drm_device *dev,
struct mtk_drm_gem_obj *mtk_drm_gem_create(struct drm_device *dev,
size_t size, bool alloc_kmap)
{
+ struct mtk_drm_private *priv = dev->dev_private;
struct mtk_drm_gem_obj *mtk_gem;
struct drm_gem_object *obj;
int ret;
@@ -58,7 +60,7 @@ struct mtk_drm_gem_obj *mtk_drm_gem_create(struct drm_device *dev,
if (!alloc_kmap)
dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &mtk_gem->dma_attrs);
- mtk_gem->cookie = dma_alloc_attrs(dev->dev, obj->size,
+ mtk_gem->cookie = dma_alloc_attrs(priv->dma_dev, obj->size,
&mtk_gem->dma_addr, GFP_KERNEL,
&mtk_gem->dma_attrs);
if (!mtk_gem->cookie) {
@@ -85,11 +87,12 @@ err_gem_free:
void mtk_drm_gem_free_object(struct drm_gem_object *obj)
{
struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj);
+ struct mtk_drm_private *priv = obj->dev->dev_private;
if (mtk_gem->sg)
drm_prime_gem_destroy(obj, mtk_gem->sg);
else
- dma_free_attrs(obj->dev->dev, obj->size, mtk_gem->cookie,
+ dma_free_attrs(priv->dma_dev, obj->size, mtk_gem->cookie,
mtk_gem->dma_addr, &mtk_gem->dma_attrs);
/* release file pointer to gem object. */
@@ -160,7 +163,7 @@ static int mtk_drm_gem_object_mmap(struct drm_gem_object *obj,
{
int ret;
struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj);
- struct drm_device *drm = obj->dev;
+ struct mtk_drm_private *priv = obj->dev->dev_private;
/*
* dma_alloc_attrs() allocated a struct page table for mtk_gem, so clear
@@ -169,8 +172,8 @@ static int mtk_drm_gem_object_mmap(struct drm_gem_object *obj,
vma->vm_flags &= ~VM_PFNMAP;
vma->vm_pgoff = 0;
- ret = dma_mmap_attrs(drm->dev, vma, mtk_gem->cookie, mtk_gem->dma_addr,
- obj->size, &mtk_gem->dma_attrs);
+ ret = dma_mmap_attrs(priv->dma_dev, vma, mtk_gem->cookie,
+ mtk_gem->dma_addr, obj->size, &mtk_gem->dma_attrs);
if (ret)
drm_gem_vm_close(vma);
@@ -211,7 +214,7 @@ int mtk_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
struct sg_table *mtk_gem_prime_get_sg_table(struct drm_gem_object *obj)
{
struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj);
- struct drm_device *drm = obj->dev;
+ struct mtk_drm_private *priv = obj->dev->dev_private;
struct sg_table *sgt;
int ret;
@@ -219,7 +222,7 @@ struct sg_table *mtk_gem_prime_get_sg_table(struct drm_gem_object *obj)
if (!sgt)
return ERR_PTR(-ENOMEM);
- ret = dma_get_sgtable_attrs(drm->dev, sgt, mtk_gem->cookie,
+ ret = dma_get_sgtable_attrs(priv->dma_dev, sgt, mtk_gem->cookie,
mtk_gem->dma_addr, obj->size,
&mtk_gem->dma_attrs);
if (ret) {