source: mainline/uspace/drv/platform/leon3/leon3.c@ 0f2a9be

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 0f2a9be was 0f2a9be, checked in by Jiri Svoboda <jiri@…>, 11 years ago

Fix missed things to rename.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * Copyright (c) 2012 Jan Vesely
3 * Copyright (c) 2013 Jakub Klama
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/**
31 * @defgroup leon3 SPARC LEON3 platform driver.
32 * @brief HelenOS SPARC LEON3 platform driver.
33 * @{
34 */
35/** @file
36 */
37
38#include <ddf/log.h>
39#include <errno.h>
40#include <ops/hw_res.h>
41#include <stdio.h>
42#include "leon3.h"
43
44#define NAME "leon3"
45
46typedef struct {
47 const char *name;
48 match_id_t match_id;
49 hw_resource_list_t hw_resources;
50} leon3_fun_t;
51
52static hw_resource_t amba_res[] = {
53 {
54 .type = MEM_RANGE,
55 .res.mem_range = {
56 .address = AMBAPP_MASTER_AREA,
57 .size = AMBAPP_MASTER_SIZE,
58 .endianness = BIG_ENDIAN
59 }
60 },
61 {
62 .type = MEM_RANGE,
63 .res.mem_range = {
64 .address = AMBAPP_SLAVE_AREA,
65 .size = AMBAPP_SLAVE_SIZE,
66 .endianness = BIG_ENDIAN,
67 }
68 }
69};
70
71static const leon3_fun_t leon3_func = {
72 .name = "leon_amba",
73 .match_id = {
74 .id = "leon_amba",
75 .score = 90
76 },
77 .hw_resources = {
78 .count = 2,
79 .resources = amba_res
80 }
81};
82
83static hw_resource_list_t *leon3_get_resources(ddf_fun_t *);
84static bool leon3_enable_interrupt(ddf_fun_t *);
85
86static hw_res_ops_t fun_hw_res_ops = {
87 .get_resource_list = &leon3_get_resources,
88 .enable_interrupt = &leon3_enable_interrupt
89};
90
91static ddf_dev_ops_t leon3_fun_ops = {
92 .interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops
93};
94
95static int leon3_add_fun(ddf_dev_t *dev, const leon3_fun_t *fun)
96{
97 assert(dev);
98 assert(fun);
99
100 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", fun->name);
101
102 /* Create new device function. */
103 ddf_fun_t *fnode = ddf_fun_create(dev, fun_inner, fun->name);
104 if (fnode == NULL)
105 return ENOMEM;
106
107 /* Add match id */
108 int ret = ddf_fun_add_match_id(fnode, fun->match_id.id,
109 fun->match_id.score);
110 if (ret != EOK) {
111 ddf_fun_destroy(fnode);
112 return ret;
113 }
114
115 /* Allocate needed data */
116 leon3_fun_t *rf =
117 ddf_fun_data_alloc(fnode, sizeof(leon3_fun_t));
118 if (!rf) {
119 ddf_fun_destroy(fnode);
120 return ENOMEM;
121 }
122 *rf = *fun;
123
124 /* Set provided operations to the device. */
125 ddf_fun_set_ops(fnode, &leon3_fun_ops);
126
127 /* Register function. */
128 ret = ddf_fun_bind(fnode);
129 if (ret != EOK) {
130 ddf_msg(LVL_ERROR, "Failed binding function %s.", fun->name);
131 ddf_fun_destroy(fnode);
132 return ret;
133 }
134
135 return EOK;
136}
137
138/** Add the root device.
139 *
140 * @param dev Device which is root of the whole device tree
141 * (both of HW and pseudo devices).
142 *
143 * @return Zero on success, negative error number otherwise.
144 *
145 */
146static int leon3_dev_add(ddf_dev_t *dev)
147{
148 assert(dev);
149
150 /* Register functions */
151 if (leon3_add_fun(dev, &leon3_func) != EOK) {
152 ddf_msg(LVL_ERROR, "Failed to add %s function for "
153 "LEON3 platform.", leon3_func.name);
154 }
155
156 return EOK;
157}
158
159/** The root device driver's standard operations. */
160static driver_ops_t leon3_ops = {
161 .dev_add = &leon3_dev_add
162};
163
164/** The root device driver structure. */
165static driver_t leon3_driver = {
166 .name = NAME,
167 .driver_ops = &leon3_ops
168};
169
170static hw_resource_list_t *leon3_get_resources(ddf_fun_t *fnode)
171{
172 leon3_fun_t *fun = ddf_fun_data_get(fnode);
173 assert(fun != NULL);
174
175 printf("leon3_get_resources() called\n");
176
177 return &fun->hw_resources;
178}
179
180static bool leon3_enable_interrupt(ddf_fun_t *fun)
181{
182 // FIXME TODO
183 return false;
184}
185
186int main(int argc, char *argv[])
187{
188 printf("%s: HelenOS SPARC LEON3 platform driver\n", NAME);
189 ddf_log_init(NAME);
190 return ddf_driver_main(&leon3_driver);
191}
192
193/**
194 * @}
195 */
Note: See TracBrowser for help on using the repository browser.