From patchwork Thu Oct 25 18:05:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 1646421 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id CECC83FE1C for ; Thu, 25 Oct 2012 18:18:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9BA27A0A3E for ; Thu, 25 Oct 2012 11:18:18 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 36E70A0A27 for ; Thu, 25 Oct 2012 11:06:47 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 25 Oct 2012 11:06:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.80,648,1344236400"; d="scan'208";a="210833198" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.168]) by orsmga001.jf.intel.com with SMTP; 25 Oct 2012 11:06:44 -0700 Received: by stinkbox (sSMTP sendmail emulation); Thu, 25 Oct 2012 21:06:44 +0300 From: ville.syrjala@linux.intel.com To: dri-devel@lists.freedesktop.org Subject: [PATCH 15/51] drm: Make blobs resizeable Date: Thu, 25 Oct 2012 21:05:18 +0300 Message-Id: <1351188354-24233-16-git-send-email-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1351188354-24233-1-git-send-email-ville.syrjala@linux.intel.com> References: <1351188354-24233-1-git-send-email-ville.syrjala@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org From: Ville Syrjälä When first allocated blobs can be given a maximum size for which memory is allocated. Later the data inside the blob can be replaced, assuming that the maximum size is not exceeded. Signed-off-by: Ville Syrjälä --- drivers/gpu/drm/drm_crtc.c | 45 ++++++++++++++++++++++++++++++++++++++----- include/drm/drm_crtc.h | 8 ++++++- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 177bc73..7a6ed7d 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -2922,6 +2922,9 @@ void drm_property_destroy(struct drm_device *dev, struct drm_property *property) { struct drm_property_enum *prop_enum, *pt; + if (!property) + return; + list_for_each_entry_safe(prop_enum, pt, &property->enum_blob_list, head) { list_del(&prop_enum->head); kfree(prop_enum); @@ -3111,16 +3114,24 @@ done: return ret; } -struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int length, - void *data) +struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, + unsigned int length, + unsigned int max_length, + const void *data) { struct drm_property_blob *blob; int ret; - if (!length || !data) + if (!!length != !!data) return NULL; - blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL); + if (max_length < length) + max_length = length; + + if (max_length == 0) + return NULL; + + blob = kzalloc(sizeof(struct drm_property_blob)+max_length, GFP_KERNEL); if (!blob) return NULL; @@ -3130,18 +3141,40 @@ struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int l return NULL; } + blob->max_length = max_length; blob->length = length; - memcpy(blob->data, data, length); + if (length) + memcpy(blob->data, data, length); list_add_tail(&blob->head, &dev->mode_config.property_blob_list); return blob; } EXPORT_SYMBOL(drm_property_create_blob); +int drm_property_blob_replace_data(struct drm_property_blob *blob, + unsigned int length, const void *data) +{ + if (!!length != !!data) + return -EINVAL; + + if (length > blob->max_length) + return -ENOSPC; + + blob->length = length; + if (length) + memcpy(blob->data, data, length); + + return 0; +} +EXPORT_SYMBOL(drm_property_blob_replace_data); + void drm_property_destroy_blob(struct drm_device *dev, struct drm_property_blob *blob) { + if (!blob) + return; + drm_mode_object_put(dev, &blob->base); list_del(&blob->head); kfree(blob); @@ -3200,7 +3233,7 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector, size = EDID_LENGTH * (1 + edid->extensions); connector->edid_blob_ptr = drm_property_create_blob(connector->dev, - size, edid); + size, 0, edid); ret = drm_connector_property_set_value(connector, dev->mode_config.edid_property, diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 4830b47..710f490 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -276,6 +276,7 @@ struct drm_property_blob { struct drm_mode_object base; struct list_head head; unsigned int length; + unsigned int max_length; unsigned char data[]; }; @@ -971,7 +972,12 @@ struct drm_property *drm_property_create_range(struct drm_device *dev, int flags uint64_t min, uint64_t max); extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property); extern struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, - int length, void *data); + unsigned int level, + unsigned int max_length, + const void *data); +extern int drm_property_blob_replace_data(struct drm_property_blob *blob, + unsigned int length, + const void *data); extern void drm_property_destroy_blob(struct drm_device *dev, struct drm_property_blob *blob); extern int drm_property_add_enum(struct drm_property *property, int index,