Commit 3ced0223 authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Resolve porting mistake on initial bus registration

On first registering a new bus in the the NetBSD build of the code usb_kthread_create(usb_create_event_thread, sc) is called which in turn creates the main event thread ("usb_event_thread").
The first thing usb_event_thread() does is set
  sc->sc_bus->needs_explore = 1;
  usb_discover(sc);
however in the RISC OS version of the code (usb.c around line 254) only the first action is performed, no discover happens.
This change schedules a callback via usb_needs_explore_callback() which in turn calls discover_callback() when the OS is next free, which calls usb_discover() for each bus in an equivalent way to NetBSD's event thread. There's then no longer any need for the special one-shot 11s rediscover callback, only the repeating 30s rediscover is needed.

For reference, the places that set needs_explore in this version are all in usb.c
  Line 254: set, but doesn't schedule a callback, as noted above
  Line 339: code not compiled for __riscos
  Line 548: set, does schedule a callback
  Line 727: cleared, in usb_discover()
  Line 743: set, does schedule a callback
  Line 756: code not called in RISC OS

NetBSD uses 500ms initial delay before discover, then 60s between discovers (or until requested by a hub, whichever is sooner).
RISC OS has a periodic callback of 30s (in usbmodule.c) and an initial discover of however long it is from the bus being registered until callbacks next fire usb_event_thread(), assumed ~500ms.

Version 1.07. Tagged as 'NetBSD-1_07'
parent 09c2d619
/* (1.06)
/* (1.07)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.06
#define Module_MajorVersion_CMHG 1.07
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 09 Nov 2015
#define Module_Date_CMHG 12 Nov 2015
#define Module_MajorVersion "1.06"
#define Module_Version 106
#define Module_MajorVersion "1.07"
#define Module_Version 107
#define Module_MinorVersion ""
#define Module_Date "09 Nov 2015"
#define Module_Date "12 Nov 2015"
#define Module_ApplicationDate "09-Nov-15"
#define Module_ApplicationDate "12-Nov-15"
#define Module_ComponentName "NetBSD"
#define Module_ComponentPath "mixed/RiscOS/Sources/HWSupport/USB/NetBSD"
#define Module_FullVersion "1.06"
#define Module_HelpVersion "1.06 (09 Nov 2015)"
#define Module_LibraryVersionInfo "1:6"
#define Module_FullVersion "1.07"
#define Module_HelpVersion "1.07 (12 Nov 2015)"
#define Module_LibraryVersionInfo "1:7"
......@@ -8,5 +8,5 @@
#define EHCIDriverModule_Module_Date_CMHG 04 Nov 2015
#define EHCIDriverModule_MajorVersion_CMHG 0.29
#define USBDriverModule_Module_Date_CMHG 28 Sep 2015
#define USBDriverModule_MajorVersion_CMHG 0.78
#define USBDriverModule_Module_Date_CMHG 12 Nov 2015
#define USBDriverModule_MajorVersion_CMHG 0.79
......@@ -289,10 +289,6 @@ static _kernel_oserror *init_handler(_kernel_swi_regs *r, void *pw, void* h)
_swix (OS_ServiceCall, _INR (0, 1),
Service_USB_USBDriverStarting,
Service_USB);
/* set up a periodic call to re-discover anything lurking */
callx_add_callevery(3000,re_discover,NULL);
/* set up a one off call to re-discover anything lurking early */
callx_add_callafter(1200,re_discover,NULL);
return NULL;
}
......@@ -337,6 +333,9 @@ _kernel_oserror *module_init(const char *cmd_tail, int podule_base, void *pw)
/* do this in a callback so that clients can call our SWIs */
callx_add_callback (init_handler, 0);
/* set up a periodic call to re-discover anything lurking */
callx_add_callevery(3000,re_discover,NULL);
_swix (OS_Claim, _INR(0,2), PointerV, pointerv_entry, pw);
return 0;
......@@ -1128,12 +1127,12 @@ struct device* get_usbdev (int unit)
}
/*---------------------------------------------------------------------------*/
static int rd_active = 0;
static _kernel_oserror *re_discover(_kernel_swi_regs *r, void *pw, void* h)
{
// struct device* dev;
if(rd_active) return NULL;
rd_active++;
static bool rd_active = false;
if (rd_active) return NULL;
rd_active = true;
for (int i = 1; i < usbbus_no; i++)
{
if (get_softc (i << 16) != NULL)
......@@ -1142,7 +1141,7 @@ static _kernel_oserror *re_discover(_kernel_swi_regs *r, void *pw, void* h)
usbioctl (i << 16, USB_DISCOVER, 0, 0, 0);
}
}
rd_active=0;
rd_active = false;
return NULL;
}
......
......@@ -249,8 +249,9 @@ USB_ATTACH(usb)
config_pending_incr();
#ifdef __riscos
/* set the explore flag here since threads don't do anything */
/* set the explore flag here since threads don't do anything */
sc->sc_bus->needs_explore = 1;
usb_needs_explore_callback(sc->sc_bus);
#else
usb_kthread_create(usb_create_event_thread, sc);
#endif
......@@ -543,11 +544,10 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p)
break;
#endif /* USB_DEBUG */
#ifdef __riscos
case USB_DISCOVER:
sc->sc_bus->needs_explore = 1;
usb_needs_explore_callback (sc->sc_bus);
// usb_discover(sc);
break;
case USB_DISCOVER:
sc->sc_bus->needs_explore = 1;
usb_needs_explore_callback(sc->sc_bus);
break;
#endif
case USB_REQUEST:
{
......@@ -567,7 +567,7 @@ usbioctl(dev_t devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p)
if (len < 0 || len > 32768)
return (EINVAL);
if (addr < 0 || addr >= USB_MAX_DEVICES ||
sc->sc_bus->devices[addr] == 0)
sc->sc_bus->devices[addr] == NULL)
return (EINVAL);
if (len != 0) {
iov.iov_base = (caddr_t)ur->ucr_data;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment