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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8312577 was 3795f9c, checked in by Jan Vesely <jano.vesely@…>, 13 years ago

rootmac: Disable hardcoded pci bus.

Reported to cause lockups.

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