From patchwork Tue Feb 2 19:18:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harry Wentland X-Patchwork-Id: 8194831 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 5A39A9F3CD for ; Tue, 2 Feb 2016 19:34:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 20F2720279 for ; Tue, 2 Feb 2016 19:34:42 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id CA2CE20253 for ; Tue, 2 Feb 2016 19:34:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E15146E436; Tue, 2 Feb 2016 11:34:39 -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-bl2on0063.outbound.protection.outlook.com [65.55.169.63]) by gabe.freedesktop.org (Postfix) with ESMTPS id 671946E437 for ; Tue, 2 Feb 2016 11:34:37 -0800 (PST) Received: from CY1PR12MB0409.namprd12.prod.outlook.com (10.163.91.154) by CY1PR12MB0698.namprd12.prod.outlook.com (10.163.238.16) with Microsoft SMTP Server (TLS) id 15.1.396.15; Tue, 2 Feb 2016 19:18:41 +0000 Received: from CY1PR12MB0409.namprd12.prod.outlook.com ([10.163.91.154]) by CY1PR12MB0409.namprd12.prod.outlook.com ([10.163.91.154]) with mapi id 15.01.0396.020; Tue, 2 Feb 2016 19:18:41 +0000 From: "Wentland, Harry" To: Dave Airlie , Daniel Vetter Subject: RE: [PATCH] drm/dp/mst: deallocate payload on port destruction Thread-Topic: [PATCH] drm/dp/mst: deallocate payload on port destruction Thread-Index: AQHRWRCUve+oLRD5mUupSbQTak6AUp8ZKkiQ Date: Tue, 2 Feb 2016 19:18:41 +0000 Message-ID: References: <1453905576-2175-1-git-send-email-harry.wentland@amd.com> In-Reply-To: <1453905576-2175-1-git-send-email-harry.wentland@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: gmail.com; dkim=none (message not signed) header.d=none; gmail.com; dmarc=none action=none header.from=amd.com; x-originating-ip: [165.204.54.251] x-ms-office365-filtering-correlation-id: 4200632d-5aee-43f5-8d14-08d32c05a95f x-microsoft-exchange-diagnostics: 1; CY1PR12MB0698; 5:EiyjJxPj84Nw2PBDbv1qnynah/sGYe1L7hqZH58y0cw1ifMshgI+vRLFS51xmz3XeJf/YCjKfdtySz1Lf5vFz6pOGSIgPOcvmv69hhwI6Qmm0RLpWbjIEr4AJ7qGPimYQp2r28QLuMLSPN7+09qwHg==; 24:K+PDY4pGE5RJHQP659x03TLGcOt+yToszTMp1k5d9FJuLWZ/5nCRAD2brKxdvtq2SEnLZygc6PAtc8O82sOGx5/KH77UfeEncgU2ItZ4208=; 20:JhxZAmY3ptDtdE8msg6R4f/wKj+yvY83mSGRKtjsrznrZipQ55nO7coTHkFT9zKoamqb9v/8gkdNfAXyrqrIaRbALchhHgalZ6k7ydXQ902QS7VuSfvPGL++W04s5DlLaGsSPhqNgdh5RBessZhG6PAFuxr45VuUUVMJxZvzadWLVH3QnQx30NQTeK7TT3jN5yk8HsnaFFH/BLfz33EMc2dkLic055IdcdU4GTuwqEgwr63EMHJigV8ragTYNUcf x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR12MB0698; 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)(8121501046)(10201501046)(3002001); SRVR:CY1PR12MB0698; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0698; x-forefront-prvs: 084080FC15 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(377454003)(164054003)(13464003)(66066001)(15975445007)(77096005)(4326007)(2900100001)(33656002)(2906002)(5001960100002)(5003600100002)(1720100001)(5001770100001)(40100003)(2950100001)(87936001)(11100500001)(189998001)(76176999)(54356999)(586003)(76576001)(19580395003)(122556002)(6116002)(19580405001)(3846002)(1096002)(102836003)(1220700001)(50986999)(10400500002)(106116001)(5008740100001)(5002640100001)(5004730100002)(86362001)(92566002)(74316001)(3280700002)(3660700001)(99286002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0698; H:CY1PR12MB0409.namprd12.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Feb 2016 19:18:41.4160 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0698 Cc: "Deucher, Alexander" , "Lysenko, Mykola" , "dri-devel@lists.freedesktop.org" 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.6 required=5.0 tests=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 Hi Dave, Daniel, Have you had a chance to take a look at this patch? Thanks, Harry -----Original Message----- From: dri-devel [mailto:dri-devel-bounces@lists.freedesktop.org] On Behalf Of Harry Wentland Sent: January 27, 2016 9:40 AM To: dri-devel@lists.freedesktop.org Cc: Lysenko, Mykola Subject: [PATCH] drm/dp/mst: deallocate payload on port destruction 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(-) /* + * 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) -- 2.1.4 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/dri-devel 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;