source: mainline/uspace/drv/platform/mac/mac.c@ a35b458

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a35b458 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

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