Ignore:
Timestamp:
Dec 11, 2005, 5:57:39 PM (20 years ago)
Author:
vladest
Message:

Latest update from ALSA. some intial > 15 interrupts support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk/alsa-kernel/synth/util_mem.c

    r33 r34  
    1616 *   You should have received a copy of the GNU General Public License
    1717 *   along with this program; if not, write to the Free Software
    18  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    19  */
    20 
    21 #define SNDRV_MAIN_OBJECT_FILE
     18 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
     19 */
     20
    2221#include <sound/driver.h>
     22#include <linux/init.h>
     23#include <linux/slab.h>
     24#include <sound/core.h>
    2325#include <sound/util_mem.h>
    2426
    2527MODULE_AUTHOR("Takashi Iwai");
    26 
    27 #define get_memblk(p)   list_entry(p, snd_util_memblk_t, list)
     28MODULE_DESCRIPTION("Generic memory management routines for soundcard memory allocation");
     29MODULE_LICENSE("GPL");
     30
     31#define get_memblk(p)   list_entry(p, struct snd_util_memblk, list)
    2832
    2933/*
    3034 * create a new memory manager
    3135 */
    32 snd_util_memhdr_t *
    33     snd_util_memhdr_new(int memsize)
    34 {
    35     snd_util_memhdr_t *hdr;
    36 
    37     hdr = kcalloc(1, sizeof(*hdr), GFP_KERNEL);
    38     if (hdr == NULL)
    39         return NULL;
    40     hdr->size = memsize;
    41     init_MUTEX(&hdr->block_mutex);
    42     INIT_LIST_HEAD(&hdr->block);
    43 
    44     return hdr;
     36struct snd_util_memhdr *
     37snd_util_memhdr_new(int memsize)
     38{
     39        struct snd_util_memhdr *hdr;
     40
     41        hdr = kzalloc(sizeof(*hdr), GFP_KERNEL);
     42        if (hdr == NULL)
     43                return NULL;
     44        hdr->size = memsize;
     45        init_MUTEX(&hdr->block_mutex);
     46        INIT_LIST_HEAD(&hdr->block);
     47
     48        return hdr;
    4549}
    4650
     
    4852 * free a memory manager
    4953 */
    50 void snd_util_memhdr_free(snd_util_memhdr_t *hdr)
    51 {
    52     struct list_head *p;
    53 
    54     snd_assert(hdr != NULL, return);
    55     /* release all blocks */
    56     while ((p = hdr->block.next) != &hdr->block) {
    57         list_del(p);
    58         kfree(get_memblk(p));
    59     }
    60     kfree(hdr);
     54void snd_util_memhdr_free(struct snd_util_memhdr *hdr)
     55{
     56        struct list_head *p;
     57
     58        snd_assert(hdr != NULL, return);
     59        /* release all blocks */
     60        while ((p = hdr->block.next) != &hdr->block) {
     61                list_del(p);
     62                kfree(get_memblk(p));
     63        }
     64        kfree(hdr);
    6165}
    6266
     
    6468 * allocate a memory block (without mutex)
    6569 */
    66 snd_util_memblk_t *
    67 __snd_util_mem_alloc(snd_util_memhdr_t *hdr, int size)
    68 {
    69     snd_util_memblk_t *blk;
    70     snd_util_unit_t units, prev_offset;
    71     struct list_head *p;
    72 
    73     snd_assert(hdr != NULL, return NULL);
    74     snd_assert(size > 0, return NULL);
    75     /* word alignment */
    76     units = size;
    77     if (units & 1)
    78         units++;
    79     if (units > hdr->size)
    80         return NULL;
    81 
    82     /* look for empty block */
    83     prev_offset = 0;
    84     list_for_each(p, &hdr->block) {
    85         blk = get_memblk(p);
    86         if (blk->offset - prev_offset >= units)
    87             goto __found;
    88         prev_offset = blk->offset + blk->size;
    89     }
    90     if (hdr->size - prev_offset < units)
    91         return NULL;
     70struct snd_util_memblk *
     71__snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size)
     72{
     73        struct snd_util_memblk *blk;
     74        unsigned int units, prev_offset;
     75        struct list_head *p;
     76
     77        snd_assert(hdr != NULL, return NULL);
     78        snd_assert(size > 0, return NULL);
     79
     80        /* word alignment */
     81        units = size;
     82        if (units & 1)
     83                units++;
     84        if (units > hdr->size)
     85                return NULL;
     86
     87        /* look for empty block */
     88        prev_offset = 0;
     89        list_for_each(p, &hdr->block) {
     90                blk = get_memblk(p);
     91                if (blk->offset - prev_offset >= units)
     92                        goto __found;
     93                prev_offset = blk->offset + blk->size;
     94        }
     95        if (hdr->size - prev_offset < units)
     96                return NULL;
    9297
    9398__found:
    94     return __snd_util_memblk_new(hdr, units, p->prev);
     99        return __snd_util_memblk_new(hdr, units, p->prev);
    95100}
    96101
     
    100105 * the block is linked next to prev
    101106 */
    102 snd_util_memblk_t *
    103 __snd_util_memblk_new(snd_util_memhdr_t *hdr, snd_util_unit_t units,
    104                       struct list_head *prev)
    105 {
    106     snd_util_memblk_t *blk;
    107 
    108     blk = kmalloc(sizeof(snd_util_memblk_t) + hdr->block_extra_size, GFP_KERNEL);
    109     if (blk == NULL)
    110         return NULL;
    111 
    112     if (! prev || prev == &hdr->block)
    113         blk->offset = 0;
    114     else {
    115         snd_util_memblk_t *p = get_memblk(prev);
    116         blk->offset = p->offset + p->size;
    117     }
    118     blk->size = units;
    119     list_add(&blk->list, prev);
    120     hdr->nblocks++;
    121     hdr->used += units;
    122     return blk;
     107struct snd_util_memblk *
     108__snd_util_memblk_new(struct snd_util_memhdr *hdr, unsigned int units,
     109                      struct list_head *prev)
     110{
     111        struct snd_util_memblk *blk;
     112
     113        blk = kmalloc(sizeof(struct snd_util_memblk) + hdr->block_extra_size,
     114                      GFP_KERNEL);
     115        if (blk == NULL)
     116                return NULL;
     117
     118        if (! prev || prev == &hdr->block)
     119                blk->offset = 0;
     120        else {
     121                struct snd_util_memblk *p = get_memblk(prev);
     122                blk->offset = p->offset + p->size;
     123        }
     124        blk->size = units;
     125        list_add(&blk->list, prev);
     126        hdr->nblocks++;
     127        hdr->used += units;
     128        return blk;
    123129}
    124130
     
    127133 * allocate a memory block (with mutex)
    128134 */
    129 snd_util_memblk_t *
    130 snd_util_mem_alloc(snd_util_memhdr_t *hdr, int size)
    131 {
    132     snd_util_memblk_t *blk;
    133     down(&hdr->block_mutex);
    134     blk = __snd_util_mem_alloc(hdr, size);
    135     up(&hdr->block_mutex);
    136     return blk;
     135struct snd_util_memblk *
     136snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size)
     137{
     138        struct snd_util_memblk *blk;
     139        down(&hdr->block_mutex);
     140        blk = __snd_util_mem_alloc(hdr, size);
     141        up(&hdr->block_mutex);
     142        return blk;
    137143}
    138144
     
    143149 */
    144150void
    145 __snd_util_mem_free(snd_util_memhdr_t *hdr, snd_util_memblk_t *blk)
    146 {
    147     list_del(&blk->list);
    148     hdr->nblocks--;
    149     hdr->used -= blk->size;
    150     kfree(blk);
     151__snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk)
     152{
     153        list_del(&blk->list);
     154        hdr->nblocks--;
     155        hdr->used -= blk->size;
     156        kfree(blk);
    151157}
    152158
     
    154160 * free a memory block (with mutex)
    155161 */
    156 int snd_util_mem_free(snd_util_memhdr_t *hdr, snd_util_memblk_t *blk)
    157 {
    158     snd_assert(hdr && blk, return -EINVAL);
    159 
    160     down(&hdr->block_mutex);
    161     __snd_util_mem_free(hdr, blk);
    162     up(&hdr->block_mutex);
    163     return 0;
     162int snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk)
     163{
     164        snd_assert(hdr && blk, return -EINVAL);
     165
     166        down(&hdr->block_mutex);
     167        __snd_util_mem_free(hdr, blk);
     168        up(&hdr->block_mutex);
     169        return 0;
    164170}
    165171
     
    167173 * return available memory size
    168174 */
    169 int snd_util_mem_avail(snd_util_memhdr_t *hdr)
    170 {
    171     unsigned int size;
    172     down(&hdr->block_mutex);
    173     size = hdr->size - hdr->used;
    174     up(&hdr->block_mutex);
    175     return size;
     175int snd_util_mem_avail(struct snd_util_memhdr *hdr)
     176{
     177        unsigned int size;
     178        down(&hdr->block_mutex);
     179        size = hdr->size - hdr->used;
     180        up(&hdr->block_mutex);
     181        return size;
    176182}
    177183
     
    192198static int __init alsa_util_mem_init(void)
    193199{
    194     return 0;
     200        return 0;
    195201}
    196202
Note: See TracChangeset for help on using the changeset viewer.