Author Topic: [PATCH] defer USB controller reset until done loading everything  (Read 24574 times)

0 Members and 1 Guest are viewing this topic.

r007

  • Observer
  • Posts: 21
As detailed in my support forum post resetting the USB when you still want to load data from it might not be a very bright idea.

This attached patch defers USB resets until setup of fake efi is through.

Issues:
- It's limited to max 10 Controllers of each type (UHCI, EHCI) due to lack of proper dynamically allocated queue
- It lacks a proper dynamically allocated queue ;)

Tell me what you think.

meklort

  • VoodooLabs
  • Posts: 65
Re: [PATCH] defer USB controller reset until done loading everything
« Reply #1 on: July 17, 2010, 06:20:41 PM »
Well, my first comment is that it's probably a bad idea to have this line:
Code: [Select]
memcpy(&gUSBEnqueuedEHCI[gUSBEnqueuedEHCICount++], pci_dev, sizeof(pci_dt_t));
gUSBEnqueuedEHCI is hardcoded to a size of  MAX_USB_DEVICES * sizeof(pci_dt_t), so if you ever have a machine with more than MAX_USB_DEVICES controllers, you're writing to memory that you shouldn't be. The same goes for the other pci_dt_t array.

If you really wanted to, you could change it to
Code: [Select]
if(gUSBEnqueuedEHCICount < MAX_USB_DEVICES ) memcpy(&gUSBEnqueuedEHCI[gUSBEnqueuedEHCICount++], pci_dev, sizeof(pci_dt_t));

I also have an implementation in my branch (http://forge.voodooprojects.org/p/chameleon/source/tree/HEAD/branches/meklort/i386/libsaio/usb.c) for the usb code, and inside of pci_setup.c as well. There is one main bug that I still haven't fixed with it (running the reset on the correct controller, but that's just two lines to fix)


« Last Edit: July 17, 2010, 06:23:36 PM by meklort »
return c ? c : !c;

r007

  • Observer
  • Posts: 21
Re: [PATCH] defer USB controller reset until done loading everything
« Reply #2 on: July 17, 2010, 10:48:38 PM »
Yup, I realize that that is extremely bad code (hey, it took me about an hour to fix what I was looking for...)

All in all I like your code better... (Sure enough, moving the commented-out switch statement from pci_setup.c to usb.c will do for calling the appropriate code for the controller.)

Only one question: shouldn't you be free()ing that array as well after usb_loop() is done?

Any chance this yours gets merged upstream anytime soon?

zef

  • Administrator
  • Posts: 265
Re: [PATCH] defer USB controller reset until done loading everything
« Reply #3 on: July 17, 2010, 11:28:38 PM »
Any chance this yours gets merged upstream anytime soon?

I'm inspecting meklort's changes, and I'd like to merge his md0 ramdisk + usb changes back to the trunk.
ASUS P8Z68-V PRO/GEN3 | i5-2500k | 16GB RAM | GTX560 | Keyboard | Mouse | Devilsound DAC

meklort

  • VoodooLabs
  • Posts: 65
Re: [PATCH] defer USB controller reset until done loading everything
« Reply #4 on: July 17, 2010, 11:49:36 PM »
Only one question: shouldn't you be free()ing that array as well after usb_loop() is done?

There isn't any reason to, the kernel with just reuse it when it's started up (I believe, correct me if I'm wrong).
return c ? c : !c;

koske

  • Entrant
  • Posts: 2
Re: [PATCH] defer USB controller reset until done loading everything
« Reply #5 on: November 09, 2014, 05:33:36 PM »
Hello,
I have the same problem when I want to install Yosemite. How to apply this patch?
Show me UHCI controller.
How to fix this problem? I can not start the installation it keeps restart PC.
thank you