Merge branches 'acpica-fixes' and 'device-properties-fixes'
[deliverable/linux.git] / include / linux / trace_seq.h
CommitLineData
9504504c
SR
1#ifndef _LINUX_TRACE_SEQ_H
2#define _LINUX_TRACE_SEQ_H
3
3a161d99 4#include <linux/seq_buf.h>
6d723736 5
78be6914
WZ
6#include <asm/page.h>
7
9504504c
SR
8/*
9 * Trace sequences are used to allow a function to call several other functions
6d3f1e12 10 * to create a string of data to use (up to a max of PAGE_SIZE).
9504504c
SR
11 */
12
13struct trace_seq {
14 unsigned char buffer[PAGE_SIZE];
3a161d99 15 struct seq_buf seq;
d184b31c 16 int full;
9504504c
SR
17};
18
19static inline void
20trace_seq_init(struct trace_seq *s)
21{
3a161d99 22 seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);
d184b31c 23 s->full = 0;
9504504c
SR
24}
25
5ac48378
SRRH
26/**
27 * trace_seq_used - amount of actual data written to buffer
28 * @s: trace sequence descriptor
29 *
30 * Returns the amount of data written to the buffer.
31 *
32 * IMPORTANT!
33 *
34 * Use this instead of @s->seq.len if you need to pass the amount
35 * of data from the buffer to another buffer (userspace, or what not).
36 * The @s->seq.len on overflow is bigger than the buffer size and
37 * using it can cause access to undefined memory.
38 */
39static inline int trace_seq_used(struct trace_seq *s)
40{
41 return seq_buf_used(&s->seq);
42}
43
7b039cb4
SRRH
44/**
45 * trace_seq_buffer_ptr - return pointer to next location in buffer
46 * @s: trace sequence descriptor
47 *
48 * Returns the pointer to the buffer where the next write to
49 * the buffer will happen. This is useful to save the location
50 * that is about to be written to and then return the result
51 * of that write.
52 */
53static inline unsigned char *
54trace_seq_buffer_ptr(struct trace_seq *s)
55{
5ac48378 56 return s->buffer + seq_buf_used(&s->seq);
7b039cb4
SRRH
57}
58
19a7fe20
SRRH
59/**
60 * trace_seq_has_overflowed - return true if the trace_seq took too much
61 * @s: trace sequence descriptor
62 *
63 * Returns true if too much data was added to the trace_seq and it is
64 * now full and will not take anymore.
65 */
66static inline bool trace_seq_has_overflowed(struct trace_seq *s)
67{
3a161d99 68 return s->full || seq_buf_has_overflowed(&s->seq);
19a7fe20
SRRH
69}
70
9504504c
SR
71/*
72 * Currently only defined when tracing is enabled.
73 */
74#ifdef CONFIG_TRACING
b9075fa9 75extern __printf(2, 3)
dba39448 76void trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
b9075fa9 77extern __printf(2, 0)
dba39448
SRRH
78void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
79extern void
9504504c 80trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
a63ce5b3 81extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
36aabfff
SRRH
82extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
83 int cnt);
dba39448
SRRH
84extern void trace_seq_puts(struct trace_seq *s, const char *str);
85extern void trace_seq_putc(struct trace_seq *s, unsigned char c);
86extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
87extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
36aabfff 88 unsigned int len);
38eff289 89extern int trace_seq_path(struct trace_seq *s, const struct path *path);
9504504c 90
dba39448 91extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
4449bf92
SRRH
92 int nmaskbits);
93
9504504c 94#else /* CONFIG_TRACING */
dba39448 95static inline void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
9504504c 96{
9504504c 97}
dba39448 98static inline void
9504504c
SR
99trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
100{
9504504c
SR
101}
102
dba39448 103static inline void
4449bf92
SRRH
104trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
105 int nmaskbits)
106{
4449bf92
SRRH
107}
108
a63ce5b3 109static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s)
9504504c 110{
a63ce5b3 111 return 0;
9504504c 112}
36aabfff
SRRH
113static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
114 int cnt)
9504504c
SR
115{
116 return 0;
117}
dba39448 118static inline void trace_seq_puts(struct trace_seq *s, const char *str)
9504504c 119{
9504504c 120}
dba39448 121static inline void trace_seq_putc(struct trace_seq *s, unsigned char c)
9504504c 122{
9504504c 123}
dba39448 124static inline void
36aabfff 125trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
9504504c 126{
9504504c 127}
dba39448 128static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
36aabfff 129 unsigned int len)
9504504c 130{
9504504c 131}
38eff289 132static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
9504504c
SR
133{
134 return 0;
135}
136#endif /* CONFIG_TRACING */
137
138#endif /* _LINUX_TRACE_SEQ_H */
This page took 0.709616 seconds and 5 git commands to generate.