[924c75e1] | 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 root device driver.
|
---|
| 31 | * @brief HelenOS root device driver.
|
---|
| 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 |
|
---|
[729fa2d6] | 50 | #include <devman.h>
|
---|
[924c75e1] | 51 | #include <ipc/devman.h>
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | ////////////////////////////////////////
|
---|
| 55 | // rudiments of generic driver support
|
---|
| 56 | // TODO - create library(ies) for this functionality
|
---|
| 57 | ////////////////////////////////////////
|
---|
| 58 |
|
---|
| 59 | typedef enum {
|
---|
| 60 | DRIVER_DEVMAN = 1,
|
---|
| 61 | DRIVER_CLIENT,
|
---|
| 62 | DRIVER_DRIVER
|
---|
| 63 | } driver_interface_t;
|
---|
| 64 |
|
---|
| 65 | typedef struct device {
|
---|
| 66 | int parent_handle;
|
---|
| 67 | ipcarg_t parent_phone;
|
---|
| 68 | // TODO add more items - parent bus type etc.
|
---|
| 69 | int handle;
|
---|
| 70 | } device_t;
|
---|
| 71 |
|
---|
| 72 | typedef struct driver_ops {
|
---|
| 73 | bool (*add_device)(device_t *dev);
|
---|
| 74 | // TODO add other generic driver operations
|
---|
| 75 | } driver_ops_t;
|
---|
| 76 |
|
---|
| 77 | typedef struct driver {
|
---|
| 78 | const char *name;
|
---|
| 79 | driver_ops_t *driver_ops;
|
---|
| 80 | } driver_t;
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | static driver_t *driver;
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | static void driver_connection_devman(ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 87 | {
|
---|
| 88 | /* Accept connection */
|
---|
| 89 | ipc_answer_0(iid, EOK);
|
---|
| 90 |
|
---|
| 91 | bool cont = true;
|
---|
| 92 | while (cont) {
|
---|
| 93 | ipc_call_t call;
|
---|
| 94 | ipc_callid_t callid = async_get_call(&call);
|
---|
| 95 |
|
---|
| 96 | switch (IPC_GET_METHOD(call)) {
|
---|
| 97 | case IPC_M_PHONE_HUNGUP:
|
---|
| 98 | cont = false;
|
---|
| 99 | continue;
|
---|
| 100 | case DRIVER_ADD_DEVICE:
|
---|
| 101 | // TODO
|
---|
| 102 | break;
|
---|
| 103 | default:
|
---|
| 104 | if (!(callid & IPC_CALLID_NOTIFICATION))
|
---|
| 105 | ipc_answer_0(callid, ENOENT);
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | static void driver_connection_driver(ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 112 | {
|
---|
| 113 | // TODO later
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | static void driver_connection_client(ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 117 | {
|
---|
| 118 | // TODO later
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 | /** Function for handling connections to device driver.
|
---|
| 125 | *
|
---|
| 126 | */
|
---|
| 127 | static void driver_connection(ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 128 | {
|
---|
| 129 | ipc_callid_t callid;
|
---|
| 130 | /* Select interface */
|
---|
| 131 | switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) {
|
---|
| 132 | case DRIVER_DEVMAN:
|
---|
| 133 | // handle PnP events from device manager
|
---|
| 134 | driver_connection_devman(iid, icall);
|
---|
| 135 | break;
|
---|
| 136 | case DRIVER_DRIVER:
|
---|
| 137 | // handle request from drivers of child devices
|
---|
| 138 | driver_connection_driver(iid, icall);
|
---|
| 139 | break;
|
---|
| 140 | case DRIVER_CLIENT:
|
---|
| 141 | // handle requests from client applications
|
---|
| 142 | driver_connection_client(iid, icall);
|
---|
| 143 | break;
|
---|
| 144 |
|
---|
| 145 | default:
|
---|
| 146 | /* No such interface */
|
---|
| 147 | ipc_answer_0(iid, ENOENT);
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 |
|
---|
| 153 | int driver_main(driver_t *drv)
|
---|
| 154 | {
|
---|
| 155 | // remember driver structure - driver_ops will be called by generic handler for incoming connections
|
---|
| 156 | driver = drv;
|
---|
| 157 |
|
---|
| 158 | // register driver by device manager with generic handler for incoming connections
|
---|
[729fa2d6] | 159 | printf("%s: sending registration request to devman.\n", driver->name);
|
---|
[924c75e1] | 160 | devman_driver_register(driver->name, driver_connection);
|
---|
| 161 |
|
---|
| 162 | async_manager();
|
---|
| 163 |
|
---|
| 164 | // Never reached
|
---|
| 165 | return 0;
|
---|
| 166 |
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | ////////////////////////////////////////
|
---|
| 170 | // ROOT driver
|
---|
| 171 | ////////////////////////////////////////
|
---|
| 172 |
|
---|
| 173 | #define NAME "root"
|
---|
| 174 |
|
---|
[729fa2d6] | 175 |
|
---|
[924c75e1] | 176 |
|
---|
| 177 | bool root_add_device(device_t *dev)
|
---|
| 178 | {
|
---|
[729fa2d6] | 179 | // TODO add root device and register its children
|
---|
[924c75e1] | 180 | return true;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
[729fa2d6] | 183 | static driver_ops_t root_ops = {
|
---|
| 184 | .add_device = &root_add_device
|
---|
| 185 | };
|
---|
| 186 |
|
---|
| 187 | static driver_t root_driver = {
|
---|
| 188 | .name = NAME,
|
---|
| 189 | .driver_ops = &root_ops
|
---|
| 190 | };
|
---|
| 191 |
|
---|
| 192 | bool root_init()
|
---|
[924c75e1] | 193 | {
|
---|
[729fa2d6] | 194 | // TODO driver initialization
|
---|
[924c75e1] | 195 | return true;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | int main(int argc, char *argv[])
|
---|
| 199 | {
|
---|
| 200 | printf(NAME ": HelenOS root device driver\n");
|
---|
[729fa2d6] | 201 | if (!root_init()) {
|
---|
| 202 | printf(NAME ": Error while initializing driver.\n");
|
---|
[924c75e1] | 203 | return -1;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | return driver_main(&root_driver);
|
---|
| 207 | }
|
---|