[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 | /**
|
---|
[0f2a9be] | 31 | * @defgroup mac Mac platform driver.
|
---|
[73d288c] | 32 | * @brief HelenOS Mac platform driver.
|
---|
| 33 | * @{
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | /** @file
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | #include <ddf/driver.h>
|
---|
| 40 | #include <ddf/log.h>
|
---|
| 41 | #include <errno.h>
|
---|
| 42 | #include <ops/hw_res.h>
|
---|
[c188c62] | 43 | #include <ops/pio_window.h>
|
---|
[73d288c] | 44 | #include <stdio.h>
|
---|
[e27e36e] | 45 | #include <sysinfo.h>
|
---|
[73d288c] | 46 |
|
---|
[2a37b9f] | 47 | #define NAME "mac"
|
---|
[73d288c] | 48 |
|
---|
| 49 | typedef struct {
|
---|
| 50 | hw_resource_list_t hw_resources;
|
---|
[c188c62] | 51 | pio_window_t pio_window;
|
---|
[2a37b9f] | 52 | } mac_fun_t;
|
---|
[73d288c] | 53 |
|
---|
[c188c62] | 54 | static hw_resource_t adb_res[] = {
|
---|
[e27e36e] | 55 | {
|
---|
| 56 | .type = IO_RANGE,
|
---|
| 57 | .res.io_range = {
|
---|
| 58 | .address = 0,
|
---|
| 59 | .size = 0x2000,
|
---|
[c188c62] | 60 | .relative = true,
|
---|
[e27e36e] | 61 | .endianness = BIG_ENDIAN
|
---|
| 62 | }
|
---|
| 63 | },
|
---|
[c188c62] | 64 | {
|
---|
| 65 | .type = INTERRUPT,
|
---|
| 66 | .res.interrupt = {
|
---|
| 67 | .irq = 0 /* patched at run time */
|
---|
| 68 | }
|
---|
| 69 | },
|
---|
[e27e36e] | 70 | };
|
---|
| 71 |
|
---|
| 72 | static mac_fun_t adb_data = {
|
---|
| 73 | .hw_resources = {
|
---|
[c188c62] | 74 | sizeof(adb_res) / sizeof(adb_res[0]),
|
---|
| 75 | adb_res
|
---|
| 76 | },
|
---|
| 77 | .pio_window = {
|
---|
| 78 | .io = {
|
---|
| 79 | .base = 0, /* patched at run time */
|
---|
| 80 | .size = 0x2000
|
---|
| 81 | }
|
---|
[e27e36e] | 82 | }
|
---|
| 83 | };
|
---|
| 84 |
|
---|
[cb3dbb63] | 85 | static hw_resource_t pci_conf_regs[] = {
|
---|
| 86 | {
|
---|
| 87 | .type = IO_RANGE,
|
---|
| 88 | .res.io_range = {
|
---|
| 89 | .address = 0xfec00000,
|
---|
| 90 | .size = 4,
|
---|
[9e470c0] | 91 | .relative = false,
|
---|
[cb3dbb63] | 92 | .endianness = LITTLE_ENDIAN
|
---|
| 93 | }
|
---|
| 94 | },
|
---|
| 95 | {
|
---|
| 96 | .type = IO_RANGE,
|
---|
| 97 | .res.io_range = {
|
---|
| 98 | .address = 0xfee00000,
|
---|
| 99 | .size = 4,
|
---|
[9e470c0] | 100 | .relative = false,
|
---|
[cb3dbb63] | 101 | .endianness = LITTLE_ENDIAN
|
---|
| 102 | }
|
---|
[73d288c] | 103 | }
|
---|
| 104 | };
|
---|
| 105 |
|
---|
[2a37b9f] | 106 | static mac_fun_t pci_data = {
|
---|
[73d288c] | 107 | .hw_resources = {
|
---|
[cb3dbb63] | 108 | 2,
|
---|
| 109 | pci_conf_regs
|
---|
[73d288c] | 110 | }
|
---|
| 111 | };
|
---|
| 112 |
|
---|
[2a37b9f] | 113 | static ddf_dev_ops_t mac_fun_ops;
|
---|
[73d288c] | 114 |
|
---|
[56fd7cf] | 115 | /** Obtain function soft-state from DDF function node */
|
---|
[c188c62] | 116 | static mac_fun_t *mac_fun(ddf_fun_t *ddf_fun)
|
---|
[56fd7cf] | 117 | {
|
---|
[c188c62] | 118 | return ddf_fun_data_get(ddf_fun);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | static pio_window_t *mac_get_pio_window(ddf_fun_t *ddf_fun)
|
---|
| 122 | {
|
---|
| 123 | mac_fun_t *fun = mac_fun(ddf_fun);
|
---|
| 124 | return &fun->pio_window;
|
---|
[56fd7cf] | 125 | }
|
---|
| 126 |
|
---|
[2a37b9f] | 127 | static bool mac_add_fun(ddf_dev_t *dev, const char *name,
|
---|
| 128 | const char *str_match_id, mac_fun_t *fun_proto)
|
---|
[73d288c] | 129 | {
|
---|
| 130 | ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
|
---|
[e27e36e] | 131 | printf("mac: Adding new function '%s'.\n", name);
|
---|
[a35b458] | 132 |
|
---|
[73d288c] | 133 | ddf_fun_t *fnode = NULL;
|
---|
[b7fd2a0] | 134 | errno_t rc;
|
---|
[a35b458] | 135 |
|
---|
[73d288c] | 136 | /* Create new device. */
|
---|
| 137 | fnode = ddf_fun_create(dev, fun_inner, name);
|
---|
| 138 | if (fnode == NULL)
|
---|
| 139 | goto failure;
|
---|
[a35b458] | 140 |
|
---|
[2a37b9f] | 141 | mac_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(mac_fun_t));
|
---|
[56fd7cf] | 142 | *fun = *fun_proto;
|
---|
[a35b458] | 143 |
|
---|
[56fd7cf] | 144 | /* Add match ID */
|
---|
| 145 | rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
|
---|
| 146 | if (rc != EOK)
|
---|
[73d288c] | 147 | goto failure;
|
---|
[a35b458] | 148 |
|
---|
[73d288c] | 149 | /* Set provided operations to the device. */
|
---|
[2a37b9f] | 150 | ddf_fun_set_ops(fnode, &mac_fun_ops);
|
---|
[a35b458] | 151 |
|
---|
[73d288c] | 152 | /* Register function. */
|
---|
| 153 | if (ddf_fun_bind(fnode) != EOK) {
|
---|
| 154 | ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
|
---|
| 155 | goto failure;
|
---|
| 156 | }
|
---|
[a35b458] | 157 |
|
---|
[e27e36e] | 158 | printf("mac: Added new function '%s' (str=%s).\n", name, str_match_id);
|
---|
[73d288c] | 159 | return true;
|
---|
[a35b458] | 160 |
|
---|
[73d288c] | 161 | failure:
|
---|
| 162 | if (fnode != NULL)
|
---|
| 163 | ddf_fun_destroy(fnode);
|
---|
[a35b458] | 164 |
|
---|
[73d288c] | 165 | ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
|
---|
[a35b458] | 166 |
|
---|
[73d288c] | 167 | return false;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | /** Get the root device.
|
---|
| 171 | *
|
---|
| 172 | * @param dev Device which is root of the whole device tree
|
---|
| 173 | * (both of HW and pseudo devices).
|
---|
| 174 | *
|
---|
[cde999a] | 175 | * @return Zero on success, error number otherwise.
|
---|
[73d288c] | 176 | *
|
---|
| 177 | */
|
---|
[b7fd2a0] | 178 | static errno_t mac_dev_add(ddf_dev_t *dev)
|
---|
[73d288c] | 179 | {
|
---|
[b7fd2a0] | 180 | errno_t rc;
|
---|
[e27e36e] | 181 | uintptr_t cuda_physical;
|
---|
[c188c62] | 182 | sysarg_t cuda_inr;
|
---|
[3795f9c] | 183 | #if 0
|
---|
[73d288c] | 184 | /* Register functions */
|
---|
[e27e36e] | 185 | if (!mac_add_fun(dev, "pci0", "intel_pci", &pci_data)) {
|
---|
| 186 | ddf_msg(LVL_ERROR, "Failed to add PCI function for Mac platform.");
|
---|
| 187 | return EIO;
|
---|
| 188 | }
|
---|
[3795f9c] | 189 | #else
|
---|
| 190 | (void)pci_data;
|
---|
| 191 | #endif
|
---|
[e27e36e] | 192 | rc = sysinfo_get_value("cuda.address.physical", &cuda_physical);
|
---|
[c188c62] | 193 | if (rc != EOK)
|
---|
| 194 | return EIO;
|
---|
| 195 | rc = sysinfo_get_value("cuda.inr", &cuda_inr);
|
---|
[e27e36e] | 196 | if (rc != EOK)
|
---|
| 197 | return EIO;
|
---|
| 198 |
|
---|
[c188c62] | 199 | adb_data.pio_window.io.base = cuda_physical;
|
---|
| 200 | adb_res[1].res.interrupt.irq = cuda_inr;
|
---|
[e27e36e] | 201 |
|
---|
| 202 | if (!mac_add_fun(dev, "adb", "cuda_adb", &adb_data)) {
|
---|
| 203 | ddf_msg(LVL_ERROR, "Failed to add ADB function for Mac platform.");
|
---|
| 204 | return EIO;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
[73d288c] | 207 | return EOK;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | /** The root device driver's standard operations. */
|
---|
[2a37b9f] | 211 | static driver_ops_t mac_ops = {
|
---|
| 212 | .dev_add = &mac_dev_add
|
---|
[73d288c] | 213 | };
|
---|
| 214 |
|
---|
| 215 | /** The root device driver structure. */
|
---|
[2a37b9f] | 216 | static driver_t mac_driver = {
|
---|
[73d288c] | 217 | .name = NAME,
|
---|
[2a37b9f] | 218 | .driver_ops = &mac_ops
|
---|
[73d288c] | 219 | };
|
---|
| 220 |
|
---|
[2a37b9f] | 221 | static hw_resource_list_t *mac_get_resources(ddf_fun_t *fnode)
|
---|
[73d288c] | 222 | {
|
---|
[2a37b9f] | 223 | mac_fun_t *fun = mac_fun(fnode);
|
---|
[73d288c] | 224 | assert(fun != NULL);
|
---|
[a35b458] | 225 |
|
---|
[73d288c] | 226 | return &fun->hw_resources;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
[b7fd2a0] | 229 | static errno_t mac_enable_interrupt(ddf_fun_t *fun, int irq)
|
---|
[73d288c] | 230 | {
|
---|
| 231 | /* TODO */
|
---|
[a35b458] | 232 |
|
---|
[73d288c] | 233 | return false;
|
---|
| 234 | }
|
---|
| 235 |
|
---|
[c188c62] | 236 | static pio_window_ops_t fun_pio_window_ops = {
|
---|
| 237 | .get_pio_window = &mac_get_pio_window
|
---|
| 238 | };
|
---|
| 239 |
|
---|
[73d288c] | 240 | static hw_res_ops_t fun_hw_res_ops = {
|
---|
[2a37b9f] | 241 | .get_resource_list = &mac_get_resources,
|
---|
| 242 | .enable_interrupt = &mac_enable_interrupt
|
---|
[73d288c] | 243 | };
|
---|
| 244 |
|
---|
| 245 | int main(int argc, char *argv[])
|
---|
| 246 | {
|
---|
| 247 | printf("%s: HelenOS Mac platform driver\n", NAME);
|
---|
[267f235] | 248 | ddf_log_init(NAME);
|
---|
[2a37b9f] | 249 | mac_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
|
---|
[c188c62] | 250 | mac_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
|
---|
[2a37b9f] | 251 | return ddf_driver_main(&mac_driver);
|
---|
[73d288c] | 252 | }
|
---|
| 253 |
|
---|
| 254 | /**
|
---|
| 255 | * @}
|
---|
| 256 | */
|
---|