1 /* This file contains the singlethreaded device driver interface.
4 * Aug 27, 2011 extracted from driver.c (A. Welzel)
6 * The entry points into this file are:
7 * blockdriver_task: the main message loop of the driver
8 * blockdriver_terminate: break out of the main message loop
9 * blockdriver_handle_msg: handle a single received message
10 * blockdriver_receive_mq: message receive interface with message queueing
11 * blockdriver_mq_queue: queue an incoming message for later processing
14 #include <minix/drivers.h>
15 #include <minix/blockdriver.h>
23 /*===========================================================================*
24 * blockdriver_receive_mq *
25 *===========================================================================*/
26 int blockdriver_receive_mq(message
*m_ptr
, int *status_ptr
)
28 /* receive() interface for drivers with message queueing. */
30 /* Any queued messages? */
31 if (mq_dequeue(SINGLE_THREAD
, m_ptr
, status_ptr
))
34 /* Fall back to standard receive() interface otherwise. */
35 return driver_receive(ANY
, m_ptr
, status_ptr
);
38 /*===========================================================================*
39 * blockdriver_terminate *
40 *===========================================================================*/
41 void blockdriver_terminate(void)
43 /* Break out of the main driver loop after finishing the current request. */
48 /*===========================================================================*
50 *===========================================================================*/
51 void blockdriver_task(struct blockdriver
*bdp
)
53 /* Main program of any block device driver task. */
59 /* Here is the main loop of the disk task. It waits for a message, carries
60 * it out, and sends a reply.
63 if ((r
= blockdriver_receive_mq(&mess
, &ipc_status
)) != OK
)
64 panic("blockdriver_receive_mq failed: %d", r
);
66 blockdriver_process(bdp
, &mess
, ipc_status
);
70 /*===========================================================================*
71 * blockdriver_process *
72 *===========================================================================*/
73 void blockdriver_process(struct blockdriver
*bdp
, message
*m_ptr
,
76 /* Handle the given received message. */
79 /* Process the notification or request. */
80 if (is_ipc_notify(ipc_status
)) {
81 blockdriver_handle_notify(bdp
, m_ptr
);
83 /* Do not reply to notifications. */
85 r
= blockdriver_handle_request(bdp
, m_ptr
, SINGLE_THREAD
);
87 blockdriver_reply(m_ptr
, ipc_status
, r
);
91 /*===========================================================================*
92 * blockdriver_mq_queue *
93 *===========================================================================*/
94 int blockdriver_mq_queue(message
*m
, int status
)
96 /* Queue a message for later processing. */
98 return mq_enqueue(SINGLE_THREAD
, m
, status
);