4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * Generic bitmap operations.
8 * Copyright (C) 2005-2006 Texas Instruments, Inc.
10 * This package is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 #include <linux/types.h>
20 /* ----------------------------------- DSP/BIOS Bridge */
21 #include <linux/types.h>
22 /* ----------------------------------- This */
23 #include <dspbridge/gs.h>
24 #include <dspbridge/gb.h>
33 * ======== gb_clear ========
35 * Clears a bit in the bit map.
38 void gb_clear(struct gb_t_map *map, u32 bitn)
42 mask = 1L << (bitn % BITS_PER_LONG);
43 map->words[bitn / BITS_PER_LONG] &= ~mask;
47 * ======== gb_create ========
52 struct gb_t_map *gb_create(u32 len)
56 map = (struct gb_t_map *)gs_alloc(sizeof(struct gb_t_map));
59 map->wcnt = len / BITS_PER_LONG + 1;
60 map->words = (u32 *) gs_alloc(map->wcnt * sizeof(u32));
61 if (map->words != NULL) {
62 for (i = 0; i < map->wcnt; i++)
66 gs_frees(map, sizeof(struct gb_t_map));
75 * ======== gb_delete ========
80 void gb_delete(struct gb_t_map *map)
82 gs_frees(map->words, map->wcnt * sizeof(u32));
83 gs_frees(map, sizeof(struct gb_t_map));
87 * ======== gb_findandset ========
89 * Finds a free bit and sets it.
91 u32 gb_findandset(struct gb_t_map *map)
95 bitn = gb_minclear(map);
97 if (bitn != GB_NOBITS)
104 * ======== gb_minclear ========
106 * returns the location of the first unset bit in the bit map.
108 u32 gb_minclear(struct gb_t_map *map)
110 u32 bit_location = 0;
116 for (word = map->words, i = 0; i < map->wcnt; word++, i++) {
118 for (bit = 0; bit < BITS_PER_LONG; bit++, bit_acc++) {
119 if (bit_acc == map->len)
122 if (~*word & (1L << bit)) {
123 bit_location = i * BITS_PER_LONG + bit;
129 bit_acc += BITS_PER_LONG;
137 * ======== gb_set ========
139 * Sets a bit in the bit map.
142 void gb_set(struct gb_t_map *map, u32 bitn)
146 mask = 1L << (bitn % BITS_PER_LONG);
147 map->words[bitn / BITS_PER_LONG] |= mask;
151 * ======== gb_test ========
153 * Returns true if the bit is set in the specified location.
156 bool gb_test(struct gb_t_map *map, u32 bitn)
162 mask = 1L << (bitn % BITS_PER_LONG);
163 word = map->words[bitn / BITS_PER_LONG];
164 state = word & mask ? true : false;