source: mainline/uspace/drv/platform/mac/mac.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.8 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Decky
3 * Copyright (c) 2017 Jiri Svoboda
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 * @addtogroup mac mac
32 * @{
33 */
34
35/** @file
36 */
37
38#include <ddf/driver.h>
39#include <ddf/log.h>
40#include <errno.h>
41#include <ops/hw_res.h>
42#include <ops/pio_window.h>
43#include <stdio.h>
44#include <sysinfo.h>
45
46#define NAME "mac"
47
48typedef struct {
49 hw_resource_list_t hw_resources;
50 pio_window_t pio_window;
51} mac_fun_t;
52
53static hw_resource_t adb_res[] = {
54 {
55 .type = IO_RANGE,
56 .res.io_range = {
57 .address = 0,
58 .size = 0x2000,
59 .relative = true,
60 .endianness = BIG_ENDIAN
61 }
62 },
63 {
64 .type = INTERRUPT,
65 .res.interrupt = {
66 .irq = 0 /* patched at run time */
67 }
68 },
69};
70
71static mac_fun_t adb_data = {
72 .hw_resources = {
73 sizeof(adb_res) / sizeof(adb_res[0]),
74 adb_res
75 },
76 .pio_window = {
77 .io = {
78 .base = 0, /* patched at run time */
79 .size = 0x2000
80 }
81 }
82};
83
84static hw_resource_t pci_conf_regs[] = {
85 {
86 .type = IO_RANGE,
87 .res.io_range = {
88 .address = 0xfec00000,
89 .size = 4,
90 .relative = false,
91 .endianness = LITTLE_ENDIAN
92 }
93 },
94 {
95 .type = IO_RANGE,
96 .res.io_range = {
97 .address = 0xfee00000,
98 .size = 4,
99 .relative = false,
100 .endianness = LITTLE_ENDIAN
101 }
102 }
103};
104
105static mac_fun_t pci_data = {
106 .hw_resources = {
107 2,
108 pci_conf_regs
109 }
110};
111
112static ddf_dev_ops_t mac_fun_ops;
113
114/** Obtain function soft-state from DDF function node */
115static mac_fun_t *mac_fun(ddf_fun_t *ddf_fun)
116{
117 return ddf_fun_data_get(ddf_fun);
118}
119
120static pio_window_t *mac_get_pio_window(ddf_fun_t *ddf_fun)
121{
122 mac_fun_t *fun = mac_fun(ddf_fun);
123 return &fun->pio_window;
124}
125
126static bool mac_add_fun(ddf_dev_t *dev, const char *name,
127 const char *str_match_id, mac_fun_t *fun_proto)
128{
129 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
130 printf("mac: Adding new function '%s'.\n", name);
131
132 ddf_fun_t *fnode = NULL;
133 errno_t rc;
134
135 /* Create new device. */
136 fnode = ddf_fun_create(dev, fun_inner, name);
137 if (fnode == NULL)
138 goto failure;
139
140 mac_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(mac_fun_t));
141 *fun = *fun_proto;
142
143 /* Add match ID */
144 rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
145 if (rc != EOK)
146 goto failure;
147
148 /* Set provided operations to the device. */
149 ddf_fun_set_ops(fnode, &mac_fun_ops);
150
151 /* Register function. */
152 if (ddf_fun_bind(fnode) != EOK) {
153 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
154 goto failure;
155 }
156
157 printf("mac: Added new function '%s' (str=%s).\n", name, str_match_id);
158 return true;
159
160failure:
161 if (fnode != NULL)
162 ddf_fun_destroy(fnode);
163
164 ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
165
166 return false;
167}
168
169/** Get the root device.
170 *
171 * @param dev Device which is root of the whole device tree
172 * (both of HW and pseudo devices).
173 *
174 * @return Zero on success, error number otherwise.
175 *
176 */
177static errno_t mac_dev_add(ddf_dev_t *dev)
178{
179 errno_t rc;
180 uintptr_t cuda_physical;
181 sysarg_t cuda_inr;
182#if 0
183 /* Register functions */
184 if (!mac_add_fun(dev, "pci0", "intel_pci", &pci_data)) {
185 ddf_msg(LVL_ERROR, "Failed to add PCI function for Mac platform.");
186 return EIO;
187 }
188#else
189 (void)pci_data;
190#endif
191 rc = sysinfo_get_value("cuda.address.physical", &cuda_physical);
192 if (rc != EOK)
193 return EIO;
194 rc = sysinfo_get_value("cuda.inr", &cuda_inr);
195 if (rc != EOK)
196 return EIO;
197
198 adb_data.pio_window.io.base = cuda_physical;
199 adb_res[1].res.interrupt.irq = cuda_inr;
200
201 if (!mac_add_fun(dev, "adb", "cuda_adb", &adb_data)) {
202 ddf_msg(LVL_ERROR, "Failed to add ADB function for Mac platform.");
203 return EIO;
204 }
205
206 return EOK;
207}
208
209/** The root device driver's standard operations. */
210static driver_ops_t mac_ops = {
211 .dev_add = &mac_dev_add
212};
213
214/** The root device driver structure. */
215static driver_t mac_driver = {
216 .name = NAME,
217 .driver_ops = &mac_ops
218};
219
220static hw_resource_list_t *mac_get_resources(ddf_fun_t *fnode)
221{
222 mac_fun_t *fun = mac_fun(fnode);
223 assert(fun != NULL);
224
225 return &fun->hw_resources;
226}
227
228static errno_t mac_enable_interrupt(ddf_fun_t *fun, int irq)
229{
230 /* TODO */
231
232 return false;
233}
234
235static pio_window_ops_t fun_pio_window_ops = {
236 .get_pio_window = &mac_get_pio_window
237};
238
239static hw_res_ops_t fun_hw_res_ops = {
240 .get_resource_list = &mac_get_resources,
241 .enable_interrupt = &mac_enable_interrupt
242};
243
244int main(int argc, char *argv[])
245{
246 printf("%s: HelenOS Mac platform driver\n", NAME);
247 ddf_log_init(NAME);
248 mac_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
249 mac_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
250 return ddf_driver_main(&mac_driver);
251}
252
253/**
254 * @}
255 */
Note: See TracBrowser for help on using the repository browser.