| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Lenka Trochtova
|
|---|
| 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 |
|
|---|
| 29 | /**
|
|---|
| 30 | * @defgroup libdrv generic device driver support.
|
|---|
| 31 | * @brief HelenOS generic device driver support.
|
|---|
| 32 | * @{
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| 35 | /** @file
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <assert.h>
|
|---|
| 39 | #include <ipc/services.h>
|
|---|
| 40 | #include <ipc/ns.h>
|
|---|
| 41 | #include <async.h>
|
|---|
| 42 | #include <stdio.h>
|
|---|
| 43 | #include <errno.h>
|
|---|
| 44 | #include <bool.h>
|
|---|
| 45 | #include <fibril_synch.h>
|
|---|
| 46 | #include <stdlib.h>
|
|---|
| 47 | #include <string.h>
|
|---|
| 48 | #include <ctype.h>
|
|---|
| 49 |
|
|---|
| 50 | #include <devman.h>
|
|---|
| 51 | #include <ipc/devman.h>
|
|---|
| 52 |
|
|---|
| 53 | #include "driver.h"
|
|---|
| 54 |
|
|---|
| 55 | static driver_t *driver;
|
|---|
| 56 |
|
|---|
| 57 | static void driver_connection_devman(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 58 | {
|
|---|
| 59 | /* Accept connection */
|
|---|
| 60 | ipc_answer_0(iid, EOK);
|
|---|
| 61 |
|
|---|
| 62 | bool cont = true;
|
|---|
| 63 | while (cont) {
|
|---|
| 64 | ipc_call_t call;
|
|---|
| 65 | ipc_callid_t callid = async_get_call(&call);
|
|---|
| 66 |
|
|---|
| 67 | switch (IPC_GET_METHOD(call)) {
|
|---|
| 68 | case IPC_M_PHONE_HUNGUP:
|
|---|
| 69 | cont = false;
|
|---|
| 70 | continue;
|
|---|
| 71 | case DRIVER_ADD_DEVICE:
|
|---|
| 72 | // TODO
|
|---|
| 73 | break;
|
|---|
| 74 | default:
|
|---|
| 75 | if (!(callid & IPC_CALLID_NOTIFICATION))
|
|---|
| 76 | ipc_answer_0(callid, ENOENT);
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | static void driver_connection_driver(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 83 | {
|
|---|
| 84 | // TODO later
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | static void driver_connection_client(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 88 | {
|
|---|
| 89 | // TODO later
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 | /** Function for handling connections to device driver.
|
|---|
| 94 | *
|
|---|
| 95 | */
|
|---|
| 96 | static void driver_connection(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 97 | {
|
|---|
| 98 | ipc_callid_t callid;
|
|---|
| 99 | /* Select interface */
|
|---|
| 100 | switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) {
|
|---|
| 101 | case DRIVER_DEVMAN:
|
|---|
| 102 | // handle PnP events from device manager
|
|---|
| 103 | driver_connection_devman(iid, icall);
|
|---|
| 104 | break;
|
|---|
| 105 | case DRIVER_DRIVER:
|
|---|
| 106 | // handle request from drivers of child devices
|
|---|
| 107 | driver_connection_driver(iid, icall);
|
|---|
| 108 | break;
|
|---|
| 109 | case DRIVER_CLIENT:
|
|---|
| 110 | // handle requests from client applications
|
|---|
| 111 | driver_connection_client(iid, icall);
|
|---|
| 112 | break;
|
|---|
| 113 |
|
|---|
| 114 | default:
|
|---|
| 115 | /* No such interface */
|
|---|
| 116 | ipc_answer_0(iid, ENOENT);
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | int driver_main(driver_t *drv)
|
|---|
| 121 | {
|
|---|
| 122 | // remember the driver structure - driver_ops will be called by generic handler for incoming connections
|
|---|
| 123 | driver = drv;
|
|---|
| 124 |
|
|---|
| 125 | // register driver by device manager with generic handler for incoming connections
|
|---|
| 126 | printf("%s: sending registration request to devman.\n", driver->name);
|
|---|
| 127 | devman_driver_register(driver->name, driver_connection);
|
|---|
| 128 |
|
|---|
| 129 | async_manager();
|
|---|
| 130 |
|
|---|
| 131 | // Never reached
|
|---|
| 132 | return 0;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | /**
|
|---|
| 136 | * @}
|
|---|
| 137 | */ |
|---|