PageRenderTime 18ms CodeModel.GetById 7ms app.highlight 9ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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
 32use strict;
 33use POSIX;
 34
 35my $base_fn = "smd_rpc_sym";
 36my %prog_table;
 37my ($in, $out) = @ARGV;
 38my $max_table_size = 1024;
 39
 40my $header = <<"EOF";
 41/* Autogenerated by mkrpcsym.pl.  Do not edit */
 42EOF
 43
 44sub smd_rpc_gen_files() {
 45	my $c_fp;
 46	my $h_fp;
 47	my @table;
 48	my $tbl_index;
 49	my $num_undefined=0;
 50
 51	# Process the input hash table into an array
 52	# Any duplicate items will be combined, missing items will
 53	# become "UNKNOWN"  We end-up with a fully-qualified table
 54	# from 0 to n.
 55
 56	$prog_table{"UNDEFINED"}{'name'}="UNDEFINED";
 57	$prog_table{"UNDEFINED"}{'prog'}=-1;
 58	my $hex_num = 0xFFFF;
 59	foreach my $api_prog (sort {$a cmp $b} keys %prog_table ) {
 60		$tbl_index = hex($api_prog) & hex("0000FFFF");
 61		if($prog_table{$api_prog}{'prog'} >= 0) {
 62			if($tbl_index < $max_table_size) {
 63				$table[$tbl_index]=$prog_table{$api_prog};
 64			} else {
 65				print "Skipping table item $tbl_index, larger ",
 66					"than max:$max_table_size \n";
 67			}
 68		}
 69	}
 70	for (my $i=0; $i<=$#table; $i++) {
 71		if (!exists $table[$i]) {
 72			$table[$i]=$prog_table{"UNDEFINED"};
 73		$num_undefined++;
 74		}
 75	}
 76
 77
 78	open($c_fp, ">", $out) or die  $!;
 79	print $c_fp $header;
 80	print $c_fp "\n\n\n";
 81	print $c_fp <<"EOF";
 82#include <linux/kernel.h>
 83#include <linux/init.h>
 84#include <linux/debugfs.h>
 85#include <linux/module.h>
 86
 87struct sym {
 88	const char *str;
 89};
 90
 91EOF
 92
 93# Each API is named starts with "CB " to allow both the forward and
 94# callback names of the API to be returned from a common database.
 95# By convention, program names starting with 0x30 are forward APIS,
 96# API names starting with 0x31 are callback apis.
 97	print $c_fp "const char *smd_rpc_syms[] = {\n";
 98
 99	for (my $i=0; $i<= $#table; $i++) {
100		my $l = length($table[$i]{'name'});
101		my $t = floor((45 - $l - 4)/8);
102		print $c_fp "\t\"CB ".uc($table[$i]{'name'})."\",";
103		if($table[$i]{'name'} ne "UNDEFINED") {
104			for (my $i=0;$i<$t;$i++) {
105				print $c_fp "\t";
106			}
107			print $c_fp "/*".$table[$i]{'prog'}."*/\n";
108		} else {
109			print $c_fp "\n";
110		}
111	}
112
113	print $c_fp "};\n";
114	print $c_fp <<"EOF";
115
116static struct sym_tbl {
117	const char **data;
118	int size;
119} tbl = { smd_rpc_syms, ARRAY_SIZE(smd_rpc_syms)};
120
121const char *smd_rpc_get_sym(uint32_t val)
122{
123	int idx = val & 0xFFFF;
124	if (idx < tbl.size) {
125		if (val & 0x01000000)
126			return tbl.data[idx];
127		else
128			return tbl.data[idx] + 3;
129	}
130	return 0;
131}
132EXPORT_SYMBOL(smd_rpc_get_sym);
133
134EOF
135	close $c_fp;
136}
137
138sub read_smd_rpc_table() {
139	my $fp;
140	my $line;
141	open($fp, "<", $in) or die  "$! File:$in";
142	while ($line = <$fp>) {
143		chomp($line);
144		if($line =~ /([^\s]+)\s+([\w]+)$/) {
145			if(defined $prog_table{$1}) {
146				print "Error entry already defined $1,",
147				      " in $prog_table{$1}{name} \n";
148			} else {
149				$prog_table{$1}{'name'}=$2;
150				$prog_table{$1}{'prog'}=$1;
151			}
152		} else {
153			if($line =~ /\w/) {
154				print "Error parsing error >>$line<< \n";
155			}
156		}
157	}
158	close $fp;
159}
160
161read_smd_rpc_table();
162smd_rpc_gen_files();