vmware/xorg: Use new stream ioctl
authorJakob Bornecrantz <jakob@vmware.com>
Mon, 14 Dec 2009 21:11:17 +0000 (22:11 +0100)
committerJakob Bornecrantz <jakob@vmware.com>
Mon, 14 Dec 2009 21:12:20 +0000 (22:12 +0100)
src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h
src/gallium/winsys/drm/vmware/xorg/vmw_driver.h
src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c
src/gallium/winsys/drm/vmware/xorg/vmw_video.c

index e05731b..438ce06 100644 (file)
@@ -46,6 +46,8 @@
 #define DRM_VMW_FENCE_WAIT           12
 #define DRM_VMW_OVERLAY              13
 #define DRM_VMW_CURSOR_BYPASS        14
+#define DRM_VMW_CLAIM_STREAM         15
+#define DRM_VMW_UNREF_STREAM         16
 
 /*************************************************************************/
 /**
  * Does the driver support the overlay ioctl.
  */
 
-#define DRM_VMW_PARAM_FIFO_OFFSET    0
-#define DRM_VMW_PARAM_OVERLAY_IOCTL  1
-#define DRM_VMW_PARAM_3D             2
+#define DRM_VMW_PARAM_FIFO_OFFSET      0
+#define DRM_VMW_PARAM_OVERLAY_IOCTL    1
+#define DRM_VMW_PARAM_3D               2
+#define DRM_VMW_PARAM_NUM_STREAMS      3
+#define DRM_VMW_PARAM_NUM_FREE_STREAMS 4
 
 /**
  * struct drm_vmw_getparam_arg
@@ -537,4 +541,31 @@ struct drm_vmw_cursor_bypass_arg {
        int32_t yhot;
 };
 
+/*************************************************************************/
+/**
+ * DRM_VMW_CLAIM_STREAM - Claim a single stream.
+ */
+
+/**
+ * struct drm_vmw_context_arg
+ *
+ * @stream_id: Device unique context ID.
+ *
+ * Output argument to the DRM_VMW_CREATE_CONTEXT Ioctl.
+ * Input argument to the DRM_VMW_UNREF_CONTEXT Ioctl.
+ */
+
+struct drm_vmw_stream_arg {
+       uint32_t stream_id;
+       uint32_t pad64;
+};
+
+/*************************************************************************/
+/**
+ * DRM_VMW_UNREF_STREAM - Unclaim a stream.
+ *
+ * Return a single stream that was claimed by this process. Also makes
+ * sure that the stream has been stopped.
+ */
+
 #endif
index 7265f76..3efe851 100644 (file)
@@ -73,8 +73,6 @@ void vmw_video_stop_all(ScrnInfoPtr pScrn, struct vmw_driver *vmw);
  * vmw_ioctl.c
  */
 
-int vmw_ioctl_supports_overlay(struct vmw_driver *vmw);
-
 int vmw_ioctl_cursor_bypass(struct vmw_driver *vmw, int xhot, int yhot);
 
 struct vmw_dma_buffer * vmw_ioctl_buffer_create(struct vmw_driver *vmw,
@@ -90,5 +88,14 @@ void vmw_ioctl_buffer_unmap(struct vmw_driver *vmw,
 void vmw_ioctl_buffer_destroy(struct vmw_driver *vmw,
                              struct vmw_dma_buffer *buf);
 
+int vmw_ioctl_supports_streams(struct vmw_driver *vmw);
+
+int vmw_ioctl_num_streams(struct vmw_driver *vmw,
+                         uint32_t *ntot, uint32_t *nfree);
+
+int vmw_ioctl_unref_stream(struct vmw_driver *vmw, uint32_t stream_id);
+
+int vmw_ioctl_claim_stream(struct vmw_driver *vmw, uint32_t *out);
+
 
 #endif
index 0d1a0fc..ab2b5fa 100644 (file)
@@ -75,12 +75,12 @@ vmw_ioctl_get_param(struct vmw_driver *vmw, uint32_t param, uint64_t *out)
 }
 
 int
-vmw_ioctl_supports_overlay(struct vmw_driver *vmw)
+vmw_ioctl_supports_streams(struct vmw_driver *vmw)
 {
     uint64_t value;
     int ret;
 
-    ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_OVERLAY_IOCTL, &value);
+    ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_STREAMS, &value);
     if (ret)
        return ret;
 
@@ -88,6 +88,58 @@ vmw_ioctl_supports_overlay(struct vmw_driver *vmw)
 }
 
 int
+vmw_ioctl_num_streams(struct vmw_driver *vmw,
+                     uint32_t *ntot, uint32_t *nfree)
+{
+    uint64_t v1, v2;
+    int ret;
+
+    ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_STREAMS, &v1);
+    if (ret)
+       return ret;
+
+    ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_FREE_STREAMS, &v2);
+    if (ret)
+       return ret;
+
+    *ntot = (uint32_t)v1;
+    *nfree = (uint32_t)v2;
+
+    return 0;
+}
+
+int
+vmw_ioctl_claim_stream(struct vmw_driver *vmw, uint32_t *out)
+{
+    struct drm_vmw_stream_arg s_arg;
+    int ret;
+
+    ret = drmCommandRead(vmw->fd, DRM_VMW_CLAIM_STREAM,
+                        &s_arg, sizeof(s_arg));
+
+    if (ret)
+       return -1;
+
+    *out = s_arg.stream_id;
+    return 0;
+}
+
+int
+vmw_ioctl_unref_stream(struct vmw_driver *vmw, uint32_t stream_id)
+{
+    struct drm_vmw_stream_arg s_arg;
+    int ret;
+
+    memset(&s_arg, 0, sizeof(s_arg));
+    s_arg.stream_id = stream_id;
+
+    ret = drmCommandRead(vmw->fd, DRM_VMW_CLAIM_STREAM,
+                        &s_arg, sizeof(s_arg));
+
+    return 0;
+}
+
+int
 vmw_ioctl_cursor_bypass(struct vmw_driver *vmw, int xhot, int yhot)
 {
     struct drm_vmw_cursor_bypass_arg arg;
index 5674e4f..c0a7ac9 100644 (file)
@@ -273,11 +273,17 @@ vmw_video_init(ScrnInfoPtr pScrn, struct vmw_driver *vmw)
     XF86VideoAdaptorPtr *overlayAdaptors, *newAdaptors = NULL;
     XF86VideoAdaptorPtr newAdaptor = NULL;
     int numAdaptors;
+    unsigned int ntot, nfree;
 
     debug_printf("%s: enter\n", __func__);
 
-    if (vmw_ioctl_supports_overlay(vmw) != 0) {
-        debug_printf("No overlay ioctl support\n");
+    if (vmw_ioctl_num_streams(vmw, &ntot, &nfree) != 0) {
+        debug_printf("No stream ioctl support\n");
+        return FALSE;
+    }
+
+    if (nfree == 0) {
+        debug_printf("No free streams\n");
         return FALSE;
     }
 
@@ -353,6 +359,7 @@ vmw_video_close(ScrnInfoPtr pScrn, struct vmw_driver *vmw)
     for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) {
        /* make sure the port is stoped as well */
        vmw_xv_stop_video(pScrn, &video->port[i], TRUE);
+       vmw_ioctl_unref_stream(vmw, video->port[i].streamId);
     }
 
     /* XXX: I'm sure this function is missing code for turning off Xv */
@@ -448,7 +455,7 @@ vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_driver *vmw)
     adaptor->pPortPrivates = video->port_ptr;
 
     for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) {
-        video->port[i].streamId = i;
+        vmw_ioctl_claim_stream(vmw, &video->port[i].streamId);
         video->port[i].play = vmw_video_port_init;
         video->port[i].flags = SVGA_VIDEO_FLAG_COLORKEY;
         video->port[i].colorKey = VMWARE_VIDEO_COLORKEY;