Changeset 357b5f5 in mainline for uspace/srv/hw/irc/apic/apic.c


Ignore:
Timestamp:
2011-01-23T20:09:13Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fdb9982c
Parents:
cead2aa (diff), 7e36c8d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/hw/irc/apic/apic.c

    rcead2aa r357b5f5  
    11/*
    2  * Copyright (c) 2006 Ondrej Palkovsky
     2 * Copyright (c) 2011 Martin Decky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 #include <inttypes.h>
     29/** @addtogroup apic
     30 * @{
     31 */
     32
     33/**
     34 * @file apic.c
     35 * @brief APIC 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 <libarch/ddi.h>
     46#include <align.h>
     47#include <bool.h>
     48#include <errno.h>
     49#include <async.h>
     50#include <align.h>
     51#include <async.h>
    3052#include <stdio.h>
    31 #include <unistd.h>
    32 #include <async.h>
    33 #include <errno.h>
    34 #include "../tester.h"
     53#include <ipc/devmap.h>
    3554
    36 #define MAX_CONNECTIONS  50
     55#define NAME  "apic"
    3756
    38 static int connections[MAX_CONNECTIONS];
     57static int apic_enable_irq(sysarg_t irq)
     58{
     59        // FIXME: TODO
     60        return ENOTSUP;
     61}
    3962
    40 static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
     63/** Handle one connection to APIC.
     64 *
     65 * @param iid   Hash of the request that opened the connection.
     66 * @param icall Call data of the request that opened the connection.
     67 *
     68 */
     69static void apic_connection(ipc_callid_t iid, ipc_call_t *icall)
    4170{
    42         unsigned int i;
     71        ipc_callid_t callid;
     72        ipc_call_t call;
    4373       
    44         TPRINTF("Connected phone %" PRIun " accepting\n", icall->in_phone_hash);
     74        /*
     75         * Answer the first IPC_M_CONNECT_ME_TO call.
     76         */
    4577        ipc_answer_0(iid, EOK);
    46         for (i = 0; i < MAX_CONNECTIONS; i++) {
    47                 if (!connections[i]) {
    48                         connections[i] = icall->in_phone_hash;
    49                         break;
    50                 }
    51         }
    5278       
    5379        while (true) {
    54                 ipc_call_t call;
    55                 ipc_callid_t callid = async_get_call(&call);
    56                 int retval;
     80                callid = async_get_call(&call);
    5781               
    58                 switch (IPC_GET_METHOD(call)) {
    59                 case IPC_M_PHONE_HUNGUP:
    60                         TPRINTF("Phone %" PRIun " hung up\n", icall->in_phone_hash);
    61                         retval = 0;
     82                switch (IPC_GET_IMETHOD(call)) {
     83                case IRC_ENABLE_INTERRUPT:
     84                        ipc_answer_0(callid, apic_enable_irq(IPC_GET_ARG1(call)));
    6285                        break;
    63                 case IPC_TEST_METHOD:
    64                         TPRINTF("Received well known message from %" PRIun ": %" PRIun "\n",
    65                             icall->in_phone_hash, callid);
     86                case IRC_CLEAR_INTERRUPT:
     87                        /* Noop */
    6688                        ipc_answer_0(callid, EOK);
    6789                        break;
    6890                default:
    69                         TPRINTF("Received unknown message from %" PRIun ": %" PRIun "\n",
    70                             icall->in_phone_hash, callid);
    71                         ipc_answer_0(callid, ENOENT);
     91                        ipc_answer_0(callid, EINVAL);
    7292                        break;
    7393                }
     
    7595}
    7696
    77 const char *test_register(void)
     97/** Initialize the APIC driver.
     98 *
     99 */
     100static bool apic_init(void)
    78101{
    79         async_set_client_connection(client_connection);
     102        sysarg_t apic;
    80103       
    81         ipcarg_t phonead;
    82         int res = ipc_connect_to_me(PHONE_NS, IPC_TEST_SERVICE, 0, 0, &phonead);
    83         if (res != 0)
    84                 return "Failed registering IPC service";
     104        if ((sysinfo_get_value("apic", &apic) != EOK) || (!apic)) {
     105                printf(NAME ": No APIC found\n");
     106                return false;
     107        }
    85108       
    86         TPRINTF("Registered as service %u, accepting connections\n", IPC_TEST_SERVICE);
     109        async_set_client_connection(apic_connection);
     110        sysarg_t phonead;
     111        ipc_connect_to_me(PHONE_NS, SERVICE_APIC, 0, 0, &phonead);
     112       
     113        return true;
     114}
     115
     116int main(int argc, char **argv)
     117{
     118        printf(NAME ": HelenOS APIC driver\n");
     119       
     120        if (!apic_init())
     121                return -1;
     122       
     123        printf(NAME ": Accepting connections\n");
    87124        async_manager();
    88125       
    89         return NULL;
     126        /* Never reached */
     127        return 0;
    90128}
     129
     130/**
     131 * @}
     132 */
Note: See TracChangeset for help on using the changeset viewer.