Rev 3976 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3976 | Rev 3977 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Jakub Jermar |
2 | * Copyright (c) 2009 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup fhc |
29 | /** @addtogroup fhc |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** |
33 | /** |
34 | * @file fhc.c |
34 | * @file fhc.c |
35 | * @brief FHC bus controller driver. |
35 | * @brief FHC bus controller driver. |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <ipc/ipc.h> |
38 | #include <ipc/ipc.h> |
39 | #include <ipc/services.h> |
39 | #include <ipc/services.h> |
40 | #include <ipc/bus.h> |
40 | #include <ipc/bus.h> |
41 | #include <ipc/ns.h> |
41 | #include <ipc/ns.h> |
42 | #include <sysinfo.h> |
42 | #include <sysinfo.h> |
43 | #include <as.h> |
43 | #include <as.h> |
44 | #include <ddi.h> |
44 | #include <ddi.h> |
45 | #include <align.h> |
45 | #include <align.h> |
46 | #include <bool.h> |
46 | #include <bool.h> |
47 | #include <errno.h> |
47 | #include <errno.h> |
48 | #include <async.h> |
48 | #include <async.h> |
49 | #include <align.h> |
49 | #include <align.h> |
50 | #include <async.h> |
50 | #include <async.h> |
51 | #include <stdio.h> |
51 | #include <stdio.h> |
52 | #include <ipc/devmap.h> |
52 | #include <ipc/devmap.h> |
53 | 53 | ||
54 | #define NAME "fhc" |
54 | #define NAME "fhc" |
55 | 55 | ||
56 | #define FHC_UART_INR 0x39 |
56 | #define FHC_UART_INR 0x39 |
57 | 57 | ||
58 | #define FHC_UART_IMAP 0x0 |
58 | #define FHC_UART_IMAP 0x0 |
59 | #define FHC_UART_ICLR 0x4 |
59 | #define FHC_UART_ICLR 0x4 |
60 | 60 | ||
61 | static void *fhc_uart_phys; |
61 | static void *fhc_uart_phys; |
62 | static volatile uint32_t *fhc_uart_virt; |
62 | static volatile uint32_t *fhc_uart_virt; |
63 | static size_t fhc_uart_size; |
63 | static size_t fhc_uart_size; |
64 | 64 | ||
65 | /** Handle one connection to fhc. |
65 | /** Handle one connection to fhc. |
66 | * |
66 | * |
67 | * @param iid Hash of the request that opened the connection. |
67 | * @param iid Hash of the request that opened the connection. |
68 | * @param icall Call data of the request that opened the connection. |
68 | * @param icall Call data of the request that opened the connection. |
69 | */ |
69 | */ |
70 | static void fhc_connection(ipc_callid_t iid, ipc_call_t *icall) |
70 | static void fhc_connection(ipc_callid_t iid, ipc_call_t *icall) |
71 | { |
71 | { |
72 | ipc_callid_t callid; |
72 | ipc_callid_t callid; |
73 | ipc_call_t call; |
73 | ipc_call_t call; |
74 | 74 | ||
75 | /* |
75 | /* |
76 | * Answer the first IPC_M_CONNECT_ME_TO call. |
76 | * Answer the first IPC_M_CONNECT_ME_TO call. |
77 | */ |
77 | */ |
78 | ipc_answer_0(iid, EOK); |
78 | ipc_answer_0(iid, EOK); |
79 | 79 | ||
80 | while (1) { |
80 | while (1) { |
81 | int inr; |
81 | int inr; |
82 | 82 | ||
83 | callid = async_get_call(&call); |
83 | callid = async_get_call(&call); |
84 | switch (IPC_GET_METHOD(call)) { |
84 | switch (IPC_GET_METHOD(call)) { |
85 | case BUS_CLEAR_INTERRUPT: |
85 | case BUS_CLEAR_INTERRUPT: |
86 | inr = IPC_GET_ARG1(call); |
86 | inr = IPC_GET_ARG1(call); |
87 | switch (inr) { |
87 | switch (inr) { |
88 | case FHC_UART_INR: |
88 | case FHC_UART_INR: |
89 | fhc_uart_virt[FHC_UART_ICLR] = 0; |
89 | fhc_uart_virt[FHC_UART_ICLR] = 0; |
90 | ipc_answer_0(callid, EOK); |
90 | ipc_answer_0(callid, EOK); |
91 | break; |
91 | break; |
92 | default: |
92 | default: |
93 | ipc_answer_0(callid, ENOTSUP); |
93 | ipc_answer_0(callid, ENOTSUP); |
94 | break; |
94 | break; |
95 | } |
95 | } |
96 | break; |
96 | break; |
97 | default: |
97 | default: |
98 | ipc_answer_0(callid, EINVAL); |
98 | ipc_answer_0(callid, EINVAL); |
99 | break; |
99 | break; |
100 | } |
100 | } |
101 | } |
101 | } |
102 | } |
102 | } |
103 | 103 | ||
104 | /** Initialize the FHC driver. |
104 | /** Initialize the FHC driver. |
105 | * |
105 | * |
106 | * So far, the driver heavily depends on information provided by the kernel via |
106 | * So far, the driver heavily depends on information provided by the kernel via |
107 | * sysinfo. In the future, there should be a standalone FHC driver. |
107 | * sysinfo. In the future, there should be a standalone FHC driver. |
108 | */ |
108 | */ |
109 | static bool fhc_init(void) |
109 | static bool fhc_init(void) |
110 | { |
110 | { |
111 | ipcarg_t phonead; |
111 | ipcarg_t phonead; |
112 | 112 | ||
113 | fhc_uart_size = sysinfo_value("fhc.uart.size"); |
113 | fhc_uart_size = sysinfo_value("fhc.uart.size"); |
114 | fhc_uart_phys = (void *) sysinfo_value("fhc.uart.physical"); |
114 | fhc_uart_phys = (void *) sysinfo_value("fhc.uart.physical"); |
115 | 115 | ||
116 | if (!fhc_uart_size) { |
116 | if (!fhc_uart_size) { |
117 | printf(NAME ": no FHC UART registers found\n"); |
117 | printf(NAME ": no FHC UART registers found\n"); |
118 | return false; |
118 | return false; |
119 | } |
119 | } |
120 | 120 | ||
121 | fhc_uart_virt = as_get_mappable_page(fhc_uart_size); |
121 | fhc_uart_virt = as_get_mappable_page(fhc_uart_size); |
122 | 122 | ||
123 | int flags = AS_AREA_READ | AS_AREA_WRITE; |
123 | int flags = AS_AREA_READ | AS_AREA_WRITE; |
124 | int retval = physmem_map(fhc_uart_phys, (void *) fhc_uart_virt, |
124 | int retval = physmem_map(fhc_uart_phys, (void *) fhc_uart_virt, |
125 | ALIGN_UP(fhc_uart_size, PAGE_SIZE) >> PAGE_WIDTH, flags); |
125 | ALIGN_UP(fhc_uart_size, PAGE_SIZE) >> PAGE_WIDTH, flags); |
126 | 126 | ||
127 | if (retval < 0) { |
127 | if (retval < 0) { |
128 | printf(NAME ": Error mapping FHC UART registers\n"); |
128 | printf(NAME ": Error mapping FHC UART registers\n"); |
129 | return false; |
129 | return false; |
130 | } |
130 | } |
131 | 131 | ||
132 | printf(NAME ": FHC UART registers at %p, %d bytes\n", fhc_uart_phys, |
132 | printf(NAME ": FHC UART registers at %p, %d bytes\n", fhc_uart_phys, |
133 | fhc_uart_size); |
133 | fhc_uart_size); |
134 | 134 | ||
135 | async_set_client_connection(fhc_connection); |
135 | async_set_client_connection(fhc_connection); |
136 | ipc_connect_to_me(PHONE_NS, SERVICE_FHC, 0, 0, &phonead); |
136 | ipc_connect_to_me(PHONE_NS, SERVICE_FHC, 0, 0, &phonead); |
137 | 137 | ||
138 | return true; |
138 | return true; |
139 | } |
139 | } |
140 | 140 | ||
141 | int main(int argc, char **argv) |
141 | int main(int argc, char **argv) |
142 | { |
142 | { |
143 | printf(NAME ": HelenOS FHC bus driver\n"); |
143 | printf(NAME ": HelenOS FHC bus controller driver\n"); |
144 | 144 | ||
145 | if (!fhc_init()) |
145 | if (!fhc_init()) |
146 | return -1; |
146 | return -1; |
147 | 147 | ||
148 | printf(NAME ": Accepting connections\n"); |
148 | printf(NAME ": Accepting connections\n"); |
149 | async_manager(); |
149 | async_manager(); |
150 | 150 | ||
151 | /* Never reached */ |
151 | /* Never reached */ |
152 | return 0; |
152 | return 0; |
153 | } |
153 | } |
154 | 154 | ||
155 | /** |
155 | /** |
156 | * @} |
156 | * @} |
157 | */ |
157 | */ |
158 | 158 |