Changeset df747b9c in mainline
- Timestamp:
- 2010-04-23T11:30:25Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5af21c5
- Parents:
- a78fa2a
- Location:
- uspace
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libdrv/generic/driver.c
ra78fa2a rdf747b9c 103 103 static void driver_add_device(ipc_callid_t iid, ipc_call_t *icall) 104 104 { 105 // TODO device state - the driver may detect the device is not actually present 106 // (old non PnP devices) or is not working properly. 107 // We should send such information to device manager. 108 109 ipcarg_t ret; 105 char *dev_name = NULL; 106 int res = EOK; 107 110 108 device_handle_t dev_handle = IPC_GET_ARG1(*icall); 111 109 device_t *dev = driver_create_device(); 112 110 dev->handle = dev_handle; 113 async_string_receive(&dev->name, 0, NULL); 114 add_to_devices_list(dev); 115 if (driver->driver_ops->add_device(dev)) { 111 112 async_string_receive(&dev_name, 0, NULL); 113 dev->name = dev_name; 114 115 add_to_devices_list(dev); 116 res = driver->driver_ops->add_device(dev); 117 if (0 == res) { 116 118 printf("%s: new device with handle = %x was added.\n", driver->name, dev_handle); 117 ret = 1;118 119 } else { 119 printf("%s: failed to add a new device with handle = % x.\n", driver->name, dev_handle);120 printf("%s: failed to add a new device with handle = %d.\n", driver->name, dev_handle); 120 121 remove_from_devices_list(dev); 121 // TODO delete device122 ret = 0;123 }124 ipc_answer_0(iid, EOK);122 delete_device(dev); 123 } 124 125 ipc_answer_0(iid, res); 125 126 } 126 127 … … 270 271 } 271 272 272 boolchild_device_register(device_t *child, device_t *parent)273 int child_device_register(device_t *child, device_t *parent) 273 274 { 274 275 // printf("%s: child_device_register\n", driver->name); … … 276 277 assert(NULL != child->name); 277 278 279 int res; 280 278 281 add_to_devices_list(child); 279 if (EOK == devman_child_device_register(child->name, &child->match_ids, parent->handle, &child->handle)) {280 return true;282 if (EOK == (res = devman_child_device_register(child->name, &child->match_ids, parent->handle, &child->handle))) { 283 return res; 281 284 } 282 285 remove_from_devices_list(child); 283 return false;286 return res; 284 287 } 285 288 -
uspace/lib/libdrv/include/driver.h
ra78fa2a rdf747b9c 109 109 typedef struct driver_ops { 110 110 /** Callback method for passing a new device to the device driver.*/ 111 bool(*add_device)(device_t *dev);111 int (*add_device)(device_t *dev); 112 112 // TODO add other generic driver operations 113 113 } driver_ops_t; … … 161 161 } 162 162 163 boolchild_device_register(device_t *child, device_t *parent);163 int child_device_register(device_t *child, device_t *parent); 164 164 165 165 -
uspace/srv/devman/devman.c
ra78fa2a rdf747b9c 519 519 async_wait_for(req, &rc); 520 520 switch(rc) { 521 // TODO inspect return value to find out whether the device was successfully probed and added522 521 case EOK: 522 node->state = DEVICE_USABLE; 523 break; 523 524 case ENOENT: 524 525 node->state = DEVICE_NOT_PRESENT; 525 526 break; 526 527 default: 528 node->state = DEVICE_INVALID; 527 529 } 528 530 -
uspace/srv/devman/devman.h
ra78fa2a rdf747b9c 93 93 } driver_list_t; 94 94 95 /** The state of the device. */ 96 typedef enum { 97 DEVICE_NOT_INITIALIZED = 0, 98 DEVICE_USABLE, 99 DEVICE_NOT_PRESENT, 100 DEVICE_INVALID 101 } device_state_t; 102 95 103 /** Representation of a node in the device tree.*/ 96 104 struct node { … … 113 121 /** Driver of this device.*/ 114 122 driver_t *drv; 123 /** The state of the device. */ 124 device_state_t state; 115 125 /** Pointer to the previous and next device in the list of devices 116 126 owned by one driver */ -
uspace/srv/devman/main.c
ra78fa2a rdf747b9c 309 309 driver = dev->parent->drv; 310 310 } 311 } else {311 } else if (DEVICE_USABLE == dev->state) { 312 312 driver = dev->drv; 313 assert(NULL != driver); 313 314 } 314 315 315 316 if (NULL == driver) { 316 printf(NAME ": devman_forward error - no driver to connect to.\n", handle);317 printf(NAME ": devman_forward error - the device is not in usable state.\n", handle); 317 318 ipc_answer_0(iid, ENOENT); 318 319 return; … … 331 332 return; 332 333 } 333 printf(NAME ": devman_forward: forward connection to device %s to driver %s with phone %d.\n", 334 dev->pathname, driver->name, driver->phone); 334 printf(NAME ": devman_forward: forward connection to device %s to driver %s.\n", dev->pathname, driver->name); 335 335 ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE); 336 336 } -
uspace/srv/drivers/isa/isa.c
ra78fa2a rdf747b9c 89 89 static device_class_t isa_child_class; 90 90 91 static boolisa_add_device(device_t *dev);91 static int isa_add_device(device_t *dev); 92 92 93 93 /** The isa device driver's standard operations. … … 474 474 } 475 475 476 static boolisa_add_device(device_t *dev)476 static int isa_add_device(device_t *dev) 477 477 { 478 478 printf(NAME ": isa_add_device, device handle = %d\n", dev->handle); … … 482 482 printf(NAME ": finished the enumeration of legacy devices\n", dev->handle); 483 483 484 return true;484 return EOK; 485 485 } 486 486 -
uspace/srv/drivers/pciintel/pci.c
ra78fa2a rdf747b9c 85 85 86 86 87 static boolpci_add_device(device_t *dev);87 static int pci_add_device(device_t *dev); 88 88 89 89 /** The pci bus driver's standard operations. … … 402 402 create_pci_match_ids(dev); 403 403 404 if ( !child_device_register(dev, parent)) {404 if (EOK != child_device_register(dev, parent)) { 405 405 pci_clean_resource_list(dev); 406 406 clean_match_ids(&dev->match_ids); … … 433 433 } 434 434 435 static boolpci_add_device(device_t *dev)435 static int pci_add_device(device_t *dev) 436 436 { 437 437 printf(NAME ": pci_add_device\n"); … … 440 440 if (NULL == bus_data) { 441 441 printf(NAME ": pci_add_device allocation failed.\n"); 442 return false;442 return ENOMEM; 443 443 } 444 444 … … 447 447 printf(NAME ": pci_add_device failed to connect to the parent's driver.\n"); 448 448 delete_pci_bus_data(bus_data); 449 return false;449 return EPARTY; 450 450 } 451 451 … … 456 456 delete_pci_bus_data(bus_data); 457 457 ipc_hangup(dev->parent_phone); 458 return false;458 return EPARTY; 459 459 } 460 460 … … 472 472 ipc_hangup(dev->parent_phone); 473 473 clean_hw_resource_list(&hw_resources); 474 return false;474 return EADDRNOTAVAIL; 475 475 } 476 476 bus_data->conf_data_port = (char *)bus_data->conf_addr_port + 4; … … 484 484 clean_hw_resource_list(&hw_resources); 485 485 486 return true;486 return EOK; 487 487 } 488 488 -
uspace/srv/drivers/root/root.c
ra78fa2a rdf747b9c 52 52 #define NAME "root" 53 53 54 static boolroot_add_device(device_t *dev);54 static int root_add_device(device_t *dev); 55 55 56 56 /** The root device driver's standard operations. … … 67 67 }; 68 68 69 /** Create the device which represents the root of HW device tree. 69 /** Create the device which represents the root of HW device tree. 70 * 70 71 * @param parent parent of the newly created device. 72 * @return 0 on success, negative error number otherwise. 71 73 */ 72 static booladd_platform_child(device_t *parent) {74 static int add_platform_child(device_t *parent) { 73 75 printf(NAME ": adding new child for platform device.\n"); 74 76 77 int res = EOK; 75 78 device_t *platform = NULL; 76 79 match_id_t *match_id = NULL; … … 78 81 // create new device 79 82 if (NULL == (platform = create_device())) { 83 res = ENOMEM; 80 84 goto failure; 81 85 } … … 86 90 // initialize match id list 87 91 if (NULL == (match_id = create_match_id())) { 92 res = ENOMEM; 88 93 goto failure; 89 94 } … … 95 100 96 101 // register child device 97 if (!child_device_register(platform, parent)) { 102 res = child_device_register(platform, parent); 103 if (EOK != res) { 98 104 goto failure; 99 105 } 100 106 101 return true;107 return res; 102 108 103 109 failure: … … 111 117 } 112 118 113 return false;119 return res; 114 120 } 115 121 … … 117 123 * @param dev the device which is root of the whole device tree (both of HW and pseudo devices). 118 124 */ 119 static boolroot_add_device(device_t *dev)125 static int root_add_device(device_t *dev) 120 126 { 121 127 printf(NAME ": root_add_device, device handle = %d\n", dev->handle); 122 128 123 129 // register root device's children 124 if (!add_platform_child(dev)) { 130 int res = add_platform_child(dev); 131 if (EOK != res) { 125 132 printf(NAME ": failed to add child device for platform.\n"); 126 return false;127 133 } 128 134 129 return true;135 return res; 130 136 } 131 137 -
uspace/srv/drivers/rootia32/rootia32.c
ra78fa2a rdf747b9c 59 59 } rootia32_child_dev_data_t; 60 60 61 static boolrootia32_add_device(device_t *dev);61 static int rootia32_add_device(device_t *dev); 62 62 static bool rootia32_init(); 63 63 … … 144 144 145 145 // register child device 146 if ( !child_device_register(child, parent)) {146 if (EOK != child_device_register(child, parent)) { 147 147 goto failure; 148 148 } … … 171 171 172 172 /** Get the root device. 173 * 173 174 * @param dev the device which is root of the whole device tree (both of HW and pseudo devices). 174 */ 175 static bool rootia32_add_device(device_t *dev) 175 * @return 0 on success, negative error number otherwise. 176 */ 177 static int rootia32_add_device(device_t *dev) 176 178 { 177 179 printf(NAME ": rootia32_add_device, device handle = %d\n", dev->handle); … … 182 184 } 183 185 184 return true;186 return EOK; 185 187 } 186 188 -
uspace/srv/drivers/serial/serial.c
ra78fa2a rdf747b9c 93 93 static device_class_t serial_dev_class; 94 94 95 static boolserial_add_device(device_t *dev);95 static int serial_add_device(device_t *dev); 96 96 97 97 /** The serial port device driver's standard operations. … … 123 123 static bool serial_pio_enable(device_t *dev) 124 124 { 125 printf(NAME ": serial_pio_enable =%s\n", dev->name);125 printf(NAME ": serial_pio_enable %s\n", dev->name); 126 126 127 127 serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data; … … 138 138 static bool serial_dev_probe(device_t *dev) 139 139 { 140 printf(NAME ": serial_dev_probe dev =%s\n", dev->name);140 printf(NAME ": serial_dev_probe %s\n", dev->name); 141 141 142 142 serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data; … … 166 166 } 167 167 168 static bool serial_dev_initialize(device_t *dev) 169 { 170 printf(NAME ": serial_dev_initialize dev = %s\n", dev->name); 171 168 static int serial_dev_initialize(device_t *dev) 169 { 170 printf(NAME ": serial_dev_initialize %s\n", dev->name); 171 172 int ret = EOK; 172 173 hw_resource_list_t hw_resources; 173 174 memset(&hw_resources, 0, sizeof(hw_resource_list_t)); … … 176 177 serial_dev_data_t *data = create_serial_dev_data(); 177 178 if (NULL == data) { 178 return false;179 return ENOMEM; 179 180 } 180 181 dev->driver_data = data; … … 184 185 if (dev->parent_phone <= 0) { 185 186 printf(NAME ": failed to connect to the parent driver of the device %s.\n", dev->name); 187 ret = EPARTY; 186 188 goto failed; 187 189 } … … 191 193 if (!get_hw_resources(dev->parent_phone, &hw_resources)) { 192 194 printf(NAME ": failed to get hw resources for the device %s.\n", dev->name); 195 ret = EPARTY; 193 196 goto failed; 194 197 } … … 211 214 if (res->res.io_range.size < REG_COUNT) { 212 215 printf(NAME ": i/o range assigned to the device %s is too small.\n", dev->name); 216 ret = EPARTY; 213 217 goto failed; 214 218 } … … 221 225 if (!irq || !ioport) { 222 226 printf(NAME ": missing hw resource(s) for the device %s.\n", dev->name); 227 ret = EPARTY; 223 228 goto failed; 224 229 } 225 230 226 231 clean_hw_resource_list(&hw_resources); 227 return true;232 return ret; 228 233 229 234 failed: 230 235 serial_dev_cleanup(dev); 231 236 clean_hw_resource_list(&hw_resources); 232 return false; 233 } 234 235 static bool serial_add_device(device_t *dev) 236 { 237 printf(NAME ": serial_add_device, device handle = %d\n", dev->handle); 238 239 if (!serial_dev_initialize(dev)) { 240 return false; 237 return ret; 238 } 239 240 static int serial_add_device(device_t *dev) 241 { 242 printf(NAME ": serial_add_device %s (handle = %d)\n", dev->name, dev->handle); 243 244 int res = serial_dev_initialize(dev); 245 if (EOK != res) { 246 return res; 241 247 } 242 248 243 249 if (!serial_pio_enable(dev)) { 244 250 serial_dev_cleanup(dev); 245 return false; 246 } 251 return EADDRNOTAVAIL; 252 } 253 247 254 248 255 if (!serial_dev_probe(dev)) { 249 256 serial_dev_cleanup(dev); 250 return false;257 return ENOENT; 251 258 } 252 259 253 260 // TODO interrupt and serial port initialization (baud rate etc.) 254 261 255 return true;262 return EOK; 256 263 } 257 264
Note:
See TracChangeset
for help on using the changeset viewer.