From patchwork Thu Sep 13 05:47:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10598717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47A32112B for ; Thu, 13 Sep 2018 05:48:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 383152A1FF for ; Thu, 13 Sep 2018 05:48:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BCDC2A22A; Thu, 13 Sep 2018 05:48:16 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB46A2A1F5 for ; Thu, 13 Sep 2018 05:48:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726693AbeIMKzr (ORCPT ); Thu, 13 Sep 2018 06:55:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53150 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726680AbeIMKzr (ORCPT ); Thu, 13 Sep 2018 06:55:47 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75C34811B7; Thu, 13 Sep 2018 05:47:51 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2801F2010CAA; Thu, 13 Sep 2018 05:47:47 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id B388620491; Thu, 13 Sep 2018 07:47:45 +0200 (CEST) From: Gerd Hoffmann To: Kirti Wankhede , intel-gvt-dev@lists.freedesktop.org, Alex Williamson Cc: kvm@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/2] vfio: add edid api for display (vgpu) devices. Date: Thu, 13 Sep 2018 07:47:44 +0200 Message-Id: <20180913054745.6353-2-kraxel@redhat.com> In-Reply-To: <20180913054745.6353-1-kraxel@redhat.com> References: <20180913054745.6353-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 13 Sep 2018 05:47:51 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Gerd Hoffmann Signed-off-by: Gerd Hoffmann --- include/uapi/linux/vfio.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 1aa7b82e81..38b591e909 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -200,8 +200,11 @@ struct vfio_device_info { #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2) /* vfio-platform device */ #define VFIO_DEVICE_FLAGS_AMBA (1 << 3) /* vfio-amba device */ #define VFIO_DEVICE_FLAGS_CCW (1 << 4) /* vfio-ccw device */ +#define VFIO_DEVICE_FLAGS_EDID (1 << 5) /* Device supports edid */ __u32 num_regions; /* Max region index + 1 */ __u32 num_irqs; /* Max IRQ index + 1 */ + __u32 edid_max_x; /* Max display width (zero == no limit) */ + __u32 edid_max_y; /* Max display height (zero == no limit) */ }; #define VFIO_DEVICE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 7) @@ -602,6 +605,41 @@ struct vfio_device_ioeventfd { #define VFIO_DEVICE_IOEVENTFD _IO(VFIO_TYPE, VFIO_BASE + 16) +/** + * VFIO_DEVICE_SET_GFX_EDID - _IOW(VFIO_TYPE, VFIO_BASE + 17, + * struct vfio_device_set_gfx_edid) + * + * Set display link state and edid blob (for UP state). + * + * For the edid blob spec look here: + * https://en.wikipedia.org/wiki/Extended_Display_Identification_Data + * + * The guest should be notified about edid changes, for example by + * setting the link status to down temporarely (emulate monitor + * hotplug). + * + * @link_state: + * VFIO_DEVICE_GFX_LINK_STATE_UP: Monitor is turned on. + * VFIO_DEVICE_GFX_LINK_STATE_DOWN: Monitor is turned off. + * + * @edid_size: Size of the edid data blob. + * @edid_blob: The actual edid data. + * + * Returns 0 on success, error code (such as -EINVAL) on failure. + */ +struct vfio_device_set_gfx_edid { + __u32 argsz; + __u32 flags; + /* in */ + __u32 link_state; +#define VFIO_DEVICE_GFX_LINK_STATE_UP 1 +#define VFIO_DEVICE_GFX_LINK_STATE_DOWN 2 + __u32 edid_size; + __u8 edid_blob[512]; +}; + +#define VFIO_DEVICE_SET_GFX_EDID _IO(VFIO_TYPE, VFIO_BASE + 17) + /* -------- API for Type1 VFIO IOMMU -------- */ /** From patchwork Thu Sep 13 05:47:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10598721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 975711822 for ; Thu, 13 Sep 2018 05:48:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 887892A1F5 for ; Thu, 13 Sep 2018 05:48:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CA332A1F6; Thu, 13 Sep 2018 05:48:16 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1848C2A1F8 for ; Thu, 13 Sep 2018 05:48:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726818AbeIMKzu (ORCPT ); Thu, 13 Sep 2018 06:55:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42706 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726786AbeIMKzu (ORCPT ); Thu, 13 Sep 2018 06:55:50 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5119E3086266; Thu, 13 Sep 2018 05:47:54 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C84130912F4; Thu, 13 Sep 2018 05:47:47 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id CBD8B2049F; Thu, 13 Sep 2018 07:47:45 +0200 (CEST) From: Gerd Hoffmann To: Kirti Wankhede , intel-gvt-dev@lists.freedesktop.org, Alex Williamson Cc: kvm@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 2/2] vfio: add edid support to mbochs sample driver Date: Thu, 13 Sep 2018 07:47:45 +0200 Message-Id: <20180913054745.6353-3-kraxel@redhat.com> In-Reply-To: <20180913054745.6353-1-kraxel@redhat.com> References: <20180913054745.6353-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 13 Sep 2018 05:47:54 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Gerd Hoffmann --- samples/vfio-mdev/mbochs.c | 54 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 2535c3677c..6331871ff5 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -95,16 +95,24 @@ MODULE_PARM_DESC(mem, "megabytes available to " MBOCHS_NAME " devices"); static const struct mbochs_type { const char *name; u32 mbytes; + u32 max_x; + u32 max_y; } mbochs_types[] = { { .name = MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_1, .mbytes = 4, + .max_x = 800, + .max_y = 600, }, { .name = MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_2, .mbytes = 16, + .max_x = 1920, + .max_y = 1440, }, { .name = MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_3, .mbytes = 64, + .max_x = 0, + .max_y = 0, }, }; @@ -151,6 +159,7 @@ struct mdev_state { u64 memsize; struct page **pages; pgoff_t pagecount; + u8 edid[512]; struct list_head dmabufs; u32 active_id; @@ -346,6 +355,11 @@ static void handle_mmio_read(struct mdev_state *mdev_state, u16 offset, int index; switch (offset) { + case 0x000 ... 0x3ff: /* edid block */ + if (offset + count > sizeof(mdev_state->edid)) + goto unhandled; + memcpy(buf, mdev_state->edid + offset, count); + break; case 0x500 ... 0x515: /* bochs dispi interface */ if (count != 2) goto unhandled; @@ -983,9 +997,13 @@ static int mbochs_get_irq_info(struct mdev_device *mdev, static int mbochs_get_device_info(struct mdev_device *mdev, struct vfio_device_info *dev_info) { + struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + dev_info->flags = VFIO_DEVICE_FLAGS_PCI; dev_info->num_regions = VFIO_PCI_NUM_REGIONS; dev_info->num_irqs = VFIO_PCI_NUM_IRQS; + dev_info->edid_max_x = mdev_state->type->max_x; + dev_info->edid_max_y = mdev_state->type->max_y; return 0; } @@ -1084,7 +1102,7 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, unsigned long arg) { int ret = 0; - unsigned long minsz; + unsigned long minsz, outsz; struct mdev_state *mdev_state; mdev_state = mdev_get_drvdata(mdev); @@ -1095,6 +1113,7 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, struct vfio_device_info info; minsz = offsetofend(struct vfio_device_info, num_irqs); + outsz = offsetofend(struct vfio_device_info, edid_max_y); if (copy_from_user(&info, (void __user *)arg, minsz)) return -EFAULT; @@ -1108,7 +1127,9 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, memcpy(&mdev_state->dev_info, &info, sizeof(info)); - if (copy_to_user((void __user *)arg, &info, minsz)) + if (outsz > info.argsz) + outsz = info.argsz; + if (copy_to_user((void __user *)arg, &info, outsz)) return -EFAULT; return 0; @@ -1194,6 +1215,35 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, return mbochs_get_gfx_dmabuf(mdev, dmabuf_id); } + case VFIO_DEVICE_SET_GFX_EDID: + { + struct vfio_device_set_gfx_edid *edid; + + edid = kmalloc(sizeof(*edid), GFP_KERNEL); + + minsz = offsetofend(struct vfio_device_set_gfx_edid, + edid_blob); + + if (copy_from_user(edid, (void __user *)arg, minsz)) { + kfree(edid); + return -EFAULT; + } + + if (edid->argsz < minsz || + edid->edid_size > sizeof(mdev_state->edid)) { + kfree(edid); + return -EINVAL; + } + + memset(mdev_state->edid, 0, sizeof(mdev_state->edid)); + if (edid->link_state == VFIO_DEVICE_GFX_LINK_STATE_UP) { + memcpy(mdev_state->edid, edid->edid_blob, edid->edid_size); + } + kfree(edid); + + return 0; + } + case VFIO_DEVICE_SET_IRQS: return -EINVAL;