Received: by 10.223.185.116 with SMTP id b49csp445456wrg; Wed, 21 Feb 2018 00:48:58 -0800 (PST) X-Google-Smtp-Source: AH8x224ypPoY/vqOFQRjvcDuFAUG2gT5E57p611hAE/ZqLQFnVzTE1QbVyX4zslS1V6eu78lmOor X-Received: by 2002:a17:902:7681:: with SMTP id m1-v6mr2513112pll.144.1519202938730; Wed, 21 Feb 2018 00:48:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519202938; cv=none; d=google.com; s=arc-20160816; b=GebrC88MwvzHpggo1OepdrqdQEz/isg9E+qa1KtD8kDTuiX1uPXUfh2OcbOv8Kp5b6 8GwFFbSCIjFhnwtQAfH874YccckdN3JuIIb3wzIEicxDdBjg1EJ1n3F4S2LVqCGSyOLg QeJRXMSOJ+cGHwR7Wpgozh4wTyzPrdZ4b1osBpCCfXTHlyU+ZEFiOTxVxDqR/bLZnvwz 8qt6WkHNHU98LbUo9FYiU0daew99G82CIcPi64iZOfY+YicU2JXE0v0ujYI5w21mE2N7 FEc/9cMdr39SXhxqYyQN0NDjE3NzcGL6xVqz7yerhDxb9f6YyqxeOBrlvogdUOBob0iT +I5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=gPpb7VClubKgSSgP6olDjKDnqwlXVvx1pslIs2rrvlU=; b=tAiPXX196CPyDj5D/WIfRVbxLbLqBjaV6fKw9Sldzy4X/M4JR4LLbBC3He6ZIOtnxD jylEZyuY7Sf3TpwOxDcjF2dxAw2BkZllJydqG2GmEW9D/48sN1eEYYXwZBKGvX7vlDXG az3ysSIPr4Rs8cep3jAZrW7n405/68ZnLons8l2M6xBlhRQZOD88CPw7N0rzFA+1GwzB XMeUTN9ZsqH1P4Klpbvu5Cb420ZvSjK/usJ/nISiXqC1edHXzPc/mxQQseOpL6LI5mqV RHeC3/jp8YUQf1jigwNE9wiFjYuRO/lw5tjG8GoUyAaly7qsgO1OvPbpgxaszZy4Zjje +G7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L3B/2Wwn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5-v6si7156818pln.274.2018.02.21.00.48.44; Wed, 21 Feb 2018 00:48:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L3B/2Wwn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751878AbeBUIEA (ORCPT + 99 others); Wed, 21 Feb 2018 03:04:00 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:37373 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751800AbeBUID4 (ORCPT ); Wed, 21 Feb 2018 03:03:56 -0500 Received: by mail-lf0-f67.google.com with SMTP id y19so1079813lfd.4 for ; Wed, 21 Feb 2018 00:03:55 -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=mq0swZI1T40BwBSGUWmJN7Nd7J5khNNOin/j0w408cOpka/2yISK0QKAdIE2UYEnv+ SzMJfybtqS4PA3d7k4GR8ncN0zPjeahW6/BPIhVIR2GsVavgNw6Jo54HDMLDtyD3uEil TgZKfu5Z/d08udIfYYPqAuN/uVi7/44TSpJafNTB6lzHSMvneAqRnxHh78r/p3fOiL2/ xYrd50rpzwoAmHZywfuDtSv/x5nq9Dy1UP1nxlY3ldISYKzAWAzx5jLN2Mn2fDLyJhyb uoc+tMxPj4KJI6KBM/p9KvP47R11aRwvE47pqS4PpEiezBlDv2v4BhScAAWmMs3U0QnM 8VYg== X-Gm-Message-State: APf1xPCx+8PsAHMBQgsVlS5dOxR4Zf4tB0p6moiSG2KWvGCh0C+fKjGS 2U6z30QG2+YhZPBYPBm/ohg= 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 Cc: andr2000@gmail.com, Oleksandr Andrushchenko 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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_ */ -- 2.7.4