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_ia32 Root HW device driver for ia32 platform.
|
---|
31 | * @brief HelenOS root HW device driver for ia32 platform.
|
---|
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 <driver.h>
|
---|
49 | #include <devman.h>
|
---|
50 | #include <ipc/devman.h>
|
---|
51 | #include <ipc/dev_iface.h>
|
---|
52 | #include <resource.h>
|
---|
53 | #include <device/hw_res.h>
|
---|
54 |
|
---|
55 | #define NAME "rootia32"
|
---|
56 |
|
---|
57 | typedef struct rootia32_child_dev_data {
|
---|
58 | hw_resource_list_t hw_resources;
|
---|
59 | } rootia32_child_dev_data_t;
|
---|
60 |
|
---|
61 | static int rootia32_add_device(device_t *dev);
|
---|
62 | static void root_ia32_init(void);
|
---|
63 |
|
---|
64 | /** The root device driver's standard operations.
|
---|
65 | */
|
---|
66 | static driver_ops_t rootia32_ops = {
|
---|
67 | .add_device = &rootia32_add_device
|
---|
68 | };
|
---|
69 |
|
---|
70 | /** The root device driver structure.
|
---|
71 | */
|
---|
72 | static driver_t rootia32_driver = {
|
---|
73 | .name = NAME,
|
---|
74 | .driver_ops = &rootia32_ops
|
---|
75 | };
|
---|
76 |
|
---|
77 | static 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 |
|
---|
86 | static rootia32_child_dev_data_t pci_data = {
|
---|
87 | .hw_resources = {
|
---|
88 | 1,
|
---|
89 | &pci_conf_regs
|
---|
90 | }
|
---|
91 | };
|
---|
92 |
|
---|
93 | static hw_resource_list_t * rootia32_get_child_resources(device_t *dev)
|
---|
94 | {
|
---|
95 | rootia32_child_dev_data_t *data = (rootia32_child_dev_data_t *)dev->driver_data;
|
---|
96 | if (NULL == data) {
|
---|
97 | return NULL;
|
---|
98 | }
|
---|
99 | return &data->hw_resources;
|
---|
100 | }
|
---|
101 |
|
---|
102 | static bool rootia32_enable_child_interrupt(device_t *dev)
|
---|
103 | {
|
---|
104 | // TODO
|
---|
105 |
|
---|
106 | return false;
|
---|
107 | }
|
---|
108 |
|
---|
109 | static resource_iface_t child_res_iface = {
|
---|
110 | &rootia32_get_child_resources,
|
---|
111 | &rootia32_enable_child_interrupt
|
---|
112 | };
|
---|
113 |
|
---|
114 | // initialized in root_ia32_init() function
|
---|
115 | static device_ops_t rootia32_child_ops;
|
---|
116 |
|
---|
117 | static bool rootia32_add_child(
|
---|
118 | device_t *parent, const char *name, const char *str_match_id,
|
---|
119 | rootia32_child_dev_data_t *drv_data)
|
---|
120 | {
|
---|
121 | printf(NAME ": adding new child device '%s'.\n", name);
|
---|
122 |
|
---|
123 | device_t *child = NULL;
|
---|
124 | match_id_t *match_id = NULL;
|
---|
125 |
|
---|
126 | // create new device
|
---|
127 | if (NULL == (child = create_device())) {
|
---|
128 | goto failure;
|
---|
129 | }
|
---|
130 |
|
---|
131 | child->name = name;
|
---|
132 | child->driver_data = drv_data;
|
---|
133 |
|
---|
134 | // initialize match id list
|
---|
135 | if (NULL == (match_id = create_match_id())) {
|
---|
136 | goto failure;
|
---|
137 | }
|
---|
138 | match_id->id = str_match_id;
|
---|
139 | match_id->score = 100;
|
---|
140 | add_match_id(&child->match_ids, match_id);
|
---|
141 |
|
---|
142 | // set provided operations to the device
|
---|
143 | child->ops = &rootia32_child_ops;
|
---|
144 |
|
---|
145 | // register child device
|
---|
146 | if (EOK != child_device_register(child, parent)) {
|
---|
147 | goto failure;
|
---|
148 | }
|
---|
149 |
|
---|
150 | return true;
|
---|
151 |
|
---|
152 | failure:
|
---|
153 | if (NULL != match_id) {
|
---|
154 | match_id->id = NULL;
|
---|
155 | }
|
---|
156 |
|
---|
157 | if (NULL != child) {
|
---|
158 | child->name = NULL;
|
---|
159 | delete_device(child);
|
---|
160 | }
|
---|
161 |
|
---|
162 | printf(NAME ": failed to add child device '%s'.\n", name);
|
---|
163 |
|
---|
164 | return false;
|
---|
165 | }
|
---|
166 |
|
---|
167 | static bool rootia32_add_children(device_t *dev)
|
---|
168 | {
|
---|
169 | return rootia32_add_child(dev, "pci0", "intel_pci", &pci_data);
|
---|
170 | }
|
---|
171 |
|
---|
172 | /** Get the root device.
|
---|
173 | *
|
---|
174 | * @param dev the device which is root of the whole device tree (both of HW and pseudo devices).
|
---|
175 | * @return 0 on success, negative error number otherwise.
|
---|
176 | */
|
---|
177 | static int rootia32_add_device(device_t *dev)
|
---|
178 | {
|
---|
179 | printf(NAME ": rootia32_add_device, device handle = %d\n", dev->handle);
|
---|
180 |
|
---|
181 | // register child devices
|
---|
182 | if (!rootia32_add_children(dev)) {
|
---|
183 | printf(NAME ": failed to add child devices for platform ia32.\n");
|
---|
184 | }
|
---|
185 |
|
---|
186 | return EOK;
|
---|
187 | }
|
---|
188 |
|
---|
189 | static void root_ia32_init() {
|
---|
190 | rootia32_child_ops.interfaces[HW_RES_DEV_IFACE] = &child_res_iface;
|
---|
191 | }
|
---|
192 |
|
---|
193 | int main(int argc, char *argv[])
|
---|
194 | {
|
---|
195 | printf(NAME ": HelenOS rootia32 device driver\n");
|
---|
196 | root_ia32_init();
|
---|
197 | return driver_main(&rootia32_driver);
|
---|
198 | }
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * @}
|
---|
202 | */
|
---|
203 |
|
---|