From nobody Mon Feb 9 19:53:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1487106490904913.1685087877571; Tue, 14 Feb 2017 13:08:10 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1EL4YQc021432; Tue, 14 Feb 2017 16:04:34 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1EL4Xj4005058 for ; Tue, 14 Feb 2017 16:04:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id A76B174A1C; Tue, 14 Feb 2017 21:04:33 +0000 (UTC) Received: from localhost (ovpn-116-118.phx2.redhat.com [10.3.116.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1C007239B; Tue, 14 Feb 2017 21:04:32 +0000 (UTC) From: marcandre.lureau@redhat.com To: libvir-list@redhat.com Date: Wed, 15 Feb 2017 01:04:12 +0400 Message-Id: <20170214210413.23142-5-marcandre.lureau@redhat.com> In-Reply-To: <20170214210413.23142-1-marcandre.lureau@redhat.com> References: <20170214210413.23142-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [libvirt] [PATCH 4/5] nodedev: add drm capability X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Marc-Andr=C3=A9 Lureau Add a new 'drm' capability for Direct Rendering Manager (DRM) devices, providing device type information. Teach the udev backend to populate those devices. Signed-off-by: Marc-Andr=C3=A9 Lureau --- docs/formatnode.html.in | 10 +++++++ docs/schemas/nodedev.rng | 14 ++++++++++ src/conf/node_device_conf.c | 44 ++++++++++++++++++++++++++= +++- src/conf/node_device_conf.h | 15 ++++++++++ src/node_device/node_device_driver.c | 1 + src/node_device/node_device_udev.c | 41 ++++++++++++++++++++++++++= ++ tests/nodedevschemadata/drm_renderD129.xml | 10 +++++++ tests/nodedevxml2xmltest.c | 1 + 8 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 tests/nodedevschemadata/drm_renderD129.xml diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in index ecdd1dbcb..a368ffc07 100644 --- a/docs/formatnode.html.in +++ b/docs/formatnode.html.in @@ -314,6 +314,16 @@ and media_label. +
drm
+
Describes a Direct Rendering Manager (DRM) device. + Sub-elements include: +
+
type
+
The type of DRM device. Could be + primary, control or + render.
+
+
diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index 62e29b6cc..0f90a73c8 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -82,6 +82,7 @@ + @@ -540,6 +541,19 @@ =20 + + + drm + + + + primary + control + render + + + + diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 0d1dafcd6..04b63cc93 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -56,12 +56,18 @@ VIR_ENUM_IMPL(virNodeDevCap, VIR_NODE_DEV_CAP_LAST, "storage", "fc_host", "vports", - "scsi_generic") + "scsi_generic", + "drm") =20 VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST, "80203", "80211") =20 +VIR_ENUM_IMPL(virNodeDevDRM, VIR_NODE_DEV_DRM_LAST, + "primary", + "control", + "render") + static int virNodeDevCapsDefParseString(const char *xpath, xmlXPathContextPtr ctxt, @@ -698,6 +704,9 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *de= f) virBufferEscapeString(&buf, "%s\n", data->sg.path); break; + case VIR_NODE_DEV_CAP_DRM: + virBufferEscapeString(&buf, "%s\n", virNodeDevDRM= TypeToString(data->drm.type)); + break; case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_LAST: @@ -799,6 +808,35 @@ virNodeDevCapsDefParseULongLong(const char *xpath, } =20 static int +virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) +{ + xmlNodePtr orignode; + int ret =3D -1; + char *type =3D NULL; + + orignode =3D ctxt->node; + ctxt->node =3D node; + + type =3D virXPathString("string(./type[1])", ctxt); + + if ((data->drm.type =3D virNodeDevDRMTypeFromString(type)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown drm type '%s' for '%s'"), type, def->nam= e); + goto out; + } + + ret =3D 0; + +out: + VIR_FREE(type); + ctxt->node =3D orignode; + return ret; +} + +static int virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, @@ -1689,6 +1727,9 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, case VIR_NODE_DEV_CAP_STORAGE: ret =3D virNodeDevCapStorageParseXML(ctxt, def, node, &caps->data); break; + case VIR_NODE_DEV_CAP_DRM: + ret =3D virNodeDevCapDRMParseXML(ctxt, def, node, &caps->data); + break; case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_SCSI_GENERIC: @@ -2116,6 +2157,7 @@ void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) case VIR_NODE_DEV_CAP_SCSI_GENERIC: VIR_FREE(data->sg.path); break; + case VIR_NODE_DEV_CAP_DRM: case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_LAST: diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index f46e9841a..be7e0e003 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -62,6 +62,7 @@ typedef enum { VIR_NODE_DEV_CAP_FC_HOST, /* FC Host Bus Adapter */ VIR_NODE_DEV_CAP_VPORTS, /* HBA which is capable of vports */ VIR_NODE_DEV_CAP_SCSI_GENERIC, /* SCSI generic device */ + VIR_NODE_DEV_CAP_DRM, /* DRM device */ =20 VIR_NODE_DEV_CAP_LAST } virNodeDevCapType; @@ -93,6 +94,17 @@ typedef enum { VIR_NODE_DEV_CAP_FLAG_PCIE =3D (1 << 2), } virNodeDevPCICapFlags; =20 +typedef enum { + /* Keep in sync with VIR_ENUM_IMPL in node_device_conf.c */ + VIR_NODE_DEV_DRM_PRIMARY, + VIR_NODE_DEV_DRM_CONTROL, + VIR_NODE_DEV_DRM_RENDER, + + VIR_NODE_DEV_DRM_LAST +} virNodeDevDRMType; + +VIR_ENUM_DECL(virNodeDevDRM) + typedef struct _virNodeDevCapData { virNodeDevCapType type; union { @@ -192,6 +204,9 @@ typedef struct _virNodeDevCapData { struct { char *path; } sg; /* SCSI generic device */ + struct { + virNodeDevDRMType type; + } drm; }; } virNodeDevCapData, *virNodeDevCapDataPtr; =20 diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 5238e231d..d04713f5e 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -72,6 +72,7 @@ static int update_caps(virNodeDeviceObjPtr dev) /* all types that (supposedly) don't require any updates * relative to what's in the cache. */ + case VIR_NODE_DEV_CAP_DRM: case VIR_NODE_DEV_CAP_SYSTEM: case VIR_NODE_DEV_CAP_USB_DEV: case VIR_NODE_DEV_CAP_USB_INTERFACE: diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index d7658410a..6a91e0722 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -410,6 +410,42 @@ static int udevProcessPCI(struct udev_device *device, return ret; } =20 +static int drmGetMinorType(int minor) +{ + int type =3D minor >> 6; + + if (minor < 0) + return -1; + + switch (type) { + case VIR_NODE_DEV_DRM_PRIMARY: + case VIR_NODE_DEV_DRM_CONTROL: + case VIR_NODE_DEV_DRM_RENDER: + return type; + default: + return -1; + } +} + +static int udevProcessDRMDevice(struct udev_device *device, + virNodeDeviceDefPtr def) +{ + virNodeDevCapDataPtr data =3D &def->caps->data; + int minor; + + if (udevGenerateDeviceName(device, def, NULL) !=3D 0) + return -1; + + if (udevGetIntProperty(device, "MINOR", &minor, 10) < 0) + return -1; + + if ((minor =3D drmGetMinorType(minor)) =3D=3D -1) + return -1; + + data->drm.type =3D minor; + + return 0; +} =20 static int udevProcessUSBDevice(struct udev_device *device, virNodeDeviceDefPtr def) @@ -971,6 +1007,8 @@ udevGetDeviceType(struct udev_device *device, *type =3D VIR_NODE_DEV_CAP_STORAGE; else if (STREQ(devtype, "wlan")) *type =3D VIR_NODE_DEV_CAP_NET; + else if (STREQ(devtype, "drm_minor")) + *type =3D VIR_NODE_DEV_CAP_DRM; } else { /* PCI devices don't set the DEVTYPE property. */ if (udevHasDeviceProperty(device, "PCI_CLASS")) @@ -1039,6 +1077,9 @@ static int udevGetDeviceDetails(struct udev_device *d= evice, case VIR_NODE_DEV_CAP_SCSI_GENERIC: ret =3D udevProcessSCSIGeneric(device, def); break; + case VIR_NODE_DEV_CAP_DRM: + ret =3D udevProcessDRMDevice(device, def); + break; default: virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown device type %d"), def->caps->data.type); diff --git a/tests/nodedevschemadata/drm_renderD129.xml b/tests/nodedevsche= madata/drm_renderD129.xml new file mode 100644 index 000000000..161481624 --- /dev/null +++ b/tests/nodedevschemadata/drm_renderD129.xml @@ -0,0 +1,10 @@ + + drm_renderD129 + /sys/devices/pci0000:00/0000:00:02.0/drm/renderD129 + /dev/dri/renderD129 + /dev/dri/by-path/pci-0000:00:02.0-render + pci_0000_00_02_0 + + render + + diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index ec96943cb..5e1ae170c 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -100,6 +100,7 @@ mymain(void) DO_TEST("pci_0000_02_10_7_sriov_zero_vfs_max_count"); DO_TEST("pci_0000_02_10_7_sriov_pf_vfs_all"); DO_TEST("pci_0000_02_10_7_sriov_pf_vfs_all_header_type"); + DO_TEST("drm_renderD129"); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.11.0.295.gd7dffce1c.dirty -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list