Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 365607
b: refs/heads/master
c: 9375db0
h: refs/heads/master
i:
  365605: e40d6f0
  365603: 5209c63
  365599: 63b370e
v: v3
  • Loading branch information
Philipp Zabel authored and Linus Torvalds committed Apr 30, 2013
1 parent f1038e4 commit c423775
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 3119b487e03650b51589a86aac33098b7cc2a09e
refs/heads/master: 9375db07adeaeea5f5ea7ca0463a8b371d71ddbb
18 changes: 18 additions & 0 deletions trunk/include/linux/genalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

#ifndef __GENALLOC_H__
#define __GENALLOC_H__

struct device;
struct device_node;

/**
* Allocation callback function type definition
* @map: Pointer to bitmap
Expand Down Expand Up @@ -105,4 +109,18 @@ extern unsigned long gen_pool_first_fit(unsigned long *map, unsigned long size,
extern unsigned long gen_pool_best_fit(unsigned long *map, unsigned long size,
unsigned long start, unsigned int nr, void *data);

extern struct gen_pool *devm_gen_pool_create(struct device *dev,
int min_alloc_order, int nid);
extern struct gen_pool *dev_get_gen_pool(struct device *dev);

#ifdef CONFIG_OF
extern struct gen_pool *of_get_named_gen_pool(struct device_node *np,
const char *propname, int index);
#else
static inline struct gen_pool *of_get_named_gen_pool(struct device_node *np,
const char *propname, int index)
{
return NULL;
}
#endif
#endif /* __GENALLOC_H__ */
81 changes: 81 additions & 0 deletions trunk/lib/genalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <linux/rculist.h>
#include <linux/interrupt.h>
#include <linux/genalloc.h>
#include <linux/of_address.h>
#include <linux/of_device.h>

static int set_bits_ll(unsigned long *addr, unsigned long mask_to_set)
{
Expand Down Expand Up @@ -480,3 +482,82 @@ unsigned long gen_pool_best_fit(unsigned long *map, unsigned long size,
return start_bit;
}
EXPORT_SYMBOL(gen_pool_best_fit);

static void devm_gen_pool_release(struct device *dev, void *res)
{
gen_pool_destroy(*(struct gen_pool **)res);
}

/**
* devm_gen_pool_create - managed gen_pool_create
* @dev: device that provides the gen_pool
* @min_alloc_order: log base 2 of number of bytes each bitmap bit represents
* @nid: node id of the node the pool structure should be allocated on, or -1
*
* Create a new special memory pool that can be used to manage special purpose
* memory not managed by the regular kmalloc/kfree interface. The pool will be
* automatically destroyed by the device management code.
*/
struct gen_pool *devm_gen_pool_create(struct device *dev, int min_alloc_order,
int nid)
{
struct gen_pool **ptr, *pool;

ptr = devres_alloc(devm_gen_pool_release, sizeof(*ptr), GFP_KERNEL);

pool = gen_pool_create(min_alloc_order, nid);
if (pool) {
*ptr = pool;
devres_add(dev, ptr);
} else {
devres_free(ptr);
}

return pool;
}

/**
* dev_get_gen_pool - Obtain the gen_pool (if any) for a device
* @dev: device to retrieve the gen_pool from
* @name: Optional name for the gen_pool, usually NULL
*
* Returns the gen_pool for the device if one is present, or NULL.
*/
struct gen_pool *dev_get_gen_pool(struct device *dev)
{
struct gen_pool **p = devres_find(dev, devm_gen_pool_release, NULL,
NULL);

if (!p)
return NULL;
return *p;
}
EXPORT_SYMBOL_GPL(dev_get_gen_pool);

#ifdef CONFIG_OF
/**
* of_get_named_gen_pool - find a pool by phandle property
* @np: device node
* @propname: property name containing phandle(s)
* @index: index into the phandle array
*
* Returns the pool that contains the chunk starting at the physical
* address of the device tree node pointed at by the phandle property,
* or NULL if not found.
*/
struct gen_pool *of_get_named_gen_pool(struct device_node *np,
const char *propname, int index)
{
struct platform_device *pdev;
struct device_node *np_pool;

np_pool = of_parse_phandle(np, propname, index);
if (!np_pool)
return NULL;
pdev = of_find_device_by_node(np_pool);
if (!pdev)
return NULL;
return dev_get_gen_pool(&pdev->dev);
}
EXPORT_SYMBOL_GPL(of_get_named_gen_pool);
#endif /* CONFIG_OF */

0 comments on commit c423775

Please sign in to comment.