source: mainline/uspace/drv/intctl/icp-ic/icp-ic.c@ 5a6cc679

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5a6cc679 was 5a6cc679, checked in by Jenda <jenda.jzqk73@…>, 8 years ago

Merge commit '50f19b7ee8e94570b5c63896736c4eb49cfa18db' into forwardport

Not all ints are converted to errno_t in xhci tree yet, however it compiles and works :)

  • Property mode set to 100644
File size: 4.0 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 icp-ic
30 * @{
31 */
32
33/**
34 * @file icp-ic.c
35 * @brief IntegratorCP interrupt controller driver
36 */
37
38#include <async.h>
39#include <bitops.h>
40#include <ddi.h>
41#include <ddf/log.h>
42#include <errno.h>
43#include <str_error.h>
44#include <ipc/irc.h>
45#include <stdint.h>
46
47#include "icp-ic.h"
48#include "icp-ic_hw.h"
49
50enum {
51 icpic_max_irq = 32
52};
53
54static errno_t icpic_enable_irq(icpic_t *icpic, sysarg_t irq)
55{
56 if (irq > icpic_max_irq)
57 return EINVAL;
58
59 ddf_msg(LVL_NOTE, "Enable IRQ %zu", irq);
60
61 pio_write_32(&icpic->regs->irq_enableset, BIT_V(uint32_t, irq));
62 return EOK;
63}
64
65/** Client connection handler.
66 *
67 * @param iid Hash of the request that opened the connection.
68 * @param icall Call data of the request that opened the connection.
69 * @param arg Local argument.
70 */
71static void icpic_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
72{
73 ipc_callid_t callid;
74 ipc_call_t call;
75 icpic_t *icpic;
76
77 /*
78 * Answer the first IPC_M_CONNECT_ME_TO call.
79 */
80 async_answer_0(iid, EOK);
81
82 icpic = (icpic_t *)ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *)arg));
83
84 while (true) {
85 callid = async_get_call(&call);
86
87 if (!IPC_GET_IMETHOD(call)) {
88 /* The other side has hung up. */
89 async_answer_0(callid, EOK);
90 return;
91 }
92
93 switch (IPC_GET_IMETHOD(call)) {
94 case IRC_ENABLE_INTERRUPT:
95 async_answer_0(callid,
96 icpic_enable_irq(icpic, IPC_GET_ARG1(call)));
97 break;
98 case IRC_DISABLE_INTERRUPT:
99 /* XXX TODO */
100 async_answer_0(callid, EOK);
101 break;
102 case IRC_CLEAR_INTERRUPT:
103 /* Noop */
104 async_answer_0(callid, EOK);
105 break;
106 default:
107 async_answer_0(callid, EINVAL);
108 break;
109 }
110 }
111}
112
113/** Add icp-ic device. */
114errno_t icpic_add(icpic_t *icpic, icpic_res_t *res)
115{
116 ddf_fun_t *fun_a = NULL;
117 void *regs;
118 errno_t rc;
119
120 rc = pio_enable((void *)res->base, sizeof(icpic_regs_t), &regs);
121 if (rc != EOK) {
122 ddf_msg(LVL_ERROR, "Error enabling PIO");
123 goto error;
124 }
125
126 icpic->regs = (icpic_regs_t *)regs;
127
128 fun_a = ddf_fun_create(icpic->dev, fun_exposed, "a");
129 if (fun_a == NULL) {
130 ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
131 rc = ENOMEM;
132 goto error;
133 }
134
135 ddf_fun_set_conn_handler(fun_a, icpic_connection);
136
137 rc = ddf_fun_bind(fun_a);
138 if (rc != EOK) {
139 ddf_msg(LVL_ERROR, "Failed binding function 'a': %s", str_error(rc));
140 goto error;
141 }
142
143 rc = ddf_fun_add_to_category(fun_a, "irc");
144 if (rc != EOK)
145 goto error;
146
147 return EOK;
148error:
149 if (fun_a != NULL)
150 ddf_fun_destroy(fun_a);
151 return rc;
152}
153
154/** Remove icp-ic device */
155errno_t icpic_remove(icpic_t *icpic)
156{
157 return ENOTSUP;
158}
159
160/** icp-ic device gone */
161errno_t icpic_gone(icpic_t *icpic)
162{
163 return ENOTSUP;
164}
165
166/**
167 * @}
168 */
Note: See TracBrowser for help on using the repository browser.