xref: /minix/minix/lib/libaudiodriver/liveupdate.c (revision 433d6423)
1 #include <minix/audio_fw.h>
2 
3 /*
4  * - From audio_fw.h:
5  * EXTERN drv_t drv;
6  * EXTERN sub_dev_t sub_dev[];
7 */
8 
9 /* State management helpers */
10 static int is_read_pending;
11 static int is_write_pending;
12 static void load_state_info(void)
13 {
14   int i, dma_mode, found_pending;
15 
16   /* Check if reads or writes are pending. */
17   is_read_pending = FALSE;
18   is_write_pending = FALSE;
19   found_pending = FALSE;
20   for (i = 0; i < drv.NrOfSubDevices && !found_pending; i++) {
21       if(sub_dev[i].RevivePending) {
22           dma_mode = sub_dev[i].DmaMode;
23 
24           if(dma_mode == READ_DMA) {
25               is_read_pending = TRUE;
26           }
27           else if (dma_mode == WRITE_DMA){
28               is_write_pending = TRUE;
29           }
30       }
31 
32       found_pending = (is_read_pending && is_write_pending);
33   }
34 }
35 
36 /* Custom states definition. */
37 #define AUDIO_STATE_READ_REQUEST_FREE   (SEF_LU_STATE_CUSTOM_BASE + 0)
38 #define AUDIO_STATE_WRITE_REQUEST_FREE  (SEF_LU_STATE_CUSTOM_BASE + 1)
39 #define AUDIO_STATE_IS_CUSTOM(s) \
40   ((s) >= AUDIO_STATE_READ_REQUEST_FREE && (s) <=AUDIO_STATE_WRITE_REQUEST_FREE)
41 
42 /*===========================================================================*
43  *       			 sef_cb_lu_prepare 	 	             *
44  *===========================================================================*/
45 int sef_cb_lu_prepare(int state)
46 {
47   int is_ready;
48 
49   /* Load state information. */
50   load_state_info();
51 
52   /* Check if we are ready for the target state. */
53   is_ready = FALSE;
54   switch(state) {
55       /* Standard states. */
56       case SEF_LU_STATE_REQUEST_FREE:
57           is_ready = (!is_read_pending && !is_write_pending);
58       break;
59 
60       case SEF_LU_STATE_PROTOCOL_FREE:
61           is_ready = (!is_read_pending && !is_write_pending);
62       break;
63 
64       /* Custom states. */
65       case AUDIO_STATE_READ_REQUEST_FREE:
66           is_ready = (!is_read_pending);
67       break;
68 
69       case AUDIO_STATE_WRITE_REQUEST_FREE:
70           is_ready = (!is_write_pending);
71       break;
72   }
73 
74   /* Tell SEF if we are ready. */
75   return is_ready ? OK : ENOTREADY;
76 }
77 
78 /*===========================================================================*
79  *      		  sef_cb_lu_state_isvalid		             *
80  *===========================================================================*/
81 int sef_cb_lu_state_isvalid(int state)
82 {
83   return SEF_LU_STATE_IS_STANDARD(state) || AUDIO_STATE_IS_CUSTOM(state);
84 }
85 
86 /*===========================================================================*
87  *      		   sef_cb_lu_state_dump         	             *
88  *===========================================================================*/
89 void sef_cb_lu_state_dump(int state)
90 {
91   /* Load state information. */
92   load_state_info();
93 
94   sef_lu_dprint("audio: live update state = %d\n", state);
95   sef_lu_dprint("audio: is_read_pending = %d\n", is_read_pending);
96   sef_lu_dprint("audio: is_write_pending = %d\n", is_write_pending);
97 
98   sef_lu_dprint("audio: SEF_LU_STATE_WORK_FREE(%d) reached = %d\n",
99       SEF_LU_STATE_WORK_FREE, TRUE);
100   sef_lu_dprint("audio: SEF_LU_STATE_REQUEST_FREE(%d) reached = %d\n",
101       SEF_LU_STATE_REQUEST_FREE, (!is_read_pending && !is_write_pending));
102   sef_lu_dprint("audio: SEF_LU_STATE_PROTOCOL_FREE(%d) reached = %d\n",
103       SEF_LU_STATE_PROTOCOL_FREE, (!is_read_pending && !is_write_pending));
104   sef_lu_dprint("audio: AUDIO_STATE_READ_REQUEST_FREE(%d) reached = %d\n",
105       AUDIO_STATE_READ_REQUEST_FREE, (!is_read_pending));
106   sef_lu_dprint("audio: AUDIO_STATE_WRITE_REQUEST_FREE(%d) reached = %d\n",
107       AUDIO_STATE_WRITE_REQUEST_FREE, (!is_write_pending));
108 }
109 
110