Some thoughts on software USB HCI design

I thought I'd make some comment on possible arhcitectures for a generic driver for 8xx & other simple host controllers.

I'd start by dividing the driver into a top half and bottom half. I'd make the top half generic and mimic the OHCI specification. I'd make the bottom half do all the real work and encapsulate all of the hardware specific bits.


top half:
	completely generic as far as hardware;
	no hardware specific code at all

	create an "hcca like" data structure which has pointers to
	lists for control, bulk, interrupt and iso endpoint descriptors.

	the control and bulk lists can be simple pointers.

	unlike ohci, I'd make the interrupt and iso pointers just
	pointers to time ordered lists of ed's.  I think the table ohci
	uses is too complex and hard to understand.  (look what I did
	in my driver for interrupt transactions)

	create endpoint descriptor data structure which contains a head
	and tail pointer to transfer descriptors.  include a physical
	and virtual pointers for the head and tail (eliminates all of the
	v_to_p and p_to_v calls and solves some ugly problems mapping).

	create a transfer descriptor which contains the basic transfers,
	setup, in, out, etc... just like ohci.  I'd make it a little less
	baroque, however.

	no timeouts;  make the bottom half be responsible for timing
	out transactions  (eliminates one set of races)

	the bottom half will, like ohci, move td's from ed's to a "done
	list".  instead of doing h/w interrupts, it can use an upcall
	to signal the top half of events.

	I would also add (initially empty) "hooks" in the code when ed's
	are enqueued and dequeued as well as when td's are enqueued and
	dequeued.

	If this is done cleanly the bottom half could be easily written
	for the SL811, the MPC8xx and even an existing OHCI controller.
	(because, imho, the ohci driver could stand to be rewritten)


	
bottom half:
	completely specific as far as hardware;
	multiple implementations based on actual hardware

	interrupt driven with timeouts done by a thread or h/w timer as
	the case may be.

	when signaled by top half a scheduler runs which scans the various
	list pointers and grabs td's off the lists and processes them,
	moving them to the "done list"...