source: mainline/uspace/drv/platform/sun4u/sun4u.c@ c68edd2

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

Define sun4u's pci_conf_regs absolute

We need to pass precise PCI memory and IO ranges to the pci driver,
so pci_conf_regs cannot be relative.

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