root/trunk/libffado/src/dice/dice_avdevice.h

Revision 1655, 20.2 kB (checked in by arnonym, 15 years ago)

Thinking about getting structured info about the router-channels.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef DICEDEVICE_H
25 #define DICEDEVICE_H
26
27 #include "ffadodevice.h"
28
29 #include "debugmodule/debugmodule.h"
30 #include "libavc/avc_definitions.h"
31
32 #include "libstreaming/amdtp/AmdtpReceiveStreamProcessor.h"
33 #include "libstreaming/amdtp/AmdtpTransmitStreamProcessor.h"
34 #include "libstreaming/amdtp/AmdtpPort.h"
35
36 #include "libieee1394/ieee1394service.h"
37
38 #include "libcontrol/Element.h"
39 #include "libcontrol/MatrixMixer.h"
40 #include "libcontrol/CrossbarRouter.h"
41
42 #include "dice_eap.h"
43
44 #include <string>
45 #include <vector>
46
47 class ConfigRom;
48 class Ieee1394Service;
49
50 namespace Util {
51     class Configuration;
52 }
53
54 namespace Dice {
55
56 class Notifier;
57
58 class Device : public FFADODevice {
59 // private:
60     typedef std::vector< std::string > diceNameVector;
61     typedef std::vector< std::string >::iterator diceNameVectorIterator;
62
63 public:
64     class Notifier;
65     class EAP;
66
67     /**
68      * this class represents the EAP interface
69      * available on some devices
70      */
71     class EAP : public Control::Container
72     {
73     public:
74         enum eWaitReturn {
75             eWR_Error,
76             eWR_Timeout,
77             eWR_Busy,
78             eWR_Done,
79         };
80         enum eRegBase {
81             eRT_Base,
82             eRT_Capability,
83             eRT_Command,
84             eRT_Mixer,
85             eRT_Peak,
86             eRT_NewRouting,
87             eRT_NewStreamCfg,
88             eRT_CurrentCfg,
89             eRT_Standalone,
90             eRT_Application,
91             eRT_None,
92         };
93         enum eRouteSource {
94             eRS_AES = 0,
95             eRS_ADAT = 1,
96             eRS_Mixer = 2,
97             eRS_InS0 = 4,
98             eRS_InS1 = 5,
99             eRS_ARM = 10,
100             eRS_ARX0 = 11,
101             eRS_ARX1 = 12,
102             eRS_Muted = 15,
103             eRS_Invalid = 16,
104         };
105         enum eRouteDestination {
106             eRD_AES = 0,
107             eRD_ADAT = 1,
108             eRD_Mixer0 = 2,
109             eRD_Mixer1 = 3,
110             eRD_InS0 = 4,
111             eRD_InS1 = 5,
112             eRD_ARM = 10,
113             eRD_ATX0 = 11,
114             eRD_ATX1 = 12,
115             eRD_Muted = 15,
116             eRD_Invalid = 16,
117         };
118
119     public:
120
121         // ----------
122         class RouterConfig {
123         public:
124             struct Route
125             {
126                 enum eRouteSource src;
127                 int srcChannel;
128                 enum eRouteDestination dst;
129                 int dstChannel;
130                 int peak;
131             };
132             typedef std::vector<RouterConfig::Route> RouteVector;
133             typedef std::vector<RouterConfig::Route>::iterator RouteVectorIterator;
134             RouterConfig(EAP &);
135             RouterConfig(EAP &, enum eRegBase, unsigned int offset);
136             virtual ~RouterConfig();
137
138             virtual bool read() {return read(m_base, m_offset);};
139             virtual bool write() {return write(m_base, m_offset);};
140             virtual bool read(enum eRegBase b, unsigned offset);
141             virtual bool write(enum eRegBase b, unsigned offset);
142             virtual void show();
143
144
145             bool insertRoute(struct Route r)
146                 {return insertRoute(r, m_routes.size());};
147             bool insertRoute(struct Route r, unsigned int index);
148             bool replaceRoute(unsigned int old_index, struct Route new_route);
149             bool replaceRoute(struct Route old_route, struct Route new_route);
150             bool removeRoute(struct Route r);
151             bool removeRoute(unsigned int index);
152             int getRouteIndex(struct Route r);
153             struct Route getRoute(unsigned int index);
154
155             unsigned int getNbRoutes() {return m_routes.size();};
156
157             struct Route getRouteForDestination(enum eRouteDestination dst, int channel);
158             RouteVector getRoutesForSource(enum eRouteSource src, int channel);
159
160             struct Route decodeRoute(uint32_t val);
161             uint32_t encodeRoute(struct Route r);
162         public:
163             static enum eRouteDestination intToRouteDestination(int);
164             static enum eRouteSource intToRouteSource(int);
165         protected:
166             EAP &m_eap;
167             enum eRegBase m_base;
168             unsigned int m_offset;
169             RouteVector m_routes;
170         protected:
171             DECLARE_DEBUG_MODULE_REFERENCE;
172         };
173
174         // ----------
175         // the peak space is a special version of a router config
176         class PeakSpace : public RouterConfig {
177         public:
178             PeakSpace(EAP &p) : RouterConfig(p, eRT_Peak, 0) {};
179             virtual ~PeakSpace() {};
180
181             virtual bool read() {return read(m_base, m_offset);};
182             virtual bool write() {return write(m_base, m_offset);};
183             virtual bool read(enum eRegBase b, unsigned offset);
184             virtual bool write(enum eRegBase b, unsigned offset);
185             virtual void show();
186         };
187
188         // ----------
189         class StreamConfig {
190         public:
191             struct ConfigBlock { // FIXME: somewhere in the DICE avdevice this is present too
192                 uint32_t nb_audio;
193                 uint32_t nb_midi;
194                 uint32_t names[DICE_EAP_CHANNEL_CONFIG_NAMESTR_LEN_QUADS];
195                 uint32_t ac3_map;
196             };
197             void showConfigBlock(struct ConfigBlock &);
198             diceNameVector getNamesForBlock(struct ConfigBlock &b);
199         public:
200             StreamConfig(EAP &, enum eRegBase, unsigned int offset);
201             ~StreamConfig();
202
203             bool read() {return read(m_base, m_offset);};
204             bool write() {return write(m_base, m_offset);};
205             bool read(enum eRegBase b, unsigned offset);
206             bool write(enum eRegBase b, unsigned offset);
207
208             void show();
209
210         private:
211             EAP &m_eap;
212             enum eRegBase m_base;
213             unsigned int m_offset;
214
215             uint32_t m_nb_tx;
216             uint32_t m_nb_rx;
217
218             struct ConfigBlock *m_tx_configs;
219             struct ConfigBlock *m_rx_configs;
220
221             DECLARE_DEBUG_MODULE_REFERENCE;
222         };
223
224     public: // mixer control subclass
225         class Mixer : public Control::MatrixMixer {
226         public:
227             Mixer(EAP &);
228             ~Mixer();
229
230             bool init();
231             void show();
232
233             void updateNameCache();
234             /**
235              * load the coefficients from the device into the local cache
236              * @return
237              */
238             bool loadCoefficients();
239             /**
240              * Stores the coefficients from the cache to the device
241              * @return
242              */
243             bool storeCoefficients();
244
245             virtual std::string getRowName( const int );
246             virtual std::string getColName( const int );
247             virtual int canWrite( const int, const int );
248             virtual double setValue( const int, const int, const double );
249             virtual double getValue( const int, const int );
250             virtual int getRowCount( );
251             virtual int getColCount( );
252        
253             // full map updates are unsupported
254             virtual bool getCoefficientMap(int &);
255             virtual bool storeCoefficientMap(int &);
256
257         private:
258             EAP &         m_eap;
259             fb_quadlet_t *m_coeff;
260
261             std::map<int, RouterConfig::Route> m_input_route_map;
262             std::map<int, RouterConfig::RouteVector> m_output_route_map;
263
264             DECLARE_DEBUG_MODULE_REFERENCE;
265         };
266
267         // ----------
268         class Router : public Control::CrossbarRouter {
269         private:
270             struct Source {
271                 std::string name;
272                 enum eRouteSource src;
273                 int srcChannel;
274             };
275             typedef std::vector<Source> SourceVector;
276             typedef std::vector<Source>::iterator SourceVectorIterator;
277
278             struct Destination {
279                 std::string name;
280                 enum eRouteDestination dst;
281                 int dstChannel;
282             };
283             typedef std::vector<Destination> DestinationVector;
284             typedef std::vector<Destination>::iterator DestinationVectorIterator;
285
286         public:
287             Router(EAP &);
288             ~Router();
289
290             void show();
291
292             // to be subclassed by the implementing
293             // devices
294             virtual void setupSources();
295             virtual void setupDestinations();
296
297             void setupDestinationsAddDestination(const char *name, enum eRouteDestination dstid,
298                                                  unsigned int base, unsigned int cnt);
299             void setupSourcesAddSource(const char *name, enum eRouteSource srcid,
300                                        unsigned int base, unsigned int cnt);
301
302             int getDestinationIndex(enum eRouteDestination dstid, int channel);
303             int getSourceIndex(enum eRouteSource srcid, int channel);
304
305             // per-coefficient access
306             virtual std::string getSourceName(const int);
307             virtual std::string getDestinationName(const int);
308             virtual int getSourceIndex(std::string);
309             virtual int getDestinationIndex(std::string);
310             virtual NameVector getSourceNames();
311             virtual NameVector getDestinationNames();
312
313             virtual Control::CrossbarRouter::Groups getSources();
314             virtual Control::CrossbarRouter::Groups getDestinations();
315
316             virtual IntVector getDestinationsForSource(const int);
317             virtual int getSourceForDestination(const int);
318
319             virtual bool canConnect( const int source, const int dest);
320             virtual bool setConnectionState( const int source, const int dest, const bool enable);
321             virtual bool getConnectionState( const int source, const int dest );
322
323             virtual bool canConnect(std::string, std::string);
324             virtual bool setConnectionState(std::string, std::string, const bool enable);
325             virtual bool getConnectionState(std::string, std::string);
326
327             virtual bool clearAllConnections();
328
329             virtual int getNbSources();
330             virtual int getNbDestinations();
331
332             // functions to access the entire routing map at once
333             // idea is that the row/col nodes that are 1 get a routing entry
334             virtual bool getConnectionMap(int *);
335             virtual bool setConnectionMap(int *);
336
337             // peak metering support
338             virtual bool hasPeakMetering();
339             virtual bool getPeakValues(double &) {return false;};
340             virtual double getPeakValue(const int source, const int dest);
341             virtual Control::CrossbarRouter::PeakValues getPeakValues();
342
343         private:
344             EAP &m_eap;
345             // these contain the sources and destinations available for this
346             // router
347             SourceVector      m_sources;
348             DestinationVector m_destinations;
349
350             PeakSpace &m_peak;
351
352             DECLARE_DEBUG_MODULE_REFERENCE;
353         };
354
355     public:
356         EAP(Device &);
357         virtual ~EAP();
358
359         static bool supportsEAP(Device &);
360         bool init();
361
362         void show();
363         enum eWaitReturn operationBusy();
364         enum eWaitReturn waitForOperationEnd(int max_wait_time_ms = 100);
365
366         bool updateConfigurationCache();
367         RouterConfig * getActiveRouterConfig();
368         StreamConfig * getActiveStreamConfig();
369
370         bool updateRouterConfig(RouterConfig&, bool low, bool mid, bool high);
371         bool updateCurrentRouterConfig(RouterConfig&);
372         bool updateStreamConfig(StreamConfig&, bool low, bool mid, bool high);
373         bool updateStreamConfig(RouterConfig&, StreamConfig&, bool low, bool mid, bool high);
374
375         bool loadFlashConfig();
376         bool storeFlashConfig();
377
378     private:
379         bool loadRouterConfig(bool low, bool mid, bool high);
380         bool loadStreamConfig(bool low, bool mid, bool high);
381         bool loadRouterAndStreamConfig(bool low, bool mid, bool high);
382     private:
383         bool     m_router_exposed;
384         bool     m_router_readonly;
385         bool     m_router_flashstored;
386         uint16_t m_router_nb_entries;
387
388         bool     m_mixer_exposed;
389         bool     m_mixer_readonly;
390         bool     m_mixer_flashstored;
391         uint8_t  m_mixer_tx_id;
392         uint8_t  m_mixer_rx_id;
393         uint8_t  m_mixer_nb_tx;
394         uint8_t  m_mixer_nb_rx;
395
396         bool     m_general_support_dynstream;
397         bool     m_general_support_flash;
398         bool     m_general_peak_enabled;
399         uint8_t  m_general_max_tx;
400         uint8_t  m_general_max_rx;
401         bool     m_general_stream_cfg_stored;
402         uint16_t m_general_chip;
403
404         bool commandHelper(fb_quadlet_t cmd);
405
406         bool readReg(enum eRegBase, unsigned offset, quadlet_t *);
407         bool writeReg(enum eRegBase, unsigned offset, quadlet_t);
408         bool readRegBlock(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
409         bool writeRegBlock(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
410         bool readRegBlockSwapped(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
411         bool writeRegBlockSwapped(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
412         fb_nodeaddr_t offsetGen(enum eRegBase, unsigned, size_t);
413
414     private:
415         DECLARE_DEBUG_MODULE_REFERENCE;
416
417     private:
418         Device & m_device;
419         Mixer*   m_mixer;
420         Router*  m_router;
421         RouterConfig m_current_cfg_routing_low;
422         RouterConfig m_current_cfg_routing_mid;
423         RouterConfig m_current_cfg_routing_high;
424         StreamConfig m_current_cfg_stream_low;
425         StreamConfig m_current_cfg_stream_mid;
426         StreamConfig m_current_cfg_stream_high;
427     public:
428         Mixer*  getMixer() {return m_mixer;};
429         Router* getRouter() {return m_router;};
430
431     private:
432
433         fb_quadlet_t m_capability_offset;
434         fb_quadlet_t m_capability_size;
435         fb_quadlet_t m_cmd_offset;
436         fb_quadlet_t m_cmd_size;
437         fb_quadlet_t m_mixer_offset;
438         fb_quadlet_t m_mixer_size;
439         fb_quadlet_t m_peak_offset;
440         fb_quadlet_t m_peak_size;
441         fb_quadlet_t m_new_routing_offset;
442         fb_quadlet_t m_new_routing_size;
443         fb_quadlet_t m_new_stream_cfg_offset;
444         fb_quadlet_t m_new_stream_cfg_size;
445         fb_quadlet_t m_curr_cfg_offset;
446         fb_quadlet_t m_curr_cfg_size;
447         fb_quadlet_t m_standalone_offset;
448         fb_quadlet_t m_standalone_size;
449         fb_quadlet_t m_app_offset;
450         fb_quadlet_t m_app_size;
451     };
452
453 public:
454     Device( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
455     ~Device();
456
457     static bool probe( Util::Configuration& c, ConfigRom& configRom, bool generic = false );
458     static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
459     virtual bool discover();
460
461     static int getConfigurationId( );
462
463     virtual void showDevice();
464
465     virtual bool setSamplingFrequency( int samplingFrequency );
466     virtual int getSamplingFrequency( );
467     virtual std::vector<int> getSupportedSamplingFrequencies();
468
469     virtual ClockSourceVector getSupportedClockSources();
470     virtual bool setActiveClockSource(ClockSource);
471     virtual ClockSource getActiveClockSource();
472
473     virtual int getStreamCount();
474     virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i);
475
476     virtual bool prepare();
477
478     virtual bool lock();
479     virtual bool unlock();
480
481     virtual bool startStreamByIndex(int i);
482     virtual bool stopStreamByIndex(int i);
483
484     virtual bool enableStreaming();
485     virtual bool disableStreaming();
486
487     virtual std::string getNickname();
488     virtual bool setNickname(std::string name);
489
490 protected:
491     // streaming stuff
492     typedef std::vector< Streaming::StreamProcessor * > StreamProcessorVector;
493     typedef std::vector< Streaming::StreamProcessor * >::iterator StreamProcessorVectorIterator;
494     StreamProcessorVector m_receiveProcessors;
495     StreamProcessorVector m_transmitProcessors;
496
497 private: // streaming & port helpers
498     enum EPortTypes {
499         ePT_Analog,
500         ePT_MIDI,
501     };
502
503     typedef struct {
504         std::string name;
505         enum EPortTypes portType;
506         unsigned int streamPosition;
507         unsigned int streamLocation;
508     } diceChannelInfo;
509
510     bool addChannelToProcessor( diceChannelInfo *,
511                               Streaming::StreamProcessor *,
512                               Streaming::Port::E_Direction direction);
513
514     int allocateIsoChannel(unsigned int packet_size);
515     bool deallocateIsoChannel(int channel);
516
517 private: // active config
518     enum eDiceConfig {
519         eDC_Unknown,
520         eDC_Low,
521         eDC_Mid,
522         eDC_High,
523     };
524
525     enum eDiceConfig getCurrentConfig();
526
527 private: // helper functions
528     bool enableIsoStreaming();
529     bool disableIsoStreaming();
530     bool isIsoStreamingEnabled();
531
532     bool maskedCheckZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
533     bool maskedCheckNotZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
534
535     diceNameVector splitNameString(std::string in);
536     diceNameVector getTxNameString(unsigned int i);
537     diceNameVector getRxNameString(unsigned int i);
538     diceNameVector getClockSourceNameString();
539     std::string getDeviceNickName();
540     bool setDeviceNickName(std::string name);
541
542     enum eClockSourceType  clockIdToType(unsigned int id);
543     bool isClockSourceIdLocked(unsigned int id, quadlet_t ext_status_reg);
544     bool isClockSourceIdSlipping(unsigned int id, quadlet_t ext_status_reg);
545
546 // EAP stuff
547 private:
548     EAP*         m_eap;
549 public:
550     EAP* getEAP() {return m_eap;};
551
552 private: // register I/O routines
553     bool initIoFunctions();
554     // quadlet read/write routines
555     bool readReg(fb_nodeaddr_t, fb_quadlet_t *);
556     bool writeReg(fb_nodeaddr_t, fb_quadlet_t);
557     bool readRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
558     bool writeRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
559
560     bool readGlobalReg(fb_nodeaddr_t, fb_quadlet_t *);
561     bool writeGlobalReg(fb_nodeaddr_t, fb_quadlet_t);
562     bool readGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
563     bool writeGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
564     fb_nodeaddr_t globalOffsetGen(fb_nodeaddr_t, size_t);
565
566     bool readTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
567     bool writeTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
568     bool readTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
569     bool writeTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
570     fb_nodeaddr_t txOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
571
572     bool readRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
573     bool writeRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
574     bool readRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
575     bool writeRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
576     fb_nodeaddr_t rxOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
577
578     fb_quadlet_t m_global_reg_offset;
579     fb_quadlet_t m_global_reg_size;
580     fb_quadlet_t m_tx_reg_offset;
581     fb_quadlet_t m_tx_reg_size;
582     fb_quadlet_t m_rx_reg_offset;
583     fb_quadlet_t m_rx_reg_size;
584     fb_quadlet_t m_unused1_reg_offset;
585     fb_quadlet_t m_unused1_reg_size;
586     fb_quadlet_t m_unused2_reg_offset;
587     fb_quadlet_t m_unused2_reg_size;
588
589     fb_quadlet_t m_nb_tx;
590     fb_quadlet_t m_tx_size;
591     fb_quadlet_t m_nb_rx;
592     fb_quadlet_t m_rx_size;
593
594 // private:
595 public:
596     // notification
597     Notifier *m_notifier;
598
599     /**
600      * this class reacts on the DICE device writing to the
601      * hosts notify address
602      */
603     #define DICE_NOTIFIER_BASE_ADDRESS 0x0000FFFFE0000000ULL
604     #define DICE_NOTIFIER_BLOCK_LENGTH 4
605     class Notifier : public Ieee1394Service::ARMHandler
606     {
607     public:
608         Notifier(Device &, nodeaddr_t start);
609         virtual ~Notifier();
610
611     private:
612         Device &m_device;
613     };
614
615
616
617 };
618
619 }
620 #endif
Note: See TracBrowser for help on using the browser.