[e2b9a993] | 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 devman Device manager.
|
---|
| 31 | * @brief HelenOS device manager.
|
---|
| 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 <dirent.h>
|
---|
| 49 | #include <fcntl.h>
|
---|
| 50 | #include <sys/stat.h>
|
---|
| 51 | #include <ctype.h>
|
---|
| 52 | #include <ipc/devman.h>
|
---|
| 53 |
|
---|
| 54 | #include "devman.h"
|
---|
| 55 |
|
---|
| 56 | #define DRIVER_DEFAULT_STORE "/srv/drivers"
|
---|
| 57 |
|
---|
[0c3666d] | 58 | static driver_list_t drivers_list;
|
---|
[e2b9a993] | 59 | static dev_tree_t device_tree;
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | /** Function for handling connections to device manager.
|
---|
| 63 | *
|
---|
| 64 | */
|
---|
[924c75e1] | 65 | static void devman_connection_driver(ipc_callid_t iid, ipc_call_t *icall)
|
---|
[e2b9a993] | 66 | {
|
---|
| 67 | ipc_callid_t callid;
|
---|
| 68 | ipc_call_t call;
|
---|
| 69 |
|
---|
| 70 | /* Accept the connection */
|
---|
| 71 | ipc_answer_0(iid, EOK);
|
---|
| 72 |
|
---|
| 73 | while (1) {
|
---|
| 74 | callid = async_get_call(&call);
|
---|
| 75 |
|
---|
| 76 | switch (IPC_GET_METHOD(call)) {
|
---|
| 77 | case DEVMAN_DRIVER_REGISTER:
|
---|
| 78 | // TODO register running driver instance - remember driver's phone and lookup devices to which it has been assigned
|
---|
| 79 | break;
|
---|
| 80 | case DEVMAN_ADD_CHILD_DEVICE:
|
---|
| 81 | // TODO add new device node to the device tree
|
---|
| 82 | break;
|
---|
| 83 | default:
|
---|
| 84 | ipc_answer_0(callid, EINVAL);
|
---|
| 85 | break;
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[924c75e1] | 90 | /** Function for handling connections to device manager.
|
---|
| 91 | *
|
---|
| 92 | */
|
---|
| 93 | static void devman_connection(ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 94 | {
|
---|
| 95 | // Select interface
|
---|
| 96 | switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) {
|
---|
| 97 | case DEVMAN_DRIVER:
|
---|
| 98 | devman_connection_driver(iid, icall);
|
---|
| 99 | break;
|
---|
| 100 | /*case DEVMAN_CLIENT:
|
---|
| 101 | devmap_connection_client(iid, icall);
|
---|
| 102 | break;
|
---|
| 103 | case DEVMAN_CONNECT_TO_DEVICE:
|
---|
| 104 | // Connect client to selected device
|
---|
| 105 | devmap_forward(iid, icall);
|
---|
| 106 | break;*/
|
---|
| 107 | default:
|
---|
| 108 | /* No such interface */
|
---|
| 109 | ipc_answer_0(iid, ENOENT);
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[e2b9a993] | 113 | /** Initialize device manager internal structures.
|
---|
| 114 | */
|
---|
| 115 | static bool devman_init()
|
---|
| 116 | {
|
---|
[0c3666d] | 117 | printf(NAME ": devman_init - looking for available drivers. \n");
|
---|
[08d9c4e6] | 118 |
|
---|
[e2b9a993] | 119 | // initialize list of available drivers
|
---|
[0c3666d] | 120 | init_driver_list(&drivers_list);
|
---|
[e2b9a993] | 121 | if (0 == lookup_available_drivers(&drivers_list, DRIVER_DEFAULT_STORE)) {
|
---|
| 122 | printf(NAME " no drivers found.");
|
---|
| 123 | return false;
|
---|
| 124 | }
|
---|
[08d9c4e6] | 125 | printf(NAME ": devman_init - list of drivers has been initialized. \n");
|
---|
[e2b9a993] | 126 |
|
---|
| 127 | // create root device node
|
---|
| 128 | if (!init_device_tree(&device_tree, &drivers_list)) {
|
---|
| 129 | printf(NAME " failed to initialize device tree.");
|
---|
| 130 | return false;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | return true;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | int main(int argc, char *argv[])
|
---|
| 137 | {
|
---|
| 138 | printf(NAME ": HelenOS Device Manager\n");
|
---|
| 139 |
|
---|
| 140 | if (!devman_init()) {
|
---|
| 141 | printf(NAME ": Error while initializing service\n");
|
---|
| 142 | return -1;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | // Set a handler of incomming connections
|
---|
| 146 | async_set_client_connection(devman_connection);
|
---|
| 147 |
|
---|
| 148 | // Register device manager at naming service
|
---|
| 149 | ipcarg_t phonead;
|
---|
| 150 | if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, &phonead) != 0)
|
---|
| 151 | return -1;
|
---|
| 152 |
|
---|
| 153 | printf(NAME ": Accepting connections\n");
|
---|
| 154 | async_manager();
|
---|
| 155 |
|
---|
| 156 | // Never reached
|
---|
| 157 | return 0;
|
---|
| 158 | }
|
---|