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

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

As a temporary measure, let IRC servers use the location service for DDF-compatible naming. This is needed until all interrupt controller drivers are in DDF and we can switch to DDF-based naming.

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