From patchwork Wed Jan 27 14:39:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harry Wentland X-Patchwork-Id: 8134551 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E3C509F1CC for ; Wed, 27 Jan 2016 14:39:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A736A2010C for ; Wed, 27 Jan 2016 14:39:51 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 2FD5A201E4 for ; Wed, 27 Jan 2016 14:39:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8C69F6E318; Wed, 27 Jan 2016 06:39:48 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0079.outbound.protection.outlook.com [65.55.169.79]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8CC4E6E318 for ; Wed, 27 Jan 2016 06:39:46 -0800 (PST) Received: from BN1PR12CA0040.namprd12.prod.outlook.com (10.160.77.50) by CY1PR12MB0854.namprd12.prod.outlook.com (10.164.70.12) with Microsoft SMTP Server (TLS) id 15.1.390.13; Wed, 27 Jan 2016 14:39:43 +0000 Received: from BY2NAM03FT008.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e4a::201) by BN1PR12CA0040.outlook.office365.com (2a01:111:e400:49::50) with Microsoft SMTP Server (TLS) id 15.1.390.13 via Frontend Transport; Wed, 27 Jan 2016 14:39:43 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.221) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from atltwp01.amd.com (165.204.84.221) by BY2NAM03FT008.mail.protection.outlook.com (10.152.84.101) with Microsoft SMTP Server id 15.1.390.12 via Frontend Transport; Wed, 27 Jan 2016 14:39:42 +0000 X-WSS-ID: 0O1M8Q4-07-CPJ-02 X-M-MSG: Received: from satlvexedge02.amd.com (satlvexedge02.amd.com [10.177.96.29]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by atltwp01.amd.com (Axway MailGate 5.3.1) with ESMTPS id 2451512C12F1 for ; Wed, 27 Jan 2016 09:39:40 -0500 (EST) Received: from SATLEXCHOV02.amd.com (10.181.40.72) by SATLVEXEDGE02.amd.com (10.177.96.29) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 27 Jan 2016 08:39:52 -0600 Received: from STOREXDAG04.amd.com (10.1.13.13) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server (TLS) id 14.3.266.1; Wed, 27 Jan 2016 08:39:40 -0600 Received: from cnhwentlanub.amd.com (172.29.225.36) by storexdag04.amd.com (10.1.13.13) with Microsoft SMTP Server id 14.3.266.1; Wed, 27 Jan 2016 09:39:38 -0500 From: Harry Wentland To: Subject: [PATCH] drm/dp/mst: deallocate payload on port destruction Date: Wed, 27 Jan 2016 09:39:36 -0500 Message-ID: <1453905576-2175-1-git-send-email-harry.wentland@amd.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.221; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(428002)(189002)(199003)(106466001)(110136002)(229853001)(11100500001)(2351001)(77096005)(189998001)(47776003)(5008740100001)(1220700001)(1096002)(50986999)(5003600100002)(105586002)(101416001)(19580395003)(48376002)(586003)(5003940100001)(36756003)(97736004)(53416004)(19580405001)(50466002)(4326007)(50226001)(3470700001)(450100001)(86362001)(33646002)(92566002)(87936001)(2906002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0854; H:atltwp01.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0854; 2:soEmkvgKpYlQCU8H7esmpPGocHVDr8VKxFyY9A8CEJXcOOwstK+Rk/KVnU7KeoNFCmGEHI5OU7p4bvh5oBNUk+D8aPVe7bN6hekhHAcaDcIWOvv8I6jV44yB9FmPKl+A00lgIH0xRVx/ICge6ufjfg==; 3:eJI0mZSdcbWYUf6pWulII3a3B78BqupCVjzyxCmc1e4lQY9HRQ/ORuWgcsZDkPAh3I1pnenwWHrv8KTlSb+ZlMEchFgHsPJM+jhqDMWG9BJ1VQda6dGW9/wjE7BnAJ1YBzrjyM8kWnATPeyUMLFu8gD+GNCweQeMQU4KUs15qFzvrsdXKwAToMZ/Pr9RfvXfJrmcPQNzMZevopQn0r/w9gfWEpzyLtu/GBMkOLGEdrs=; 25:HyMEn/mwqNWY4ZVzwmZ1i73lNcivlFOtTjawVL3Zcg808SkXs1bEk38RaVQlo7LMQVnVnb/r/0y+DHcUBbcJixzwKjkyLRy5cotF5TCDuHilXLAGa9ebvob3pTFJIH3eIE5jlcTFIbzKNk8tQO/RPD02ySv6OQIIhFKAFJwhzRMMc4wc9EetV37hFA+qqnLoPo6B1t12DNGFTMOrthrVzQMheyQ6DZEEapXJhxkbjLok21fK1rZ/MeW0RJo362G2 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR12MB0854; X-MS-Office365-Filtering-Correlation-Id: fc8035f8-6794-4ac0-afc2-08d32727b1aa X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0854; 20:0jZM/PLz0frOOzjS6CQIM2yXkQTWHqT5+7SVkIpFXnZxyA/3ojQweYfdHe0ct7+28yLFttTCuh6x6yBhePDPqcaTyMC1wz4MEmsGmCEy3Y2OQXVDCcvBKTeFftCd0Jkgnp3bpeVdImfYushkBJStzsGdyLV3wUfViAoRK+AKSY0gOwg5UN/PEB9QxGUslFZdjNVlGdVvWur0urQKskp2/kLinT1qP+ius1zZYhJyPB0C8YsGg02Yxt7UfN5XQK3ENgJLCBq7SoZBzocSisUGVgt2+xguV3d5nsuo7Mxa/x3wLNUcfQ+e2qkDMtWGtZhdZgx14SHSQ8o4r5sEOkwUx2hHOCogIUZidY5DTpsVFerAzOkmmkxuLJhW6Xl2QDAurTHrga8+EsI9FnbwnQ6fGUzA2SBRVACJEgV/z+/RAChXTn+gy7ckZ3PL7Hm4EgOE2VvfX7PRwoUAFhPMXRC45s1eKQtQqE9E2k0Haqf97SieN2e0NCbz5oRGyO1KvOK8 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(13024025)(13018025)(13017025)(13023025)(8121501046)(13015025)(3002001)(10201501046); SRVR:CY1PR12MB0854; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0854; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0854; 4:FrBQ2PIPwck163eYOh9x9OW/MTQgMQ9zTM0OOaVM61iq/P2zjGlHIkwOavYZvpO3+gvBTLi25Txe746XBTJAmW+M2DV3wct4KbNjM7fuY4lXHWhC/ZjSf46H5saFH9EyjO4i1M57Rza3Y/QLn2QZ1RGvg8utgTVQ48XV/opgVvLeOz/SDUBkUwni3gurH8mlri+ZPMcZYwMf/4D2C3+FKPN1ac5bo1lIiGcambbCVbHemN1DxgeVJPjfeG+3n6BI2/UNfzTOB3EI9EoUm8GLXQrbOHOxL1VW20fbMb4xgXEKGwEHYakdoF9E9mUzpevQJTxi9ZXsOBnbtvBBdOAlHoPfq0zMooicxKln1kHMOrT+4cBEbLhVLHSPzZ11b1sr53w7AvrFIYXhlkR3eI5Tj9IsItklTab3NRxpz+aD9Lyy0j9ebtvfBZNMpQz1aAk6eUGeVie+SOv6bnoQc3YVsF+Clq+dmryzKiYszdISo3S/oCZaXptn1Me+0VuyusBK X-Forefront-PRVS: 0834BAF534 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR12MB0854; 23:38vd0Ru1q2m0ozbeCjt9ouuZa75rD3EJqpO1mJ+T5?= =?us-ascii?Q?Krjdl0wvWWLcY57/FUR73/fZurY01sUNZtbudHskHxKBMPFfHDs6L2dB9I9E?= =?us-ascii?Q?hEM6G7l6RhHhOzOv2az/MuImjyvZASb8Pl/bOkpp4vpHQbd7xpRGJYgvQdPX?= =?us-ascii?Q?Tl/FOH5ptRKGviTrdiwij/HBK2dabmNSeBp/cWxCGvpZWdTL5dzAGjP7rKS7?= =?us-ascii?Q?R7PCVoi3vSkO4f7mnZpBsgSZ2SqBa97qnKP0+LDYTfOafrLKCDEyomsrC/IM?= =?us-ascii?Q?aV84L2PsUmDp/66JixwvE8/H0EcH3iFALaJNbk7AE4HybBLlgvu2boT2/AEQ?= =?us-ascii?Q?eKCYLsDAWzR3fEyIeYrgTv++R67otOspGMe/LFtRhO3tDX/HSjGZ4loMNHD8?= =?us-ascii?Q?402198A3MF/rQN1O7XnvThtiAZHgrTnhdQT7z3hsXhealO92iMb5vIr3NlJa?= =?us-ascii?Q?n1FJwZ5cizRPRCPKgLtfRxGAaYk75I85BTgkJku12C9mWVgP9oF1anovVQGK?= =?us-ascii?Q?nnNcWT4pFUOxewUuJpEhmMIibtTitBlaKMGpHxaulJ6YYj9wTBnANTutNhkx?= =?us-ascii?Q?5O71/YLYmEWBgqONY2kY5OjqT+T6LS/D0QEspv2hy7Ct23CyC6rqAdwm75Pf?= =?us-ascii?Q?LMz0/LGpQRX5KtwUoz3xdRHGsC1CqIOF8jMaFp5K8ydM2uC+0v7/0DYED+Wq?= =?us-ascii?Q?gu74EG8EwbhkC/kLqbFA8lrMUEO6Gi7epXfCycKMXIgJ4eGXZO8CUyH/fRXZ?= =?us-ascii?Q?ofqsTRGjHKeJuIuAkxtOsE+SrjoF9GPhpk9SYajIqUPWcrc1qun3wFIcgaHi?= =?us-ascii?Q?hUjU51RpNA2em1GMbS+jtxTBJvvTLPwp9UxmYVdKIFnXEj3yI0728Q1mmXzq?= =?us-ascii?Q?/UHBrSuQhSADdo8msioRb/SkU+TAcep4YFzNJ3sTTbqSUdduk0pjTXDzDlw/?= =?us-ascii?Q?cO5+eW2inWNRHsLzAWx94Tl7PDLXZOkzULFXTeGZ5OcRQXLtsJNiwy1ycYgX?= =?us-ascii?Q?bCGUBr31k9ajc7QgADDanGw?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0854; 5:6w6/rCsNbpw2Y2vILmvNENTWfqbJpQFliWQNmv3QjUUhVFOvoDx65mv1n7gf3nd9TJ6ntQEV806j3xakqziwntlTV1hBVcX3q0gFwaQrm35/m3wuMgw3FofhLaCG8ypK9JO2+LQNfKbOm9J/X6pdzg==; 24:6FNooSDQGsP+QN0wLs1xEAdTg8U2PdkaCYDzLfG5TqlXaWoa54Va4HDC0w3IElPwebm771YgpjcX66FsXiAenVUI/ohgCFKl7H0sBzc93Qw=; 20:PjgMRgs9ESYWmpsUojiDrOVi7fb5wuXTd9sBGY6j6b4iEv2Yrs4SXvL4ABLGEEDw+ntUecPsd37KYxRGod3bjoDQIyiIt1WZJNgWmO8n1NYBDPIYQAlmz8rjhufwts3AA2pRTvZolnlLBJhJinsPfnpIBdwEk+NpF32XX9+L6bExZuMxF7hq97DWxNgWniA01/faZtC9E4iLYXczsJyW/0Ns3CeiX+/MZ307rjXsXbKi8ozkEapRq5mTjw3RWpaA SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2016 14:39:42.5301 (UTC) X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.221]; Helo=[atltwp01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0854 Cc: Mykola Lysenko X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mykola Lysenko This is needed to properly deallocate port payload after downstream branch get unplugged. In order to do this unplugged MST topology should be preserved, to find first alive port on path to unplugged MST topology, and send payload deallocation request to branch device of found port. For this mstb and port kref's are used in reversed order to track when port and branch memory could be freed. Added additional functions to find appropriate mstb as described above. Signed-off-by: Mykola Lysenko Reviewed-by: Harry Wentland --- drivers/gpu/drm/drm_dp_mst_topology.c | 91 ++++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c index fc589265068b..5662e68ecccd 100644 --- a/drivers/gpu/drm/drm_dp_mst_topology.c +++ b/drivers/gpu/drm/drm_dp_mst_topology.c @@ -803,6 +803,18 @@ static struct drm_dp_mst_branch *drm_dp_add_mst_branch_device(u8 lct, u8 *rad) return mstb; } +static void drm_dp_free_mst_port(struct kref *kref); + +static void drm_dp_free_mst_branch_device(struct kref *kref) +{ + struct drm_dp_mst_branch *mstb = container_of(kref, struct drm_dp_mst_branch, kref); + if (mstb->port_parent) { + if (list_empty(&mstb->port_parent->next)) + kref_put(&mstb->port_parent->kref, drm_dp_free_mst_port); + } + kfree(mstb); +} + static void drm_dp_destroy_mst_branch_device(struct kref *kref) { struct drm_dp_mst_branch *mstb = container_of(kref, struct drm_dp_mst_branch, kref); @@ -810,6 +822,15 @@ static void drm_dp_destroy_mst_branch_device(struct kref *kref) bool wake_tx = false; /* + * init kref again to be used by ports to remove mst branch when it is + * not needed anymore + */ + kref_init(kref); + + if (mstb->port_parent && list_empty(&mstb->port_parent->next)) + kref_get(&mstb->port_parent->kref); + + /* * destroy all ports - don't need lock * as there are no more references to the mst branch * device at this point. @@ -835,7 +856,8 @@ static void drm_dp_destroy_mst_branch_device(struct kref *kref) if (wake_tx) wake_up(&mstb->mgr->tx_waitq); - kfree(mstb); + + kref_put(kref, drm_dp_free_mst_branch_device); } static void drm_dp_put_mst_branch_device(struct drm_dp_mst_branch *mstb) @@ -883,6 +905,7 @@ static void drm_dp_destroy_port(struct kref *kref) * from an EDID retrieval */ mutex_lock(&mgr->destroy_connector_lock); + kref_get(&port->parent->kref); list_add(&port->next, &mgr->destroy_connector_list); mutex_unlock(&mgr->destroy_connector_lock); schedule_work(&mgr->destroy_connector_work); @@ -1617,6 +1640,37 @@ static int drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr, return 0; } +static struct drm_dp_mst_port *drm_dp_get_last_connected_port_to_mstb(struct drm_dp_mst_branch *mstb) +{ + if (!mstb->port_parent) + return NULL; + + if (mstb->port_parent->mstb != mstb) + return mstb->port_parent; + + return drm_dp_get_last_connected_port_to_mstb(mstb->port_parent->parent); +} + +static struct drm_dp_mst_branch *drm_dp_get_last_connected_port_and_mstb(struct drm_dp_mst_topology_mgr *mgr, + struct drm_dp_mst_branch *mstb, + int *port_num) +{ + struct drm_dp_mst_branch *rmstb = NULL; + struct drm_dp_mst_port *found_port; + mutex_lock(&mgr->lock); + if (mgr->mst_primary) { + found_port = drm_dp_get_last_connected_port_to_mstb(mstb); + + if (found_port) { + rmstb = found_port->parent; + kref_get(&rmstb->kref); + *port_num = found_port->port_num; + } + } + mutex_unlock(&mgr->lock); + return rmstb; +} + static int drm_dp_payload_send_msg(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int id, @@ -1624,13 +1678,18 @@ static int drm_dp_payload_send_msg(struct drm_dp_mst_topology_mgr *mgr, { struct drm_dp_sideband_msg_tx *txmsg; struct drm_dp_mst_branch *mstb; - int len, ret; + int len, ret, port_num; u8 sinks[DRM_DP_MAX_SDP_STREAMS]; int i; + port_num = port->port_num; mstb = drm_dp_get_validated_mstb_ref(mgr, port->parent); - if (!mstb) - return -EINVAL; + if (!mstb) { + mstb = drm_dp_get_last_connected_port_and_mstb(mgr, port->parent, &port_num); + + if (!mstb) + return -EINVAL; + } txmsg = kzalloc(sizeof(*txmsg), GFP_KERNEL); if (!txmsg) { @@ -1642,7 +1701,7 @@ static int drm_dp_payload_send_msg(struct drm_dp_mst_topology_mgr *mgr, sinks[i] = i; txmsg->dst = mstb; - len = build_allocate_payload(txmsg, port->port_num, + len = build_allocate_payload(txmsg, port_num, id, pbn, port->num_sdp_streams, sinks); @@ -2787,6 +2846,13 @@ static void drm_dp_tx_work(struct work_struct *work) mutex_unlock(&mgr->qlock); } +static void drm_dp_free_mst_port(struct kref *kref) +{ + struct drm_dp_mst_port *port = container_of(kref, struct drm_dp_mst_port, kref); + kref_put(&port->parent->kref, drm_dp_free_mst_branch_device); + kfree(port); +} + static void drm_dp_destroy_connector_work(struct work_struct *work) { struct drm_dp_mst_topology_mgr *mgr = container_of(work, struct drm_dp_mst_topology_mgr, destroy_connector_work); @@ -2807,13 +2873,22 @@ static void drm_dp_destroy_connector_work(struct work_struct *work) list_del(&port->next); mutex_unlock(&mgr->destroy_connector_lock); + kref_init(&port->kref); + INIT_LIST_HEAD(&port->next); + mgr->cbs->destroy_connector(mgr, port->connector); drm_dp_port_teardown_pdt(port, port->pdt); - if (!port->input && port->vcpi.vcpi > 0) - drm_dp_mst_put_payload_id(mgr, port->vcpi.vcpi); - kfree(port); + if (!port->input && port->vcpi.vcpi > 0) { + if (mgr->mst_state) { + drm_dp_mst_reset_vcpi_slots(mgr, port); + drm_dp_update_payload_part1(mgr); + drm_dp_mst_put_payload_id(mgr, port->vcpi.vcpi); + } + } + + kref_put(&port->kref, drm_dp_free_mst_port); send_hotplug = true; } if (send_hotplug)