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