[73d288c] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Martin Decky
|
---|
[c188c62] | 3 | * Copyright (c) 2017 Jiri Svoboda
|
---|
[73d288c] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
[4122410] | 31 | * @addtogroup mac mac
|
---|
[73d288c] | 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>
|
---|
[c188c62] | 42 | #include <ops/pio_window.h>
|
---|
[73d288c] | 43 | #include <stdio.h>
|
---|
[e27e36e] | 44 | #include <sysinfo.h>
|
---|
[73d288c] | 45 |
|
---|
[2a37b9f] | 46 | #define NAME "mac"
|
---|
[73d288c] | 47 |
|
---|
| 48 | typedef struct {
|
---|
| 49 | hw_resource_list_t hw_resources;
|
---|
[c188c62] | 50 | pio_window_t pio_window;
|
---|
[2a37b9f] | 51 | } mac_fun_t;
|
---|
[73d288c] | 52 |
|
---|
[c188c62] | 53 | static hw_resource_t adb_res[] = {
|
---|
[e27e36e] | 54 | {
|
---|
| 55 | .type = IO_RANGE,
|
---|
| 56 | .res.io_range = {
|
---|
| 57 | .address = 0,
|
---|
| 58 | .size = 0x2000,
|
---|
[c188c62] | 59 | .relative = true,
|
---|
[e27e36e] | 60 | .endianness = BIG_ENDIAN
|
---|
| 61 | }
|
---|
| 62 | },
|
---|
[c188c62] | 63 | {
|
---|
| 64 | .type = INTERRUPT,
|
---|
| 65 | .res.interrupt = {
|
---|
| 66 | .irq = 0 /* patched at run time */
|
---|
| 67 | }
|
---|
| 68 | },
|
---|
[e27e36e] | 69 | };
|
---|
| 70 |
|
---|
| 71 | static mac_fun_t adb_data = {
|
---|
| 72 | .hw_resources = {
|
---|
[c188c62] | 73 | sizeof(adb_res) / sizeof(adb_res[0]),
|
---|
| 74 | adb_res
|
---|
| 75 | },
|
---|
| 76 | .pio_window = {
|
---|
| 77 | .io = {
|
---|
| 78 | .base = 0, /* patched at run time */
|
---|
| 79 | .size = 0x2000
|
---|
| 80 | }
|
---|
[e27e36e] | 81 | }
|
---|
| 82 | };
|
---|
| 83 |
|
---|
[cb3dbb63] | 84 | static hw_resource_t pci_conf_regs[] = {
|
---|
| 85 | {
|
---|
| 86 | .type = IO_RANGE,
|
---|
| 87 | .res.io_range = {
|
---|
| 88 | .address = 0xfec00000,
|
---|
| 89 | .size = 4,
|
---|
[9e470c0] | 90 | .relative = false,
|
---|
[cb3dbb63] | 91 | .endianness = LITTLE_ENDIAN
|
---|
| 92 | }
|
---|
| 93 | },
|
---|
| 94 | {
|
---|
| 95 | .type = IO_RANGE,
|
---|
| 96 | .res.io_range = {
|
---|
| 97 | .address = 0xfee00000,
|
---|
| 98 | .size = 4,
|
---|
[9e470c0] | 99 | .relative = false,
|
---|
[cb3dbb63] | 100 | .endianness = LITTLE_ENDIAN
|
---|
| 101 | }
|
---|
[73d288c] | 102 | }
|
---|
| 103 | };
|
---|
| 104 |
|
---|
[2a37b9f] | 105 | static mac_fun_t pci_data = {
|
---|
[73d288c] | 106 | .hw_resources = {
|
---|
[cb3dbb63] | 107 | 2,
|
---|
| 108 | pci_conf_regs
|
---|
[73d288c] | 109 | }
|
---|
| 110 | };
|
---|
| 111 |
|
---|
[2a37b9f] | 112 | static ddf_dev_ops_t mac_fun_ops;
|
---|
[73d288c] | 113 |
|
---|
[56fd7cf] | 114 | /** Obtain function soft-state from DDF function node */
|
---|
[c188c62] | 115 | static mac_fun_t *mac_fun(ddf_fun_t *ddf_fun)
|
---|
[56fd7cf] | 116 | {
|
---|
[c188c62] | 117 | return ddf_fun_data_get(ddf_fun);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | static pio_window_t *mac_get_pio_window(ddf_fun_t *ddf_fun)
|
---|
| 121 | {
|
---|
| 122 | mac_fun_t *fun = mac_fun(ddf_fun);
|
---|
| 123 | return &fun->pio_window;
|
---|
[56fd7cf] | 124 | }
|
---|
| 125 |
|
---|
[2a37b9f] | 126 | static bool mac_add_fun(ddf_dev_t *dev, const char *name,
|
---|
| 127 | const char *str_match_id, mac_fun_t *fun_proto)
|
---|
[73d288c] | 128 | {
|
---|
| 129 | ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
|
---|
[e27e36e] | 130 | printf("mac: Adding new function '%s'.\n", name);
|
---|
[a35b458] | 131 |
|
---|
[73d288c] | 132 | ddf_fun_t *fnode = NULL;
|
---|
[b7fd2a0] | 133 | errno_t rc;
|
---|
[a35b458] | 134 |
|
---|
[73d288c] | 135 | /* Create new device. */
|
---|
| 136 | fnode = ddf_fun_create(dev, fun_inner, name);
|
---|
| 137 | if (fnode == NULL)
|
---|
| 138 | goto failure;
|
---|
[a35b458] | 139 |
|
---|
[2a37b9f] | 140 | mac_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(mac_fun_t));
|
---|
[56fd7cf] | 141 | *fun = *fun_proto;
|
---|
[a35b458] | 142 |
|
---|
[56fd7cf] | 143 | /* Add match ID */
|
---|
| 144 | rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
|
---|
| 145 | if (rc != EOK)
|
---|
[73d288c] | 146 | goto failure;
|
---|
[a35b458] | 147 |
|
---|
[73d288c] | 148 | /* Set provided operations to the device. */
|
---|
[2a37b9f] | 149 | ddf_fun_set_ops(fnode, &mac_fun_ops);
|
---|
[a35b458] | 150 |
|
---|
[73d288c] | 151 | /* Register function. */
|
---|
| 152 | if (ddf_fun_bind(fnode) != EOK) {
|
---|
| 153 | ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
|
---|
| 154 | goto failure;
|
---|
| 155 | }
|
---|
[a35b458] | 156 |
|
---|
[e27e36e] | 157 | printf("mac: Added new function '%s' (str=%s).\n", name, str_match_id);
|
---|
[73d288c] | 158 | return true;
|
---|
[a35b458] | 159 |
|
---|
[73d288c] | 160 | failure:
|
---|
| 161 | if (fnode != NULL)
|
---|
| 162 | ddf_fun_destroy(fnode);
|
---|
[a35b458] | 163 |
|
---|
[73d288c] | 164 | ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
|
---|
[a35b458] | 165 |
|
---|
[73d288c] | 166 | return false;
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | /** Get the root device.
|
---|
| 170 | *
|
---|
| 171 | * @param dev Device which is root of the whole device tree
|
---|
| 172 | * (both of HW and pseudo devices).
|
---|
| 173 | *
|
---|
[cde999a] | 174 | * @return Zero on success, error number otherwise.
|
---|
[73d288c] | 175 | *
|
---|
| 176 | */
|
---|
[b7fd2a0] | 177 | static errno_t mac_dev_add(ddf_dev_t *dev)
|
---|
[73d288c] | 178 | {
|
---|
[b7fd2a0] | 179 | errno_t rc;
|
---|
[e27e36e] | 180 | uintptr_t cuda_physical;
|
---|
[c188c62] | 181 | sysarg_t cuda_inr;
|
---|
[3795f9c] | 182 | #if 0
|
---|
[73d288c] | 183 | /* Register functions */
|
---|
[e27e36e] | 184 | if (!mac_add_fun(dev, "pci0", "intel_pci", &pci_data)) {
|
---|
| 185 | ddf_msg(LVL_ERROR, "Failed to add PCI function for Mac platform.");
|
---|
| 186 | return EIO;
|
---|
| 187 | }
|
---|
[3795f9c] | 188 | #else
|
---|
| 189 | (void)pci_data;
|
---|
| 190 | #endif
|
---|
[e27e36e] | 191 | rc = sysinfo_get_value("cuda.address.physical", &cuda_physical);
|
---|
[c188c62] | 192 | if (rc != EOK)
|
---|
| 193 | return EIO;
|
---|
| 194 | rc = sysinfo_get_value("cuda.inr", &cuda_inr);
|
---|
[e27e36e] | 195 | if (rc != EOK)
|
---|
| 196 | return EIO;
|
---|
| 197 |
|
---|
[c188c62] | 198 | adb_data.pio_window.io.base = cuda_physical;
|
---|
| 199 | adb_res[1].res.interrupt.irq = cuda_inr;
|
---|
[e27e36e] | 200 |
|
---|
| 201 | if (!mac_add_fun(dev, "adb", "cuda_adb", &adb_data)) {
|
---|
| 202 | ddf_msg(LVL_ERROR, "Failed to add ADB function for Mac platform.");
|
---|
| 203 | return EIO;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
[73d288c] | 206 | return EOK;
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | /** The root device driver's standard operations. */
|
---|
[2a37b9f] | 210 | static driver_ops_t mac_ops = {
|
---|
| 211 | .dev_add = &mac_dev_add
|
---|
[73d288c] | 212 | };
|
---|
| 213 |
|
---|
| 214 | /** The root device driver structure. */
|
---|
[2a37b9f] | 215 | static driver_t mac_driver = {
|
---|
[73d288c] | 216 | .name = NAME,
|
---|
[2a37b9f] | 217 | .driver_ops = &mac_ops
|
---|
[73d288c] | 218 | };
|
---|
| 219 |
|
---|
[2a37b9f] | 220 | static hw_resource_list_t *mac_get_resources(ddf_fun_t *fnode)
|
---|
[73d288c] | 221 | {
|
---|
[2a37b9f] | 222 | mac_fun_t *fun = mac_fun(fnode);
|
---|
[73d288c] | 223 | assert(fun != NULL);
|
---|
[a35b458] | 224 |
|
---|
[73d288c] | 225 | return &fun->hw_resources;
|
---|
| 226 | }
|
---|
| 227 |
|
---|
[b7fd2a0] | 228 | static errno_t mac_enable_interrupt(ddf_fun_t *fun, int irq)
|
---|
[73d288c] | 229 | {
|
---|
| 230 | /* TODO */
|
---|
[a35b458] | 231 |
|
---|
[73d288c] | 232 | return false;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
[c188c62] | 235 | static pio_window_ops_t fun_pio_window_ops = {
|
---|
[1433ecda] | 236 | .get_pio_window = &mac_get_pio_window
|
---|
[c188c62] | 237 | };
|
---|
| 238 |
|
---|
[73d288c] | 239 | static hw_res_ops_t fun_hw_res_ops = {
|
---|
[1433ecda] | 240 | .get_resource_list = &mac_get_resources,
|
---|
[2a37b9f] | 241 | .enable_interrupt = &mac_enable_interrupt
|
---|
[73d288c] | 242 | };
|
---|
| 243 |
|
---|
| 244 | int main(int argc, char *argv[])
|
---|
| 245 | {
|
---|
| 246 | printf("%s: HelenOS Mac platform driver\n", NAME);
|
---|
[267f235] | 247 | ddf_log_init(NAME);
|
---|
[2a37b9f] | 248 | mac_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
|
---|
[c188c62] | 249 | mac_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
|
---|
[2a37b9f] | 250 | return ddf_driver_main(&mac_driver);
|
---|
[73d288c] | 251 | }
|
---|
| 252 |
|
---|
| 253 | /**
|
---|
| 254 | * @}
|
---|
| 255 | */
|
---|