usb: claim port at device initialization time.

This patch makes qemu assign a port when creating the device, not when
attaching it.  For most usb devices this isn't a noticable difference
because they are in attached state all the time.

The change affects usb-host devices which live in detached state while
the real device is unplugged from the host.  They have a fixed port
assigned all the time now instead of getting grabbing one on attach and
releasing it at detach, i.e. they stop floating around at the usb bus.

The change also allows to simplify usb-hub.  It doesn't need the
handle_attach() callback any more to configure the downstream ports.
This can be done at device initialitation time now.  The changed
initialization order (first grab upstream port, then register downstream
ports) also fixes some icky corner cases.  For example it is not possible
any more to plug the hub into one of its own downstream ports.

The usb host adapters must care too.  USBPort->dev being non-NULL
doesn't imply any more the device is in attached state.  The host
adapters must additionally check the USBPort->dev->attached flag.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
8 files changed
tree: 9f7c75abb2c3de0e1f856cdd4179518f1603b04b
  1. audio/
  2. block/
  3. bsd-user/
  4. darwin-user/
  5. default-configs/
  6. docs/
  7. fpu/
  8. fsdev/
  9. gdb-xml/
  10. hw/
  11. libcacard/
  12. linux-headers/
  13. linux-user/
  14. net/
  15. pc-bios/
  16. qapi/
  17. qga/
  18. QMP/
  19. roms/
  20. scripts/
  21. slirp/
  22. sysconfigs/
  23. target-alpha/
  24. target-arm/
  25. target-cris/
  26. target-i386/
  27. target-lm32/
  28. target-m68k/
  29. target-microblaze/
  30. target-mips/
  31. target-ppc/
  32. target-s390x/
  33. target-sh4/
  34. target-sparc/
  35. target-unicore32/
  36. tcg/
  37. tests/
  38. trace/
  39. ui/
  40. .gitignore
  41. .gitmodules
  42. a.out.h
  43. acl.c
  44. acl.h
  45. aes.c
  46. aes.h
  47. aio.c
  48. alpha-dis.c
  49. alpha.ld
  50. arch_init.c
  51. arch_init.h
  52. arm-dis.c
  53. arm-semi.c
  54. arm.ld
  55. async.c
  56. balloon.c
  57. balloon.h
  58. bitmap.c
  59. bitmap.h
  60. bitops.c
  61. bitops.h
  62. block-migration.c
  63. block-migration.h
  64. block.c
  65. block.h
  66. block_int.h
  67. blockdev.c
  68. blockdev.h
  69. bswap.h
  70. bt-host.c
  71. bt-host.h
  72. bt-vhci.c
  73. buffered_file.c
  74. buffered_file.h
  75. cache-utils.c
  76. cache-utils.h
  77. Changelog
  78. check-qdict.c
  79. check-qfloat.c
  80. check-qint.c
  81. check-qjson.c
  82. check-qlist.c
  83. check-qstring.c
  84. cmd.c
  85. cmd.h
  86. CODING_STYLE
  87. compatfd.c
  88. compatfd.h
  89. compiler.h
  90. config.h
  91. configure
  92. console.c
  93. console.h
  94. COPYING
  95. COPYING.LIB
  96. coroutine-gthread.c
  97. coroutine-ucontext.c
  98. coroutine-win32.c
  99. cpu-all.h
  100. cpu-common.h
  101. cpu-defs.h
  102. cpu-exec.c
  103. cpus.c
  104. cpus.h
  105. cris-dis.c
  106. cursor.c
  107. cursor_hidden.xpm
  108. cursor_left_ptr.xpm
  109. cutils.c
  110. def-helper.h
  111. device_tree.c
  112. device_tree.h
  113. dis-asm.h
  114. disas.c
  115. disas.h
  116. dma-helpers.c
  117. dma.h
  118. dyngen-exec.h
  119. elf.h
  120. envlist.c
  121. envlist.h
  122. error.c
  123. error.h
  124. error_int.h
  125. exec-all.h
  126. exec-memory.h
  127. exec.c
  128. gdbstub.c
  129. gdbstub.h
  130. gen-icount.h
  131. HACKING
  132. hmp-commands.hx
  133. host-utils.c
  134. host-utils.h
  135. hpet.h
  136. hppa-dis.c
  137. hppa.ld
  138. i386-dis.c
  139. i386.ld
  140. ia64-dis.c
  141. ia64.ld
  142. input.c
  143. iohandler.c
  144. ioport-user.c
  145. ioport.c
  146. ioport.h
  147. iorange.h
  148. iov.c
  149. iov.h
  150. json-lexer.c
  151. json-lexer.h
  152. json-parser.c
  153. json-parser.h
  154. json-streamer.c
  155. json-streamer.h
  156. kvm-all.c
  157. kvm-stub.c
  158. kvm.h
  159. libfdt_env.h
  160. LICENSE
  161. linux-aio.c
  162. m68k-dis.c
  163. m68k-semi.c
  164. m68k.ld
  165. MAINTAINERS
  166. Makefile
  167. Makefile.dis
  168. Makefile.hw
  169. Makefile.objs
  170. Makefile.target
  171. Makefile.user
  172. memory.c
  173. memory.h
  174. microblaze-dis.c
  175. migration-exec.c
  176. migration-fd.c
  177. migration-tcp.c
  178. migration-unix.c
  179. migration.c
  180. migration.h
  181. mips-dis.c
  182. mips.ld
  183. module.c
  184. module.h
  185. monitor.c
  186. monitor.h
  187. nbd.c
  188. nbd.h
  189. net.c
  190. net.h
  191. notify.c
  192. notify.h
  193. os-posix.c
  194. os-win32.c
  195. osdep.c
  196. osdep.h
  197. oslib-posix.c
  198. oslib-win32.c
  199. path.c
  200. pci-ids.txt
  201. pflib.c
  202. pflib.h
  203. poison.h
  204. posix-aio-compat.c
  205. ppc-dis.c
  206. ppc.ld
  207. ppc64.ld
  208. qapi-schema-guest.json
  209. qapi-schema-test.json
  210. qbool.c
  211. qbool.h
  212. qdict-test-data.txt
  213. qdict.c
  214. qdict.h
  215. qemu-aio.h
  216. qemu-barrier.h
  217. qemu-char.c
  218. qemu-char.h
  219. qemu-common.h
  220. qemu-config.c
  221. qemu-config.h
  222. qemu-coroutine-int.h
  223. qemu-coroutine-lock.c
  224. qemu-coroutine.c
  225. qemu-coroutine.h
  226. qemu-doc.texi
  227. qemu-error.c
  228. qemu-error.h
  229. qemu-ga.c
  230. qemu-img-cmds.hx
  231. qemu-img.c
  232. qemu-img.texi
  233. qemu-io.c
  234. qemu-lock.h
  235. qemu-log.h
  236. qemu-nbd.c
  237. qemu-nbd.texi
  238. qemu-objects.h
  239. qemu-option.c
  240. qemu-option.h
  241. qemu-options.h
  242. qemu-options.hx
  243. qemu-os-posix.h
  244. qemu-os-win32.h
  245. qemu-progress.c
  246. qemu-queue.h
  247. qemu-sockets.c
  248. qemu-tech.texi
  249. qemu-thread-posix.c
  250. qemu-thread-posix.h
  251. qemu-thread-win32.c
  252. qemu-thread-win32.h
  253. qemu-thread.h
  254. qemu-timer-common.c
  255. qemu-timer.c
  256. qemu-timer.h
  257. qemu-tool.c
  258. qemu-x509.h
  259. qemu.sasl
  260. qemu_socket.h
  261. qerror.c
  262. qerror.h
  263. qfloat.c
  264. qfloat.h
  265. qint.c
  266. qint.h
  267. qjson.c
  268. qjson.h
  269. qlist.c
  270. qlist.h
  271. qmp-commands.hx
  272. qobject.h
  273. qstring.c
  274. qstring.h
  275. range.h
  276. readline.c
  277. readline.h
  278. README
  279. rules.mak
  280. rwhandler.c
  281. rwhandler.h
  282. s390-dis.c
  283. s390.ld
  284. savevm.c
  285. sh4-dis.c
  286. softmmu-semi.h
  287. softmmu_defs.h
  288. softmmu_exec.h
  289. softmmu_header.h
  290. softmmu_template.h
  291. sparc-dis.c
  292. sparc.ld
  293. sparc64.ld
  294. spice-qemu-char.c
  295. sysemu.h
  296. targphys.h
  297. tcg-runtime.c
  298. test-coroutine.c
  299. test-qmp-commands.c
  300. test-visitor.c
  301. thunk.c
  302. thunk.h
  303. TODO
  304. trace-events
  305. translate-all.c
  306. uboot_image.h
  307. usb-bsd.c
  308. usb-linux.c
  309. usb-redir.c
  310. usb-stub.c
  311. user-exec.c
  312. VERSION
  313. version.rc
  314. vgafont.h
  315. vl.c
  316. x86_64.ld
  317. xen-all.c
  318. xen-mapcache.c
  319. xen-mapcache.h
  320. xen-stub.c