custom message type for VM_INFO
[minix3.git] / lib / libaudiodriver / liveupdate.c
blob000da3672d3378275081c111431029282574072b
1 #include <minix/audio_fw.h>
3 /*
4 * - From audio_fw.h:
5 * EXTERN drv_t drv;
6 * EXTERN sub_dev_t sub_dev[];
7 */
9 /* State management helpers */
10 static int is_read_pending;
11 static int is_write_pending;
12 static void load_state_info(void)
14 int i, dma_mode, found_pending;
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;
24 if(dma_mode == READ_DMA) {
25 is_read_pending = TRUE;
27 else if (dma_mode == WRITE_DMA){
28 is_write_pending = TRUE;
32 found_pending = (is_read_pending && is_write_pending);
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)
42 /*===========================================================================*
43 * sef_cb_lu_prepare *
44 *===========================================================================*/
45 int sef_cb_lu_prepare(int state)
47 int is_ready;
49 /* Load state information. */
50 load_state_info();
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;
60 case SEF_LU_STATE_PROTOCOL_FREE:
61 is_ready = (!is_read_pending && !is_write_pending);
62 break;
64 /* Custom states. */
65 case AUDIO_STATE_READ_REQUEST_FREE:
66 is_ready = (!is_read_pending);
67 break;
69 case AUDIO_STATE_WRITE_REQUEST_FREE:
70 is_ready = (!is_write_pending);
71 break;
74 /* Tell SEF if we are ready. */
75 return is_ready ? OK : ENOTREADY;
78 /*===========================================================================*
79 * sef_cb_lu_state_isvalid *
80 *===========================================================================*/
81 int sef_cb_lu_state_isvalid(int state)
83 return SEF_LU_STATE_IS_STANDARD(state) || AUDIO_STATE_IS_CUSTOM(state);
86 /*===========================================================================*
87 * sef_cb_lu_state_dump *
88 *===========================================================================*/
89 void sef_cb_lu_state_dump(int state)
91 /* Load state information. */
92 load_state_info();
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);
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));