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

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

Move the device driver framework drivers under "uspace/drv" in the source tree and
"/drv" on the RAM disk.

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