]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/libdrm.git/blobdiff - xf86drmMode.c
radeon: add some new SI pci ids
[glsdk/libdrm.git] / xf86drmMode.c
index da7b4620fa3046f4de224c4fb788d21560bd466c..04fdf1ff04c907dbc5c36995aaf6006948064f3b 100644 (file)
@@ -96,6 +96,10 @@ void drmModeFreeResources(drmModeResPtr ptr)
        if (!ptr)
                return;
 
+       drmFree(ptr->fbs);
+       drmFree(ptr->crtcs);
+       drmFree(ptr->connectors);
+       drmFree(ptr->encoders);
        drmFree(ptr);
 
 }
@@ -267,9 +271,9 @@ int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
        f.height = height;
        f.pixel_format = pixel_format;
        f.flags = flags;
-       memcpy(f.handles, bo_handles, sizeof(bo_handles));
-       memcpy(f.pitches, pitches, sizeof(pitches));
-       memcpy(f.offsets, offsets, sizeof(offsets));
+       memcpy(f.handles, bo_handles, 4 * sizeof(bo_handles[0]));
+       memcpy(f.pitches, pitches, 4 * sizeof(pitches[0]));
+       memcpy(f.offsets, offsets, 4 * sizeof(offsets[0]));
 
        if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB2, &f)))
                return ret;
@@ -571,7 +575,7 @@ drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id)
        if (prop.count_values)
                prop.values_ptr = VOID2U64(drmMalloc(prop.count_values * sizeof(uint64_t)));
 
-       if (prop.count_enum_blobs && (prop.flags & DRM_MODE_PROP_ENUM))
+       if (prop.count_enum_blobs && (prop.flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)))
                prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(struct drm_mode_property_enum)));
 
        if (prop.count_enum_blobs && (prop.flags & DRM_MODE_PROP_BLOB)) {
@@ -593,7 +597,7 @@ drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id)
        r->flags = prop.flags;
        if (prop.count_values)
                r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_values, sizeof(uint64_t));
-       if (prop.flags & DRM_MODE_PROP_ENUM) {
+       if (prop.flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) {
                r->count_enums = prop.count_enum_blobs;
                r->enums = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(struct drm_mode_property_enum));
        } else if (prop.flags & DRM_MODE_PROP_BLOB) {
@@ -898,6 +902,7 @@ retry:
                                 ovr.count_format_types, sizeof(uint32_t));
        if (ovr.count_format_types && !r->formats) {
                drmFree(r->formats);
+               drmFree(r);
                r = 0;
        }
 
@@ -951,6 +956,7 @@ retry:
                                  res.count_planes, sizeof(uint32_t));
        if (res.count_planes && !r->planes) {
                drmFree(r->planes);
+               drmFree(r);
                r = 0;
        }
 
@@ -959,3 +965,95 @@ err_allocs:
 
        return r;
 }
+
+void drmModeFreePlaneResources(drmModePlaneResPtr ptr)
+{
+       if (!ptr)
+               return;
+
+       drmFree(ptr->planes);
+       drmFree(ptr);
+}
+
+drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
+                                                     uint32_t object_id,
+                                                     uint32_t object_type)
+{
+       struct drm_mode_obj_get_properties properties;
+       drmModeObjectPropertiesPtr ret = NULL;
+       uint32_t count;
+
+retry:
+       memset(&properties, 0, sizeof(struct drm_mode_obj_get_properties));
+       properties.obj_id = object_id;
+       properties.obj_type = object_type;
+
+       if (drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties))
+               return 0;
+
+       count = properties.count_props;
+
+       if (count) {
+               properties.props_ptr = VOID2U64(drmMalloc(count *
+                                                         sizeof(uint32_t)));
+               if (!properties.props_ptr)
+                       goto err_allocs;
+               properties.prop_values_ptr = VOID2U64(drmMalloc(count *
+                                                     sizeof(uint64_t)));
+               if (!properties.prop_values_ptr)
+                       goto err_allocs;
+       }
+
+       if (drmIoctl(fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, &properties))
+               goto err_allocs;
+
+       if (count < properties.count_props) {
+               drmFree(U642VOID(properties.props_ptr));
+               drmFree(U642VOID(properties.prop_values_ptr));
+               goto retry;
+       }
+       count = properties.count_props;
+
+       ret = drmMalloc(sizeof(*ret));
+       if (!ret)
+               goto err_allocs;
+
+       ret->count_props = count;
+       ret->props = drmAllocCpy(U642VOID(properties.props_ptr),
+                                count, sizeof(uint32_t));
+       ret->prop_values = drmAllocCpy(U642VOID(properties.prop_values_ptr),
+                                      count, sizeof(uint64_t));
+       if (ret->count_props && (!ret->props || !ret->prop_values)) {
+               drmFree(ret->props);
+               drmFree(ret->prop_values);
+               drmFree(ret);
+               ret = NULL;
+       }
+
+err_allocs:
+       drmFree(U642VOID(properties.props_ptr));
+       drmFree(U642VOID(properties.prop_values_ptr));
+       return ret;
+}
+
+void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr)
+{
+       if (!ptr)
+               return;
+       drmFree(ptr->props);
+       drmFree(ptr->prop_values);
+       drmFree(ptr);
+}
+
+int drmModeObjectSetProperty(int fd, uint32_t object_id, uint32_t object_type,
+                            uint32_t property_id, uint64_t value)
+{
+       struct drm_mode_obj_set_property prop;
+
+       prop.value = value;
+       prop.prop_id = property_id;
+       prop.obj_id = object_id;
+       prop.obj_type = object_type;
+
+       return DRM_IOCTL(fd, DRM_IOCTL_MODE_OBJ_SETPROPERTY, &prop);
+}