source: branches/minix3-book/kernel/system/do_irqctl.c@ 25

Last change on this file since 25 was 4, checked in by Mattia Monga, 14 years ago

Importazione sorgenti libro

File size: 4.4 KB
Line 
1/* The kernel call implemented in this file:
2 * m_type: SYS_IRQCTL
3 *
4 * The parameters for this kernel call are:
5 * m5_c1: IRQ_REQUEST (control operation to perform)
6 * m5_c2: IRQ_VECTOR (irq line that must be controlled)
7 * m5_i1: IRQ_POLICY (irq policy allows reenabling interrupts)
8 * m5_l3: IRQ_HOOK_ID (provides index to be returned on interrupt)
9 * ,, ,, (returns index of irq hook assigned at kernel)
10 */
11
12#include "../system.h"
13
14#if USE_IRQCTL
15
16FORWARD _PROTOTYPE(int generic_handler, (irq_hook_t *hook));
17
18/*===========================================================================*
19 * do_irqctl *
20 *===========================================================================*/
21PUBLIC int do_irqctl(m_ptr)
22register message *m_ptr; /* pointer to request message */
23{
24 /* Dismember the request message. */
25 int irq_vec;
26 int irq_hook_id;
27 int notify_id;
28 int r = OK;
29 irq_hook_t *hook_ptr;
30
31 /* Hook identifiers start at 1 and end at NR_IRQ_HOOKS. */
32 irq_hook_id = (unsigned) m_ptr->IRQ_HOOK_ID - 1;
33 irq_vec = (unsigned) m_ptr->IRQ_VECTOR;
34
35 /* See what is requested and take needed actions. */
36 switch(m_ptr->IRQ_REQUEST) {
37
38 /* Enable or disable IRQs. This is straightforward. */
39 case IRQ_ENABLE:
40 case IRQ_DISABLE:
41 if (irq_hook_id >= NR_IRQ_HOOKS ||
42 irq_hooks[irq_hook_id].proc_nr == NONE) return(EINVAL);
43 if (irq_hooks[irq_hook_id].proc_nr != m_ptr->m_source) return(EPERM);
44 if (m_ptr->IRQ_REQUEST == IRQ_ENABLE)
45 enable_irq(&irq_hooks[irq_hook_id]);
46 else
47 disable_irq(&irq_hooks[irq_hook_id]);
48 break;
49
50 /* Control IRQ policies. Set a policy and needed details in the IRQ table.
51 * This policy is used by a generic function to handle hardware interrupts.
52 */
53 case IRQ_SETPOLICY:
54
55 /* Check if IRQ line is acceptable. */
56 if (irq_vec < 0 || irq_vec >= NR_IRQ_VECTORS) return(EINVAL);
57
58 /* Find a free IRQ hook for this mapping. */
59 hook_ptr = NULL;
60 for (irq_hook_id=0; irq_hook_id<NR_IRQ_HOOKS; irq_hook_id++) {
61 if (irq_hooks[irq_hook_id].proc_nr == NONE) {
62 hook_ptr = &irq_hooks[irq_hook_id]; /* free hook */
63 break;
64 }
65 }
66 if (hook_ptr == NULL) return(ENOSPC);
67
68 /* When setting a policy, the caller must provide an identifier that
69 * is returned on the notification message if a interrupt occurs.
70 */
71 notify_id = (unsigned) m_ptr->IRQ_HOOK_ID;
72 if (notify_id > CHAR_BIT * sizeof(irq_id_t) - 1) return(EINVAL);
73
74 /* Install the handler. */
75 hook_ptr->proc_nr = m_ptr->m_source; /* process to notify */
76 hook_ptr->notify_id = notify_id; /* identifier to pass */
77 hook_ptr->policy = m_ptr->IRQ_POLICY; /* policy for interrupts */
78 put_irq_handler(hook_ptr, irq_vec, generic_handler);
79
80 /* Return index of the IRQ hook in use. */
81 m_ptr->IRQ_HOOK_ID = irq_hook_id + 1;
82 break;
83
84 case IRQ_RMPOLICY:
85 if (irq_hook_id >= NR_IRQ_HOOKS ||
86 irq_hooks[irq_hook_id].proc_nr == NONE) {
87 return(EINVAL);
88 } else if (m_ptr->m_source != irq_hooks[irq_hook_id].proc_nr) {
89 return(EPERM);
90 }
91 /* Remove the handler and return. */
92 rm_irq_handler(&irq_hooks[irq_hook_id]);
93 break;
94
95 default:
96 r = EINVAL; /* invalid IRQ_REQUEST */
97 }
98 return(r);
99}
100
101/*===========================================================================*
102 * generic_handler *
103 *===========================================================================*/
104PRIVATE int generic_handler(hook)
105irq_hook_t *hook;
106{
107/* This function handles hardware interrupt in a simple and generic way. All
108 * interrupts are transformed into messages to a driver. The IRQ line will be
109 * reenabled if the policy says so.
110 */
111
112 /* As a side-effect, the interrupt handler gathers random information by
113 * timestamping the interrupt events. This is used for /dev/random.
114 */
115 get_randomness(hook->irq);
116
117 /* Add a bit for this interrupt to the process' pending interrupts. When
118 * sending the notification message, this bit map will be magically set
119 * as an argument.
120 */
121 priv(proc_addr(hook->proc_nr))->s_int_pending |= (1 << hook->notify_id);
122
123 /* Build notification message and return. */
124 lock_notify(HARDWARE, hook->proc_nr);
125 return(hook->policy & IRQ_REENABLE);
126}
127
128#endif /* USE_IRQCTL */
129
Note: See TracBrowser for help on using the repository browser.