source: mainline/uspace/lib/c/generic/irc.c@ c8afd5a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c8afd5a was b7fd2a0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Use errno_t in all uspace and kernel code.

Change type of every variable, parameter and return value that holds an
<errno.h> constant to either errno_t (the usual case), or sys_errno_t
(some places in kernel). This is for the purpose of self-documentation,
as well as for type-checking with a bit of type definition hackery.

Although this is a massive commit, it is a simple text replacement, and thus
is very easy to verify. Simply do the following:

`
git checkout <this commit's hash>
git reset HEAD
git add .
tools/srepl '\berrno_t\b' int
git add .
tools/srepl '\bsys_errno_t\b' sysarg_t
git reset
git diff
`

While this doesn't ensure that the replacements are correct, it does ensure
that the commit doesn't do anything except those replacements. Since errno_t
is typedef'd to int in the usual case (and sys_errno_t to sysarg_t), even if
incorrect, this commit cannot change behavior.

  • Property mode set to 100644
File size: 3.5 KB
Line 
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 <ipc/irc.h>
39#include <ipc/services.h>
40#include <irc.h>
41#include <loc.h>
42#include <stdlib.h>
43#include <sysinfo.h>
44
45static async_sess_t *irc_sess;
46
47/** Connect to IRC service.
48 *
49 * @return EOK on success, EIO on failure
50 */
51static errno_t irc_init(void)
52{
53 category_id_t irc_cat;
54 service_id_t *svcs;
55 size_t count;
56 errno_t rc;
57
58 assert(irc_sess == NULL);
59 rc = loc_category_get_id("irc", &irc_cat, IPC_FLAG_BLOCKING);
60 if (rc != EOK)
61 return EIO;
62
63 while (true) {
64 rc = loc_category_get_svcs(irc_cat, &svcs, &count);
65 if (rc != EOK)
66 return EIO;
67
68 if (count > 0)
69 break;
70
71 free(svcs);
72
73 // XXX This is just a temporary hack
74 async_usleep(500 * 1000);
75 }
76
77 irc_sess = loc_service_connect(svcs[0], INTERFACE_IRC,
78 IPC_FLAG_BLOCKING);
79 free(svcs);
80
81 if (irc_sess == NULL)
82 return EIO;
83
84 return EOK;
85}
86
87/** Enable interrupt.
88 *
89 * Allow interrupt delivery.
90 *
91 * @param irq IRQ number
92 */
93errno_t irc_enable_interrupt(int irq)
94{
95 errno_t rc;
96
97 if (irc_sess == NULL) {
98 rc = irc_init();
99 if (rc != EOK)
100 return rc;
101 }
102
103 async_exch_t *exch = async_exchange_begin(irc_sess);
104 rc = async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
105 async_exchange_end(exch);
106
107 return rc;
108}
109
110/** Disable interrupt.
111 *
112 * Disallow interrupt delivery.
113 *
114 * @param irq IRQ number
115 */
116errno_t irc_disable_interrupt(int irq)
117{
118 errno_t rc;
119
120 if (irc_sess == NULL) {
121 rc = irc_init();
122 if (rc != EOK)
123 return rc;
124 }
125
126 async_exch_t *exch = async_exchange_begin(irc_sess);
127 rc = async_req_1_0(exch, IRC_DISABLE_INTERRUPT, irq);
128 async_exchange_end(exch);
129
130 return rc;
131}
132
133/** Clear interrupt.
134 *
135 * Clear/acknowledge interrupt in interrupt controller so that
136 * another interrupt can be delivered.
137 *
138 * @param irq IRQ number
139 */
140errno_t irc_clear_interrupt(int irq)
141{
142 errno_t rc;
143
144 if (irc_sess == NULL) {
145 rc = irc_init();
146 if (rc != EOK)
147 return rc;
148 }
149
150 async_exch_t *exch = async_exchange_begin(irc_sess);
151 rc = async_req_1_0(exch, IRC_CLEAR_INTERRUPT, irq);
152 async_exchange_end(exch);
153
154 return rc;
155}
156
157/** @}
158 */
Note: See TracBrowser for help on using the repository browser.