2005-09-16 13:09:08 +02:00
|
|
|
/* This file contains the driver for a DSP (Digital Sound Processor) on
|
|
|
|
* a SoundBlaster 16 soundcard.
|
|
|
|
*
|
|
|
|
* The driver supports the following operations (using message format m2):
|
|
|
|
*
|
2006-03-03 11:21:45 +01:00
|
|
|
* m_type DEVICE IO_ENDPT COUNT POSITION ADRRESS
|
2005-09-16 13:09:08 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
* | DEV_OPEN | device | proc nr | | | |
|
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
|
|
|
* | DEV_CLOSE | device | proc nr | | | |
|
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
|
|
|
* | DEV_READ | device | proc nr | bytes | | buf ptr |
|
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
|
|
|
* | DEV_WRITE | device | proc nr | bytes | | buf ptr |
|
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
|
|
|
* | DEV_IOCTL | device | proc nr |func code| | buf ptr |
|
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* The file contains one entry point:
|
|
|
|
*
|
|
|
|
* main: main entry when driver is brought up
|
|
|
|
*
|
|
|
|
* August 24 2005 Ported driver to user space (only audio playback) (Peter Boonstoppel)
|
|
|
|
* May 20 1995 Author: Michel R. Prevenier
|
|
|
|
*/
|
|
|
|
|
2009-09-29 20:47:56 +02:00
|
|
|
#include <minix/endpoint.h>
|
2005-08-22 13:46:06 +02:00
|
|
|
#include "sb16.h"
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
|
|
|
|
FORWARD _PROTOTYPE( int dsp_open, (void) );
|
|
|
|
FORWARD _PROTOTYPE( int dsp_close, (void) );
|
2010-04-01 14:51:31 +02:00
|
|
|
FORWARD _PROTOTYPE( int dsp_ioctl, (const message *m_ptr) );
|
|
|
|
FORWARD _PROTOTYPE( void dsp_write, (const message *m_ptr) );
|
2005-08-22 13:46:06 +02:00
|
|
|
FORWARD _PROTOTYPE( void dsp_hardware_msg, (void) );
|
|
|
|
FORWARD _PROTOTYPE( void dsp_status, (message *m_ptr) );
|
|
|
|
|
|
|
|
FORWARD _PROTOTYPE( void reply, (int code, int replyee, int process, int status) );
|
|
|
|
FORWARD _PROTOTYPE( int dsp_init, (void) );
|
|
|
|
FORWARD _PROTOTYPE( int dsp_reset, (void) );
|
|
|
|
FORWARD _PROTOTYPE( int dsp_command, (int value) );
|
|
|
|
FORWARD _PROTOTYPE( int dsp_set_size, (unsigned int size) );
|
|
|
|
FORWARD _PROTOTYPE( int dsp_set_speed, (unsigned int speed) );
|
|
|
|
FORWARD _PROTOTYPE( int dsp_set_stereo, (unsigned int stereo) );
|
|
|
|
FORWARD _PROTOTYPE( int dsp_set_bits, (unsigned int bits) );
|
|
|
|
FORWARD _PROTOTYPE( int dsp_set_sign, (unsigned int sign) );
|
|
|
|
FORWARD _PROTOTYPE( void dsp_dma_setup, (phys_bytes address, int count) );
|
|
|
|
FORWARD _PROTOTYPE( void dsp_setup, (void) );
|
|
|
|
|
|
|
|
PRIVATE int irq_hook_id; /* id of irq hook at the kernel */
|
|
|
|
|
|
|
|
PRIVATE char DmaBuffer[DMA_SIZE + 64 * 1024];
|
|
|
|
PRIVATE char* DmaPtr;
|
|
|
|
PRIVATE phys_bytes DmaPhys;
|
|
|
|
|
|
|
|
PRIVATE char Buffer[DSP_MAX_FRAGMENT_SIZE * DSP_NR_OF_BUFFERS];
|
|
|
|
|
|
|
|
PRIVATE int DspVersion[2];
|
|
|
|
PRIVATE unsigned int DspStereo = DEFAULT_STEREO;
|
|
|
|
PRIVATE unsigned int DspSpeed = DEFAULT_SPEED;
|
|
|
|
PRIVATE unsigned int DspBits = DEFAULT_BITS;
|
|
|
|
PRIVATE unsigned int DspSign = DEFAULT_SIGN;
|
|
|
|
PRIVATE unsigned int DspFragmentSize = DSP_MAX_FRAGMENT_SIZE;
|
|
|
|
PRIVATE int DspAvail = 0;
|
|
|
|
PRIVATE int DspBusy = 0;
|
|
|
|
PRIVATE int DmaMode = 0;
|
|
|
|
PRIVATE int DmaBusy = -1;
|
|
|
|
PRIVATE int DmaFillNext = 0;
|
|
|
|
PRIVATE int BufReadNext = -1;
|
|
|
|
PRIVATE int BufFillNext = 0;
|
|
|
|
|
|
|
|
PRIVATE int revivePending = 0;
|
|
|
|
PRIVATE int reviveStatus;
|
|
|
|
PRIVATE int reviveProcNr;
|
|
|
|
|
|
|
|
#define dprint (void)
|
|
|
|
|
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
|
|
|
/* SEF functions and variables. */
|
|
|
|
FORWARD _PROTOTYPE( void sef_local_startup, (void) );
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
FORWARD _PROTOTYPE( int sef_cb_init_fresh, (int type, sef_init_info_t *info) );
|
New RS and new signal handling for system processes.
UPDATING INFO:
20100317:
/usr/src/etc/system.conf updated to ignore default kernel calls: copy
it (or merge it) to /etc/system.conf.
The hello driver (/dev/hello) added to the distribution:
# cd /usr/src/commands/scripts && make clean install
# cd /dev && MAKEDEV hello
KERNEL CHANGES:
- Generic signal handling support. The kernel no longer assumes PM as a signal
manager for every process. The signal manager of a given process can now be
specified in its privilege slot. When a signal has to be delivered, the kernel
performs the lookup and forwards the signal to the appropriate signal manager.
PM is the default signal manager for user processes, RS is the default signal
manager for system processes. To enable ptrace()ing for system processes, it
is sufficient to change the default signal manager to PM. This will temporarily
disable crash recovery, though.
- sys_exit() is now split into sys_exit() (i.e. exit() for system processes,
which generates a self-termination signal), and sys_clear() (i.e. used by PM
to ask the kernel to clear a process slot when a process exits).
- Added a new kernel call (i.e. sys_update()) to swap two process slots and
implement live update.
PM CHANGES:
- Posix signal handling is no longer allowed for system processes. System
signals are split into two fixed categories: termination and non-termination
signals. When a non-termination signaled is processed, PM transforms the signal
into an IPC message and delivers the message to the system process. When a
termination signal is processed, PM terminates the process.
- PM no longer assumes itself as the signal manager for system processes. It now
makes sure that every system signal goes through the kernel before being
actually processes. The kernel will then dispatch the signal to the appropriate
signal manager which may or may not be PM.
SYSLIB CHANGES:
- Simplified SEF init and LU callbacks.
- Added additional predefined SEF callbacks to debug crash recovery and
live update.
- Fixed a temporary ack in the SEF init protocol. SEF init reply is now
completely synchronous.
- Added SEF signal event type to provide a uniform interface for system
processes to deal with signals. A sef_cb_signal_handler() callback is
available for system processes to handle every received signal. A
sef_cb_signal_manager() callback is used by signal managers to process
system signals on behalf of the kernel.
- Fixed a few bugs with memory mapping and DS.
VM CHANGES:
- Page faults and memory requests coming from the kernel are now implemented
using signals.
- Added a new VM call to swap two process slots and implement live update.
- The call is used by RS at update time and in turn invokes the kernel call
sys_update().
RS CHANGES:
- RS has been reworked with a better functional decomposition.
- Better kernel call masks. com.h now defines the set of very basic kernel calls
every system service is allowed to use. This makes system.conf simpler and
easier to maintain. In addition, this guarantees a higher level of isolation
for system libraries that use one or more kernel calls internally (e.g. printf).
- RS is the default signal manager for system processes. By default, RS
intercepts every signal delivered to every system process. This makes crash
recovery possible before bringing PM and friends in the loop.
- RS now supports fast rollback when something goes wrong while initializing
the new version during a live update.
- Live update is now implemented by keeping the two versions side-by-side and
swapping the process slots when the old version is ready to update.
- Crash recovery is now implemented by keeping the two versions side-by-side
and cleaning up the old version only when the recovery process is complete.
DS CHANGES:
- Fixed a bug when the process doing ds_publish() or ds_delete() is not known
by DS.
- Fixed the completely broken support for strings. String publishing is now
implemented in the system library and simply wraps publishing of memory ranges.
Ideally, we should adopt a similar approach for other data types as well.
- Test suite fixed.
DRIVER CHANGES:
- The hello driver has been added to the Minix distribution to demonstrate basic
live update and crash recovery functionalities.
- Other drivers have been adapted to conform the new SEF interface.
2010-03-17 02:15:29 +01:00
|
|
|
EXTERN _PROTOTYPE( int sef_cb_lu_prepare, (int state) );
|
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
|
|
|
EXTERN _PROTOTYPE( int sef_cb_lu_state_isvalid, (int state) );
|
|
|
|
EXTERN _PROTOTYPE( void sef_cb_lu_state_dump, (int state) );
|
|
|
|
PUBLIC int is_processing = FALSE;
|
|
|
|
PUBLIC int is_status_msg_expected = FALSE;
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* main
|
|
|
|
*===========================================================================*/
|
2010-07-06 13:29:23 +02:00
|
|
|
PUBLIC int main(int argc, char *argv[])
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
2010-04-01 14:51:31 +02:00
|
|
|
int r;
|
|
|
|
endpoint_t caller;
|
|
|
|
int proc_nr;
|
2005-08-22 13:46:06 +02:00
|
|
|
message mess;
|
2010-04-08 15:41:35 +02:00
|
|
|
int ipc_status;
|
2005-08-22 13:46:06 +02:00
|
|
|
|
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
|
|
|
/* SEF local startup. */
|
|
|
|
sef_local_startup();
|
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
while(TRUE) {
|
|
|
|
/* Wait for an incoming message */
|
2010-04-08 15:41:35 +02:00
|
|
|
driver_receive(ANY, &mess, &ipc_status);
|
2005-08-22 13:46:06 +02:00
|
|
|
|
|
|
|
caller = mess.m_source;
|
2006-03-03 11:21:45 +01:00
|
|
|
proc_nr = mess.IO_ENDPT;
|
2005-08-22 13:46:06 +02:00
|
|
|
|
2010-04-08 15:41:35 +02:00
|
|
|
if (is_ipc_notify(ipc_status)) {
|
2009-09-29 20:47:56 +02:00
|
|
|
switch (_ENDPOINT_P(mess.m_source)) {
|
|
|
|
case HARDWARE:
|
|
|
|
dsp_hardware_msg();
|
|
|
|
continue; /* don't reply */
|
|
|
|
default:
|
|
|
|
r = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dont with this message */
|
|
|
|
goto send_reply;
|
|
|
|
}
|
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/* Now carry out the work. */
|
|
|
|
switch(mess.m_type) {
|
|
|
|
case DEV_OPEN: r = dsp_open(); break;
|
|
|
|
case DEV_CLOSE: r = dsp_close(); break;
|
2007-02-07 17:22:19 +01:00
|
|
|
#ifdef DEV_IOCTL
|
2005-08-22 13:46:06 +02:00
|
|
|
case DEV_IOCTL: r = dsp_ioctl(&mess); break;
|
2007-02-07 17:22:19 +01:00
|
|
|
#endif
|
|
|
|
#ifdef DEV_READ
|
2005-08-22 13:46:06 +02:00
|
|
|
|
|
|
|
case DEV_READ: r = EINVAL; break; /* Not yet implemented */
|
|
|
|
case DEV_WRITE: dsp_write(&mess); continue; /* don't reply */
|
2007-02-07 17:22:19 +01:00
|
|
|
#endif
|
2005-08-22 13:46:06 +02:00
|
|
|
|
|
|
|
case DEV_STATUS: dsp_status(&mess); continue; /* don't reply */
|
|
|
|
default: r = EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-09-29 20:47:56 +02:00
|
|
|
send_reply:
|
2005-08-22 13:46:06 +02:00
|
|
|
/* Finally, prepare and send the reply message. */
|
|
|
|
reply(TASK_REPLY, caller, proc_nr, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/*===========================================================================*
|
|
|
|
* sef_local_startup *
|
|
|
|
*===========================================================================*/
|
2010-04-01 14:51:31 +02:00
|
|
|
PRIVATE void sef_local_startup(void)
|
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
|
|
|
{
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
/* Register init callbacks. */
|
|
|
|
sef_setcb_init_fresh(sef_cb_init_fresh);
|
|
|
|
sef_setcb_init_lu(sef_cb_init_fresh);
|
|
|
|
sef_setcb_init_restart(sef_cb_init_fresh);
|
|
|
|
|
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
|
|
|
/* Register live update callbacks. */
|
|
|
|
sef_setcb_lu_prepare(sef_cb_lu_prepare);
|
|
|
|
sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid);
|
|
|
|
sef_setcb_lu_state_dump(sef_cb_lu_state_dump);
|
|
|
|
|
|
|
|
/* Let SEF perform startup. */
|
|
|
|
sef_startup();
|
|
|
|
}
|
2005-09-16 13:09:08 +02:00
|
|
|
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* sef_cb_init_fresh *
|
|
|
|
*===========================================================================*/
|
2010-04-01 14:51:31 +02:00
|
|
|
PRIVATE int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
{
|
|
|
|
/* Initialize the rtl8169 driver. */
|
|
|
|
unsigned left;
|
|
|
|
|
|
|
|
/* Select a buffer that can safely be used for dma transfers.
|
|
|
|
* Its absolute address is 'DmaPhys', the normal address is 'DmaPtr'.
|
|
|
|
*/
|
|
|
|
#if (CHIP == INTEL)
|
|
|
|
DmaPtr = DmaBuffer;
|
2010-04-01 14:51:31 +02:00
|
|
|
sys_umap(SELF, D, (vir_bytes)DmaBuffer, sizeof(DmaBuffer), &DmaPhys);
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
|
|
|
|
if((left = dma_bytes_left(DmaPhys)) < DMA_SIZE) {
|
|
|
|
/* First half of buffer crosses a 64K boundary, can't DMA into that */
|
|
|
|
DmaPtr += left;
|
|
|
|
DmaPhys += left;
|
|
|
|
}
|
|
|
|
#else /* CHIP != INTEL */
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("initialization failed: CHIP != INTEL: %d", 0);
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
#endif /* CHIP == INTEL */
|
|
|
|
|
2010-04-08 15:41:35 +02:00
|
|
|
/* Announce we are up! */
|
|
|
|
driver_announce();
|
|
|
|
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_open
|
|
|
|
*===========================================================================*/
|
2010-04-01 14:51:31 +02:00
|
|
|
PRIVATE int dsp_open(void)
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
|
|
|
dprint("sb16_dsp.c: dsp_open()\n");
|
|
|
|
|
|
|
|
/* try to detect SoundBlaster card */
|
|
|
|
if(!DspAvail && dsp_init() != OK) return EIO;
|
|
|
|
|
|
|
|
/* Only one open at a time with soundcards */
|
|
|
|
if(DspBusy) return EBUSY;
|
|
|
|
|
|
|
|
/* Start with a clean DSP */
|
|
|
|
if(dsp_reset() != OK) return EIO;
|
|
|
|
|
|
|
|
/* Setup default values */
|
|
|
|
DspStereo = DEFAULT_STEREO;
|
|
|
|
DspSpeed = DEFAULT_SPEED;
|
|
|
|
DspBits = DEFAULT_BITS;
|
|
|
|
DspSign = DEFAULT_SIGN;
|
|
|
|
DspFragmentSize = DMA_SIZE / 2;
|
|
|
|
|
|
|
|
DspBusy = 1;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_close
|
|
|
|
*===========================================================================*/
|
2010-04-01 14:51:31 +02:00
|
|
|
PRIVATE int dsp_close(void)
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
|
|
|
dprint("sb16_dsp.c: dsp_close()\n");
|
|
|
|
|
|
|
|
DspBusy = 0; /* soundcard available again */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_ioctl
|
|
|
|
*===========================================================================*/
|
2010-04-01 14:51:31 +02:00
|
|
|
PRIVATE int dsp_ioctl(const message *m_ptr)
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
unsigned int val;
|
|
|
|
|
|
|
|
dprint("sb16_dsp.c: dsp_ioctl()\n");
|
|
|
|
|
|
|
|
/* Cannot change parameters during play or recording */
|
|
|
|
if(DmaBusy >= 0) return EBUSY;
|
|
|
|
|
|
|
|
/* Get user data */
|
|
|
|
if(m_ptr->REQUEST != DSPIORESET) {
|
2006-03-03 11:21:45 +01:00
|
|
|
sys_vircopy(m_ptr->IO_ENDPT, D, (vir_bytes)m_ptr->ADDRESS, SELF, D, (vir_bytes)&val, sizeof(val));
|
2005-08-22 13:46:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
dprint("dsp_ioctl: got ioctl %d, argument: %d\n", m_ptr->REQUEST, val);
|
|
|
|
|
|
|
|
switch(m_ptr->REQUEST) {
|
|
|
|
case DSPIORATE: status = dsp_set_speed(val); break;
|
|
|
|
case DSPIOSTEREO: status = dsp_set_stereo(val); break;
|
|
|
|
case DSPIOBITS: status = dsp_set_bits(val); break;
|
|
|
|
case DSPIOSIZE: status = dsp_set_size(val); break;
|
|
|
|
case DSPIOSIGN: status = dsp_set_sign(val); break;
|
|
|
|
case DSPIOMAX:
|
|
|
|
val = DSP_MAX_FRAGMENT_SIZE;
|
2006-03-03 11:21:45 +01:00
|
|
|
sys_vircopy(SELF, D, (vir_bytes)&val, m_ptr->IO_ENDPT, D, (vir_bytes)m_ptr->ADDRESS, sizeof(val));
|
2005-08-22 13:46:06 +02:00
|
|
|
status = OK;
|
|
|
|
break;
|
|
|
|
case DSPIORESET: status = dsp_reset(); break;
|
|
|
|
default: status = ENOTTY; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_write
|
|
|
|
*===========================================================================*/
|
2010-04-01 14:51:31 +02:00
|
|
|
PRIVATE void dsp_write(const message *m_ptr)
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
|
|
|
message mess;
|
2010-04-08 15:41:35 +02:00
|
|
|
int ipc_status;
|
2005-08-22 13:46:06 +02:00
|
|
|
|
|
|
|
dprint("sb16_dsp.c: dsp_write()\n");
|
|
|
|
|
|
|
|
if(m_ptr->COUNT != DspFragmentSize) {
|
2006-03-03 11:21:45 +01:00
|
|
|
reply(TASK_REPLY, m_ptr->m_source, m_ptr->IO_ENDPT, EINVAL);
|
2005-08-22 13:46:06 +02:00
|
|
|
return;
|
|
|
|
}
|
2005-09-16 13:09:08 +02:00
|
|
|
if(m_ptr->m_type != DmaMode && DmaBusy >= 0) {
|
2006-03-03 11:21:45 +01:00
|
|
|
reply(TASK_REPLY, m_ptr->m_source, m_ptr->IO_ENDPT, EBUSY);
|
2005-09-16 13:09:08 +02:00
|
|
|
return;
|
|
|
|
}
|
2005-08-22 13:46:06 +02:00
|
|
|
|
2006-03-03 11:21:45 +01:00
|
|
|
reply(TASK_REPLY, m_ptr->m_source, m_ptr->IO_ENDPT, SUSPEND);
|
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
|
|
|
is_processing = TRUE;
|
2005-08-22 13:46:06 +02:00
|
|
|
|
|
|
|
if(DmaBusy < 0) { /* Dma tranfer not yet started */
|
|
|
|
|
2007-02-07 17:22:19 +01:00
|
|
|
DmaMode = DEV_WRITE_S; /* Dma mode is writing */
|
2006-03-03 11:21:45 +01:00
|
|
|
sys_datacopy(m_ptr->IO_ENDPT, (vir_bytes)m_ptr->ADDRESS, SELF, (vir_bytes)DmaPtr, (phys_bytes)DspFragmentSize);
|
2005-08-22 13:46:06 +02:00
|
|
|
dsp_dma_setup(DmaPhys, DspFragmentSize * DMA_NR_OF_BUFFERS);
|
|
|
|
dsp_setup();
|
|
|
|
DmaBusy = 0; /* Dma is busy */
|
|
|
|
dprint(" filled dma[0]\n");
|
|
|
|
DmaFillNext = 1;
|
|
|
|
|
|
|
|
} else if(DmaBusy != DmaFillNext) { /* Dma transfer started, but Dma buffer not yet full */
|
|
|
|
|
2006-03-03 11:21:45 +01:00
|
|
|
sys_datacopy(m_ptr->IO_ENDPT, (vir_bytes)m_ptr->ADDRESS, SELF, (vir_bytes)DmaPtr + DmaFillNext * DspFragmentSize, (phys_bytes)DspFragmentSize);
|
2005-08-22 13:46:06 +02:00
|
|
|
dprint(" filled dma[%d]\n", DmaFillNext);
|
|
|
|
DmaFillNext = (DmaFillNext + 1) % DMA_NR_OF_BUFFERS;
|
|
|
|
|
|
|
|
} else if(BufReadNext < 0) { /* Dma buffer full, fill first element of second buffer */
|
|
|
|
|
2006-03-03 11:21:45 +01:00
|
|
|
sys_datacopy(m_ptr->IO_ENDPT, (vir_bytes)m_ptr->ADDRESS, SELF, (vir_bytes)Buffer, (phys_bytes)DspFragmentSize);
|
2005-08-22 13:46:06 +02:00
|
|
|
dprint(" filled buf[0]\n");
|
|
|
|
BufReadNext = 0;
|
|
|
|
BufFillNext = 1;
|
|
|
|
|
|
|
|
} else { /* Dma buffer is full, filling second buffer */
|
|
|
|
|
|
|
|
while(BufReadNext == BufFillNext) { /* Second buffer also full, wait for space to become available */
|
2010-04-08 15:41:35 +02:00
|
|
|
driver_receive(HARDWARE, &mess, &ipc_status);
|
2005-08-22 13:46:06 +02:00
|
|
|
dsp_hardware_msg();
|
|
|
|
}
|
2006-03-03 11:21:45 +01:00
|
|
|
sys_datacopy(m_ptr->IO_ENDPT, (vir_bytes)m_ptr->ADDRESS, SELF, (vir_bytes)Buffer + BufFillNext * DspFragmentSize, (phys_bytes)DspFragmentSize);
|
2005-08-22 13:46:06 +02:00
|
|
|
dprint(" filled buf[%d]\n", BufFillNext);
|
|
|
|
BufFillNext = (BufFillNext + 1) % DSP_NR_OF_BUFFERS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
is_status_msg_expected = TRUE;
|
2005-08-22 13:46:06 +02:00
|
|
|
revivePending = 1;
|
|
|
|
reviveStatus = DspFragmentSize;
|
2006-03-03 11:21:45 +01:00
|
|
|
reviveProcNr = m_ptr->IO_ENDPT;
|
2005-08-22 13:46:06 +02:00
|
|
|
notify(m_ptr->m_source);
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_hardware_msg
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void dsp_hardware_msg()
|
|
|
|
{
|
|
|
|
dprint("Interrupt: ");
|
|
|
|
if(DmaBusy >= 0) { /* Dma transfer was actually busy */
|
|
|
|
dprint("Finished playing dma[%d]; ", DmaBusy);
|
|
|
|
DmaBusy = (DmaBusy + 1) % DMA_NR_OF_BUFFERS;
|
|
|
|
if(DmaBusy == DmaFillNext) { /* Dma buffer empty, stop Dma transfer */
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
dsp_command((DspBits == 8 ? DSP_CMD_DMA8HALT : DSP_CMD_DMA16HALT));
|
|
|
|
dprint("No more work...!\n");
|
|
|
|
DmaBusy = -1;
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
} else if(BufReadNext >= 0) { /* Data in second buffer, copy one fragment to Dma buffer */
|
2005-09-16 13:09:08 +02:00
|
|
|
|
|
|
|
/* Acknowledge the interrupt on the DSP */
|
|
|
|
sb16_inb((DspBits == 8 ? DSP_DATA_AVL : DSP_DATA16_AVL));
|
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
memcpy(DmaPtr + DmaFillNext * DspFragmentSize, Buffer + BufReadNext * DspFragmentSize, DspFragmentSize);
|
|
|
|
dprint("copy buf[%d] -> dma[%d]; ", BufReadNext, DmaFillNext);
|
|
|
|
BufReadNext = (BufReadNext + 1) % DSP_NR_OF_BUFFERS;
|
|
|
|
DmaFillNext = (DmaFillNext + 1) % DMA_NR_OF_BUFFERS;
|
|
|
|
if(BufReadNext == BufFillNext) {
|
|
|
|
BufReadNext = -1;
|
|
|
|
}
|
|
|
|
dprint("Starting dma[%d]\n", DmaBusy);
|
2005-09-16 13:09:08 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
} else { /* Second buffer empty, still data in Dma buffer, continue playback */
|
|
|
|
dprint("Starting dma[%d]\n", DmaBusy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Acknowledge the interrupt on the DSP */
|
2005-09-16 13:09:08 +02:00
|
|
|
sb16_inb((DspBits == 8 ? DSP_DATA_AVL : DSP_DATA16_AVL));
|
2005-08-22 13:46:06 +02:00
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_status *
|
|
|
|
*===========================================================================*/
|
2010-01-27 11:19:13 +01:00
|
|
|
PRIVATE void dsp_status(message *m_ptr)
|
|
|
|
/* m_ptr pointer to the newly arrived message */
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
|
|
|
if(revivePending) {
|
|
|
|
m_ptr->m_type = DEV_REVIVE; /* build message */
|
2006-03-03 11:21:45 +01:00
|
|
|
m_ptr->REP_ENDPT = reviveProcNr;
|
2005-08-22 13:46:06 +02:00
|
|
|
m_ptr->REP_STATUS = reviveStatus;
|
|
|
|
|
|
|
|
revivePending = 0; /* unmark event */
|
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
|
|
|
is_processing = FALSE;
|
2005-08-22 13:46:06 +02:00
|
|
|
} else {
|
|
|
|
m_ptr->m_type = DEV_NO_STATUS;
|
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
|
|
|
|
|
|
|
is_status_msg_expected = FALSE;
|
2005-08-22 13:46:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
send(m_ptr->m_source, m_ptr); /* send the message */
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* reply *
|
|
|
|
*===========================================================================*/
|
2010-01-27 11:19:13 +01:00
|
|
|
PRIVATE void reply(int code, int replyee, int process, int status)
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
|
|
|
message m;
|
|
|
|
|
|
|
|
m.m_type = code; /* TASK_REPLY or REVIVE */
|
|
|
|
m.REP_STATUS = status; /* result of device operation */
|
2006-03-03 11:21:45 +01:00
|
|
|
m.REP_ENDPT = process; /* which user made the request */
|
2005-08-22 13:46:06 +02:00
|
|
|
|
|
|
|
send(replyee, &m);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_init
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int dsp_init()
|
|
|
|
{
|
|
|
|
int i, s;
|
|
|
|
|
|
|
|
if(dsp_reset () != OK) {
|
|
|
|
dprint("sb16: No SoundBlaster card detected\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DspVersion[0] = DspVersion[1] = 0;
|
|
|
|
dsp_command(DSP_GET_VERSION); /* Get DSP version bytes */
|
|
|
|
|
|
|
|
for(i = 1000; i; i--) {
|
2005-09-16 13:09:08 +02:00
|
|
|
if(sb16_inb(DSP_DATA_AVL) & 0x80) {
|
2005-08-22 13:46:06 +02:00
|
|
|
if(DspVersion[0] == 0) {
|
2005-09-16 13:09:08 +02:00
|
|
|
DspVersion[0] = sb16_inb(DSP_READ);
|
2005-08-22 13:46:06 +02:00
|
|
|
} else {
|
2005-09-16 13:09:08 +02:00
|
|
|
DspVersion[1] = sb16_inb(DSP_READ);
|
2005-08-22 13:46:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(DspVersion[0] < 4) {
|
|
|
|
dprint("sb16: No SoundBlaster 16 compatible card detected\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dprint("sb16: SoundBlaster DSP version %d.%d detected\n", DspVersion[0], DspVersion[1]);
|
|
|
|
|
|
|
|
/* set SB to use our IRQ and DMA channels */
|
|
|
|
mixer_set(MIXER_SET_IRQ, (1 << (SB_IRQ / 2 - 1)));
|
|
|
|
mixer_set(MIXER_SET_DMA, (1 << SB_DMA_8 | 1 << SB_DMA_16));
|
|
|
|
|
|
|
|
/* register interrupt vector and enable irq */
|
|
|
|
if ((s=sys_irqsetpolicy(SB_IRQ, IRQ_REENABLE, &irq_hook_id )) != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("Couldn't set IRQ policy: %d", s);
|
2005-08-22 13:46:06 +02:00
|
|
|
if ((s=sys_irqenable(&irq_hook_id)) != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("Couldn't enable IRQ: %d", s);
|
2005-08-22 13:46:06 +02:00
|
|
|
|
|
|
|
DspAvail = 1;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_reset
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int dsp_reset()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
sb16_outb(DSP_RESET, 1);
|
2005-08-22 13:46:06 +02:00
|
|
|
for(i = 0; i < 1000; i++); /* wait a while */
|
2005-09-16 13:09:08 +02:00
|
|
|
sb16_outb(DSP_RESET, 0);
|
2005-08-22 13:46:06 +02:00
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
for(i = 0; i < 1000 && !(sb16_inb(DSP_DATA_AVL) & 0x80); i++);
|
2005-08-22 13:46:06 +02:00
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
if(sb16_inb(DSP_READ) != 0xAA) return EIO; /* No SoundBlaster */
|
2005-08-22 13:46:06 +02:00
|
|
|
|
|
|
|
DmaBusy = -1;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_command
|
|
|
|
*===========================================================================*/
|
2010-01-27 11:19:13 +01:00
|
|
|
PRIVATE int dsp_command(int value)
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
2010-04-01 14:51:31 +02:00
|
|
|
int i;
|
2005-08-22 13:46:06 +02:00
|
|
|
|
|
|
|
for (i = 0; i < SB_TIMEOUT; i++) {
|
2005-09-16 13:09:08 +02:00
|
|
|
if((sb16_inb(DSP_STATUS) & 0x80) == 0) {
|
|
|
|
sb16_outb(DSP_COMMAND, value);
|
2005-08-22 13:46:06 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dprint("sb16: SoundBlaster: DSP Command(%x) timeout\n", value);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_set_size
|
|
|
|
*===========================================================================*/
|
2010-01-27 11:19:13 +01:00
|
|
|
static int dsp_set_size(unsigned int size)
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
|
|
|
dprint("dsp_set_size(): set fragment size to %u\n", size);
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
if(size < DSP_MIN_FRAGMENT_SIZE || size > DSP_MAX_FRAGMENT_SIZE || size % 2 != 0) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DspFragmentSize = size;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_set_speed
|
|
|
|
*===========================================================================*/
|
2010-01-27 11:19:13 +01:00
|
|
|
static int dsp_set_speed(unsigned int speed)
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
|
|
|
dprint("sb16: setting speed to %u, stereo = %d\n", speed, DspStereo);
|
|
|
|
|
|
|
|
if(speed < DSP_MIN_SPEED || speed > DSP_MAX_SPEED) {
|
|
|
|
return EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Soundblaster 16 can be programmed with real sample rates
|
|
|
|
* instead of time constants
|
|
|
|
*
|
|
|
|
* Since you cannot sample and play at the same time
|
|
|
|
* we set in- and output rate to the same value
|
|
|
|
*/
|
|
|
|
|
|
|
|
dsp_command(DSP_INPUT_RATE); /* set input rate */
|
|
|
|
dsp_command(speed >> 8); /* high byte of speed */
|
|
|
|
dsp_command(speed); /* low byte of speed */
|
|
|
|
dsp_command(DSP_OUTPUT_RATE); /* same for output rate */
|
|
|
|
dsp_command(speed >> 8);
|
|
|
|
dsp_command(speed);
|
|
|
|
|
|
|
|
DspSpeed = speed;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_set_stereo
|
|
|
|
*===========================================================================*/
|
2010-01-27 11:19:13 +01:00
|
|
|
static int dsp_set_stereo(unsigned int stereo)
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
|
|
|
if(stereo) {
|
|
|
|
DspStereo = 1;
|
|
|
|
} else {
|
|
|
|
DspStereo = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_set_bits
|
|
|
|
*===========================================================================*/
|
2010-01-27 11:19:13 +01:00
|
|
|
static int dsp_set_bits(unsigned int bits)
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
|
|
|
/* Sanity checks */
|
|
|
|
if(bits != 8 && bits != 16) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DspBits = bits;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_set_sign
|
|
|
|
*===========================================================================*/
|
2010-01-27 11:19:13 +01:00
|
|
|
static int dsp_set_sign(unsigned int sign)
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
|
|
|
dprint("sb16: set sign to %u\n", sign);
|
|
|
|
|
|
|
|
DspSign = (sign > 0 ? 1 : 0);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_dma_setup
|
|
|
|
*===========================================================================*/
|
2010-01-27 11:19:13 +01:00
|
|
|
PRIVATE void dsp_dma_setup(phys_bytes address, int count)
|
2005-08-22 13:46:06 +02:00
|
|
|
{
|
2005-09-16 13:09:08 +02:00
|
|
|
pvb_pair_t pvb[9];
|
|
|
|
|
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
dprint("Setting up %d bit DMA\n", DspBits);
|
|
|
|
|
|
|
|
if(DspBits == 8) { /* 8 bit sound */
|
|
|
|
count--;
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
pv_set(pvb[0], DMA8_MASK, SB_DMA_8 | 0x04); /* Disable DMA channel */
|
|
|
|
pv_set(pvb[1], DMA8_CLEAR, 0x00); /* Clear flip flop */
|
2005-08-22 13:46:06 +02:00
|
|
|
|
|
|
|
/* set DMA mode */
|
2007-02-07 17:22:19 +01:00
|
|
|
pv_set(pvb[2], DMA8_MODE, (DmaMode == DEV_WRITE_S ? DMA8_AUTO_PLAY : DMA8_AUTO_REC));
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2007-02-26 12:52:04 +01:00
|
|
|
pv_set(pvb[3], DMA8_ADDR, (address >> 0) & 0xff); /* Low_byte of address */
|
|
|
|
pv_set(pvb[4], DMA8_ADDR, (address >> 8) & 0xff); /* High byte of address */
|
|
|
|
pv_set(pvb[5], DMA8_PAGE, (address >> 16) & 0xff); /* 64K page number */
|
|
|
|
pv_set(pvb[6], DMA8_COUNT, (count >> 0) & 0xff); /* Low byte of count */
|
|
|
|
pv_set(pvb[7], DMA8_COUNT, (count >> 8) & 0xff); /* High byte of count */
|
2005-09-16 13:09:08 +02:00
|
|
|
pv_set(pvb[8], DMA8_MASK, SB_DMA_8); /* Enable DMA channel */
|
|
|
|
|
|
|
|
sys_voutb(pvb, 9);
|
2005-08-22 13:46:06 +02:00
|
|
|
} else { /* 16 bit sound */
|
|
|
|
count-= 2;
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
pv_set(pvb[0], DMA16_MASK, (SB_DMA_16 & 3) | 0x04); /* Disable DMA channel */
|
|
|
|
|
|
|
|
pv_set(pvb[1], DMA16_CLEAR, 0x00); /* Clear flip flop */
|
2005-08-22 13:46:06 +02:00
|
|
|
|
|
|
|
/* Set dma mode */
|
2007-02-07 17:22:19 +01:00
|
|
|
pv_set(pvb[2], DMA16_MODE, (DmaMode == DEV_WRITE_S ? DMA16_AUTO_PLAY : DMA16_AUTO_REC));
|
2005-09-16 13:09:08 +02:00
|
|
|
|
|
|
|
pv_set(pvb[3], DMA16_ADDR, (address >> 1) & 0xFF); /* Low_byte of address */
|
|
|
|
pv_set(pvb[4], DMA16_ADDR, (address >> 9) & 0xFF); /* High byte of address */
|
|
|
|
pv_set(pvb[5], DMA16_PAGE, (address >> 16) & 0xFE); /* 128K page number */
|
2007-02-26 12:52:04 +01:00
|
|
|
pv_set(pvb[6], DMA16_COUNT, (count >> 1) & 0xff); /* Low byte of count */
|
|
|
|
pv_set(pvb[7], DMA16_COUNT, (count >> 9) & 0xff); /* High byte of count */
|
2005-09-16 13:09:08 +02:00
|
|
|
pv_set(pvb[8], DMA16_MASK, SB_DMA_16 & 3); /* Enable DMA channel */
|
|
|
|
|
|
|
|
sys_voutb(pvb, 9);
|
2005-08-22 13:46:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|
2005-08-22 13:46:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dsp_setup()
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void dsp_setup()
|
|
|
|
{
|
|
|
|
/* Set current sample speed */
|
|
|
|
dsp_set_speed(DspSpeed);
|
|
|
|
|
|
|
|
/* Put the speaker on */
|
2007-02-07 17:22:19 +01:00
|
|
|
if(DmaMode == DEV_WRITE_S) {
|
2005-08-22 13:46:06 +02:00
|
|
|
dsp_command (DSP_CMD_SPKON); /* put speaker on */
|
|
|
|
|
|
|
|
/* Program DSP with dma mode */
|
|
|
|
dsp_command((DspBits == 8 ? DSP_CMD_8BITAUTO_OUT : DSP_CMD_16BITAUTO_OUT));
|
|
|
|
} else {
|
|
|
|
dsp_command (DSP_CMD_SPKOFF); /* put speaker off */
|
|
|
|
|
|
|
|
/* Program DSP with dma mode */
|
|
|
|
dsp_command((DspBits == 8 ? DSP_CMD_8BITAUTO_IN : DSP_CMD_16BITAUTO_IN));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Program DSP with transfer mode */
|
|
|
|
if (!DspSign) {
|
|
|
|
dsp_command((DspStereo == 1 ? DSP_MODE_STEREO_US : DSP_MODE_MONO_US));
|
|
|
|
} else {
|
|
|
|
dsp_command((DspStereo == 1 ? DSP_MODE_STEREO_S : DSP_MODE_MONO_S));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Give length of fragment to DSP */
|
|
|
|
if (DspBits == 8) { /* 8 bit transfer */
|
|
|
|
/* #bytes - 1 */
|
|
|
|
dsp_command((DspFragmentSize - 1) >> 0);
|
|
|
|
dsp_command((DspFragmentSize - 1) >> 8);
|
|
|
|
} else { /* 16 bit transfer */
|
|
|
|
/* #words - 1 */
|
|
|
|
dsp_command((DspFragmentSize - 1) >> 1);
|
|
|
|
dsp_command((DspFragmentSize - 1) >> 9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-16 13:09:08 +02:00
|
|
|
|