MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / nios2nommu / scripts / PTF / SystemPTF / Module.pm
blob48d246b2f22838a051fb8f78b95f21a8d68aa984
1 package Module;
3 use PTF::PTFSection;
5 sub new {
6 my $invocant = shift;
7 my $class = ref($invocant) || $invocant;
8 my $self = {
9 @_,
12 # if no ptf section was passed in, then return undef
13 $self->{ptf} or return;
15 bless ($self, $class);
16 return $self;
19 sub getClass {
20 my ($self) = @_;
22 return $self->{ptf}->getAssignment ('class');
25 sub getPorts {
26 my ($self) = @_;
28 my @port_names;
30 my @ports = $self->{ptf}->getSections ('SLAVE');
31 foreach $port (@ports) {
32 push @port_names, $port->name;
35 return @port_names;
38 sub getPort {
39 my ($self, $port_name) = @_;
41 my $port;
43 if (! $port_name) {
44 # use first port found
45 my @port_names = $self->getPorts ();
46 $port = $self->{ptf}->getSection ('SLAVE', $port_names[0]);
47 } else {
48 $port = $self->{ptf}->getSection ('SLAVE', $port_name);
49 if (! $port) {
50 # return undef if the PTF section doesn't exist
51 return;
55 return $port;
58 sub getWSAAssignment {
59 my ($self, $assignment) = @_;
61 my $WSA = $self->{ptf}->getSection ('WIZARD_SCRIPT_ARGUMENTS', '');
62 if (! $WSA) {
63 # return undef if the WSA section doesn't exist.
64 return;
67 my $result = $WSA->getAssignment ($assignment);
69 return $result;
73 sub getWSAConstant {
74 my ($self, $name) = @_;
76 my $WSA = $self->{ptf}->getSection ('WIZARD_SCRIPT_ARGUMENTS', '');
77 if (! $WSA) {
78 # return undef if the WSA section doesn't exist.
79 return;
82 my $constants = $WSA->getSection ('CONSTANTS', '');
83 if (! $constants) {
84 # return undef if the CONSTANTS section doesn't exist.
85 return;
88 my $constant = $constants->getSection ('CONSTANT', $name);
89 if (! $constant) {
90 # return undef if the CONSTANT $name section doesn't exist.
91 return;
94 my $result = $constant->getAssignment ('value');
95 return $result;
99 sub isMemoryDevice {
100 my ($self, $port_name) = @_;
102 my $port = $self->getPort ($port_name);
103 if (! $port) {
104 # return undef if the PTF section doesn't exist
105 return;
108 my $SBI = $port->getSection('SYSTEM_BUILDER_INFO', '');
109 if (! $SBI) {
110 # return undef if the PTF section doesn't exist
111 return;
114 my $result = $SBI->getAssignment('Is_Memory_Device');
116 return $result;
119 sub isCustomInstruction {
120 my ($self, $port_name) = @_;
122 my $port = $self->getPort ($port_name);
123 if (! $port) {
124 # return undef if the PTF section doesn't exist
125 return;
128 my $SBI = $port->getSection('SYSTEM_BUILDER_INFO', '');
129 if (! $SBI) {
130 # return undef if the PTF section doesn't exist
131 return;
134 my $result = $SBI->getAssignment('Is_Custom_Instruction');
136 return $result;
139 sub getBaseAddress {
140 my ($self, $port_name) = @_;
142 my $port = $self->getPort ($port_name);
143 if (! $port) {
144 # return undef if the PTF section doesn't exist
145 return;
148 my $SBI = $port->getSection('SYSTEM_BUILDER_INFO', '');
149 if (! $SBI) {
150 # return undef if the PTF section doesn't exist
151 return;
154 my $result = $SBI->getAssignment('Base_Address');
155 if ($result eq 'N/A') {
156 return;
158 return $result;
161 sub getSize {
162 my ($self, $port_name) = @_;
164 my $port = $self->getPort ($port_name);
165 $port or return; #return undef if the ptf section doesn't exist
167 my $SBI = $port->getSection ('SYSTEM_BUILDER_INFO', '');
168 my $data_width = $SBI->getAssignment ('Data_Width');
169 my $addr_width = $SBI->getAssignment ('Address_Width');
171 if ($data_width == 8) {
172 $size = 1 << $addr_width;
173 } elsif ($data_width == 16) {
174 $size = 1 << ($addr_width + 1);
175 } elsif ($data_width == 32) {
176 $size = 1 << ($addr_width + 2);
177 } elsif ($data_width == 64) {
178 $size = 1 << ($addr_width + 3);
179 } elsif ($data_width == 128) {
180 $size = 1 << ($addr_width + 4);
181 } else {
182 return;
185 $size_text = sprintf ("%#010x", $size);
186 return $size_text;
189 sub getIRQ {
190 my ($self, $port_name) = @_;
192 my $port = $self->getPort ($port_name);
193 if (! $port) {
194 # return undef if the PTF section doesn't exist
195 return;
198 my $SBI = $port->getSection('SYSTEM_BUILDER_INFO', '');
199 if (! $SBI) {
200 # return undef if the PTF section doesn't exist
201 return;
204 my $result = $SBI->getAssignment('Has_IRQ');
205 if ($result ne "1") {
206 # this device has no associated IRQ
207 return;
210 my @irq_masters = $SBI->getSections('IRQ_MASTER');
211 return $irq_masters[0]->getAssignment('IRQ_Number');
214 sub getMasters {
215 my ($self, $type) = @_;
216 my %masters = ();
218 # get list of all slave for device
219 my @slaves = $self->{ptf}->getSections ('SLAVE');
221 # get list of masters of relevant type for all slaves
222 foreach my $slave (@slaves) {
223 # get SBI for slave
224 my $SBI = $slave->getSection ('SYSTEM_BUILDER_INFO', '');
226 # get list of all MASTERED_BY and IRQ_MASTER sections
227 my @mastered_bys = $SBI->getSections ('MASTERED_BY');
228 my @irq_masters = $SBI->getSections ('IRQ_MASTER');
230 # start adding masters to the list
231 foreach my $master (@mastered_bys, @irq_masters) {
232 my $section_name = $master->name;
233 $section_name =~ /(.*)\/(.*)/;
234 my $master_name = $1;
235 my $master_type = $2;
237 if (! $type) {
238 $masters{$master_name} = ();
239 } else {
240 if ($master_type eq $type) {
241 $masters{$master_name} = ();
249 return keys (%masters);
252 sub isEnabled {
253 my ($self) = @_;
255 $sbi = $self->{ptf}->getSection('SYSTEM_BUILDER_INFO', '');
256 $sbi or return;
258 my $enabled = $sbi->getAssignment ('Is_Enabled');
259 if ($enabled eq "1") {
260 return 1;
261 } else {
262 return 0;