From patchwork Fri Aug 31 14:13:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10583845 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4172717DE for ; Fri, 31 Aug 2018 14:13:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C07827E01 for ; Fri, 31 Aug 2018 14:13:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 201F728569; Fri, 31 Aug 2018 14:13:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A5C6C27E01 for ; Fri, 31 Aug 2018 14:13:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 44C346E106; Fri, 31 Aug 2018 14:13:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6407E6E106 for ; Fri, 31 Aug 2018 14:13:17 +0000 (UTC) Received: by mail-lf1-x144.google.com with SMTP id h64-v6so10075479lfi.10 for ; Fri, 31 Aug 2018 07:13:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=MPcKXq+sJKw1DzSt4olA9dZSQBRDj+izZI+S4O7k/oQ=; b=Zvb99PSrk8Oiqwg1EBUdugTV/SjoKs6cTjFJTXT7Fot1NKBHDOL7KL6aDjUyWNH7Jz Obey6/BGRxOsF+vWpccOWwnHnE1oSG4XiE/LxXiHudtiax7NvLjEO3XwtH6GFfNWYVEt 81l71MRXWT0G9IJitf/1MA19BeSZJlW/KSIyssKn73pL/AnZPjXjoMgCFCdm2NOxa1Ap pS2kum/wKn2hXj/yANfq9mm2qRngS1WuzlWe5Gp8jbo8F39WX06+ELJEZ5D1CUnlaetw BGoCm77eA/8qVY0UeaNbwq+qDgecJsMcu1SEXB5Xs+iZy0f9sPj59ZpF9LkLwWCQITp9 nkDw== X-Gm-Message-State: APzg51B1Um4ymgOGHNDXWsAvr8cN2c7f5cRBG5nx64eLfZaVUpL4k8LK m2x19BU5njxDr6c2lbd98OGVAw== X-Google-Smtp-Source: ANB0VdaM1YZwfw0zJq3SImBPLa79VgE8gRFCgF4SUe96J/nZTlVSUPS8Oyqktq28o9aIho03cxWn4A== X-Received: by 2002:a19:d105:: with SMTP id i5-v6mr11078805lfg.31.1535724795687; Fri, 31 Aug 2018 07:13:15 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id b15-v6sm1902052lfg.18.2018.08.31.07.13.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Aug 2018 07:13:14 -0700 (PDT) From: Linus Walleij To: Christoph Hellwig , Marek Szyprowski , Robin Murphy , Russell King Subject: [PATCH v3] of/platform: initialise AMBA default DMA masks Date: Fri, 31 Aug 2018 16:13:07 +0200 Message-Id: <20180831141307.9053-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: iommu@lists.linux-foundation.org, dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This addresses a v4.19-rc1 regression in the PL111 DRM driver in drivers/gpu/pl111/* The driver uses the CMA KMS helpers and will thus at some point call down to dma_alloc_attrs() to allocate a chunk of contigous DMA memory for the framebuffer. It appears that in v4.18, it was OK that this (and other DMA mastering AMBA devices) left dev->coherent_dma_mask blank (zero). In v4.19-rc1 the WARN_ON_ONCE(dev && !dev->coherent_dma_mask) in dma_alloc_attrs() in include/linux/dma-mapping.h is triggered. The allocation later fails when get_coherent_dma_mask() is called from __dma_alloc() and __dma_alloc() returns NULL: drm-clcd-pl111 dev:20: coherent DMA mask is unset drm-clcd-pl111 dev:20: [drm:drm_fb_helper_fbdev_setup] *ERROR* Failed to set fbdev configuration It turns out that in commit 4d8bde883bfb ("OF: Don't set default coherent DMA mask") the OF core stops setting the default DMA mask on new devices, especially those lines of the patch: - if (!dev->coherent_dma_mask) - dev->coherent_dma_mask = DMA_BIT_MASK(32); Robin Murphy solved a similar problem in a5516219b102 ("of/platform: Initialise default DMA masks") by simply assigning dev.coherent_dma_mask and the dev.dma_mask to point to the same when creating devices from the device tree, and introducing the same code into the code path creating AMBA/PrimeCell devices solved my problem, graphics now come up. The code simply assumes that the device can access all of the system memory by setting the coherent DMA mask to 0xffffffff when creating a device from the device tree, which is crude, but seems to be what kernel v4.18 assumed. The AMBA PrimeCells do not differ between coherent and streaming DMA so we can just assign the same to any DMA mask. Possibly drivers should augment their coherent DMA mask in accordance with "dma-ranges" from the device tree if more finegranular masking is needed. Reported-by: Russell King Fixes: 4d8bde883bfb ("OF: Don't set default coherent DMA mask") Cc: Russell King Cc: Christoph Hellwig Cc: Robin Murphy Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Provide proper root cause analysis, point to the right offending commit with Fixes: - Make even more elaborate description of what is causing this. ChangeLog v1->v2: - Provide a better description for the change. --- drivers/of/platform.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 7ba90c290a42..6c59673933e9 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -241,6 +241,10 @@ static struct amba_device *of_amba_device_create(struct device_node *node, if (!dev) goto err_clear_flag; + /* AMBA devices only support a single DMA mask */ + dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); + dev->dev.dma_mask = &dev->dev.coherent_dma_mask; + /* setup generic device info */ dev->dev.of_node = of_node_get(node); dev->dev.fwnode = &node->fwnode;