Changeset 0206d35 in mainline for uspace/lib/usbhost/src/bus.c
- Timestamp:
- 2017-10-25T00:03:57Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c3d926f
- Parents:
- 56db65d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/bus.c
r56db65d r0206d35 66 66 } 67 67 68 int bus_add_ep(bus_t *bus, device_t *device, const usb_endpoint_desc_t *desc)69 {70 assert(bus);71 assert(device);72 73 /* Temporary reference */74 endpoint_t *ep = bus_create_endpoint(bus);75 if (!ep)76 return ENOMEM;77 78 ep->device = device;79 const int err = bus_register_endpoint(bus, ep, desc);80 81 /* drop Temporary reference */82 endpoint_del_ref(ep);83 84 return err;85 }86 87 int bus_remove_ep(bus_t *bus, device_t *dev, usb_target_t target, usb_direction_t dir)88 {89 assert(bus);90 endpoint_t *ep = bus_find_endpoint(bus, dev, target, dir);91 if (!ep)92 return ENOENT;93 94 return bus_unregister_endpoint(bus, ep);95 }96 97 68 int device_set_default_name(device_t *dev) 98 69 { … … 136 107 } 137 108 138 endpoint_t *bus_create_endpoint(bus_t *bus) 139 { 140 assert(bus); 141 142 fibril_mutex_lock(&bus->guard); 109 int bus_add_endpoint(bus_t *bus, device_t *device, const usb_endpoint_desc_t *desc, endpoint_t **out_ep) 110 { 111 int err = ENOMEM; 112 113 assert(bus); 114 assert(device); 115 116 fibril_mutex_lock(&bus->guard); 117 143 118 endpoint_t *ep = bus->ops.create_endpoint(bus); 144 if (ep) { 145 /* Exporting reference */ 146 endpoint_add_ref(ep); 147 } 148 fibril_mutex_unlock(&bus->guard); 149 150 return ep; 151 } 152 153 int bus_register_endpoint(bus_t *bus, endpoint_t *ep, const usb_endpoint_desc_t *desc) 154 { 155 assert(bus); 156 assert(ep); 119 if (!ep) 120 goto err; 157 121 158 122 /* Bus reference */ 159 123 endpoint_add_ref(ep); 160 124 161 fibril_mutex_lock(&bus->guard); 162 const int r = bus->ops.register_endpoint(bus, ep, desc); 163 fibril_mutex_unlock(&bus->guard); 164 165 return r; 166 } 167 168 int bus_unregister_endpoint(bus_t *bus, endpoint_t *ep) 169 { 170 assert(bus); 171 assert(ep); 172 173 fibril_mutex_lock(&bus->guard); 174 const int r = bus->ops.unregister_endpoint(bus, ep); 175 fibril_mutex_unlock(&bus->guard); 176 177 if (r) 178 return r; 179 180 /* Bus reference */ 125 ep->device = device; 126 if ((err = bus->ops.register_endpoint(bus, ep, desc))) 127 goto err_ep; 128 129 if (out_ep) { 130 endpoint_add_ref(ep); 131 *out_ep = ep; 132 } 133 134 fibril_mutex_unlock(&bus->guard); 135 return EOK; 136 137 err_ep: 181 138 endpoint_del_ref(ep); 182 183 return EOK; 139 err: 140 fibril_mutex_unlock(&bus->guard); 141 return err; 184 142 } 185 143 … … 201 159 } 202 160 161 int bus_remove_endpoint(bus_t *bus, endpoint_t *ep) 162 { 163 assert(bus); 164 assert(ep); 165 166 fibril_mutex_lock(&bus->guard); 167 const int r = bus->ops.unregister_endpoint(bus, ep); 168 fibril_mutex_unlock(&bus->guard); 169 170 if (r) 171 return r; 172 173 /* Bus reference */ 174 endpoint_del_ref(ep); 175 176 return EOK; 177 } 178 203 179 int bus_request_address(bus_t *bus, usb_address_t *hint, bool strict, usb_speed_t speed) 204 180 {
Note:
See TracChangeset
for help on using the changeset viewer.