xhci: OS crash after send ENABLE_SLOT command.
xhci: OS crash after send ENABLE_SLOT command.
Hello!
I'm writing a xhci driver for my OS, all of the code runs well on QEMU.
But, when I run my OS on my computer, after the ENABLE_SLOT command sent, it looks like it is stuck.
I can ensure that the interrupt handler of XHCI can work normally, and I can receive the interrupt from the event ring when I reset the port. However, after the ENABLE SLOT command is issued, the handler does not run. Then the system looks jammed.
The code which related to the problem: Line 1326.
https://github.com/fslongjin/DragonOS/b ... ci.c#L1326
And, after I ring the doorbell at Line 1565, the problem come into being:
https://github.com/fslongjin/DragonOS/b ... ci.c#L1565
I have thought for a long time and still can't solve the problem. How can I solve this?
I'm writing a xhci driver for my OS, all of the code runs well on QEMU.
But, when I run my OS on my computer, after the ENABLE_SLOT command sent, it looks like it is stuck.
I can ensure that the interrupt handler of XHCI can work normally, and I can receive the interrupt from the event ring when I reset the port. However, after the ENABLE SLOT command is issued, the handler does not run. Then the system looks jammed.
The code which related to the problem: Line 1326.
https://github.com/fslongjin/DragonOS/b ... ci.c#L1326
And, after I ring the doorbell at Line 1565, the problem come into being:
https://github.com/fslongjin/DragonOS/b ... ci.c#L1565
I have thought for a long time and still can't solve the problem. How can I solve this?
- Demindiro
- Member
- Posts: 96
- Joined: Fri Jun 11, 2021 6:02 am
- Libera.chat IRC: demindiro
- Location: Belgium
- Contact:
Re: xhci: OS crash after send ENABLE_SLOT command.
It's hard to tell what's wrong at a glance, but have you confirmed that the command ring works with No Op TRBs?
Also, it appears you're not assigning any scratchpad pages?
Also, it appears you're not assigning any scratchpad pages?
Re: xhci: OS crash after send ENABLE_SLOT command.
Yeah, the NOP trb can run properly after I ring the doorbell. And, is the scratchpad buffer necessary?Demindiro wrote:It's hard to tell what's wrong at a glance, but have you confirmed that the command ring works with No Op TRBs?
Also, it appears you're not assigning any scratchpad pages?
- Demindiro
- Member
- Posts: 96
- Joined: Fri Jun 11, 2021 6:02 am
- Libera.chat IRC: demindiro
- Location: Belgium
- Contact:
Re: xhci: OS crash after send ENABLE_SLOT command.
It absolutely is. Imagine what would happen to your program if it had no memory / something started randomly overwriting memory in itlongjin wrote:And, is the scratchpad buffer necessary?
Emulators such as QEMU do not need scratchpad buffers since they have access to malloc() which is faster & safer anyways.
Re: xhci: OS crash after send ENABLE_SLOT command.
I haven't thought about this before. The problem solved with your help, thank you!!!Demindiro wrote:
It absolutely is. Imagine what would happen to your program if it had no memory / something started randomly overwriting memory in it
Emulators such as QEMU do not need scratchpad buffers since they have access to malloc() which is faster & safer anyways.
May I ask you another question?
After I reset the port, and try to send ADDRESS_DEVICE again, something came wrong. I received an event TRB, which has completion code=17, trb type=33. It means a Parameter Error. (It can work on QEMU but the computer)
I only want to get the device descriptor, so I only set the slot_context and control EP context in the input_context. How can I solve this?
The code: https://github.com/fslongjin/DragonOS/b ... ci.c#L1379
- Demindiro
- Member
- Posts: 96
- Joined: Fri Jun 11, 2021 6:02 am
- Libera.chat IRC: demindiro
- Location: Belgium
- Contact:
Re: xhci: OS crash after send ENABLE_SLOT command.
QEMU is quite lax and ignores many of the parameters it doesn't need (unlike real hardware).longjin wrote:I received an event TRB, which has completion code=17, trb type=33. It means a Parameter Error. (It can work on QEMU but the computer)
Parameter Error means you didn't properly configure one or more fields in the Input Context. Looking at your code it appears you're not initializing a lot of fields, such as the maximum packet size. If you set the same fields as I do it should work fine (my code is GPLv3 but I give you permission to use it).
Re: xhci: OS crash after send ENABLE_SLOT command.
Hmm, what I do is, copy the slot_context and ep_context from device_context of the port to the input context directly. I think this should contain all the information we need. The function works at the first time. But at the second time, it failed.Demindiro wrote: Looking at your code it appears you're not initializing a lot of fields, such as the maximum packet size. If you set the same fields as I do it should work fine (my code is GPLv3 but I give you permission to use it).
Re: xhci: OS crash after send ENABLE_SLOT command.
And, I try to directly send the ADDRESS_DEVICE command with BSR=0 to the device (just comment out Line 1356~1375), and successfully got the descriptor.
So, why I cannot request the first 8 bytes and reset the device, then set address again, and request all 18 bytes?
So, why I cannot request the first 8 bytes and reset the device, then set address again, and request all 18 bytes?
Re: xhci: OS crash after send ENABLE_SLOT command.
Unfortunately, the controller takes the same shortcut. It copies most fields from the input context as is to the output context,longjin wrote: Hmm, what I do is, copy the slot_context and ep_context from device_context of the port to the input context directly. I think this should contain all the information we need.
I'm almost certain that you can. On the other hand, you could also send a evaluate context cmd instead of resetting the device.longjin wrote: So, why I cannot request the first 8 bytes and reset the device, then set address again, and request all 18 bytes?
Re: xhci: OS crash after send ENABLE_SLOT command.
Hmm, I'll try it. Thank u!!!xeyes wrote: I'm almost certain that you can. On the other hand, you could also send a evaluate context cmd instead of resetting the device.