| 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_pc PC platform driver.
|
|---|
| 31 | * @brief HelenOS PC platform driver.
|
|---|
| 32 | * @{
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| 35 | /** @file
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <assert.h>
|
|---|
| 39 | #include <stdio.h>
|
|---|
| 40 | #include <errno.h>
|
|---|
| 41 | #include <bool.h>
|
|---|
| 42 | #include <fibril_synch.h>
|
|---|
| 43 | #include <stdlib.h>
|
|---|
| 44 | #include <str.h>
|
|---|
| 45 | #include <ctype.h>
|
|---|
| 46 | #include <macros.h>
|
|---|
| 47 |
|
|---|
| 48 | #include <driver.h>
|
|---|
| 49 | #include <devman.h>
|
|---|
| 50 | #include <ipc/devman.h>
|
|---|
| 51 | #include <ipc/dev_iface.h>
|
|---|
| 52 | #include <ops/hw_res.h>
|
|---|
| 53 | #include <device/hw_res.h>
|
|---|
| 54 |
|
|---|
| 55 | #define NAME "rootpc"
|
|---|
| 56 |
|
|---|
| 57 | typedef struct rootpc_child_dev_data {
|
|---|
| 58 | hw_resource_list_t hw_resources;
|
|---|
| 59 | } rootpc_child_dev_data_t;
|
|---|
| 60 |
|
|---|
| 61 | static int rootpc_add_device(device_t *dev);
|
|---|
| 62 | static void root_pc_init(void);
|
|---|
| 63 |
|
|---|
| 64 | /** The root device driver's standard operations. */
|
|---|
| 65 | static driver_ops_t rootpc_ops = {
|
|---|
| 66 | .add_device = &rootpc_add_device
|
|---|
| 67 | };
|
|---|
| 68 |
|
|---|
| 69 | /** The root device driver structure. */
|
|---|
| 70 | static driver_t rootpc_driver = {
|
|---|
| 71 | .name = NAME,
|
|---|
| 72 | .driver_ops = &rootpc_ops
|
|---|
| 73 | };
|
|---|
| 74 |
|
|---|
| 75 | static hw_resource_t pci_conf_regs = {
|
|---|
| 76 | .type = IO_RANGE,
|
|---|
| 77 | .res.io_range = {
|
|---|
| 78 | .address = 0xCF8,
|
|---|
| 79 | .size = 8,
|
|---|
| 80 | .endianness = LITTLE_ENDIAN
|
|---|
| 81 | }
|
|---|
| 82 | };
|
|---|
| 83 |
|
|---|
| 84 | static rootpc_child_dev_data_t pci_data = {
|
|---|
| 85 | .hw_resources = {
|
|---|
| 86 | 1,
|
|---|
| 87 | &pci_conf_regs
|
|---|
| 88 | }
|
|---|
| 89 | };
|
|---|
| 90 |
|
|---|
| 91 | static hw_resource_list_t *rootpc_get_child_resources(device_t *dev)
|
|---|
| 92 | {
|
|---|
| 93 | rootpc_child_dev_data_t *data;
|
|---|
| 94 |
|
|---|
| 95 | data = (rootpc_child_dev_data_t *) dev->driver_data;
|
|---|
| 96 | if (NULL == data)
|
|---|
| 97 | return NULL;
|
|---|
| 98 |
|
|---|
| 99 | return &data->hw_resources;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | static bool rootpc_enable_child_interrupt(device_t *dev)
|
|---|
| 103 | {
|
|---|
| 104 | /* TODO */
|
|---|
| 105 |
|
|---|
| 106 | return false;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | static hw_res_ops_t child_hw_res_ops = {
|
|---|
| 110 | &rootpc_get_child_resources,
|
|---|
| 111 | &rootpc_enable_child_interrupt
|
|---|
| 112 | };
|
|---|
| 113 |
|
|---|
| 114 | /* Initialized in root_pc_init() function. */
|
|---|
| 115 | static device_ops_t rootpc_child_ops;
|
|---|
| 116 |
|
|---|
| 117 | static bool
|
|---|
| 118 | rootpc_add_child(device_t *parent, const char *name, const char *str_match_id,
|
|---|
| 119 | rootpc_child_dev_data_t *drv_data)
|
|---|
| 120 | {
|
|---|
| 121 | printf(NAME ": adding new child device '%s'.\n", name);
|
|---|
| 122 |
|
|---|
| 123 | device_t *child = NULL;
|
|---|
| 124 | match_id_t *match_id = NULL;
|
|---|
| 125 |
|
|---|
| 126 | /* Create new device. */
|
|---|
| 127 | child = create_device();
|
|---|
| 128 | if (NULL == child)
|
|---|
| 129 | goto failure;
|
|---|
| 130 |
|
|---|
| 131 | child->name = name;
|
|---|
| 132 | child->driver_data = drv_data;
|
|---|
| 133 |
|
|---|
| 134 | /* Initialize match id list */
|
|---|
| 135 | match_id = create_match_id();
|
|---|
| 136 | if (NULL == match_id)
|
|---|
| 137 | goto failure;
|
|---|
| 138 |
|
|---|
| 139 | match_id->id = str_match_id;
|
|---|
| 140 | match_id->score = 100;
|
|---|
| 141 | add_match_id(&child->match_ids, match_id);
|
|---|
| 142 |
|
|---|
| 143 | /* Set provided operations to the device. */
|
|---|
| 144 | child->ops = &rootpc_child_ops;
|
|---|
| 145 |
|
|---|
| 146 | /* Register child device. */
|
|---|
| 147 | if (EOK != child_device_register(child, parent))
|
|---|
| 148 | goto failure;
|
|---|
| 149 |
|
|---|
| 150 | return true;
|
|---|
| 151 |
|
|---|
| 152 | failure:
|
|---|
| 153 | if (NULL != match_id)
|
|---|
| 154 | match_id->id = NULL;
|
|---|
| 155 |
|
|---|
| 156 | if (NULL != child) {
|
|---|
| 157 | child->name = NULL;
|
|---|
| 158 | delete_device(child);
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | printf(NAME ": failed to add child device '%s'.\n", name);
|
|---|
| 162 |
|
|---|
| 163 | return false;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | static bool rootpc_add_children(device_t *dev)
|
|---|
| 167 | {
|
|---|
| 168 | return rootpc_add_child(dev, "pci0", "intel_pci", &pci_data);
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | /** Get the root device.
|
|---|
| 172 | *
|
|---|
| 173 | * @param dev The device which is root of the whole device tree (both
|
|---|
| 174 | * of HW and pseudo devices).
|
|---|
| 175 | * @return Zero on success, negative error number otherwise.
|
|---|
| 176 | */
|
|---|
| 177 | static int rootpc_add_device(device_t *dev)
|
|---|
| 178 | {
|
|---|
| 179 | printf(NAME ": rootpc_add_device, device handle = %d\n",
|
|---|
| 180 | (int)dev->handle);
|
|---|
| 181 |
|
|---|
| 182 | /* Register child devices. */
|
|---|
| 183 | if (!rootpc_add_children(dev)) {
|
|---|
| 184 | printf(NAME ": failed to add child devices for PC platform.\n");
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | return EOK;
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | static void root_pc_init(void)
|
|---|
| 191 | {
|
|---|
| 192 | rootpc_child_ops.interfaces[HW_RES_DEV_IFACE] = &child_hw_res_ops;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | int main(int argc, char *argv[])
|
|---|
| 196 | {
|
|---|
| 197 | printf(NAME ": HelenOS PC platform driver\n");
|
|---|
| 198 | root_pc_init();
|
|---|
| 199 | return driver_main(&rootpc_driver);
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | /**
|
|---|
| 203 | * @}
|
|---|
| 204 | */
|
|---|