2
* Copyright (c) 2009 Jakub Jermar
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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.
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.
35
* @brief FHC bus controller driver.
39
#include <ipc/services.h>
52
#include <ipc/devmap.h>
56
#define FHC_UART_INR 0x39
58
#define FHC_UART_IMAP 0x0
59
#define FHC_UART_ICLR 0x4
61
static void *fhc_uart_phys;
62
static volatile uint32_t *fhc_uart_virt;
63
static size_t fhc_uart_size;
65
/** Handle one connection to fhc.
67
* @param iid Hash of the request that opened the connection.
68
* @param icall Call data of the request that opened the connection.
70
static void fhc_connection(ipc_callid_t iid, ipc_call_t *icall)
76
* Answer the first IPC_M_CONNECT_ME_TO call.
78
ipc_answer_0(iid, EOK);
83
callid = async_get_call(&call);
84
switch (IPC_GET_METHOD(call)) {
85
case BUS_CLEAR_INTERRUPT:
86
inr = IPC_GET_ARG1(call);
89
fhc_uart_virt[FHC_UART_ICLR] = 0;
90
ipc_answer_0(callid, EOK);
93
ipc_answer_0(callid, ENOTSUP);
98
ipc_answer_0(callid, EINVAL);
104
/** Initialize the FHC driver.
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.
109
static bool fhc_init(void)
113
fhc_uart_size = sysinfo_value("fhc.uart.size");
114
fhc_uart_phys = (void *) sysinfo_value("fhc.uart.physical");
116
if (!fhc_uart_size) {
117
printf(NAME ": no FHC UART registers found\n");
121
fhc_uart_virt = as_get_mappable_page(fhc_uart_size);
123
int flags = AS_AREA_READ | AS_AREA_WRITE;
124
int retval = physmem_map(fhc_uart_phys, (void *) fhc_uart_virt,
125
ALIGN_UP(fhc_uart_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
128
printf(NAME ": Error mapping FHC UART registers\n");
132
printf(NAME ": FHC UART registers at %p, %d bytes\n", fhc_uart_phys,
135
async_set_client_connection(fhc_connection);
136
ipc_connect_to_me(PHONE_NS, SERVICE_FHC, 0, 0, &phonead);
141
int main(int argc, char **argv)
143
printf(NAME ": HelenOS FHC bus controller driver\n");
148
printf(NAME ": Accepting connections\n");