source: mainline/uspace/drv/infrastructure/rootmac/rootmac.c@ 612ad864

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 612ad864 was 5203e256, checked in by Martin Decky <martin@…>, 14 years ago

keep the drivers source tree tidy by using logical subdirectories

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