source: mainline/uspace/drv/infrastructure/rootpc/rootpc.c@ c5bff3c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c5bff3c was 81716eb, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

Mainline changes.

  • Property mode set to 100644
File size: 5.0 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/**
[5f0123b]30 * @defgroup root_pc PC platform driver.
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>
41#include <bool.h>
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>
[3843ecb]52#include <device/hw_res.h>
[eff1a590]53
[178673c]54#define NAME "rootpc"
[eff1a590]55
[68414f4a]56/** Obtain function soft-state from DDF function node */
57#define ROOTPC_FUN(fnode) ((rootpc_fun_t *) (fnode)->driver_data)
58
59typedef struct rootpc_fun {
[b9ccc46d]60 hw_resource_list_t hw_resources;
[68414f4a]61} rootpc_fun_t;
[5cd136ab]62
[0c0f823b]63static int rootpc_dev_add(ddf_dev_t *dev);
[178673c]64static void root_pc_init(void);
[eff1a590]65
[b9ccc46d]66/** The root device driver's standard operations. */
[178673c]67static driver_ops_t rootpc_ops = {
[0c0f823b]68 .dev_add = &rootpc_dev_add
[eff1a590]69};
70
[b9ccc46d]71/** The root device driver structure. */
[178673c]72static driver_t rootpc_driver = {
[eff1a590]73 .name = NAME,
[178673c]74 .driver_ops = &rootpc_ops
[eff1a590]75};
76
[230385c]77static hw_resource_t pci_conf_regs[] = {
78 {
79 .type = IO_RANGE,
80 .res.io_range = {
81 .address = 0xCF8,
82 .size = 4,
83 .endianness = LITTLE_ENDIAN
84 }
85 },
86 {
87 .type = IO_RANGE,
88 .res.io_range = {
89 .address = 0xCFC,
90 .size = 4,
91 .endianness = LITTLE_ENDIAN
92 }
[b9ccc46d]93 }
[5cd136ab]94};
95
[68414f4a]96static rootpc_fun_t pci_data = {
[5cd136ab]97 .hw_resources = {
[230385c]98 sizeof(pci_conf_regs)/sizeof(pci_conf_regs[0]),
99 pci_conf_regs
[5cd136ab]100 }
101};
102
[83a2f43]103static hw_resource_list_t *rootpc_get_resources(ddf_fun_t *fnode)
[9a66bc2e]104{
[68414f4a]105 rootpc_fun_t *fun = ROOTPC_FUN(fnode);
[b9ccc46d]106
[68414f4a]107 assert(fun != NULL);
108 return &fun->hw_resources;
[9a66bc2e]109}
110
[83a2f43]111static bool rootpc_enable_interrupt(ddf_fun_t *fun)
[9a66bc2e]112{
[b9ccc46d]113 /* TODO */
[9a66bc2e]114
115 return false;
116}
117
[8b1e15ac]118static hw_res_ops_t fun_hw_res_ops = {
[d9cf684a]119 .get_resource_list = &rootpc_get_resources,
120 .enable_interrupt = &rootpc_enable_interrupt,
[9a66bc2e]121};
122
[178673c]123/* Initialized in root_pc_init() function. */
[83a2f43]124static ddf_dev_ops_t rootpc_fun_ops;
[3843ecb]125
[b9ccc46d]126static bool
[83a2f43]127rootpc_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id,
[68414f4a]128 rootpc_fun_t *fun)
[5cd136ab]129{
[ebcb05a]130 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
[eff1a590]131
[83a2f43]132 ddf_fun_t *fnode = NULL;
[b9ccc46d]133 match_id_t *match_id = NULL;
[eff1a590]134
[b9ccc46d]135 /* Create new device. */
[97a62fe]136 fnode = ddf_fun_create(dev, fun_inner, name);
[68414f4a]137 if (fnode == NULL)
[eff1a590]138 goto failure;
139
[68414f4a]140 fnode->driver_data = fun;
[eff1a590]141
[b9ccc46d]142 /* Initialize match id list */
143 match_id = create_match_id();
[68414f4a]144 if (match_id == NULL)
[eff1a590]145 goto failure;
[b9ccc46d]146
[eff1a590]147 match_id->id = str_match_id;
148 match_id->score = 100;
[68414f4a]149 add_match_id(&fnode->match_ids, match_id);
[eff1a590]150
[b9ccc46d]151 /* Set provided operations to the device. */
[68414f4a]152 fnode->ops = &rootpc_fun_ops;
[9a66bc2e]153
[8b1e15ac]154 /* Register function. */
[97a62fe]155 if (ddf_fun_bind(fnode) != EOK) {
[ebcb05a]156 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
[eff1a590]157 goto failure;
[97a62fe]158 }
[eff1a590]159
160 return true;
161
162failure:
[68414f4a]163 if (match_id != NULL)
[eff1a590]164 match_id->id = NULL;
165
[97a62fe]166 if (fnode != NULL)
167 ddf_fun_destroy(fnode);
[eff1a590]168
[ebcb05a]169 ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
[eff1a590]170
[b9ccc46d]171 return false;
[eff1a590]172}
173
[83a2f43]174static bool rootpc_add_functions(ddf_dev_t *dev)
[eff1a590]175{
[8b1e15ac]176 return rootpc_add_fun(dev, "pci0", "intel_pci", &pci_data);
[eff1a590]177}
178
179/** Get the root device.
[b9ccc46d]180 *
181 * @param dev The device which is root of the whole device tree (both
182 * of HW and pseudo devices).
183 * @return Zero on success, negative error number otherwise.
[eff1a590]184 */
[0c0f823b]185static int rootpc_dev_add(ddf_dev_t *dev)
[eff1a590]186{
[0c0f823b]187 ddf_msg(LVL_DEBUG, "rootpc_dev_add, device handle = %d",
[ab3a851]188 (int)dev->handle);
[eff1a590]189
[8b1e15ac]190 /* Register functions. */
191 if (!rootpc_add_functions(dev)) {
[ebcb05a]192 ddf_msg(LVL_ERROR, "Failed to add functions for PC platform.");
[eff1a590]193 }
194
[df747b9c]195 return EOK;
[eff1a590]196}
197
[178673c]198static void root_pc_init(void)
[b9ccc46d]199{
[fc51296]200 ddf_log_init(NAME, LVL_ERROR);
[8b1e15ac]201 rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
[3843ecb]202}
203
[eff1a590]204int main(int argc, char *argv[])
205{
[5f0123b]206 printf(NAME ": HelenOS PC platform driver\n");
[178673c]207 root_pc_init();
[83a2f43]208 return ddf_driver_main(&rootpc_driver);
[eff1a590]209}
210
211/**
212 * @}
213 */
Note: See TracBrowser for help on using the repository browser.