/arch/arm/mach-msm/mkrpcsym.pl

https://bitbucket.org/sammyz/iscream_thunderc-2.6.35-rebase · Perl · 162 lines · 102 code · 18 blank · 42 comment · 17 complexity · 9834c7e4dbd0000eb157b9b90efb5407 MD5 · raw file

  1. #!/usr/bin/perl
  2. #
  3. # Generate the smd_rpc_sym.c symbol file for ONCRPC SMEM Logging
  4. #
  5. # Copyright (c) 2009, Code Aurora Forum. All rights reserved.
  6. #
  7. # Redistribution and use in source and binary forms, with or without
  8. # modification, are permitted provided that the following conditions are
  9. # met:
  10. # * Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # * Redistributions in binary form must reproduce the above
  13. # copyright notice, this list of conditions and the following
  14. # disclaimer in the documentation and/or other materials provided
  15. # with the distribution.
  16. # * Neither the name of Code Aurora Forum, Inc. nor the names of its
  17. # contributors may be used to endorse or promote products derived
  18. # from this software without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  21. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  23. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  24. # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  27. # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  29. # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  30. # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. use strict;
  32. use POSIX;
  33. my $base_fn = "smd_rpc_sym";
  34. my %prog_table;
  35. my ($in, $out) = @ARGV;
  36. my $max_table_size = 1024;
  37. my $header = <<"EOF";
  38. /* Autogenerated by mkrpcsym.pl. Do not edit */
  39. EOF
  40. sub smd_rpc_gen_files() {
  41. my $c_fp;
  42. my $h_fp;
  43. my @table;
  44. my $tbl_index;
  45. my $num_undefined=0;
  46. # Process the input hash table into an array
  47. # Any duplicate items will be combined, missing items will
  48. # become "UNKNOWN" We end-up with a fully-qualified table
  49. # from 0 to n.
  50. $prog_table{"UNDEFINED"}{'name'}="UNDEFINED";
  51. $prog_table{"UNDEFINED"}{'prog'}=-1;
  52. my $hex_num = 0xFFFF;
  53. foreach my $api_prog (sort {$a cmp $b} keys %prog_table ) {
  54. $tbl_index = hex($api_prog) & hex("0000FFFF");
  55. if($prog_table{$api_prog}{'prog'} >= 0) {
  56. if($tbl_index < $max_table_size) {
  57. $table[$tbl_index]=$prog_table{$api_prog};
  58. } else {
  59. print "Skipping table item $tbl_index, larger ",
  60. "than max:$max_table_size \n";
  61. }
  62. }
  63. }
  64. for (my $i=0; $i<=$#table; $i++) {
  65. if (!exists $table[$i]) {
  66. $table[$i]=$prog_table{"UNDEFINED"};
  67. $num_undefined++;
  68. }
  69. }
  70. open($c_fp, ">", $out) or die $!;
  71. print $c_fp $header;
  72. print $c_fp "\n\n\n";
  73. print $c_fp <<"EOF";
  74. #include <linux/kernel.h>
  75. #include <linux/init.h>
  76. #include <linux/debugfs.h>
  77. #include <linux/module.h>
  78. struct sym {
  79. const char *str;
  80. };
  81. EOF
  82. # Each API is named starts with "CB " to allow both the forward and
  83. # callback names of the API to be returned from a common database.
  84. # By convention, program names starting with 0x30 are forward APIS,
  85. # API names starting with 0x31 are callback apis.
  86. print $c_fp "const char *smd_rpc_syms[] = {\n";
  87. for (my $i=0; $i<= $#table; $i++) {
  88. my $l = length($table[$i]{'name'});
  89. my $t = floor((45 - $l - 4)/8);
  90. print $c_fp "\t\"CB ".uc($table[$i]{'name'})."\",";
  91. if($table[$i]{'name'} ne "UNDEFINED") {
  92. for (my $i=0;$i<$t;$i++) {
  93. print $c_fp "\t";
  94. }
  95. print $c_fp "/*".$table[$i]{'prog'}."*/\n";
  96. } else {
  97. print $c_fp "\n";
  98. }
  99. }
  100. print $c_fp "};\n";
  101. print $c_fp <<"EOF";
  102. static struct sym_tbl {
  103. const char **data;
  104. int size;
  105. } tbl = { smd_rpc_syms, ARRAY_SIZE(smd_rpc_syms)};
  106. const char *smd_rpc_get_sym(uint32_t val)
  107. {
  108. int idx = val & 0xFFFF;
  109. if (idx < tbl.size) {
  110. if (val & 0x01000000)
  111. return tbl.data[idx];
  112. else
  113. return tbl.data[idx] + 3;
  114. }
  115. return 0;
  116. }
  117. EXPORT_SYMBOL(smd_rpc_get_sym);
  118. EOF
  119. close $c_fp;
  120. }
  121. sub read_smd_rpc_table() {
  122. my $fp;
  123. my $line;
  124. open($fp, "<", $in) or die "$! File:$in";
  125. while ($line = <$fp>) {
  126. chomp($line);
  127. if($line =~ /([^\s]+)\s+([\w]+)$/) {
  128. if(defined $prog_table{$1}) {
  129. print "Error entry already defined $1,",
  130. " in $prog_table{$1}{name} \n";
  131. } else {
  132. $prog_table{$1}{'name'}=$2;
  133. $prog_table{$1}{'prog'}=$1;
  134. }
  135. } else {
  136. if($line =~ /\w/) {
  137. print "Error parsing error >>$line<< \n";
  138. }
  139. }
  140. }
  141. close $fp;
  142. }
  143. read_smd_rpc_table();
  144. smd_rpc_gen_files();