@@ -589,6 +589,7 @@ static int compare_str(struct device *dev, void *data)
589589static int etnaviv_pdev_probe (struct platform_device * pdev )
590590{
591591 struct device * dev = & pdev -> dev ;
592+ struct device_node * first_node = NULL ;
592593 struct component_match * match = NULL ;
593594
594595 if (!dev -> platform_data ) {
@@ -598,6 +599,9 @@ static int etnaviv_pdev_probe(struct platform_device *pdev)
598599 if (!of_device_is_available (core_node ))
599600 continue ;
600601
602+ if (!first_node )
603+ first_node = core_node ;
604+
601605 drm_of_component_match_add (& pdev -> dev , & match ,
602606 compare_of , core_node );
603607 }
@@ -609,6 +613,32 @@ static int etnaviv_pdev_probe(struct platform_device *pdev)
609613 component_match_add (dev , & match , compare_str , names [i ]);
610614 }
611615
616+ /*
617+ * PTA and MTLB can have 40 bit base addresses, but
618+ * unfortunately, an entry in the MTLB can only point to a
619+ * 32 bit base address of a STLB. Moreover, to initialize the
620+ * MMU we need a command buffer with a 32 bit address because
621+ * without an MMU there is only an indentity mapping between
622+ * the internal 32 bit addresses and the bus addresses.
623+ *
624+ * To make things easy, we set the dma_coherent_mask to 32
625+ * bit to make sure we are allocating the command buffers and
626+ * TLBs in the lower 4 GiB address space.
627+ */
628+ if (dma_set_mask (& pdev -> dev , DMA_BIT_MASK (40 )) ||
629+ dma_set_coherent_mask (& pdev -> dev , DMA_BIT_MASK (32 ))) {
630+ dev_dbg (& pdev -> dev , "No suitable DMA available\n" );
631+ return - ENODEV ;
632+ }
633+
634+ /*
635+ * Apply the same DMA configuration to the virtual etnaviv
636+ * device as the GPU we found. This assumes that all Vivante
637+ * GPUs in the system share the same DMA constraints.
638+ */
639+ if (first_node )
640+ of_dma_configure (& pdev -> dev , first_node , true);
641+
612642 return component_master_add_with_match (dev , & etnaviv_master_ops , match );
613643}
614644
@@ -653,21 +683,12 @@ static int __init etnaviv_init(void)
653683 if (!of_device_is_available (np ))
654684 continue ;
655685
656- pdev = platform_device_alloc ("etnaviv" , -1 );
686+ pdev = platform_device_alloc ("etnaviv" , PLATFORM_DEVID_NONE );
657687 if (!pdev ) {
658688 ret = - ENOMEM ;
659689 of_node_put (np );
660690 goto unregister_platform_driver ;
661691 }
662- pdev -> dev .coherent_dma_mask = DMA_BIT_MASK (40 );
663- pdev -> dev .dma_mask = & pdev -> dev .coherent_dma_mask ;
664-
665- /*
666- * Apply the same DMA configuration to the virtual etnaviv
667- * device as the GPU we found. This assumes that all Vivante
668- * GPUs in the system share the same DMA constraints.
669- */
670- of_dma_configure (& pdev -> dev , np , true);
671692
672693 ret = platform_device_add (pdev );
673694 if (ret ) {
0 commit comments