Browse Source

[susieq] Update qib_genbits.pl to handle SusieQ definitions

The latest RTL-generated register lists include (mostly redundant)
xxx_MSB values alongside xxx_LSB and xxx_RMASK, and also include
default register values.
tags/v1.0.0-rc1
Michael Brown 15 years ago
parent
commit
ef0e76811b
1 changed files with 24 additions and 4 deletions
  1. 24
    4
      src/drivers/infiniband/qib_genbits.pl

+ 24
- 4
src/drivers/infiniband/qib_genbits.pl View File

20
 use warnings;
20
 use warnings;
21
 
21
 
22
 my $offsets = {};
22
 my $offsets = {};
23
+my $defaults = {};
23
 my $structures = {};
24
 my $structures = {};
24
 my $structure = "";
25
 my $structure = "";
25
 
26
 
28
   if ( /^\#define (\S+)_OFFS (\S+)$/ ) {
29
   if ( /^\#define (\S+)_OFFS (\S+)$/ ) {
29
     $structure = $1;
30
     $structure = $1;
30
     $offsets->{$structure} = $2;
31
     $offsets->{$structure} = $2;
32
+  } elsif ( /^\#define ${structure}_DEF (\S+)$/ ) {
33
+    $defaults->{$structure} = $1;
31
   } elsif ( /^\#define ${structure}_(\S+)_LSB (\S+)$/ ) {
34
   } elsif ( /^\#define ${structure}_(\S+)_LSB (\S+)$/ ) {
32
     $structures->{$structure}->{$1}->{LSB} = $2;
35
     $structures->{$structure}->{$1}->{LSB} = $2;
36
+  } elsif ( /^\#define ${structure}_(\S+)_MSB (\S+)$/ ) {
37
+    $structures->{$structure}->{$1}->{MSB} = $2;
33
   } elsif ( /^\#define ${structure}_(\S+)_RMASK (\S+)$/ ) {
38
   } elsif ( /^\#define ${structure}_(\S+)_RMASK (\S+)$/ ) {
34
     $structures->{$structure}->{$1}->{RMASK} = $2;
39
     $structures->{$structure}->{$1}->{RMASK} = $2;
35
   } elsif ( /^\s*$/ ) {
40
   } elsif ( /^\s*$/ ) {
39
   }
44
   }
40
 }
45
 }
41
 
46
 
42
-my $data = [ map { { name => $_, offset => $offsets->{$_} }; }
47
+my $data = [ map { { name => $_, offset => $offsets->{$_},
48
+		     default => $defaults->{$_} }; }
43
 	     sort { hex ( $offsets->{$a} ) <=> hex ( $offsets->{$b} ) }
49
 	     sort { hex ( $offsets->{$a} ) <=> hex ( $offsets->{$b} ) }
44
 	     keys %$offsets ];
50
 	     keys %$offsets ];
45
 
51
 
47
   next unless exists $structures->{$datum->{name}};
53
   next unless exists $structures->{$datum->{name}};
48
   $structure = $structures->{$datum->{name}};
54
   $structure = $structures->{$datum->{name}};
49
   my $fields = [ map { { name => $_, lsb => $structure->{$_}->{LSB},
55
   my $fields = [ map { { name => $_, lsb => $structure->{$_}->{LSB},
56
+			 msb => $structure->{$_}->{MSB},
50
 			 rmask => $structure->{$_}->{RMASK} }; }
57
 			 rmask => $structure->{$_}->{RMASK} }; }
51
 		 sort { hex ( $structure->{$a}->{LSB} ) <=>
58
 		 sort { hex ( $structure->{$a}->{LSB} ) <=>
52
 			    hex ( $structure->{$b}->{LSB} ) }
59
 			    hex ( $structure->{$b}->{LSB} ) }
54
   $datum->{fields} = $fields;
61
   $datum->{fields} = $fields;
55
 }
62
 }
56
 
63
 
57
-print "\n/* This file has been further processed by $0 */\n\n"
64
+print "\n/* This file has been further processed by $0 */\n\n";
58
 print "FILE_LICENCE ( GPL2_ONLY );\n\n";
65
 print "FILE_LICENCE ( GPL2_ONLY );\n\n";
59
 
66
 
60
 foreach my $datum ( @$data ) {
67
 foreach my $datum ( @$data ) {
66
     printf "struct %s_pb {\n", $datum->{name};
73
     printf "struct %s_pb {\n", $datum->{name};
67
     foreach my $field ( @{$datum->{fields}} ) {
74
     foreach my $field ( @{$datum->{fields}} ) {
68
       my $pad_width = ( hex ( $field->{lsb} ) - $lsb );
75
       my $pad_width = ( hex ( $field->{lsb} ) - $lsb );
69
-      die "Inconsistent LSB/RMASK in $datum->{name}\n" if $pad_width < 0;
76
+      die "Inconsistent LSB/RMASK in $datum->{name} before $field->{name}\n"
77
+	  if $pad_width < 0;
70
       printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
78
       printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
71
 	  if $pad_width;
79
 	  if $pad_width;
80
+      $lsb += $pad_width;
72
       # Damn Perl can't cope with 64-bit hex constants
81
       # Damn Perl can't cope with 64-bit hex constants
73
       my $width = 0;
82
       my $width = 0;
83
+      die "Missing RMASK in $datum->{name}.$field->{name}\n"
84
+	  unless defined $field->{rmask};
74
       my $rmask = $field->{rmask};
85
       my $rmask = $field->{rmask};
75
       while ( $rmask =~ /^(0x.+)f$/i ) {
86
       while ( $rmask =~ /^(0x.+)f$/i ) {
76
 	$width += 4;
87
 	$width += 4;
81
 	$width++;
92
 	$width++;
82
 	$rmask >>= 1;
93
 	$rmask >>= 1;
83
       }
94
       }
95
+      if ( defined $field->{msb} ) {
96
+	my $msb_width = ( hex ( $field->{msb} ) - $lsb + 1 );
97
+	$width ||= $msb_width;
98
+	die "Inconsistent LSB/MSB/RMASK in $datum->{name}.$field->{name}\n"
99
+	    unless $width == $msb_width;
100
+      }
84
       printf "\tpseudo_bit_t %s[%u];\n", $field->{name}, $width;
101
       printf "\tpseudo_bit_t %s[%u];\n", $field->{name}, $width;
85
       $lsb += $width;
102
       $lsb += $width;
86
     }
103
     }
87
     my $pad_width = ( 64 - $lsb );
104
     my $pad_width = ( 64 - $lsb );
88
-    die "Inconsistent LSB/RMASK in $datum->{name}\n" if $pad_width < 0;
105
+    die "Inconsistent LSB/RMASK in $datum->{name} final field\n"
106
+	if $pad_width < 0;
89
     printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
107
     printf "\tpseudo_bit_t _unused_%u[%u];\n", $reserved_idx++, $pad_width
90
 	if $pad_width;
108
 	if $pad_width;
91
     printf "};\n";
109
     printf "};\n";
92
     printf "struct %s {\n\tPSEUDO_BIT_STRUCT ( struct %s_pb );\n};\n",
110
     printf "struct %s {\n\tPSEUDO_BIT_STRUCT ( struct %s_pb );\n};\n",
93
 	$datum->{name}, $datum->{name};
111
 	$datum->{name}, $datum->{name};
94
   }
112
   }
113
+  printf "/* Default value: %s */\n", $datum->{default}
114
+      if defined $datum->{default};
95
   print "\n";
115
   print "\n";
96
 }
116
 }

Loading…
Cancel
Save