1 | /*
|
---|
2 | * Copyright (c) 2009 Jakub Jermar
|
---|
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 obio
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * @file obio.c
|
---|
35 | * @brief OBIO driver.
|
---|
36 | *
|
---|
37 | * OBIO is a short for on-board I/O. On UltraSPARC IIi and systems with U2P,
|
---|
38 | * there is a piece of the root PCI bus controller address space, which
|
---|
39 | * contains interrupt mapping and clear registers for all on-board devices.
|
---|
40 | * Although UltraSPARC IIi and U2P are different in general, these registers can
|
---|
41 | * be found at the same addresses.
|
---|
42 | */
|
---|
43 |
|
---|
44 | #include <async.h>
|
---|
45 | #include <ddf/driver.h>
|
---|
46 | #include <ddf/log.h>
|
---|
47 | #include <ddi.h>
|
---|
48 | #include <errno.h>
|
---|
49 | #include <str_error.h>
|
---|
50 | #include <inttypes.h>
|
---|
51 | #include <ipc/irc.h>
|
---|
52 | #include <stdbool.h>
|
---|
53 | #include <stdio.h>
|
---|
54 |
|
---|
55 | #include "obio.h"
|
---|
56 |
|
---|
57 | #define NAME "obio"
|
---|
58 |
|
---|
59 | #define OBIO_SIZE 0x1898
|
---|
60 |
|
---|
61 | #define OBIO_IMR_BASE 0x200
|
---|
62 | #define OBIO_IMR(ino) (OBIO_IMR_BASE + ((ino) & INO_MASK))
|
---|
63 |
|
---|
64 | #define OBIO_CIR_BASE 0x300
|
---|
65 | #define OBIO_CIR(ino) (OBIO_CIR_BASE + ((ino) & INO_MASK))
|
---|
66 |
|
---|
67 | #define INO_MASK 0x1f
|
---|
68 |
|
---|
69 | /** Handle one connection to obio.
|
---|
70 | *
|
---|
71 | * @param icall Call data of the request that opened the connection.
|
---|
72 | * @param arg Local argument.
|
---|
73 | *
|
---|
74 | */
|
---|
75 | static void obio_connection(ipc_call_t *icall, void *arg)
|
---|
76 | {
|
---|
77 | ipc_call_t call;
|
---|
78 | obio_t *obio;
|
---|
79 |
|
---|
80 | /*
|
---|
81 | * Answer the first IPC_M_CONNECT_ME_TO call.
|
---|
82 | */
|
---|
83 | async_accept_0(icall);
|
---|
84 |
|
---|
85 | obio = (obio_t *) ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *) arg));
|
---|
86 |
|
---|
87 | while (true) {
|
---|
88 | int inr;
|
---|
89 |
|
---|
90 | async_get_call(&call);
|
---|
91 |
|
---|
92 | switch (ipc_get_imethod(&call)) {
|
---|
93 | case IRC_ENABLE_INTERRUPT:
|
---|
94 | inr = ipc_get_arg1(&call);
|
---|
95 | pio_set_64(&obio->regs[OBIO_IMR(inr & INO_MASK)],
|
---|
96 | 1UL << 31, 0);
|
---|
97 | async_answer_0(&call, EOK);
|
---|
98 | break;
|
---|
99 | case IRC_DISABLE_INTERRUPT:
|
---|
100 | /* XXX TODO */
|
---|
101 | async_answer_0(&call, EOK);
|
---|
102 | break;
|
---|
103 | case IRC_CLEAR_INTERRUPT:
|
---|
104 | inr = ipc_get_arg1(&call);
|
---|
105 | pio_write_64(&obio->regs[OBIO_CIR(inr & INO_MASK)], 0);
|
---|
106 | async_answer_0(&call, EOK);
|
---|
107 | break;
|
---|
108 | default:
|
---|
109 | async_answer_0(&call, EINVAL);
|
---|
110 | break;
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | /** Add OBIO device. */
|
---|
116 | errno_t obio_add(obio_t *obio, obio_res_t *res)
|
---|
117 | {
|
---|
118 | ddf_fun_t *fun_a = NULL;
|
---|
119 | errno_t rc;
|
---|
120 | bool bound = false;
|
---|
121 |
|
---|
122 | rc = pio_enable((void *)res->base, OBIO_SIZE, (void **) &obio->regs);
|
---|
123 | if (rc != EOK) {
|
---|
124 | ddf_msg(LVL_ERROR, "Error mapping OBIO registers");
|
---|
125 | rc = EIO;
|
---|
126 | goto error;
|
---|
127 | }
|
---|
128 |
|
---|
129 | ddf_msg(LVL_NOTE, "OBIO registers with base at 0x%" PRIxn, res->base);
|
---|
130 |
|
---|
131 | fun_a = ddf_fun_create(obio->dev, fun_exposed, "a");
|
---|
132 | if (fun_a == NULL) {
|
---|
133 | ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
|
---|
134 | rc = ENOMEM;
|
---|
135 | goto error;
|
---|
136 | }
|
---|
137 |
|
---|
138 | ddf_fun_set_conn_handler(fun_a, obio_connection);
|
---|
139 |
|
---|
140 | rc = ddf_fun_bind(fun_a);
|
---|
141 | if (rc != EOK) {
|
---|
142 | ddf_msg(LVL_ERROR, "Failed binding function 'a': %s", str_error(rc));
|
---|
143 | goto error;
|
---|
144 | }
|
---|
145 |
|
---|
146 | rc = ddf_fun_add_to_category(fun_a, "irc");
|
---|
147 | if (rc != EOK)
|
---|
148 | goto error;
|
---|
149 |
|
---|
150 | return EOK;
|
---|
151 | error:
|
---|
152 | if (bound)
|
---|
153 | ddf_fun_unbind(fun_a);
|
---|
154 | if (fun_a != NULL)
|
---|
155 | ddf_fun_destroy(fun_a);
|
---|
156 | return rc;
|
---|
157 | }
|
---|
158 |
|
---|
159 | /** Remove OBIO device */
|
---|
160 | errno_t obio_remove(obio_t *obio)
|
---|
161 | {
|
---|
162 | return ENOTSUP;
|
---|
163 | }
|
---|
164 |
|
---|
165 | /** OBIO device gone */
|
---|
166 | errno_t obio_gone(obio_t *obio)
|
---|
167 | {
|
---|
168 | return ENOTSUP;
|
---|
169 | }
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * @}
|
---|
173 | */
|
---|