root/trunk/libffado/src/libieee1394/configrom.cpp

Revision 2673, 23.1 kB (checked in by jwoithe, 7 years ago)

libieee1394: fix incorrect comparisons when searching for the first zero byte in a string right-padded with zero bytes. Rather than comparing the string's characters, a pointer was compared instead. The problem came to light due to a warning from gcc7 as reported by Orcan Ogetbil. Thanks Orcan.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Copyright (C) 2005-2008 by Daniel Wagner
3  * Copyright (C) 2005-2008 by Jonathan Woithe
4  * Copyright (C) 2005-2008 by Pieter Palmers
5  *
6  * This file is part of FFADO
7  * FFADO = Free Firewire (pro-)audio drivers for linux
8  *
9  * FFADO is based upon FreeBoB
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 2 of the License, or
14  * (at your option) version 3 of the License.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  *
24  */
25
26 #include "config.h"
27
28 #include "configrom.h"
29 #include "ieee1394service.h"
30
31 #include "vendor_model_ids.h"
32
33 #include "libutil/SystemTimeSource.h"
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #include <iostream>
39 #include <iomanip>
40
41 using namespace std;
42
43 IMPL_DEBUG_MODULE( ConfigRom, ConfigRom, DEBUG_LEVEL_NORMAL );
44
45 static int busRead( struct csr1212_csr* csr,
46                     u_int64_t addr,
47                     u_int16_t length,
48                     void* buffer,
49                     void* private_data );
50
51 static int getMaxRom( u_int32_t* bus_info_data,
52                       void* private_data );
53
54 static struct csr1212_bus_ops configrom_csr1212_ops = {
55     busRead,
56     0,
57     0,
58     getMaxRom
59 };
60
61 struct config_csr_info {
62     Ieee1394Service* service;
63     fb_nodeid_t      nodeId;
64 };
65
66 //-------------------------------------------------------------
67
68 ConfigRom::ConfigRom( Ieee1394Service& ieee1394service, fb_nodeid_t nodeId )
69     : Control::Element(NULL, "ConfigRom")
70     , m_1394Service( ieee1394service )
71     , m_nodeId( nodeId )
72     , m_avcDevice( false ) // FIXME: this does not seem veryu
73     , m_guid( 0 )
74     , m_vendorName( "" )
75     , m_modelName( "" )
76     , m_vendorId( 0 )
77     , m_modelId( 0 )
78     , m_unit_specifier_id( 0 )
79     , m_unit_version( 0 )
80     , m_isIsoResourceManager( false )
81     , m_isCycleMasterCapable( false )
82     , m_isSupportIsoOperations( false )
83     , m_isBusManagerCapable( false )
84     , m_cycleClkAcc( 0 )
85     , m_maxRec( 0 )
86     , m_nodeVendorId( 0 )
87     , m_chipIdHi( 0 )
88     , m_chipIdLow( 0 )
89     , m_vendorNameKv( 0 )
90     , m_modelNameKv( 0 )
91     , m_csr( 0 )
92 {
93 }
94
95 ConfigRom::ConfigRom()
96     : Control::Element(NULL, "ConfigRom")
97     , m_1394Service( *(new Ieee1394Service()) )
98     , m_nodeId( -1 )
99     , m_avcDevice( false ) // FIXME: this does not seem veryu
100     , m_guid( 0 )
101     , m_vendorName( "" )
102     , m_modelName( "" )
103     , m_vendorId( 0 )
104     , m_modelId( 0 )
105     , m_unit_specifier_id( 0 )
106     , m_unit_version( 0 )
107     , m_isIsoResourceManager( false )
108     , m_isCycleMasterCapable( false )
109     , m_isSupportIsoOperations( false )
110     , m_isBusManagerCapable( false )
111     , m_cycleClkAcc( 0 )
112     , m_maxRec( 0 )
113     , m_nodeVendorId( 0 )
114     , m_chipIdHi( 0 )
115     , m_chipIdLow( 0 )
116     , m_vendorNameKv( 0 )
117     , m_modelNameKv( 0 )
118     , m_csr( 0 )
119 {
120 }
121
122 Ieee1394Service&
123 ConfigRom::get1394Service()
124 {
125     return m_1394Service;
126 }
127
128 bool
129 ConfigRom::operator == ( const ConfigRom& rhs )
130 {
131     return m_guid == rhs.m_guid;
132 }
133
134 bool
135 ConfigRom::compareGUID( const ConfigRom& a, const ConfigRom& b ) {
136     return a.getGuid() > b.getGuid();
137 }
138
139 bool
140 ConfigRom::initialize()
141 {
142      struct config_csr_info csr_info;
143      csr_info.service = &m_1394Service;
144      csr_info.nodeId = 0xffc0 | m_nodeId;
145
146      m_csr = csr1212_create_csr( &configrom_csr1212_ops,
147                                  5 * sizeof(fb_quadlet_t),   // XXX Why 5 ?!?
148                                  &csr_info );
149     if (!m_csr || csr1212_parse_csr( m_csr ) != CSR1212_SUCCESS) {
150         debugOutput(DEBUG_LEVEL_INFO, "Could not parse config rom of node %d on port %d\n", m_nodeId, m_1394Service.getPort() );
151         if (m_csr) {
152             csr1212_destroy_csr(m_csr);
153             m_csr = 0;
154         }
155         return false;
156     }
157
158     // Process Bus_Info_Block
159     m_isIsoResourceManager = CSR1212_BE32_TO_CPU(m_csr->bus_info_data[2] ) >> 31;
160     m_isCycleMasterCapable = ( CSR1212_BE32_TO_CPU(m_csr->bus_info_data[2] ) >> 30 ) & 0x1;
161     m_isSupportIsoOperations = ( CSR1212_BE32_TO_CPU(m_csr->bus_info_data[2] ) >> 29 ) & 0x1;
162     m_isBusManagerCapable = ( CSR1212_BE32_TO_CPU(m_csr->bus_info_data[2] ) >> 28 ) & 0x1;
163     m_cycleClkAcc = ( CSR1212_BE32_TO_CPU(m_csr->bus_info_data[2] ) >> 16 ) & 0xff;
164     m_maxRec = ( CSR1212_BE32_TO_CPU( m_csr->bus_info_data[2] ) >> 12 ) & 0xf;
165     m_nodeVendorId = ( CSR1212_BE32_TO_CPU( m_csr->bus_info_data[3] ) >> 8 );
166     m_chipIdHi = ( CSR1212_BE32_TO_CPU( m_csr->bus_info_data[3] ) ) & 0xff;
167     m_chipIdLow = CSR1212_BE32_TO_CPU( m_csr->bus_info_data[4] );
168
169     // Process Root Directory
170     processRootDirectory(m_csr);
171
172     if ( m_vendorNameKv ) {
173         int len = ( m_vendorNameKv->value.leaf.len - 2) * sizeof( quadlet_t );
174         char* buf = new char[len+2];
175         memcpy( buf,
176                 ( void* )CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA( m_vendorNameKv ),
177                 len );
178
179     while (*(buf + len - 1) == '\0') {
180             len--;
181         }
182         // \todo XXX seems a bit strage to do this but the nodemgr.c code does
183         // it. try to figure out why this is needed (or not)
184     buf[len++] = ' ';
185     buf[len] = '\0';
186
187
188         debugOutput( DEBUG_LEVEL_VERBOSE, "Vendor name: '%s'\n", buf );
189         m_vendorName = buf;
190         delete[] buf;
191     }
192     if ( m_modelNameKv ) {
193         int len = ( m_modelNameKv->value.leaf.len - 2) * sizeof( quadlet_t );
194         char* buf = new char[len+2];
195         memcpy( buf,
196                 ( void* )CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA( m_modelNameKv ),
197                 len );
198     while (*(buf + len - 1) == '\0') {
199             len--;
200         }
201         // \todo XXX for edirol fa-66 it seems somehow broken. see above
202         // todo as well.
203     buf[len++] = ' ';
204     buf[len] = '\0';
205
206         debugOutput( DEBUG_LEVEL_VERBOSE, "Model name: '%s'\n", buf);
207         m_modelName = buf;
208         delete[] buf;
209     }
210
211     m_guid = ((u_int64_t)CSR1212_BE32_TO_CPU(m_csr->bus_info_data[3]) << 32)
212              | CSR1212_BE32_TO_CPU(m_csr->bus_info_data[4]);
213
214     if ( m_vendorNameKv ) {
215         csr1212_release_keyval( m_vendorNameKv );
216         m_vendorNameKv = 0;
217     }
218     if ( m_modelNameKv ) {
219         csr1212_release_keyval( m_modelNameKv );
220         m_modelNameKv = 0;
221     }
222     if ( m_csr ) {
223         csr1212_destroy_csr(m_csr);
224         m_csr = 0;
225     }
226     return true;
227 }
228
229 static int
230 busRead( struct csr1212_csr* csr,
231          u_int64_t addr,
232          u_int16_t length,
233          void* buffer,
234          void* private_data )
235 {
236     struct config_csr_info* csr_info = (struct config_csr_info*) private_data;
237
238     int nb_retries = 5;
239
240     while ( nb_retries--
241             && !csr_info->service->read( csr_info->nodeId,
242                                          addr,
243                                          (size_t)length/4,
244                                          ( quadlet_t* )buffer)  )
245     {// failed, retry
246         Util::SystemTimeSource::SleepUsecRelative(IEEE1394SERVICE_CONFIGROM_READ_WAIT_USECS);
247     }
248     Util::SystemTimeSource::SleepUsecRelative(IEEE1394SERVICE_CONFIGROM_READ_WAIT_USECS);
249
250     if (nb_retries > -1) return 0; // success
251     else return -1; // failure
252 }
253
254 static int
255 getMaxRom( u_int32_t* bus_info_data,
256            void* /*private_data*/)
257 {
258     return (CSR1212_BE32_TO_CPU( bus_info_data[2] ) >> 8) & 0x3;
259 }
260
261
262 void
263 ConfigRom::processUnitDirectory( struct csr1212_csr* csr,
264                                  struct csr1212_keyval* ud_kv,
265                                  unsigned int *id )
266 {
267     struct csr1212_dentry *dentry;
268     struct csr1212_keyval *kv;
269     unsigned int last_key_id = 0;
270
271     debugOutput( DEBUG_LEVEL_VERBOSE, "process unit directory:\n" );
272     csr1212_for_each_dir_entry(csr, kv, ud_kv, dentry) {
273     switch (kv->key.id) {
274         case CSR1212_KV_ID_VENDOR:
275         if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) {
276                     debugOutput( DEBUG_LEVEL_VERBOSE,
277                                  "\tvendor_id = 0x%08x\n",
278                                  kv->value.immediate);
279                     m_vendorId = kv->value.immediate;
280         }
281         break;
282
283         case CSR1212_KV_ID_MODEL:
284                 debugOutput( DEBUG_LEVEL_VERBOSE,
285                              "\tmodel_id = 0x%08x\n",
286                              kv->value.immediate);
287                 m_modelId = kv->value.immediate;
288         break;
289
290         case CSR1212_KV_ID_SPECIFIER_ID:
291                 debugOutput( DEBUG_LEVEL_VERBOSE,
292                              "\tspecifier_id = 0x%08x\n",
293                              kv->value.immediate);
294                 m_unit_specifier_id = kv->value.immediate;
295         break;
296
297         case CSR1212_KV_ID_VERSION:
298                 debugOutput( DEBUG_LEVEL_VERBOSE,
299                              "\tversion = 0x%08x\n",
300                              kv->value.immediate);
301                 m_unit_version = kv->value.immediate;
302                 if ( m_unit_specifier_id == 0x0000a02d ) // XXX
303                 {
304                     m_avcDevice = true; // FIXME: disable this check for the moment
305                     if ( kv->value.immediate == 0x14001 ) {
306                         m_avcDevice = true;
307                     }
308                 }
309         break;
310
311         case CSR1212_KV_ID_DESCRIPTOR:
312         if (kv->key.type == CSR1212_KV_TYPE_LEAF &&
313             CSR1212_DESCRIPTOR_LEAF_TYPE(kv) == 0 &&
314             CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) == 0 &&
315             CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) == 0 &&
316             CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) == 0 &&
317             CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) == 0)
318         {
319             switch (last_key_id) {
320             case CSR1212_KV_ID_VENDOR:
321                 csr1212_keep_keyval(kv);
322                             m_vendorNameKv = kv;
323                 break;
324
325             case CSR1212_KV_ID_MODEL:
326                             m_modelNameKv = kv;
327                 csr1212_keep_keyval(kv);
328                 break;
329
330             }
331         } /* else if (kv->key.type == CSR1212_KV_TYPE_DIRECTORY) ... */
332         break;
333
334         case CSR1212_KV_ID_DEPENDENT_INFO:
335         if (kv->key.type == CSR1212_KV_TYPE_DIRECTORY) {
336             /* This should really be done in SBP2 as this is
337              * doing SBP2 specific parsing. */
338             processUnitDirectory(csr, kv, id);
339         }
340
341         break;
342
343         default:
344         break;
345     }
346     last_key_id = kv->key.id;
347     }
348 }
349
350 void
351 ConfigRom::processRootDirectory(struct csr1212_csr* csr)
352 {
353     unsigned int ud_id = 0;
354     struct csr1212_dentry *dentry;
355     struct csr1212_keyval *kv;
356     unsigned int last_key_id = 0;
357
358     csr1212_for_each_dir_entry(csr, kv, csr->root_kv, dentry) {
359     switch (kv->key.id) {
360         case CSR1212_KV_ID_VENDOR:
361                 debugOutput( DEBUG_LEVEL_VERBOSE,
362                              "vendor id = 0x%08x\n", kv->value.immediate);
363         break;
364
365         case CSR1212_KV_ID_NODE_CAPABILITIES:
366                 debugOutput( DEBUG_LEVEL_VERBOSE,
367                              "capabilities = 0x%08x\n", kv->value.immediate);
368         break;
369
370         case CSR1212_KV_ID_UNIT:
371         processUnitDirectory(csr, kv, &ud_id);
372         break;
373
374         case CSR1212_KV_ID_DESCRIPTOR:
375         if (last_key_id == CSR1212_KV_ID_VENDOR) {
376             if (kv->key.type == CSR1212_KV_TYPE_LEAF &&
377             CSR1212_DESCRIPTOR_LEAF_TYPE(kv) == 0 &&
378             CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) == 0 &&
379             CSR1212_TEXTUAL_DESCRIPTOR_LEAF_WIDTH(kv) == 0 &&
380             CSR1212_TEXTUAL_DESCRIPTOR_LEAF_CHAR_SET(kv) == 0 &&
381             CSR1212_TEXTUAL_DESCRIPTOR_LEAF_LANGUAGE(kv) == 0)
382                     {
383                         m_vendorNameKv = kv;
384             csr1212_keep_keyval(kv);
385             }
386         }
387         break;
388     }
389     last_key_id = kv->key.id;
390     }
391
392 }
393
394 const fb_nodeid_t
395 ConfigRom::getNodeId() const
396 {
397     return m_nodeId;
398 }
399
400 const fb_octlet_t
401 ConfigRom::getGuid() const
402 {
403     return m_guid;
404 }
405
406 const std::string
407 ConfigRom::getGuidString() const
408 {
409     char* buf;
410     asprintf( &buf, "%08x%08x",
411               ( unsigned int ) ( getGuid() >> 32 ),
412               ( unsigned int ) ( getGuid() & 0xffffffff ) );
413     std::string result = buf;
414     free( buf );
415     return result;
416 }
417  
418 const std::string
419 ConfigRom::getModelName() const
420 {
421     // HACK:
422     // workarounds for devices that don't fill a correct model name
423     switch(m_vendorId) {
424         case FW_VENDORID_MOTU:
425             switch(m_unit_specifier_id) {
426                 case 0x00000001:
427                     return "828MkI";
428                 case 0x00000003:
429                     return "828MkII";
430                 case 0x00000005:
431                     return "896HD";
432                 case 0x00000009:
433                     return "Traveler";
434                 case 0x0000000d:
435                     return "UltraLite";
436                 case 0x0000000f:
437                     return "8pre";
438                 case 0x00000015:
439                     return "828Mk3";
440                 case 0x00000017:
441                     return "896Mk3";
442                 case 0x00000019:
443                     return "UltraliteMk3";
444                 case 0x0000001b:
445                     return "TravelerMk3";
446                 case 0x00000021:
447                     return "V4HD subdevice 0";
448                 case 0x00000022:
449                     return "V4HD subdevice 1";
450                 case 0x00000023:
451                     return "V4HD subdevice 2";
452                 case 0x00000024:
453                     return "V4HD subdevice 3";
454                 case 0x00000030:
455                     return "UltraLiteMk3-hybrid";
456                 default:
457                     return "unknown";
458             }
459             break;
460         default:
461             break;
462     }
463     // Note: m_nodeVendorId is not the same as m_vendorId; some devices use
464     // one, others use the other.
465     switch (m_nodeVendorId) {
466         case FW_VENDORID_RME:
467             switch (m_unit_version) {
468                 case 0x0001:
469                     return "Fireface 800";
470                 case 0x0002:
471                     return "Fireface 400";
472                 default:
473                     return "unknown";
474             }
475             break;
476         default:
477             break;
478     }
479     return m_modelName;
480 }
481
482 const std::string
483 ConfigRom::getVendorName() const
484 {
485     // HACK:
486     // workarounds for devices that don't fill a correct vendor name
487     switch(m_vendorId) {
488         case FW_VENDORID_MOTU:
489             return "MOTU";
490         default:
491             break;
492     }
493     switch (m_nodeVendorId) {
494         case FW_VENDORID_RME:
495             return "RME";
496         default:
497             break;
498     }
499     return m_vendorName;
500 }
501
502 const unsigned int
503 ConfigRom::getModelId() const
504 {
505     return m_modelId;
506 }
507
508 const unsigned int
509 ConfigRom::getVendorId() const
510 {
511     return m_vendorId;
512 }
513
514 const unsigned int
515 ConfigRom::getUnitSpecifierId() const
516 {
517     return m_unit_specifier_id;
518 }
519
520 const unsigned int
521 ConfigRom::getUnitVersion() const
522 {
523     return m_unit_version;
524 }
525
526 bool
527 ConfigRom::updatedNodeId()
528 {
529     debugOutput( DEBUG_LEVEL_VERBOSE,
530                  "Checking for updated node id for device with GUID 0x%016" PRIX64 "...\n",
531                  getGuid());
532
533     struct csr1212_csr* csr = NULL;
534     for ( fb_nodeid_t nodeId = 0;
535           nodeId < m_1394Service.getNodeCount();
536           ++nodeId )
537     {
538         struct config_csr_info csr_info;
539         csr_info.service = &m_1394Service;
540         csr_info.nodeId = 0xffc0 | nodeId;
541         debugOutput( DEBUG_LEVEL_VERBOSE, "Looking at node %d...\n", nodeId);
542
543         csr = csr1212_create_csr( &configrom_csr1212_ops,
544                                   5 * sizeof(fb_quadlet_t),   // XXX Why 5 ?!?
545                                   &csr_info );
546
547         if (!csr || csr1212_parse_csr( csr ) != CSR1212_SUCCESS) {
548             debugWarning( "Failed to get/parse CSR\n");
549             if (csr) {
550                 csr1212_destroy_csr(csr);
551                 csr = NULL;
552             }
553             continue;
554         }
555
556         octlet_t guid =
557             ((u_int64_t)CSR1212_BE32_TO_CPU(csr->bus_info_data[3]) << 32)
558             | CSR1212_BE32_TO_CPU(csr->bus_info_data[4]);
559
560         debugOutput( DEBUG_LEVEL_VERBOSE,
561                         " Node has GUID 0x%016" PRIX64 "\n",
562                         guid);
563
564         if ( guid == getGuid() ) {
565             debugOutput( DEBUG_LEVEL_VERBOSE, "GUID matches ours\n");
566             if ( nodeId != getNodeId() ) {
567                 debugOutput( DEBUG_LEVEL_VERBOSE,
568                              "Device with GUID 0x%016" PRIX64 " changed node id "
569                              "from %d to %d\n",
570                              getGuid(),
571                              getNodeId(),
572                              nodeId );
573                 m_nodeId = nodeId;
574             } else {
575                 debugOutput( DEBUG_LEVEL_VERBOSE,
576                              "Device with GUID 0x%016" PRIX64 " kept node id %d\n",
577                              getGuid(),
578                              getNodeId());
579             }
580             if (csr) {
581                 csr1212_destroy_csr(csr);
582                 csr = NULL;
583             }
584             return true;
585         }
586     }
587
588     if (csr) {
589         csr1212_destroy_csr(csr);
590     }
591
592     debugOutput( DEBUG_LEVEL_VERBOSE,
593                  "Device with GUID 0x%016" PRIX64 " could not be found on "
594                  "the bus anymore (removed?)\n",
595                  getGuid() );
596     m_nodeId = INVALID_NODE_ID;
597     return false;
598 }
599
600 void
601 ConfigRom::printConfigRomDebug() const
602 {
603     using namespace std;
604     debugOutput(DEBUG_LEVEL_NORMAL, "Config ROM\n" );
605     debugOutput(DEBUG_LEVEL_NORMAL, "\tCurrent Node Id:\t%d\n",       getNodeId() );
606     debugOutput(DEBUG_LEVEL_NORMAL, "\tGUID:\t\t\t0x%016" PRIX64 "\n",       getGuid());
607     debugOutput(DEBUG_LEVEL_NORMAL, "\tVendor Name:\t\t%s\n",         getVendorName().c_str() );
608     debugOutput(DEBUG_LEVEL_NORMAL, "\tModel Name:\t\t%s\n",          getModelName().c_str() );
609     debugOutput(DEBUG_LEVEL_NORMAL, "\tNode Vendor ID:\t\t0x%06x\n",  getNodeVendorId() );
610     debugOutput(DEBUG_LEVEL_NORMAL, "\tModel Id:\t\t0x%08x\n",        getModelId() );
611     debugOutput(DEBUG_LEVEL_NORMAL, "\tUnit Specifier ID:\t0x%06x\n", getUnitSpecifierId() );
612     debugOutput(DEBUG_LEVEL_NORMAL, "\tUnit version:\t\t0x%08x\n",    getUnitVersion() );
613     debugOutput(DEBUG_LEVEL_NORMAL, "\tISO resource manager:\t%d\n",  isIsoResourseManager() );
614     debugOutput(DEBUG_LEVEL_NORMAL, "\tCycle master capable:\t%d\n",  isSupportsIsoOperations() );
615     debugOutput(DEBUG_LEVEL_NORMAL, "\tBus manager capable:\t%d\n",   isBusManagerCapable() );
616     debugOutput(DEBUG_LEVEL_NORMAL, "\tCycle clock accuracy:\t%d\n",  getCycleClockAccurancy() );
617     debugOutput(DEBUG_LEVEL_NORMAL, "\tMax rec:\t\t%d (max asy payload: %d bytes)\n",
618             getMaxRec(), getAsyMaxPayload() );
619 }
620
621 void
622 ConfigRom::printConfigRom() const
623 {
624     using namespace std;
625     printMessage("Config ROM\n" );
626     printMessage("\tCurrent Node Id:\t%d\n",       getNodeId() );
627     printMessage("\tGUID:\t\t\t0x%016" PRIX64 "\n",       getGuid());
628     printMessage("\tVendor Name:\t\t%s\n",         getVendorName().c_str() );
629     printMessage("\tModel Name:\t\t%s\n",          getModelName().c_str() );
630     printMessage("\tNode Vendor ID:\t\t0x%06x\n",  getNodeVendorId() );
631     printMessage("\tModel Id:\t\t0x%08x\n",        getModelId() );
632     printMessage("\tUnit Specifier ID:\t0x%06x\n", getUnitSpecifierId() );
633     printMessage("\tUnit version:\t\t0x%08x\n",    getUnitVersion() );
634     printMessage("\tISO resource manager:\t%d\n",  isIsoResourseManager() );
635     printMessage("\tCycle master capable:\t%d\n",  isSupportsIsoOperations() );
636     printMessage("\tBus manager capable:\t%d\n",   isBusManagerCapable() );
637     printMessage("\tCycle clock accuracy:\t%d\n",  getCycleClockAccurancy() );
638     printMessage("\tMax rec:\t\t%d (max asy payload: %d bytes)\n", getMaxRec(), getAsyMaxPayload() );
639 }
640
641 unsigned short
642 ConfigRom::getAsyMaxPayload() const
643 {
644     // XXX use pow instead?
645     return 1 << ( m_maxRec + 1 );
646 }
647
648 bool
649 ConfigRom::serialize( std::string path, Util::IOSerialize& ser )
650 {
651     bool result;
652     result  = ser.write( path + "m_nodeId", m_nodeId );
653     result &= ser.write( path + "m_avcDevice",  m_avcDevice );
654     result &= ser.write( path + "m_guid", m_guid );
655     result &= ser.write( path + "m_vendorName", std::string( m_vendorName ) );
656     result &= ser.write( path + "m_modelName", std::string( m_modelName ) );
657     result &= ser.write( path + "m_vendorId", m_vendorId );
658     result &= ser.write( path + "m_modelId", m_modelId );
659     result &= ser.write( path + "m_unit_specifier_id", m_unit_specifier_id );
660     result &= ser.write( path + "m_unit_version",  m_unit_version );
661     result &= ser.write( path + "m_isIsoResourceManager", m_isIsoResourceManager );
662     result &= ser.write( path + "m_isCycleMasterCapable", m_isCycleMasterCapable );
663     result &= ser.write( path + "m_isSupportIsoOperations", m_isSupportIsoOperations );
664     result &= ser.write( path + "m_isBusManagerCapable", m_isBusManagerCapable );
665     result &= ser.write( path + "m_cycleClkAcc", m_cycleClkAcc );
666     result &= ser.write( path + "m_maxRec", m_maxRec );
667     result &= ser.write( path + "m_nodeVendorId", m_nodeVendorId );
668     result &= ser.write( path + "m_chipIdHi", m_chipIdHi );
669     result &= ser.write( path + "m_chipIdLow", m_chipIdLow );
670     return result;
671 }
672
673 ConfigRom*
674 ConfigRom::deserialize( std::string path, Util::IODeserialize& deser, Ieee1394Service& ieee1394Service )
675 {
676     ConfigRom* pConfigRom = new ConfigRom;
677     if ( !pConfigRom ) {
678         return 0;
679     }
680
681     pConfigRom->m_1394Service = ieee1394Service;
682
683     bool result;
684     result  = deser.read( path + "m_nodeId", pConfigRom->m_nodeId );
685     result &= deser.read( path + "m_avcDevice", pConfigRom->m_avcDevice );
686     result &= deser.read( path + "m_guid", pConfigRom->m_guid );
687     result &= deser.read( path + "m_vendorName", pConfigRom->m_vendorName );
688     result &= deser.read( path + "m_modelName", pConfigRom->m_modelName );
689     result &= deser.read( path + "m_vendorId", pConfigRom->m_vendorId );
690     result &= deser.read( path + "m_modelId", pConfigRom->m_modelId );
691     result &= deser.read( path + "m_unit_specifier_id", pConfigRom->m_unit_specifier_id );
692     result &= deser.read( path + "m_unit_version", pConfigRom->m_unit_version );
693     result &= deser.read( path + "m_isIsoResourceManager", pConfigRom->m_isIsoResourceManager );
694     result &= deser.read( path + "m_isCycleMasterCapable", pConfigRom->m_isCycleMasterCapable );
695     result &= deser.read( path + "m_isSupportIsoOperations", pConfigRom->m_isSupportIsoOperations );
696     result &= deser.read( path + "m_isBusManagerCapable", pConfigRom->m_isBusManagerCapable );
697     result &= deser.read( path + "m_cycleClkAcc", pConfigRom->m_cycleClkAcc );
698     result &= deser.read( path + "m_maxRec", pConfigRom->m_maxRec );
699     result &= deser.read( path + "m_nodeVendorId", pConfigRom->m_nodeVendorId );
700     result &= deser.read( path + "m_chipIdHi", pConfigRom->m_chipIdHi );
701     result &= deser.read( path + "m_chipIdLow", pConfigRom->m_chipIdLow );
702
703     if ( !result ) {
704         delete pConfigRom;
705         return 0;
706     }
707
708     return pConfigRom;
709 }
710
711 bool
712 ConfigRom::setNodeId( fb_nodeid_t nodeId )
713 {
714     m_nodeId = nodeId;
715     return true;
716 }
Note: See TracBrowser for help on using the browser.