source: mainline/uspace/drv/rootia32/rootia32.c@ b9ccc46d

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

Cstyle fixes in rootia32 driver.

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