Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp928270pxb; Mon, 25 Oct 2021 22:43:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRp7j8gB4IJqeqfN658mW1+VkYwHhyMcMGTEA9sXyEVnMn7tbZmONviKPVW9RPMvtFZuEw X-Received: by 2002:a63:1406:: with SMTP id u6mr17317411pgl.106.1635226982334; Mon, 25 Oct 2021 22:43:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635226982; cv=none; d=google.com; s=arc-20160816; b=Xo8kIChDNr93U0hv5p/NWcxzD2MnJj6bIoePo/g03s66vdS9xPVMVm9pmwOQWAzMpQ cH2SC7ov0FK1gtqkWJFWJ2gfOFRuhUpN1oFyVN8IYuaNPC4EU/iO5WaQBPmhTC8EbuNy B97O2dVPJo8fKqPvIMFFbF0ljtV31MH2TKAPGN7vBb/g+SAjYFO2uQ+yw+InJWvUj3q2 bMpB0spwQTOTFgcsf7qAP5xcaa+C9v42dlvPXkv5raX32APyxHQIUpQ1CSyvF/Vk0jgW 42sBaShWl5EoMPCpljXdF9LiFgYS2rsB6qBaJbuomfKArlX6+AlX4+as57MyAekxA0LR qpYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6Qz3MqVp4L66d3gQlwKw4vRvuaWChiqClLaMXKhYzGc=; b=sD03QFj30kQJa7TG+3gvZVfrimn9Azn+rpbUCuvynjtIJ6kYsViX++Sl8/iJUUsVTB ydbrKb522Y948HUPB4xDK8PF2GO+DmDFilENFjOXglUYPAlSLzYgm90tU0ssDvSoie2t plQZcoHgvEl/YQGUN22xBNnq6xenTWnW1eU5jK4AinWRIDv3uf6Inx/feAlA7fPGHb5b mxY+A+Zk0hRLvvhA9CVgiuLszo8BfmjdcHI1T895jYRKc4wvYvp3jKI6RE8a6pkhUs4D zqqDl6xpkVIMobvgaDpq1piBd+NP75uHfZHxU6TZYnGA765aQPmdz5Q3+adBGQ64XUZh z7yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PJpytGBB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z18si34255342plg.159.2021.10.25.22.42.50; Mon, 25 Oct 2021 22:43:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PJpytGBB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235818AbhJZADj (ORCPT + 99 others); Mon, 25 Oct 2021 20:03:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235541AbhJZADR (ORCPT ); Mon, 25 Oct 2021 20:03:17 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E6F5C06122B for ; Mon, 25 Oct 2021 17:00:53 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id q187so12309250pgq.2 for ; Mon, 25 Oct 2021 17:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6Qz3MqVp4L66d3gQlwKw4vRvuaWChiqClLaMXKhYzGc=; b=PJpytGBBWaPNrbxJ524Enj9tcJVEvongLfIiTnX8PdA+TukXQJQijTprv6q8XSVgWz 3PpJxK8VRMCzRNHNIdPcrWiXw5gvRjVWQ3UtJgZDkeQxfBOeA4NieLqlcDnI9b/Cw0pB MFQwcrjqAhn7CjG862bnO3VvoLMkgg7kofMbc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6Qz3MqVp4L66d3gQlwKw4vRvuaWChiqClLaMXKhYzGc=; b=tl/77Khb2Ji0LaoqEA6IBExcpUl3kV8c07uRJEQTJP0adzJzqYXmPazq7f6xcV9eWZ rsd+QkZmdIytKY+5xBZiUrOzloLGesLvAMn06RemXoGsNmo44fzMF1yT8YvUoigtIBCS TQP+1JEGMU+lh/1iRmHvfGoDzXx2/XdRAh3coTuHxMY8CAhK5I/4WYAT+/zJM9HMuvYp ze9r0IcF+ofIwhxeTBjk+V9cZ/h23FOLmp8zz8mk5vVcIGv+ZGJIx3xYUyfJDTsIs6eW SG/6pe/Sl1X7KusE+lWmPQ3qN9jue59aLKQWvnkue0VA1oZ84awE+aVZXMJOAKw7X5Q3 4MPA== X-Gm-Message-State: AOAM531rkHe04I3hHaaotrttMd6MxNk0iQYA5Q04CC5j+SZkAZ3/4kTh sTQU/49gKvA8WleTgnz+mSXTrA== X-Received: by 2002:a05:6a00:1352:b0:44d:4573:3ac2 with SMTP id k18-20020a056a00135200b0044d45733ac2mr22502964pfu.12.1635206452710; Mon, 25 Oct 2021 17:00:52 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:201:f5e3:5eb1:d5ee:6893]) by smtp.gmail.com with ESMTPSA id b7sm9900747pfm.28.2021.10.25.17.00.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 17:00:52 -0700 (PDT) From: Stephen Boyd To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, Daniel Vetter , "Rafael J. Wysocki" , Rob Clark , Russell King , Saravana Kannan Subject: [PATCH v3 07/34] drm/msm: Migrate to aggregate driver Date: Mon, 25 Oct 2021 17:00:17 -0700 Message-Id: <20211026000044.885195-8-swboyd@chromium.org> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog In-Reply-To: <20211026000044.885195-1-swboyd@chromium.org> References: <20211026000044.885195-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The device lists are poorly ordered when the component device code is used. This is because component_master_add_with_match() returns 0 regardless of component devices calling component_add() first. It can really only fail if an allocation fails, in which case everything is going bad and we're out of memory. The driver that registers the aggregate driver, can succeed at probe and put the attached device on the DPM lists before any of the component devices are probed and put on the lists. Within the component device framework this usually isn't that bad because the real driver work is done at bind time via component{,master}_ops::bind(). It becomes a problem when the driver core, or host driver, wants to operate on the component device outside of the bind/unbind functions, e.g. via 'remove' or 'shutdown'. The driver core doesn't understand the relationship between the host device and the component devices and could possibly try to operate on component devices when they're already removed from the system or shut down. Normally, device links or probe defer would reorder the lists and put devices that depend on other devices in the lists at the correct location, but with component devices this doesn't happen because this information isn't expressed anywhere. Drivers simply succeed at registering their component or the aggregate driver with the component framework and wait for their bind() callback to be called once the other components are ready. In summary, the drivers that make up the aggregate driver can probe in any order. This ordering problem becomes fairly obvious when shutting down the device with a DSI controller connected to a DSI bridge that is controlled via i2c. In this case, the msm display driver wants to tear down the display pipeline on shutdown via msm_pdev_shutdown() by calling drm_atomic_helper_shutdown(), and it can't do that unless the whole display chain is still probed and active in the system. When a display bridge is on i2c, the i2c device for the bridge will be created whenever the i2c controller probes, which could be before or after the msm display driver probes. If the i2c controller probes after the display driver, then the i2c controller will be shutdown before the display controller during system wide shutdown and thus i2c transactions will stop working before the display pipeline is shut down. This means we'll have the display bridge trying to access an i2c bus that's shut down because drm_atomic_helper_shutdown() is trying to disable the bridge after the bridge is off. The solution is to make the aggregate driver into a real struct driver that is bound to a device when the other component devices have all probed. Now that the component driver code is a proper bus, we can simply register an aggregate driver with that bus via component_aggregate_register() and then attach the shutdown hook to that driver to be sure that the shutdown for the display pipeline is called before any of the component device driver shutdown hooks are called. Cc: Daniel Vetter Cc: "Rafael J. Wysocki" Cc: Rob Clark Cc: Russell King Cc: Saravana Kannan Signed-off-by: Stephen Boyd --- drivers/gpu/drm/msm/msm_drv.c | 46 +++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index 2e6fc185e54d..efbcae6e585f 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -1324,19 +1324,35 @@ static int add_gpu_components(struct device *dev, return 0; } -static int msm_drm_bind(struct device *dev) +static int msm_drm_bind(struct aggregate_device *adev) { - return msm_drm_init(dev, &msm_driver); + return msm_drm_init(adev->parent, &msm_driver); } -static void msm_drm_unbind(struct device *dev) +static void msm_drm_unbind(struct aggregate_device *adev) { - msm_drm_uninit(dev); + msm_drm_uninit(adev->parent); +} + +static void msm_drm_shutdown(struct aggregate_device *adev) +{ + struct drm_device *drm = platform_get_drvdata(to_platform_device(adev->parent)); + struct msm_drm_private *priv = drm ? drm->dev_private : NULL; + + if (!priv || !priv->kms) + return; + + drm_atomic_helper_shutdown(drm); } -static const struct component_master_ops msm_drm_ops = { - .bind = msm_drm_bind, - .unbind = msm_drm_unbind, +static struct aggregate_driver msm_drm_aggregate_driver = { + .probe = msm_drm_bind, + .remove = msm_drm_unbind, + .shutdown = msm_drm_shutdown, + .driver = { + .name = "msm_drm", + .owner = THIS_MODULE, + }, }; /* @@ -1365,7 +1381,7 @@ static int msm_pdev_probe(struct platform_device *pdev) if (ret) goto fail; - ret = component_master_add_with_match(&pdev->dev, &msm_drm_ops, match); + ret = component_aggregate_register(&pdev->dev, &msm_drm_aggregate_driver, match); if (ret) goto fail; @@ -1378,23 +1394,12 @@ static int msm_pdev_probe(struct platform_device *pdev) static int msm_pdev_remove(struct platform_device *pdev) { - component_master_del(&pdev->dev, &msm_drm_ops); + component_aggregate_unregister(&pdev->dev, &msm_drm_aggregate_driver); of_platform_depopulate(&pdev->dev); return 0; } -static void msm_pdev_shutdown(struct platform_device *pdev) -{ - struct drm_device *drm = platform_get_drvdata(pdev); - struct msm_drm_private *priv = drm ? drm->dev_private : NULL; - - if (!priv || !priv->kms) - return; - - drm_atomic_helper_shutdown(drm); -} - static const struct of_device_id dt_match[] = { { .compatible = "qcom,mdp4", .data = (void *)KMS_MDP4 }, { .compatible = "qcom,mdss", .data = (void *)KMS_MDP5 }, @@ -1410,7 +1415,6 @@ MODULE_DEVICE_TABLE(of, dt_match); static struct platform_driver msm_platform_driver = { .probe = msm_pdev_probe, .remove = msm_pdev_remove, - .shutdown = msm_pdev_shutdown, .driver = { .name = "msm", .of_match_table = dt_match, -- https://chromeos.dev