2005-04-21 16:53:53 +02:00
|
|
|
/* This file contains device independent device driver interface.
|
2005-07-26 14:50:25 +02:00
|
|
|
*
|
2005-04-21 16:53:53 +02:00
|
|
|
* Changes:
|
2005-08-02 17:30:36 +02:00
|
|
|
* Jul 25, 2005 added SYS_SIG type for signals (Jorrit N. Herder)
|
2005-04-21 16:53:53 +02:00
|
|
|
* Sep 15, 2004 added SYN_ALARM type for timeouts (Jorrit N. Herder)
|
|
|
|
* Jul 23, 2004 removed kernel dependencies (Jorrit N. Herder)
|
2005-07-26 14:50:25 +02:00
|
|
|
* Apr 02, 1992 constructed from AT wini and floppy driver (Kees J. Bot)
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* The drivers support the following operations (using message format m2):
|
|
|
|
*
|
2009-12-02 10:57:48 +01:00
|
|
|
* m_type DEVICE IO_ENDPT COUNT POSITION HIGHPOS IO_GRANT
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
* | DEV_OPEN | device | proc nr | | | | |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_CLOSE | device | proc nr | | | | |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_READ_S | device | proc nr | bytes | off lo | off hi i buf grant |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_WRITE_S | device | proc nr | bytes | off lo | off hi | buf grant |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_GATHER_S | device | proc nr | iov len | off lo | off hi | iov grant |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_SCATTER_S | device | proc nr | iov len | off lo | off hi | iov grant |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_IOCTL_S | device | proc nr | request | | | buf grant |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | CANCEL | device | proc nr | r/w | | | |
|
|
|
|
* ----------------------------------------------------------------------------
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
2009-12-02 10:57:48 +01:00
|
|
|
* The file contains the following entry points:
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
|
|
|
* driver_task: called by the device dependent task entry
|
2009-12-02 10:57:48 +01:00
|
|
|
* init_buffer: initialize a DMA buffer
|
|
|
|
* mq_queue: queue an incoming message for later processing
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
|
|
|
|
2007-02-07 17:22:19 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "../drivers.h"
|
|
|
|
#include <sys/ioc_disk.h>
|
2007-01-12 14:33:12 +01:00
|
|
|
#include <minix/mq.h>
|
2009-09-29 20:47:56 +02:00
|
|
|
#include <minix/endpoint.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "driver.h"
|
|
|
|
|
|
|
|
/* Claim space for variables. */
|
2009-12-02 10:57:48 +01:00
|
|
|
u8_t *tmp_buf = NULL; /* the DMA buffer eventually */
|
2005-04-21 16:53:53 +02:00
|
|
|
phys_bytes tmp_phys; /* phys address of DMA buffer */
|
|
|
|
|
2009-12-02 10:57:48 +01:00
|
|
|
FORWARD _PROTOTYPE( void asyn_reply, (message *mess, int proc_nr, int r) );
|
|
|
|
FORWARD _PROTOTYPE( int do_rdwt, (struct driver *dr, message *mp) );
|
|
|
|
FORWARD _PROTOTYPE( int do_vrdwt, (struct driver *dr, message *mp) );
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-07-08 19:23:44 +02:00
|
|
|
int device_caller;
|
2007-01-12 14:33:12 +01:00
|
|
|
PRIVATE mq_t *queue_head = NULL;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2009-12-02 10:57:48 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* asyn_reply *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void asyn_reply(mess, proc_nr, r)
|
|
|
|
message *mess;
|
|
|
|
int proc_nr;
|
|
|
|
int r;
|
|
|
|
{
|
|
|
|
/* Send a reply using the new asynchronous character device protocol.
|
|
|
|
*/
|
|
|
|
message reply_mess;
|
|
|
|
|
|
|
|
switch (mess->m_type) {
|
|
|
|
case DEV_OPEN:
|
|
|
|
reply_mess.m_type = DEV_REVIVE;
|
|
|
|
reply_mess.REP_ENDPT = proc_nr;
|
|
|
|
reply_mess.REP_STATUS = r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DEV_CLOSE:
|
|
|
|
reply_mess.m_type = DEV_CLOSE_REPL;
|
|
|
|
reply_mess.REP_ENDPT = proc_nr;
|
|
|
|
reply_mess.REP_STATUS = r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DEV_READ_S:
|
|
|
|
case DEV_WRITE_S:
|
|
|
|
if (r == SUSPEND)
|
|
|
|
printf("driver_task: reviving %d with SUSPEND\n", proc_nr);
|
|
|
|
|
|
|
|
reply_mess.m_type = DEV_REVIVE;
|
|
|
|
reply_mess.REP_ENDPT = proc_nr;
|
|
|
|
reply_mess.REP_IO_GRANT = (cp_grant_id_t) mess->IO_GRANT;
|
|
|
|
reply_mess.REP_STATUS = r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CANCEL:
|
|
|
|
/* The original request should send a reply. */
|
|
|
|
return;
|
|
|
|
|
|
|
|
case DEV_SELECT:
|
|
|
|
reply_mess.m_type = DEV_SEL_REPL1;
|
|
|
|
reply_mess.DEV_MINOR = mess->DEVICE;
|
|
|
|
reply_mess.DEV_SEL_OPS = r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
reply_mess.m_type = TASK_REPLY;
|
|
|
|
reply_mess.REP_ENDPT = proc_nr;
|
|
|
|
/* Status is # of bytes transferred or error code. */
|
|
|
|
reply_mess.REP_STATUS = r;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
r= asynsend(device_caller, &reply_mess);
|
|
|
|
if (r != OK)
|
|
|
|
{
|
|
|
|
printf("driver_task: unable to asynsend to %d: %d\n",
|
|
|
|
device_caller, r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* driver_task *
|
|
|
|
*===========================================================================*/
|
2009-12-02 10:57:48 +01:00
|
|
|
PUBLIC void driver_task(dp, type)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct driver *dp; /* Device dependent entry points. */
|
2009-12-02 10:57:48 +01:00
|
|
|
int type; /* Driver type (DRIVER_STD or DRIVER_ASYN) */
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* Main program of any device driver task. */
|
|
|
|
|
2005-07-08 19:23:44 +02:00
|
|
|
int r, proc_nr;
|
2005-04-21 16:53:53 +02:00
|
|
|
message mess;
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
sigset_t set;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2007-01-12 14:33:12 +01:00
|
|
|
/* Init MQ library. */
|
|
|
|
mq_init();
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Here is the main loop of the disk task. It waits for a message, carries
|
|
|
|
* it out, and sends a reply.
|
|
|
|
*/
|
|
|
|
while (TRUE) {
|
2007-01-12 14:33:12 +01:00
|
|
|
/* Any queued messages? Oldest are at the head. */
|
|
|
|
if(queue_head) {
|
|
|
|
mq_t *mq;
|
|
|
|
mq = queue_head;
|
|
|
|
memcpy(&mess, &mq->mq_mess, sizeof(mess));
|
|
|
|
queue_head = queue_head->mq_next;
|
|
|
|
mq_free(mq);
|
|
|
|
} else {
|
|
|
|
int s;
|
|
|
|
/* Wait for a request to read or write a disk block. */
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
if ((s=sef_receive(ANY, &mess)) != OK)
|
|
|
|
panic((*dp->dr_name)(),"sef_receive() failed", s);
|
2007-01-12 14:33:12 +01:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-07-08 19:23:44 +02:00
|
|
|
device_caller = mess.m_source;
|
2006-03-03 11:21:45 +01:00
|
|
|
proc_nr = mess.IO_ENDPT;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Now carry out the work. */
|
2009-09-29 20:47:56 +02:00
|
|
|
if (is_notify(mess.m_type)) {
|
|
|
|
switch (_ENDPOINT_P(mess.m_source)) {
|
|
|
|
case HARDWARE:
|
|
|
|
/* leftover interrupt or expired timer. */
|
|
|
|
if(dp->dr_hw_int) {
|
|
|
|
(*dp->dr_hw_int)(dp, &mess);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PM_PROC_NR:
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
if (getsigset(&set) != 0) break;
|
|
|
|
(*dp->dr_signal)(dp, &set);
|
|
|
|
break;
|
2009-09-29 20:47:56 +02:00
|
|
|
case SYSTEM:
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
set = mess.NOTIFY_ARG;
|
|
|
|
(*dp->dr_signal)(dp, &set);
|
2009-09-29 20:47:56 +02:00
|
|
|
break;
|
|
|
|
case CLOCK:
|
|
|
|
(*dp->dr_alarm)(dp, &mess);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if(dp->dr_other)
|
2009-12-02 10:57:48 +01:00
|
|
|
r = (*dp->dr_other)(dp, &mess);
|
2009-09-29 20:47:56 +02:00
|
|
|
else
|
|
|
|
r = EINVAL;
|
|
|
|
goto send_reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* done, get a new message */
|
|
|
|
continue;
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
switch(mess.m_type) {
|
2005-10-20 22:26:02 +02:00
|
|
|
case DEV_OPEN: r = (*dp->dr_open)(dp, &mess); break;
|
2005-04-21 16:53:53 +02:00
|
|
|
case DEV_CLOSE: r = (*dp->dr_close)(dp, &mess); break;
|
2009-12-02 10:57:48 +01:00
|
|
|
case DEV_IOCTL_S: r = (*dp->dr_ioctl)(dp, &mess); break;
|
2005-07-08 19:23:44 +02:00
|
|
|
case CANCEL: r = (*dp->dr_cancel)(dp, &mess);break;
|
|
|
|
case DEV_SELECT: r = (*dp->dr_select)(dp, &mess);break;
|
2006-06-20 10:49:51 +02:00
|
|
|
case DEV_READ_S:
|
2009-12-02 10:57:48 +01:00
|
|
|
case DEV_WRITE_S: r = do_rdwt(dp, &mess); break;
|
2006-06-20 10:49:51 +02:00
|
|
|
case DEV_GATHER_S:
|
2009-12-02 10:57:48 +01:00
|
|
|
case DEV_SCATTER_S: r = do_vrdwt(dp, &mess); break;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-07-08 19:23:44 +02:00
|
|
|
default:
|
|
|
|
if(dp->dr_other)
|
2009-12-02 10:57:48 +01:00
|
|
|
r = (*dp->dr_other)(dp, &mess);
|
2005-07-08 19:23:44 +02:00
|
|
|
else
|
|
|
|
r = EINVAL;
|
|
|
|
break;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2009-09-29 20:47:56 +02:00
|
|
|
send_reply:
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Clean up leftover state. */
|
|
|
|
(*dp->dr_cleanup)();
|
|
|
|
|
|
|
|
/* Finally, prepare and send the reply message. */
|
2009-12-02 10:57:48 +01:00
|
|
|
if (r == EDONTREPLY)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DRIVER_STD:
|
2005-07-21 20:29:52 +02:00
|
|
|
mess.m_type = TASK_REPLY;
|
2006-03-03 11:21:45 +01:00
|
|
|
mess.REP_ENDPT = proc_nr;
|
2005-07-21 20:29:52 +02:00
|
|
|
/* Status is # of bytes transferred or error code. */
|
2009-12-02 10:57:48 +01:00
|
|
|
mess.REP_STATUS = r;
|
|
|
|
|
|
|
|
/* Changed from sendnb() to asynsend() by dcvmoole on 20091129.
|
|
|
|
* This introduces a potential overflow if a single process is
|
|
|
|
* flooding us with requests, but we need reliable delivery of
|
|
|
|
* reply messages for the 'filter' driver. A possible solution
|
|
|
|
* would be to allow only one pending asynchronous reply to a
|
|
|
|
* single process at any time. FIXME.
|
|
|
|
*/
|
|
|
|
r= asynsend(device_caller, &mess);
|
2008-02-22 16:52:13 +01:00
|
|
|
if (r != OK)
|
|
|
|
{
|
2009-12-02 10:57:48 +01:00
|
|
|
printf("driver_task: unable to send reply to %d: %d\n",
|
2008-02-22 16:52:13 +01:00
|
|
|
device_caller, r);
|
|
|
|
}
|
2009-12-02 10:57:48 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRIVER_ASYN:
|
|
|
|
asyn_reply(&mess, proc_nr, r);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic(__FILE__, "unknown driver type", type);
|
2005-07-21 20:29:52 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-20 22:26:02 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* init_buffer *
|
|
|
|
*===========================================================================*/
|
2008-11-19 13:26:10 +01:00
|
|
|
PUBLIC void init_buffer(void)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* Select a buffer that can safely be used for DMA transfers. It may also
|
|
|
|
* be used to read partition tables and such. Its absolute address is
|
|
|
|
* 'tmp_phys', the normal address is 'tmp_buf'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned left;
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
if(!(tmp_buf = alloc_contig(2*DMA_BUF_SIZE, AC_ALIGN4K, &tmp_phys)))
|
|
|
|
panic(__FILE__, "can't allocate tmp_buf", DMA_BUF_SIZE);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_rdwt *
|
|
|
|
*===========================================================================*/
|
2009-12-02 10:57:48 +01:00
|
|
|
PRIVATE int do_rdwt(dp, mp)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct driver *dp; /* device dependent entry points */
|
|
|
|
message *mp; /* pointer to read or write message */
|
|
|
|
{
|
|
|
|
/* Carry out a single read or write request. */
|
|
|
|
iovec_t iovec1;
|
|
|
|
int r, opcode;
|
|
|
|
phys_bytes phys_addr;
|
2006-11-27 15:21:43 +01:00
|
|
|
u64_t position;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Disk address? Address and length of the user buffer? */
|
|
|
|
if (mp->COUNT < 0) return(EINVAL);
|
|
|
|
|
|
|
|
/* Prepare for I/O. */
|
|
|
|
if ((*dp->dr_prepare)(mp->DEVICE) == NIL_DEV) return(ENXIO);
|
|
|
|
|
|
|
|
/* Create a one element scatter/gather vector for the buffer. */
|
2009-12-02 10:57:48 +01:00
|
|
|
if(mp->m_type == DEV_READ_S) opcode = DEV_GATHER_S;
|
2007-02-07 17:22:19 +01:00
|
|
|
else opcode = DEV_SCATTER_S;
|
2006-06-20 10:49:51 +02:00
|
|
|
|
2009-12-02 10:57:48 +01:00
|
|
|
iovec1.iov_addr = (vir_bytes) mp->IO_GRANT;
|
2005-04-21 16:53:53 +02:00
|
|
|
iovec1.iov_size = mp->COUNT;
|
|
|
|
|
|
|
|
/* Transfer bytes from/to the device. */
|
2006-11-27 15:21:43 +01:00
|
|
|
position= make64(mp->POSITION, mp->HIGHPOS);
|
2009-12-02 10:57:48 +01:00
|
|
|
r = (*dp->dr_transfer)(mp->IO_ENDPT, opcode, position, &iovec1, 1);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Return the number of bytes transferred or an error code. */
|
|
|
|
return(r == OK ? (mp->COUNT - iovec1.iov_size) : r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*==========================================================================*
|
|
|
|
* do_vrdwt *
|
|
|
|
*==========================================================================*/
|
2009-12-02 10:57:48 +01:00
|
|
|
PRIVATE int do_vrdwt(dp, mp)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct driver *dp; /* device dependent entry points */
|
|
|
|
message *mp; /* pointer to read or write message */
|
|
|
|
{
|
|
|
|
/* Carry out an device read or write to/from a vector of user addresses.
|
|
|
|
* The "user addresses" are assumed to be safe, i.e. FS transferring to/from
|
|
|
|
* its own buffers, so they are not checked.
|
|
|
|
*/
|
|
|
|
static iovec_t iovec[NR_IOREQS];
|
|
|
|
phys_bytes iovec_size;
|
|
|
|
unsigned nr_req;
|
2006-06-20 10:49:51 +02:00
|
|
|
int r, j, opcode;
|
2006-11-27 15:21:43 +01:00
|
|
|
u64_t position;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
nr_req = mp->COUNT; /* Length of I/O vector */
|
|
|
|
|
2009-12-02 10:57:48 +01:00
|
|
|
/* Copy the vector from the caller to kernel space. */
|
|
|
|
if (nr_req > NR_IOREQS) nr_req = NR_IOREQS;
|
|
|
|
iovec_size = (phys_bytes) (nr_req * sizeof(iovec[0]));
|
|
|
|
|
|
|
|
if (OK != sys_safecopyfrom(mp->m_source, (vir_bytes) mp->IO_GRANT,
|
|
|
|
0, (vir_bytes) iovec, iovec_size, D)) {
|
|
|
|
panic((*dp->dr_name)(),"bad I/O vector by", mp->m_source);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare for I/O. */
|
|
|
|
if ((*dp->dr_prepare)(mp->DEVICE) == NIL_DEV) return(ENXIO);
|
|
|
|
|
|
|
|
/* Transfer bytes from/to the device. */
|
2006-06-20 10:49:51 +02:00
|
|
|
opcode = mp->m_type;
|
2006-11-27 15:21:43 +01:00
|
|
|
position= make64(mp->POSITION, mp->HIGHPOS);
|
2009-12-02 10:57:48 +01:00
|
|
|
r = (*dp->dr_transfer)(mp->IO_ENDPT, opcode, position, iovec, nr_req);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Copy the I/O vector back to the caller. */
|
2009-12-02 10:57:48 +01:00
|
|
|
if (OK != sys_safecopyto(mp->m_source, (vir_bytes) mp->IO_GRANT,
|
|
|
|
0, (vir_bytes) iovec, iovec_size, D)) {
|
|
|
|
panic((*dp->dr_name)(),"couldn't return I/O vector", mp->m_source);
|
2006-06-20 10:49:51 +02:00
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* no_name *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC char *no_name()
|
|
|
|
{
|
|
|
|
/* Use this default name if there is no specific name for the device. This was
|
|
|
|
* originally done by fetching the name from the task table for this process:
|
|
|
|
* "return(tasktab[proc_number(proc_ptr) + NR_TASKS].name);", but currently a
|
|
|
|
* real "noname" is returned. Perhaps, some system information service can be
|
|
|
|
* queried for a name at a later time.
|
|
|
|
*/
|
|
|
|
static char name[] = "noname";
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*============================================================================*
|
|
|
|
* do_nop *
|
|
|
|
*============================================================================*/
|
|
|
|
PUBLIC int do_nop(dp, mp)
|
|
|
|
struct driver *dp;
|
|
|
|
message *mp;
|
|
|
|
{
|
|
|
|
/* Nothing there, or nothing to do. */
|
|
|
|
|
|
|
|
switch (mp->m_type) {
|
|
|
|
case DEV_OPEN: return(ENODEV);
|
|
|
|
case DEV_CLOSE: return(OK);
|
2007-02-07 17:22:19 +01:00
|
|
|
case DEV_IOCTL_S:
|
2009-12-02 10:57:48 +01:00
|
|
|
default: printf("nop: ignoring code %d\n", mp->m_type);
|
|
|
|
return(EIO);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-20 10:49:51 +02:00
|
|
|
/*============================================================================*
|
|
|
|
* nop_ioctl *
|
|
|
|
*============================================================================*/
|
2009-12-02 10:57:48 +01:00
|
|
|
PUBLIC int nop_ioctl(dp, mp)
|
2006-06-20 10:49:51 +02:00
|
|
|
struct driver *dp;
|
|
|
|
message *mp;
|
|
|
|
{
|
|
|
|
return(ENOTTY);
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*============================================================================*
|
2005-07-26 14:50:25 +02:00
|
|
|
* nop_signal *
|
2005-04-21 16:53:53 +02:00
|
|
|
*============================================================================*/
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
PUBLIC void nop_signal(dp, set)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct driver *dp;
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
sigset_t *set;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2005-07-26 14:50:25 +02:00
|
|
|
/* Default action for signal is to ignore. */
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*============================================================================*
|
|
|
|
* nop_alarm *
|
|
|
|
*============================================================================*/
|
2005-07-26 14:50:25 +02:00
|
|
|
PUBLIC void nop_alarm(dp, mp)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct driver *dp;
|
2005-07-26 14:50:25 +02:00
|
|
|
message *mp;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* Ignore the leftover alarm. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* nop_prepare *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC struct device *nop_prepare(device)
|
|
|
|
{
|
|
|
|
/* Nothing to prepare for. */
|
|
|
|
return(NIL_DEV);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* nop_cleanup *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void nop_cleanup()
|
|
|
|
{
|
|
|
|
/* Nothing to clean up. */
|
|
|
|
}
|
|
|
|
|
2005-07-08 19:23:44 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* nop_cancel *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int nop_cancel(struct driver *dr, message *m)
|
|
|
|
{
|
|
|
|
/* Nothing to do for cancel. */
|
2005-08-25 14:50:11 +02:00
|
|
|
return(OK);
|
2005-07-08 19:23:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* nop_select *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int nop_select(struct driver *dr, message *m)
|
|
|
|
{
|
|
|
|
/* Nothing to do for select. */
|
2005-08-25 14:50:11 +02:00
|
|
|
return(OK);
|
2005-07-08 19:23:44 +02:00
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*============================================================================*
|
|
|
|
* do_diocntl *
|
|
|
|
*============================================================================*/
|
2009-12-02 10:57:48 +01:00
|
|
|
PUBLIC int do_diocntl(dp, mp)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct driver *dp;
|
|
|
|
message *mp; /* pointer to ioctl request */
|
|
|
|
{
|
|
|
|
/* Carry out a partition setting/getting request. */
|
|
|
|
struct device *dv;
|
|
|
|
struct partition entry;
|
|
|
|
int s;
|
|
|
|
|
2005-07-13 16:58:21 +02:00
|
|
|
if (mp->REQUEST != DIOCSETP && mp->REQUEST != DIOCGETP) {
|
|
|
|
if(dp->dr_other) {
|
2009-12-02 10:57:48 +01:00
|
|
|
return dp->dr_other(dp, mp);
|
2005-07-13 16:58:21 +02:00
|
|
|
} else return(ENOTTY);
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Decode the message parameters. */
|
|
|
|
if ((dv = (*dp->dr_prepare)(mp->DEVICE)) == NIL_DEV) return(ENXIO);
|
|
|
|
|
|
|
|
if (mp->REQUEST == DIOCSETP) {
|
|
|
|
/* Copy just this one partition table entry. */
|
2009-12-02 10:57:48 +01:00
|
|
|
s=sys_safecopyfrom(mp->IO_ENDPT, (vir_bytes) mp->IO_GRANT,
|
|
|
|
0, (vir_bytes) &entry, sizeof(entry), D);
|
2006-06-20 10:49:51 +02:00
|
|
|
if(s != OK)
|
2005-04-21 16:53:53 +02:00
|
|
|
return s;
|
|
|
|
dv->dv_base = entry.base;
|
|
|
|
dv->dv_size = entry.size;
|
|
|
|
} else {
|
|
|
|
/* Return a partition table entry and the geometry of the drive. */
|
|
|
|
entry.base = dv->dv_base;
|
|
|
|
entry.size = dv->dv_size;
|
|
|
|
(*dp->dr_geometry)(&entry);
|
2009-12-02 10:57:48 +01:00
|
|
|
s=sys_safecopyto(mp->IO_ENDPT, (vir_bytes) mp->IO_GRANT,
|
|
|
|
0, (vir_bytes) &entry, sizeof(entry), D);
|
2006-06-20 10:49:51 +02:00
|
|
|
if (OK != s)
|
2005-04-21 16:53:53 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
return(OK);
|
|
|
|
}
|
2007-01-12 14:33:12 +01:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* mq_queue *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int mq_queue(message *m)
|
|
|
|
{
|
|
|
|
mq_t *mq, *mi;
|
|
|
|
|
|
|
|
if(!(mq = mq_get()))
|
|
|
|
panic("libdriver","mq_queue: mq_get failed", NO_NUM);
|
|
|
|
memcpy(&mq->mq_mess, m, sizeof(mq->mq_mess));
|
|
|
|
mq->mq_next = NULL;
|
|
|
|
if(!queue_head) {
|
|
|
|
queue_head = mq;
|
|
|
|
} else {
|
|
|
|
for(mi = queue_head; mi->mq_next; mi = mi->mq_next)
|
|
|
|
;
|
|
|
|
mi->mq_next = mq;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|