Changeset eb522e8 in mainline for uspace/drv/rootpc/rootpc.c
- Timestamp:
- 2011-06-01T08:43:42Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8d6c1f1
- Parents:
- 9e2e715 (diff), e51a514 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/rootpc/rootpc.c
r9e2e715 reb522e8 28 28 29 29 /** 30 * @defgroup root_ ia32 Root HW device driver for ia32 platform.31 * @brief HelenOS root HW device driver for ia32 platform.30 * @defgroup root_pc PC platform driver. 31 * @brief HelenOS PC platform driver. 32 32 * @{ 33 33 */ … … 46 46 #include <macros.h> 47 47 48 #include <driver.h> 48 #include <ddf/driver.h> 49 #include <ddf/log.h> 49 50 #include <devman.h> 50 51 #include <ipc/devman.h> 51 52 #include <ipc/dev_iface.h> 52 #include < resource.h>53 #include <ops/hw_res.h> 53 54 #include <device/hw_res.h> 54 55 55 #define NAME "rootia32" 56 57 typedef struct rootia32_child_dev_data { 56 #define NAME "rootpc" 57 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 { 58 62 hw_resource_list_t hw_resources; 59 } root ia32_child_dev_data_t;60 61 static int root ia32_add_device(device_t *dev);62 static void root_ ia32_init(void);63 } rootpc_fun_t; 64 65 static int rootpc_add_device(ddf_dev_t *dev); 66 static void root_pc_init(void); 63 67 64 68 /** The root device driver's standard operations. */ 65 static driver_ops_t root ia32_ops = {66 .add_device = &root ia32_add_device69 static driver_ops_t rootpc_ops = { 70 .add_device = &rootpc_add_device 67 71 }; 68 72 69 73 /** The root device driver structure. */ 70 static driver_t root ia32_driver = {74 static driver_t rootpc_driver = { 71 75 .name = NAME, 72 .driver_ops = &root ia32_ops76 .driver_ops = &rootpc_ops 73 77 }; 74 78 … … 82 86 }; 83 87 84 static root ia32_child_dev_data_t pci_data = {88 static rootpc_fun_t pci_data = { 85 89 .hw_resources = { 86 90 1, … … 89 93 }; 90 94 91 static hw_resource_list_t *rootia32_get_child_resources(device_t *dev) 92 { 93 rootia32_child_dev_data_t *data; 94 95 data = (rootia32_child_dev_data_t *) dev->driver_data; 96 if (NULL == data) 97 return NULL; 98 99 return &data->hw_resources; 100 } 101 102 static bool rootia32_enable_child_interrupt(device_t *dev) 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) 103 104 { 104 105 /* TODO */ … … 107 108 } 108 109 109 static resource_iface_t child_res_iface= {110 &root ia32_get_child_resources,111 &root ia32_enable_child_interrupt112 }; 113 114 /* Initialized in root_ ia32_init() function. */115 static d evice_ops_t rootia32_child_ops;110 static hw_res_ops_t fun_hw_res_ops = { 111 &rootpc_get_resources, 112 &rootpc_enable_interrupt 113 }; 114 115 /* Initialized in root_pc_init() function. */ 116 static ddf_dev_ops_t rootpc_fun_ops; 116 117 117 118 static bool 118 root ia32_add_child(device_t *parent, const char *name, const char *str_match_id,119 root ia32_child_dev_data_t *drv_data)120 { 121 printf(NAME ": adding new child device '%s'.\n", name);122 123 d evice_t *child= NULL;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; 124 125 match_id_t *match_id = NULL; 125 126 126 127 /* Create new device. */ 127 child = create_device();128 if ( NULL == child)128 fnode = ddf_fun_create(dev, fun_inner, name); 129 if (fnode == NULL) 129 130 goto failure; 130 131 131 child->name = name; 132 child->driver_data = drv_data; 132 fnode->driver_data = fun; 133 133 134 134 /* Initialize match id list */ 135 135 match_id = create_match_id(); 136 if ( NULL == match_id)136 if (match_id == NULL) 137 137 goto failure; 138 138 139 139 match_id->id = str_match_id; 140 140 match_id->score = 100; 141 add_match_id(& child->match_ids, match_id);141 add_match_id(&fnode->match_ids, match_id); 142 142 143 143 /* Set provided operations to the device. */ 144 child->ops = &rootia32_child_ops; 145 146 /* Register child device. */ 147 if (EOK != child_device_register(child, parent)) 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); 148 149 goto failure; 150 } 149 151 150 152 return true; 151 153 152 154 failure: 153 if ( NULL != match_id)155 if (match_id != NULL) 154 156 match_id->id = NULL; 155 157 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); 158 if (fnode != NULL) 159 ddf_fun_destroy(fnode); 160 161 ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name); 162 162 163 163 return false; 164 164 } 165 165 166 static bool root ia32_add_children(device_t *dev)167 { 168 return root ia32_add_child(dev, "pci0", "intel_pci", &pci_data);166 static bool rootpc_add_functions(ddf_dev_t *dev) 167 { 168 return rootpc_add_fun(dev, "pci0", "intel_pci", &pci_data); 169 169 } 170 170 … … 175 175 * @return Zero on success, negative error number otherwise. 176 176 */ 177 static int root ia32_add_device(device_t *dev)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 "184 "ia32.\n");177 static int rootpc_add_device(ddf_dev_t *dev) 178 { 179 ddf_msg(LVL_DEBUG, "rootpc_add_device, device handle = %d", 180 (int)dev->handle); 181 182 /* Register functions. */ 183 if (!rootpc_add_functions(dev)) { 184 ddf_msg(LVL_ERROR, "Failed to add functions for PC platform."); 185 185 } 186 186 … … 188 188 } 189 189 190 static void root_ia32_init(void) 191 { 192 rootia32_child_ops.interfaces[HW_RES_DEV_IFACE] = &child_res_iface; 190 static void root_pc_init(void) 191 { 192 ddf_log_init(NAME, LVL_ERROR); 193 rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops; 193 194 } 194 195 195 196 int main(int argc, char *argv[]) 196 197 { 197 printf(NAME ": HelenOS rootia32 devicedriver\n");198 root_ ia32_init();199 return d river_main(&rootia32_driver);198 printf(NAME ": HelenOS PC platform driver\n"); 199 root_pc_init(); 200 return ddf_driver_main(&rootpc_driver); 200 201 } 201 202
Note:
See TracChangeset
for help on using the changeset viewer.