linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhao Qiang <qiang.zhao@freescale.com>
To: <scottwood@freescale.com>
Cc: <linux-kernel@vger.kernel.org>, <linuxppc-dev@lists.ozlabs.org>,
	<lauraa@codeaurora.org>, <X.xie@freescale.com>,
	<benh@kernel.crashing.org>, <leoli@freescale.com>,
	<paulus@samba.org>, Zhao Qiang <qiang.zhao@freescale.com>
Subject: [PATCH v12 2/6] genalloc:support allocating specific region
Date: Wed, 14 Oct 2015 15:16:04 +0800	[thread overview]
Message-ID: <1444806968-4627-2-git-send-email-qiang.zhao@freescale.com> (raw)
In-Reply-To: <1444806968-4627-1-git-send-email-qiang.zhao@freescale.com>

Add new algo for genalloc, it reserve a specific region of
memory matching the size requirement (no alignment constraint)

Signed-off-by: Zhao Qiang <qiang.zhao@freescale.com>
---
Changes for v9:
	- reserve a specific region, if the return region
	- is not during the specific region, return fail.
Changes for v10:
	- rename gen_pool_fixed_fit to gen_pool_fixed_alloc
Changes for v11:
	- rename gen_pool_fixed_fit to gen_pool_fixed_alloc
Changes for v12:
	- Nil

 include/linux/genalloc.h | 11 +++++++++++
 lib/genalloc.c           | 30 ++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/include/linux/genalloc.h b/include/linux/genalloc.h
index aaf3dc2..56d5d96 100644
--- a/include/linux/genalloc.h
+++ b/include/linux/genalloc.h
@@ -82,6 +82,13 @@ struct genpool_data_align {
 	int align;		/* alignment by bytes for starting address */
 };
 
+/*
+ *  gen_pool data descriptor for gen_pool_fixed_alloc.
+ */
+struct genpool_data_fixed {
+	unsigned long offset;		/* The offset of the specific region */
+};
+
 extern struct gen_pool *gen_pool_create(int, int);
 extern phys_addr_t gen_pool_virt_to_phys(struct gen_pool *pool, unsigned long);
 extern int gen_pool_add_virt(struct gen_pool *, unsigned long, phys_addr_t,
@@ -121,6 +128,10 @@ extern unsigned long gen_pool_first_fit(unsigned long *map, unsigned long size,
 		unsigned long start, unsigned int nr, void *data,
 		struct gen_pool *pool);
 
+extern unsigned long gen_pool_fixed_alloc(unsigned long *map,
+		unsigned long size, unsigned long start, unsigned int nr,
+		void *data, struct gen_pool *pool);
+
 extern unsigned long gen_pool_first_fit_align(unsigned long *map,
 		unsigned long size, unsigned long start, unsigned int nr,
 		void *data, struct gen_pool *pool);
diff --git a/lib/genalloc.c b/lib/genalloc.c
index b8762b1..1e6fde8 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -554,6 +554,36 @@ unsigned long gen_pool_first_fit_align(unsigned long *map, unsigned long size,
 EXPORT_SYMBOL(gen_pool_first_fit_align);
 
 /**
+ * gen_pool_fixed_alloc - reserve a specific region of
+ * matching the size requirement (no alignment constraint)
+ * @map: The address to base the search on
+ * @size: The bitmap size in bits
+ * @start: The bitnumber to start searching at
+ * @nr: The number of zeroed bits we're looking for
+ * @data: data for alignment
+ * @pool: pool to get order from
+ */
+unsigned long gen_pool_fixed_alloc(unsigned long *map, unsigned long size,
+		unsigned long start, unsigned int nr, void *data,
+		struct gen_pool *pool)
+{
+	struct genpool_data_fixed *fixed_data;
+	int order;
+	unsigned long offset_bit;
+	unsigned long start_bit;
+
+	fixed_data = data;
+	order = pool->min_alloc_order;
+	offset_bit = fixed_data->offset >> order;
+	start_bit = bitmap_find_next_zero_area(map, size,
+			start + offset_bit, nr, 0);
+	if (start_bit != offset_bit)
+		start_bit = size;
+	return start_bit;
+}
+EXPORT_SYMBOL(gen_pool_fixed_alloc);
+
+/**
  * gen_pool_first_fit_order_align - find the first available region
  * of memory matching the size requirement. The region will be aligned
  * to the order of the size specified.
-- 
2.1.0.27.g96db324


  reply	other threads:[~2015-10-14  7:22 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-14  7:16 [PATCH v12 1/6] genalloc:support memory-allocation with bytes-alignment to genalloc Zhao Qiang
2015-10-14  7:16 ` Zhao Qiang [this message]
2015-10-14  7:16 ` [PATCH v12 3/6] CPM/QE: use genalloc to manage CPM/QE muram Zhao Qiang
2015-10-23  2:59   ` Scott Wood
     [not found]     ` <SN1PR0301MB1550906A0C2A2F6BA4EF807D9B260@SN1PR0301MB1550.namprd03.prod.outlook.com>
2015-10-23 20:59       ` Scott Wood
2015-10-26  3:15         ` Zhao Qiang
2015-10-27  4:50           ` Scott Wood
2015-10-14  7:16 ` [PATCH v12 4/6] QE/CPM: move muram management functions to qe_common Zhao Qiang
2015-10-23  3:09   ` Scott Wood
2015-10-23  7:45     ` Zhao Qiang
2015-10-23 20:56       ` Scott Wood
2015-10-26  2:42         ` Zhao Qiang
2015-10-27  4:48           ` Scott Wood
2015-10-27  6:24             ` Zhao Qiang
2015-10-27  6:50               ` Scott Wood
2015-10-27  7:34                 ` Zhao Qiang
2015-10-27  7:36                   ` Scott Wood
2015-10-14  7:16 ` [PATCH v12 5/6] QE: use subsys_initcall to init qe Zhao Qiang
2015-10-23  3:11   ` Scott Wood
2015-10-14  7:16 ` [PATCH v12 6/6] QE: Move QE from arch/powerpc to drivers/soc Zhao Qiang
2015-10-23  3:19   ` Scott Wood
2015-10-23  7:49     ` Zhao Qiang
2015-10-23 20:55       ` Scott Wood
2015-10-26  2:33         ` Zhao Qiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1444806968-4627-2-git-send-email-qiang.zhao@freescale.com \
    --to=qiang.zhao@freescale.com \
    --cc=X.xie@freescale.com \
    --cc=benh@kernel.crashing.org \
    --cc=lauraa@codeaurora.org \
    --cc=leoli@freescale.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=paulus@samba.org \
    --cc=scottwood@freescale.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).