[9191607] | 1 | /*
|
---|
| 2 | * Copyright (c) 2016 Jakub Jermar
|
---|
| 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 sun4u sun4u platform driver.
|
---|
| 31 | * @brief HelenOS sun4u platform driver.
|
---|
| 32 | * @{
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | /** @file
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #include <assert.h>
|
---|
| 39 | #include <stdio.h>
|
---|
| 40 | #include <errno.h>
|
---|
| 41 | #include <stdbool.h>
|
---|
| 42 | #include <fibril_synch.h>
|
---|
| 43 | #include <stdlib.h>
|
---|
| 44 | #include <str.h>
|
---|
| 45 | #include <ctype.h>
|
---|
| 46 | #include <macros.h>
|
---|
| 47 |
|
---|
| 48 | #include <ddi.h>
|
---|
| 49 | #include <ddf/driver.h>
|
---|
| 50 | #include <ddf/log.h>
|
---|
| 51 | #include <ipc/dev_iface.h>
|
---|
| 52 | #include <ops/hw_res.h>
|
---|
| 53 | #include <ops/pio_window.h>
|
---|
| 54 | #include <byteorder.h>
|
---|
| 55 |
|
---|
| 56 | #define NAME "sun4u"
|
---|
| 57 |
|
---|
| 58 | #define PBM_BASE UINT64_C(0x1fe00000000)
|
---|
| 59 | #define PBM_SIZE UINT64_C(0x00200000000)
|
---|
| 60 |
|
---|
[54861ca] | 61 | #define PBM_PCI_CONFIG_BASE UINT64_C(0x00001000000)
|
---|
[9191607] | 62 | #define PBM_PCI_CONFIG_SIZE UINT64_C(0x00001000000)
|
---|
| 63 |
|
---|
[54861ca] | 64 | #define PBM_PCI_IO_BASE UINT64_C(0x00002000000)
|
---|
| 65 | #define PBM_PCI_IO_SIZE UINT64_C(0x00001000000)
|
---|
| 66 |
|
---|
| 67 | #define PBM_PCI_MEM_BASE UINT64_C(0x00100000000)
|
---|
| 68 | #define PBM_PCI_MEM_SIZE UINT64_C(0x00100000000)
|
---|
| 69 |
|
---|
[48adf0f] | 70 | #define PBM_OBIO_BASE UINT64_C(0)
|
---|
| 71 | #define PBM_OBIO_SIZE UINT64_C(0x1898)
|
---|
| 72 |
|
---|
| 73 |
|
---|
[9191607] | 74 | typedef struct sun4u_fun {
|
---|
| 75 | hw_resource_list_t hw_resources;
|
---|
| 76 | pio_window_t pio_window;
|
---|
| 77 | } sun4u_fun_t;
|
---|
| 78 |
|
---|
[b7fd2a0] | 79 | static errno_t sun4u_dev_add(ddf_dev_t *dev);
|
---|
[9191607] | 80 | static void sun4u_init(void);
|
---|
| 81 |
|
---|
| 82 | /** The root device driver's standard operations. */
|
---|
| 83 | static driver_ops_t sun4u_ops = {
|
---|
| 84 | .dev_add = &sun4u_dev_add
|
---|
| 85 | };
|
---|
| 86 |
|
---|
| 87 | /** The root device driver structure. */
|
---|
| 88 | static driver_t sun4u_driver = {
|
---|
| 89 | .name = NAME,
|
---|
| 90 | .driver_ops = &sun4u_ops
|
---|
| 91 | };
|
---|
| 92 |
|
---|
[be1b1e68] | 93 | static hw_resource_t obio_res[] = {
|
---|
| 94 | {
|
---|
| 95 | .type = MEM_RANGE,
|
---|
| 96 | .res.mem_range = {
|
---|
[48adf0f] | 97 | .address = PBM_BASE + PBM_OBIO_BASE,
|
---|
| 98 | .size = PBM_OBIO_SIZE,
|
---|
[be1b1e68] | 99 | .relative = false,
|
---|
| 100 | .endianness = LITTLE_ENDIAN
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | };
|
---|
| 104 |
|
---|
| 105 | static sun4u_fun_t obio_data = {
|
---|
| 106 | .hw_resources = {
|
---|
| 107 | .count = sizeof(obio_res) / sizeof(obio_res[0]),
|
---|
| 108 | .resources = obio_res
|
---|
| 109 | },
|
---|
| 110 | .pio_window = {
|
---|
| 111 | .mem = {
|
---|
[48adf0f] | 112 | .base = PBM_BASE + PBM_OBIO_BASE,
|
---|
| 113 | .size = PBM_OBIO_SIZE
|
---|
[be1b1e68] | 114 | }
|
---|
| 115 | }
|
---|
| 116 | };
|
---|
| 117 |
|
---|
[9191607] | 118 | static hw_resource_t pci_conf_regs[] = {
|
---|
| 119 | {
|
---|
| 120 | .type = MEM_RANGE,
|
---|
| 121 | .res.mem_range = {
|
---|
[54861ca] | 122 | .address = PBM_BASE + PBM_PCI_CONFIG_BASE,
|
---|
[9191607] | 123 | .size = PBM_PCI_CONFIG_SIZE,
|
---|
[54861ca] | 124 | .relative = false,
|
---|
[9191607] | 125 | .endianness = LITTLE_ENDIAN
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 | };
|
---|
| 129 |
|
---|
| 130 | static sun4u_fun_t pci_data = {
|
---|
| 131 | .hw_resources = {
|
---|
| 132 | .count = sizeof(pci_conf_regs) / sizeof(pci_conf_regs[0]),
|
---|
| 133 | .resources = pci_conf_regs
|
---|
| 134 | },
|
---|
| 135 | .pio_window = {
|
---|
| 136 | .mem = {
|
---|
[54861ca] | 137 | .base = PBM_BASE + PBM_PCI_MEM_BASE,
|
---|
| 138 | .size = PBM_PCI_MEM_SIZE
|
---|
[9191607] | 139 | },
|
---|
| 140 | .io = {
|
---|
[54861ca] | 141 | .base = PBM_BASE + PBM_PCI_IO_BASE,
|
---|
| 142 | .size = PBM_PCI_IO_SIZE
|
---|
[9191607] | 143 | }
|
---|
| 144 | }
|
---|
| 145 | };
|
---|
| 146 |
|
---|
| 147 | /** Obtain function soft-state from DDF function node */
|
---|
| 148 | static sun4u_fun_t *sun4u_fun(ddf_fun_t *fnode)
|
---|
| 149 | {
|
---|
| 150 | return ddf_fun_data_get(fnode);
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | static hw_resource_list_t *sun4u_get_resources(ddf_fun_t *fnode)
|
---|
| 154 | {
|
---|
| 155 | sun4u_fun_t *fun = sun4u_fun(fnode);
|
---|
[a35b458] | 156 |
|
---|
[9191607] | 157 | assert(fun != NULL);
|
---|
| 158 | return &fun->hw_resources;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
[b7fd2a0] | 161 | static errno_t sun4u_enable_interrupt(ddf_fun_t *fun, int irq)
|
---|
[9191607] | 162 | {
|
---|
| 163 | /* TODO */
|
---|
[a35b458] | 164 |
|
---|
[9191607] | 165 | return false;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | static pio_window_t *sun4u_get_pio_window(ddf_fun_t *fnode)
|
---|
| 169 | {
|
---|
| 170 | sun4u_fun_t *fun = sun4u_fun(fnode);
|
---|
| 171 |
|
---|
| 172 | assert(fun != NULL);
|
---|
| 173 | return &fun->pio_window;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | static hw_res_ops_t fun_hw_res_ops = {
|
---|
| 177 | .get_resource_list = &sun4u_get_resources,
|
---|
| 178 | .enable_interrupt = &sun4u_enable_interrupt,
|
---|
| 179 | };
|
---|
| 180 |
|
---|
| 181 | static pio_window_ops_t fun_pio_window_ops = {
|
---|
| 182 | .get_pio_window = &sun4u_get_pio_window
|
---|
| 183 | };
|
---|
| 184 |
|
---|
| 185 | /* Initialized in sun4u_init() function. */
|
---|
| 186 | static ddf_dev_ops_t sun4u_fun_ops;
|
---|
| 187 |
|
---|
| 188 | static bool
|
---|
| 189 | sun4u_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id,
|
---|
| 190 | sun4u_fun_t *fun_proto)
|
---|
| 191 | {
|
---|
| 192 | ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
|
---|
[a35b458] | 193 |
|
---|
[9191607] | 194 | ddf_fun_t *fnode = NULL;
|
---|
[b7fd2a0] | 195 | errno_t rc;
|
---|
[a35b458] | 196 |
|
---|
[9191607] | 197 | /* Create new device. */
|
---|
| 198 | fnode = ddf_fun_create(dev, fun_inner, name);
|
---|
| 199 | if (fnode == NULL)
|
---|
| 200 | goto failure;
|
---|
[a35b458] | 201 |
|
---|
[9191607] | 202 | sun4u_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(sun4u_fun_t));
|
---|
| 203 | *fun = *fun_proto;
|
---|
[a35b458] | 204 |
|
---|
[9191607] | 205 | /* Add match ID */
|
---|
| 206 | rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
|
---|
| 207 | if (rc != EOK)
|
---|
| 208 | goto failure;
|
---|
[a35b458] | 209 |
|
---|
[9191607] | 210 | /* Set provided operations to the device. */
|
---|
| 211 | ddf_fun_set_ops(fnode, &sun4u_fun_ops);
|
---|
[a35b458] | 212 |
|
---|
[9191607] | 213 | /* Register function. */
|
---|
| 214 | if (ddf_fun_bind(fnode) != EOK) {
|
---|
| 215 | ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
|
---|
| 216 | goto failure;
|
---|
| 217 | }
|
---|
[a35b458] | 218 |
|
---|
[9191607] | 219 | return true;
|
---|
[a35b458] | 220 |
|
---|
[9191607] | 221 | failure:
|
---|
| 222 | if (fnode != NULL)
|
---|
| 223 | ddf_fun_destroy(fnode);
|
---|
[a35b458] | 224 |
|
---|
[9191607] | 225 | ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
|
---|
[a35b458] | 226 |
|
---|
[9191607] | 227 | return false;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | static bool sun4u_add_functions(ddf_dev_t *dev)
|
---|
| 231 | {
|
---|
[be1b1e68] | 232 | if (!sun4u_add_fun(dev, "obio", "ebus/obio", &obio_data))
|
---|
| 233 | return false;
|
---|
| 234 |
|
---|
[9191607] | 235 | return sun4u_add_fun(dev, "pci0", "intel_pci", &pci_data);
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | /** Get the root device.
|
---|
| 239 | *
|
---|
| 240 | * @param dev The device which is root of the whole device tree (both
|
---|
| 241 | * of HW and pseudo devices).
|
---|
[cde999a] | 242 | * @return Zero on success, error number otherwise.
|
---|
[9191607] | 243 | */
|
---|
[b7fd2a0] | 244 | static errno_t sun4u_dev_add(ddf_dev_t *dev)
|
---|
[9191607] | 245 | {
|
---|
| 246 | ddf_msg(LVL_DEBUG, "sun4u_dev_add, device handle = %d",
|
---|
| 247 | (int)ddf_dev_get_handle(dev));
|
---|
| 248 |
|
---|
| 249 | /* Register functions. */
|
---|
| 250 | if (!sun4u_add_functions(dev)) {
|
---|
| 251 | ddf_msg(LVL_ERROR, "Failed to add functions for the Malta platform.");
|
---|
| 252 | }
|
---|
[a35b458] | 253 |
|
---|
[9191607] | 254 | return EOK;
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | static void sun4u_init(void)
|
---|
| 258 | {
|
---|
| 259 | ddf_log_init(NAME);
|
---|
| 260 | sun4u_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
|
---|
| 261 | sun4u_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | int main(int argc, char *argv[])
|
---|
| 265 | {
|
---|
| 266 | printf(NAME ": HelenOS sun4u platform driver\n");
|
---|
| 267 | sun4u_init();
|
---|
| 268 | return ddf_driver_main(&sun4u_driver);
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | /**
|
---|
| 272 | * @}
|
---|
| 273 | */
|
---|