1 | /*
|
---|
2 | * Copyright (c) 2011 Martin Decky
|
---|
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 | /**
|
---|
30 | * @defgroup mac Mac platform driver.
|
---|
31 | * @brief HelenOS Mac platform driver.
|
---|
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 <stdio.h>
|
---|
43 |
|
---|
44 | #define NAME "mac"
|
---|
45 |
|
---|
46 | typedef struct {
|
---|
47 | hw_resource_list_t hw_resources;
|
---|
48 | } mac_fun_t;
|
---|
49 |
|
---|
50 | static hw_resource_t pci_conf_regs[] = {
|
---|
51 | {
|
---|
52 | .type = IO_RANGE,
|
---|
53 | .res.io_range = {
|
---|
54 | .address = 0xfec00000,
|
---|
55 | .size = 4,
|
---|
56 | .relative = false,
|
---|
57 | .endianness = LITTLE_ENDIAN
|
---|
58 | }
|
---|
59 | },
|
---|
60 | {
|
---|
61 | .type = IO_RANGE,
|
---|
62 | .res.io_range = {
|
---|
63 | .address = 0xfee00000,
|
---|
64 | .size = 4,
|
---|
65 | .relative = false,
|
---|
66 | .endianness = LITTLE_ENDIAN
|
---|
67 | }
|
---|
68 | }
|
---|
69 | };
|
---|
70 |
|
---|
71 | static mac_fun_t pci_data = {
|
---|
72 | .hw_resources = {
|
---|
73 | 2,
|
---|
74 | pci_conf_regs
|
---|
75 | }
|
---|
76 | };
|
---|
77 |
|
---|
78 | static ddf_dev_ops_t mac_fun_ops;
|
---|
79 |
|
---|
80 | /** Obtain function soft-state from DDF function node */
|
---|
81 | static mac_fun_t *mac_fun(ddf_fun_t *fnode)
|
---|
82 | {
|
---|
83 | return ddf_fun_data_get(fnode);
|
---|
84 | }
|
---|
85 |
|
---|
86 | static bool mac_add_fun(ddf_dev_t *dev, const char *name,
|
---|
87 | const char *str_match_id, mac_fun_t *fun_proto)
|
---|
88 | {
|
---|
89 | ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
|
---|
90 |
|
---|
91 | ddf_fun_t *fnode = NULL;
|
---|
92 | int rc;
|
---|
93 |
|
---|
94 | /* Create new device. */
|
---|
95 | fnode = ddf_fun_create(dev, fun_inner, name);
|
---|
96 | if (fnode == NULL)
|
---|
97 | goto failure;
|
---|
98 |
|
---|
99 | mac_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(mac_fun_t));
|
---|
100 | *fun = *fun_proto;
|
---|
101 |
|
---|
102 | /* Add match ID */
|
---|
103 | rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
|
---|
104 | if (rc != EOK)
|
---|
105 | goto failure;
|
---|
106 |
|
---|
107 | /* Set provided operations to the device. */
|
---|
108 | ddf_fun_set_ops(fnode, &mac_fun_ops);
|
---|
109 |
|
---|
110 | /* Register function. */
|
---|
111 | if (ddf_fun_bind(fnode) != EOK) {
|
---|
112 | ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
|
---|
113 | goto failure;
|
---|
114 | }
|
---|
115 |
|
---|
116 | return true;
|
---|
117 |
|
---|
118 | failure:
|
---|
119 | if (fnode != NULL)
|
---|
120 | ddf_fun_destroy(fnode);
|
---|
121 |
|
---|
122 | ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
|
---|
123 |
|
---|
124 | return false;
|
---|
125 | }
|
---|
126 |
|
---|
127 | /** Get the root device.
|
---|
128 | *
|
---|
129 | * @param dev Device which is root of the whole device tree
|
---|
130 | * (both of HW and pseudo devices).
|
---|
131 | *
|
---|
132 | * @return Zero on success, negative error number otherwise.
|
---|
133 | *
|
---|
134 | */
|
---|
135 | static int mac_dev_add(ddf_dev_t *dev)
|
---|
136 | {
|
---|
137 | #if 0
|
---|
138 | /* Register functions */
|
---|
139 | if (!mac_add_fun(dev, "pci0", "intel_pci", &pci_data))
|
---|
140 | ddf_msg(LVL_ERROR, "Failed to add functions for Mac platform.");
|
---|
141 | #else
|
---|
142 | (void)pci_data;
|
---|
143 | (void)mac_add_fun;
|
---|
144 | #endif
|
---|
145 |
|
---|
146 | return EOK;
|
---|
147 | }
|
---|
148 |
|
---|
149 | /** The root device driver's standard operations. */
|
---|
150 | static driver_ops_t mac_ops = {
|
---|
151 | .dev_add = &mac_dev_add
|
---|
152 | };
|
---|
153 |
|
---|
154 | /** The root device driver structure. */
|
---|
155 | static driver_t mac_driver = {
|
---|
156 | .name = NAME,
|
---|
157 | .driver_ops = &mac_ops
|
---|
158 | };
|
---|
159 |
|
---|
160 | static hw_resource_list_t *mac_get_resources(ddf_fun_t *fnode)
|
---|
161 | {
|
---|
162 | mac_fun_t *fun = mac_fun(fnode);
|
---|
163 | assert(fun != NULL);
|
---|
164 |
|
---|
165 | return &fun->hw_resources;
|
---|
166 | }
|
---|
167 |
|
---|
168 | static bool mac_enable_interrupt(ddf_fun_t *fun)
|
---|
169 | {
|
---|
170 | /* TODO */
|
---|
171 |
|
---|
172 | return false;
|
---|
173 | }
|
---|
174 |
|
---|
175 | static hw_res_ops_t fun_hw_res_ops = {
|
---|
176 | .get_resource_list = &mac_get_resources,
|
---|
177 | .enable_interrupt = &mac_enable_interrupt
|
---|
178 | };
|
---|
179 |
|
---|
180 | int main(int argc, char *argv[])
|
---|
181 | {
|
---|
182 | printf("%s: HelenOS Mac platform driver\n", NAME);
|
---|
183 | ddf_log_init(NAME);
|
---|
184 | mac_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
|
---|
185 | return ddf_driver_main(&mac_driver);
|
---|
186 | }
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * @}
|
---|
190 | */
|
---|