Page 1 of 3
XeroMouse & hid.usbfd could co-exist?
Posted: Thu Mar 14, 2013 11:48 am
by whose
Hi,
I encountered a rather strange problem with XeroMouse in conjunction with hid.usbfd.
There were some tests to use XeroMouse.usbfd as Kickstart module. So far, it works fine, the Xero Mouse is usable in Early Startup, nice and dandy. After OS boot, it was "kicked out" by hid.usbfd, so I raised the USBA_Priority Tag to 6. After that, XeroMouse stays with the mouse, all fine and dandy again.
BUT, as soon as I disconnect the mouse, the whole system freezes!
I wondered about this for some time, and then I decided to "clean" the system from all unneeded usbfd.
Well, after I disabled hid.usbfd, it works all fine? Disconnecting, reconnecting the mouse for several times, no problems at all
Ok, there is a problem with USB2.0, but I think this is a different matter. With OHCI driven ports, all is nice.
So my question is: Is there anything really wrong with rMouse/XeroMouse, that prevents proper disconnect operation? If not, is there any way to achieve peaceful co-existence with hid.usbfd?
I really have no clue whats going wrong here...
Re: XeroMouse & hid.usbfd could co-exist?
Posted: Thu Mar 14, 2013 12:48 pm
by abalaban
@whose
It's a bug in the (rmouse) code of the Expunge routine. ReRead it carefully and you'll notice that it is accessing some libBase member after it has deleted it... That's BAD

I should probably modify and upload a fixed version of the rMouse driver so that no one else comes to this problem again.
Re: XeroMouse & hid.usbfd could co-exist?
Posted: Thu Mar 14, 2013 1:10 pm
by whose
@alaban:
Ah, dang... thx!
I will correct it for XeroMouse and I could upload a modified rMouse, too.
Re: XeroMouse & hid.usbfd could co-exist?
Posted: Thu Mar 14, 2013 1:56 pm
by whose
Ok, I changed the code to the following:
Code: Select all
/* Expunge the library */
APTR _manager_Expunge(
struct LibraryManagerInterface *Self )
{
struct rMouseBase *libBase;
APTR result;
libBase = (struct rMouseBase *)Self->Data.LibBase;
if ( libBase->rmb_OpenCnt == 0 )
{
/* Undo what the init code did */
if ( libBase->rmb_fdkey ) {
libBase->rmb_IUSBResource->USBResUnregisterFD( libBase->rmb_fdkey );
}
if ( libBase->rmb_IUSBResource ) {
libBase->rmb_IExec->DropInterface( (struct Interface *)libBase->rmb_IUSBResource );
}
if ( libBase->rmb_USBResourceBase ) {
libBase->rmb_IExec->CloseLibrary( libBase->rmb_USBResourceBase );
}
/* Remove Library from Public */
/* Wolfgang : I rearranged some parts here. DeleteLibrary() was called BEFORE
rmb_SegmentList was saved in "result". So there was "something" saved,
but probably not the SegmentList. On top of that, libBase->rmb_IExec
was referenced after deleting the Library, which is probably not very clever.
*/
libBase->rmb_IExec->Remove( (struct Node *)libBase );
//libBase->rmb_IExec->Release();
result = libBase->rmb_SegmentList;
libBase->rmb_IExec->DeleteLibrary( (struct Library *)libBase );
//libBase->rmb_IExec = NULL;
}
else
{
libBase->rmb_Flags |= LIBF_DELEXP;
result = NULL;
}
return( result );
}
I commented out the Release() call, too, as I really dont know what it should do here. Theres nothing Obtain()ed before and I dont find a Release() function within the Exec AutoDocs...
Nonetheless, the result is still the same. As long as hid.usbfd is active, the system freezes as soon as I rip out the Xero mouse. If hid.usbfd is inactive, it works very fine if plugged into an OHCI driven port. I can re-plug it at my wish, no freeze.
Besides that, I investigated regarding the EHCI problem. The mouse might work, BUT, for unknown reason, the "second device" of the mouse is bound to bootkeyboard.usbfd, if I plug it into an EHCI driven port??
What the...

Re: XeroMouse & hid.usbfd could co-exist?
Posted: Thu Mar 14, 2013 2:35 pm
by abalaban
Here is the code from my WacomDriver which I can plug/unplug at will without any crash
Code: Select all
/* Expunge the library */
APTR _manager_Expunge(
struct LibraryManagerInterface *Self )
{
struct WacomTabletBase *libBase;
APTR result;
libBase = (struct WacomTabletBase *)Self->Data.LibBase;
if ( libBase->rmb_OpenCnt == 0 )
{
#if DebugLevel > 0
((struct ExecIFace *)((*(struct ExecBase **)4)->MainInterface))->DebugPrintF(
"--> _manager_Expunge really expunging ( Self = %lx )\n", Self );
#endif
/* Undo what the init code did */
if ( libBase->rmb_fdkey ) {
libBase->rmb_IUSBResource->USBResUnregisterFD( libBase->rmb_fdkey );
}
if ( libBase->rmb_IUSBResource ) {
libBase->rmb_IExec->DropInterface( (struct Interface *)libBase->rmb_IUSBResource );
}
if ( libBase->rmb_USBResourceBase ) {
libBase->rmb_IExec->CloseLibrary( libBase->rmb_USBResourceBase );
}
/* Remove Library from Public */
libBase->rmb_IExec->Remove( (struct Node *)libBase );
result = libBase->rmb_SegmentList;
struct Interface * IExec = (struct Interface*)libBase->rmb_IExec;
libBase->rmb_IExec->DeleteLibrary( (struct Library *)libBase );
IExec->Release();
}
else
{
libBase->rmb_Flags |= LIBF_DELEXP;
result = NULL;
}
#if DebugLevel > 1
((struct ExecIFace *)((*(struct ExecBase **)4)->MainInterface))->DebugPrintF(
"--> _manager_Expunge( Self = %lx Result %lx)\n", Self,result );
#endif
return( result );
}
Releasing the IExec shall be done, in my code I have an Obtain() call in the _manager_Init() function see:
Code: Select all
struct Library *_manager_Init(
struct WacomTabletBase *libBase,
APTR seglist,
struct ExecIFace *IExec )
{
uint32 err;
#if DebugLevel > 0
((struct ExecIFace *)((*(struct ExecBase **)4)->MainInterface))->DebugPrintF(
"--> _manager_Init( LibBase = %lx, seglist = %lx, IExec = %lx )\n", libBase, seglist, IExec );
#endif
libBase->rmb_Type = NT_LIBRARY;
libBase->rmb_Pri = LIBPRI;
libBase->rmb_Name = LIBNAME;
libBase->rmb_Flags = LIBF_SUMUSED|LIBF_CHANGED;
libBase->rmb_Version = LIBVERSION;
libBase->rmb_Revision = LIBREVISION;
libBase->rmb_IdString = VSTRING;
libBase->rmb_SegmentList= seglist;
libBase->rmb_IExec = IExec;
libBase->rmb_IExec->Obtain();
//---------------------------------------------------------------
libBase->rmb_USBResourceBase = IExec->OpenLibrary( "usbresource.library", 1 );
if ( libBase->rmb_USBResourceBase )
{
libBase->rmb_IUSBResource = (struct USBResourceIFace *)IExec->GetInterface( libBase->rmb_USBResourceBase, "main", 1, NULL );
if ( libBase->rmb_IUSBResource )
{
//---------------------------------------------------------------
libBase->rmb_fdkey = libBase->rmb_IUSBResource->USBResRegisterFD(
USBA_FD_Name, LIBNAME,
USBA_FD_Title, VSTRING,
USBA_FD_InterfaceDriver, TRUE,
USBA_ErrorCode, &err,
USBA_VendorID, (ULONG)USB_VENDOR_ID_WACOM,
USBA_Priority, 1,
TAG_DONE
);
if (( libBase->rmb_fdkey != NULL ) || ( libBase->rmb_fdkey == NULL && err == USBERR_ISPRESENT ))
{
return( (struct Library *)libBase );
}
//---------------------------------------------------------------
IExec->DropInterface( (struct Interface *)libBase->rmb_IUSBResource );
}
IExec->CloseLibrary( libBase->rmb_USBResourceBase );
}
//---------------------------------------------------------------
return( NULL );
}
But you are right Obtain()/Release() calls are not documented anywhere in the autodocs. It's difficult to put them there because they are part of the standard methods every Interface provides,. Refer to the wiki or the Library documentation in the SDK.
PS: Yes I know those
Code: Select all
((struct ExecIFace *)((*(struct ExecBase **)4)->MainInterface))->DebugPrintF()
calls are awful but they ensure me that they will always work even if my variable aren't correctly setup yet...
You can look at my WacomDriver code it's available
here
Re: XeroMouse & hid.usbfd could co-exist?
Posted: Thu Mar 14, 2013 3:02 pm
by whose
I changed it again, according to your code.
Same behaviour. Total freeze on unplugging as long as hid.usbfd is active.
I discovered another mistake, I forgot to change the XeroMouse driver to claim by VENDOR/PRODUCT. I changed that, and XeroMouse and bootmouse happily co-exist as Kickstart module. No problems at all, as long as hid.usbfd isnt active.
I suspect hid.usbfd to be the real quirk here...
Re: XeroMouse & hid.usbfd could co-exist?
Posted: Thu Mar 14, 2013 3:14 pm
by abalaban
@whose
By any chance do you have a serial cable that would be able to capture your crash?
It would be really odd that hid.usbfd would cause problem to your driver while it does not on mine... (Note that without an adapted driver a Wacom device will still be recognized as an HID mouse and work in a reduced feature mode).
Does you problem happen with hid.usbfd still present in Kickstart and if you only plug your mouse after complete boot?
Re: XeroMouse & hid.usbfd could co-exist?
Posted: Thu Mar 14, 2013 3:54 pm
by ssolie
abalaban wrote:But you are right Obtain()/Release() calls are not documented anywhere in the autodocs. It's difficult to put them there because they are part of the standard methods every Interface provides,. Refer to the wiki or the Library documentation in the SDK.
There is information in the autodocs which state you must Obtain/Release every Interface you use for each Task/Process.
Also check out
Exec Libraries where information on Interfaces has been merged in. It isn't perfect but it is a good start I think.
Re: XeroMouse & hid.usbfd could co-exist?
Posted: Thu Mar 14, 2013 4:42 pm
by abalaban
ssolie wrote:There is information in the autodocs which state you must Obtain/Release every Interface you use for each Task/Process.
I'm not near my Amiga right now, but IIRC looking for an Obtain or Release section in the autodocs one would not find anything. It seems to me the documentation is located in the exec/GetInterface() autodocs section which is not an obvious place to search if you are not already familiar with the concept.
ssolie wrote:Also check out
Exec Libraries where information on Interfaces has been merged in. It isn't perfect but it is a good start I think.
Yep that's why I was pointing to the wiki (but I admit I can't be bothered to provide the link

)
Re: XeroMouse & hid.usbfd could co-exist?
Posted: Thu Mar 14, 2013 7:05 pm
by whose
abalaban wrote:@whose
By any chance do you have a serial cable that would be able to capture your crash?
I think its time to do some research about the whereabout of my humble old nullmodem cable
It would be really odd that hid.usbfd would cause problem to your driver while it does not on mine... (Note that without an adapted driver a Wacom device will still be recognized as an HID mouse and work in a reduced feature mode).
Its quite similar here. The Xero works with hid.usbfd, to some extend. Scroll wheel and MMB, 4th and 5th button are dysfunctional. It doesnt work correct with bootmouse.usbfd, although it should. I think the format report isnt interpreted correctly, so that the 0x20 in the beginning of each Xero packet is interpreted as button data (but shouldnt).
A quite interesting point is, that XeroMouse and bootmouse work together absolutely flawless. You could even use two mice in the Early Startup (one Xero, one bootmouse), no problems at all.
Does you problem happen with hid.usbfd still present in Kickstart and if you only plug your mouse after complete boot?
This one I didnt check yet, but I will do!