Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 5056 → Rev 4292

/drivers/ddk/linux/kasprintf.c
File deleted
/drivers/ddk/linux/hdmi.c
File deleted
/drivers/ddk/linux/mutex.c
File deleted
/drivers/ddk/linux/interval_tree.c
File deleted
/drivers/ddk/linux/scatterlist.c
File deleted
/drivers/ddk/linux/idr.c
18,6 → 18,12
* pointer or what ever, we treat it as a (void *). You can pass this
* id to a user for him to pass back at a later time. You then pass
* that id to this code and it returns your pointer.
 
* You can release ids at any time. When all ids are released, most of
* the memory is returned (we keep MAX_IDR_FREE) in a local pool so we
* don't need to go to the memory "store" during an id allocate, just
* so you don't need to be too concerned about locking and conflicts
* with the slab allocator.
*/
 
#include <linux/kernel.h>
130,7 → 136,7
 
static inline void free_layer(struct idr *idr, struct idr_layer *p)
{
if (idr->hint == p)
if (idr->hint && idr->hint == p)
RCU_INIT_POINTER(idr->hint, NULL);
idr_layer_rcu_free(&p->rcu_head);
}
175,7 → 181,7
}
}
 
static int __idr_pre_get(struct idr *idp, gfp_t gfp_mask)
int __idr_pre_get(struct idr *idp, gfp_t gfp_mask)
{
while (idp->id_free_cnt < MAX_IDR_FREE) {
struct idr_layer *new;
186,6 → 192,7
}
return 1;
}
EXPORT_SYMBOL(__idr_pre_get);
 
/**
* sub_alloc - try to allocate an id without growing the tree depth
228,7 → 235,7
id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
 
/* if already at the top layer, we need to grow */
if (id > idr_max(idp->layers)) {
if (id >= 1 << (idp->layers * IDR_BITS)) {
*starting_id = id;
return -EAGAIN;
}
352,7 → 359,21
idr_mark_full(pa, id);
}
 
int __idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id)
{
struct idr_layer *pa[MAX_IDR_LEVEL + 1];
int rv;
 
rv = idr_get_empty_slot(idp, starting_id, pa, 0, idp);
if (rv < 0)
return rv == -ENOMEM ? -EAGAIN : rv;
 
idr_fill_slot(idp, ptr, rv, pa);
*id = rv;
return 0;
}
EXPORT_SYMBOL(__idr_get_new_above);
 
/**
* idr_preload - preload for idr_alloc()
* @gfp_mask: allocation mask to use for preloading
529,11 → 550,6
if (id < 0)
return;
 
if (id > idr_max(idp->layers)) {
idr_remove_warning(id);
return;
}
 
sub_remove(idp, (idp->layers - 1) * IDR_BITS, id);
if (idp->top && idp->top->count == 1 && (idp->layers > 1) &&
idp->top->ary[0]) {
551,10 → 567,20
bitmap_clear(to_free->bitmap, 0, IDR_SIZE);
free_layer(idp, to_free);
}
while (idp->id_free_cnt >= MAX_IDR_FREE) {
p = get_from_free_list(idp);
/*
* Note: we don't call the rcu callback here, since the only
* layers that fall into the freelist are those that have been
* preallocated.
*/
kfree(p);
}
return;
}
EXPORT_SYMBOL(idr_remove);
 
static void __idr_remove_all(struct idr *idp)
void __idr_remove_all(struct idr *idp)
{
int n, id, max;
int bt_mask;
563,17 → 589,16
struct idr_layer **paa = &pa[0];
 
n = idp->layers * IDR_BITS;
*paa = idp->top;
p = idp->top;
rcu_assign_pointer(idp->top, NULL);
max = idr_max(idp->layers);
 
id = 0;
while (id >= 0 && id <= max) {
p = *paa;
while (n > IDR_BITS && p) {
n -= IDR_BITS;
*paa++ = p;
p = p->ary[(id >> n) & IDR_MASK];
*++paa = p;
}
 
bt_mask = id;
580,14 → 605,15
id += 1 << n;
/* Get the highest bit that the above add changed from 0->1. */
while (n < fls(id ^ bt_mask)) {
if (*paa)
free_layer(idp, *paa);
if (p)
free_layer(idp, p);
n += IDR_BITS;
--paa;
p = *--paa;
}
}
idp->layers = 0;
}
EXPORT_SYMBOL(__idr_remove_all);
 
/**
* idr_destroy - release all cached layers within an idr tree
666,16 → 692,15
struct idr_layer **paa = &pa[0];
 
n = idp->layers * IDR_BITS;
*paa = rcu_dereference_raw(idp->top);
p = rcu_dereference_raw(idp->top);
max = idr_max(idp->layers);
 
id = 0;
while (id >= 0 && id <= max) {
p = *paa;
while (n > 0 && p) {
n -= IDR_BITS;
*paa++ = p;
p = rcu_dereference_raw(p->ary[(id >> n) & IDR_MASK]);
*++paa = p;
}
 
if (p) {
687,7 → 712,7
id += 1 << n;
while (n < fls(id)) {
n += IDR_BITS;
--paa;
p = *--paa;
}
}
 
715,7 → 740,7
int n, max;
 
/* find first ent */
p = *paa = rcu_dereference_raw(idp->top);
p = rcu_dereference_raw(idp->top);
if (!p)
return NULL;
n = (p->layer + 1) * IDR_BITS;
722,11 → 747,10
max = idr_max(p->layer + 1);
 
while (id >= 0 && id <= max) {
p = *paa;
while (n > 0 && p) {
n -= IDR_BITS;
*paa++ = p;
p = rcu_dereference_raw(p->ary[(id >> n) & IDR_MASK]);
*++paa = p;
}
 
if (p) {
744,7 → 768,7
id = round_up(id + 1, 1 << n);
while (n < fls(id)) {
n += IDR_BITS;
--paa;
p = *--paa;
}
}
return NULL;
774,12 → 798,14
 
p = idp->top;
if (!p)
return ERR_PTR(-ENOENT);
return ERR_PTR(-EINVAL);
 
if (id > idr_max(p->layer + 1))
return ERR_PTR(-ENOENT);
n = (p->layer+1) * IDR_BITS;
 
n = p->layer * IDR_BITS;
if (id >= (1 << n))
return ERR_PTR(-EINVAL);
 
n -= IDR_BITS;
while ((n > 0) && p) {
p = p->ary[(id >> n) & IDR_MASK];
n -= IDR_BITS;
816,17 → 842,7
}
EXPORT_SYMBOL(idr_init);
 
static int idr_has_entry(int id, void *p, void *data)
{
return 1;
}
 
bool idr_is_empty(struct idr *idp)
{
return !idr_for_each(idp, idr_has_entry, NULL);
}
EXPORT_SYMBOL(idr_is_empty);
 
/**
* DOC: IDA description
* IDA - IDR based ID allocator
990,9 → 1006,6
int n;
struct ida_bitmap *bitmap;
 
if (idr_id > idr_max(ida->idr.layers))
goto err;
 
/* clear full bits while looking up the leaf idr_layer */
while ((shift > 0) && p) {
n = (idr_id >> shift) & IDR_MASK;
1008,7 → 1021,7
__clear_bit(n, p->bitmap);
 
bitmap = (void *)p->ary[n];
if (!bitmap || !test_bit(offset, bitmap->bitmap))
if (!test_bit(offset, bitmap->bitmap))
goto err;
 
/* update bitmap and remove it if empty */
1231,17 → 1244,3
return (res + (res >> 16)) & 0x000000FF;
}
 
unsigned long hweight64(__u64 w)
{
#if BITS_PER_LONG == 32
return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
#elif BITS_PER_LONG == 64
__u64 res = w - ((w >> 1) & 0x5555555555555555ul);
res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
res = res + (res >> 8);
res = res + (res >> 16);
return (res + (res >> 32)) & 0x00000000000000FFul;
#endif
}
 
/drivers/ddk/linux/bitmap.c
2,7 → 2,7
* lib/bitmap.c
* Helper functions for bitmap.h.
*
* This source code is licensed under the GNU General Public License,
* Tlhis source code is licensed under the GNU General Public License,
* Version 2. See the file COPYING for more details.
*/
#include <syscall.h>
41,9 → 41,9
* for the best explanations of this ordering.
*/
 
int __bitmap_empty(const unsigned long *bitmap, unsigned int bits)
int __bitmap_empty(const unsigned long *bitmap, int bits)
{
unsigned int k, lim = bits/BITS_PER_LONG;
int k, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; ++k)
if (bitmap[k])
return 0;
56,9 → 56,9
}
EXPORT_SYMBOL(__bitmap_empty);
 
int __bitmap_full(const unsigned long *bitmap, unsigned int bits)
int __bitmap_full(const unsigned long *bitmap, int bits)
{
unsigned int k, lim = bits/BITS_PER_LONG;
int k, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; ++k)
if (~bitmap[k])
return 0;
72,9 → 72,9
EXPORT_SYMBOL(__bitmap_full);
 
int __bitmap_equal(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
const unsigned long *bitmap2, int bits)
{
unsigned int k, lim = bits/BITS_PER_LONG;
int k, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; ++k)
if (bitmap1[k] != bitmap2[k])
return 0;
87,14 → 87,14
}
EXPORT_SYMBOL(__bitmap_equal);
 
void __bitmap_complement(unsigned long *dst, const unsigned long *src, unsigned int bits)
void __bitmap_complement(unsigned long *dst, const unsigned long *src, int bits)
{
unsigned int k, lim = bits/BITS_PER_LONG;
int k, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; ++k)
dst[k] = ~src[k];
 
if (bits % BITS_PER_LONG)
dst[k] = ~src[k];
dst[k] = ~src[k] & BITMAP_LAST_WORD_MASK(bits);
}
EXPORT_SYMBOL(__bitmap_complement);
 
183,26 → 183,23
EXPORT_SYMBOL(__bitmap_shift_left);
 
int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
const unsigned long *bitmap2, int bits)
{
unsigned int k;
unsigned int lim = bits/BITS_PER_LONG;
int k;
int nr = BITS_TO_LONGS(bits);
unsigned long result = 0;
 
for (k = 0; k < lim; k++)
for (k = 0; k < nr; k++)
result |= (dst[k] = bitmap1[k] & bitmap2[k]);
if (bits % BITS_PER_LONG)
result |= (dst[k] = bitmap1[k] & bitmap2[k] &
BITMAP_LAST_WORD_MASK(bits));
return result != 0;
}
EXPORT_SYMBOL(__bitmap_and);
 
void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
const unsigned long *bitmap2, int bits)
{
unsigned int k;
unsigned int nr = BITS_TO_LONGS(bits);
int k;
int nr = BITS_TO_LONGS(bits);
 
for (k = 0; k < nr; k++)
dst[k] = bitmap1[k] | bitmap2[k];
210,10 → 207,10
EXPORT_SYMBOL(__bitmap_or);
 
void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
const unsigned long *bitmap2, int bits)
{
unsigned int k;
unsigned int nr = BITS_TO_LONGS(bits);
int k;
int nr = BITS_TO_LONGS(bits);
 
for (k = 0; k < nr; k++)
dst[k] = bitmap1[k] ^ bitmap2[k];
221,25 → 218,22
EXPORT_SYMBOL(__bitmap_xor);
 
int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
const unsigned long *bitmap2, int bits)
{
unsigned int k;
unsigned int lim = bits/BITS_PER_LONG;
int k;
int nr = BITS_TO_LONGS(bits);
unsigned long result = 0;
 
for (k = 0; k < lim; k++)
for (k = 0; k < nr; k++)
result |= (dst[k] = bitmap1[k] & ~bitmap2[k]);
if (bits % BITS_PER_LONG)
result |= (dst[k] = bitmap1[k] & ~bitmap2[k] &
BITMAP_LAST_WORD_MASK(bits));
return result != 0;
}
EXPORT_SYMBOL(__bitmap_andnot);
 
int __bitmap_intersects(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
const unsigned long *bitmap2, int bits)
{
unsigned int k, lim = bits/BITS_PER_LONG;
int k, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; ++k)
if (bitmap1[k] & bitmap2[k])
return 1;
252,9 → 246,9
EXPORT_SYMBOL(__bitmap_intersects);
 
int __bitmap_subset(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
const unsigned long *bitmap2, int bits)
{
unsigned int k, lim = bits/BITS_PER_LONG;
int k, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; ++k)
if (bitmap1[k] & ~bitmap2[k])
return 0;
266,10 → 260,9
}
EXPORT_SYMBOL(__bitmap_subset);
 
int __bitmap_weight(const unsigned long *bitmap, unsigned int bits)
int __bitmap_weight(const unsigned long *bitmap, int bits)
{
unsigned int k, lim = bits/BITS_PER_LONG;
int w = 0;
int k, w = 0, lim = bits/BITS_PER_LONG;
 
for (k = 0; k < lim; k++)
w += hweight_long(bitmap[k]);
281,21 → 274,21
}
EXPORT_SYMBOL(__bitmap_weight);
 
void bitmap_set(unsigned long *map, unsigned int start, int len)
void bitmap_set(unsigned long *map, int start, int nr)
{
unsigned long *p = map + BIT_WORD(start);
const unsigned int size = start + len;
const int size = start + nr;
int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start);
 
while (len - bits_to_set >= 0) {
while (nr - bits_to_set >= 0) {
*p |= mask_to_set;
len -= bits_to_set;
nr -= bits_to_set;
bits_to_set = BITS_PER_LONG;
mask_to_set = ~0UL;
p++;
}
if (len) {
if (nr) {
mask_to_set &= BITMAP_LAST_WORD_MASK(size);
*p |= mask_to_set;
}
302,21 → 295,21
}
EXPORT_SYMBOL(bitmap_set);
 
void bitmap_clear(unsigned long *map, unsigned int start, int len)
void bitmap_clear(unsigned long *map, int start, int nr)
{
unsigned long *p = map + BIT_WORD(start);
const unsigned int size = start + len;
const int size = start + nr;
int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
 
while (len - bits_to_clear >= 0) {
while (nr - bits_to_clear >= 0) {
*p &= ~mask_to_clear;
len -= bits_to_clear;
nr -= bits_to_clear;
bits_to_clear = BITS_PER_LONG;
mask_to_clear = ~0UL;
p++;
}
if (len) {
if (nr) {
mask_to_clear &= BITMAP_LAST_WORD_MASK(size);
*p &= ~mask_to_clear;
}
385,7 → 378,7
*
* If for example, just bits 4 through 7 are set in @buf, then @pos
* values 4 through 7 will get mapped to 0 through 3, respectively,
* and other @pos values will get mapped to -1. When @pos value 7
* and other @pos values will get mapped to 0. When @pos value 7
* gets mapped to (returns) @ord value 3 in this example, that means
* that bit 7 is the 3rd (starting with 0th) set bit in @buf.
*
715,7 → 708,7
REG_OP_RELEASE, /* clear all bits in region */
};
 
static int __reg_op(unsigned long *bitmap, unsigned int pos, int order, int reg_op)
static int __reg_op(unsigned long *bitmap, int pos, int order, int reg_op)
{
int nbits_reg; /* number of bits in region */
int index; /* index first long of region in bitmap */
781,11 → 774,11
* Return the bit offset in bitmap of the allocated region,
* or -errno on failure.
*/
int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order)
int bitmap_find_free_region(unsigned long *bitmap, int bits, int order)
{
unsigned int pos, end; /* scans bitmap by regions of size order */
int pos, end; /* scans bitmap by regions of size order */
 
for (pos = 0 ; (end = pos + (1U << order)) <= bits; pos = end) {
for (pos = 0 ; (end = pos + (1 << order)) <= bits; pos = end) {
if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE))
continue;
__reg_op(bitmap, pos, order, REG_OP_ALLOC);
806,7 → 799,7
*
* No return value.
*/
void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order)
void bitmap_release_region(unsigned long *bitmap, int pos, int order)
{
__reg_op(bitmap, pos, order, REG_OP_RELEASE);
}
823,11 → 816,12
* Return 0 on success, or %-EBUSY if specified region wasn't
* free (not all bits were zero).
*/
int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order)
int bitmap_allocate_region(unsigned long *bitmap, int pos, int order)
{
if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE))
return -EBUSY;
return __reg_op(bitmap, pos, order, REG_OP_ALLOC);
__reg_op(bitmap, pos, order, REG_OP_ALLOC);
return 0;
}
EXPORT_SYMBOL(bitmap_allocate_region);