source: mainline/uspace/drv/platform/pc/pc.c@ d8513177

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d8513177 was 0f2a9be, checked in by Jiri Svoboda <jiri@…>, 11 years ago

Fix missed things to rename.

  • Property mode set to 100644
File size: 5.4 KB
RevLine 
[eff1a590]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/**
[0f2a9be]30 * @defgroup pc PC platform driver.
[5f0123b]31 * @brief HelenOS PC platform driver.
[eff1a590]32 * @{
33 */
34
35/** @file
36 */
37
38#include <assert.h>
39#include <stdio.h>
40#include <errno.h>
[3e6a98c5]41#include <stdbool.h>
[eff1a590]42#include <fibril_synch.h>
43#include <stdlib.h>
[c47e1a8]44#include <str.h>
[eff1a590]45#include <ctype.h>
46#include <macros.h>
47
[af6b5157]48#include <ddf/driver.h>
[fc51296]49#include <ddf/log.h>
[5cd136ab]50#include <ipc/dev_iface.h>
[41b56084]51#include <ops/hw_res.h>
[26bc0fd1]52#include <ops/pio_window.h>
[eff1a590]53
[2a37b9f]54#define NAME "pc"
[eff1a590]55
[2a37b9f]56typedef struct pc_fun {
[b9ccc46d]57 hw_resource_list_t hw_resources;
[26bc0fd1]58 pio_window_t pio_window;
[2a37b9f]59} pc_fun_t;
[5cd136ab]60
[2a37b9f]61static int pc_dev_add(ddf_dev_t *dev);
[0f2a9be]62static void pc_init(void);
[eff1a590]63
[b9ccc46d]64/** The root device driver's standard operations. */
[2a37b9f]65static driver_ops_t pc_ops = {
66 .dev_add = &pc_dev_add
[eff1a590]67};
68
[b9ccc46d]69/** The root device driver structure. */
[2a37b9f]70static driver_t pc_driver = {
[eff1a590]71 .name = NAME,
[2a37b9f]72 .driver_ops = &pc_ops
[eff1a590]73};
74
[230385c]75static hw_resource_t pci_conf_regs[] = {
76 {
77 .type = IO_RANGE,
78 .res.io_range = {
79 .address = 0xCF8,
80 .size = 4,
[9e470c0]81 .relative = false,
[230385c]82 .endianness = LITTLE_ENDIAN
83 }
84 },
85 {
86 .type = IO_RANGE,
87 .res.io_range = {
88 .address = 0xCFC,
89 .size = 4,
[9e470c0]90 .relative = false,
[230385c]91 .endianness = LITTLE_ENDIAN
92 }
[b9ccc46d]93 }
[5cd136ab]94};
95
[2a37b9f]96static pc_fun_t pci_data = {
[5cd136ab]97 .hw_resources = {
[26bc0fd1]98 sizeof(pci_conf_regs) / sizeof(pci_conf_regs[0]),
[230385c]99 pci_conf_regs
[26bc0fd1]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 }
[5cd136ab]110 }
111};
112
[56fd7cf]113/** Obtain function soft-state from DDF function node */
[2a37b9f]114static pc_fun_t *pc_fun(ddf_fun_t *fnode)
[56fd7cf]115{
116 return ddf_fun_data_get(fnode);
117}
118
[2a37b9f]119static hw_resource_list_t *pc_get_resources(ddf_fun_t *fnode)
[9a66bc2e]120{
[2a37b9f]121 pc_fun_t *fun = pc_fun(fnode);
[b9ccc46d]122
[68414f4a]123 assert(fun != NULL);
124 return &fun->hw_resources;
[9a66bc2e]125}
126
[2a37b9f]127static bool pc_enable_interrupt(ddf_fun_t *fun)
[9a66bc2e]128{
[b9ccc46d]129 /* TODO */
[9a66bc2e]130
131 return false;
132}
133
[2a37b9f]134static pio_window_t *pc_get_pio_window(ddf_fun_t *fnode)
[26bc0fd1]135{
[2a37b9f]136 pc_fun_t *fun = pc_fun(fnode);
[26bc0fd1]137
138 assert(fun != NULL);
139 return &fun->pio_window;
140}
141
[8b1e15ac]142static hw_res_ops_t fun_hw_res_ops = {
[2a37b9f]143 .get_resource_list = &pc_get_resources,
144 .enable_interrupt = &pc_enable_interrupt,
[9a66bc2e]145};
146
[26bc0fd1]147static pio_window_ops_t fun_pio_window_ops = {
[2a37b9f]148 .get_pio_window = &pc_get_pio_window
[26bc0fd1]149};
150
[0f2a9be]151/* Initialized in pc_init() function. */
[2a37b9f]152static ddf_dev_ops_t pc_fun_ops;
[3843ecb]153
[b9ccc46d]154static bool
[2a37b9f]155pc_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id,
156 pc_fun_t *fun_proto)
[5cd136ab]157{
[ebcb05a]158 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
[eff1a590]159
[83a2f43]160 ddf_fun_t *fnode = NULL;
[56fd7cf]161 int rc;
[eff1a590]162
[b9ccc46d]163 /* Create new device. */
[97a62fe]164 fnode = ddf_fun_create(dev, fun_inner, name);
[68414f4a]165 if (fnode == NULL)
[eff1a590]166 goto failure;
167
[2a37b9f]168 pc_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(pc_fun_t));
[56fd7cf]169 *fun = *fun_proto;
[eff1a590]170
[56fd7cf]171 /* Add match ID */
172 rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
173 if (rc != EOK)
[eff1a590]174 goto failure;
[b9ccc46d]175
176 /* Set provided operations to the device. */
[2a37b9f]177 ddf_fun_set_ops(fnode, &pc_fun_ops);
[9a66bc2e]178
[8b1e15ac]179 /* Register function. */
[97a62fe]180 if (ddf_fun_bind(fnode) != EOK) {
[ebcb05a]181 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
[eff1a590]182 goto failure;
[97a62fe]183 }
[eff1a590]184
185 return true;
186
187failure:
[97a62fe]188 if (fnode != NULL)
189 ddf_fun_destroy(fnode);
[eff1a590]190
[ebcb05a]191 ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
[eff1a590]192
[b9ccc46d]193 return false;
[eff1a590]194}
195
[2a37b9f]196static bool pc_add_functions(ddf_dev_t *dev)
[eff1a590]197{
[2a37b9f]198 return pc_add_fun(dev, "pci0", "intel_pci", &pci_data);
[eff1a590]199}
200
201/** Get the root device.
[b9ccc46d]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, negative error number otherwise.
[eff1a590]206 */
[2a37b9f]207static int pc_dev_add(ddf_dev_t *dev)
[eff1a590]208{
[2a37b9f]209 ddf_msg(LVL_DEBUG, "pc_dev_add, device handle = %d",
[56fd7cf]210 (int)ddf_dev_get_handle(dev));
[eff1a590]211
[8b1e15ac]212 /* Register functions. */
[2a37b9f]213 if (!pc_add_functions(dev)) {
[ebcb05a]214 ddf_msg(LVL_ERROR, "Failed to add functions for PC platform.");
[eff1a590]215 }
216
[df747b9c]217 return EOK;
[eff1a590]218}
219
[0f2a9be]220static void pc_init(void)
[b9ccc46d]221{
[267f235]222 ddf_log_init(NAME);
[2a37b9f]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;
[3843ecb]225}
226
[eff1a590]227int main(int argc, char *argv[])
228{
[5f0123b]229 printf(NAME ": HelenOS PC platform driver\n");
[0f2a9be]230 pc_init();
[2a37b9f]231 return ddf_driver_main(&pc_driver);
[eff1a590]232}
233
234/**
235 * @}
236 */
Note: See TracBrowser for help on using the repository browser.