[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>
|
---|
[3e5a814] | 40 | #include <ipc/ns.h>
|
---|
| 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 |
|
---|
[c5b6431c] | 56 | static bool apic_found = false;
|
---|
| 57 |
|
---|
[acc7ce4] | 58 | static int apic_enable_irq(sysarg_t irq)
|
---|
| 59 | {
|
---|
| 60 | // FIXME: TODO
|
---|
| 61 | return ENOTSUP;
|
---|
| 62 | }
|
---|
[3e5a814] | 63 |
|
---|
[acc7ce4] | 64 | /** Handle one connection to APIC.
|
---|
| 65 | *
|
---|
| 66 | * @param iid Hash of the request that opened the connection.
|
---|
| 67 | * @param icall Call data of the request that opened the connection.
|
---|
[3e5a814] | 68 | *
|
---|
| 69 | */
|
---|
[acc7ce4] | 70 | static void apic_connection(ipc_callid_t iid, ipc_call_t *icall)
|
---|
[3e5a814] | 71 | {
|
---|
| 72 | ipc_callid_t callid;
|
---|
| 73 | ipc_call_t call;
|
---|
[acc7ce4] | 74 |
|
---|
[3e5a814] | 75 | /*
|
---|
| 76 | * Answer the first IPC_M_CONNECT_ME_TO call.
|
---|
| 77 | */
|
---|
[ffa2c8ef] | 78 | async_answer_0(iid, EOK);
|
---|
[3e5a814] | 79 |
|
---|
[acc7ce4] | 80 | while (true) {
|
---|
[3e5a814] | 81 | callid = async_get_call(&call);
|
---|
[acc7ce4] | 82 |
|
---|
[c5b6431c] | 83 | sysarg_t method = IPC_GET_IMETHOD(call);
|
---|
| 84 | if (method == IPC_M_PHONE_HUNGUP) {
|
---|
| 85 | return;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | if (!apic_found) {
|
---|
| 89 | async_answer_0(callid, ENOTSUP);
|
---|
| 90 | break;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | switch (method) {
|
---|
[acc7ce4] | 94 | case IRC_ENABLE_INTERRUPT:
|
---|
[ffa2c8ef] | 95 | async_answer_0(callid, apic_enable_irq(IPC_GET_ARG1(call)));
|
---|
[acc7ce4] | 96 | break;
|
---|
| 97 | case IRC_CLEAR_INTERRUPT:
|
---|
| 98 | /* Noop */
|
---|
[ffa2c8ef] | 99 | async_answer_0(callid, EOK);
|
---|
[3e5a814] | 100 | break;
|
---|
| 101 | default:
|
---|
[ffa2c8ef] | 102 | async_answer_0(callid, EINVAL);
|
---|
[3e5a814] | 103 | break;
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[acc7ce4] | 108 | /** Initialize the APIC driver.
|
---|
[3e5a814] | 109 | *
|
---|
| 110 | */
|
---|
[c5b6431c] | 111 | static void apic_init(void)
|
---|
[3e5a814] | 112 | {
|
---|
[acc7ce4] | 113 | sysarg_t apic;
|
---|
[3e5a814] | 114 |
|
---|
[c5b6431c] | 115 | apic_found = sysinfo_get_value("apic", &apic) && apic;
|
---|
| 116 | if (!apic_found) {
|
---|
| 117 | printf(NAME ": Warning: no APIC found\n");
|
---|
[3e5a814] | 118 | }
|
---|
| 119 |
|
---|
[acc7ce4] | 120 | async_set_client_connection(apic_connection);
|
---|
[007e6efa] | 121 | service_register(SERVICE_APIC);
|
---|
[3e5a814] | 122 | }
|
---|
| 123 |
|
---|
| 124 | int main(int argc, char **argv)
|
---|
| 125 | {
|
---|
[acc7ce4] | 126 | printf(NAME ": HelenOS APIC driver\n");
|
---|
[3e5a814] | 127 |
|
---|
[c5b6431c] | 128 | apic_init();
|
---|
| 129 |
|
---|
[3e5a814] | 130 | printf(NAME ": Accepting connections\n");
|
---|
| 131 | async_manager();
|
---|
[acc7ce4] | 132 |
|
---|
[3e5a814] | 133 | /* Never reached */
|
---|
| 134 | return 0;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | /**
|
---|
| 138 | * @}
|
---|
[acc7ce4] | 139 | */
|
---|