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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 659ebd86 was b688fd8, checked in by Martin Decky <martin@…>, 10 years ago

gradually introduce async ports, initial phase

The initial phase is to reimplement the traditional async client connections as an untyped fallback port. This creates the possibility to introduce ports typed by interface type gradually in later changesets.

  • Property mode set to 100644
File size: 4.4 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 %d", 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_CLEAR_INTERRUPT:
104 /* Noop */
105 async_answer_0(callid, EOK);
106 break;
107 default:
108 async_answer_0(callid, EINVAL);
109 break;
110 }
111 }
112}
113
114static int icpic_init(void)
115{
116 char *platform = NULL;
117 char *pstr = NULL;
118 size_t platform_size;
119 void *regs;
120 int rc;
121
122 platform = sysinfo_get_data("platform", &platform_size);
123 if (platform == NULL) {
124 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting platform type.");
125 rc = ENOENT;
126 goto error;
127 }
128
129 pstr = str_ndup(platform, platform_size);
130 if (pstr == NULL) {
131 log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory.");
132 rc = ENOMEM;
133 goto error;
134 }
135
136 if (str_cmp(pstr, "integratorcp") != 0) {
137 log_msg(LOG_DEFAULT, LVL_ERROR, "Platform '%s' is not 'integratorcp'.",
138
139 pstr);
140 rc = ENOENT;
141 goto error;
142 }
143
144 rc = pio_enable((void *)icp_pic_base, sizeof(icpic_regs_t), &regs);
145 if (rc != EOK) {
146 log_msg(LOG_DEFAULT, LVL_ERROR, "Error enabling PIO");
147 goto error;
148 }
149
150 icpic_regs = (icpic_regs_t *)regs;
151
152 async_set_fallback_port_handler(icpic_connection, NULL);
153 service_register(SERVICE_IRC);
154
155 free(platform);
156 free(pstr);
157 return EOK;
158error:
159 free(platform);
160 free(pstr);
161 return rc;
162}
163
164int main(int argc, char **argv)
165{
166 int rc;
167
168 printf("%s: HelenOS IntegratorCP interrupt controller driver\n", NAME);
169
170 rc = log_init(NAME);
171 if (rc != EOK) {
172 printf(NAME ": Error connecting logging service.");
173 return 1;
174 }
175
176 if (icpic_init() != EOK)
177 return -1;
178
179 log_msg(LOG_DEFAULT, LVL_NOTE, "%s: Accepting connections\n", NAME);
180 task_retval(0);
181 async_manager();
182
183 /* Not reached */
184 return 0;
185}
186
187/**
188 * @}
189 */
Note: See TracBrowser for help on using the repository browser.