[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>
|
---|
[41b56084] | 52 | #include <ops/hw_res.h>
|
---|
[3843ecb] | 53 | #include <device/hw_res.h>
|
---|
[eff1a590] | 54 |
|
---|
[178673c] | 55 | #define NAME "rootpc"
|
---|
[eff1a590] | 56 |
|
---|
[68414f4a] | 57 | /** Obtain function soft-state from DDF function node */
|
---|
| 58 | #define ROOTPC_FUN(fnode) ((rootpc_fun_t *) (fnode)->driver_data)
|
---|
| 59 |
|
---|
| 60 | typedef struct rootpc_fun {
|
---|
[b9ccc46d] | 61 | hw_resource_list_t hw_resources;
|
---|
[68414f4a] | 62 | } rootpc_fun_t;
|
---|
[5cd136ab] | 63 |
|
---|
[178673c] | 64 | static int rootpc_add_device(device_t *dev);
|
---|
| 65 | static void root_pc_init(void);
|
---|
[eff1a590] | 66 |
|
---|
[b9ccc46d] | 67 | /** The root device driver's standard operations. */
|
---|
[178673c] | 68 | static driver_ops_t rootpc_ops = {
|
---|
| 69 | .add_device = &rootpc_add_device
|
---|
[eff1a590] | 70 | };
|
---|
| 71 |
|
---|
[b9ccc46d] | 72 | /** The root device driver structure. */
|
---|
[178673c] | 73 | static driver_t rootpc_driver = {
|
---|
[eff1a590] | 74 | .name = NAME,
|
---|
[178673c] | 75 | .driver_ops = &rootpc_ops
|
---|
[eff1a590] | 76 | };
|
---|
| 77 |
|
---|
[5cd136ab] | 78 | static hw_resource_t pci_conf_regs = {
|
---|
[3a5909f] | 79 | .type = IO_RANGE,
|
---|
| 80 | .res.io_range = {
|
---|
| 81 | .address = 0xCF8,
|
---|
[5cd136ab] | 82 | .size = 8,
|
---|
[b9ccc46d] | 83 | .endianness = LITTLE_ENDIAN
|
---|
| 84 | }
|
---|
[5cd136ab] | 85 | };
|
---|
| 86 |
|
---|
[68414f4a] | 87 | static rootpc_fun_t pci_data = {
|
---|
[5cd136ab] | 88 | .hw_resources = {
|
---|
[b9ccc46d] | 89 | 1,
|
---|
[5cd136ab] | 90 | &pci_conf_regs
|
---|
| 91 | }
|
---|
| 92 | };
|
---|
| 93 |
|
---|
[68414f4a] | 94 | static hw_resource_list_t *rootpc_get_resources(function_t *fnode)
|
---|
[9a66bc2e] | 95 | {
|
---|
[68414f4a] | 96 | rootpc_fun_t *fun = ROOTPC_FUN(fnode);
|
---|
[b9ccc46d] | 97 |
|
---|
[68414f4a] | 98 | assert(fun != NULL);
|
---|
| 99 | return &fun->hw_resources;
|
---|
[9a66bc2e] | 100 | }
|
---|
| 101 |
|
---|
[68414f4a] | 102 | static bool rootpc_enable_interrupt(function_t *fun)
|
---|
[9a66bc2e] | 103 | {
|
---|
[b9ccc46d] | 104 | /* TODO */
|
---|
[9a66bc2e] | 105 |
|
---|
| 106 | return false;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[8b1e15ac] | 109 | static hw_res_ops_t fun_hw_res_ops = {
|
---|
[68414f4a] | 110 | &rootpc_get_resources,
|
---|
| 111 | &rootpc_enable_interrupt
|
---|
[9a66bc2e] | 112 | };
|
---|
| 113 |
|
---|
[178673c] | 114 | /* Initialized in root_pc_init() function. */
|
---|
[8b1e15ac] | 115 | static device_ops_t rootpc_fun_ops;
|
---|
[3843ecb] | 116 |
|
---|
[b9ccc46d] | 117 | static bool
|
---|
[68414f4a] | 118 | rootpc_add_fun(device_t *dev, const char *name, const char *str_match_id,
|
---|
| 119 | rootpc_fun_t *fun)
|
---|
[5cd136ab] | 120 | {
|
---|
[8b1e15ac] | 121 | printf(NAME ": adding new function '%s'.\n", name);
|
---|
[eff1a590] | 122 |
|
---|
[68414f4a] | 123 | function_t *fnode = NULL;
|
---|
[b9ccc46d] | 124 | match_id_t *match_id = NULL;
|
---|
[eff1a590] | 125 |
|
---|
[b9ccc46d] | 126 | /* Create new device. */
|
---|
[68414f4a] | 127 | fnode = create_function();
|
---|
| 128 | if (fnode == NULL)
|
---|
[eff1a590] | 129 | goto failure;
|
---|
| 130 |
|
---|
[68414f4a] | 131 | fnode->name = name;
|
---|
| 132 | fnode->driver_data = fun;
|
---|
| 133 | fnode->ftype = fun_inner;
|
---|
[eff1a590] | 134 |
|
---|
[b9ccc46d] | 135 | /* Initialize match id list */
|
---|
| 136 | match_id = create_match_id();
|
---|
[68414f4a] | 137 | if (match_id == NULL)
|
---|
[eff1a590] | 138 | goto failure;
|
---|
[b9ccc46d] | 139 |
|
---|
[eff1a590] | 140 | match_id->id = str_match_id;
|
---|
| 141 | match_id->score = 100;
|
---|
[68414f4a] | 142 | add_match_id(&fnode->match_ids, match_id);
|
---|
[eff1a590] | 143 |
|
---|
[b9ccc46d] | 144 | /* Set provided operations to the device. */
|
---|
[68414f4a] | 145 | fnode->ops = &rootpc_fun_ops;
|
---|
[9a66bc2e] | 146 |
|
---|
[8b1e15ac] | 147 | /* Register function. */
|
---|
[68414f4a] | 148 | if (register_function(fnode, dev) != EOK)
|
---|
[eff1a590] | 149 | goto failure;
|
---|
[68414f4a] | 150 | printf(NAME ": registered function handle = %u\n", fnode->handle);
|
---|
[eff1a590] | 151 |
|
---|
| 152 | return true;
|
---|
| 153 |
|
---|
| 154 | failure:
|
---|
[68414f4a] | 155 | if (match_id != NULL)
|
---|
[eff1a590] | 156 | match_id->id = NULL;
|
---|
| 157 |
|
---|
[68414f4a] | 158 | if (fnode != NULL) {
|
---|
| 159 | fnode->name = NULL;
|
---|
| 160 | delete_function(fnode);
|
---|
[eff1a590] | 161 | }
|
---|
| 162 |
|
---|
[8b1e15ac] | 163 | printf(NAME ": failed to add function '%s'.\n", name);
|
---|
[eff1a590] | 164 |
|
---|
[b9ccc46d] | 165 | return false;
|
---|
[eff1a590] | 166 | }
|
---|
| 167 |
|
---|
[8b1e15ac] | 168 | static bool rootpc_add_functions(device_t *dev)
|
---|
[eff1a590] | 169 | {
|
---|
[8b1e15ac] | 170 | return rootpc_add_fun(dev, "pci0", "intel_pci", &pci_data);
|
---|
[eff1a590] | 171 | }
|
---|
| 172 |
|
---|
| 173 | /** Get the root device.
|
---|
[b9ccc46d] | 174 | *
|
---|
| 175 | * @param dev The device which is root of the whole device tree (both
|
---|
| 176 | * of HW and pseudo devices).
|
---|
| 177 | * @return Zero on success, negative error number otherwise.
|
---|
[eff1a590] | 178 | */
|
---|
[178673c] | 179 | static int rootpc_add_device(device_t *dev)
|
---|
[eff1a590] | 180 | {
|
---|
[ab3a851] | 181 | printf(NAME ": rootpc_add_device, device handle = %d\n",
|
---|
| 182 | (int)dev->handle);
|
---|
[eff1a590] | 183 |
|
---|
[8b1e15ac] | 184 | /* Register functions. */
|
---|
| 185 | if (!rootpc_add_functions(dev)) {
|
---|
| 186 | printf(NAME ": failed to add functions for PC platform.\n");
|
---|
[eff1a590] | 187 | }
|
---|
| 188 |
|
---|
[df747b9c] | 189 | return EOK;
|
---|
[eff1a590] | 190 | }
|
---|
| 191 |
|
---|
[178673c] | 192 | static void root_pc_init(void)
|
---|
[b9ccc46d] | 193 | {
|
---|
[8b1e15ac] | 194 | rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
|
---|
[3843ecb] | 195 | }
|
---|
| 196 |
|
---|
[eff1a590] | 197 | int main(int argc, char *argv[])
|
---|
| 198 | {
|
---|
[5f0123b] | 199 | printf(NAME ": HelenOS PC platform driver\n");
|
---|
[178673c] | 200 | root_pc_init();
|
---|
| 201 | return driver_main(&rootpc_driver);
|
---|
[eff1a590] | 202 | }
|
---|
| 203 |
|
---|
| 204 | /**
|
---|
| 205 | * @}
|
---|
| 206 | */
|
---|