From patchwork Wed Dec 12 16:15:39 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: 1868171 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 8EC8E3FC81 for ; Wed, 12 Dec 2012 16:43:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 80FB2E61DE for ; Wed, 12 Dec 2012 08:43:32 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [143.182.124.37]) by gabe.freedesktop.org (Postfix) with ESMTP id 541CEE6364; Wed, 12 Dec 2012 08:17:41 -0800 (PST) Received: from azsmga002.ch.intel.com ([10.2.17.35]) by azsmga102.ch.intel.com with ESMTP; 12 Dec 2012 08:17:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.84,267,1355126400"; d="scan'208";a="179977052" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.168]) by AZSMGA002.ch.intel.com with SMTP; 12 Dec 2012 08:17:38 -0800 Received: by stinkbox (sSMTP sendmail emulation); Wed, 12 Dec 2012 18:17:38 +0200 From: ville.syrjala@linux.intel.com To: dri-devel@lists.freedesktop.org Subject: [PATCH 12/81] drm: Make blobs resizeable Date: Wed, 12 Dec 2012 18:15:39 +0200 Message-Id: <1355329008-31459-13-git-send-email-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1355329008-31459-1-git-send-email-ville.syrjala@linux.intel.com> References: <1355329008-31459-1-git-send-email-ville.syrjala@linux.intel.com> MIME-Version: 1.0 Cc: intel-gfx@lists.freedesktop.org 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 3709f8c..aeda9f4 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -2926,6 +2926,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); @@ -3115,16 +3118,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; @@ -3134,18 +3145,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); @@ -3204,7 +3237,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); if (!connector->edid_blob_ptr) return -EINVAL; diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 23f2f37..5b8b1b7 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[]; }; @@ -972,7 +973,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,