[892e4e1] | 1 | /*
|
---|
[832cbe7] | 2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
[892e4e1] | 3 | * Copyright (c) 2010 Lenka Trochtova
|
---|
[ec388d7] | 4 | * Copyright (c) 2011 Jan Vesely
|
---|
[892e4e1] | 5 | * All rights reserved.
|
---|
| 6 | *
|
---|
| 7 | * Redistribution and use in source and binary forms, with or without
|
---|
| 8 | * modification, are permitted provided that the following conditions
|
---|
| 9 | * are met:
|
---|
| 10 | *
|
---|
| 11 | * - Redistributions of source code must retain the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
---|
| 13 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 14 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 15 | * documentation and/or other materials provided with the distribution.
|
---|
| 16 | * - The name of the author may not be used to endorse or promote products
|
---|
| 17 | * derived from this software without specific prior written permission.
|
---|
| 18 | *
|
---|
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | /**
|
---|
[4122410] | 32 | * @addtogroup isa
|
---|
[892e4e1] | 33 | * @{
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | /** @file
|
---|
| 37 | */
|
---|
| 38 |
|
---|
[f278930] | 39 | #include <adt/list.h>
|
---|
[892e4e1] | 40 | #include <assert.h>
|
---|
| 41 | #include <stdio.h>
|
---|
| 42 | #include <errno.h>
|
---|
[3e6a98c5] | 43 | #include <stdbool.h>
|
---|
[892e4e1] | 44 | #include <fibril_synch.h>
|
---|
| 45 | #include <stdlib.h>
|
---|
[c47e1a8] | 46 | #include <str.h>
|
---|
[cd0684d] | 47 | #include <str_error.h>
|
---|
[892e4e1] | 48 | #include <ctype.h>
|
---|
| 49 | #include <macros.h>
|
---|
[38d150e] | 50 | #include <stdlib.h>
|
---|
[c1a8ae52] | 51 | #include <dirent.h>
|
---|
[5960b48] | 52 | #include <ipc/irc.h>
|
---|
| 53 | #include <ipc/services.h>
|
---|
[23a0368] | 54 | #include <vfs/vfs.h>
|
---|
[ebc9c2c] | 55 | #include <irc.h>
|
---|
[1a11a16] | 56 | #include <ns.h>
|
---|
[892e4e1] | 57 |
|
---|
[af6b5157] | 58 | #include <ddf/driver.h>
|
---|
[fc51296] | 59 | #include <ddf/log.h>
|
---|
[41b56084] | 60 | #include <ops/hw_res.h>
|
---|
[ff97957] | 61 | #include <ops/pio_window.h>
|
---|
[5dc9622] | 62 |
|
---|
| 63 | #include <device/hw_res.h>
|
---|
[0a428943] | 64 | #include <device/pio_window.h>
|
---|
[892e4e1] | 65 |
|
---|
[3c5b86c] | 66 | #include <pci_dev_iface.h>
|
---|
| 67 |
|
---|
[d9cf684a] | 68 | #include "i8237.h"
|
---|
[ec388d7] | 69 |
|
---|
[892e4e1] | 70 | #define NAME "isa"
|
---|
[3c5b86c] | 71 | #define ISA_CHILD_FUN_CONF_PATH "/drv/isa/isa.dev"
|
---|
| 72 | #define EBUS_CHILD_FUN_CONF_PATH "/drv/isa/ebus.dev"
|
---|
[892e4e1] | 73 |
|
---|
[646849b3] | 74 | #define ISA_MAX_HW_RES 6
|
---|
[5dc9622] | 75 |
|
---|
[f278930] | 76 | typedef struct {
|
---|
| 77 | fibril_mutex_t mutex;
|
---|
[443695e] | 78 | bool pci_isa_bridge;
|
---|
[7e9e652] | 79 | uint16_t pci_vendor_id;
|
---|
| 80 | uint16_t pci_device_id;
|
---|
| 81 | uint8_t pci_class;
|
---|
| 82 | uint8_t pci_subclass;
|
---|
[f278930] | 83 | ddf_dev_t *dev;
|
---|
| 84 | ddf_fun_t *fctl;
|
---|
[0a428943] | 85 | pio_window_t pio_win;
|
---|
[f278930] | 86 | list_t functions;
|
---|
| 87 | } isa_bus_t;
|
---|
| 88 |
|
---|
[68414f4a] | 89 | typedef struct isa_fun {
|
---|
[f278930] | 90 | fibril_mutex_t mutex;
|
---|
[83a2f43] | 91 | ddf_fun_t *fnode;
|
---|
[85c4cc45] | 92 | hw_resource_t resources[ISA_MAX_HW_RES];
|
---|
[032e0bb] | 93 | hw_resource_list_t hw_resources;
|
---|
[f278930] | 94 | link_t bus_link;
|
---|
[443695e] | 95 | isa_bus_t *bus;
|
---|
[68414f4a] | 96 | } isa_fun_t;
|
---|
[5dc9622] | 97 |
|
---|
[56fd7cf] | 98 | /** Obtain soft-state from device node */
|
---|
| 99 | static isa_bus_t *isa_bus(ddf_dev_t *dev)
|
---|
| 100 | {
|
---|
| 101 | return ddf_dev_data_get(dev);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /** Obtain soft-state from function node */
|
---|
| 105 | static isa_fun_t *isa_fun(ddf_fun_t *fun)
|
---|
| 106 | {
|
---|
| 107 | return ddf_fun_data_get(fun);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[ff97957] | 110 | static hw_resource_list_t *isa_fun_get_resources(ddf_fun_t *fnode)
|
---|
[5dc9622] | 111 | {
|
---|
[ff97957] | 112 | isa_fun_t *fun = isa_fun(fnode);
|
---|
| 113 | assert(fun);
|
---|
[032e0bb] | 114 |
|
---|
[ff97957] | 115 | return &fun->hw_resources;
|
---|
[5dc9622] | 116 | }
|
---|
| 117 |
|
---|
[d51838f] | 118 | static bool isa_fun_owns_interrupt(isa_fun_t *fun, int irq)
|
---|
[5dc9622] | 119 | {
|
---|
[ff97957] | 120 | const hw_resource_list_t *res = &fun->hw_resources;
|
---|
[1a11a16] | 121 |
|
---|
[cccd60c3] | 122 | /* Check that specified irq really belongs to the function */
|
---|
| 123 | for (size_t i = 0; i < res->count; ++i) {
|
---|
| 124 | if (res->resources[i].type == INTERRUPT &&
|
---|
| 125 | res->resources[i].res.interrupt.irq == irq) {
|
---|
[d51838f] | 126 | return true;
|
---|
[1a11a16] | 127 | }
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[d51838f] | 130 | return false;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[b7fd2a0] | 133 | static errno_t isa_fun_enable_interrupt(ddf_fun_t *fnode, int irq)
|
---|
[d51838f] | 134 | {
|
---|
| 135 | isa_fun_t *fun = isa_fun(fnode);
|
---|
| 136 |
|
---|
| 137 | if (!isa_fun_owns_interrupt(fun, irq))
|
---|
[cccd60c3] | 138 | return EINVAL;
|
---|
| 139 |
|
---|
| 140 | return irc_enable_interrupt(irq);
|
---|
[5dc9622] | 141 | }
|
---|
| 142 |
|
---|
[b7fd2a0] | 143 | static errno_t isa_fun_disable_interrupt(ddf_fun_t *fnode, int irq)
|
---|
[d51838f] | 144 | {
|
---|
| 145 | isa_fun_t *fun = isa_fun(fnode);
|
---|
| 146 |
|
---|
| 147 | if (!isa_fun_owns_interrupt(fun, irq))
|
---|
| 148 | return EINVAL;
|
---|
| 149 |
|
---|
| 150 | return irc_disable_interrupt(irq);
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[b7fd2a0] | 153 | static errno_t isa_fun_clear_interrupt(ddf_fun_t *fnode, int irq)
|
---|
[d51838f] | 154 | {
|
---|
| 155 | isa_fun_t *fun = isa_fun(fnode);
|
---|
| 156 |
|
---|
| 157 | if (!isa_fun_owns_interrupt(fun, irq))
|
---|
| 158 | return EINVAL;
|
---|
| 159 |
|
---|
| 160 | return irc_clear_interrupt(irq);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[b7fd2a0] | 163 | static errno_t isa_fun_setup_dma(ddf_fun_t *fnode,
|
---|
[301032a] | 164 | unsigned int channel, uint32_t pa, uint32_t size, uint8_t mode)
|
---|
[ec388d7] | 165 | {
|
---|
| 166 | assert(fnode);
|
---|
[ff97957] | 167 | isa_fun_t *fun = isa_fun(fnode);
|
---|
| 168 | assert(fun);
|
---|
| 169 | const hw_resource_list_t *res = &fun->hw_resources;
|
---|
[ec388d7] | 170 | assert(res);
|
---|
[03362fbd] | 171 |
|
---|
[ec388d7] | 172 | for (size_t i = 0; i < res->count; ++i) {
|
---|
[1ec394e] | 173 | /* Check for assigned channel */
|
---|
[d9cf684a] | 174 | if (((res->resources[i].type == DMA_CHANNEL_16) &&
|
---|
[1ec394e] | 175 | (res->resources[i].res.dma_channel.dma16 == channel)) ||
|
---|
[d9cf684a] | 176 | ((res->resources[i].type == DMA_CHANNEL_8) &&
|
---|
[1ec394e] | 177 | (res->resources[i].res.dma_channel.dma8 == channel))) {
|
---|
| 178 | return dma_channel_setup(channel, pa, size, mode);
|
---|
[ec388d7] | 179 | }
|
---|
| 180 | }
|
---|
[03362fbd] | 181 |
|
---|
[ec388d7] | 182 | return EINVAL;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
[b7fd2a0] | 185 | static errno_t isa_fun_remain_dma(ddf_fun_t *fnode,
|
---|
[3869c596] | 186 | unsigned channel, size_t *size)
|
---|
[1864948] | 187 | {
|
---|
| 188 | assert(size);
|
---|
| 189 | assert(fnode);
|
---|
[ff97957] | 190 | isa_fun_t *fun = isa_fun(fnode);
|
---|
| 191 | assert(fun);
|
---|
| 192 | const hw_resource_list_t *res = &fun->hw_resources;
|
---|
[1864948] | 193 | assert(res);
|
---|
[03362fbd] | 194 |
|
---|
[1864948] | 195 | for (size_t i = 0; i < res->count; ++i) {
|
---|
| 196 | /* Check for assigned channel */
|
---|
| 197 | if (((res->resources[i].type == DMA_CHANNEL_16) &&
|
---|
| 198 | (res->resources[i].res.dma_channel.dma16 == channel)) ||
|
---|
| 199 | ((res->resources[i].type == DMA_CHANNEL_8) &&
|
---|
| 200 | (res->resources[i].res.dma_channel.dma8 == channel))) {
|
---|
| 201 | return dma_channel_remain(channel, size);
|
---|
| 202 | }
|
---|
| 203 | }
|
---|
[03362fbd] | 204 |
|
---|
[1864948] | 205 | return EINVAL;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
[832cbe7] | 208 | /** Handle legacy IO availability query from function.
|
---|
| 209 | *
|
---|
| 210 | * @param fnode Function performing the query
|
---|
| 211 | * @param rclaims Place to store the legacy IO claims bitmask
|
---|
| 212 | * @return EOK on success or an error code
|
---|
| 213 | */
|
---|
| 214 | static errno_t isa_fun_query_legacy_io(ddf_fun_t *fnode,
|
---|
| 215 | hw_res_claims_t *rclaims)
|
---|
[443695e] | 216 | {
|
---|
| 217 | isa_fun_t *fun = isa_fun(fnode);
|
---|
[832cbe7] | 218 | hw_res_claims_t claims;
|
---|
| 219 | async_sess_t *sess;
|
---|
| 220 | errno_t rc;
|
---|
[443695e] | 221 |
|
---|
[832cbe7] | 222 | ddf_msg(LVL_DEBUG, "isa_fun_query_legacy_io()");
|
---|
| 223 |
|
---|
| 224 | sess = ddf_dev_parent_sess_get(fun->bus->dev);
|
---|
| 225 | if (sess == NULL) {
|
---|
| 226 | ddf_msg(LVL_ERROR, "isa_dev_add failed to connect to the "
|
---|
| 227 | "parent driver.");
|
---|
| 228 | return ENOENT;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | if (!fun->bus->pci_isa_bridge) {
|
---|
| 232 | ddf_msg(LVL_NOTE, "isa_fun_query_legacy_io: classic ISA - "
|
---|
| 233 | "legacy IDE range is available");
|
---|
| 234 | /* Classic ISA, we can be sure IDE is unclaimed by PCI */
|
---|
| 235 | claims = 0;
|
---|
| 236 | } else {
|
---|
| 237 | ddf_msg(LVL_NOTE, "isa_fun_query_legacy_io: ISA bridge - "
|
---|
| 238 | "determine legacy IDE availability from PCI bus driver");
|
---|
| 239 | rc = hw_res_query_legacy_io(sess, &claims);
|
---|
| 240 | if (rc != EOK) {
|
---|
| 241 | ddf_msg(LVL_NOTE, "Error querying legacy IO claims.");
|
---|
| 242 | return rc;
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
[443695e] | 245 |
|
---|
[832cbe7] | 246 | ddf_msg(LVL_DEBUG, "isa_fun_query_legacy_io: returning 0x%x", claims);
|
---|
| 247 | *rclaims = claims;
|
---|
[443695e] | 248 | return EOK;
|
---|
| 249 | }
|
---|
| 250 |
|
---|
[8b1e15ac] | 251 | static hw_res_ops_t isa_fun_hw_res_ops = {
|
---|
[ff97957] | 252 | .get_resource_list = isa_fun_get_resources,
|
---|
[bc6762f] | 253 | .enable_interrupt = isa_fun_enable_interrupt,
|
---|
[d51838f] | 254 | .disable_interrupt = isa_fun_disable_interrupt,
|
---|
| 255 | .clear_interrupt = isa_fun_clear_interrupt,
|
---|
[bc6762f] | 256 | .dma_channel_setup = isa_fun_setup_dma,
|
---|
[1864948] | 257 | .dma_channel_remain = isa_fun_remain_dma,
|
---|
[832cbe7] | 258 | .query_legacy_io = isa_fun_query_legacy_io
|
---|
[5dc9622] | 259 | };
|
---|
| 260 |
|
---|
[ff97957] | 261 | static pio_window_t *isa_fun_get_pio_window(ddf_fun_t *fnode)
|
---|
| 262 | {
|
---|
| 263 | ddf_dev_t *dev = ddf_fun_get_dev(fnode);
|
---|
| 264 | isa_bus_t *isa = isa_bus(dev);
|
---|
| 265 | assert(isa);
|
---|
| 266 |
|
---|
| 267 | return &isa->pio_win;
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | static pio_window_ops_t isa_fun_pio_window_ops = {
|
---|
| 271 | .get_pio_window = isa_fun_get_pio_window
|
---|
| 272 | };
|
---|
| 273 |
|
---|
[1433ecda] | 274 | static ddf_dev_ops_t isa_fun_ops = {
|
---|
[b28dabe] | 275 | .interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops,
|
---|
[ff97957] | 276 | .interfaces[PIO_WINDOW_DEV_IFACE] = &isa_fun_pio_window_ops,
|
---|
[b28dabe] | 277 | };
|
---|
[5dc9622] | 278 |
|
---|
[b7fd2a0] | 279 | static errno_t isa_dev_add(ddf_dev_t *dev);
|
---|
| 280 | static errno_t isa_dev_remove(ddf_dev_t *dev);
|
---|
| 281 | static errno_t isa_fun_online(ddf_fun_t *fun);
|
---|
| 282 | static errno_t isa_fun_offline(ddf_fun_t *fun);
|
---|
[892e4e1] | 283 |
|
---|
[032e0bb] | 284 | /** The isa device driver's standard operations */
|
---|
[892e4e1] | 285 | static driver_ops_t isa_ops = {
|
---|
[0c0f823b] | 286 | .dev_add = &isa_dev_add,
|
---|
[f278930] | 287 | .dev_remove = &isa_dev_remove,
|
---|
[5b68e0c] | 288 | .fun_online = &isa_fun_online,
|
---|
| 289 | .fun_offline = &isa_fun_offline
|
---|
[892e4e1] | 290 | };
|
---|
| 291 |
|
---|
[032e0bb] | 292 | /** The isa device driver structure. */
|
---|
[892e4e1] | 293 | static driver_t isa_driver = {
|
---|
| 294 | .name = NAME,
|
---|
| 295 | .driver_ops = &isa_ops
|
---|
| 296 | };
|
---|
| 297 |
|
---|
[f278930] | 298 | static isa_fun_t *isa_fun_create(isa_bus_t *isa, const char *name)
|
---|
[c1a8ae52] | 299 | {
|
---|
[f278930] | 300 | ddf_fun_t *fnode = ddf_fun_create(isa->dev, fun_inner, name);
|
---|
| 301 | if (fnode == NULL)
|
---|
[c1a8ae52] | 302 | return NULL;
|
---|
[032e0bb] | 303 |
|
---|
[f278930] | 304 | isa_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(isa_fun_t));
|
---|
[0bbd13e] | 305 | if (fun == NULL) {
|
---|
| 306 | ddf_fun_destroy(fnode);
|
---|
[c1a8ae52] | 307 | return NULL;
|
---|
[0bbd13e] | 308 | }
|
---|
[032e0bb] | 309 |
|
---|
[f278930] | 310 | fibril_mutex_initialize(&fun->mutex);
|
---|
[85c4cc45] | 311 | fun->hw_resources.resources = fun->resources;
|
---|
[443695e] | 312 | fun->bus = isa;
|
---|
[85c4cc45] | 313 |
|
---|
[68414f4a] | 314 | fun->fnode = fnode;
|
---|
[8b1e15ac] | 315 | return fun;
|
---|
[c1a8ae52] | 316 | }
|
---|
| 317 |
|
---|
[68414f4a] | 318 | static char *fun_conf_read(const char *conf_path)
|
---|
[032e0bb] | 319 | {
|
---|
| 320 | bool suc = false;
|
---|
[c1a8ae52] | 321 | char *buf = NULL;
|
---|
| 322 | bool opened = false;
|
---|
[032e0bb] | 323 | int fd;
|
---|
[6efd162] | 324 | size_t len;
|
---|
[b7fd2a0] | 325 | errno_t rc;
|
---|
[8e3498b] | 326 | size_t nread;
|
---|
[39330200] | 327 | vfs_stat_t st;
|
---|
[032e0bb] | 328 |
|
---|
[f77c1c9] | 329 | rc = vfs_lookup_open(conf_path, WALK_REGULAR, MODE_READ, &fd);
|
---|
| 330 | if (rc != EOK) {
|
---|
[ebcb05a] | 331 | ddf_msg(LVL_ERROR, "Unable to open %s", conf_path);
|
---|
[c1a8ae52] | 332 | goto cleanup;
|
---|
[032e0bb] | 333 | }
|
---|
| 334 |
|
---|
| 335 | opened = true;
|
---|
| 336 |
|
---|
[23a0368] | 337 | if (vfs_stat(fd, &st) != EOK) {
|
---|
| 338 | ddf_msg(LVL_ERROR, "Unable to vfs_stat %d", fd);
|
---|
[58898d1d] | 339 | goto cleanup;
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | len = st.size;
|
---|
[6efd162] | 343 | if (len == 0) {
|
---|
[ebcb05a] | 344 | ddf_msg(LVL_ERROR, "Configuration file '%s' is empty.",
|
---|
[fc51296] | 345 | conf_path);
|
---|
[032e0bb] | 346 | goto cleanup;
|
---|
[c1a8ae52] | 347 | }
|
---|
[032e0bb] | 348 |
|
---|
[6efd162] | 349 | buf = malloc(len + 1);
|
---|
[c1a8ae52] | 350 | if (buf == NULL) {
|
---|
[ebcb05a] | 351 | ddf_msg(LVL_ERROR, "Memory allocation failed.");
|
---|
[c1a8ae52] | 352 | goto cleanup;
|
---|
[032e0bb] | 353 | }
|
---|
| 354 |
|
---|
[1433ecda] | 355 | rc = vfs_read(fd, (aoff64_t []) { 0 }, buf, len, &nread);
|
---|
[8e3498b] | 356 | if (rc != EOK) {
|
---|
[6efd162] | 357 | ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
|
---|
| 358 | goto cleanup;
|
---|
| 359 | }
|
---|
[032e0bb] | 360 |
|
---|
[8e3498b] | 361 | buf[nread] = 0;
|
---|
[032e0bb] | 362 |
|
---|
[c1a8ae52] | 363 | suc = true;
|
---|
[032e0bb] | 364 |
|
---|
[c1a8ae52] | 365 | cleanup:
|
---|
[032e0bb] | 366 | if (!suc && buf != NULL) {
|
---|
| 367 | free(buf);
|
---|
[c1a8ae52] | 368 | buf = NULL;
|
---|
| 369 | }
|
---|
[032e0bb] | 370 |
|
---|
| 371 | if (opened)
|
---|
[9c4cf0d] | 372 | vfs_put(fd);
|
---|
[032e0bb] | 373 |
|
---|
| 374 | return buf;
|
---|
[c1a8ae52] | 375 | }
|
---|
| 376 |
|
---|
[032e0bb] | 377 | static char *str_get_line(char *str, char **next)
|
---|
| 378 | {
|
---|
[5dc9622] | 379 | char *line = str;
|
---|
[cf56332] | 380 | *next = NULL;
|
---|
[032e0bb] | 381 |
|
---|
| 382 | if (str == NULL) {
|
---|
[f928a8a] | 383 | return NULL;
|
---|
| 384 | }
|
---|
[032e0bb] | 385 |
|
---|
| 386 | while (*str != '\0' && *str != '\n') {
|
---|
[5dc9622] | 387 | str++;
|
---|
[032e0bb] | 388 | }
|
---|
| 389 |
|
---|
| 390 | if (*str != '\0') {
|
---|
[5dc9622] | 391 | *next = str + 1;
|
---|
[032e0bb] | 392 | }
|
---|
| 393 |
|
---|
| 394 | *str = '\0';
|
---|
[5dc9622] | 395 | return line;
|
---|
[c1a8ae52] | 396 | }
|
---|
| 397 |
|
---|
| 398 | static bool line_empty(const char *line)
|
---|
| 399 | {
|
---|
[032e0bb] | 400 | while (line != NULL && *line != 0) {
|
---|
| 401 | if (!isspace(*line))
|
---|
[c1a8ae52] | 402 | return false;
|
---|
[032e0bb] | 403 | line++;
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | return true;
|
---|
[c1a8ae52] | 407 | }
|
---|
| 408 |
|
---|
[032e0bb] | 409 | static char *get_device_name(char *line)
|
---|
| 410 | {
|
---|
| 411 | /* Skip leading spaces. */
|
---|
| 412 | while (*line != '\0' && isspace(*line)) {
|
---|
[c1a8ae52] | 413 | line++;
|
---|
| 414 | }
|
---|
[032e0bb] | 415 |
|
---|
| 416 | /* Get the name part of the rest of the line. */
|
---|
[ee3f6f6] | 417 | str_tok(line, ":", NULL);
|
---|
[3d4ad475] | 418 | return line;
|
---|
[c1a8ae52] | 419 | }
|
---|
| 420 |
|
---|
[b5f305b] | 421 | static inline const char *skip_spaces(const char *line)
|
---|
[c1a8ae52] | 422 | {
|
---|
[032e0bb] | 423 | /* Skip leading spaces. */
|
---|
| 424 | while (*line != '\0' && isspace(*line))
|
---|
[c1a8ae52] | 425 | line++;
|
---|
| 426 |
|
---|
[032e0bb] | 427 | return line;
|
---|
| 428 | }
|
---|
[c1a8ae52] | 429 |
|
---|
[82e4005] | 430 | static void isa_fun_add_irq(isa_fun_t *fun, int irq)
|
---|
[c1a8ae52] | 431 | {
|
---|
[68414f4a] | 432 | size_t count = fun->hw_resources.count;
|
---|
| 433 | hw_resource_t *resources = fun->hw_resources.resources;
|
---|
[032e0bb] | 434 |
|
---|
[5dc9622] | 435 | if (count < ISA_MAX_HW_RES) {
|
---|
| 436 | resources[count].type = INTERRUPT;
|
---|
| 437 | resources[count].res.interrupt.irq = irq;
|
---|
[032e0bb] | 438 |
|
---|
[68414f4a] | 439 | fun->hw_resources.count++;
|
---|
[032e0bb] | 440 |
|
---|
[ebcb05a] | 441 | ddf_msg(LVL_NOTE, "Added irq 0x%x to function %s", irq,
|
---|
[56fd7cf] | 442 | ddf_fun_get_name(fun->fnode));
|
---|
[032e0bb] | 443 | }
|
---|
[5dc9622] | 444 | }
|
---|
| 445 |
|
---|
[82e4005] | 446 | static void isa_fun_add_dma(isa_fun_t *fun, int dma)
|
---|
[55a8e0cb] | 447 | {
|
---|
| 448 | size_t count = fun->hw_resources.count;
|
---|
| 449 | hw_resource_t *resources = fun->hw_resources.resources;
|
---|
[a35b458] | 450 |
|
---|
[55a8e0cb] | 451 | if (count < ISA_MAX_HW_RES) {
|
---|
[d9cf684a] | 452 | if ((dma > 0) && (dma < 4)) {
|
---|
[55a8e0cb] | 453 | resources[count].type = DMA_CHANNEL_8;
|
---|
| 454 | resources[count].res.dma_channel.dma8 = dma;
|
---|
[a35b458] | 455 |
|
---|
[55a8e0cb] | 456 | fun->hw_resources.count++;
|
---|
| 457 | ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma,
|
---|
[56fd7cf] | 458 | ddf_fun_get_name(fun->fnode));
|
---|
[a35b458] | 459 |
|
---|
[55a8e0cb] | 460 | return;
|
---|
| 461 | }
|
---|
| 462 |
|
---|
[d9cf684a] | 463 | if ((dma > 4) && (dma < 8)) {
|
---|
[55a8e0cb] | 464 | resources[count].type = DMA_CHANNEL_16;
|
---|
| 465 | resources[count].res.dma_channel.dma16 = dma;
|
---|
[a35b458] | 466 |
|
---|
[55a8e0cb] | 467 | fun->hw_resources.count++;
|
---|
| 468 | ddf_msg(LVL_NOTE, "Added dma 0x%x to function %s", dma,
|
---|
[56fd7cf] | 469 | ddf_fun_get_name(fun->fnode));
|
---|
[a35b458] | 470 |
|
---|
[55a8e0cb] | 471 | return;
|
---|
| 472 | }
|
---|
[a35b458] | 473 |
|
---|
[55a8e0cb] | 474 | ddf_msg(LVL_WARN, "Skipped dma 0x%x for function %s", dma,
|
---|
[56fd7cf] | 475 | ddf_fun_get_name(fun->fnode));
|
---|
[55a8e0cb] | 476 | }
|
---|
| 477 | }
|
---|
| 478 |
|
---|
[82e4005] | 479 | static void isa_fun_add_io_range(isa_fun_t *fun, size_t addr, size_t len)
|
---|
[5dc9622] | 480 | {
|
---|
[68414f4a] | 481 | size_t count = fun->hw_resources.count;
|
---|
| 482 | hw_resource_t *resources = fun->hw_resources.resources;
|
---|
[032e0bb] | 483 |
|
---|
[0a428943] | 484 | isa_bus_t *isa = isa_bus(ddf_fun_get_dev(fun->fnode));
|
---|
| 485 |
|
---|
[5dc9622] | 486 | if (count < ISA_MAX_HW_RES) {
|
---|
| 487 | resources[count].type = IO_RANGE;
|
---|
| 488 | resources[count].res.io_range.address = addr;
|
---|
[0a428943] | 489 | resources[count].res.io_range.address += isa->pio_win.io.base;
|
---|
[5dc9622] | 490 | resources[count].res.io_range.size = len;
|
---|
[9e470c0] | 491 | resources[count].res.io_range.relative = false;
|
---|
[032e0bb] | 492 | resources[count].res.io_range.endianness = LITTLE_ENDIAN;
|
---|
| 493 |
|
---|
[68414f4a] | 494 | fun->hw_resources.count++;
|
---|
[032e0bb] | 495 |
|
---|
[fc51296] | 496 | ddf_msg(LVL_NOTE, "Added io range (addr=0x%x, size=0x%x) to "
|
---|
[ebcb05a] | 497 | "function %s", (unsigned int) addr, (unsigned int) len,
|
---|
[56fd7cf] | 498 | ddf_fun_get_name(fun->fnode));
|
---|
[032e0bb] | 499 | }
|
---|
[c1a8ae52] | 500 | }
|
---|
| 501 |
|
---|
[b446b02] | 502 | static void isa_fun_add_mem_range(isa_fun_t *fun, uintptr_t addr, size_t len)
|
---|
| 503 | {
|
---|
| 504 | size_t count = fun->hw_resources.count;
|
---|
| 505 | hw_resource_t *resources = fun->hw_resources.resources;
|
---|
| 506 |
|
---|
| 507 | isa_bus_t *isa = isa_bus(ddf_fun_get_dev(fun->fnode));
|
---|
| 508 |
|
---|
| 509 | if (count < ISA_MAX_HW_RES) {
|
---|
| 510 | resources[count].type = MEM_RANGE;
|
---|
| 511 | resources[count].res.mem_range.address = addr;
|
---|
| 512 | resources[count].res.mem_range.address += isa->pio_win.mem.base;
|
---|
| 513 | resources[count].res.mem_range.size = len;
|
---|
[3d0fd0d] | 514 | resources[count].res.mem_range.relative = false;
|
---|
[b446b02] | 515 | resources[count].res.mem_range.endianness = LITTLE_ENDIAN;
|
---|
| 516 |
|
---|
| 517 | fun->hw_resources.count++;
|
---|
| 518 |
|
---|
| 519 | ddf_msg(LVL_NOTE, "Added mem range (addr=0x%zx, size=0x%x) to "
|
---|
| 520 | "function %s", (uintptr_t) addr, (unsigned int) len,
|
---|
| 521 | ddf_fun_get_name(fun->fnode));
|
---|
| 522 | }
|
---|
| 523 | }
|
---|
| 524 |
|
---|
[b5f305b] | 525 | static void fun_parse_irq(isa_fun_t *fun, const char *val)
|
---|
[c1a8ae52] | 526 | {
|
---|
| 527 | int irq = 0;
|
---|
| 528 | char *end = NULL;
|
---|
[032e0bb] | 529 |
|
---|
[8b1e15ac] | 530 | val = skip_spaces(val);
|
---|
[5cc9eba] | 531 | irq = (int) strtol(val, &end, 10);
|
---|
[032e0bb] | 532 |
|
---|
| 533 | if (val != end)
|
---|
[82e4005] | 534 | isa_fun_add_irq(fun, irq);
|
---|
[c1a8ae52] | 535 | }
|
---|
| 536 |
|
---|
[b5f305b] | 537 | static void fun_parse_dma(isa_fun_t *fun, const char *val)
|
---|
[55a8e0cb] | 538 | {
|
---|
| 539 | char *end = NULL;
|
---|
[a35b458] | 540 |
|
---|
[55a8e0cb] | 541 | val = skip_spaces(val);
|
---|
[1ec394e] | 542 | const int dma = strtol(val, &end, 10);
|
---|
[a35b458] | 543 |
|
---|
[55a8e0cb] | 544 | if (val != end)
|
---|
[82e4005] | 545 | isa_fun_add_dma(fun, dma);
|
---|
[55a8e0cb] | 546 | }
|
---|
| 547 |
|
---|
[b5f305b] | 548 | static void fun_parse_io_range(isa_fun_t *fun, const char *val)
|
---|
[c1a8ae52] | 549 | {
|
---|
[5dc9622] | 550 | size_t addr, len;
|
---|
| 551 | char *end = NULL;
|
---|
[032e0bb] | 552 |
|
---|
[8b1e15ac] | 553 | val = skip_spaces(val);
|
---|
[5dc9622] | 554 | addr = strtol(val, &end, 0x10);
|
---|
[032e0bb] | 555 |
|
---|
| 556 | if (val == end)
|
---|
[5dc9622] | 557 | return;
|
---|
[032e0bb] | 558 |
|
---|
[8b1e15ac] | 559 | val = skip_spaces(end);
|
---|
[5dc9622] | 560 | len = strtol(val, &end, 0x10);
|
---|
[032e0bb] | 561 |
|
---|
| 562 | if (val == end)
|
---|
[5dc9622] | 563 | return;
|
---|
[032e0bb] | 564 |
|
---|
[82e4005] | 565 | isa_fun_add_io_range(fun, addr, len);
|
---|
[c1a8ae52] | 566 | }
|
---|
| 567 |
|
---|
[b446b02] | 568 | static void fun_parse_mem_range(isa_fun_t *fun, const char *val)
|
---|
| 569 | {
|
---|
| 570 | uintptr_t addr;
|
---|
| 571 | size_t len;
|
---|
| 572 | char *end = NULL;
|
---|
| 573 |
|
---|
| 574 | val = skip_spaces(val);
|
---|
| 575 | addr = strtoul(val, &end, 0x10);
|
---|
| 576 |
|
---|
| 577 | if (val == end)
|
---|
| 578 | return;
|
---|
| 579 |
|
---|
| 580 | val = skip_spaces(end);
|
---|
| 581 | len = strtol(val, &end, 0x10);
|
---|
| 582 |
|
---|
| 583 | if (val == end)
|
---|
| 584 | return;
|
---|
| 585 |
|
---|
| 586 | isa_fun_add_mem_range(fun, addr, len);
|
---|
| 587 | }
|
---|
| 588 |
|
---|
[b5f305b] | 589 | static void get_match_id(char **id, const char *val)
|
---|
[c1a8ae52] | 590 | {
|
---|
[b5f305b] | 591 | const char *end = val;
|
---|
[032e0bb] | 592 |
|
---|
| 593 | while (!isspace(*end))
|
---|
[5dc9622] | 594 | end++;
|
---|
[032e0bb] | 595 |
|
---|
[f928a8a] | 596 | size_t size = end - val + 1;
|
---|
[5dc9622] | 597 | *id = (char *)malloc(size);
|
---|
[032e0bb] | 598 | str_cpy(*id, size, val);
|
---|
[5dc9622] | 599 | }
|
---|
| 600 |
|
---|
[b5f305b] | 601 | static void fun_parse_match_id(isa_fun_t *fun, const char *val)
|
---|
[032e0bb] | 602 | {
|
---|
[5dc9622] | 603 | char *id = NULL;
|
---|
| 604 | char *end = NULL;
|
---|
[032e0bb] | 605 |
|
---|
[68414f4a] | 606 | val = skip_spaces(val);
|
---|
[032e0bb] | 607 |
|
---|
[cf56332] | 608 | int score = (int)strtol(val, &end, 10);
|
---|
[5dc9622] | 609 | if (val == end) {
|
---|
[fc51296] | 610 | ddf_msg(LVL_ERROR, "Cannot read match score for function "
|
---|
[56fd7cf] | 611 | "%s.", ddf_fun_get_name(fun->fnode));
|
---|
[5dc9622] | 612 | return;
|
---|
| 613 | }
|
---|
[032e0bb] | 614 |
|
---|
[bab6388] | 615 | val = skip_spaces(end);
|
---|
[5dc9622] | 616 | get_match_id(&id, val);
|
---|
[032e0bb] | 617 | if (id == NULL) {
|
---|
[ebcb05a] | 618 | ddf_msg(LVL_ERROR, "Cannot read match ID for function %s.",
|
---|
[56fd7cf] | 619 | ddf_fun_get_name(fun->fnode));
|
---|
[5dc9622] | 620 | return;
|
---|
| 621 | }
|
---|
[032e0bb] | 622 |
|
---|
[fc51296] | 623 | ddf_msg(LVL_DEBUG, "Adding match id '%s' with score %d to "
|
---|
[56fd7cf] | 624 | "function %s", id, score, ddf_fun_get_name(fun->fnode));
|
---|
[cd0684d] | 625 |
|
---|
[b7fd2a0] | 626 | errno_t rc = ddf_fun_add_match_id(fun->fnode, id, score);
|
---|
[fc51296] | 627 | if (rc != EOK) {
|
---|
[ebcb05a] | 628 | ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
|
---|
[fc51296] | 629 | str_error(rc));
|
---|
| 630 | }
|
---|
[ef9460b] | 631 |
|
---|
| 632 | free(id);
|
---|
[c1a8ae52] | 633 | }
|
---|
| 634 |
|
---|
[b5f305b] | 635 | static bool prop_parse(isa_fun_t *fun, const char *line, const char *prop,
|
---|
| 636 | void (*read_fn)(isa_fun_t *, const char *))
|
---|
[5fe1c32] | 637 | {
|
---|
| 638 | size_t proplen = str_size(prop);
|
---|
[032e0bb] | 639 |
|
---|
| 640 | if (str_lcmp(line, prop, proplen) == 0) {
|
---|
[5fe1c32] | 641 | line += proplen;
|
---|
| 642 | line = skip_spaces(line);
|
---|
[8b1e15ac] | 643 | (*read_fn)(fun, line);
|
---|
[032e0bb] | 644 |
|
---|
[5fe1c32] | 645 | return true;
|
---|
| 646 | }
|
---|
[032e0bb] | 647 |
|
---|
| 648 | return false;
|
---|
[5fe1c32] | 649 | }
|
---|
| 650 |
|
---|
[b5f305b] | 651 | static void fun_prop_parse(isa_fun_t *fun, const char *line)
|
---|
[c1a8ae52] | 652 | {
|
---|
[032e0bb] | 653 | /* Skip leading spaces. */
|
---|
[c1a8ae52] | 654 | line = skip_spaces(line);
|
---|
[032e0bb] | 655 |
|
---|
[68414f4a] | 656 | if (!prop_parse(fun, line, "io_range", &fun_parse_io_range) &&
|
---|
[b446b02] | 657 | !prop_parse(fun, line, "mem_range", &fun_parse_mem_range) &&
|
---|
[68414f4a] | 658 | !prop_parse(fun, line, "irq", &fun_parse_irq) &&
|
---|
[55a8e0cb] | 659 | !prop_parse(fun, line, "dma", &fun_parse_dma) &&
|
---|
[fc51296] | 660 | !prop_parse(fun, line, "match", &fun_parse_match_id)) {
|
---|
| 661 |
|
---|
[ebcb05a] | 662 | ddf_msg(LVL_ERROR, "Undefined device property at line '%s'",
|
---|
[fc51296] | 663 | line);
|
---|
[032e0bb] | 664 | }
|
---|
[c1a8ae52] | 665 | }
|
---|
| 666 |
|
---|
[f278930] | 667 | static char *isa_fun_read_info(char *fun_conf, isa_bus_t *isa)
|
---|
[c1a8ae52] | 668 | {
|
---|
| 669 | char *line;
|
---|
[032e0bb] | 670 |
|
---|
| 671 | /* Skip empty lines. */
|
---|
[1de97fe6] | 672 | do {
|
---|
[8b1e15ac] | 673 | line = str_get_line(fun_conf, &fun_conf);
|
---|
[032e0bb] | 674 |
|
---|
| 675 | if (line == NULL) {
|
---|
| 676 | /* no more lines */
|
---|
[c1a8ae52] | 677 | return NULL;
|
---|
| 678 | }
|
---|
[032e0bb] | 679 |
|
---|
[1de97fe6] | 680 | } while (line_empty(line));
|
---|
[032e0bb] | 681 |
|
---|
| 682 | /* Get device name. */
|
---|
[3d4ad475] | 683 | const char *fun_name = get_device_name(line);
|
---|
[8b1e15ac] | 684 | if (fun_name == NULL)
|
---|
[c1a8ae52] | 685 | return NULL;
|
---|
[032e0bb] | 686 |
|
---|
[f278930] | 687 | isa_fun_t *fun = isa_fun_create(isa, fun_name);
|
---|
[8b1e15ac] | 688 | if (fun == NULL) {
|
---|
[c1a8ae52] | 689 | return NULL;
|
---|
| 690 | }
|
---|
[032e0bb] | 691 |
|
---|
| 692 | /* Get properties of the device (match ids, irq and io range). */
|
---|
| 693 | while (true) {
|
---|
[8b1e15ac] | 694 | line = str_get_line(fun_conf, &fun_conf);
|
---|
[032e0bb] | 695 |
|
---|
[5dc9622] | 696 | if (line_empty(line)) {
|
---|
[032e0bb] | 697 | /* no more device properties */
|
---|
[5dc9622] | 698 | break;
|
---|
| 699 | }
|
---|
[032e0bb] | 700 |
|
---|
| 701 | /*
|
---|
| 702 | * Get the device's property from the configuration line
|
---|
| 703 | * and store it in the device structure.
|
---|
| 704 | */
|
---|
[68414f4a] | 705 | fun_prop_parse(fun, line);
|
---|
[c1a8ae52] | 706 | }
|
---|
[032e0bb] | 707 |
|
---|
| 708 | /* Set device operations to the device. */
|
---|
[56fd7cf] | 709 | ddf_fun_set_ops(fun->fnode, &isa_fun_ops);
|
---|
[97a62fe] | 710 |
|
---|
[56fd7cf] | 711 | ddf_msg(LVL_DEBUG, "Binding function %s.", ddf_fun_get_name(fun->fnode));
|
---|
[032e0bb] | 712 |
|
---|
[97a62fe] | 713 | /* XXX Handle error */
|
---|
| 714 | (void) ddf_fun_bind(fun->fnode);
|
---|
[032e0bb] | 715 |
|
---|
[f278930] | 716 | list_append(&fun->bus_link, &isa->functions);
|
---|
| 717 |
|
---|
[8b1e15ac] | 718 | return fun_conf;
|
---|
[c1a8ae52] | 719 | }
|
---|
| 720 |
|
---|
[0d7eb0f] | 721 | static void isa_functions_add(isa_bus_t *isa)
|
---|
[c1a8ae52] | 722 | {
|
---|
[7e9e652] | 723 | #define BASE_CLASS_BRIDGE 0x06
|
---|
| 724 | #define SUB_CLASS_BRIDGE_ISA 0x01
|
---|
| 725 | bool isa_bridge = ((isa->pci_class == BASE_CLASS_BRIDGE) &&
|
---|
| 726 | (isa->pci_subclass == SUB_CLASS_BRIDGE_ISA));
|
---|
| 727 |
|
---|
[3c5b86c] | 728 | #define VENDOR_ID_SUN 0x108e
|
---|
| 729 | #define DEVICE_ID_EBUS 0x1000
|
---|
[7e9e652] | 730 | bool ebus = ((isa->pci_vendor_id == VENDOR_ID_SUN) &&
|
---|
| 731 | (isa->pci_device_id == DEVICE_ID_EBUS));
|
---|
[3c5b86c] | 732 |
|
---|
[7e9e652] | 733 | const char *conf_path = NULL;
|
---|
| 734 | if (isa_bridge)
|
---|
[3c5b86c] | 735 | conf_path = ISA_CHILD_FUN_CONF_PATH;
|
---|
[7e9e652] | 736 | else if (ebus)
|
---|
| 737 | conf_path = EBUS_CHILD_FUN_CONF_PATH;
|
---|
[3c5b86c] | 738 |
|
---|
| 739 | char *conf = fun_conf_read(conf_path);
|
---|
[032e0bb] | 740 | while (conf != NULL && *conf != '\0') {
|
---|
[f278930] | 741 | conf = isa_fun_read_info(conf, isa);
|
---|
[032e0bb] | 742 | }
|
---|
[0d7eb0f] | 743 | free(conf);
|
---|
[c1a8ae52] | 744 | }
|
---|
[892e4e1] | 745 |
|
---|
[b25970f] | 746 | static errno_t isa_read_pci_cfg(isa_bus_t *isa, async_sess_t *sess)
|
---|
| 747 | {
|
---|
| 748 | errno_t rc;
|
---|
| 749 |
|
---|
| 750 | rc = pci_config_space_read_16(sess, PCI_VENDOR_ID, &isa->pci_vendor_id);
|
---|
| 751 | if (rc != EOK)
|
---|
| 752 | return rc;
|
---|
| 753 | rc = pci_config_space_read_16(sess, PCI_DEVICE_ID, &isa->pci_device_id);
|
---|
| 754 | if (rc != EOK)
|
---|
| 755 | return rc;
|
---|
| 756 | rc = pci_config_space_read_8(sess, PCI_BASE_CLASS, &isa->pci_class);
|
---|
| 757 | if (rc != EOK)
|
---|
| 758 | return rc;
|
---|
| 759 | rc = pci_config_space_read_8(sess, PCI_SUB_CLASS, &isa->pci_subclass);
|
---|
| 760 | if (rc != EOK)
|
---|
| 761 | return rc;
|
---|
| 762 |
|
---|
| 763 | return EOK;
|
---|
| 764 | }
|
---|
| 765 |
|
---|
[b7fd2a0] | 766 | static errno_t isa_dev_add(ddf_dev_t *dev)
|
---|
[892e4e1] | 767 | {
|
---|
[0a428943] | 768 | async_sess_t *sess;
|
---|
[b7fd2a0] | 769 | errno_t rc;
|
---|
[0a428943] | 770 |
|
---|
[0c0f823b] | 771 | ddf_msg(LVL_DEBUG, "isa_dev_add, device handle = %d",
|
---|
[56fd7cf] | 772 | (int) ddf_dev_get_handle(dev));
|
---|
[032e0bb] | 773 |
|
---|
[cf56332] | 774 | isa_bus_t *isa = ddf_dev_data_alloc(dev, sizeof(isa_bus_t));
|
---|
[f278930] | 775 | if (isa == NULL)
|
---|
| 776 | return ENOMEM;
|
---|
| 777 |
|
---|
| 778 | fibril_mutex_initialize(&isa->mutex);
|
---|
| 779 | isa->dev = dev;
|
---|
| 780 | list_initialize(&isa->functions);
|
---|
| 781 |
|
---|
[2fd26bb] | 782 | sess = ddf_dev_parent_sess_get(dev);
|
---|
[0a428943] | 783 | if (sess == NULL) {
|
---|
| 784 | ddf_msg(LVL_ERROR, "isa_dev_add failed to connect to the "
|
---|
| 785 | "parent driver.");
|
---|
| 786 | return ENOENT;
|
---|
| 787 | }
|
---|
| 788 |
|
---|
[b25970f] | 789 | rc = isa_read_pci_cfg(isa, sess);
|
---|
| 790 | if (rc != EOK) {
|
---|
| 791 | ddf_msg(LVL_NOTE, "Cannot read PCI config. Assuming ISA classic.");
|
---|
[443695e] | 792 | isa->pci_isa_bridge = false;
|
---|
[b25970f] | 793 | isa->pci_vendor_id = 0;
|
---|
| 794 | isa->pci_device_id = 0;
|
---|
| 795 | isa->pci_class = BASE_CLASS_BRIDGE;
|
---|
| 796 | isa->pci_subclass = SUB_CLASS_BRIDGE_ISA;
|
---|
[443695e] | 797 | } else {
|
---|
| 798 | ddf_msg(LVL_NOTE, "ISA Bridge");
|
---|
| 799 | isa->pci_isa_bridge = true;
|
---|
[b25970f] | 800 | }
|
---|
[a35b458] | 801 |
|
---|
[0a428943] | 802 | rc = pio_window_get(sess, &isa->pio_win);
|
---|
| 803 | if (rc != EOK) {
|
---|
| 804 | ddf_msg(LVL_ERROR, "isa_dev_add failed to get PIO window "
|
---|
| 805 | "for the device.");
|
---|
| 806 | return rc;
|
---|
[1b20da0] | 807 | }
|
---|
[0a428943] | 808 |
|
---|
[8b1e15ac] | 809 | /* Make the bus device more visible. Does not do anything. */
|
---|
[ebcb05a] | 810 | ddf_msg(LVL_DEBUG, "Adding a 'ctl' function");
|
---|
[8b1e15ac] | 811 |
|
---|
[f278930] | 812 | fibril_mutex_lock(&isa->mutex);
|
---|
| 813 |
|
---|
| 814 | isa->fctl = ddf_fun_create(dev, fun_exposed, "ctl");
|
---|
| 815 | if (isa->fctl == NULL) {
|
---|
[ebcb05a] | 816 | ddf_msg(LVL_ERROR, "Failed creating control function.");
|
---|
[97a62fe] | 817 | return EXDEV;
|
---|
| 818 | }
|
---|
| 819 |
|
---|
[f278930] | 820 | if (ddf_fun_bind(isa->fctl) != EOK) {
|
---|
| 821 | ddf_fun_destroy(isa->fctl);
|
---|
[ebcb05a] | 822 | ddf_msg(LVL_ERROR, "Failed binding control function.");
|
---|
[97a62fe] | 823 | return EXDEV;
|
---|
| 824 | }
|
---|
[8b1e15ac] | 825 |
|
---|
[68414f4a] | 826 | /* Add functions as specified in the configuration file. */
|
---|
[f278930] | 827 | isa_functions_add(isa);
|
---|
[ebcb05a] | 828 | ddf_msg(LVL_NOTE, "Finished enumerating legacy functions");
|
---|
[032e0bb] | 829 |
|
---|
[f278930] | 830 | fibril_mutex_unlock(&isa->mutex);
|
---|
| 831 |
|
---|
| 832 | return EOK;
|
---|
| 833 | }
|
---|
| 834 |
|
---|
[b7fd2a0] | 835 | static errno_t isa_dev_remove(ddf_dev_t *dev)
|
---|
[f278930] | 836 | {
|
---|
[56fd7cf] | 837 | isa_bus_t *isa = isa_bus(dev);
|
---|
[f278930] | 838 |
|
---|
| 839 | fibril_mutex_lock(&isa->mutex);
|
---|
| 840 |
|
---|
| 841 | while (!list_empty(&isa->functions)) {
|
---|
| 842 | isa_fun_t *fun = list_get_instance(list_first(&isa->functions),
|
---|
| 843 | isa_fun_t, bus_link);
|
---|
| 844 |
|
---|
[b7fd2a0] | 845 | errno_t rc = ddf_fun_offline(fun->fnode);
|
---|
[f278930] | 846 | if (rc != EOK) {
|
---|
| 847 | fibril_mutex_unlock(&isa->mutex);
|
---|
[56fd7cf] | 848 | ddf_msg(LVL_ERROR, "Failed offlining %s", ddf_fun_get_name(fun->fnode));
|
---|
[f278930] | 849 | return rc;
|
---|
| 850 | }
|
---|
| 851 |
|
---|
| 852 | rc = ddf_fun_unbind(fun->fnode);
|
---|
| 853 | if (rc != EOK) {
|
---|
| 854 | fibril_mutex_unlock(&isa->mutex);
|
---|
[56fd7cf] | 855 | ddf_msg(LVL_ERROR, "Failed unbinding %s", ddf_fun_get_name(fun->fnode));
|
---|
[f278930] | 856 | return rc;
|
---|
| 857 | }
|
---|
| 858 |
|
---|
| 859 | list_remove(&fun->bus_link);
|
---|
| 860 |
|
---|
| 861 | ddf_fun_destroy(fun->fnode);
|
---|
| 862 | }
|
---|
| 863 |
|
---|
| 864 | if (ddf_fun_unbind(isa->fctl) != EOK) {
|
---|
| 865 | fibril_mutex_unlock(&isa->mutex);
|
---|
| 866 | ddf_msg(LVL_ERROR, "Failed unbinding control function.");
|
---|
| 867 | return EXDEV;
|
---|
| 868 | }
|
---|
| 869 |
|
---|
| 870 | fibril_mutex_unlock(&isa->mutex);
|
---|
| 871 |
|
---|
[df747b9c] | 872 | return EOK;
|
---|
[892e4e1] | 873 | }
|
---|
| 874 |
|
---|
[b7fd2a0] | 875 | static errno_t isa_fun_online(ddf_fun_t *fun)
|
---|
[5b68e0c] | 876 | {
|
---|
| 877 | ddf_msg(LVL_DEBUG, "isa_fun_online()");
|
---|
| 878 | return ddf_fun_online(fun);
|
---|
| 879 | }
|
---|
| 880 |
|
---|
[b7fd2a0] | 881 | static errno_t isa_fun_offline(ddf_fun_t *fun)
|
---|
[5b68e0c] | 882 | {
|
---|
| 883 | ddf_msg(LVL_DEBUG, "isa_fun_offline()");
|
---|
| 884 | return ddf_fun_offline(fun);
|
---|
| 885 | }
|
---|
| 886 |
|
---|
[892e4e1] | 887 | int main(int argc, char *argv[])
|
---|
| 888 | {
|
---|
[032e0bb] | 889 | printf(NAME ": HelenOS ISA bus driver\n");
|
---|
[03362fbd] | 890 | ddf_log_init(NAME);
|
---|
[83a2f43] | 891 | return ddf_driver_main(&isa_driver);
|
---|
[892e4e1] | 892 | }
|
---|
| 893 |
|
---|
| 894 | /**
|
---|
| 895 | * @}
|
---|
| 896 | */
|
---|