ARM: cpu topology: Add debugfs interface for cpu_power
[cmplus.git] / arch / arm / common / fiq_debugger_ringbuf.h
blob2649b5581088cadda57b2910a469c7480644fe68
1 /*
2 * arch/arm/common/fiq_debugger_ringbuf.c
4 * simple lockless ringbuffer
6 * Copyright (C) 2010 Google, Inc.
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/kernel.h>
19 #include <linux/slab.h>
21 struct fiq_debugger_ringbuf {
22 int len;
23 int head;
24 int tail;
25 u8 buf[];
29 static inline struct fiq_debugger_ringbuf *fiq_debugger_ringbuf_alloc(int len)
31 struct fiq_debugger_ringbuf *rbuf;
33 rbuf = kzalloc(sizeof(*rbuf) + len, GFP_KERNEL);
34 if (rbuf == NULL)
35 return NULL;
37 rbuf->len = len;
38 rbuf->head = 0;
39 rbuf->tail = 0;
40 smp_mb();
42 return rbuf;
45 static inline void fiq_debugger_ringbuf_free(struct fiq_debugger_ringbuf *rbuf)
47 kfree(rbuf);
50 static inline int fiq_debugger_ringbuf_level(struct fiq_debugger_ringbuf *rbuf)
52 int level = rbuf->head - rbuf->tail;
54 if (level < 0)
55 level = rbuf->len + level;
57 return level;
60 static inline int fiq_debugger_ringbuf_room(struct fiq_debugger_ringbuf *rbuf)
62 return rbuf->len - fiq_debugger_ringbuf_level(rbuf) - 1;
65 static inline u8
66 fiq_debugger_ringbuf_peek(struct fiq_debugger_ringbuf *rbuf, int i)
68 return rbuf->buf[(rbuf->tail + i) % rbuf->len];
71 static inline int
72 fiq_debugger_ringbuf_consume(struct fiq_debugger_ringbuf *rbuf, int count)
74 count = min(count, fiq_debugger_ringbuf_level(rbuf));
76 rbuf->tail = (rbuf->tail + count) % rbuf->len;
77 smp_mb();
79 return count;
82 static inline int
83 fiq_debugger_ringbuf_push(struct fiq_debugger_ringbuf *rbuf, u8 datum)
85 if (fiq_debugger_ringbuf_room(rbuf) == 0)
86 return 0;
88 rbuf->buf[rbuf->head] = datum;
89 smp_mb();
90 rbuf->head = (rbuf->head + 1) % rbuf->len;
91 smp_mb();
93 return 1;