treewide: remove FSF address
[osmocom-bb.git] / src / target / firmware / comm / msgb.c
blobc564e790e0115b8d528d6c38573aaa1f32d58c11
1 /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
2 * All Rights Reserved
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
17 #include <stdint.h>
18 #include <stdio.h>
19 #include <string.h>
20 #include <sys/types.h>
21 #include <asm/system.h>
23 #include <debug.h>
24 #include <delay.h>
25 #include <console.h>
27 #include <osmocom/core/msgb.h>
29 #define NO_TALLOC
31 #ifdef NO_TALLOC
32 /* This is a poor mans static allocator for msgb objects */
33 #define MSGB_DATA_SIZE 256+4
34 #define MSGB_NUM 32
35 struct supermsg {
36 uint8_t allocated;
37 struct msgb msg;
38 uint8_t buf[MSGB_DATA_SIZE];
40 static struct supermsg msgs[MSGB_NUM];
41 void *_talloc_zero(void *ctx, unsigned int size, const char *name)
43 unsigned long flags;
44 unsigned int i;
46 local_firq_save(flags);
48 if (size > sizeof(struct msgb) + MSGB_DATA_SIZE)
49 goto panic;
51 for (i = 0; i < ARRAY_SIZE(msgs); i++) {
52 if (!msgs[i].allocated) {
53 msgs[i].allocated = 1;
54 memset(&msgs[i].msg, 0, sizeof(msgs[i].msg));
55 memset(&msgs[i].buf, 0, sizeof(msgs[i].buf));
56 local_irq_restore(flags);
57 return &msgs[i].msg;
61 panic:
62 cons_puts("unable to allocate msgb\n");
63 while (1);
65 return NULL; /* not reached */
67 void talloc_free(void *msg)
69 struct supermsg *smsg = container_of(msg, struct supermsg, msg);
70 /* no locking required, since this is atomic */
71 smsg->allocated = 0;
73 #endif