#include <drm.h>
#include <string.h>
+#define U642VOID(x) ((void *)(unsigned long)(x))
+#define VOID2U64(x) ((uint64_t)(unsigned long)(x))
+
/*
* Util functions
*/
return 0;
if (res.count_fbs)
- res.fb_id = drmMalloc(res.count_fbs*sizeof(uint32_t));
+ res.fb_id_ptr = VOID2U64(drmMalloc(res.count_fbs*sizeof(uint32_t)));
if (res.count_crtcs)
- res.crtc_id = drmMalloc(res.count_crtcs*sizeof(uint32_t));
+ res.crtc_id_ptr = VOID2U64(drmMalloc(res.count_crtcs*sizeof(uint32_t)));
if (res.count_outputs)
- res.output_id = drmMalloc(res.count_outputs*sizeof(uint32_t));
+ res.output_id_ptr = VOID2U64(drmMalloc(res.count_outputs*sizeof(uint32_t)));
if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res)) {
r = NULL;
if (!(r = drmMalloc(sizeof(*r))))
return 0;
+ r->min_width = res.min_width;
+ r->max_width = res.max_width;
+ r->min_height = res.min_height;
+ r->max_height = res.max_height;
r->count_fbs = res.count_fbs;
r->count_crtcs = res.count_crtcs;
r->count_outputs = res.count_outputs;
/* TODO we realy should test if these allocs fails. */
- r->fbs = drmAllocCpy(res.fb_id, res.count_fbs, sizeof(uint32_t));
- r->crtcs = drmAllocCpy(res.crtc_id, res.count_crtcs, sizeof(uint32_t));
- r->outputs = drmAllocCpy(res.output_id, res.count_outputs, sizeof(uint32_t));
+ r->fbs = drmAllocCpy(U642VOID(res.fb_id_ptr), res.count_fbs, sizeof(uint32_t));
+ r->crtcs = drmAllocCpy(U642VOID(res.crtc_id_ptr), res.count_crtcs, sizeof(uint32_t));
+ r->outputs = drmAllocCpy(U642VOID(res.output_id_ptr), res.count_outputs, sizeof(uint32_t));
err_allocs:
- drmFree(res.fb_id);
- drmFree(res.crtc_id);
- drmFree(res.output_id);
+ drmFree(U642VOID(res.fb_id_ptr));
+ drmFree(U642VOID(res.crtc_id_ptr));
+ drmFree(U642VOID(res.output_id_ptr));
return r;
}
crtc.y = y;
crtc.crtc_id = crtcId;
crtc.fb_id = bufferId;
- crtc.set_outputs = outputs;
+ crtc.set_outputs_ptr = VOID2U64(outputs);
crtc.count_outputs = count;
if (mode) {
memcpy(&crtc.mode, mode, sizeof(struct drm_mode_modeinfo));
out.count_clones = 0;
out.clones = 0;
out.count_modes = 0;
- out.modes = 0;
+ out.modes_ptr = 0;
out.count_props = 0;
- out.props = NULL;
- out.prop_values = NULL;
+ out.props_ptr = 0;
+ out.prop_values_ptr = 0;
if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out))
return 0;
if (out.count_props) {
- out.props = drmMalloc(out.count_props*sizeof(uint32_t));
- out.prop_values = drmMalloc(out.count_props*sizeof(uint32_t));
+ out.props_ptr = VOID2U64(drmMalloc(out.count_props*sizeof(uint32_t)));
+ out.prop_values_ptr = VOID2U64(drmMalloc(out.count_props*sizeof(uint64_t)));
}
if (out.count_modes)
- out.modes = drmMalloc(out.count_modes*sizeof(struct drm_mode_modeinfo));
+ out.modes_ptr = VOID2U64(drmMalloc(out.count_modes*sizeof(struct drm_mode_modeinfo)));
if (ioctl(fd, DRM_IOCTL_MODE_GETOUTPUT, &out))
goto err_allocs;
r->crtcs = out.crtcs;
r->clones = out.clones;
r->count_props = out.count_props;
- r->props = drmAllocCpy(out.props, out.count_props, sizeof(uint32_t));
- r->prop_values = drmAllocCpy(out.prop_values, out.count_props, sizeof(uint32_t));
- r->modes = drmAllocCpy(out.modes, out.count_modes, sizeof(struct drm_mode_modeinfo));
+ r->props = drmAllocCpy(U642VOID(out.props_ptr), out.count_props, sizeof(uint32_t));
+ r->prop_values = drmAllocCpy(U642VOID(out.prop_values_ptr), out.count_props, sizeof(uint64_t));
+ r->modes = drmAllocCpy(U642VOID(out.modes_ptr), out.count_modes, sizeof(struct drm_mode_modeinfo));
strncpy(r->name, out.name, DRM_OUTPUT_NAME_LEN);
r->name[DRM_OUTPUT_NAME_LEN-1] = 0;
err_allocs:
- drmFree(out.prop_values);
- drmFree(out.props);
- drmFree(out.modes);
+ drmFree(U642VOID(out.prop_values_ptr));
+ drmFree(U642VOID(out.props_ptr));
+ drmFree(U642VOID(out.modes_ptr));
return r;
}
drmModePropertyPtr r;
prop.prop_id = property_id;
- prop.count_enums = 0;
+ prop.count_enum_blobs = 0;
prop.count_values = 0;
prop.flags = 0;
- prop.enums = NULL;
- prop.values = NULL;
+ prop.enum_blob_ptr = 0;
+ prop.values_ptr = 0;
if (ioctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop))
return 0;
if (prop.count_values)
- prop.values = drmMalloc(prop.count_values * sizeof(uint32_t));
+ prop.values_ptr = VOID2U64(drmMalloc(prop.count_values * sizeof(uint64_t)));
- if (prop.count_enums)
- prop.enums = drmMalloc(prop.count_enums * sizeof(struct drm_mode_property_enum));
+ if (prop.count_enum_blobs)
+ prop.enum_blob_ptr = VOID2U64(drmMalloc(prop.count_enum_blobs * sizeof(struct drm_mode_property_enum)));
if (ioctl(fd, DRM_IOCTL_MODE_GETPROPERTY, &prop)) {
r = NULL;
r->prop_id = prop.prop_id;
r->count_values = prop.count_values;
- r->count_enums = prop.count_enums;
-
- r->values = drmAllocCpy(prop.values, prop.count_values, sizeof(uint32_t));
- r->enums = drmAllocCpy(prop.enums, prop.count_enums, sizeof(struct drm_mode_property_enum));
+ r->count_enums = prop.count_enum_blobs;
+ r->flags = prop.flags;
+ r->values = drmAllocCpy(U642VOID(prop.values_ptr), prop.count_values, sizeof(uint64_t));
+ r->enums = drmAllocCpy(U642VOID(prop.enum_blob_ptr), prop.count_enum_blobs, sizeof(struct drm_mode_property_enum));
strncpy(r->name, prop.name, DRM_PROP_NAME_LEN);
r->name[DRM_PROP_NAME_LEN-1] = 0;
err_allocs:
- drmFree(prop.values);
- drmFree(prop.enums);
+ drmFree(U642VOID(prop.values_ptr));
+ drmFree(U642VOID(prop.enum_blob_ptr));
return r;
}
INIT_LIST_HEAD(&dev->mode_config.crtc_list);
INIT_LIST_HEAD(&dev->mode_config.output_list);
INIT_LIST_HEAD(&dev->mode_config.property_list);
+ INIT_LIST_HEAD(&dev->mode_config.property_blob_list);
idr_init(&dev->mode_config.crtc_idr);
+ dev->mode_config.edid_property = drm_property_create(dev,
+ DRM_MODE_PROP_BLOB | DRM_MODE_PROP_IMMUTABLE,
+ "EDID", 0);
}
EXPORT_SYMBOL(drm_mode_config_init);
if (crtc_info->x != crtc->x || crtc_info->y != crtc->y)
changed = true;
- if (new_mode && (crtc->mode.mode_id != new_mode->mode_id))
+ if (new_mode && !drm_mode_equal(new_mode, &crtc->mode))
changed = true;
list_for_each_entry(output, &dev->mode_config.output_list, head) {
int crtc_count = 0;
int fb_count = 0;
int copied = 0;
+ uint32_t __user *fb_id;
+ uint32_t __user *crtc_id;
+ uint32_t __user *output_id;
mutex_lock(&dev->mode_config.mutex);
list_for_each(lh, &dev->mode_config.output_list)
output_count++;
+ card_res->max_height = dev->mode_config.max_height;
+ card_res->min_height = dev->mode_config.min_height;
+ card_res->max_width = dev->mode_config.max_width;
+ card_res->min_width = dev->mode_config.min_width;
+
/* handle this in 4 parts */
/* FBs */
if (card_res->count_fbs >= fb_count) {
copied = 0;
+ fb_id = (uint32_t *)(unsigned long)card_res->fb_id_ptr;
list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
- if (put_user(fb->id, card_res->fb_id + copied)) {
+ if (put_user(fb->id, fb_id + copied)) {
ret = -EFAULT;
goto out;
}
/* CRTCs */
if (card_res->count_crtcs >= crtc_count) {
copied = 0;
+ crtc_id = (uint32_t *)(unsigned long)card_res->crtc_id_ptr;
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head){
DRM_DEBUG("CRTC ID is %d\n", crtc->id);
- if (put_user(crtc->id, card_res->crtc_id + copied)) {
+ if (put_user(crtc->id, crtc_id + copied)) {
ret = -EFAULT;
goto out;
}
/* Outputs */
if (card_res->count_outputs >= output_count) {
copied = 0;
+ output_id = (uint32_t *)(unsigned long)card_res->output_id_ptr;
list_for_each_entry(output, &dev->mode_config.output_list,
head) {
DRM_DEBUG("OUTPUT ID is %d\n", output->id);
- if (put_user(output->id, card_res->output_id + copied)) {
+ if (put_user(output->id, output_id + copied)) {
ret = -EFAULT;
goto out;
}
DRM_DEBUG("Counted %d %d\n", card_res->count_crtcs,
card_res->count_outputs);
-
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
int copied = 0;
int i;
struct drm_mode_modeinfo u_mode;
+ struct drm_mode_modeinfo __user *mode_ptr;
+ uint32_t __user *prop_ptr;
+ uint64_t __user *prop_values;
memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
if ((out_resp->count_modes >= mode_count) && mode_count) {
copied = 0;
+ mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
list_for_each_entry(mode, &output->modes, head) {
drm_crtc_convert_to_umode(&u_mode, mode);
- if (copy_to_user(out_resp->modes + copied,
+ if (copy_to_user(mode_ptr + copied,
&u_mode, sizeof(u_mode))) {
ret = -EFAULT;
goto out;
if ((out_resp->count_props >= props_count) && props_count) {
copied = 0;
+ prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
+ prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
for (i = 0; i < DRM_OUTPUT_MAX_PROPERTY; i++) {
if (output->property_ids[i] != 0) {
- if (put_user(output->property_ids[i], out_resp->props + copied)) {
+ if (put_user(output->property_ids[i], prop_ptr + copied)) {
ret = -EFAULT;
goto out;
}
- if (put_user(output->property_values[i], out_resp->prop_values + copied)) {
+ if (put_user(output->property_values[i], prop_values + copied)) {
ret = -EFAULT;
goto out;
}
struct drm_crtc *crtc;
struct drm_output **output_set = NULL, *output;
struct drm_framebuffer *fb = NULL;
- struct drm_display_mode mode;
- int mode_valid = 0;
+ struct drm_display_mode *mode = NULL;
int ret = 0;
int i;
+ uint32_t __user *set_outputs_ptr;
mutex_lock(&dev->mode_config.mutex);
crtc = idr_find(&dev->mode_config.crtc_idr, crtc_req->crtc_id);
}
}
- mode_valid = 1;
- drm_crtc_convert_umode(&mode, &crtc_req->mode);
- } else
- mode_valid = 0;
+ mode = drm_mode_create(dev);
+ drm_crtc_convert_umode(mode, &crtc_req->mode);
+ }
- if (crtc_req->count_outputs == 0 && mode_valid) {
+ if (crtc_req->count_outputs == 0 && mode) {
DRM_DEBUG("Count outputs is 0 but mode set\n");
ret = -EINVAL;
goto out;
}
- if (crtc_req->count_outputs > 0 && !mode_valid && !fb) {
+ if (crtc_req->count_outputs > 0 && !mode && !fb) {
DRM_DEBUG("Count outputs is %d but no mode or fb set\n", crtc_req->count_outputs);
ret = -EINVAL;
goto out;
}
for (i = 0; i < crtc_req->count_outputs; i++) {
- if (get_user(out_id, &crtc_req->set_outputs[i])) {
+ set_outputs_ptr = (uint32_t *)(unsigned long)crtc_req->set_outputs_ptr;
+ if (get_user(out_id, &set_outputs_ptr[i])) {
ret = -EFAULT;
goto out;
}
}
}
- if (mode_valid) {
- ret = drm_crtc_set_config(crtc, crtc_req, &mode, output_set, fb);
- } else {
- ret = drm_crtc_set_config(crtc, crtc_req, NULL, output_set, fb);
- }
+ ret = drm_crtc_set_config(crtc, crtc_req, mode, output_set, fb);
out:
mutex_unlock(&dev->mode_config.mutex);
property = kzalloc(sizeof(struct drm_output), GFP_KERNEL);
if (!property)
return NULL;
-
- property->values = kzalloc(sizeof(uint32_t)*num_values, GFP_KERNEL);
- if (!property->values)
- goto fail;
+
+ if (num_values) {
+ property->values = kzalloc(sizeof(uint64_t)*num_values, GFP_KERNEL);
+ if (!property->values)
+ goto fail;
+ }
property->id = drm_idr_get(dev, property);
property->flags = flags;
property->num_values = num_values;
- INIT_LIST_HEAD(&property->enum_list);
+ INIT_LIST_HEAD(&property->enum_blob_list);
if (name)
strncpy(property->name, name, DRM_PROP_NAME_LEN);
EXPORT_SYMBOL(drm_property_create);
int drm_property_add_enum(struct drm_property *property, int index,
- uint32_t value, const char *name)
+ uint64_t value, const char *name)
{
struct drm_property_enum *prop_enum;
if (!(property->flags & DRM_MODE_PROP_ENUM))
return -EINVAL;
- if (!list_empty(&property->enum_list)) {
- list_for_each_entry(prop_enum, &property->enum_list, head) {
+ if (!list_empty(&property->enum_blob_list)) {
+ list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
if (prop_enum->value == value) {
strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
prop_enum->value = value;
property->values[index] = value;
- list_add_tail(&prop_enum->head, &property->enum_list);
+ list_add_tail(&prop_enum->head, &property->enum_blob_list);
return 0;
}
EXPORT_SYMBOL(drm_property_add_enum);
{
struct drm_property_enum *prop_enum, *pt;
- list_for_each_entry_safe(prop_enum, pt, &property->enum_list, head) {
+ list_for_each_entry_safe(prop_enum, pt, &property->enum_blob_list, head) {
list_del(&prop_enum->head);
kfree(prop_enum);
}
- kfree(property->values);
+ if (property->num_values)
+ kfree(property->values);
drm_idr_put(dev, property->id);
list_del(&property->head);
kfree(property);
int drm_output_attach_property(struct drm_output *output,
- struct drm_property *property, int init_val)
+ struct drm_property *property, uint64_t init_val)
{
int i;
struct drm_mode_get_property *out_resp = data;
struct drm_property *property;
int enum_count = 0;
+ int blob_count = 0;
int value_count = 0;
int ret = 0, i;
int copied;
struct drm_property_enum *prop_enum;
+ struct drm_property_enum __user *enum_ptr;
+ struct drm_property_blob *prop_blob;
+ uint64_t __user *values_ptr;
mutex_lock(&dev->mode_config.mutex);
property = idr_find(&dev->mode_config.crtc_idr, out_resp->prop_id);
goto done;
}
-
- list_for_each_entry(prop_enum, &property->enum_list, head)
- enum_count++;
+ if (property->flags & DRM_MODE_PROP_ENUM) {
+ list_for_each_entry(prop_enum, &property->enum_blob_list, head)
+ enum_count++;
+ } else if (property->flags & DRM_MODE_PROP_BLOB) {
+ list_for_each_entry(prop_blob, &property->enum_blob_list, head)
+ blob_count++;
+ }
value_count = property->num_values;
out_resp->flags = property->flags;
if ((out_resp->count_values >= value_count) && value_count) {
+ values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
for (i = 0; i < value_count; i++) {
- if (put_user(property->values[i], out_resp->values + i)) {
+ if (put_user(property->values[i], values_ptr + i)) {
ret = -EFAULT;
goto done;
}
}
out_resp->count_values = value_count;
- if ((out_resp->count_enums >= enum_count) && enum_count) {
+ if ((out_resp->count_enum_blobs >= enum_count) && enum_count && (property->flags & DRM_MODE_PROP_ENUM)) {
+ copied = 0;
+ enum_ptr = (struct drm_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
+ list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
+ if (put_user(prop_enum->value, &enum_ptr[copied].value)) {
+ ret = -EFAULT;
+ goto done;
+ }
+
+ if (copy_to_user(&enum_ptr[copied].name,
+ prop_enum->name, DRM_PROP_NAME_LEN)) {
+ ret = -EFAULT;
+ goto done;
+ }
+ copied++;
+ }
+ }
+ out_resp->count_enum_blobs = enum_count;
+
+#if 0
+ if ((out_resp->count_blobs >= enum_count) && blob_count && (property->flags & DRM_MODE_PROP_BLOB)) {
copied = 0;
- list_for_each_entry(prop_enum, &property->enum_list, head) {
- if (put_user(prop_enum->value, &out_resp->enums[copied].value)) {
+ list_for_each_entry(prop_blob, &property->enum_list, head) {
+ if (put_user(prop_enum->value, &out_resp->blobs[copied].value)) {
ret = -EFAULT;
goto done;
}
}
}
out_resp->count_enums = enum_count;
-
+#endif
done:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
+
+static int drm_property_create_blob(struct drm_device *dev, int length,
+ void *data)
+{
+ struct drm_property_blob *blob;
+
+ if (!length || !data)
+ return -EINVAL;
+
+ blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
+ if (!blob)
+ return -EINVAL;
+
+ blob->data = (void *)((char *)blob + sizeof(struct drm_property_blob));
+ blob->length = length;
+
+ memcpy(blob->data, data, length);
+
+ blob->id = drm_idr_get(dev, blob);
+
+ list_add_tail(&blob->head, &dev->mode_config.property_blob_list);
+ return blob->id;
+}
+
+static void drm_property_destroy_blob(struct drm_device *dev,
+ struct drm_property_blob *blob)
+{
+ drm_idr_put(dev, blob->id);
+ list_del(&blob->head);
+ kfree(blob);
+}
};
struct drm_mode_card_res {
-
+ uint64_t fb_id_ptr;
+ uint64_t crtc_id_ptr;
+ uint64_t output_id_ptr;
int count_fbs;
- unsigned int __user *fb_id;
-
int count_crtcs;
- unsigned int __user *crtc_id;
-
int count_outputs;
- unsigned int __user *output_id;
+ int min_width, max_width;
+ int min_height, max_height;
};
struct drm_mode_crtc {
+ uint64_t set_outputs_ptr;
+
unsigned int crtc_id; /**< Id */
unsigned int fb_id; /**< Id of framebuffer */
int count_possibles;
unsigned int possibles; /**< Outputs that can be connected */
-
- unsigned int __user *set_outputs; /**< Outputs to be connected */
-
int gamma_size;
int mode_valid;
struct drm_mode_modeinfo mode;
struct drm_mode_get_output {
+ uint64_t modes_ptr;
+ uint64_t props_ptr;
+ uint64_t prop_values_ptr;
+
+ int count_modes;
+ int count_props;
unsigned int output; /**< Id */
unsigned int crtc; /**< Id of crtc */
unsigned char name[DRM_OUTPUT_NAME_LEN];
unsigned int connection;
unsigned int mm_width, mm_height; /**< HxW in millimeters */
unsigned int subpixel;
-
int count_crtcs;
- unsigned int crtcs; /**< possible crtc to connect to */
-
int count_clones;
+ unsigned int crtcs; /**< possible crtc to connect to */
unsigned int clones; /**< list of clones */
-
- int count_modes;
- struct drm_mode_modeinfo *modes;
-
- int count_props;
- unsigned int __user *props;
- unsigned int __user *prop_values;
};
#define DRM_MODE_PROP_PENDING (1<<0)
#define DRM_MODE_PROP_RANGE (1<<1)
#define DRM_MODE_PROP_IMMUTABLE (1<<2)
#define DRM_MODE_PROP_ENUM (1<<3) // enumerated type with text strings
+#define DRM_MODE_PROP_BLOB (1<<4)
struct drm_mode_property_enum {
- uint32_t value;
+ uint64_t value;
unsigned char name[DRM_PROP_NAME_LEN];
};
+
+struct drm_mode_property_blob {
+ uint32_t length;
+};
struct drm_mode_get_property {
+ uint64_t values_ptr;
+ uint64_t enum_blob_ptr;
unsigned int prop_id;
unsigned int flags;
unsigned char name[DRM_PROP_NAME_LEN];
int count_values;
- uint32_t __user *values;
-
- int count_enums;
- struct drm_mode_property_enum *enums;
+ int count_enum_blobs;
};
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)
+#define DRM_IOCTL_MODE_GETPROPBLOB DRM_IOWR(0xA8, struct drm_mode_get_propblob)
#define DRM_IOCTL_MODE_ATTACHMODE DRM_IOWR(0xA9, struct drm_mode_mode_cmd)
#define DRM_IOCTL_MODE_DETACHMODE DRM_IOWR(0xAA, struct drm_mode_mode_cmd)