source: mainline/uspace/srv/hw/irc/apic/apic.c@ 9934f7d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9934f7d was 9934f7d, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Add extra argument to async connection handlers that can be used for passing
information from async_connect_to_me() to the handler.

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[3e5a814]1/*
[acc7ce4]2 * Copyright (c) 2011 Martin Decky
[3e5a814]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
[acc7ce4]29/** @addtogroup apic
[3e5a814]30 * @{
[acc7ce4]31 */
[3e5a814]32
33/**
[acc7ce4]34 * @file apic.c
35 * @brief APIC driver.
[3e5a814]36 */
37
38#include <ipc/services.h>
[acc7ce4]39#include <ipc/irc.h>
[79ae36dd]40#include <ns.h>
[3e5a814]41#include <sysinfo.h>
42#include <as.h>
43#include <ddi.h>
[acc7ce4]44#include <libarch/ddi.h>
[3e5a814]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
[acc7ce4]54#define NAME "apic"
[3e5a814]55
[acc7ce4]56static int apic_enable_irq(sysarg_t irq)
57{
58 // FIXME: TODO
59 return ENOTSUP;
60}
[3e5a814]61
[acc7ce4]62/** Handle one connection to APIC.
63 *
64 * @param iid Hash of the request that opened the connection.
65 * @param icall Call data of the request that opened the connection.
[9934f7d]66 * @param arg Local argument.
[3e5a814]67 */
[9934f7d]68static void apic_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
[3e5a814]69{
70 ipc_callid_t callid;
71 ipc_call_t call;
[acc7ce4]72
[3e5a814]73 /*
74 * Answer the first IPC_M_CONNECT_ME_TO call.
75 */
[ffa2c8ef]76 async_answer_0(iid, EOK);
[3e5a814]77
[acc7ce4]78 while (true) {
[3e5a814]79 callid = async_get_call(&call);
[acc7ce4]80
[79ae36dd]81 if (!IPC_GET_IMETHOD(call)) {
82 /* The other side has hung up. */
83 async_answer_0(callid, EOK);
84 return;
85 }
86
[228e490]87 switch (IPC_GET_IMETHOD(call)) {
[acc7ce4]88 case IRC_ENABLE_INTERRUPT:
[ffa2c8ef]89 async_answer_0(callid, apic_enable_irq(IPC_GET_ARG1(call)));
[acc7ce4]90 break;
91 case IRC_CLEAR_INTERRUPT:
92 /* Noop */
[ffa2c8ef]93 async_answer_0(callid, EOK);
[3e5a814]94 break;
95 default:
[ffa2c8ef]96 async_answer_0(callid, EINVAL);
[3e5a814]97 break;
98 }
99 }
100}
101
[acc7ce4]102/** Initialize the APIC driver.
[3e5a814]103 *
104 */
[acc7ce4]105static bool apic_init(void)
[3e5a814]106{
[acc7ce4]107 sysarg_t apic;
[3e5a814]108
[acc7ce4]109 if ((sysinfo_get_value("apic", &apic) != EOK) || (!apic)) {
[79ae36dd]110 printf("%s: No APIC found\n", NAME);
[3e5a814]111 return false;
112 }
113
[acc7ce4]114 async_set_client_connection(apic_connection);
[57d129e]115 service_register(SERVICE_IRC);
[3e5a814]116
117 return true;
118}
119
120int main(int argc, char **argv)
121{
[79ae36dd]122 printf("%s: HelenOS APIC driver\n", NAME);
[3e5a814]123
[acc7ce4]124 if (!apic_init())
[3e5a814]125 return -1;
126
[79ae36dd]127 printf("%s: Accepting connections\n", NAME);
128 task_retval(0);
[3e5a814]129 async_manager();
[acc7ce4]130
[3e5a814]131 /* Never reached */
132 return 0;
133}
134
135/**
136 * @}
[acc7ce4]137 */
Note: See TracBrowser for help on using the repository browser.