Changeset da55d5b in mainline
- Timestamp:
- 2010-11-26T15:24:37Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 08f747e, 8e423a2d, bbc28be, c39544a
- Parents:
- b12d3cc
- git-author:
- smekideki@…> (2010-11-26 15:24:37)
- git-committer:
- smekideki@…> (2010-11-26 15:24:37)
- Location:
- uspace/lib/usb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/include/usb/classes/hub.h
rb12d3cc rda55d5b 37 37 38 38 #include <sys/types.h> 39 #include <usb/hcdhubd.h> 39 40 40 41 … … 148 149 } usb_hub_descriptor_t; 149 150 150 /** 151 * Maximum size of usb hub descriptor in bytes 152 */ 153 extern size_t USB_HUB_MAX_DESCRIPTOR_SIZE; 154 155 /** 156 * hub descriptor type 157 */ 158 extern uint8_t USB_HUB_DESCRIPTOR_TYPE; 159 160 /** 161 * @brief create uint8_t array with serialized descriptor 162 * 163 * @param descriptor 164 */ 165 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor); 166 167 /** 168 * @brief create deserialized desriptor structure out of serialized descriptor 169 * 170 * The serialized descriptor must be proper usb hub descriptor, otherwise an eerror might occur. 171 * 172 * @param sdescriptor serialized descriptor 173 */ 174 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor); 151 175 152 176 153 /** @brief usb hub specific request types. … … 215 192 } usb_hub_request_t; 216 193 194 /** 195 * Maximum size of usb hub descriptor in bytes 196 */ 197 extern size_t USB_HUB_MAX_DESCRIPTOR_SIZE; 198 199 /** 200 * @brief create uint8_t array with serialized descriptor 201 * 202 * @param descriptor 203 */ 204 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor); 205 206 /** 207 * @brief create deserialized desriptor structure out of serialized descriptor 208 * 209 * The serialized descriptor must be proper usb hub descriptor, otherwise an eerror might occur. 210 * 211 * @param sdescriptor serialized descriptor 212 */ 213 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor); 214 215 /** 216 * @brief create hub structure instance 217 * 218 * @param device 219 * @return 220 */ 221 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device); 222 217 223 218 224 -
uspace/lib/usb/src/hcdhubd.c
rb12d3cc rda55d5b 36 36 #include <usb/devreq.h> 37 37 #include <usbhc_iface.h> 38 #include <usb/descriptor.h> 38 39 #include <driver.h> 39 40 #include <bool.h> … … 42 43 43 44 #define USB_HUB_DEVICE_NAME "usbhub" 45 46 #define USB_KBD_DEVICE_NAME "hid" 47 48 49 44 50 45 51 /** List of handled host controllers. */ … … 68 74 //********************************************* 69 75 70 71 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor){ 76 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor) { 72 77 //base size 73 78 size_t size = 7; 74 79 //variable size according to port count 75 size_t var_size = descriptor->ports_count / 8 + ((descriptor->ports_count % 8 >0)?1:0);80 size_t var_size = descriptor->ports_count / 8 + ((descriptor->ports_count % 8 > 0) ? 1 : 0); 76 81 size += 2 * var_size; 77 82 uint8_t * result = (uint8_t*) malloc(size); 78 83 //size 79 result[0] =size;84 result[0] = size; 80 85 //descriptor type 81 result[1] =USB_HUB_DESCRIPTOR_TYPE;82 result[2] =descriptor->ports_count;86 result[1] = USB_DESCTYPE_HUB; 87 result[2] = descriptor->ports_count; 83 88 /// @fixme handling of endianness?? 84 result[3] =descriptor->hub_characteristics / 256;85 result[4] =descriptor->hub_characteristics % 256;86 result[5] =descriptor->pwr_on_2_good_time;87 result[6] =descriptor->current_requirement;88 89 90 for (i=0;i<var_size;++i){91 result[7 +i]=descriptor->devices_removable[i];92 } 93 for (i=0;i<var_size;++i){94 result[7 +var_size+i]=255;89 result[3] = descriptor->hub_characteristics / 256; 90 result[4] = descriptor->hub_characteristics % 256; 91 result[5] = descriptor->pwr_on_2_good_time; 92 result[6] = descriptor->current_requirement; 93 94 size_t i; 95 for (i = 0; i < var_size; ++i) { 96 result[7 + i] = descriptor->devices_removable[i]; 97 } 98 for (i = 0; i < var_size; ++i) { 99 result[7 + var_size + i] = 255; 95 100 } 96 101 return result; 97 102 } 98 103 99 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * serialized_descriptor) {100 uint8_t * sdescriptor = (uint8_t*)serialized_descriptor;101 if (sdescriptor[1]!=USB_HUB_DESCRIPTOR_TYPE) return NULL;102 usb_hub_descriptor_t * result = (usb_hub_descriptor_t*) malloc(sizeof (usb_hub_descriptor_t));104 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * serialized_descriptor) { 105 uint8_t * sdescriptor = (uint8_t*) serialized_descriptor; 106 if (sdescriptor[1] != USB_DESCTYPE_HUB) return NULL; 107 usb_hub_descriptor_t * result = (usb_hub_descriptor_t*) malloc(sizeof (usb_hub_descriptor_t)); 103 108 //uint8_t size = sdescriptor[0]; 104 109 result->ports_count = sdescriptor[2]; 105 110 /// @fixme handling of endianness?? 106 111 result->hub_characteristics = sdescriptor[4] + 256 * sdescriptor[3]; 107 result->pwr_on_2_good_time =sdescriptor[5];108 result->current_requirement =sdescriptor[6];109 size_t var_size = result->ports_count / 8 + ((result->ports_count % 8 >0)?1:0);110 result->devices_removable = (uint8_t*) malloc(var_size);111 112 113 for (i=0;i<var_size;++i){114 result->devices_removable[i] = sdescriptor[7 +i];112 result->pwr_on_2_good_time = sdescriptor[5]; 113 result->current_requirement = sdescriptor[6]; 114 size_t var_size = result->ports_count / 8 + ((result->ports_count % 8 > 0) ? 1 : 0); 115 result->devices_removable = (uint8_t*) malloc(var_size); 116 117 size_t i; 118 for (i = 0; i < var_size; ++i) { 119 result->devices_removable[i] = sdescriptor[7 + i]; 115 120 } 116 121 return result; … … 124 129 //********************************************* 125 130 126 127 128 131 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address); 132 133 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) { 134 usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t)); 135 //get parent device 136 /// @TODO this code is not correct 137 device_t * my_hcd = device; 138 while (my_hcd->parent) 139 my_hcd = my_hcd->parent; 140 //dev-> 141 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name); 142 //we add the hub into the first hc 143 //link_t *link_hc = hc_list.next; 144 //usb_hc_device_t *hc = list_get_instance(link_hc, 145 // usb_hc_device_t, link); 146 //must get generic device info 147 148 149 return result; 150 } 129 151 130 152 /** Callback when new device is detected and must be handled by this driver. … … 133 155 * @return Error code.hub added, hurrah!\n" 134 156 */ 135 static int add_device(device_t *dev) 136 { 157 static int add_device(device_t *dev) { 137 158 /* 138 159 * FIXME: use some magic to determine whether hub or another HC … … 146 167 * We are the HC itself. 147 168 */ 148 usb_hc_device_t *hc_dev = malloc(sizeof (usb_hc_device_t));169 usb_hc_device_t *hc_dev = malloc(sizeof (usb_hc_device_t)); 149 170 list_initialize(&hc_dev->link); 150 171 hc_dev->transfer_ops = NULL; … … 168 189 list_append(&hc_dev->link, &hc_list); 169 190 191 //add keyboard 192 /// @TODO this is not correct code 193 194 /* 195 * Announce presence of child device. 196 */ 197 device_t *kbd = NULL; 198 match_id_t *match_id = NULL; 199 200 kbd = create_device(); 201 if (kbd == NULL) { 202 printf("ERROR: enomem\n"); 203 } 204 kbd->name = USB_KBD_DEVICE_NAME; 205 206 match_id = create_match_id(); 207 if (match_id == NULL) { 208 printf("ERROR: enomem\n"); 209 } 210 211 char *id; 212 rc = asprintf(&id, USB_KBD_DEVICE_NAME); 213 if (rc <= 0) { 214 printf("ERROR: enomem\n"); 215 return rc; 216 } 217 218 match_id->id = id; 219 match_id->score = 30; 220 221 add_match_id(&kbd->match_ids, match_id); 222 223 rc = child_device_register(kbd, dev); 224 if (rc != EOK) { 225 printf("ERROR: cannot register kbd\n"); 226 return rc; 227 } 228 229 printf("%s: registered root hub\n", dev->name); 170 230 return EOK; 231 232 233 171 234 } else { 172 235 usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link); … … 178 241 * connected devices. 179 242 */ 180 //insert hub into list 181 //find owner hcd 182 device_t * my_hcd = dev; 183 while(my_hcd->parent) 184 my_hcd = my_hcd->parent; 185 //dev-> 186 printf("%s: owner hcd found: %s\n",hc_driver->name, my_hcd->name); 187 188 189 return ENOTSUP; 243 //insert hub into list 244 //find owner hcd 245 device_t * my_hcd = dev; 246 while (my_hcd->parent) 247 my_hcd = my_hcd->parent; 248 //dev-> 249 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name); 250 my_hcd = dev; 251 while (my_hcd->parent) 252 my_hcd = my_hcd->parent; 253 //dev-> 254 255 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name); 256 257 //create the hub structure 258 usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev); 259 260 261 //append into the list 262 //we add the hub into the first hc 263 list_append(&hub_info->link, &hc->hubs); 264 265 266 267 return EOK; 268 //return ENOTSUP; 190 269 } 191 270 } … … 200 279 * @param address New hub address. 201 280 */ 202 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) 203 { 281 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) { 204 282 printf("%s: setting hub address to %d\n", hc->generic->name, address); 205 283 usb_target_t target = {0, 0}; … … 216 294 217 295 rc = usb_hc_async_control_write_setup(hc, target, 218 &setup_packet, sizeof(setup_packet), &handle);296 &setup_packet, sizeof (setup_packet), &handle); 219 297 if (rc != EOK) { 220 298 return; … … 241 319 /** Check changes on all known hubs. 242 320 */ 243 static void check_hub_changes(void) 244 { 321 static void check_hub_changes(void) { 245 322 /* 246 323 * Iterate through all HCs. … … 248 325 link_t *link_hc; 249 326 for (link_hc = hc_list.next; 250 251 327 link_hc != &hc_list; 328 link_hc = link_hc->next) { 252 329 usb_hc_device_t *hc = list_get_instance(link_hc, 253 330 usb_hc_device_t, link); 254 331 /* 255 332 * Iterate through all their hubs. … … 257 334 link_t *link_hub; 258 335 for (link_hub = hc->hubs.next; 259 260 336 link_hub != &hc->hubs; 337 link_hub = link_hub->next) { 261 338 usb_hcd_hub_info_t *hub = list_get_instance(link_hub, 262 339 usb_hcd_hub_info_t, link); 263 340 264 341 /* … … 282 359 */ 283 360 usb_hc_async_interrupt_in(hc, target, 284 285 361 change_bitmap, byte_length, &actual_size, 362 &handle); 286 363 287 364 usb_hc_async_wait_for(handle); … … 311 388 * @return Error code. 312 389 */ 313 int usb_hcd_main(usb_hc_driver_t *hc) 314 { 390 int usb_hcd_main(usb_hc_driver_t *hc) { 315 391 hc_driver = hc; 316 392 hc_driver_generic.name = hc->name; … … 338 414 * @return Error code. 339 415 */ 340 int usb_hcd_add_root_hub(usb_hc_device_t *dev) 341 { 416 int usb_hcd_add_root_hub(usb_hc_device_t *dev) { 342 417 int rc; 343 418
Note:
See TracChangeset
for help on using the changeset viewer.