From patchwork Wed Feb 21 08:03:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 10231397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A54EE60209 for ; Wed, 21 Feb 2018 08:04:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8ACA2289A3 for ; Wed, 21 Feb 2018 08:04:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EFB828A68; Wed, 21 Feb 2018 08:04:24 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 10B24289A3 for ; Wed, 21 Feb 2018 08:04:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0CF306E54D; Wed, 21 Feb 2018 08:04:08 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf0-x242.google.com (mail-lf0-x242.google.com [IPv6:2a00:1450:4010:c07::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 422A36E522 for ; Wed, 21 Feb 2018 08:03:56 +0000 (UTC) Received: by mail-lf0-x242.google.com with SMTP id v9so1063632lfa.11 for ; Wed, 21 Feb 2018 00:03:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gPpb7VClubKgSSgP6olDjKDnqwlXVvx1pslIs2rrvlU=; b=L3B/2Wwn4/cBA3o+wWG93QnG3O+75Tv8WIqdkO4W2jmQGk+oNUR0pOLYv5Npp5WomJ yqmAlGA0/e4mvGJ5RbHerEaLd7syiyYNeU3ay+vKwNuiheCFMtqV0QqS307JcnEpRtAS hqSY2a5VkBmWKqNTB8LRdvDYzxhna/jzqcEQo/95TaK5nBeVNB4cPG98f2EV9fymunQf RGPR1sNT6RxXh3eewu34UGDKRr8W2zgXOFyt9trxyvJGk9Rm7Z6RQww0TdjFJ62gBXqe tOyTzv3VhVxawQbJMPUj0lbkfQGE5f+GAtrZ4iNWPOKfS7lJePGdbdlmK9NioDW2u6Pc zcvg== 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:in-reply-to :references; bh=gPpb7VClubKgSSgP6olDjKDnqwlXVvx1pslIs2rrvlU=; b=WQsCHjOrfc2eDTDKQMKmnhqVJUR1Vrims2G0Ww0GGeDezrl8LBuSZBMThs9XTOhDCA SwMA+z+iUzxYK9tt9vnPhx3PBPGUAd9By9RtV9yv6Qn/WZN5HVi4puHDiYcQb1i8OW9w K/Ivepb3ZmpzQG+u2t/GP2iGLeToyB/qvG1dJjKmwq0JYggLS3Yj3ejPeuVUUbLhXpGH LMDjzUGYyRF5mi+zDlNxM/i9+r564A/oIl0iWUptFI23ndg2uC4/Yv0t09E3dSU/Slet GCGHZBD5UHPJN9mpgJHCdVmhg/vMzSr8G0rb2EPeFkoR+wIIuY2uuvUubrsqpEyubaGZ z4/Q== X-Gm-Message-State: APf1xPA+fP29NB6WQwfhA4HDmFx/ykDdOQA4YSZ/ZBE0yg623iBHE2dx 4oV/vJmpU0KsOmlUbKUOHEw= X-Google-Smtp-Source: AH8x226LVoCGFVg//M1LNjSaukAPPnpvfI1uwfHDkinWWWZjdLbCQRgoQPAx/4Kg+b9Acjdculo8jA== X-Received: by 10.46.4.74 with SMTP id 71mr1612375lje.51.1519200234511; Wed, 21 Feb 2018 00:03:54 -0800 (PST) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-53.209.223.85.sovam.net.ua. [85.223.209.53]) by smtp.gmail.com with ESMTPSA id g38sm687394lji.24.2018.02.21.00.03.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Feb 2018 00:03:53 -0800 (PST) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, airlied@linux.ie, daniel.vetter@intel.com, seanpaul@chromium.org, gustavo@padovan.org, jgross@suse.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com Subject: [PATCH 2/9] drm/xen-front: Implement Xen bus state handling Date: Wed, 21 Feb 2018 10:03:35 +0200 Message-Id: <1519200222-20623-3-git-send-email-andr2000@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519200222-20623-1-git-send-email-andr2000@gmail.com> References: <1519200222-20623-1-git-send-email-andr2000@gmail.com> 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: andr2000@gmail.com, Oleksandr Andrushchenko MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Andrushchenko Initial handling for Xen bus states: implement Xen bus state machine for the frontend driver according to the state diagram and recovery flow from display para-virtualized protocol: xen/interface/io/displif.h. Signed-off-by: Oleksandr Andrushchenko --- drivers/gpu/drm/xen/xen_drm_front.c | 124 +++++++++++++++++++++++++++++++++++- drivers/gpu/drm/xen/xen_drm_front.h | 26 ++++++++ 2 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/xen/xen_drm_front.h diff --git a/drivers/gpu/drm/xen/xen_drm_front.c b/drivers/gpu/drm/xen/xen_drm_front.c index fd372fb464a1..d0306f9d660d 100644 --- a/drivers/gpu/drm/xen/xen_drm_front.c +++ b/drivers/gpu/drm/xen/xen_drm_front.c @@ -24,19 +24,141 @@ #include +#include "xen_drm_front.h" + +static void xen_drv_remove_internal(struct xen_drm_front_info *front_info) +{ +} + +static int backend_on_initwait(struct xen_drm_front_info *front_info) +{ + return 0; +} + +static int backend_on_connected(struct xen_drm_front_info *front_info) +{ + return 0; +} + +static void backend_on_disconnected(struct xen_drm_front_info *front_info) +{ + xenbus_switch_state(front_info->xb_dev, XenbusStateInitialising); +} + static void backend_on_changed(struct xenbus_device *xb_dev, enum xenbus_state backend_state) { + struct xen_drm_front_info *front_info = dev_get_drvdata(&xb_dev->dev); + int ret; + + DRM_DEBUG("Backend state is %s, front is %s\n", + xenbus_strstate(backend_state), + xenbus_strstate(xb_dev->state)); + + switch (backend_state) { + case XenbusStateReconfiguring: + /* fall through */ + case XenbusStateReconfigured: + /* fall through */ + case XenbusStateInitialised: + break; + + case XenbusStateInitialising: + /* recovering after backend unexpected closure */ + backend_on_disconnected(front_info); + break; + + case XenbusStateInitWait: + /* recovering after backend unexpected closure */ + backend_on_disconnected(front_info); + if (xb_dev->state != XenbusStateInitialising) + break; + + ret = backend_on_initwait(front_info); + if (ret < 0) + xenbus_dev_fatal(xb_dev, ret, "initializing frontend"); + else + xenbus_switch_state(xb_dev, XenbusStateInitialised); + break; + + case XenbusStateConnected: + if (xb_dev->state != XenbusStateInitialised) + break; + + ret = backend_on_connected(front_info); + if (ret < 0) + xenbus_dev_fatal(xb_dev, ret, "initializing DRM driver"); + else + xenbus_switch_state(xb_dev, XenbusStateConnected); + break; + + case XenbusStateClosing: + /* + * in this state backend starts freeing resources, + * so let it go into closed state, so we can also + * remove ours + */ + break; + + case XenbusStateUnknown: + /* fall through */ + case XenbusStateClosed: + if (xb_dev->state == XenbusStateClosed) + break; + + backend_on_disconnected(front_info); + break; + } } static int xen_drv_probe(struct xenbus_device *xb_dev, const struct xenbus_device_id *id) { - return 0; + struct xen_drm_front_info *front_info; + + front_info = devm_kzalloc(&xb_dev->dev, + sizeof(*front_info), GFP_KERNEL); + if (!front_info) { + xenbus_dev_fatal(xb_dev, -ENOMEM, "allocating device memory"); + return -ENOMEM; + } + + front_info->xb_dev = xb_dev; + dev_set_drvdata(&xb_dev->dev, front_info); + return xenbus_switch_state(xb_dev, XenbusStateInitialising); } static int xen_drv_remove(struct xenbus_device *dev) { + struct xen_drm_front_info *front_info = dev_get_drvdata(&dev->dev); + int to = 100; + + xenbus_switch_state(dev, XenbusStateClosing); + + /* + * On driver removal it is disconnected from XenBus, + * so no backend state change events come via .otherend_changed + * callback. This prevents us from exiting gracefully, e.g. + * signaling the backend to free event channels, waiting for its + * state to change to XenbusStateClosed and cleaning at our end. + * Normally when front driver removed backend will finally go into + * XenbusStateInitWait state. + * + * Workaround: read backend's state manually and wait with time-out. + */ + while ((xenbus_read_unsigned(front_info->xb_dev->otherend, + "state", XenbusStateUnknown) != XenbusStateInitWait) && + to--) + msleep(10); + + if (!to) + DRM_ERROR("Backend state is %s while removing driver\n", + xenbus_strstate(xenbus_read_unsigned( + front_info->xb_dev->otherend, + "state", XenbusStateUnknown))); + + xen_drv_remove_internal(front_info); + xenbus_frontend_closed(dev); return 0; } diff --git a/drivers/gpu/drm/xen/xen_drm_front.h b/drivers/gpu/drm/xen/xen_drm_front.h new file mode 100644 index 000000000000..8af46850f126 --- /dev/null +++ b/drivers/gpu/drm/xen/xen_drm_front.h @@ -0,0 +1,26 @@ +/* + * Xen para-virtual DRM device + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Copyright (C) 2016-2018 EPAM Systems Inc. + * + * Author: Oleksandr Andrushchenko + */ + +#ifndef __XEN_DRM_FRONT_H_ +#define __XEN_DRM_FRONT_H_ + +struct xen_drm_front_info { + struct xenbus_device *xb_dev; +}; + +#endif /* __XEN_DRM_FRONT_H_ */