minix/kernel/system/do_irqctl.c

130 lines
4.4 KiB
C
Raw Normal View History

/* The kernel call implemented in this file:
2005-04-21 16:53:53 +02:00
* m_type: SYS_IRQCTL
*
* The parameters for this kernel call are:
2005-04-21 16:53:53 +02:00
* m5_c1: IRQ_REQUEST (control operation to perform)
* m5_c2: IRQ_VECTOR (irq line that must be controlled)
2005-05-02 16:30:04 +02:00
* m5_i1: IRQ_POLICY (irq policy allows reenabling interrupts)
* m5_l3: IRQ_HOOK_ID (provides index to be returned on interrupt)
* ,, ,, (returns index of irq hook assigned at kernel)
2005-04-21 16:53:53 +02:00
*/
#include "../system.h"
#if USE_IRQCTL
FORWARD _PROTOTYPE(int generic_handler, (irq_hook_t *hook));
2005-04-21 16:53:53 +02:00
/*===========================================================================*
2005-05-02 16:30:04 +02:00
* do_irqctl *
2005-04-21 16:53:53 +02:00
*===========================================================================*/
PUBLIC int do_irqctl(m_ptr)
register message *m_ptr; /* pointer to request message */
{
/* Dismember the request message. */
2005-05-02 16:30:04 +02:00
int irq_vec;
int irq_hook_id;
int notify_id;
int r = OK;
2005-05-02 16:30:04 +02:00
irq_hook_t *hook_ptr;
2005-04-21 16:53:53 +02:00
/* Hook identifiers start at 1 and end at NR_IRQ_HOOKS. */
irq_hook_id = (unsigned) m_ptr->IRQ_HOOK_ID - 1;
irq_vec = (unsigned) m_ptr->IRQ_VECTOR;
2005-04-21 16:53:53 +02:00
/* See what is requested and take needed actions. */
switch(m_ptr->IRQ_REQUEST) {
/* Enable or disable IRQs. This is straightforward. */
case IRQ_ENABLE:
case IRQ_DISABLE:
if (irq_hook_id >= NR_IRQ_HOOKS ||
irq_hooks[irq_hook_id].proc_nr == NONE) return(EINVAL);
if (irq_hooks[irq_hook_id].proc_nr != m_ptr->m_source) return(EPERM);
if (m_ptr->IRQ_REQUEST == IRQ_ENABLE)
enable_irq(&irq_hooks[irq_hook_id]);
else
disable_irq(&irq_hooks[irq_hook_id]);
2005-04-21 16:53:53 +02:00
break;
2005-04-21 16:53:53 +02:00
/* Control IRQ policies. Set a policy and needed details in the IRQ table.
* This policy is used by a generic function to handle hardware interrupts.
*/
case IRQ_SETPOLICY:
2005-04-21 16:53:53 +02:00
2005-05-02 16:30:04 +02:00
/* Check if IRQ line is acceptable. */
if (irq_vec < 0 || irq_vec >= NR_IRQ_VECTORS) return(EINVAL);
2005-05-02 16:30:04 +02:00
/* Find a free IRQ hook for this mapping. */
hook_ptr = NULL;
for (irq_hook_id=0; irq_hook_id<NR_IRQ_HOOKS; irq_hook_id++) {
if (irq_hooks[irq_hook_id].proc_nr == NONE) {
hook_ptr = &irq_hooks[irq_hook_id]; /* free hook */
break;
}
2005-04-21 16:53:53 +02:00
}
2005-05-02 16:30:04 +02:00
if (hook_ptr == NULL) return(ENOSPC);
/* When setting a policy, the caller must provide an identifier that
* is returned on the notification message if a interrupt occurs.
*/
notify_id = (unsigned) m_ptr->IRQ_HOOK_ID;
if (notify_id > CHAR_BIT * sizeof(irq_id_t) - 1) return(EINVAL);
/* Install the handler. */
2005-05-02 16:30:04 +02:00
hook_ptr->proc_nr = m_ptr->m_source; /* process to notify */
hook_ptr->notify_id = notify_id; /* identifier to pass */
2005-05-02 16:30:04 +02:00
hook_ptr->policy = m_ptr->IRQ_POLICY; /* policy for interrupts */
put_irq_handler(hook_ptr, irq_vec, generic_handler);
/* Return index of the IRQ hook in use. */
m_ptr->IRQ_HOOK_ID = irq_hook_id + 1;
2005-04-21 16:53:53 +02:00
break;
case IRQ_RMPOLICY:
if (irq_hook_id >= NR_IRQ_HOOKS ||
irq_hooks[irq_hook_id].proc_nr == NONE) {
return(EINVAL);
} else if (m_ptr->m_source != irq_hooks[irq_hook_id].proc_nr) {
return(EPERM);
}
/* Remove the handler and return. */
rm_irq_handler(&irq_hooks[irq_hook_id]);
break;
2005-04-21 16:53:53 +02:00
default:
r = EINVAL; /* invalid IRQ_REQUEST */
2005-04-21 16:53:53 +02:00
}
return(r);
2005-04-21 16:53:53 +02:00
}
/*===========================================================================*
* generic_handler *
*===========================================================================*/
PRIVATE int generic_handler(hook)
irq_hook_t *hook;
{
/* This function handles hardware interrupt in a simple and generic way. All
* interrupts are transformed into messages to a driver. The IRQ line will be
* reenabled if the policy says so.
*/
/* As a side-effect, the interrupt handler gathers random information by
* timestamping the interrupt events. This is used for /dev/random.
*/
get_randomness(hook->irq);
/* Add a bit for this interrupt to the process' pending interrupts. When
* sending the notification message, this bit map will be magically set
* as an argument.
*/
priv(proc_addr(hook->proc_nr))->s_int_pending |= (1 << hook->notify_id);
/* Build notification message and return. */
lock_notify(HARDWARE, hook->proc_nr);
return(hook->policy & IRQ_REENABLE);
}
#endif /* USE_IRQCTL */