source: mainline/uspace/drv/platform/pc/pc.c@ 02246b8

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 02246b8 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

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