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