Changeset 5cd136ab in mainline
- Timestamp:
- 2010-04-02T13:37:58Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9a66bc2e
- Parents:
- 57937dd
- Location:
- uspace
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/Makefile
r57937dd r5cd136ab 54 54 generic/devmap.c \ 55 55 generic/devman.c \ 56 generic/device/hw_res.c \ 56 57 generic/event.c \ 57 58 generic/errno.c \ -
uspace/lib/libc/generic/devman.c
r57937dd r5cd136ab 28 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 29 */ 30 31 /** @addtogroup libc 32 * @{ 33 */ 34 /** @file 35 */ 30 36 31 37 #include <string.h> … … 193 199 } 194 200 } 201 202 int devman_device_connect(device_handle_t handle, unsigned int flags) 203 { 204 int phone; 205 206 if (flags & IPC_FLAG_BLOCKING) { 207 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN, 208 DEVMAN_CONNECT_TO_DEVICE, handle); 209 } else { 210 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN, 211 DEVMAN_CONNECT_TO_DEVICE, handle); 212 } 213 214 return phone; 215 } 216 217 int devman_parent_device_connect(device_handle_t handle, unsigned int flags) 218 { 219 int phone; 220 221 if (flags & IPC_FLAG_BLOCKING) { 222 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN, 223 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle); 224 } else { 225 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN, 226 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle); 227 } 228 229 return phone; 230 } 231 232 /** @} 233 */ -
uspace/lib/libc/include/devman.h
r57937dd r5cd136ab 48 48 int devman_child_device_register(const char *, match_id_list_t *, device_handle_t, device_handle_t *); 49 49 50 int devman_device_connect(device_handle_t handle, unsigned int flags); 51 int devman_parent_device_connect(device_handle_t handle, unsigned int flags); 52 50 53 51 54 #endif -
uspace/lib/libc/include/ipc/dev_iface.h
r57937dd r5cd136ab 77 77 int irq; 78 78 } intr; 79 } ;79 } res; 80 80 } hw_resource_t; 81 81 82 typedef struct {82 typedef struct hw_resource_list { 83 83 size_t count; 84 84 hw_resource_t *resources; -
uspace/lib/libc/include/ipc/devman.h
r57937dd r5cd136ab 116 116 DEVMAN_DRIVER = 1, 117 117 DEVMAN_CLIENT, 118 DEVMAN_CONNECT_TO_DEVICE 118 DEVMAN_CONNECT_TO_DEVICE, 119 DEVMAN_CONNECT_TO_PARENTS_DEVICE 119 120 } devman_interface_t; 120 121 -
uspace/lib/libdrv/generic/driver.c
r57937dd r5cd136ab 141 141 return; 142 142 } 143 144 145 // TODO - if the client is not a driver, check whether it is allowed to use the device 143 146 144 147 // TODO open the device (introduce some callbacks for opening and closing devices registered by the driver) -
uspace/srv/devman/devman.c
r57937dd r5cd136ab 506 506 if (rc != EOK) { 507 507 // TODO handle error 508 return false;508 return; 509 509 } 510 510 511 511 // TODO inspect return value (ret) to find out whether the device was successfully probed and added 512 512 513 return true;513 return; 514 514 } 515 515 … … 618 618 * @return true on success, false otherwise (insufficient resources etc.). 619 619 */ 620 bool insert_dev_node(dev_tree_t *tree, node_t *node, c onst char *dev_name, node_t *parent)620 bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, node_t *parent) 621 621 { 622 622 printf(NAME ": insert_dev_node\n"); … … 650 650 } 651 651 652 /** 653 * Find device node with a specified path in the device tree. 654 * 655 * @param path the path of the device node in the device tree. 656 * @param tree the device tree. 657 * 658 * @return the device node if it is present in the tree, NULL otherwise. 659 */ 660 node_t * find_dev_node_by_path(dev_tree_t *tree, char *path) 661 { 662 node_t *dev = tree->root_node; 663 char *rel_path = path; 664 char *next_path_elem = NULL; 665 size_t elem_size = 0; 666 bool cont = '/' == rel_path[0]; 667 668 while (cont && NULL != dev) { 669 next_path_elem = get_path_elem_end(rel_path+1); 670 if ('/' == next_path_elem[0]) { 671 cont = true; 672 next_path_elem[0] = 0; 673 } else { 674 cont = false; 675 } 676 677 dev = find_node_child(dev, rel_path); 678 679 if (cont) { 680 next_path_elem[0] = '/'; 681 } 682 rel_path = next_path_elem; 683 } 684 685 return dev; 686 } 687 688 /** 689 * Find child device node with a specified name. 690 * 691 * @param parent the parent device node. 692 * @param name the name of the child device node. 693 * 694 * @return the child device node. 695 */ 696 node_t *find_node_child(node_t *parent, const char *name) 697 { 698 node_t *dev; 699 link_t *link; 700 701 fibril_mutex_lock(&parent->children_mutex); 702 link = parent->children.next; 703 704 while (link != &parent->children) { 705 dev = list_get_instance(link, node_t, sibling); 706 707 if (0 == str_cmp(name, dev->name)) { 708 fibril_mutex_unlock(&parent->children_mutex); 709 return dev; 710 } 711 } 712 713 fibril_mutex_unlock(&parent->children_mutex); 714 return NULL; 715 } 716 652 717 /** @} 653 718 */ -
uspace/srv/devman/devman.h
r57937dd r5cd136ab 238 238 } 239 239 240 /** 241 * Delete a device node. 242 * 243 * @param node a device node structure. 244 * 245 */ 240 246 static inline void delete_dev_node(node_t *node) 241 247 { … … 263 269 } 264 270 271 node_t * find_dev_node_by_path(dev_tree_t *tree, char *path); 272 node_t *find_node_child(node_t *parent, const char *name); 273 265 274 // Device tree 266 275 267 276 bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list); 268 277 bool create_root_node(dev_tree_t *tree); 269 bool insert_dev_node(dev_tree_t *tree, node_t *node, c onst char *dev_name, node_t *parent);278 bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, node_t *parent); 270 279 271 280 #endif -
uspace/srv/devman/main.c
r57937dd r5cd136ab 51 51 #include <ctype.h> 52 52 #include <ipc/devman.h> 53 #include <ipc/driver.h> 53 54 #include <thread.h> 54 55 … … 158 159 { 159 160 int ret = EOK; 160 int i;161 size_t i; 161 162 for (i = 0; i < match_count; i++) { 162 163 if (EOK != (ret = devman_receive_match_id(match_ids))) { … … 257 258 } 258 259 260 static void devman_forward(ipc_callid_t iid, ipc_call_t *icall, bool drv_to_parent) { 261 device_handle_t handle; 262 node_t *dev = find_dev_node(&device_tree, handle); 263 if (NULL == dev) { 264 ipc_answer_0(iid, ENOENT); 265 return; 266 } 267 268 driver_t *driver = NULL; 269 270 if (drv_to_parent) { 271 driver = dev->parent->drv; 272 } else { 273 driver = dev->drv; 274 } 275 276 if (NULL == driver) { 277 ipc_answer_0(iid, ENOENT); 278 return; 279 } 280 281 int method; 282 if (drv_to_parent) { 283 method = DRIVER_DRIVER; 284 } else { 285 method = DRIVER_CLIENT; 286 } 287 288 ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE); 289 } 290 259 291 /** Function for handling connections to device manager. 260 292 * … … 269 301 /*case DEVMAN_CLIENT: 270 302 devmap_connection_client(iid, icall); 271 break; 303 break;*/ 272 304 case DEVMAN_CONNECT_TO_DEVICE: 273 305 // Connect client to selected device 274 devmap_forward(iid, icall); 275 break;*/ 306 devman_forward(iid, icall, false); 307 break; 308 case DEVMAN_CONNECT_TO_PARENTS_DEVICE: 309 // Connect client to selected device 310 devman_forward(iid, icall, true); 311 break; 276 312 default: 277 313 /* No such interface */ -
uspace/srv/devman/util.c
r57937dd r5cd136ab 61 61 return res; 62 62 } 63 64 const char * get_path_elem_end(const char *path) 65 { 66 while (0 != *path && '/' != *path) { 67 path++; 68 } 69 return path; 70 } -
uspace/srv/devman/util.h
r57937dd r5cd136ab 38 38 39 39 char * get_abs_path(const char *base_path, const char *name, const char *ext); 40 const char * get_path_elem_end(const char *path); 40 41 41 42 static inline bool skip_spaces(const char **buf) -
uspace/srv/drivers/rootia32/rootia32.c
r57937dd r5cd136ab 49 49 #include <devman.h> 50 50 #include <ipc/devman.h> 51 #include <ipc/dev_iface.h> 51 52 52 53 #define NAME "rootia32" 54 55 typedef struct rootia32_dev_data { 56 hw_resource_list_t hw_resources; 57 } rootia32_dev_data_t; 53 58 54 59 static bool rootia32_add_device(device_t *dev); … … 68 73 }; 69 74 70 // TODO HW resources 71 static bool rootia32_add_child(device_t *parent, const char *name, const char *str_match_id) { 75 static hw_resource_t pci_conf_regs = { 76 .type = REGISTER, 77 .res.reg = { 78 .address = (void *)0xCF8, 79 .size = 8, 80 .endianness = LITTLE_ENDIAN 81 } 82 }; 83 84 static rootia32_dev_data_t pci_data = { 85 .hw_resources = { 86 1, 87 &pci_conf_regs 88 } 89 }; 90 91 static bool rootia32_add_child( 92 device_t *parent, const char *name, const char *str_match_id, 93 rootia32_dev_data_t *drv_data) 94 { 72 95 printf(NAME ": adding new child device '%s'.\n", name); 73 96 … … 81 104 82 105 child->name = name; 106 child->driver_data = drv_data; 83 107 84 108 // initialize match id list … … 112 136 } 113 137 114 static bool rootia32_add_children(dev )138 static bool rootia32_add_children(device_t *dev) 115 139 { 116 return rootia32_add_child(dev, "pci0", "intel_pci" );140 return rootia32_add_child(dev, "pci0", "intel_pci", &pci_data); 117 141 } 118 142
Note:
See TracChangeset
for help on using the changeset viewer.