source: mainline/uspace/drv/intctl/gicv2/main.c

Last change on this file was 8df0306, checked in by Jakub Jermář <jakub@…>, 6 years ago

arm64: Add GICv2 uspace driver

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2018 Petr Pavlu
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/** @addtogroup uspace_drv_gicv2
30 * @{
31 */
32/** @file GICv2 driver.
33 * @brief ARM Generic Interrupt Controller, Architecture version 2.0.
34 *
35 * This IRQ controller is present on the QEMU virt platform for ARM.
36 */
37
38#include <ddf/driver.h>
39#include <ddf/log.h>
40#include <device/hw_res_parsed.h>
41#include <errno.h>
42#include <stdio.h>
43
44#include "gicv2.h"
45
46#define NAME "gicv2"
47
48static errno_t gicv2_dev_add(ddf_dev_t *dev);
49static errno_t gicv2_dev_remove(ddf_dev_t *dev);
50static errno_t gicv2_dev_gone(ddf_dev_t *dev);
51static errno_t gicv2_fun_online(ddf_fun_t *fun);
52static errno_t gicv2_fun_offline(ddf_fun_t *fun);
53
54static driver_ops_t driver_ops = {
55 .dev_add = gicv2_dev_add,
56 .dev_remove = gicv2_dev_remove,
57 .dev_gone = gicv2_dev_gone,
58 .fun_online = gicv2_fun_online,
59 .fun_offline = gicv2_fun_offline
60};
61
62static driver_t gicv2_driver = {
63 .name = NAME,
64 .driver_ops = &driver_ops
65};
66
67static errno_t gicv2_get_res(ddf_dev_t *dev, gicv2_res_t *res)
68{
69 async_sess_t *parent_sess;
70 hw_res_list_parsed_t hw_res;
71 errno_t rc;
72
73 parent_sess = ddf_dev_parent_sess_get(dev);
74 if (parent_sess == NULL)
75 return ENOMEM;
76
77 hw_res_list_parsed_init(&hw_res);
78 rc = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
79 if (rc != EOK)
80 return rc;
81
82 if (hw_res.mem_ranges.count != 2) {
83 rc = EINVAL;
84 goto error;
85 }
86
87 res->distr_base = RNGABS(hw_res.mem_ranges.ranges[0]);
88 res->cpui_base = RNGABS(hw_res.mem_ranges.ranges[1]);
89
90 return EOK;
91error:
92 hw_res_list_parsed_clean(&hw_res);
93 return rc;
94}
95
96static errno_t gicv2_dev_add(ddf_dev_t *dev)
97{
98 gicv2_t *gicv2;
99 gicv2_res_t gicv2_res;
100 errno_t rc;
101
102 ddf_msg(LVL_DEBUG, "gicv2_dev_add(%p)", dev);
103 gicv2 = ddf_dev_data_alloc(dev, sizeof(gicv2_t));
104 if (gicv2 == NULL) {
105 ddf_msg(LVL_ERROR, "Failed allocating soft state.");
106 return ENOMEM;
107 }
108
109 gicv2->dev = dev;
110
111 rc = gicv2_get_res(dev, &gicv2_res);
112 if (rc != EOK) {
113 ddf_msg(LVL_ERROR, "Failed getting hardware resource list.\n");
114 return EIO;
115 }
116
117 return gicv2_add(gicv2, &gicv2_res);
118}
119
120static errno_t gicv2_dev_remove(ddf_dev_t *dev)
121{
122 gicv2_t *gicv2 = (gicv2_t *)ddf_dev_data_get(dev);
123
124 ddf_msg(LVL_DEBUG, "gicv2_dev_remove(%p)", dev);
125
126 return gicv2_remove(gicv2);
127}
128
129static errno_t gicv2_dev_gone(ddf_dev_t *dev)
130{
131 gicv2_t *gicv2 = (gicv2_t *)ddf_dev_data_get(dev);
132
133 ddf_msg(LVL_DEBUG, "gicv2_dev_gone(%p)", dev);
134
135 return gicv2_gone(gicv2);
136}
137
138static errno_t gicv2_fun_online(ddf_fun_t *fun)
139{
140 ddf_msg(LVL_DEBUG, "gicv2_fun_online()");
141 return ddf_fun_online(fun);
142}
143
144static errno_t gicv2_fun_offline(ddf_fun_t *fun)
145{
146 ddf_msg(LVL_DEBUG, "gicv2_fun_offline()");
147 return ddf_fun_offline(fun);
148}
149
150int main(int argc, char *argv[])
151{
152 printf(NAME ": GICv2 interrupt controller driver\n");
153 ddf_log_init(NAME);
154 return ddf_driver_main(&gicv2_driver);
155}
156
157/** @}
158 */
Note: See TracBrowser for help on using the repository browser.