source: mainline/uspace/drv/infrastructure/rootpc/rootpc.c@ 9e470c0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9e470c0 was 9e470c0, checked in by Jakub Jermar <jakub@…>, 12 years ago

Add IO_RANGE and MEM_RANGE members to distinguish whether the range is
parent-relative or absolute. pio_read/write_n(), pio_enable() and
IRQ pseudocode need to be passed absolute values.

  • Property mode set to 100644
File size: 5.6 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 <stdbool.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#include <ops/pio_window.h>
54#include <device/pio_window.h>
55
56#define NAME "rootpc"
57
58typedef struct rootpc_fun {
59 hw_resource_list_t hw_resources;
60 pio_window_t pio_window;
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 {
79 .type = IO_RANGE,
80 .res.io_range = {
81 .address = 0xCF8,
82 .size = 4,
83 .relative = false,
84 .endianness = LITTLE_ENDIAN
85 }
86 },
87 {
88 .type = IO_RANGE,
89 .res.io_range = {
90 .address = 0xCFC,
91 .size = 4,
92 .relative = false,
93 .endianness = LITTLE_ENDIAN
94 }
95 }
96};
97
98static rootpc_fun_t pci_data = {
99 .hw_resources = {
100 sizeof(pci_conf_regs) / sizeof(pci_conf_regs[0]),
101 pci_conf_regs
102 },
103 .pio_window = {
104 .mem = {
105 .base = UINT32_C(0),
106 .size = UINT32_C(0xffffffff) /* practical maximum */
107 },
108 .io = {
109 .base = UINT32_C(0),
110 .size = UINT32_C(0x10000)
111 }
112 }
113};
114
115/** Obtain function soft-state from DDF function node */
116static rootpc_fun_t *rootpc_fun(ddf_fun_t *fnode)
117{
118 return ddf_fun_data_get(fnode);
119}
120
121static hw_resource_list_t *rootpc_get_resources(ddf_fun_t *fnode)
122{
123 rootpc_fun_t *fun = rootpc_fun(fnode);
124
125 assert(fun != NULL);
126 return &fun->hw_resources;
127}
128
129static bool rootpc_enable_interrupt(ddf_fun_t *fun)
130{
131 /* TODO */
132
133 return false;
134}
135
136static pio_window_t *rootpc_get_pio_window(ddf_fun_t *fnode)
137{
138 rootpc_fun_t *fun = rootpc_fun(fnode);
139
140 assert(fun != NULL);
141 return &fun->pio_window;
142}
143
144static hw_res_ops_t fun_hw_res_ops = {
145 .get_resource_list = &rootpc_get_resources,
146 .enable_interrupt = &rootpc_enable_interrupt,
147};
148
149static pio_window_ops_t fun_pio_window_ops = {
150 .get_pio_window = &rootpc_get_pio_window
151};
152
153/* Initialized in root_pc_init() function. */
154static ddf_dev_ops_t rootpc_fun_ops;
155
156static bool
157rootpc_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id,
158 rootpc_fun_t *fun_proto)
159{
160 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
161
162 ddf_fun_t *fnode = NULL;
163 int rc;
164
165 /* Create new device. */
166 fnode = ddf_fun_create(dev, fun_inner, name);
167 if (fnode == NULL)
168 goto failure;
169
170 rootpc_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(rootpc_fun_t));
171 *fun = *fun_proto;
172
173 /* Add match ID */
174 rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
175 if (rc != EOK)
176 goto failure;
177
178 /* Set provided operations to the device. */
179 ddf_fun_set_ops(fnode, &rootpc_fun_ops);
180
181 /* Register function. */
182 if (ddf_fun_bind(fnode) != EOK) {
183 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
184 goto failure;
185 }
186
187 return true;
188
189failure:
190 if (fnode != NULL)
191 ddf_fun_destroy(fnode);
192
193 ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
194
195 return false;
196}
197
198static bool rootpc_add_functions(ddf_dev_t *dev)
199{
200 return rootpc_add_fun(dev, "pci0", "intel_pci", &pci_data);
201}
202
203/** Get the root device.
204 *
205 * @param dev The device which is root of the whole device tree (both
206 * of HW and pseudo devices).
207 * @return Zero on success, negative error number otherwise.
208 */
209static int rootpc_dev_add(ddf_dev_t *dev)
210{
211 ddf_msg(LVL_DEBUG, "rootpc_dev_add, device handle = %d",
212 (int)ddf_dev_get_handle(dev));
213
214 /* Register functions. */
215 if (!rootpc_add_functions(dev)) {
216 ddf_msg(LVL_ERROR, "Failed to add functions for PC platform.");
217 }
218
219 return EOK;
220}
221
222static void root_pc_init(void)
223{
224 ddf_log_init(NAME);
225 rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
226 rootpc_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
227}
228
229int main(int argc, char *argv[])
230{
231 printf(NAME ": HelenOS PC platform driver\n");
232 root_pc_init();
233 return ddf_driver_main(&rootpc_driver);
234}
235
236/**
237 * @}
238 */
Note: See TracBrowser for help on using the repository browser.