From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ben Widawsky Subject: Re: [PATCH 01/18] drm: Introduce drm_mm_create_block() Date: Fri, 26 Oct 2012 14:47:43 -0700 Message-ID: <20121026144743.6d168d86@bwidawsk.net> References: <1350666204-8101-1-git-send-email-chris@chris-wilson.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from shiva.chad-versace.us (209-20-75-48.static.cloud-ips.com [209.20.75.48]) by gabe.freedesktop.org (Postfix) with ESMTP id 99A809E79E for ; Fri, 26 Oct 2012 14:47:26 -0700 (PDT) In-Reply-To: <1350666204-8101-1-git-send-email-chris@chris-wilson.co.uk> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: Chris Wilson Cc: dri-devel@lists.freedestkop.org, Dave Airlie , intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org On Fri, 19 Oct 2012 18:03:07 +0100 Chris Wilson wrote: > To be used later by i915 to preallocate exact blocks of space from the > range manager. > > Signed-off-by: Chris Wilson > Cc: Dave Airlie > Cc: dri-devel@lists.freedestkop.org With bikesheds below addressed or not: Reviewed-by: Ben Widawsky > --- > drivers/gpu/drm/drm_mm.c | 49 > ++++++++++++++++++++++++++++++++++++++++++++++ > include/drm/drm_mm.h | 4 ++++ 2 files changed, 53 insertions(+) > > diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c > index 9bb82f7..5db8c20 100644 > --- a/drivers/gpu/drm/drm_mm.c > +++ b/drivers/gpu/drm/drm_mm.c > @@ -161,6 +161,55 @@ static void drm_mm_insert_helper(struct > drm_mm_node *hole_node, } > } > > +struct drm_mm_node *drm_mm_create_block(struct drm_mm *mm, > + unsigned long start, > + unsigned long size, > + bool atomic) > +{ You could add a best_fit field like some of the other interfaces which will try to find a start == hole_start and end == hole_end. I'd guess this interface won't be called enough to worry about fragmentation too much though. > + struct drm_mm_node *hole, *node; > + unsigned long end = start + size; > + > + list_for_each_entry(hole, &mm->hole_stack, hole_stack) { > + unsigned long hole_start; > + unsigned long hole_end; > + > + BUG_ON(!hole->hole_follows); This isn't bad, but I don't think sticking the bug here is all that helpful in finding where the bug occured, since it wasn't here. WARN is perhaps more useful, but equally unhelpful IMO. > + hole_start = drm_mm_hole_node_start(hole); > + hole_end = drm_mm_hole_node_end(hole); > + > + if (hole_start > start || hole_end < end) > + continue; > + > + node = drm_mm_kmalloc(mm, atomic); > + if (unlikely(node == NULL)) > + return NULL; > + > + node->start = start; > + node->size = size; > + node->mm = mm; > + node->allocated = 1; > + > + INIT_LIST_HEAD(&node->hole_stack); > + list_add(&node->node_list, &hole->node_list); > + > + if (start == hole_start) { > + hole->hole_follows = 0; > + list_del_init(&hole->hole_stack); > + } > + > + node->hole_follows = 0; > + if (end != hole_end) { > + list_add(&node->hole_stack, &mm->hole_stack); > + node->hole_follows = 1; > + } > + > + return node; > + } > + > + return NULL; > +} > +EXPORT_SYMBOL(drm_mm_create_block); > + > struct drm_mm_node *drm_mm_get_block_generic(struct drm_mm_node > *hole_node, unsigned long size, > unsigned alignment, > diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h > index 06d7f79..4020f96 100644 > --- a/include/drm/drm_mm.h > +++ b/include/drm/drm_mm.h > @@ -102,6 +102,10 @@ static inline bool drm_mm_initialized(struct > drm_mm *mm) /* > * Basic range manager support (drm_mm.c) > */ > +extern struct drm_mm_node *drm_mm_create_block(struct drm_mm *mm, > + unsigned long start, > + unsigned long size, > + bool atomic); > extern struct drm_mm_node *drm_mm_get_block_generic(struct > drm_mm_node *node, unsigned long size, > unsigned > alignment, -- Ben Widawsky, Intel Open Source Technology Center