1 | /*
|
---|
2 | * Copyright (c) 2014 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup libc
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | */
|
---|
34 |
|
---|
35 | #include <assert.h>
|
---|
36 | #include <async.h>
|
---|
37 | #include <errno.h>
|
---|
38 | #include <fibril.h>
|
---|
39 | #include <ipc/irc.h>
|
---|
40 | #include <ipc/services.h>
|
---|
41 | #include <irc.h>
|
---|
42 | #include <loc.h>
|
---|
43 | #include <stdlib.h>
|
---|
44 | #include <sysinfo.h>
|
---|
45 |
|
---|
46 | static async_sess_t *irc_sess;
|
---|
47 |
|
---|
48 | /** Connect to IRC service.
|
---|
49 | *
|
---|
50 | * @return EOK on success, EIO on failure
|
---|
51 | */
|
---|
52 | static errno_t irc_init(void)
|
---|
53 | {
|
---|
54 | category_id_t irc_cat;
|
---|
55 | service_id_t *svcs;
|
---|
56 | size_t count;
|
---|
57 | errno_t rc;
|
---|
58 |
|
---|
59 | assert(irc_sess == NULL);
|
---|
60 | rc = loc_category_get_id("irc", &irc_cat, IPC_FLAG_BLOCKING);
|
---|
61 | if (rc != EOK)
|
---|
62 | return EIO;
|
---|
63 |
|
---|
64 | while (true) {
|
---|
65 | rc = loc_category_get_svcs(irc_cat, &svcs, &count);
|
---|
66 | if (rc != EOK)
|
---|
67 | return EIO;
|
---|
68 |
|
---|
69 | if (count > 0)
|
---|
70 | break;
|
---|
71 |
|
---|
72 | free(svcs);
|
---|
73 |
|
---|
74 | // XXX This is just a temporary hack
|
---|
75 | fibril_usleep(500 * 1000);
|
---|
76 | }
|
---|
77 |
|
---|
78 | irc_sess = loc_service_connect(svcs[0], INTERFACE_IRC,
|
---|
79 | IPC_FLAG_BLOCKING);
|
---|
80 | free(svcs);
|
---|
81 |
|
---|
82 | if (irc_sess == NULL)
|
---|
83 | return EIO;
|
---|
84 |
|
---|
85 | return EOK;
|
---|
86 | }
|
---|
87 |
|
---|
88 | /** Enable interrupt.
|
---|
89 | *
|
---|
90 | * Allow interrupt delivery.
|
---|
91 | *
|
---|
92 | * @param irq IRQ number
|
---|
93 | */
|
---|
94 | errno_t irc_enable_interrupt(int irq)
|
---|
95 | {
|
---|
96 | errno_t rc;
|
---|
97 |
|
---|
98 | if (irc_sess == NULL) {
|
---|
99 | rc = irc_init();
|
---|
100 | if (rc != EOK)
|
---|
101 | return rc;
|
---|
102 | }
|
---|
103 |
|
---|
104 | async_exch_t *exch = async_exchange_begin(irc_sess);
|
---|
105 | rc = async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
|
---|
106 | async_exchange_end(exch);
|
---|
107 |
|
---|
108 | return rc;
|
---|
109 | }
|
---|
110 |
|
---|
111 | /** Disable interrupt.
|
---|
112 | *
|
---|
113 | * Disallow interrupt delivery.
|
---|
114 | *
|
---|
115 | * @param irq IRQ number
|
---|
116 | */
|
---|
117 | errno_t irc_disable_interrupt(int irq)
|
---|
118 | {
|
---|
119 | errno_t rc;
|
---|
120 |
|
---|
121 | if (irc_sess == NULL) {
|
---|
122 | rc = irc_init();
|
---|
123 | if (rc != EOK)
|
---|
124 | return rc;
|
---|
125 | }
|
---|
126 |
|
---|
127 | async_exch_t *exch = async_exchange_begin(irc_sess);
|
---|
128 | rc = async_req_1_0(exch, IRC_DISABLE_INTERRUPT, irq);
|
---|
129 | async_exchange_end(exch);
|
---|
130 |
|
---|
131 | return rc;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /** Clear interrupt.
|
---|
135 | *
|
---|
136 | * Clear/acknowledge interrupt in interrupt controller so that
|
---|
137 | * another interrupt can be delivered.
|
---|
138 | *
|
---|
139 | * @param irq IRQ number
|
---|
140 | */
|
---|
141 | errno_t irc_clear_interrupt(int irq)
|
---|
142 | {
|
---|
143 | errno_t rc;
|
---|
144 |
|
---|
145 | if (irc_sess == NULL) {
|
---|
146 | rc = irc_init();
|
---|
147 | if (rc != EOK)
|
---|
148 | return rc;
|
---|
149 | }
|
---|
150 |
|
---|
151 | async_exch_t *exch = async_exchange_begin(irc_sess);
|
---|
152 | rc = async_req_1_0(exch, IRC_CLEAR_INTERRUPT, irq);
|
---|
153 | async_exchange_end(exch);
|
---|
154 |
|
---|
155 | return rc;
|
---|
156 | }
|
---|
157 |
|
---|
158 | /** @}
|
---|
159 | */
|
---|