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