1 /**
2 * Copyright (C) ARM Limited 2012. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 */
10 #define ESCAPE_CODE 0x1c
11 #define STRING_ANNOTATION 0x03
12 #define VISUAL_ANNOTATION 0x04
13 #define MARKER_ANNOTATION 0x05
15 static void kannotate_write(const char* ptr, unsigned int size)
16 {
17 int retval;
18 int pos = 0;
19 loff_t offset = 0;
20 while (pos < size) {
21 retval = annotate_write(NULL, &ptr[pos], size - pos, &offset);
22 if (retval < 0) {
23 printk(KERN_WARNING "gator: kannotate_write failed with return value %d\n", retval);
24 return;
25 }
26 pos += retval;
27 }
28 }
30 static void gator_annotate_code(char code)
31 {
32 int header = ESCAPE_CODE | (code << 8);
33 kannotate_write((char*)&header, sizeof(header));
34 }
36 static void gator_annotate_code_str(char code, const char* string)
37 {
38 int str_size = strlen(string) & 0xffff;
39 int header = ESCAPE_CODE | (code << 8) | (str_size << 16);
40 kannotate_write((char*)&header, sizeof(header));
41 kannotate_write(string, str_size);
42 }
44 static void gator_annotate_code_color(char code, int color)
45 {
46 long long header = (ESCAPE_CODE | (code << 8) | 0x00040000 | ((long long)color << 32));
47 kannotate_write((char*)&header, sizeof(header));
48 }
50 static void gator_annotate_code_color_str(char code, int color, const char* string)
51 {
52 int str_size = (strlen(string) + 4) & 0xffff;
53 long long header = ESCAPE_CODE | (code << 8) | (str_size << 16) | ((long long)color << 32);
54 kannotate_write((char*)&header, sizeof(header));
55 kannotate_write(string, str_size - 4);
56 }
58 // String annotation
59 void gator_annotate(const char* string)
60 {
61 gator_annotate_code_str(STRING_ANNOTATION, string);
62 }
63 EXPORT_SYMBOL(gator_annotate);
65 // String annotation with color
66 void gator_annotate_color(int color, const char* string)
67 {
68 gator_annotate_code_color_str(STRING_ANNOTATION, color, string);
69 }
70 EXPORT_SYMBOL(gator_annotate_color);
72 // Terminate an annotation
73 void gator_annotate_end(void)
74 {
75 gator_annotate_code(STRING_ANNOTATION);
76 }
77 EXPORT_SYMBOL(gator_annotate_end);
79 // Image annotation with optional string
80 void gator_annotate_visual(const char* data, unsigned int length, const char* string)
81 {
82 int str_size = strlen(string) & 0xffff;
83 int visual_annotation = ESCAPE_CODE | (VISUAL_ANNOTATION << 8) | (str_size << 16);
84 kannotate_write((char*)&visual_annotation, sizeof(visual_annotation));
85 kannotate_write(string, str_size);
86 kannotate_write((char*)&length, sizeof(length));
87 kannotate_write(data, length);
88 }
89 EXPORT_SYMBOL(gator_annotate_visual);
91 // Marker annotation
92 void gator_annotate_marker(void)
93 {
94 gator_annotate_code(MARKER_ANNOTATION);
95 }
96 EXPORT_SYMBOL(gator_annotate_marker);
98 // Marker annotation with a string
99 void gator_annotate_marker_str(const char* string)
100 {
101 gator_annotate_code_str(MARKER_ANNOTATION, string);
102 }
103 EXPORT_SYMBOL(gator_annotate_marker_str);
105 // Marker annotation with a color
106 void gator_annotate_marker_color(int color)
107 {
108 gator_annotate_code_color(MARKER_ANNOTATION, color);
109 }
110 EXPORT_SYMBOL(gator_annotate_marker_color);
112 // Marker annotation with a string and color
113 void gator_annotate_marker_color_str(int color, const char* string)
114 {
115 gator_annotate_code_color_str(MARKER_ANNOTATION, color, string);
116 }
117 EXPORT_SYMBOL(gator_annotate_marker_color_str);