source: mainline/uspace/drv/infrastructure/rootmac/rootmac.c@ a14f346

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a14f346 was 267f235, checked in by Vojtech Horky <vojtechhorky@…>, 13 years ago

log_init() needs only one parameter

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