rootpc.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010 Lenka Trochtova
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00038 #include <assert.h>
00039 #include <stdio.h>
00040 #include <errno.h>
00041 #include <bool.h>
00042 #include <fibril_synch.h>
00043 #include <stdlib.h>
00044 #include <str.h>
00045 #include <ctype.h>
00046 #include <macros.h>
00047 
00048 #include <ddf/driver.h>
00049 #include <ddf/log.h>
00050 #include <devman.h>
00051 #include <ipc/devman.h>
00052 #include <ipc/dev_iface.h>
00053 #include <ops/hw_res.h>
00054 #include <device/hw_res.h>
00055 
00056 #define NAME "rootpc"
00057 
00059 #define ROOTPC_FUN(fnode) ((rootpc_fun_t *) (fnode)->driver_data)
00060 
00061 typedef struct rootpc_fun {
00062         hw_resource_list_t hw_resources;
00063 } rootpc_fun_t;
00064 
00065 static int rootpc_add_device(ddf_dev_t *dev);
00066 static void root_pc_init(void);
00067 
00069 static driver_ops_t rootpc_ops = {
00070         .add_device = &rootpc_add_device
00071 };
00072 
00074 static driver_t rootpc_driver = {
00075         .name = NAME,
00076         .driver_ops = &rootpc_ops
00077 };
00078 
00079 static hw_resource_t pci_conf_regs = {
00080         .type = IO_RANGE,
00081         .res.io_range = {
00082                 .address = 0xCF8,
00083                 .size = 8,
00084                 .endianness = LITTLE_ENDIAN
00085         }
00086 };
00087 
00088 static rootpc_fun_t pci_data = {
00089         .hw_resources = {
00090                 1,
00091                 &pci_conf_regs
00092         }
00093 };
00094 
00095 static hw_resource_list_t *rootpc_get_resources(ddf_fun_t *fnode)
00096 {
00097         rootpc_fun_t *fun = ROOTPC_FUN(fnode);
00098         
00099         assert(fun != NULL);
00100         return &fun->hw_resources;
00101 }
00102 
00103 static bool rootpc_enable_interrupt(ddf_fun_t *fun)
00104 {
00105         /* TODO */
00106         
00107         return false;
00108 }
00109 
00110 static hw_res_ops_t fun_hw_res_ops = {
00111         &rootpc_get_resources,
00112         &rootpc_enable_interrupt
00113 };
00114 
00115 /* Initialized in root_pc_init() function. */
00116 static ddf_dev_ops_t rootpc_fun_ops;
00117 
00118 static bool
00119 rootpc_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id,
00120     rootpc_fun_t *fun)
00121 {
00122         ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
00123         
00124         ddf_fun_t *fnode = NULL;
00125         match_id_t *match_id = NULL;
00126         
00127         /* Create new device. */
00128         fnode = ddf_fun_create(dev, fun_inner, name);
00129         if (fnode == NULL)
00130                 goto failure;
00131         
00132         fnode->driver_data = fun;
00133         
00134         /* Initialize match id list */
00135         match_id = create_match_id();
00136         if (match_id == NULL)
00137                 goto failure;
00138         
00139         match_id->id = str_match_id;
00140         match_id->score = 100;
00141         add_match_id(&fnode->match_ids, match_id);
00142         
00143         /* Set provided operations to the device. */
00144         fnode->ops = &rootpc_fun_ops;
00145         
00146         /* Register function. */
00147         if (ddf_fun_bind(fnode) != EOK) {
00148                 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
00149                 goto failure;
00150         }
00151         
00152         return true;
00153         
00154 failure:
00155         if (match_id != NULL)
00156                 match_id->id = NULL;
00157         
00158         if (fnode != NULL)
00159                 ddf_fun_destroy(fnode);
00160         
00161         ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
00162         
00163         return false;
00164 }
00165 
00166 static bool rootpc_add_functions(ddf_dev_t *dev)
00167 {
00168         return rootpc_add_fun(dev, "pci0", "intel_pci", &pci_data);
00169 }
00170 
00177 static int rootpc_add_device(ddf_dev_t *dev)
00178 {
00179         ddf_msg(LVL_DEBUG, "rootpc_add_device, device handle = %d",
00180             (int)dev->handle);
00181         
00182         /* Register functions. */
00183         if (!rootpc_add_functions(dev)) {
00184                 ddf_msg(LVL_ERROR, "Failed to add functions for PC platform.");
00185         }
00186         
00187         return EOK;
00188 }
00189 
00190 static void root_pc_init(void)
00191 {
00192         ddf_log_init(NAME, LVL_ERROR);
00193         rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
00194 }
00195 
00196 int main(int argc, char *argv[])
00197 {
00198         printf(NAME ": HelenOS PC platform driver\n");
00199         root_pc_init();
00200         return ddf_driver_main(&rootpc_driver);
00201 }
00202 

Generated on Thu Jun 2 07:45:44 2011 for HelenOS/USB by  doxygen 1.4.7