[73d288c] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Martin Decky
|
---|
| 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 | * @defgroup root_mac Mac platform driver.
|
---|
| 31 | * @brief HelenOS Mac platform driver.
|
---|
| 32 | * @{
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | /** @file
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #include <ddf/driver.h>
|
---|
| 39 | #include <ddf/log.h>
|
---|
| 40 | #include <errno.h>
|
---|
| 41 | #include <ops/hw_res.h>
|
---|
| 42 | #include <stdio.h>
|
---|
| 43 |
|
---|
| 44 | #define NAME "rootmac"
|
---|
| 45 |
|
---|
| 46 | typedef struct {
|
---|
| 47 | hw_resource_list_t hw_resources;
|
---|
| 48 | } rootmac_fun_t;
|
---|
| 49 |
|
---|
[cb3dbb63] | 50 | static hw_resource_t pci_conf_regs[] = {
|
---|
| 51 | {
|
---|
| 52 | .type = IO_RANGE,
|
---|
| 53 | .res.io_range = {
|
---|
| 54 | .address = 0xfec00000,
|
---|
| 55 | .size = 4,
|
---|
[9e470c0] | 56 | .relative = false,
|
---|
[cb3dbb63] | 57 | .endianness = LITTLE_ENDIAN
|
---|
| 58 | }
|
---|
| 59 | },
|
---|
| 60 | {
|
---|
| 61 | .type = IO_RANGE,
|
---|
| 62 | .res.io_range = {
|
---|
| 63 | .address = 0xfee00000,
|
---|
| 64 | .size = 4,
|
---|
[9e470c0] | 65 | .relative = false,
|
---|
[cb3dbb63] | 66 | .endianness = LITTLE_ENDIAN
|
---|
| 67 | }
|
---|
[73d288c] | 68 | }
|
---|
| 69 | };
|
---|
| 70 |
|
---|
| 71 | static rootmac_fun_t pci_data = {
|
---|
| 72 | .hw_resources = {
|
---|
[cb3dbb63] | 73 | 2,
|
---|
| 74 | pci_conf_regs
|
---|
[73d288c] | 75 | }
|
---|
| 76 | };
|
---|
| 77 |
|
---|
| 78 | static ddf_dev_ops_t rootmac_fun_ops;
|
---|
| 79 |
|
---|
[56fd7cf] | 80 | /** Obtain function soft-state from DDF function node */
|
---|
| 81 | static rootmac_fun_t *rootmac_fun(ddf_fun_t *fnode)
|
---|
| 82 | {
|
---|
| 83 | return ddf_fun_data_get(fnode);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[73d288c] | 86 | static bool rootmac_add_fun(ddf_dev_t *dev, const char *name,
|
---|
[56fd7cf] | 87 | const char *str_match_id, rootmac_fun_t *fun_proto)
|
---|
[73d288c] | 88 | {
|
---|
| 89 | ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
|
---|
| 90 |
|
---|
| 91 | ddf_fun_t *fnode = NULL;
|
---|
[56fd7cf] | 92 | int rc;
|
---|
[73d288c] | 93 |
|
---|
| 94 | /* Create new device. */
|
---|
| 95 | fnode = ddf_fun_create(dev, fun_inner, name);
|
---|
| 96 | if (fnode == NULL)
|
---|
| 97 | goto failure;
|
---|
| 98 |
|
---|
[56fd7cf] | 99 | rootmac_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(rootmac_fun_t));
|
---|
| 100 | *fun = *fun_proto;
|
---|
[73d288c] | 101 |
|
---|
[56fd7cf] | 102 | /* Add match ID */
|
---|
| 103 | rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
|
---|
| 104 | if (rc != EOK)
|
---|
[73d288c] | 105 | goto failure;
|
---|
| 106 |
|
---|
| 107 | /* Set provided operations to the device. */
|
---|
[56fd7cf] | 108 | ddf_fun_set_ops(fnode, &rootmac_fun_ops);
|
---|
[73d288c] | 109 |
|
---|
| 110 | /* Register function. */
|
---|
| 111 | if (ddf_fun_bind(fnode) != EOK) {
|
---|
| 112 | ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
|
---|
| 113 | goto failure;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | return true;
|
---|
| 117 |
|
---|
| 118 | failure:
|
---|
| 119 | if (fnode != NULL)
|
---|
| 120 | ddf_fun_destroy(fnode);
|
---|
| 121 |
|
---|
| 122 | ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
|
---|
| 123 |
|
---|
| 124 | return false;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | /** Get the root device.
|
---|
| 128 | *
|
---|
| 129 | * @param dev Device which is root of the whole device tree
|
---|
| 130 | * (both of HW and pseudo devices).
|
---|
| 131 | *
|
---|
| 132 | * @return Zero on success, negative error number otherwise.
|
---|
| 133 | *
|
---|
| 134 | */
|
---|
[0c0f823b] | 135 | static int rootmac_dev_add(ddf_dev_t *dev)
|
---|
[73d288c] | 136 | {
|
---|
[3795f9c] | 137 | #if 0
|
---|
[73d288c] | 138 | /* Register functions */
|
---|
[cb3dbb63] | 139 | if (!rootmac_add_fun(dev, "pci0", "intel_pci", &pci_data))
|
---|
[73d288c] | 140 | ddf_msg(LVL_ERROR, "Failed to add functions for Mac platform.");
|
---|
[3795f9c] | 141 | #else
|
---|
| 142 | (void)pci_data;
|
---|
| 143 | (void)rootmac_add_fun;
|
---|
| 144 | #endif
|
---|
[73d288c] | 145 |
|
---|
| 146 | return EOK;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | /** The root device driver's standard operations. */
|
---|
| 150 | static driver_ops_t rootmac_ops = {
|
---|
[0c0f823b] | 151 | .dev_add = &rootmac_dev_add
|
---|
[73d288c] | 152 | };
|
---|
| 153 |
|
---|
| 154 | /** The root device driver structure. */
|
---|
| 155 | static driver_t rootmac_driver = {
|
---|
| 156 | .name = NAME,
|
---|
| 157 | .driver_ops = &rootmac_ops
|
---|
| 158 | };
|
---|
| 159 |
|
---|
| 160 | static hw_resource_list_t *rootmac_get_resources(ddf_fun_t *fnode)
|
---|
| 161 | {
|
---|
[56fd7cf] | 162 | rootmac_fun_t *fun = rootmac_fun(fnode);
|
---|
[73d288c] | 163 | assert(fun != NULL);
|
---|
| 164 |
|
---|
| 165 | return &fun->hw_resources;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | static bool rootmac_enable_interrupt(ddf_fun_t *fun)
|
---|
| 169 | {
|
---|
| 170 | /* TODO */
|
---|
| 171 |
|
---|
| 172 | return false;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | static hw_res_ops_t fun_hw_res_ops = {
|
---|
[827ec41] | 176 | .get_resource_list = &rootmac_get_resources,
|
---|
| 177 | .enable_interrupt = &rootmac_enable_interrupt
|
---|
[73d288c] | 178 | };
|
---|
| 179 |
|
---|
| 180 | int main(int argc, char *argv[])
|
---|
| 181 | {
|
---|
| 182 | printf("%s: HelenOS Mac platform driver\n", NAME);
|
---|
[267f235] | 183 | ddf_log_init(NAME);
|
---|
[73d288c] | 184 | rootmac_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
|
---|
| 185 | return ddf_driver_main(&rootmac_driver);
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | /**
|
---|
| 189 | * @}
|
---|
| 190 | */
|
---|