source: mainline/uspace/srv/hw/irc/icp-ic/icp-ic.c@ d75dc05

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d75dc05 was 07cb0108, checked in by Jiri Svoboda <jiri@…>, 8 years ago

Sort out irc_disable_interrupt vs irc_clear_interrupt.

  • Property mode set to 100644
File size: 4.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 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 <errno.h>
42#include <io/log.h>
43#include <ipc/services.h>
44#include <ipc/irc.h>
45#include <ns.h>
46#include <sysinfo.h>
47#include <stdio.h>
48#include <stdint.h>
49#include <str.h>
50
51#include "icp-ic_hw.h"
52
53#define NAME "icp-ic"
54
55enum {
56 icp_pic_base = 0x14000000,
57 icpic_max_irq = 32
58};
59
60static icpic_regs_t *icpic_regs;
61
62static int icpic_enable_irq(sysarg_t irq)
63{
64 if (irq > icpic_max_irq)
65 return EINVAL;
66
67 log_msg(LOG_DEFAULT, LVL_NOTE, "Enable IRQ %zu", irq);
68
69 pio_write_32(&icpic_regs->irq_enableset, BIT_V(uint32_t, irq));
70 return EOK;
71}
72
73/** Handle one connection to i8259.
74 *
75 * @param iid Hash of the request that opened the connection.
76 * @param icall Call data of the request that opened the connection.
77 * @param arg Local argument.
78 */
79static void icpic_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
80{
81 ipc_callid_t callid;
82 ipc_call_t call;
83
84 /*
85 * Answer the first IPC_M_CONNECT_ME_TO call.
86 */
87 async_answer_0(iid, EOK);
88
89 while (true) {
90 callid = async_get_call(&call);
91
92 if (!IPC_GET_IMETHOD(call)) {
93 /* The other side has hung up. */
94 async_answer_0(callid, EOK);
95 return;
96 }
97
98 switch (IPC_GET_IMETHOD(call)) {
99 case IRC_ENABLE_INTERRUPT:
100 async_answer_0(callid,
101 icpic_enable_irq(IPC_GET_ARG1(call)));
102 break;
103 case IRC_DISABLE_INTERRUPT:
104 /* XXX TODO */
105 async_answer_0(callid, EOK);
106 break;
107 case IRC_CLEAR_INTERRUPT:
108 /* Noop */
109 async_answer_0(callid, EOK);
110 break;
111 default:
112 async_answer_0(callid, EINVAL);
113 break;
114 }
115 }
116}
117
118static int icpic_init(void)
119{
120 char *platform = NULL;
121 char *pstr = NULL;
122 size_t platform_size;
123 void *regs;
124 int rc;
125
126 platform = sysinfo_get_data("platform", &platform_size);
127 if (platform == NULL) {
128 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting platform type.");
129 rc = ENOENT;
130 goto error;
131 }
132
133 pstr = str_ndup(platform, platform_size);
134 if (pstr == NULL) {
135 log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory.");
136 rc = ENOMEM;
137 goto error;
138 }
139
140 if (str_cmp(pstr, "integratorcp") != 0) {
141 log_msg(LOG_DEFAULT, LVL_ERROR, "Platform '%s' is not 'integratorcp'.",
142
143 pstr);
144 rc = ENOENT;
145 goto error;
146 }
147
148 rc = pio_enable((void *)icp_pic_base, sizeof(icpic_regs_t), &regs);
149 if (rc != EOK) {
150 log_msg(LOG_DEFAULT, LVL_ERROR, "Error enabling PIO");
151 goto error;
152 }
153
154 icpic_regs = (icpic_regs_t *)regs;
155
156 async_set_fallback_port_handler(icpic_connection, NULL);
157 service_register(SERVICE_IRC);
158
159 free(platform);
160 free(pstr);
161 return EOK;
162error:
163 free(platform);
164 free(pstr);
165 return rc;
166}
167
168int main(int argc, char **argv)
169{
170 int rc;
171
172 printf("%s: HelenOS IntegratorCP interrupt controller driver\n", NAME);
173
174 rc = log_init(NAME);
175 if (rc != EOK) {
176 printf(NAME ": Error connecting logging service.");
177 return 1;
178 }
179
180 if (icpic_init() != EOK)
181 return -1;
182
183 log_msg(LOG_DEFAULT, LVL_NOTE, "%s: Accepting connections\n", NAME);
184 task_retval(0);
185 async_manager();
186
187 /* Not reached */
188 return 0;
189}
190
191/**
192 * @}
193 */
Note: See TracBrowser for help on using the repository browser.