[e27e36e] | 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 |
|
---|
[6404aca] | 29 | /** @addtogroup uspace_drv_cuda_adb
|
---|
[e27e36e] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file VIA-CUDA Apple Desktop Bus driver
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <ddf/driver.h>
|
---|
| 36 | #include <ddf/log.h>
|
---|
[c188c62] | 37 | #include <device/hw_res_parsed.h>
|
---|
[e27e36e] | 38 | #include <errno.h>
|
---|
| 39 | #include <stdio.h>
|
---|
| 40 |
|
---|
| 41 | #include "cuda_adb.h"
|
---|
| 42 |
|
---|
| 43 | #define NAME "cuda_adb"
|
---|
| 44 |
|
---|
[b7fd2a0] | 45 | static errno_t cuda_dev_add(ddf_dev_t *dev);
|
---|
| 46 | static errno_t cuda_dev_remove(ddf_dev_t *dev);
|
---|
| 47 | static errno_t cuda_dev_gone(ddf_dev_t *dev);
|
---|
| 48 | static errno_t cuda_fun_online(ddf_fun_t *fun);
|
---|
| 49 | static errno_t cuda_fun_offline(ddf_fun_t *fun);
|
---|
[e27e36e] | 50 |
|
---|
| 51 | static driver_ops_t driver_ops = {
|
---|
| 52 | .dev_add = cuda_dev_add,
|
---|
| 53 | .dev_remove = cuda_dev_remove,
|
---|
| 54 | .dev_gone = cuda_dev_gone,
|
---|
| 55 | .fun_online = cuda_fun_online,
|
---|
| 56 | .fun_offline = cuda_fun_offline
|
---|
| 57 | };
|
---|
| 58 |
|
---|
| 59 | static driver_t cuda_adb_driver = {
|
---|
| 60 | .name = NAME,
|
---|
| 61 | .driver_ops = &driver_ops
|
---|
| 62 | };
|
---|
| 63 |
|
---|
[b7fd2a0] | 64 | static errno_t cuda_get_res(ddf_dev_t *dev, cuda_res_t *res)
|
---|
[c188c62] | 65 | {
|
---|
| 66 | async_sess_t *parent_sess;
|
---|
| 67 | hw_res_list_parsed_t hw_res;
|
---|
[b7fd2a0] | 68 | errno_t rc;
|
---|
[c188c62] | 69 |
|
---|
[2fd26bb] | 70 | parent_sess = ddf_dev_parent_sess_get(dev);
|
---|
[c188c62] | 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.io_ranges.count != 1) {
|
---|
| 80 | rc = EINVAL;
|
---|
| 81 | goto error;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | res->base = RNGABS(hw_res.io_ranges.ranges[0]);
|
---|
| 85 |
|
---|
| 86 | if (hw_res.irqs.count != 1) {
|
---|
| 87 | rc = EINVAL;
|
---|
| 88 | goto error;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | res->irq = hw_res.irqs.irqs[0];
|
---|
| 92 |
|
---|
| 93 | return EOK;
|
---|
| 94 | error:
|
---|
| 95 | hw_res_list_parsed_clean(&hw_res);
|
---|
| 96 | return rc;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[b7fd2a0] | 99 | static errno_t cuda_dev_add(ddf_dev_t *dev)
|
---|
[e27e36e] | 100 | {
|
---|
| 101 | cuda_t *cuda;
|
---|
[c188c62] | 102 | cuda_res_t cuda_res;
|
---|
[b7fd2a0] | 103 | errno_t rc;
|
---|
[e27e36e] | 104 |
|
---|
[1433ecda] | 105 | ddf_msg(LVL_DEBUG, "cuda_dev_add(%p)", dev);
|
---|
[e27e36e] | 106 | cuda = ddf_dev_data_alloc(dev, sizeof(cuda_t));
|
---|
| 107 | if (cuda == NULL) {
|
---|
| 108 | ddf_msg(LVL_ERROR, "Failed allocating soft state.");
|
---|
| 109 | return ENOMEM;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | cuda->dev = dev;
|
---|
| 113 | list_initialize(&cuda->devs);
|
---|
[c188c62] | 114 |
|
---|
| 115 | rc = cuda_get_res(dev, &cuda_res);
|
---|
| 116 | if (rc != EOK) {
|
---|
| 117 | ddf_msg(LVL_ERROR, "Failed getting hardware resource list.\n");
|
---|
| 118 | return EIO;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | return cuda_add(cuda, &cuda_res);
|
---|
[e27e36e] | 122 | }
|
---|
| 123 |
|
---|
[b7fd2a0] | 124 | static errno_t cuda_dev_remove(ddf_dev_t *dev)
|
---|
[e27e36e] | 125 | {
|
---|
[1433ecda] | 126 | cuda_t *cuda = (cuda_t *)ddf_dev_data_get(dev);
|
---|
[e27e36e] | 127 |
|
---|
[1433ecda] | 128 | ddf_msg(LVL_DEBUG, "cuda_dev_remove(%p)", dev);
|
---|
[e27e36e] | 129 |
|
---|
[1433ecda] | 130 | return cuda_remove(cuda);
|
---|
[e27e36e] | 131 | }
|
---|
| 132 |
|
---|
[b7fd2a0] | 133 | static errno_t cuda_dev_gone(ddf_dev_t *dev)
|
---|
[e27e36e] | 134 | {
|
---|
[1433ecda] | 135 | cuda_t *cuda = (cuda_t *)ddf_dev_data_get(dev);
|
---|
[e27e36e] | 136 |
|
---|
[1433ecda] | 137 | ddf_msg(LVL_DEBUG, "cuda_dev_gone(%p)", dev);
|
---|
[e27e36e] | 138 |
|
---|
[1433ecda] | 139 | return cuda_gone(cuda);
|
---|
[e27e36e] | 140 | }
|
---|
| 141 |
|
---|
[b7fd2a0] | 142 | static errno_t cuda_fun_online(ddf_fun_t *fun)
|
---|
[e27e36e] | 143 | {
|
---|
[1433ecda] | 144 | ddf_msg(LVL_DEBUG, "cuda_fun_online()");
|
---|
| 145 | return ddf_fun_online(fun);
|
---|
[e27e36e] | 146 | }
|
---|
| 147 |
|
---|
[b7fd2a0] | 148 | static errno_t cuda_fun_offline(ddf_fun_t *fun)
|
---|
[e27e36e] | 149 | {
|
---|
[1433ecda] | 150 | ddf_msg(LVL_DEBUG, "cuda_fun_offline()");
|
---|
| 151 | return ddf_fun_offline(fun);
|
---|
[e27e36e] | 152 | }
|
---|
| 153 |
|
---|
| 154 | int main(int argc, char *argv[])
|
---|
| 155 | {
|
---|
| 156 | printf(NAME ": VIA-CUDA Apple Desktop Bus driver\n");
|
---|
| 157 | ddf_log_init(NAME);
|
---|
| 158 | return ddf_driver_main(&cuda_adb_driver);
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | /** @}
|
---|
| 162 | */
|
---|