add getfb ioctl
authorDave Airlie <airlied@linux.ie>
Wed, 11 Apr 2007 22:45:40 +0000 (08:45 +1000)
committerDave Airlie <airlied@linux.ie>
Wed, 11 Apr 2007 22:45:40 +0000 (08:45 +1000)
libdrm/xf86drmMode.c
libdrm/xf86drmMode.h
linux-core/drm_crtc.c
linux-core/drm_crtc.h
linux-core/drm_drv.c
shared-core/drm.h

index 04fb07d..6070ec6 100644 (file)
@@ -215,51 +215,33 @@ int drmModeRmFB(int fd, uint32_t bufferId)
        return ioctl(fd, DRM_IOCTL_MODE_RMFB, bufferId);
 }
 
-#if 0
-int drmModeForceProbe(int fd, uint32_t outputId)
-{
-       /* TODO impl/keep? */
-}
-
-drmModeFrameBufferPtr drmModeGetFrameBuffer(int fd, uint32_t buf)
+drmModeFrameBufferPtr drmModeGetFB(int fd, uint32_t buf)
 {
-//     struct drm_mode_fb_cmd info;
+       struct drm_mode_fb_cmd info;
        drmModeFrameBufferPtr r;
 
-       //      if (ioctl(fd, DRM_IOCTL_MODE_GETFRAMEBUFFER, &info))
-               return 0;
+       info.buffer_id = buf;
+
+       if (ioctl(fd, DRM_IOCTL_MODE_GETFB, &info))
+               return NULL;
 
        if (!(r = drmMalloc(sizeof(*r))))
-               return 0;
+               return NULL;
 
-       /* TODO change to new code
-       r->minWidth  = info.minWidth;
-       r->maxWidth  = info.maxWidth;
-       r->minHeight = info.minHeight;
-       r->maxHeight = info.maxHeight;*/
+       r->buffer_id = info.buffer_id;
+       r->width = info.width;
+       r->height = info.height;
+       r->pitch = info.pitch;
+       r->bpp = info.bpp;
+       r->handle = info.handle;
+       r->depth = info.depth;
 
        return r;
 }
-
-uint32_t drmModeNewFrameBuffer(int fd, uint32_t width, uint32_t height,
-               uint8_t bpp, uint32_t pitch, drmBO *bo)
-{
-       drm_mode_fb_cmd_t f;
-
-       f.handle = bo->handle;
-       f.width  = width;
-       f.height = height;
-       f.pitch  = pitch;
-
-       //      if (ioctl(fd, DRM_IOCTL_MODE_NEWFRAMEBUFFER, &f))
-               return 0;
-
-       return f.bufferId;
-}
-
-int drmModeDesFrameBuffer(int fd, uint32_t bufferId)
+#if 0
+int drmModeForceProbe(int fd, uint32_t outputId)
 {
-  //   return ioctl(fd, DRM_IOCTL_MODE_DESFRAMEBUFFER, bufferId);
+       /* TODO impl/keep? */
 }
 
 #endif
index cdc82f7..6a566c4 100644 (file)
@@ -76,14 +76,7 @@ typedef struct _drmModeRes {
 
 } drmModeRes, *drmModeResPtr;
 
-typedef struct _drmModeFrameBuffer {
-
-       uint32_t width;
-       uint32_t height;
-       uint32_t pitch;
-       uint8_t bpp;
-
-} drmModeFrameBuffer, *drmModeFrameBufferPtr;
+typedef struct drm_mode_fb_cmd drmModeFrameBuffer, *drmModeFrameBufferPtr;
 
 typedef struct _drmModeCrtc {
 
@@ -209,14 +202,14 @@ extern int drmModeForceProbe(int fd, uint32_t outputId);
 /**
  * Retrive information about framebuffer bufferId
  */
-extern drmModeFrameBufferPtr drmModeGetFB(int fd,
-               uint32_t bufferId);
+extern drmModeFrameBufferPtr drmModeGetFB(int fd, uint32_t bufferId);
 
 /**
  * Creates a new framebuffer with an buffer object as its scanout buffer.
  */
 extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
-                       uint8_t bpp, uint32_t pitch, drmBO *bo, uint32_t *buf_id);
+                       uint8_t bpp, uint32_t pitch, drmBO *bo,
+                       uint32_t *buf_id);
 /**
  * Destroies the given framebuffer.
  */
index b349527..d1f3c07 100644 (file)
@@ -1058,3 +1058,33 @@ int drm_mode_rmfb(struct inode *inode, struct file *filp,
        return 0;
 }
 
+int drm_mode_getfb(struct inode *inode, struct file *filp,
+                  unsigned int cmd, unsigned long arg)
+{
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->head->dev;    
+       struct drm_mode_fb_cmd __user *argp = (void __user *)arg;
+       struct drm_mode_fb_cmd r;
+       struct drm_framebuffer *fb;
+
+       if (copy_from_user(&r, argp, sizeof(r)))
+               return -EFAULT;
+
+       fb = idr_find(&dev->mode_config.crtc_idr, r.buffer_id);
+       if (!fb || (r.buffer_id != fb->id)) {
+               DRM_ERROR("invalid framebuffer id\n");
+               return -EINVAL;
+       }
+
+       r.height = fb->height;
+       r.width = fb->width;
+       r.depth = fb->depth;
+       r.bpp = fb->bits_per_pixel;
+       r.handle = fb->bo->base.hash.key;
+       r.pitch = fb->pitch;
+
+       if (copy_to_user(argp, &r, sizeof(r)))
+               return -EFAULT;
+
+       return 0;
+}
index 54c508c..c02dced 100644 (file)
@@ -474,5 +474,7 @@ extern int drm_mode_addfb(struct inode *inode, struct file *filp,
                          unsigned int cmd, unsigned long arg);
 extern int drm_mode_rmfb(struct inode *inode, struct file *filp,
                         unsigned int cmd, unsigned long arg);
+extern int drm_mode_getfb(struct inode *inode, struct file *filp,
+                         unsigned int cmd, unsigned long arg);
 #endif /* __DRM_CRTC_H__ */
 
index b43af32..b7a7ade 100644 (file)
@@ -129,6 +129,7 @@ static drm_ioctl_desc_t drm_ioctls[] = {
        [DRM_IOCTL_NR(DRM_IOCTL_MODE_SETCRTC)] = {drm_mode_setcrtc, DRM_MASTER|DRM_ROOT_ONLY},
        [DRM_IOCTL_NR(DRM_IOCTL_MODE_ADDFB)] = {drm_mode_addfb, DRM_MASTER|DRM_ROOT_ONLY},
        [DRM_IOCTL_NR(DRM_IOCTL_MODE_RMFB)] = {drm_mode_rmfb, DRM_MASTER|DRM_ROOT_ONLY},
+       [DRM_IOCTL_NR(DRM_IOCTL_MODE_GETFB)] = {drm_mode_getfb, DRM_MASTER|DRM_ROOT_ONLY},
 };
 
 #define DRM_CORE_IOCTL_COUNT   ARRAY_SIZE( drm_ioctls )
index 698f851..b5b0aa5 100644 (file)
@@ -1051,6 +1051,7 @@ struct drm_mode_fb_cmd {
 #define DRM_IOCTL_MODE_SETCRTC          DRM_IOWR(0xA3, struct drm_mode_crtc)
 #define DRM_IOCTL_MODE_ADDFB            DRM_IOWR(0xA4, struct drm_mode_fb_cmd)
 #define DRM_IOCTL_MODE_RMFB             DRM_IOWR(0xA5, unsigned int)
+#define DRM_IOCTL_MODE_GETFB             DRM_IOWR(0xA6, struct drm_mode_fb_cmd)
 /*@}*/
 
 /**