00001 /* 00002 * Copyright (c) 2011 Martin Decky 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * - Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * - The name of the author may not be used to endorse or promote products 00015 * derived from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00019 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00020 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00038 #include <ipc/services.h> 00039 #include <ipc/irc.h> 00040 #include <ipc/ns.h> 00041 #include <sysinfo.h> 00042 #include <as.h> 00043 #include <ddi.h> 00044 #include <libarch/ddi.h> 00045 #include <align.h> 00046 #include <bool.h> 00047 #include <errno.h> 00048 #include <async.h> 00049 #include <align.h> 00050 #include <async.h> 00051 #include <stdio.h> 00052 #include <ipc/devmap.h> 00053 00054 #define NAME "apic" 00055 00056 static int apic_enable_irq(sysarg_t irq) 00057 { 00058 // FIXME: TODO 00059 return ENOTSUP; 00060 } 00061 00068 static void apic_connection(ipc_callid_t iid, ipc_call_t *icall) 00069 { 00070 ipc_callid_t callid; 00071 ipc_call_t call; 00072 00073 /* 00074 * Answer the first IPC_M_CONNECT_ME_TO call. 00075 */ 00076 async_answer_0(iid, EOK); 00077 00078 while (true) { 00079 callid = async_get_call(&call); 00080 00081 switch (IPC_GET_IMETHOD(call)) { 00082 case IRC_ENABLE_INTERRUPT: 00083 async_answer_0(callid, apic_enable_irq(IPC_GET_ARG1(call))); 00084 break; 00085 case IRC_CLEAR_INTERRUPT: 00086 /* Noop */ 00087 async_answer_0(callid, EOK); 00088 break; 00089 case IPC_M_PHONE_HUNGUP: 00090 /* The other side has hung up. */ 00091 async_answer_0(callid, EOK); 00092 return; 00093 default: 00094 async_answer_0(callid, EINVAL); 00095 break; 00096 } 00097 } 00098 } 00099 00103 static bool apic_init(void) 00104 { 00105 sysarg_t apic; 00106 00107 if ((sysinfo_get_value("apic", &apic) != EOK) || (!apic)) { 00108 printf(NAME ": No APIC found\n"); 00109 return false; 00110 } 00111 00112 async_set_client_connection(apic_connection); 00113 service_register(SERVICE_IRC); 00114 00115 return true; 00116 } 00117 00118 int main(int argc, char **argv) 00119 { 00120 printf(NAME ": HelenOS APIC driver\n"); 00121 00122 if (!apic_init()) 00123 return -1; 00124 00125 printf(NAME ": Accepting connections\n"); 00126 async_manager(); 00127 00128 /* Never reached */ 00129 return 0; 00130 } 00131