source: mainline/uspace/drv/platform/sun4v/sun4v.c

Last change on this file was 4122410, checked in by Jakub Jermar <jakub@…>, 7 years ago

Improve Doxygen documentaion

This is stil WiP. A number of libraries, drivers and services were
converted to using a more hierarchical and decentralized scheme when it
comes to specifying to which doxygen group they belong.

  • Property mode set to 100644
File size: 5.7 KB
RevLine 
[7aa94304]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
29/**
[4122410]30 * @addtogroup sun4v sun4v
[7aa94304]31 * @{
32 */
33
34/** @file
35 */
36
[19d2ce01]37#include <as.h>
[7aa94304]38#include <assert.h>
39#include <ddf/driver.h>
40#include <ddf/log.h>
[19d2ce01]41#include <errno.h>
[c1694b6b]42#include <str_error.h>
[19d2ce01]43#include <ops/hw_res.h>
44#include <ops/pio_window.h>
45#include <stdio.h>
46#include <stdlib.h>
47#include <sysinfo.h>
[7aa94304]48
49#define NAME "sun4v"
50
[19d2ce01]51typedef struct sun4v_fun {
52 hw_resource_list_t hw_resources;
53 pio_window_t pio_window;
54} sun4v_fun_t;
55
[b7fd2a0]56static errno_t sun4v_dev_add(ddf_dev_t *dev);
[7aa94304]57
58static driver_ops_t sun4v_ops = {
59 .dev_add = &sun4v_dev_add
60};
61
62static driver_t sun4v_driver = {
63 .name = NAME,
64 .driver_ops = &sun4v_ops
65};
66
[19d2ce01]67static hw_resource_t console_res[] = {
68 {
69 .type = MEM_RANGE,
70 .res.mem_range = {
71 .address = 0,
72 .size = PAGE_SIZE,
73 .relative = true,
74 .endianness = LITTLE_ENDIAN
75 }
76 },
[f4cfd271]77 {
78 .type = MEM_RANGE,
79 .res.mem_range = {
80 .address = 0,
81 .size = PAGE_SIZE,
82 .relative = true,
83 .endianness = LITTLE_ENDIAN
84 }
85 },
[19d2ce01]86};
87
88static sun4v_fun_t console_data = {
89 .hw_resources = {
90 sizeof(console_res) / sizeof(console_res[0]),
91 console_res
92 },
93 .pio_window = {
94 .mem = {
95 .base = 0,
96 .size = PAGE_SIZE
97 }
98 }
99};
100
101/** Obtain function soft-state from DDF function node */
102static sun4v_fun_t *sun4v_fun(ddf_fun_t *fnode)
103{
104 return ddf_fun_data_get(fnode);
105}
106
107static hw_resource_list_t *sun4v_get_resources(ddf_fun_t *fnode)
108{
109 sun4v_fun_t *fun = sun4v_fun(fnode);
110
111 assert(fun != NULL);
112 return &fun->hw_resources;
113}
114
[b7fd2a0]115static errno_t sun4v_enable_interrupt(ddf_fun_t *fun, int irq)
[19d2ce01]116{
[1569a9b]117 return EOK;
[19d2ce01]118}
119
120static pio_window_t *sun4v_get_pio_window(ddf_fun_t *fnode)
121{
122 sun4v_fun_t *fun = sun4v_fun(fnode);
123
124 assert(fun != NULL);
125 return &fun->pio_window;
126}
127
128static hw_res_ops_t fun_hw_res_ops = {
129 .get_resource_list = &sun4v_get_resources,
130 .enable_interrupt = &sun4v_enable_interrupt,
131};
132
133static pio_window_ops_t fun_pio_window_ops = {
134 .get_pio_window = &sun4v_get_pio_window
135};
136
137static ddf_dev_ops_t sun4v_fun_ops;
138
[b7fd2a0]139static errno_t sun4v_add_fun(ddf_dev_t *dev, const char *name,
[19d2ce01]140 const char *str_match_id, sun4v_fun_t *fun_proto)
[7aa94304]141{
142 ddf_msg(LVL_NOTE, "Adding function '%s'.", name);
143
144 ddf_fun_t *fnode = NULL;
[b7fd2a0]145 errno_t rc;
[7aa94304]146
147 /* Create new device. */
148 fnode = ddf_fun_create(dev, fun_inner, name);
149 if (fnode == NULL) {
150 ddf_msg(LVL_ERROR, "Error creating function '%s'", name);
151 rc = ENOMEM;
152 goto error;
153 }
154
[19d2ce01]155 sun4v_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(sun4v_fun_t));
156 if (fun == NULL) {
157 rc = ENOMEM;
158 goto error;
159 }
160
161 *fun = *fun_proto;
162
[7aa94304]163 /* Add match ID */
164 rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
165 if (rc != EOK) {
166 ddf_msg(LVL_ERROR, "Error adding match ID");
167 goto error;
168 }
169
[19d2ce01]170 /* Set provided operations to the device. */
171 ddf_fun_set_ops(fnode, &sun4v_fun_ops);
172
[7aa94304]173 /* Register function. */
[19d2ce01]174 rc = ddf_fun_bind(fnode);
175 if (rc != EOK) {
[7aa94304]176 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
177 goto error;
178 }
179
180 return EOK;
181
182error:
183 if (fnode != NULL)
184 ddf_fun_destroy(fnode);
185
186 return rc;
187}
188
[b7fd2a0]189static errno_t sun4v_add_functions(ddf_dev_t *dev)
[7aa94304]190{
[b7fd2a0]191 errno_t rc;
[7aa94304]192
[19d2ce01]193 rc = sun4v_add_fun(dev, "console", "sun4v/console", &console_data);
[7aa94304]194 if (rc != EOK)
195 return rc;
196
197 return EOK;
198}
199
200/** Add device. */
[b7fd2a0]201static errno_t sun4v_dev_add(ddf_dev_t *dev)
[7aa94304]202{
[19d2ce01]203 ddf_msg(LVL_DEBUG, "sun4v_dev_add, device handle = %d",
[7aa94304]204 (int)ddf_dev_get_handle(dev));
205
206 /* Register functions. */
207 if (sun4v_add_functions(dev)) {
208 ddf_msg(LVL_ERROR, "Failed to add functions for sun4v platform.");
209 }
210
211 return EOK;
212}
213
[b7fd2a0]214static errno_t sun4v_init(void)
[7aa94304]215{
[b7fd2a0]216 errno_t rc;
[19d2ce01]217 sysarg_t paddr;
[7aa94304]218
[19d2ce01]219 sun4v_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
220 sun4v_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
[7aa94304]221
222 rc = ddf_log_init(NAME);
223 if (rc != EOK) {
[19d2ce01]224 printf(NAME ": Failed initializing logging service\n");
225 return rc;
[7aa94304]226 }
227
[19d2ce01]228 rc = sysinfo_get_value("niagara.inbuf.address", &paddr);
229 if (rc != EOK) {
[c1694b6b]230 ddf_msg(LVL_ERROR, "niagara.inbuf.address not set: %s", str_error(rc));
[19d2ce01]231 return rc;
232 }
233
[f4cfd271]234 console_res[0].res.mem_range.address = paddr;
235
236 rc = sysinfo_get_value("niagara.outbuf.address", &paddr);
237 if (rc != EOK) {
[c1694b6b]238 ddf_msg(LVL_ERROR, "niagara.outbuf.address not set: %s", str_error(rc));
[f4cfd271]239 return rc;
240 }
241
242 console_res[1].res.mem_range.address = paddr;
[19d2ce01]243 return EOK;
244}
245
246int main(int argc, char *argv[])
247{
[b7fd2a0]248 errno_t rc;
[19d2ce01]249
250 printf(NAME ": Sun4v platform driver\n");
251
252 rc = sun4v_init();
253 if (rc != EOK)
254 return 1;
255
[7aa94304]256 return ddf_driver_main(&sun4v_driver);
257}
258
259/**
260 * @}
261 */
Note: See TracBrowser for help on using the repository browser.