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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 124c061 was 124c061, checked in by Jakub Jermar <jakub@…>, 14 years ago

ipc_connect_to_me() now takes one extra argument to store the client task hash.

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