Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/rootpc/rootpc.c

    rebcb05a r41b56084  
    4646#include <macros.h>
    4747
    48 #include <ddf/driver.h>
    49 #include <ddf/log.h>
     48#include <driver.h>
    5049#include <devman.h>
    5150#include <ipc/devman.h>
     
    5655#define NAME "rootpc"
    5756
    58 /** Obtain function soft-state from DDF function node */
    59 #define ROOTPC_FUN(fnode) ((rootpc_fun_t *) (fnode)->driver_data)
    60 
    61 typedef struct rootpc_fun {
     57typedef struct rootpc_child_dev_data {
    6258        hw_resource_list_t hw_resources;
    63 } rootpc_fun_t;
    64 
    65 static int rootpc_add_device(ddf_dev_t *dev);
     59} rootpc_child_dev_data_t;
     60
     61static int rootpc_add_device(device_t *dev);
    6662static void root_pc_init(void);
    6763
     
    8682};
    8783
    88 static rootpc_fun_t pci_data = {
     84static rootpc_child_dev_data_t pci_data = {
    8985        .hw_resources = {
    9086                1,
     
    9389};
    9490
    95 static hw_resource_list_t *rootpc_get_resources(ddf_fun_t *fnode)
    96 {
    97         rootpc_fun_t *fun = ROOTPC_FUN(fnode);
    98        
    99         assert(fun != NULL);
    100         return &fun->hw_resources;
    101 }
    102 
    103 static bool rootpc_enable_interrupt(ddf_fun_t *fun)
     91static hw_resource_list_t *rootpc_get_child_resources(device_t *dev)
     92{
     93        rootpc_child_dev_data_t *data;
     94       
     95        data = (rootpc_child_dev_data_t *) dev->driver_data;
     96        if (NULL == data)
     97                return NULL;
     98       
     99        return &data->hw_resources;
     100}
     101
     102static bool rootpc_enable_child_interrupt(device_t *dev)
    104103{
    105104        /* TODO */
     
    108107}
    109108
    110 static hw_res_ops_t fun_hw_res_ops = {
    111         &rootpc_get_resources,
    112         &rootpc_enable_interrupt
     109static hw_res_ops_t child_hw_res_ops = {
     110        &rootpc_get_child_resources,
     111        &rootpc_enable_child_interrupt
    113112};
    114113
    115114/* Initialized in root_pc_init() function. */
    116 static ddf_dev_ops_t rootpc_fun_ops;
     115static device_ops_t rootpc_child_ops;
    117116
    118117static bool
    119 rootpc_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id,
    120     rootpc_fun_t *fun)
    121 {
    122         ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
    123        
    124         ddf_fun_t *fnode = NULL;
     118rootpc_add_child(device_t *parent, const char *name, const char *str_match_id,
     119    rootpc_child_dev_data_t *drv_data)
     120{
     121        printf(NAME ": adding new child device '%s'.\n", name);
     122       
     123        device_t *child = NULL;
    125124        match_id_t *match_id = NULL;
    126125       
    127126        /* Create new device. */
    128         fnode = ddf_fun_create(dev, fun_inner, name);
    129         if (fnode == NULL)
     127        child = create_device();
     128        if (NULL == child)
    130129                goto failure;
    131130       
    132         fnode->driver_data = fun;
     131        child->name = name;
     132        child->driver_data = drv_data;
    133133       
    134134        /* Initialize match id list */
    135135        match_id = create_match_id();
    136         if (match_id == NULL)
     136        if (NULL == match_id)
    137137                goto failure;
    138138       
    139139        match_id->id = str_match_id;
    140140        match_id->score = 100;
    141         add_match_id(&fnode->match_ids, match_id);
     141        add_match_id(&child->match_ids, match_id);
    142142       
    143143        /* Set provided operations to the device. */
    144         fnode->ops = &rootpc_fun_ops;
    145        
    146         /* Register function. */
    147         if (ddf_fun_bind(fnode) != EOK) {
    148                 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
     144        child->ops = &rootpc_child_ops;
     145       
     146        /* Register child device. */
     147        if (EOK != child_device_register(child, parent))
    149148                goto failure;
    150         }
    151149       
    152150        return true;
    153151       
    154152failure:
    155         if (match_id != NULL)
     153        if (NULL != match_id)
    156154                match_id->id = NULL;
    157155       
    158         if (fnode != NULL)
    159                 ddf_fun_destroy(fnode);
    160        
    161         ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
     156        if (NULL != child) {
     157                child->name = NULL;
     158                delete_device(child);
     159        }
     160       
     161        printf(NAME ": failed to add child device '%s'.\n", name);
    162162       
    163163        return false;
    164164}
    165165
    166 static bool rootpc_add_functions(ddf_dev_t *dev)
    167 {
    168         return rootpc_add_fun(dev, "pci0", "intel_pci", &pci_data);
     166static bool rootpc_add_children(device_t *dev)
     167{
     168        return rootpc_add_child(dev, "pci0", "intel_pci", &pci_data);
    169169}
    170170
     
    175175 * @return              Zero on success, negative error number otherwise.
    176176 */
    177 static int rootpc_add_device(ddf_dev_t *dev)
    178 {
    179         ddf_msg(LVL_DEBUG, "rootpc_add_device, device handle = %d",
     177static int rootpc_add_device(device_t *dev)
     178{
     179        printf(NAME ": rootpc_add_device, device handle = %d\n",
    180180            (int)dev->handle);
    181181       
    182         /* Register functions. */
    183         if (!rootpc_add_functions(dev)) {
    184                 ddf_msg(LVL_ERROR, "Failed to add functions for PC platform.");
     182        /* Register child devices. */
     183        if (!rootpc_add_children(dev)) {
     184                printf(NAME ": failed to add child devices for PC platform.\n");
    185185        }
    186186       
     
    190190static void root_pc_init(void)
    191191{
    192         ddf_log_init(NAME, LVL_ERROR);
    193         rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
     192        rootpc_child_ops.interfaces[HW_RES_DEV_IFACE] = &child_hw_res_ops;
    194193}
    195194
     
    198197        printf(NAME ": HelenOS PC platform driver\n");
    199198        root_pc_init();
    200         return ddf_driver_main(&rootpc_driver);
     199        return driver_main(&rootpc_driver);
    201200}
    202201
Note: See TracChangeset for help on using the changeset viewer.