Changeset 5debe97 in mainline
- Timestamp:
- 2013-01-27T16:24:25Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fe9d542
- Parents:
- 2745176
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkbd/main.c
r2745176 r5debe97 222 222 devman_handle_t dev_handle = 0; 223 223 224 int rc = usb_resolve_device_handle(devpath, NULL, NULL,&dev_handle);224 int rc = usb_resolve_device_handle(devpath, &dev_handle); 225 225 if (rc != EOK) { 226 226 printf("Device not found or not of USB kind: %s.\n", -
uspace/app/usbinfo/main.c
r2745176 r5debe97 199 199 /* The initialization is here only to make compiler happy. */ 200 200 devman_handle_t handle = 0; 201 int rc = usb_resolve_device_handle(devpath, 202 NULL, NULL, &handle); 201 int rc = usb_resolve_device_handle(devpath, &handle); 203 202 if (rc != EOK) { 204 203 fprintf(stderr, NAME ": device `%s' not found " -
uspace/lib/usb/include/usb/dev.h
r2745176 r5debe97 38 38 #include <usb/usb.h> 39 39 40 int usb_resolve_device_handle(const char *, devman_handle_t *, usb_address_t *, 41 devman_handle_t *); 40 int usb_resolve_device_handle(const char *, devman_handle_t *); 42 41 #endif 43 42 /** -
uspace/lib/usb/src/dev.c
r2745176 r5debe97 36 36 37 37 #define MAX_DEVICE_PATH 1024 38 39 /** Find host controller handle, address and iface number for the device.40 *41 * @param[in] device_handle Device devman handle.42 * @param[out] hc_handle Where to store handle of host controller43 * controlling device with @p device_handle handle.44 * @param[out] address Place to store the device's address45 * @param[out] iface Place to stoer the assigned USB interface number.46 * @return Error code.47 */48 static int usb_get_info_by_handle(devman_handle_t device_handle,49 devman_handle_t *hc_handle, usb_address_t *address, int *iface)50 {51 async_sess_t *parent_sess =52 devman_parent_device_connect(EXCHANGE_ATOMIC, device_handle,53 IPC_FLAG_BLOCKING);54 if (!parent_sess)55 return ENOMEM;56 57 async_exch_t *exch = async_exchange_begin(parent_sess);58 if (!exch) {59 async_hangup(parent_sess);60 return ENOMEM;61 }62 63 usb_address_t tmp_address;64 devman_handle_t tmp_handle;65 int tmp_iface;66 67 if (address) {68 const int ret = usb_get_my_address(exch, &tmp_address);69 if (ret != EOK) {70 async_exchange_end(exch);71 async_hangup(parent_sess);72 return ret;73 }74 }75 76 if (hc_handle) {77 const int ret = usb_get_hc_handle(exch, &tmp_handle);78 if (ret != EOK) {79 async_exchange_end(exch);80 async_hangup(parent_sess);81 return ret;82 }83 }84 85 if (iface) {86 const int ret = usb_get_my_interface(exch, &tmp_iface);87 switch (ret) {88 case ENOTSUP:89 /* Implementing GET_MY_INTERFACE is voluntary. */90 tmp_iface = -1;91 case EOK:92 break;93 default:94 async_exchange_end(exch);95 async_hangup(parent_sess);96 return ret;97 }98 }99 100 if (hc_handle)101 *hc_handle = tmp_handle;102 103 if (address)104 *address = tmp_address;105 106 if (iface)107 *iface = tmp_iface;108 109 async_exchange_end(exch);110 async_hangup(parent_sess);111 112 return EOK;113 }114 115 static inline int usb_get_hc_by_handle(devman_handle_t dev, devman_handle_t *hc)116 {117 return usb_get_info_by_handle(dev, hc, NULL, NULL);118 }119 120 static inline int usb_get_address_by_handle(121 devman_handle_t dev, usb_address_t *address)122 {123 return usb_get_info_by_handle(dev, NULL, address, NULL);124 }125 38 126 39 static bool try_parse_bus_and_address(const char *path, … … 186 99 * @return Error code. 187 100 */ 188 int usb_resolve_device_handle(const char *dev_path, devman_handle_t *out_hc_handle, 189 usb_address_t *out_dev_addr, devman_handle_t *out_dev_handle) 101 int usb_resolve_device_handle(const char *dev_path, devman_handle_t *dev_handle) 190 102 { 191 if (dev_path == NULL ) {103 if (dev_path == NULL || dev_handle == NULL) { 192 104 return EBADMEM; 193 105 } 194 106 195 bool found_hc = false; 196 bool found_addr = false; 197 devman_handle_t hc_handle, dev_handle; 198 usb_address_t dev_addr = -1; 107 devman_handle_t hc; 108 usb_address_t addr = -1; 199 109 int rc; 200 bool is_bus_addr;201 110 char *func_start = NULL; 202 111 char *path = NULL; 203 112 204 113 /* First try the BUS.ADDR format. */ 205 is_bus_addr = try_parse_bus_and_address(dev_path, &func_start, 206 &hc_handle, &dev_addr); 207 if (is_bus_addr) { 208 found_hc = true; 209 found_addr = true; 114 if (try_parse_bus_and_address(dev_path, &func_start, &hc, &addr)) { 210 115 /* 211 116 * Now get the handle of the device. We will need that … … 219 124 * Otherwise, we will 220 125 */ 221 rc = get_device_handle_by_address(hc_handle, dev_addr, 222 &dev_handle);126 127 rc = get_device_handle_by_address(hc, addr, dev_handle); 223 128 if (rc != EOK) { 224 129 return rc; … … 226 131 if (str_length(func_start) > 0) { 227 132 char tmp_path[MAX_DEVICE_PATH]; 228 rc = devman_fun_get_path( dev_handle,133 rc = devman_fun_get_path(*dev_handle, 229 134 tmp_path, MAX_DEVICE_PATH); 230 135 if (rc != EOK) { … … 237 142 } else { 238 143 /* Everything is resolved. Get out of here. */ 239 goto copy_out;144 return EOK; 240 145 } 241 146 } else { … … 247 152 248 153 /* First try to get the device handle. */ 249 rc = devman_fun_get_handle(path, &dev_handle, 0);154 rc = devman_fun_get_handle(path, dev_handle, 0); 250 155 if (rc != EOK) { 251 156 free(path); … … 264 169 } 265 170 266 /* Try to find its host controller. */267 if (!found_hc) {268 rc = usb_get_hc_by_handle(tmp_handle, &hc_handle);269 if (rc == EOK) {270 found_hc = true;271 }272 }273 274 /* Try to get its address. */275 if (!found_addr) {276 rc = usb_get_address_by_handle(tmp_handle, &dev_addr);277 if (rc == 0) {278 found_addr = true;279 }280 }281 282 /* Speed-up. */283 if (found_hc && found_addr) {284 break;285 }286 287 171 /* Remove the last suffix. */ 288 172 char *slash_pos = str_rchr(path, '/'); … … 294 178 free(path); 295 179 296 if (!found_addr || !found_hc) {297 return ENOENT;298 }299 300 copy_out:301 if (out_dev_addr != NULL) {302 *out_dev_addr = dev_addr;303 }304 if (out_hc_handle != NULL) {305 *out_hc_handle = hc_handle;306 }307 if (out_dev_handle != NULL) {308 *out_dev_handle = dev_handle;309 }310 180 311 181 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.