source: mainline/uspace/srv/hw/irc/fhc/fhc.c@ ffa2c8ef

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

do not intermix low-level IPC methods with async framework methods

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[3e5a814]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 fhc
30 * @{
[ffa2c8ef]31 */
[3e5a814]32
33/**
[ffa2c8ef]34 * @file fhc.c
35 * @brief FHC bus controller driver.
[3e5a814]36 */
37
38#include <ipc/services.h>
[acc7ce4]39#include <ipc/irc.h>
[3e5a814]40#include <ipc/ns.h>
41#include <sysinfo.h>
42#include <as.h>
43#include <ddi.h>
44#include <align.h>
45#include <bool.h>
46#include <errno.h>
47#include <async.h>
48#include <align.h>
49#include <async.h>
50#include <stdio.h>
51#include <ipc/devmap.h>
52
53#define NAME "fhc"
54
55#define FHC_UART_INR 0x39
56
57#define FHC_UART_IMAP 0x0
58#define FHC_UART_ICLR 0x4
59
60static void *fhc_uart_phys;
61static volatile uint32_t *fhc_uart_virt;
62static size_t fhc_uart_size;
63
[dbaaf0a]64/** Handle one connection to fhc.
[3e5a814]65 *
66 * @param iid Hash of the request that opened the connection.
67 * @param icall Call data of the request that opened the connection.
68 */
69static void fhc_connection(ipc_callid_t iid, ipc_call_t *icall)
70{
71 ipc_callid_t callid;
72 ipc_call_t call;
73
74 /*
75 * Answer the first IPC_M_CONNECT_ME_TO call.
76 */
[ffa2c8ef]77 async_answer_0(iid, EOK);
[3e5a814]78
79 while (1) {
80 int inr;
81
82 callid = async_get_call(&call);
[228e490]83 switch (IPC_GET_IMETHOD(call)) {
[acc7ce4]84 case IRC_ENABLE_INTERRUPT:
85 /* Noop */
[ffa2c8ef]86 async_answer_0(callid, EOK);
[acc7ce4]87 break;
88 case IRC_CLEAR_INTERRUPT:
[3e5a814]89 inr = IPC_GET_ARG1(call);
90 switch (inr) {
91 case FHC_UART_INR:
92 fhc_uart_virt[FHC_UART_ICLR] = 0;
[ffa2c8ef]93 async_answer_0(callid, EOK);
[3e5a814]94 break;
95 default:
[ffa2c8ef]96 async_answer_0(callid, ENOTSUP);
[3e5a814]97 break;
98 }
99 break;
100 default:
[ffa2c8ef]101 async_answer_0(callid, EINVAL);
[3e5a814]102 break;
103 }
104 }
105}
106
107/** Initialize the FHC driver.
108 *
109 * So far, the driver heavily depends on information provided by the kernel via
110 * sysinfo. In the future, there should be a standalone FHC driver.
111 */
112static bool fhc_init(void)
113{
[d9fae235]114 sysarg_t paddr;
[3e5a814]115
[d9fae235]116 if ((sysinfo_get_value("fhc.uart.physical", &paddr) != EOK)
117 || (sysinfo_get_value("fhc.uart.size", &fhc_uart_size) != EOK)) {
[3e5a814]118 printf(NAME ": no FHC UART registers found\n");
119 return false;
120 }
[d9fae235]121
122 fhc_uart_phys = (void *) paddr;
[3e5a814]123 fhc_uart_virt = as_get_mappable_page(fhc_uart_size);
124
125 int flags = AS_AREA_READ | AS_AREA_WRITE;
126 int retval = physmem_map(fhc_uart_phys, (void *) fhc_uart_virt,
127 ALIGN_UP(fhc_uart_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
128
129 if (retval < 0) {
130 printf(NAME ": Error mapping FHC UART registers\n");
131 return false;
132 }
133
[7e752b2]134 printf(NAME ": FHC UART registers at %p, %zu bytes\n", fhc_uart_phys,
[3e5a814]135 fhc_uart_size);
[d9fae235]136
[3e5a814]137 async_set_client_connection(fhc_connection);
[007e6efa]138 service_register(SERVICE_FHC);
[3e5a814]139
140 return true;
141}
142
143int main(int argc, char **argv)
144{
[12081e6]145 printf(NAME ": HelenOS FHC bus controller driver\n");
[3e5a814]146
147 if (!fhc_init())
148 return -1;
149
150 printf(NAME ": Accepting connections\n");
151 async_manager();
152
153 /* Never reached */
154 return 0;
155}
156
157/**
158 * @}
159 */
Note: See TracBrowser for help on using the repository browser.