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