1 | /*
|
---|
2 | * Copyright (c) 2010 Lenka Trochtova
|
---|
3 | * Copyright (c) 2013 Jakub Jermar
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without
|
---|
7 | * modification, are permitted provided that the following conditions
|
---|
8 | * are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * - The name of the author may not be used to endorse or promote products
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * @defgroup root_malta Malta board platform driver.
|
---|
32 | * @brief HelenOS Malta board platform driver.
|
---|
33 | * @{
|
---|
34 | */
|
---|
35 |
|
---|
36 | /** @file
|
---|
37 | */
|
---|
38 |
|
---|
39 | #include <assert.h>
|
---|
40 | #include <stdio.h>
|
---|
41 | #include <errno.h>
|
---|
42 | #include <stdbool.h>
|
---|
43 | #include <fibril_synch.h>
|
---|
44 | #include <stdlib.h>
|
---|
45 | #include <str.h>
|
---|
46 | #include <ctype.h>
|
---|
47 | #include <macros.h>
|
---|
48 |
|
---|
49 | #include <ddi.h>
|
---|
50 | #include <ddf/driver.h>
|
---|
51 | #include <ddf/log.h>
|
---|
52 | #include <ipc/dev_iface.h>
|
---|
53 | #include <ops/hw_res.h>
|
---|
54 | #include <ops/pio_window.h>
|
---|
55 | #include <byteorder.h>
|
---|
56 |
|
---|
57 | #define NAME "rootmalta"
|
---|
58 |
|
---|
59 | #define GT_BASE UINT32_C(0x1be00000)
|
---|
60 | #define GT_SIZE (2 * 1024 * 1024)
|
---|
61 |
|
---|
62 | #define GT_PCI_CMD 0xc00
|
---|
63 | #define GT_PCI_CONFADDR 0xcf8
|
---|
64 | #define GT_PCI_CONFDATA 0xcfc
|
---|
65 |
|
---|
66 | #define GT_PCI_CMD_MBYTESWAP 0x1
|
---|
67 |
|
---|
68 | #define GT_PCI_MEMBASE UINT32_C(0x10000000)
|
---|
69 | #define GT_PCI_MEMSIZE UINT32_C(0x08000000)
|
---|
70 |
|
---|
71 | #define GT_PCI_IOBASE UINT32_C(0x18000000)
|
---|
72 | #define GT_PCI_IOSIZE UINT32_C(0x00200000)
|
---|
73 |
|
---|
74 | typedef struct rootmalta_fun {
|
---|
75 | hw_resource_list_t hw_resources;
|
---|
76 | pio_window_t pio_window;
|
---|
77 | } rootmalta_fun_t;
|
---|
78 |
|
---|
79 | static int rootmalta_dev_add(ddf_dev_t *dev);
|
---|
80 | static void root_malta_init(void);
|
---|
81 |
|
---|
82 | /** The root device driver's standard operations. */
|
---|
83 | static driver_ops_t rootmalta_ops = {
|
---|
84 | .dev_add = &rootmalta_dev_add
|
---|
85 | };
|
---|
86 |
|
---|
87 | /** The root device driver structure. */
|
---|
88 | static driver_t rootmalta_driver = {
|
---|
89 | .name = NAME,
|
---|
90 | .driver_ops = &rootmalta_ops
|
---|
91 | };
|
---|
92 |
|
---|
93 | static hw_resource_t pci_conf_regs[] = {
|
---|
94 | {
|
---|
95 | .type = IO_RANGE,
|
---|
96 | .res.io_range = {
|
---|
97 | .address = GT_BASE + GT_PCI_CONFADDR,
|
---|
98 | .size = 4,
|
---|
99 | .relative = false,
|
---|
100 | .endianness = LITTLE_ENDIAN
|
---|
101 | }
|
---|
102 | },
|
---|
103 | {
|
---|
104 | .type = IO_RANGE,
|
---|
105 | .res.io_range = {
|
---|
106 | .address = GT_BASE + GT_PCI_CONFDATA,
|
---|
107 | .size = 4,
|
---|
108 | .relative = false,
|
---|
109 | .endianness = LITTLE_ENDIAN
|
---|
110 | }
|
---|
111 | }
|
---|
112 | };
|
---|
113 |
|
---|
114 | static rootmalta_fun_t pci_data = {
|
---|
115 | .hw_resources = {
|
---|
116 | sizeof(pci_conf_regs) / sizeof(pci_conf_regs[0]),
|
---|
117 | pci_conf_regs
|
---|
118 | },
|
---|
119 | .pio_window = {
|
---|
120 | .mem = {
|
---|
121 | .base = GT_PCI_MEMBASE,
|
---|
122 | .size = GT_PCI_MEMSIZE
|
---|
123 | },
|
---|
124 | .io = {
|
---|
125 | .base = GT_PCI_IOBASE,
|
---|
126 | .size = GT_PCI_IOSIZE
|
---|
127 | }
|
---|
128 | }
|
---|
129 | };
|
---|
130 |
|
---|
131 | /** Obtain function soft-state from DDF function node */
|
---|
132 | static rootmalta_fun_t *rootmalta_fun(ddf_fun_t *fnode)
|
---|
133 | {
|
---|
134 | return ddf_fun_data_get(fnode);
|
---|
135 | }
|
---|
136 |
|
---|
137 | static hw_resource_list_t *rootmalta_get_resources(ddf_fun_t *fnode)
|
---|
138 | {
|
---|
139 | rootmalta_fun_t *fun = rootmalta_fun(fnode);
|
---|
140 |
|
---|
141 | assert(fun != NULL);
|
---|
142 | return &fun->hw_resources;
|
---|
143 | }
|
---|
144 |
|
---|
145 | static bool rootmalta_enable_interrupt(ddf_fun_t *fun)
|
---|
146 | {
|
---|
147 | /* TODO */
|
---|
148 |
|
---|
149 | return false;
|
---|
150 | }
|
---|
151 |
|
---|
152 | static pio_window_t *rootmalta_get_pio_window(ddf_fun_t *fnode)
|
---|
153 | {
|
---|
154 | rootmalta_fun_t *fun = rootmalta_fun(fnode);
|
---|
155 |
|
---|
156 | assert(fun != NULL);
|
---|
157 | return &fun->pio_window;
|
---|
158 | }
|
---|
159 |
|
---|
160 | static hw_res_ops_t fun_hw_res_ops = {
|
---|
161 | .get_resource_list = &rootmalta_get_resources,
|
---|
162 | .enable_interrupt = &rootmalta_enable_interrupt,
|
---|
163 | };
|
---|
164 |
|
---|
165 | static pio_window_ops_t fun_pio_window_ops = {
|
---|
166 | .get_pio_window = &rootmalta_get_pio_window
|
---|
167 | };
|
---|
168 |
|
---|
169 | /* Initialized in root_malta_init() function. */
|
---|
170 | static ddf_dev_ops_t rootmalta_fun_ops;
|
---|
171 |
|
---|
172 | static bool
|
---|
173 | rootmalta_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id,
|
---|
174 | rootmalta_fun_t *fun_proto)
|
---|
175 | {
|
---|
176 | ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
|
---|
177 |
|
---|
178 | ddf_fun_t *fnode = NULL;
|
---|
179 | int rc;
|
---|
180 |
|
---|
181 | /* Create new device. */
|
---|
182 | fnode = ddf_fun_create(dev, fun_inner, name);
|
---|
183 | if (fnode == NULL)
|
---|
184 | goto failure;
|
---|
185 |
|
---|
186 | rootmalta_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(rootmalta_fun_t));
|
---|
187 | *fun = *fun_proto;
|
---|
188 |
|
---|
189 | /* Add match ID */
|
---|
190 | rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
|
---|
191 | if (rc != EOK)
|
---|
192 | goto failure;
|
---|
193 |
|
---|
194 | /* Set provided operations to the device. */
|
---|
195 | ddf_fun_set_ops(fnode, &rootmalta_fun_ops);
|
---|
196 |
|
---|
197 | /* Register function. */
|
---|
198 | if (ddf_fun_bind(fnode) != EOK) {
|
---|
199 | ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
|
---|
200 | goto failure;
|
---|
201 | }
|
---|
202 |
|
---|
203 | return true;
|
---|
204 |
|
---|
205 | failure:
|
---|
206 | if (fnode != NULL)
|
---|
207 | ddf_fun_destroy(fnode);
|
---|
208 |
|
---|
209 | ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
|
---|
210 |
|
---|
211 | return false;
|
---|
212 | }
|
---|
213 |
|
---|
214 | static bool rootmalta_add_functions(ddf_dev_t *dev)
|
---|
215 | {
|
---|
216 | return rootmalta_add_fun(dev, "pci0", "intel_pci", &pci_data);
|
---|
217 | }
|
---|
218 |
|
---|
219 | /** Get the root device.
|
---|
220 | *
|
---|
221 | * @param dev The device which is root of the whole device tree (both
|
---|
222 | * of HW and pseudo devices).
|
---|
223 | * @return Zero on success, negative error number otherwise.
|
---|
224 | */
|
---|
225 | static int rootmalta_dev_add(ddf_dev_t *dev)
|
---|
226 | {
|
---|
227 | ioport32_t *gt;
|
---|
228 | uint32_t val;
|
---|
229 | int ret;
|
---|
230 |
|
---|
231 | ddf_msg(LVL_DEBUG, "rootmalta_dev_add, device handle = %d",
|
---|
232 | (int)ddf_dev_get_handle(dev));
|
---|
233 |
|
---|
234 | /*
|
---|
235 | * We need to disable byte swapping of the outgoing and incoming
|
---|
236 | * PCI data, because the PCI driver assumes no byte swapping behind
|
---|
237 | * the scenes and takes care of it itself.
|
---|
238 | */
|
---|
239 | ret = pio_enable((void *) GT_BASE, GT_SIZE, (void **) >);
|
---|
240 | if (ret != EOK)
|
---|
241 | return ret;
|
---|
242 | val = uint32_t_le2host(pio_read_32(
|
---|
243 | >[GT_PCI_CMD / sizeof(ioport32_t)]));
|
---|
244 | val |= GT_PCI_CMD_MBYTESWAP;
|
---|
245 | pio_write_32(
|
---|
246 | >[GT_PCI_CMD / sizeof(ioport32_t)], host2uint32_t_le(val));
|
---|
247 |
|
---|
248 |
|
---|
249 | /* Register functions. */
|
---|
250 | if (!rootmalta_add_functions(dev)) {
|
---|
251 | ddf_msg(LVL_ERROR, "Failed to add functions for the Malta platform.");
|
---|
252 | }
|
---|
253 |
|
---|
254 | return EOK;
|
---|
255 | }
|
---|
256 |
|
---|
257 | static void root_malta_init(void)
|
---|
258 | {
|
---|
259 | ddf_log_init(NAME);
|
---|
260 | rootmalta_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
|
---|
261 | rootmalta_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
|
---|
262 | }
|
---|
263 |
|
---|
264 | int main(int argc, char *argv[])
|
---|
265 | {
|
---|
266 | printf(NAME ": HelenOS Malta platform driver\n");
|
---|
267 | root_malta_init();
|
---|
268 | return ddf_driver_main(&rootmalta_driver);
|
---|
269 | }
|
---|
270 |
|
---|
271 | /**
|
---|
272 | * @}
|
---|
273 | */
|
---|