source: mainline/uspace/drv/infrastructure/rootpc/rootpc.c@ e882e3a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e882e3a was e882e3a, checked in by Jiri Svoboda <jiri@…>, 13 years ago

Remove include of devman.h where not needed.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * Copyright (c) 2010 Lenka Trochtova
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_pc PC platform driver.
31 * @brief HelenOS PC platform driver.
32 * @{
33 */
34
35/** @file
36 */
37
38#include <assert.h>
39#include <stdio.h>
40#include <errno.h>
41#include <bool.h>
42#include <fibril_synch.h>
43#include <stdlib.h>
44#include <str.h>
45#include <ctype.h>
46#include <macros.h>
47
48#include <ddf/driver.h>
49#include <ddf/log.h>
50#include <ipc/dev_iface.h>
51#include <ops/hw_res.h>
52#include <device/hw_res.h>
53
54#define NAME "rootpc"
55
56/** Obtain function soft-state from DDF function node */
57#define ROOTPC_FUN(fnode) ((rootpc_fun_t *) (fnode)->driver_data)
58
59typedef struct rootpc_fun {
60 hw_resource_list_t hw_resources;
61} rootpc_fun_t;
62
63static int rootpc_dev_add(ddf_dev_t *dev);
64static void root_pc_init(void);
65
66/** The root device driver's standard operations. */
67static driver_ops_t rootpc_ops = {
68 .dev_add = &rootpc_dev_add
69};
70
71/** The root device driver structure. */
72static driver_t rootpc_driver = {
73 .name = NAME,
74 .driver_ops = &rootpc_ops
75};
76
77static hw_resource_t pci_conf_regs = {
78 .type = IO_RANGE,
79 .res.io_range = {
80 .address = 0xCF8,
81 .size = 8,
82 .endianness = LITTLE_ENDIAN
83 }
84};
85
86static rootpc_fun_t pci_data = {
87 .hw_resources = {
88 1,
89 &pci_conf_regs
90 }
91};
92
93static hw_resource_list_t *rootpc_get_resources(ddf_fun_t *fnode)
94{
95 rootpc_fun_t *fun = ROOTPC_FUN(fnode);
96
97 assert(fun != NULL);
98 return &fun->hw_resources;
99}
100
101static bool rootpc_enable_interrupt(ddf_fun_t *fun)
102{
103 /* TODO */
104
105 return false;
106}
107
108static hw_res_ops_t fun_hw_res_ops = {
109 .get_resource_list = &rootpc_get_resources,
110 .enable_interrupt = &rootpc_enable_interrupt,
111};
112
113/* Initialized in root_pc_init() function. */
114static ddf_dev_ops_t rootpc_fun_ops;
115
116static bool
117rootpc_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id,
118 rootpc_fun_t *fun)
119{
120 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
121
122 ddf_fun_t *fnode = NULL;
123 match_id_t *match_id = NULL;
124
125 /* Create new device. */
126 fnode = ddf_fun_create(dev, fun_inner, name);
127 if (fnode == NULL)
128 goto failure;
129
130 fnode->driver_data = fun;
131
132 /* Initialize match id list */
133 match_id = create_match_id();
134 if (match_id == NULL)
135 goto failure;
136
137 match_id->id = str_match_id;
138 match_id->score = 100;
139 add_match_id(&fnode->match_ids, match_id);
140
141 /* Set provided operations to the device. */
142 fnode->ops = &rootpc_fun_ops;
143
144 /* Register function. */
145 if (ddf_fun_bind(fnode) != EOK) {
146 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
147 goto failure;
148 }
149
150 return true;
151
152failure:
153 if (match_id != NULL)
154 match_id->id = NULL;
155
156 if (fnode != NULL)
157 ddf_fun_destroy(fnode);
158
159 ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
160
161 return false;
162}
163
164static bool rootpc_add_functions(ddf_dev_t *dev)
165{
166 return rootpc_add_fun(dev, "pci0", "intel_pci", &pci_data);
167}
168
169/** Get the root device.
170 *
171 * @param dev The device which is root of the whole device tree (both
172 * of HW and pseudo devices).
173 * @return Zero on success, negative error number otherwise.
174 */
175static int rootpc_dev_add(ddf_dev_t *dev)
176{
177 ddf_msg(LVL_DEBUG, "rootpc_dev_add, device handle = %d",
178 (int)dev->handle);
179
180 /* Register functions. */
181 if (!rootpc_add_functions(dev)) {
182 ddf_msg(LVL_ERROR, "Failed to add functions for PC platform.");
183 }
184
185 return EOK;
186}
187
188static void root_pc_init(void)
189{
190 ddf_log_init(NAME, LVL_ERROR);
191 rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
192}
193
194int main(int argc, char *argv[])
195{
196 printf(NAME ": HelenOS PC platform driver\n");
197 root_pc_init();
198 return ddf_driver_main(&rootpc_driver);
199}
200
201/**
202 * @}
203 */
Note: See TracBrowser for help on using the repository browser.