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 <ipc/services.h>
|
---|
45 | #include <ipc/irc.h>
|
---|
46 | #include <ns.h>
|
---|
47 | #include <sysinfo.h>
|
---|
48 | #include <as.h>
|
---|
49 | #include <ddi.h>
|
---|
50 | #include <align.h>
|
---|
51 | #include <bool.h>
|
---|
52 | #include <errno.h>
|
---|
53 | #include <async.h>
|
---|
54 | #include <align.h>
|
---|
55 | #include <async.h>
|
---|
56 | #include <stdio.h>
|
---|
57 | #include <ipc/loc.h>
|
---|
58 |
|
---|
59 | #define NAME "obio"
|
---|
60 |
|
---|
61 | #define OBIO_SIZE 0x1898
|
---|
62 |
|
---|
63 | #define OBIO_IMR_BASE 0x200
|
---|
64 | #define OBIO_IMR(ino) (OBIO_IMR_BASE + ((ino) & INO_MASK))
|
---|
65 |
|
---|
66 | #define OBIO_CIR_BASE 0x300
|
---|
67 | #define OBIO_CIR(ino) (OBIO_CIR_BASE + ((ino) & INO_MASK))
|
---|
68 |
|
---|
69 | #define INO_MASK 0x1f
|
---|
70 |
|
---|
71 | static void *base_phys;
|
---|
72 | static volatile uint64_t *base_virt;
|
---|
73 |
|
---|
74 | /** Handle one connection to obio.
|
---|
75 | *
|
---|
76 | * @param iid Hash of the request that opened the connection.
|
---|
77 | * @param icall Call data of the request that opened the connection.
|
---|
78 | * @param arg Local argument.
|
---|
79 | */
|
---|
80 | static void obio_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
81 | {
|
---|
82 | ipc_callid_t callid;
|
---|
83 | ipc_call_t call;
|
---|
84 |
|
---|
85 | /*
|
---|
86 | * Answer the first IPC_M_CONNECT_ME_TO call.
|
---|
87 | */
|
---|
88 | async_answer_0(iid, EOK);
|
---|
89 |
|
---|
90 | while (1) {
|
---|
91 | int inr;
|
---|
92 |
|
---|
93 | callid = async_get_call(&call);
|
---|
94 | switch (IPC_GET_IMETHOD(call)) {
|
---|
95 | case IRC_ENABLE_INTERRUPT:
|
---|
96 | /* Noop */
|
---|
97 | async_answer_0(callid, EOK);
|
---|
98 | break;
|
---|
99 | case IRC_CLEAR_INTERRUPT:
|
---|
100 | inr = IPC_GET_ARG1(call);
|
---|
101 | base_virt[OBIO_CIR(inr & INO_MASK)] = 0;
|
---|
102 | async_answer_0(callid, EOK);
|
---|
103 | break;
|
---|
104 | default:
|
---|
105 | async_answer_0(callid, EINVAL);
|
---|
106 | break;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | /** Initialize the OBIO driver.
|
---|
112 | *
|
---|
113 | * So far, the driver heavily depends on information provided by the kernel via
|
---|
114 | * sysinfo. In the future, there should be a standalone OBIO driver.
|
---|
115 | */
|
---|
116 | static bool obio_init(void)
|
---|
117 | {
|
---|
118 | sysarg_t paddr;
|
---|
119 |
|
---|
120 | if (sysinfo_get_value("obio.base.physical", &paddr) != EOK) {
|
---|
121 | printf("%s: No OBIO registers found\n", NAME);
|
---|
122 | return false;
|
---|
123 | }
|
---|
124 |
|
---|
125 | base_phys = (void *) paddr;
|
---|
126 | base_virt = as_get_mappable_page(OBIO_SIZE);
|
---|
127 |
|
---|
128 | int flags = AS_AREA_READ | AS_AREA_WRITE;
|
---|
129 | int retval = physmem_map(base_phys, (void *) base_virt,
|
---|
130 | ALIGN_UP(OBIO_SIZE, PAGE_SIZE) >> PAGE_WIDTH, flags);
|
---|
131 |
|
---|
132 | if (retval < 0) {
|
---|
133 | printf("%s: Error mapping OBIO registers\n", NAME);
|
---|
134 | return false;
|
---|
135 | }
|
---|
136 |
|
---|
137 | printf("%s: OBIO registers with base at %p\n", NAME, base_phys);
|
---|
138 |
|
---|
139 | async_set_client_connection(obio_connection);
|
---|
140 | service_register(SERVICE_IRC);
|
---|
141 |
|
---|
142 | return true;
|
---|
143 | }
|
---|
144 |
|
---|
145 | int main(int argc, char **argv)
|
---|
146 | {
|
---|
147 | printf("%s: HelenOS OBIO driver\n", NAME);
|
---|
148 |
|
---|
149 | if (!obio_init())
|
---|
150 | return -1;
|
---|
151 |
|
---|
152 | printf("%s: Accepting connections\n", NAME);
|
---|
153 | task_retval(0);
|
---|
154 | async_manager();
|
---|
155 |
|
---|
156 | /* Never reached */
|
---|
157 | return 0;
|
---|
158 | }
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * @}
|
---|
162 | */
|
---|