| 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 | * @addtogroup pc pc
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 |
|
|---|
| 34 | /** @file
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <assert.h>
|
|---|
| 38 | #include <stdio.h>
|
|---|
| 39 | #include <errno.h>
|
|---|
| 40 | #include <stdbool.h>
|
|---|
| 41 | #include <fibril_synch.h>
|
|---|
| 42 | #include <stdlib.h>
|
|---|
| 43 | #include <str.h>
|
|---|
| 44 | #include <ctype.h>
|
|---|
| 45 | #include <macros.h>
|
|---|
| 46 |
|
|---|
| 47 | #include <ddf/driver.h>
|
|---|
| 48 | #include <ddf/log.h>
|
|---|
| 49 | #include <ipc/dev_iface.h>
|
|---|
| 50 | #include <ops/hw_res.h>
|
|---|
| 51 | #include <ops/pio_window.h>
|
|---|
| 52 |
|
|---|
| 53 | #define NAME "pc"
|
|---|
| 54 |
|
|---|
| 55 | typedef struct pc_fun {
|
|---|
| 56 | hw_resource_list_t hw_resources;
|
|---|
| 57 | pio_window_t pio_window;
|
|---|
| 58 | } pc_fun_t;
|
|---|
| 59 |
|
|---|
| 60 | static errno_t pc_dev_add(ddf_dev_t *dev);
|
|---|
| 61 | static void pc_init(void);
|
|---|
| 62 |
|
|---|
| 63 | /** The root device driver's standard operations. */
|
|---|
| 64 | static driver_ops_t pc_ops = {
|
|---|
| 65 | .dev_add = &pc_dev_add
|
|---|
| 66 | };
|
|---|
| 67 |
|
|---|
| 68 | /** The root device driver structure. */
|
|---|
| 69 | static driver_t pc_driver = {
|
|---|
| 70 | .name = NAME,
|
|---|
| 71 | .driver_ops = &pc_ops
|
|---|
| 72 | };
|
|---|
| 73 |
|
|---|
| 74 | static hw_resource_t pci_conf_regs[] = {
|
|---|
| 75 | {
|
|---|
| 76 | .type = IO_RANGE,
|
|---|
| 77 | .res.io_range = {
|
|---|
| 78 | .address = 0xCF8,
|
|---|
| 79 | .size = 4,
|
|---|
| 80 | .relative = false,
|
|---|
| 81 | .endianness = LITTLE_ENDIAN
|
|---|
| 82 | }
|
|---|
| 83 | },
|
|---|
| 84 | {
|
|---|
| 85 | .type = IO_RANGE,
|
|---|
| 86 | .res.io_range = {
|
|---|
| 87 | .address = 0xCFC,
|
|---|
| 88 | .size = 4,
|
|---|
| 89 | .relative = false,
|
|---|
| 90 | .endianness = LITTLE_ENDIAN
|
|---|
| 91 | }
|
|---|
| 92 | }
|
|---|
| 93 | };
|
|---|
| 94 |
|
|---|
| 95 | static pc_fun_t pci_data = {
|
|---|
| 96 | .hw_resources = {
|
|---|
| 97 | sizeof(pci_conf_regs) / sizeof(pci_conf_regs[0]),
|
|---|
| 98 | pci_conf_regs
|
|---|
| 99 | },
|
|---|
| 100 | .pio_window = {
|
|---|
| 101 | .mem = {
|
|---|
| 102 | .base = UINT32_C(0),
|
|---|
| 103 | .size = UINT32_C(0xffffffff) /* practical maximum */
|
|---|
| 104 | },
|
|---|
| 105 | .io = {
|
|---|
| 106 | .base = UINT32_C(0),
|
|---|
| 107 | .size = UINT32_C(0x10000)
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | };
|
|---|
| 111 |
|
|---|
| 112 | /** Obtain function soft-state from DDF function node */
|
|---|
| 113 | static pc_fun_t *pc_fun(ddf_fun_t *fnode)
|
|---|
| 114 | {
|
|---|
| 115 | return ddf_fun_data_get(fnode);
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | static hw_resource_list_t *pc_get_resources(ddf_fun_t *fnode)
|
|---|
| 119 | {
|
|---|
| 120 | pc_fun_t *fun = pc_fun(fnode);
|
|---|
| 121 |
|
|---|
| 122 | assert(fun != NULL);
|
|---|
| 123 | return &fun->hw_resources;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | static errno_t pc_enable_interrupt(ddf_fun_t *fun, int irq)
|
|---|
| 127 | {
|
|---|
| 128 | /* TODO */
|
|---|
| 129 |
|
|---|
| 130 | return false;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | static pio_window_t *pc_get_pio_window(ddf_fun_t *fnode)
|
|---|
| 134 | {
|
|---|
| 135 | pc_fun_t *fun = pc_fun(fnode);
|
|---|
| 136 |
|
|---|
| 137 | assert(fun != NULL);
|
|---|
| 138 | return &fun->pio_window;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | static hw_res_ops_t fun_hw_res_ops = {
|
|---|
| 142 | .get_resource_list = &pc_get_resources,
|
|---|
| 143 | .enable_interrupt = &pc_enable_interrupt,
|
|---|
| 144 | };
|
|---|
| 145 |
|
|---|
| 146 | static pio_window_ops_t fun_pio_window_ops = {
|
|---|
| 147 | .get_pio_window = &pc_get_pio_window
|
|---|
| 148 | };
|
|---|
| 149 |
|
|---|
| 150 | /* Initialized in pc_init() function. */
|
|---|
| 151 | static ddf_dev_ops_t pc_fun_ops;
|
|---|
| 152 |
|
|---|
| 153 | static bool
|
|---|
| 154 | pc_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id,
|
|---|
| 155 | pc_fun_t *fun_proto)
|
|---|
| 156 | {
|
|---|
| 157 | ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
|
|---|
| 158 |
|
|---|
| 159 | ddf_fun_t *fnode = NULL;
|
|---|
| 160 | errno_t rc;
|
|---|
| 161 |
|
|---|
| 162 | /* Create new device. */
|
|---|
| 163 | fnode = ddf_fun_create(dev, fun_inner, name);
|
|---|
| 164 | if (fnode == NULL)
|
|---|
| 165 | goto failure;
|
|---|
| 166 |
|
|---|
| 167 | pc_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(pc_fun_t));
|
|---|
| 168 | *fun = *fun_proto;
|
|---|
| 169 |
|
|---|
| 170 | /* Add match ID */
|
|---|
| 171 | rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
|
|---|
| 172 | if (rc != EOK)
|
|---|
| 173 | goto failure;
|
|---|
| 174 |
|
|---|
| 175 | /* Set provided operations to the device. */
|
|---|
| 176 | ddf_fun_set_ops(fnode, &pc_fun_ops);
|
|---|
| 177 |
|
|---|
| 178 | /* Register function. */
|
|---|
| 179 | if (ddf_fun_bind(fnode) != EOK) {
|
|---|
| 180 | ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
|
|---|
| 181 | goto failure;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | return true;
|
|---|
| 185 |
|
|---|
| 186 | failure:
|
|---|
| 187 | if (fnode != NULL)
|
|---|
| 188 | ddf_fun_destroy(fnode);
|
|---|
| 189 |
|
|---|
| 190 | ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
|
|---|
| 191 |
|
|---|
| 192 | return false;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | static bool pc_add_functions(ddf_dev_t *dev)
|
|---|
| 196 | {
|
|---|
| 197 | return pc_add_fun(dev, "pci0", "intel_pci", &pci_data);
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | /** Get the root device.
|
|---|
| 201 | *
|
|---|
| 202 | * @param dev The device which is root of the whole device tree (both
|
|---|
| 203 | * of HW and pseudo devices).
|
|---|
| 204 | * @return Zero on success, error number otherwise.
|
|---|
| 205 | */
|
|---|
| 206 | static errno_t pc_dev_add(ddf_dev_t *dev)
|
|---|
| 207 | {
|
|---|
| 208 | ddf_msg(LVL_DEBUG, "pc_dev_add, device handle = %d",
|
|---|
| 209 | (int)ddf_dev_get_handle(dev));
|
|---|
| 210 |
|
|---|
| 211 | /* Register functions. */
|
|---|
| 212 | if (!pc_add_functions(dev)) {
|
|---|
| 213 | ddf_msg(LVL_ERROR, "Failed to add functions for PC platform.");
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | return EOK;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | static void pc_init(void)
|
|---|
| 220 | {
|
|---|
| 221 | ddf_log_init(NAME);
|
|---|
| 222 | pc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
|
|---|
| 223 | pc_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | int main(int argc, char *argv[])
|
|---|
| 227 | {
|
|---|
| 228 | printf(NAME ": HelenOS PC platform driver\n");
|
|---|
| 229 | pc_init();
|
|---|
| 230 | return ddf_driver_main(&pc_driver);
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | /**
|
|---|
| 234 | * @}
|
|---|
| 235 | */
|
|---|