[b446b02] | 1 | /*
|
---|
| 2 | * Copyright (c) 2017 Jiri Svoboda
|
---|
| 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 |
|
---|
[c8ea6eca] | 29 | /** @addtogroup i8259
|
---|
[b446b02] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file i8259 Interrupt Controller driver
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <ddf/driver.h>
|
---|
| 36 | #include <ddf/log.h>
|
---|
| 37 | #include <device/hw_res_parsed.h>
|
---|
| 38 | #include <errno.h>
|
---|
| 39 | #include <stdio.h>
|
---|
| 40 |
|
---|
| 41 | #include "i8259.h"
|
---|
| 42 |
|
---|
| 43 | #define NAME "i8259"
|
---|
| 44 |
|
---|
[b7fd2a0] | 45 | static errno_t i8259_dev_add(ddf_dev_t *dev);
|
---|
| 46 | static errno_t i8259_dev_remove(ddf_dev_t *dev);
|
---|
| 47 | static errno_t i8259_dev_gone(ddf_dev_t *dev);
|
---|
| 48 | static errno_t i8259_fun_online(ddf_fun_t *fun);
|
---|
| 49 | static errno_t i8259_fun_offline(ddf_fun_t *fun);
|
---|
[b446b02] | 50 |
|
---|
| 51 | static driver_ops_t driver_ops = {
|
---|
| 52 | .dev_add = i8259_dev_add,
|
---|
| 53 | .dev_remove = i8259_dev_remove,
|
---|
| 54 | .dev_gone = i8259_dev_gone,
|
---|
| 55 | .fun_online = i8259_fun_online,
|
---|
| 56 | .fun_offline = i8259_fun_offline
|
---|
| 57 | };
|
---|
| 58 |
|
---|
| 59 | static driver_t i8259_driver = {
|
---|
| 60 | .name = NAME,
|
---|
| 61 | .driver_ops = &driver_ops
|
---|
| 62 | };
|
---|
| 63 |
|
---|
[b7fd2a0] | 64 | static errno_t i8259_get_res(ddf_dev_t *dev, i8259_res_t *res)
|
---|
[b446b02] | 65 | {
|
---|
| 66 | async_sess_t *parent_sess;
|
---|
| 67 | hw_res_list_parsed_t hw_res;
|
---|
[b7fd2a0] | 68 | errno_t rc;
|
---|
[b446b02] | 69 |
|
---|
| 70 | parent_sess = ddf_dev_parent_sess_get(dev);
|
---|
| 71 | if (parent_sess == NULL)
|
---|
| 72 | return ENOMEM;
|
---|
| 73 |
|
---|
| 74 | hw_res_list_parsed_init(&hw_res);
|
---|
| 75 | rc = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
|
---|
| 76 | if (rc != EOK)
|
---|
| 77 | return rc;
|
---|
| 78 |
|
---|
| 79 | if (hw_res.mem_ranges.count != 2) {
|
---|
| 80 | rc = EINVAL;
|
---|
| 81 | goto error;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | res->base0 = RNGABS(hw_res.mem_ranges.ranges[0]);
|
---|
| 85 | res->base1 = RNGABS(hw_res.mem_ranges.ranges[1]);
|
---|
| 86 |
|
---|
| 87 | return EOK;
|
---|
| 88 | error:
|
---|
| 89 | hw_res_list_parsed_clean(&hw_res);
|
---|
| 90 | return rc;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[b7fd2a0] | 93 | static errno_t i8259_dev_add(ddf_dev_t *dev)
|
---|
[b446b02] | 94 | {
|
---|
| 95 | i8259_t *i8259;
|
---|
| 96 | i8259_res_t i8259_res;
|
---|
[b7fd2a0] | 97 | errno_t rc;
|
---|
[b446b02] | 98 |
|
---|
[1433ecda] | 99 | ddf_msg(LVL_DEBUG, "i8259_dev_add(%p)", dev);
|
---|
[b446b02] | 100 | i8259 = ddf_dev_data_alloc(dev, sizeof(i8259_t));
|
---|
| 101 | if (i8259 == NULL) {
|
---|
| 102 | ddf_msg(LVL_ERROR, "Failed allocating soft state.");
|
---|
| 103 | return ENOMEM;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | i8259->dev = dev;
|
---|
| 107 |
|
---|
| 108 | rc = i8259_get_res(dev, &i8259_res);
|
---|
| 109 | if (rc != EOK) {
|
---|
| 110 | ddf_msg(LVL_ERROR, "Failed getting hardware resource list.\n");
|
---|
| 111 | return EIO;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | return i8259_add(i8259, &i8259_res);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[b7fd2a0] | 117 | static errno_t i8259_dev_remove(ddf_dev_t *dev)
|
---|
[b446b02] | 118 | {
|
---|
[1433ecda] | 119 | i8259_t *i8259 = (i8259_t *)ddf_dev_data_get(dev);
|
---|
[b446b02] | 120 |
|
---|
[1433ecda] | 121 | ddf_msg(LVL_DEBUG, "i8259_dev_remove(%p)", dev);
|
---|
[b446b02] | 122 |
|
---|
[1433ecda] | 123 | return i8259_remove(i8259);
|
---|
[b446b02] | 124 | }
|
---|
| 125 |
|
---|
[b7fd2a0] | 126 | static errno_t i8259_dev_gone(ddf_dev_t *dev)
|
---|
[b446b02] | 127 | {
|
---|
[1433ecda] | 128 | i8259_t *i8259 = (i8259_t *)ddf_dev_data_get(dev);
|
---|
[b446b02] | 129 |
|
---|
[1433ecda] | 130 | ddf_msg(LVL_DEBUG, "i8259_dev_gone(%p)", dev);
|
---|
[b446b02] | 131 |
|
---|
[1433ecda] | 132 | return i8259_gone(i8259);
|
---|
[b446b02] | 133 | }
|
---|
| 134 |
|
---|
[b7fd2a0] | 135 | static errno_t i8259_fun_online(ddf_fun_t *fun)
|
---|
[b446b02] | 136 | {
|
---|
[1433ecda] | 137 | ddf_msg(LVL_DEBUG, "i8259_fun_online()");
|
---|
| 138 | return ddf_fun_online(fun);
|
---|
[b446b02] | 139 | }
|
---|
| 140 |
|
---|
[b7fd2a0] | 141 | static errno_t i8259_fun_offline(ddf_fun_t *fun)
|
---|
[b446b02] | 142 | {
|
---|
[1433ecda] | 143 | ddf_msg(LVL_DEBUG, "i8259_fun_offline()");
|
---|
| 144 | return ddf_fun_offline(fun);
|
---|
[b446b02] | 145 | }
|
---|
| 146 |
|
---|
| 147 | int main(int argc, char *argv[])
|
---|
| 148 | {
|
---|
| 149 | printf(NAME ": i8259 Interrupt Controller driver\n");
|
---|
| 150 | ddf_log_init(NAME);
|
---|
| 151 | return ddf_driver_main(&i8259_driver);
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | /** @}
|
---|
| 155 | */
|
---|