[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>
|
---|
[924c75e1] | 48 |
|
---|
[c16cf62] | 49 | #include <driver.h>
|
---|
[729fa2d6] | 50 | #include <devman.h>
|
---|
[924c75e1] | 51 | #include <ipc/devman.h>
|
---|
| 52 |
|
---|
| 53 | #define NAME "root"
|
---|
| 54 |
|
---|
[0ca16307] | 55 | #define PLATFORM_DEVICE_NAME "hw"
|
---|
| 56 | #define PLATFORM_DEVICE_MATCH_ID STRING(UARCH)
|
---|
| 57 | #define PLATFORM_DEVICE_MATCH_SCORE 100
|
---|
| 58 |
|
---|
[df747b9c] | 59 | static int root_add_device(device_t *dev);
|
---|
[924c75e1] | 60 |
|
---|
[5291411] | 61 | /** The root device driver's standard operations. */
|
---|
[729fa2d6] | 62 | static driver_ops_t root_ops = {
|
---|
| 63 | .add_device = &root_add_device
|
---|
| 64 | };
|
---|
| 65 |
|
---|
[5291411] | 66 | /** The root device driver structure. */
|
---|
[729fa2d6] | 67 | static driver_t root_driver = {
|
---|
| 68 | .name = NAME,
|
---|
| 69 | .driver_ops = &root_ops
|
---|
| 70 | };
|
---|
| 71 |
|
---|
[df747b9c] | 72 | /** Create the device which represents the root of HW device tree.
|
---|
[5291411] | 73 | *
|
---|
| 74 | * @param parent Parent of the newly created device.
|
---|
[df747b9c] | 75 | * @return 0 on success, negative error number otherwise.
|
---|
[66babbd] | 76 | */
|
---|
[5291411] | 77 | static int add_platform_child(device_t *parent)
|
---|
| 78 | {
|
---|
[bda60d9] | 79 | printf(NAME ": adding new child for platform device.\n");
|
---|
[0ca16307] | 80 | printf(NAME ": device node is `%s' (%d %s)\n", PLATFORM_DEVICE_NAME,
|
---|
| 81 | PLATFORM_DEVICE_MATCH_SCORE, PLATFORM_DEVICE_MATCH_ID);
|
---|
[bda60d9] | 82 |
|
---|
[0ca16307] | 83 | int res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME,
|
---|
| 84 | PLATFORM_DEVICE_MATCH_ID, PLATFORM_DEVICE_MATCH_SCORE);
|
---|
| 85 |
|
---|
[5291411] | 86 | return res;
|
---|
[bda60d9] | 87 | }
|
---|
| 88 |
|
---|
[66babbd] | 89 | /** Get the root device.
|
---|
[5291411] | 90 | *
|
---|
| 91 | * @param dev The device which is root of the whole device tree (both
|
---|
| 92 | * of HW and pseudo devices).
|
---|
[66babbd] | 93 | */
|
---|
[5291411] | 94 | static int root_add_device(device_t *dev)
|
---|
[c16cf62] | 95 | {
|
---|
[bda60d9] | 96 | printf(NAME ": root_add_device, device handle = %d\n", dev->handle);
|
---|
| 97 |
|
---|
[5291411] | 98 | /* Register root device's children. */
|
---|
| 99 | int res = add_platform_child(dev);
|
---|
| 100 | if (EOK != res)
|
---|
[d347b53] | 101 | printf(NAME ": failed to add child device for platform.\n");
|
---|
[bda60d9] | 102 |
|
---|
[df747b9c] | 103 | return res;
|
---|
[c16cf62] | 104 | }
|
---|
| 105 |
|
---|
[924c75e1] | 106 | int main(int argc, char *argv[])
|
---|
| 107 | {
|
---|
[5291411] | 108 | printf(NAME ": HelenOS root device driver\n");
|
---|
[924c75e1] | 109 | return driver_main(&root_driver);
|
---|
| 110 | }
|
---|
[c16cf62] | 111 |
|
---|
| 112 | /**
|
---|
| 113 | * @}
|
---|
[bda60d9] | 114 | */
|
---|
[5291411] | 115 |
|
---|