[924c75e1] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Lenka Trochtova
|
---|
[0ca16307] | 3 | * Copyright (c) 2010 Vojtech Horky
|
---|
[924c75e1] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
[c16cf62] | 31 | * @defgroup root Root device driver.
|
---|
[924c75e1] | 32 | * @brief HelenOS root device driver.
|
---|
| 33 | * @{
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | /** @file
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | #include <assert.h>
|
---|
| 40 | #include <stdio.h>
|
---|
| 41 | #include <errno.h>
|
---|
| 42 | #include <bool.h>
|
---|
| 43 | #include <fibril_synch.h>
|
---|
| 44 | #include <stdlib.h>
|
---|
[c47e1a8] | 45 | #include <str.h>
|
---|
[924c75e1] | 46 | #include <ctype.h>
|
---|
[bda60d9] | 47 | #include <macros.h>
|
---|
[7e752b2] | 48 | #include <inttypes.h>
|
---|
[924c75e1] | 49 |
|
---|
[c16cf62] | 50 | #include <driver.h>
|
---|
[729fa2d6] | 51 | #include <devman.h>
|
---|
[924c75e1] | 52 | #include <ipc/devman.h>
|
---|
| 53 |
|
---|
| 54 | #define NAME "root"
|
---|
| 55 |
|
---|
[0ca16307] | 56 | #define PLATFORM_DEVICE_NAME "hw"
|
---|
| 57 | #define PLATFORM_DEVICE_MATCH_ID STRING(UARCH)
|
---|
| 58 | #define PLATFORM_DEVICE_MATCH_SCORE 100
|
---|
| 59 |
|
---|
[6f9e7fea] | 60 | #define VIRTUAL_DEVICE_NAME "virt"
|
---|
| 61 | #define VIRTUAL_DEVICE_MATCH_ID "rootvirt"
|
---|
| 62 | #define VIRTUAL_DEVICE_MATCH_SCORE 100
|
---|
| 63 |
|
---|
[df747b9c] | 64 | static int root_add_device(device_t *dev);
|
---|
[924c75e1] | 65 |
|
---|
[5291411] | 66 | /** The root device driver's standard operations. */
|
---|
[729fa2d6] | 67 | static driver_ops_t root_ops = {
|
---|
| 68 | .add_device = &root_add_device
|
---|
| 69 | };
|
---|
| 70 |
|
---|
[5291411] | 71 | /** The root device driver structure. */
|
---|
[729fa2d6] | 72 | static driver_t root_driver = {
|
---|
| 73 | .name = NAME,
|
---|
| 74 | .driver_ops = &root_ops
|
---|
| 75 | };
|
---|
| 76 |
|
---|
[6f9e7fea] | 77 | /** Create the device which represents the root of virtual device tree.
|
---|
| 78 | *
|
---|
| 79 | * @param parent Parent of the newly created device.
|
---|
| 80 | * @return Error code.
|
---|
| 81 | */
|
---|
| 82 | static int add_virtual_root_child(device_t *parent)
|
---|
| 83 | {
|
---|
| 84 | printf(NAME ": adding new child for virtual devices.\n");
|
---|
| 85 | printf(NAME ": device node is `%s' (%d %s)\n", VIRTUAL_DEVICE_NAME,
|
---|
| 86 | VIRTUAL_DEVICE_MATCH_SCORE, VIRTUAL_DEVICE_MATCH_ID);
|
---|
| 87 |
|
---|
| 88 | int res = child_device_register_wrapper(parent, VIRTUAL_DEVICE_NAME,
|
---|
| 89 | VIRTUAL_DEVICE_MATCH_ID, VIRTUAL_DEVICE_MATCH_SCORE);
|
---|
| 90 |
|
---|
| 91 | return res;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[df747b9c] | 94 | /** Create the device which represents the root of HW device tree.
|
---|
[5291411] | 95 | *
|
---|
| 96 | * @param parent Parent of the newly created device.
|
---|
[df747b9c] | 97 | * @return 0 on success, negative error number otherwise.
|
---|
[66babbd] | 98 | */
|
---|
[5291411] | 99 | static int add_platform_child(device_t *parent)
|
---|
| 100 | {
|
---|
[bda60d9] | 101 | printf(NAME ": adding new child for platform device.\n");
|
---|
[0ca16307] | 102 | printf(NAME ": device node is `%s' (%d %s)\n", PLATFORM_DEVICE_NAME,
|
---|
| 103 | PLATFORM_DEVICE_MATCH_SCORE, PLATFORM_DEVICE_MATCH_ID);
|
---|
[bda60d9] | 104 |
|
---|
[0ca16307] | 105 | int res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME,
|
---|
| 106 | PLATFORM_DEVICE_MATCH_ID, PLATFORM_DEVICE_MATCH_SCORE);
|
---|
| 107 |
|
---|
[5291411] | 108 | return res;
|
---|
[bda60d9] | 109 | }
|
---|
| 110 |
|
---|
[63b4f90] | 111 | /** Create virtual USB host controller device.
|
---|
| 112 | * Note that the virtual HC is actually device and driver in one
|
---|
| 113 | * task.
|
---|
| 114 | *
|
---|
| 115 | * @param parent Parent device.
|
---|
| 116 | * @return Error code.
|
---|
| 117 | */
|
---|
| 118 | static int add_virtual_usb_host_controller(device_t *parent)
|
---|
| 119 | {
|
---|
| 120 | printf(NAME ": adding virtual host contoller.\n");
|
---|
| 121 |
|
---|
| 122 | int rc;
|
---|
| 123 | device_t *vhc = NULL;
|
---|
| 124 | match_id_t *match_id = NULL;
|
---|
| 125 |
|
---|
| 126 | vhc = create_device();
|
---|
| 127 | if (vhc == NULL) {
|
---|
| 128 | rc = ENOMEM;
|
---|
| 129 | goto failure;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | vhc->name = "vhc";
|
---|
| 133 | printf(NAME ": the new device's name is %s.\n", vhc->name);
|
---|
| 134 |
|
---|
| 135 | /* Initialize match id list. */
|
---|
| 136 | match_id = create_match_id();
|
---|
| 137 | if (match_id == NULL) {
|
---|
| 138 | rc = ENOMEM;
|
---|
| 139 | goto failure;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | match_id->id = "usb&hc=vhc";
|
---|
| 143 | match_id->score = 100;
|
---|
| 144 | add_match_id(&vhc->match_ids, match_id);
|
---|
| 145 |
|
---|
| 146 | /* Register child device. */
|
---|
| 147 | rc = child_device_register(vhc, parent);
|
---|
| 148 | if (rc != EOK)
|
---|
| 149 | goto failure;
|
---|
| 150 |
|
---|
| 151 | return EOK;
|
---|
| 152 |
|
---|
| 153 | failure:
|
---|
| 154 | if (match_id != NULL)
|
---|
| 155 | match_id->id = NULL;
|
---|
| 156 |
|
---|
| 157 | if (vhc != NULL) {
|
---|
| 158 | vhc->name = NULL;
|
---|
| 159 | delete_device(vhc);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | return rc;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[66babbd] | 165 | /** Get the root device.
|
---|
[5291411] | 166 | *
|
---|
| 167 | * @param dev The device which is root of the whole device tree (both
|
---|
| 168 | * of HW and pseudo devices).
|
---|
[66babbd] | 169 | */
|
---|
[5291411] | 170 | static int root_add_device(device_t *dev)
|
---|
[c16cf62] | 171 | {
|
---|
[7e752b2] | 172 | printf(NAME ": root_add_device, device handle=%" PRIun "\n",
|
---|
| 173 | dev->handle);
|
---|
[bda60d9] | 174 |
|
---|
[6f9e7fea] | 175 | /*
|
---|
| 176 | * Register virtual devices root.
|
---|
| 177 | * We ignore error occurrence because virtual devices shall not be
|
---|
| 178 | * vital for the system.
|
---|
| 179 | */
|
---|
| 180 | add_virtual_root_child(dev);
|
---|
| 181 |
|
---|
[5291411] | 182 | /* Register root device's children. */
|
---|
| 183 | int res = add_platform_child(dev);
|
---|
| 184 | if (EOK != res)
|
---|
[d347b53] | 185 | printf(NAME ": failed to add child device for platform.\n");
|
---|
[bda60d9] | 186 |
|
---|
[63b4f90] | 187 | /* Register virtual USB host controller. */
|
---|
| 188 | int rc = add_virtual_usb_host_controller(dev);
|
---|
| 189 | if (EOK != rc) {
|
---|
| 190 | printf(NAME ": failed to add child device - virtual USB HC.\n");
|
---|
| 191 | }
|
---|
| 192 |
|
---|
[df747b9c] | 193 | return res;
|
---|
[c16cf62] | 194 | }
|
---|
| 195 |
|
---|
[924c75e1] | 196 | int main(int argc, char *argv[])
|
---|
| 197 | {
|
---|
[5291411] | 198 | printf(NAME ": HelenOS root device driver\n");
|
---|
[924c75e1] | 199 | return driver_main(&root_driver);
|
---|
| 200 | }
|
---|
[c16cf62] | 201 |
|
---|
| 202 | /**
|
---|
| 203 | * @}
|
---|
[bda60d9] | 204 | */
|
---|
[5291411] | 205 |
|
---|