Commit bad89421 authored by Ben Avison's avatar Ben Avison
Browse files

Merge of Dan Ellis's USB2 sources.

Version 0.22. Tagged as 'NetBSD-0_22'
parent 778cee75
/* (0.21)
/* (0.22)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.2.
*
*/
#define Module_MajorVersion_CMHG 0.21
#define Module_MajorVersion_CMHG 0.22
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 21 Jan 2004
#define Module_MajorVersion "0.21"
#define Module_Version 21
#define Module_MajorVersion "0.22"
#define Module_Version 22
#define Module_MinorVersion ""
#define Module_Date "21 Jan 2004"
......@@ -18,6 +18,6 @@
#define Module_ComponentName "NetBSD"
#define Module_ComponentPath "RiscOS/Sources/HWSupport/USB/NetBSD"
#define Module_FullVersion "0.21"
#define Module_HelpVersion "0.21 (21 Jan 2004)"
#define Module_LibraryVersionInfo "0:21"
#define Module_FullVersion "0.22"
#define Module_HelpVersion "0.22 (21 Jan 2004)"
#define Module_LibraryVersionInfo "0:22"
......@@ -14,8 +14,9 @@
|
dir <obey$dir>
echo starting build
amu_machine all rom debug COMPONENT=USBDriver CFLAGS="-DSTANDALONE"
amu_machine all rom debug COMPONENT=OHCIDriver CFLAGS="-DSTANDALONE"
|amu_machine -f MakeEHCID all debug
amu_machine all rom COMPONENT=USBDriver CFLAGS="-ff -DSTANDALONE" THROWBACK=-throwback
amu_machine all rom COMPONENT=OHCIDriver CFLAGS="-ff -DSTANDALONE" THROWBACK=-throwback
amu_machine all rom COMPONENT=EHCIDriver CFLAGS="-ff -DSTANDALONE" THROWBACK=-throwback
|amu_machine -f MakeEHCID all
|amu_machine -f MakeHUB all
|amu_machine -f MakeHID all
......@@ -14,8 +14,8 @@
|
dir <obey$dir>
echo starting build
amu_machine all rom debug COMPONENT=OHCIDriver CDEBUG="-DDIAGNOSTIC -DDEBUGLIB -DUSB_DEBUG -DOHCI_DEBUG" CFLAGS="-DSTANDALONE -g"
|amu_machine -f MakeEHCID all debug
amu_machine all rom debug COMPONENT=USBDriver CDEBUG="-DDIAGNOSTIC -DDEBUGLIB -DUSB_DEBUG -DOHCI_DEBUG" CFLAGS="-DSTANDALONE -g"
amu_machine all rom debug COMPONENT=USBDriver CDEBUG="-DDIAGNOSTIC -DDEBUGLIB -DUSB_DEBUG -DOHCI_DEBUG" CFLAGS="-g -DSTANDALONE" THROWBACK=-throwback
amu_machine all rom debug COMPONENT=OHCIDriver CDEBUG="-DDIAGNOSTIC -DDEBUGLIB -DUSB_DEBUG -DOHCI_DEBUG" CFLAGS="-g -DSTANDALONE" THROWBACK=-throwback
amu_machine all rom debug COMPONENT=EHCIDriver CDEBUG="-DDIAGNOSTIC -DDEBUGLIB -DUSB_DEBUG -DEHCI_DEBUG" CFLAGS="-g -DSTANDALONE" THROWBACK=-throwback
|amu_machine -f MakeHUB all
|amu_machine -f MakeHID all
......@@ -18,4 +18,5 @@ mkdir -p bin
amu_machine bin.MakeDevs COMPONENT=USBDriver
amu_machine resources RESDIR=rm COMPONENT=OHCIdriver
amu_machine resources RESDIR=rm COMPONENT=USBDriver
amu_machine resources RESDIR=rm COMPONENT=EHCIDriver
......@@ -26,7 +26,7 @@ RDIR = ${RESDIR}.${COMPONENT}
USBDIR = <Lib$Dir>.USB
CINCLUDES = -Itbox:,TCPIPLibs:,^.,OS:
CDEFINES += ${CDEBUG} -DKERNEL -Dpaddr_t=int -D__P(A)=A -DKLD_MODULE -DDISABLE_PACKED
CDEFINES += ${CDEBUG} -DKERNEL -D_KERNEL -Dpaddr_t=int -D__P(A)=A -DKLD_MODULE -DDISABLE_PACKED
CMHGINCLUDES = ${CINCLUDES}
CMHGDEFINES = -DMSGLOC=${MSGLOC} ${CDEBUG}
CFLAGS += -ff -wp -wc -zm -zps1
......@@ -53,6 +53,7 @@ clean:
${WIPE} gpa ${WFLAGS}
${WIPE} bin ${WFLAGS}
${WIPE} linked ${WFLAGS}
${RM} h.ehcimodhead
${RM} h.ohcimodhead
${RM} h.usbmodhead
${RM} Resources.<Locale>.USBDevs
......@@ -84,6 +85,11 @@ resources_OHCIDriver: LocalRes:OHCIMessages
${CP} LocalRes:OHCIMessages ${RDIR}.Messages ${CPFLAGS}
@echo ${COMPONENT}: resource files copied
resources_EHCIDriver: LocalRes:EHCIMessages
${MKDIR} ${RDIR}
${CP} LocalRes:EHCIMessages ${RDIR}.Messages ${CPFLAGS}
@echo ${COMPONENT}: resource files copied
resources_USBDriver: LocalRes:USBDriver ${DEVICELIST}
${MKDIR} ${RDIR}
${CP} LocalRes:USBMessages ${RDIR}.Messages ${CPFLAGS}
......@@ -101,6 +107,7 @@ o._dirs:
${MKDIR} bin
${TOUCH} o._dirs
ehcimodule.o: ehcimodhead.h
ohcimodule.o: ohcimodhead.h USBDriver.h
usbmodule.o usbkboard.o: usbmodhead.h
......@@ -123,6 +130,9 @@ usbmsgs.o: Resources.<Locale>.USBMessages Resources.<Locale>.USBDevs
ohcimsgs.o: Resources.<Locale>.OHCIMessages
resgen resource_files o.ohcimsgs Resources.<Locale>.OHCIMessages ${MSGLOC}
ehcimsgs.o: Resources.<Locale>.EHCIMessages
resgen resource_files o.ehcimsgs Resources.<Locale>.EHCIMessages ${MSGLOC}
# RISC OS debug:
aif.${COMPONENT}: ${RAM_OBJS} ${RAM_LIBS} ${CLIB} ${DIRS}
link -base 0 -aif -bin -d -o $@ ${RAM_OBJS} ${RAM_LIBS} ${CLIB}
......@@ -136,7 +146,7 @@ debug: gpa.${COMPONENT} ${DIRS}
.c.i:; ${CC} -E ${CFLAGS} $< > $@
listing: i.ohci i.ohcimodule i.usb i.usbdi i.usbdi_util i.usb_subr i.ugen i.usbmodule
listing: i.ohci i.ohcimodule i.usb i.usbdi i.usbdi_util i.usb_subr i.ugen i.usbmodule i.ehcimodule
# Dynamic dependencies:
OBJS = \
ehcimodhead.o \
ehcimodule.o \
ehci.o \
port.o \
call_veneer.o \
triggercbs.o
......@@ -8,11 +8,9 @@ usb_subr.o \
usbdi_util.o \
usb_quirks.o \
uhub.o \
ums.o \
usbmouse.o \
usbkboard.o \
hid.o \
bufman.o \
triggercbs.o \
usbmsgs.o
#ugen.o
File added
No preview for this file type
......@@ -2,8 +2,11 @@
VersionNum file really,as a work around define them here so the CMHG
file remains unaltered */
#define OHCIDriverModule_Module_Date_CMHG 16 Jun 2003
#define OHCIDriverModule_MajorVersion_CMHG 0.14
#define OHCIDriverModule_Module_Date_CMHG 21 Jan 2004
#define OHCIDriverModule_MajorVersion_CMHG 0.16
#define USBDriverModule_Module_Date_CMHG 07 Jan 2004
#define EHCIDriverModule_Module_Date_CMHG 21 Jan 2004
#define EHCIDriverModule_MajorVersion_CMHG 0.01
#define USBDriverModule_Module_Date_CMHG 21 Jan 2004
#define USBDriverModule_MajorVersion_CMHG 0.26
/* Copyright 2004 Castle Technology Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ehcimodhead.h"
#include "USBDriver.h"
#include "swis.h"
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <machine/bus.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdivar.h>
#include <dev/usb/ehcireg.h>
#include <dev/usb/ehcivar.h>
#include "Global/RISCOS.h"
#include "Global/HALEntries.h"
#include "Interface/PCI.h"
#include "callx/callx.h"
/* Have to avoid including stdio as there's a clash with the BSD stuff */
#define __stdio_h
#include "DebugLib/DebugLib.h"
#include "service.h"
#include "oslib/devicefs.h"
extern uint64_t gettime (void);
/* for debugging */
#ifdef EHCI_DEBUG
extern int ehcidebug;
int usbdebug;
uint32_t irq0;
int irq_device;
int irq_buf;
#endif
void* private_word;
volatile int* ehci_base;
ehci_softc_t ehci_soft;
struct device * usb_soft;
extern int * init_veneer (void);
#ifdef EHCI_DEBUG
extern void ehci_dump_regs (ehci_softc_t *);
//extern void ehci_dump_ed (ehci_soft_ed_t*);
#endif
extern void ehci_abort_xfer (void*, int);
int* magic = NULL;
void build_veneer (int* vn, int* st, size_t sz)
{
int i;
dprintf (("", "writing veneer from %p at %p\n", st, vn));
int* entry_table = vn + sz / sizeof (void*);
for (i = 0; i < sz / sizeof (void*); ++i) {
int* entry = entry_table + 2 * i;
/* copy function pointer into veneer */
vn[i] = st[i];
/* copy new pointer into structure */
st[i] = (int) entry;
/* LDR ip, function[i] */
entry[0] = 0xe51fC000 /* LDR ip, [pc, #-0] */
+ 8 /* go back to current instruction */
+ i * 8 /* go back to beginning of veneers */
+ sz /* go back to beginning of struct */
- i * 4; /* go to func pointer */
/* B common */
entry[1] = 0xea000000 /* B here + 8 */
| ((magic - entry - 1) & 0x00ffffff);
/* branch to diff */
}
}
int pci_device = 0;
int instance = 0;
int device_number;
int unhandled_irqs;
_kernel_oserror* new_instance (_kernel_swi_regs* r, void* pw)
{
_kernel_oserror * e;
(void) r;
(void) pw;
// allow enough space for name, % and number, then space, and
// another number
char name[sizeof Module_Title + 1 + 12 + 1 + 12];
sprintf (name, Module_Title"%%%d %d", instance + 1, pci_device);
dprintf (("Main_0", "Trying to start %s\n", name));
e = _swix (OS_Module, _INR(0,1), 14, name);
if (e)
{
dprintf (("", "Failed to start %s: %s\n", name, e->errmess));
}
return NULL;
}
_kernel_oserror *module_init(const char *cmd_tail, int podule_base, void *pw) {
_kernel_oserror* e = 0;
callx_init (pw);
/* set up debugging */
debug_initialise ("EHCIDriver", 0, 0);
debug_set_device(DEBUGIT_OUTPUT);
debug_set_unbuffered_files (TRUE);
dprintf (("Main_0", "Starting driver\n"));
/* simulate having one OHCI device attached. This section has to
communicate with HAL or podule manager to find out where it can read/write to some OHCI registers */
/* assume podule_base is actually instantiation number - how to do this
in a HAL world? If we're the first instance, then search for devices
on the PCI bus */
instance = podule_base;
/* if we're the first instance, then start searching from device # 0,
otherwise the device to start searching from was passed as a string
in the command tail */
if (podule_base != 0)
{
pci_device = atoi (cmd_tail);
}
/* quick bodge */
if (pci_device == 10)
{
pci_device = 13;
}
else
do {
e = _swix(PCI_FindByClass, _INR(0,1)|_IN(3)|_OUT(3),
0x0C0320,
0xFFFFFF,
pci_device,
&pci_device);
if (e) return e;
} while (0);//pci_device == 2 || pci_device == 3);
/* if there were no more OHCI controllers, then return an error. This
will be thrown away by the callback above */
if (pci_device == 0)
{
return (_kernel_oserror*) "\0\0\0\0No EHCI devices found";
}
dprintf (("Main_0", "Found EHCI controller on device %d\n", pci_device));
/* now establish our interrupt and address */
e = _swix(PCI_ReadInfo, _INR(0,3),
PCI_ReadInfo_IntDeviceVector,
&device_number,
sizeof device_number,
pci_device);
if (e) goto error;
dprintf (("Main_0", "interrupt device %d\n", device_number));
e = _swix(PCI_HardwareAddress, _INR(0,1)|_IN(3)|_OUT(4),
0, 0, pci_device, &ehci_base);
if (e) goto error;
dprintf (("Main_0", "hardware address %p\n", ehci_base));
memset (&ehci_soft, 0, sizeof ehci_soft);
sprintf (ehci_soft.sc_bus.bdev.dv_xname, "EHCI%d", instance);
private_word = pw;
#ifdef EHCI_DEBUG
usbdebug = ehcidebug = atoi (getenv ("ehcidebug"));
irq0 = gettime () / 1000;
struct dev_struct {
devicefs_device dev;
int null;
char name[32];
}* dev = calloc (sizeof *dev, 1);
strcpy (dev->name, ehci_soft.sc_bus.bdev.dv_xname);
dev->dev.name_offset = dev->name - (char*) dev;
dev->dev.flags = 3;
dev->dev.tx_flags = 0x8;
dev->dev.tx_buffer_size = 0;
dev->dev.rx_flags = 0x8;
dev->dev.rx_buffer_size = 1024;
e = _swix (DeviceFS_Register, _INR (0, 7) | _OUT(0),
4,
dev,
driver_entry,
NULL,
pw,
NULL,
INT_MAX, // XXX should be -1, but that doesn't seem to work
INT_MAX,
&irq_device);
#endif
_swix (OS_ClaimDeviceVector, _INR(0,4),
device_number| (1u<<31), usb_irq_entry, pw, 0, 0);
_swix (OS_Hardware, _IN(0) | _INR(8,9),
device_number, 0, EntryNo_HAL_IRQEnable);
if ((magic = init_veneer ()) == NULL)
{
return (_kernel_oserror*) "\0\0\0\0Couldn't claim magic";
}
dprintf (("", "magic at %p", magic));
/* fix n companions */
ehci_soft.sc_ncomp = 2;
/* in BSD this is called from sys/pci/ehci_pci.c */
ehci_init (&ehci_soft);
/* register with the usbdriver module if it's already resident */
dprintf (("Main_0", "Registering with USB driver\n"));
_swix (USBDriver_RegisterBus, _IN(0)|_OUT(0),
&ehci_soft, &usb_soft);
dprintf (("Main_0", "Finished module initialisation\n"));
/* try and start a new instance to catch any more controllers on the bus */
_swix (OS_AddCallBack, _INR(0,1), new_entry, pw);
return 0;
error:
dprintf (("Failed initialisation: %s\n", e->errmess));
return e;
}
_kernel_oserror *module_final(int fatal, int podule, void *pw)
{
if (magic) _swix (OS_Module, _IN(0)|_IN(2), 7, magic);
_swix (OS_Hardware, _IN(0) | _INR(8,9),
device_number, 0, EntryNo_HAL_IRQDisable);
_swix (OS_ReleaseDeviceVector, _INR(0,4),
device_number | (1u<<31), usb_irq_entry, pw, 0, 0);
if (usb_soft != NULL)
_swix (USBDriver_DeRegisterBus, _IN(0), usb_soft);
callx_remove_all_callbacks ();
callx_remove_all_callafters ();
callx_remove_all_calleverys ();
return NULL;
}
void module_services(int service_number, _kernel_swi_regs *r, void *pw)
{
switch (r->r[0]) {
case Service_USBDriver_Starting:
if (usb_soft == NULL)
{
dprintf (("Main_0", "Registering with USB driver\n"));
_swix (USBDriver_RegisterBus, _IN(0)|_OUT(0),
&ehci_soft, &usb_soft);
}
break;
case Service_USBDriver_Dying:
dprintf (("", "Deregistering with USB driver\n"));
_swix (USBDriver_DeRegisterBus, _IN(0), usb_soft);
usb_soft = NULL;
memset (&ehci_soft, 0, sizeof ehci_soft);
sprintf (ehci_soft.sc_bus.bdev.dv_xname, "OHCI%d", instance);
ehci_init (&ehci_soft);
break;
}
}
#define OREAD(o) ehci_base[o/4]
_kernel_oserror *module_commands(const char *arg_string, int argc, int cmd_no, void *pw)
{
ehci_softc_t* sc = &ehci_soft;
switch (cmd_no) {
case CMD_EHCIRegs:
printf
(
" PCI device %8d\n"
" Unhandled IRQs %8d\n"
"%2X USB Command %8.8X\n"
"%2X USB Status %8.8X\n"
"%2X USB Interrupt Enable %8.8X\n"
"%2X USB Frame Index %8.8X\n"
"%2X 4G Segment Selector %8.8X\n"
"%2X Frame List Base Addres %8.8X\n"
"%2X Next Asynch List %8.8X\n"
// "%2X Config flag %8.8X\n"
"%2X Port1 %8.8X\n"
"%2X Port2 %8.8X\n"
"%2X Port3 %8.8X\n"
"%2X Port4 %8.8X\n"
"%2X Port5 %8.8X\n"
"%2X Port6 %8.8X\n",
pci_device,
unhandled_irqs,
EHCI_USBCMD, EOREAD4(sc, EHCI_USBCMD),
EHCI_USBSTS, EOREAD4(sc, EHCI_USBSTS),
EHCI_USBSTS, EOREAD4(sc, EHCI_USBINTR),
EHCI_FRINDEX, EOREAD4(sc, EHCI_FRINDEX),
EHCI_CTRLDSSEGMENT, EOREAD4(sc, EHCI_CTRLDSSEGMENT),
EHCI_PERIODICLISTBASE, EOREAD4(sc, EHCI_PERIODICLISTBASE),
EHCI_ASYNCLISTADDR, EOREAD4(sc, EHCI_ASYNCLISTADDR),
EHCI_PORTSC(1), EOREAD4(sc, EHCI_PORTSC(1)),
EHCI_PORTSC(2), EOREAD4(sc, EHCI_PORTSC(2)),
EHCI_PORTSC(3), EOREAD4(sc, EHCI_PORTSC(3)),
EHCI_PORTSC(4), EOREAD4(sc, EHCI_PORTSC(4)),
EHCI_PORTSC(5), EOREAD4(sc, EHCI_PORTSC(5)),
EHCI_PORTSC(6), EOREAD4(sc, EHCI_PORTSC(6))
);
#ifdef EHCI_DEBUG
ehci_dump_regs (&ehci_soft);
break;
case CMD_EHCIDebug:
{
char* ptr;
ehcidebug = (int) strtoul (arg_string, &ptr, 0);
if (ptr) usbdebug = (int) strtoul (ptr, &ptr, 0);
}
#endif
break;
// case CMD_OHCIEDS:
// {
//#ifdef EHCI_DEBUG
// ehci_soft_ed_t* sed;
// sed = ehci_soft.sc_isoc_head;
// while (sed != NULL) {
// ehci_dump_ed(sed);
// sed = sed->next;
// }
// sed = ehci_soft.sc_ctrl_head;
// while (sed != NULL) {
//
// ehci_dump_ed(sed);
// sed = sed->next;
// }
// sed = ehci_soft.sc_bulk_head;
// while (sed != NULL) {
// ehci_dump_ed(sed);
// sed = sed->next;
// }
//#endif
// break;
// }
// case CMD_OHCIWrite:
// {
// int a, b;
// char* ptr;
// a = (int) strtoul (arg_string, &ptr, 16);
// b = (int) strtoul (ptr, 0, 16);
// printf ("writing %x to %x\n", b, a);
// ehci_base[a / 4] = b;
// }
// break;
// default:
// break;
}
return 0;
}
int usb_irq_handler(_kernel_swi_regs *r, void *pw)
{
int ret;
// ehci_intr returns 0 for failure, 1 for success, the inverse of what
// we're expected to return
#ifdef EHCI_DEBUG
int u2s, u2s1;
_swix (OS_Hardware, _INR(8,9)|_OUT(0),
0, EntryNo_HAL_CounterRead, &u2s);
// irqs++;
ehci_softc_t* sc = &ehci_soft;
// if (ehcidebug > 1) dprintf (("", "Frame index: %x\n",
// EOREAD4(sc, EHCI_FRINDEX)));
#endif
ret = !ehci_intr (&ehci_soft);
#ifdef EHCI_DEBUG
if (ret)
{
unhandled_irqs++;
}
else
{
_swix (OS_Hardware, _INR(8,9)|_OUT(0),
0, EntryNo_HAL_CounterRead, &u2s1);
int t = (u2s - u2s1) * 5;
if (t < 0) t += 10000000; /* it wrapped */
if (ehcidebug > 1) dprintf(("", "irq for: %d nsecs\n", t));
if (irq_buf)
{
_swix (OS_CallAVector, _INR(1,3)|_IN(9),
irq_buf | (1<<31),
(int [2]) { gettime () / 1000 - irq0, t},
8,
20);
}
// irq_tot += t;
// if (t < irq_min) irq_min = t;
// if (t > irq_max) irq_max = t;
}
#endif
return ret;
}
void bus_space_write_4 (bus_space_tag_t iot, bus_space_handle_t ioh, int o, int x)
{
#ifdef EHCI_DEBUG
if (ehcidebug > 10)
dprintf (("", "write %x to %p\n", x, ehci_base + o/4));
#endif
ehci_base[o/4] = x;
}
int bus_space_read_4 (bus_space_tag_t iot, bus_space_handle_t ioh, int o)
{
#ifdef EHCI_DEBUG
if (ehcidebug > 15)
dprintf (("", "read %x from %p\n", ehci_base[o/4], ehci_base + o/4));
#endif
return ehci_base[o/4];
}
void bus_space_write_2 (bus_space_tag_t iot, bus_space_handle_t ioh, int o, int x)
{
#ifdef EHCI_DEBUG
if (ehcidebug > 10)
dprintf (("", "write %x to %p\n", x, ((uint16_t*) ehci_base) + o/2));
#endif
((uint16_t*) ehci_base)[o/2] = x;
}
int bus_space_read_2 (bus_space_tag_t iot, bus_space_handle_t ioh, int o)
{
#ifdef EHCI_DEBUG
if (ehcidebug > 15)
dprintf (("", "read %x from %p\n",
((uint16_t*)ehci_base)[o/2], ((uint16_t*)ehci_base) + o/2));
#endif
return ehci_base[o/4];
}
void bus_space_write_1 (bus_space_tag_t iot, bus_space_handle_t ioh, int o, int x)
{
#ifdef EHCI_DEBUG
if (ehcidebug > 10)
dprintf (("", "write %x to %p\n", x, ((uint8_t*) ehci_base) + o));
#endif
((uint8_t*) ehci_base)[o] = x;
}
int bus_space_read_1 (bus_space_tag_t iot, bus_space_handle_t ioh, int o)
{
#ifdef EHCI_DEBUG
if (ehcidebug > 15)
dprintf (("", "read %x from %p\n",
((uint8_t*) ehci_base)[o], ehci_base + o));
#endif
return ((uint8_t*) ehci_base)[o];
}
void timeout(timeout_func_t f, void * h, int t)
{
dprintf (("Main_0", "timeout %p %d\n", h, t));
}
void untimeout(timeout_func_t f, void * h)
{
dprintf (("Main_0", "untimeout %p\n", h));
}
/* declare here to avoid clash with sys/types.h */
int tsleep(void *chan, int pri, char *wmesg, int timo, int noblock);
void usb_delay_ms(usbd_bus_handle h, u_int d)
{
tsleep (&d, 0, "usbdly", d, 0);
}
usbd_status
usb_insert_transfer(usbd_xfer_handle xfer)
{
usbd_status status;
_swix (USBDriver_InsertTransfer, _IN (0) | _OUT (0), xfer, &status);
return status;
}
void
usb_transfer_complete(usbd_xfer_handle xfer)
{
_swix (USBDriver_TransferComplete, _IN (0), xfer);
}
_kernel_oserror*
_riscos_abort_pipe (_kernel_swi_regs * r, void* pw, void* v)
{
ehci_abort_xfer (v, USBD_TIMEOUT);
return NULL;
}
void
riscos_abort_pipe (void* v)
{
callx_add_callback (_riscos_abort_pipe, v);
}
void
usb_schedsoftintr (struct usbd_bus* sc)
{
// dprintf (("", "Scheduling soft interrupt\n"));
// *(void**) sc->soft = (void*) softintr_entry;
_swix (USBDriver_ScheduleSoftInterrupt, _IN(0), sc);
}
int
softintr (_kernel_swi_regs* r, void* pw)
{
ehci_softintr ((void*) r->r[0]);
return 1;
}
/*---------------------------------------------------------------------------*/
#ifdef EHCI_DEBUG
_kernel_oserror* driver (_kernel_swi_regs* r, void* pw)
{
switch (r->r[0])
{
case DeviceFSCallDevice_Terminate:
irq_buf = 0;
break;
case DeviceFSCallDevice_StreamCreated:
irq_buf = r->r[3];
break;
}
return NULL;
}
#endif
......@@ -79,6 +79,7 @@ extern void* resource_files (void);
extern void ohci_dumpregs (ohci_softc_t *);
extern void ohci_dump_ed (ohci_soft_ed_t*);
#endif
extern void ohci_abort_xfer (void*, int);
extern char panic_string[255];
......@@ -251,6 +252,9 @@ _kernel_oserror *module_init(const char *cmd_tail, int podule_base, void *pw) {
memset (&ohci_soft, 0, sizeof ohci_soft);
sprintf (ohci_soft.sc_bus.bdev.dv_xname, "OHCI%d", instance);
_swix (PCI_ReadInfo, _INR(0,3), (1<<16), &v, 4, pci_device);
strncpy (ohci_soft.sc_vendor, v, sizeof ohci_soft.sc_vendor)
[sizeof ohci_soft.sc_vendor - 1] = '\0';
_swix (PCI_ReadInfo, _INR(0,3), (1<<16), &v, 4, pci_device);
strncpy (ohci_soft.sc_vendor, v, sizeof ohci_soft.sc_vendor)
......@@ -386,44 +390,27 @@ static void service_pci (_kernel_swi_regs* r)
sizeof p,
r->r[3]);
sprintf (tok, "D%04X%04X", p & 0xffff, p >> 16);
/* claim service call if lookup was successful */
if (NULL == _swix (MessageTrans_Lookup, _INR(0,2)|_OUT(2),
&mod_messages,
tok,
0,
r->r + 2))
{
r->r[1] = 0;
}
break;
case 1:
_swix (PCI_ReadInfo, _INR(0,3),
PCI_ReadInfo_ClassCode,
&p,
sizeof p,
r->r[3]);
if (p == 0x0C0310)
{
/* Only lookup a vendor id if it's an OHCI controller */
sprintf (tok, "V%04X", r->r[0]);
/* claim service call if lookup was successful */
if (NULL == _swix (MessageTrans_Lookup, _INR(0,2)|_OUT(2),
&mod_messages,
tok,
0,
r->r + 2))
{
r->r[1] = 0;
}
}
sprintf (tok, "V%04X", r->r[0]);
break;
default:
return;
}
/* claim service call if lookup was successful */
if (NULL == _swix (MessageTrans_Lookup, _INR(0,2)|_OUT(2),
&mod_messages,
tok,
0,
r->r + 2))
{
r->r[1] = 0;
}
else
{
dprintf (("", "Couldn't find token %s\n", tok));
}
}
void module_services(int service_number, _kernel_swi_regs *r, void *pw)
......@@ -669,7 +656,7 @@ int usb_irq_handler(_kernel_swi_regs *r, void *pw)
0, EntryNo_HAL_CounterRead, &u2s1);
int t = (u2s - u2s1) * 5;
if (t < 0) t += 10000000; /* it wrapped */
if (ohcidebug > 15) dprintf(("", "irq for: %d nsecs", t));
if (ohcidebug > 1) dprintf(("", "irq for: %d nsecs\n", t));
irq_tot += t;
if (t < irq_min) irq_min = t;
if (t > irq_max) irq_max = t;
......@@ -732,3 +719,31 @@ usb_transfer_complete(usbd_xfer_handle xfer)
{
_swix (USBDriver_TransferComplete, _IN (0), xfer);
}
_kernel_oserror*
_riscos_abort_pipe (_kernel_swi_regs * r, void* pw, void* v)
{
ohci_abort_xfer (v, USBD_TIMEOUT);
return NULL;
}
void
riscos_abort_pipe (void* v)
{
callx_add_callback (_riscos_abort_pipe, v);
}
void
usb_schedsoftintr (struct usbd_bus* sc)
{
// dprintf (("", "Scheduling soft interrupt\n"));
// *(void**) sc->soft = (void*) softintr_entry;
_swix (USBDriver_ScheduleSoftInterrupt, _IN(0), sc);
}
int
softintr (_kernel_swi_regs* r, void* pw)
{
ohci_softintr ((void*) r->r[0]);
return 0;
}
......@@ -36,7 +36,9 @@ int total_sleep;
extern void detach_hub (struct device*);
extern void detach_device (struct device*);
static uint64_t gettime (void)
extern uint64_t gettime (void);
uint64_t gettime (void)
{
uint32_t cs;
static uint32_t (*readcode) (void);
......@@ -53,8 +55,10 @@ static uint64_t gettime (void)
0, EntryNo_HAL_CounterPeriod,
&max_count);
#if 0 // fixed in RISC OS 5.03
/* bug here - force 2000000 */
max_count = 2000000;
#endif
/* conversion to ns, assume counter is for 1 cs */
ns_factor = 10000000 / max_count;
......@@ -79,12 +83,14 @@ int spltty (void)
void splx (int s)
{
if (s == 0) _kernel_irqs_on ();
// dprintf (("", "int on\n"));
}
int splbio (void)
{
int s = _kernel_irqs_disabled ();
_kernel_irqs_off ();
// dprintf (("", "int off\n"));
return s;
}
......@@ -254,8 +260,8 @@ int tsleep (void* ident, int priority, const char* wmesg, int timo, int noblock)
"from %lu.%.09lu\n"
"til %lu.%.09lu\n",
wmesg, ident, priority, timo,
(uint32_t) t0 / 1000000000, (uint32_t) t0 % 1000000000,
(uint32_t) t1 / 1000000000, (uint32_t) t1 % 1000000000));
(uint32_t) (t0 / 1000000000), (uint32_t) (t0 % 1000000000),
(uint32_t) (t1 / 1000000000), (uint32_t) (t1 % 1000000000)));
#endif
for (i = 0; i < nhandles && t_handles[i] && t_handles[i] != ident; ++i);
......@@ -306,13 +312,13 @@ int tsleep (void* ident, int priority, const char* wmesg, int timo, int noblock)
#ifdef USB_DEBUG
if (usbdebug > 19)
dprintf (("", "now %lu.%09lu\n",
(uint32_t) t2 / 100000000, (uint32_t) t2 % 1000000000));
(uint32_t) (t2 / 100000000), (uint32_t) (t2 % 1000000000)));
t2 -= t0;
_swix (OS_ReadMonotonicTime, _OUT(0), &cs1);
total_sleep += cs1 - cs0;
if (usbdebug > 10)
dprintf (("", "slept for %lu.%.06lu seconds (timo = %dms), %d cs\n",
(uint32_t) t2 / 100000000, (uint32_t) t2 % 1000000000,
dprintf (("", "slept for %lu.%.09lu seconds (timo = %dms), %d cs\n",
(uint32_t) (t2 / 100000000), (uint32_t) (t2 % 1000000000),
timo, cs1 - cs0));
#endif
......@@ -418,3 +424,30 @@ void logprintf (char* format, ...)
va_start (p, format);
dvprintf (("Log", format, p));
}
#ifdef USB_USE_SOFTINTR
void* softintr_establish(int pri, void (*f) (void*), void* h)
{
void** p = malloc (3 * sizeof *p);
if (p == NULL) return p;
p[0] = 0;
p[1] = h;
p[2] = (void*) f;
_swix (CBAI_RegisterPollWord, _INR(0, 2), p, pri, private_word);
return p;
}
//void softintr_schedule (void** p)
//{
// dprintf (("", "Setting pollword to %p\n", p[2]));
// p[0] = p[2];
//}
void softintr_disestablish (void* p)
{
_swix (CBAI_DeregisterPollWord, _IN(0), p);
free (p);
}
#endif
......@@ -35,6 +35,8 @@
#include "dev/usb/usbdivar.h"
#include "dev/usb/usbhid.h"
#include "usbkboard.h"
#include "wimplib.h"
#define NUM_LOCK 0x01
......@@ -149,6 +151,15 @@ RSVD, RSVD, RSVD, RSVD,
RSVD, RSVD, RSVD, RSVD
};
extern void remove_all_keyboards (void)
{
struct ukbd_softc* sc;
TAILQ_FOREACH(sc, &allukbds, link_kb)
{
detach_keyboard ((struct device*) sc);
}
}
struct device* attach_keyboard (struct device* parent, void* aux)
{
struct ukbd_softc* softc;
......@@ -210,6 +221,8 @@ struct device* attach_keyboard (struct device* parent, void* aux)
KeyV_KeyboardPresent, KeyboardID_PC, KEYV);
dprintf (("", "USB keyboard enabled\n"));
/* set idle rate to 0 */
usbd_set_idle (softc->sc_iface, 0, 0);
/* Set up interrupt pipe. */
usbd_open_pipe_intr(softc->sc_iface, softc->sc_ep_addr,
......@@ -280,6 +293,24 @@ int keyv (_kernel_swi_regs* r, void* pw)
return 1;
}
#ifdef PS2KLUDGE
_kernel_oserror* keyup (_kernel_swi_regs* r, void* pw, void* k)
{
(void) r;
(void) pw;
// dprintf (("", "Key Up: %x\n", (int) k));
return _swix (OS_CallAVector,
_INR(0,1) | _IN(9),
KeyV_KeyUp,
k,
KEYV
);
}
#endif
void ukbd_intr
(
usbd_xfer_handle xfer,
......@@ -352,6 +383,7 @@ void ukbd_intr
bit = 1 << (key % 32);
newstatus[key / 32] |= bit;
if ((status[key / 32] & bit) == 0)
{
_swix (OS_CallAVector,
_INR(0,1) | _IN(9),
......@@ -360,6 +392,8 @@ void ukbd_intr
key,
KEYV
);
// dprintf (("", "Key Down: %x\n", key));
}
}
}
......@@ -369,6 +403,10 @@ void ukbd_intr
if (key != RSVD && key != NEQV) {
bit = 1 << (key % 32);
if ((newstatus[key / 32] & bit) == 0)
{
#ifdef PS2KLUDGE
callx_add_callafter (2, keyup, (void*) key);
#else
_swix (OS_CallAVector,
_INR(0,1) | _IN(9),
......@@ -377,6 +415,9 @@ void ukbd_intr
key,
KEYV
);
// dprintf (("", "Key Up: %x\n", key));
#endif
}
}
}
......
This diff is collapsed.
......@@ -24,15 +24,22 @@
#include "usbmodhead.h"
#include "swis.h"
#include "debuglib/debuglib.h"
#include "callx/callx.h"
#include <sys/callout.h>
#include <sys/ioctl.h>
#include "dev/usb/usb.h"
#include "dev/usb/usbhid.h"
#include "dev/usb/usbdi.h"
#include "dev/usb/usbdi_util.h"
#include "dev/usb/usbdivar.h"
#include "dev/usb/usbhid.h"
#include <dev/usb/usbdevs.h>
#include <dev/usb/usb_quirks.h>
#include <dev/usb/hid.h>
#include "usbmouse.h"
#include "wimplib.h"
......@@ -45,45 +52,326 @@ extern struct messages mod_messages;
extern struct cfattach ums_ca;
static int relx = 0, rely = 0;
static uint8_t buttons;
static int relx = 0, rely = 0, relz = 0;
static bool enabled = false;
#define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE)
#define MOUSE_FLAGS (HIO_RELATIVE)
void ums_intr (usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status);
struct ums_softc {
USBBASEDEVICE sc_dev; /* base device */
usbd_device_handle sc_udev;
usbd_interface_handle sc_iface; /* interface */
usbd_pipe_handle sc_intrpipe; /* interrupt pipe */
int sc_ep_addr;
u_char *sc_ibuf;
u_int8_t sc_iid;
int sc_isize;
struct hid_location sc_loc_x, sc_loc_y, sc_loc_z;
struct hid_location *sc_loc_btn;
int sc_enabled;
int flags; /* device configuration */
#define UMS_Z 0x01 /* z direction available */
#define UMS_SPUR_BUT_UP 0x02 /* spurious button up events */
#define UMS_REVZ 0x04 /* Z-axis is reversed */
int nbuttons;
#define MAX_BUTTONS 31 /* chosen because sc_buttons is u_int32_t */
u_int32_t sc_buttons; /* mouse button status */
struct device *sc_wsmousedev;
char sc_dying;
/* list of ukbd softcs */
TAILQ_ENTRY(ums_softc) link_ms;
};
TAILQ_HEAD(umslist, ums_softc) allums = TAILQ_HEAD_INITIALIZER(allums);
extern void remove_all_mice (void)
{
struct ums_softc* sc;
TAILQ_FOREACH(sc, &allums, link_ms)
{
detach_mouse ((struct device*) sc);
}
}
static int match_mouse (struct usb_attach_arg *uaa)
{
usb_interface_descriptor_t *id;
int size, ret;
void *desc;
usbd_status err;
dprintf (("", "Trying ums attach\n"));
if (uaa->iface == NULL)
return (UMATCH_NONE);
id = usbd_get_interface_descriptor(uaa->iface);
if (id == NULL || id->bInterfaceClass != UICLASS_HID)
{
dprintf (("", "failed class match: id == %p\n", id));
return (UMATCH_NONE);
}
err = usbd_read_report_desc(uaa->iface, &desc, &size, M_USBDEV);
if (err)
{
dprintf (("", "failed to get report\n"));
return (UMATCH_NONE);
}
if (hid_is_collection(desc, size, 0,
HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)))
ret = UMATCH_IFACECLASS;
else
ret = UMATCH_NONE;
free(desc);
dprintf (("", "ums attach returning: %d\n", ret));
return (ret);
}
static void do_attach_mouse (struct ums_softc* sc, struct usb_attach_arg *uaa)
{
usbd_interface_handle iface = uaa->iface;
usb_interface_descriptor_t *id;
usb_endpoint_descriptor_t *ed;
int size;
void *desc;
usbd_status err;
char devinfo[1024];
u_int32_t flags, quirks;
int i, wheel;
struct hid_location loc_btn;
sc->sc_udev = uaa->device;
sc->sc_iface = iface;
id = usbd_get_interface_descriptor(iface);
usbd_devinfo(uaa->device, 0, devinfo);
USB_ATTACH_SETUP;
dprintf(("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
devinfo, id->bInterfaceClass, id->bInterfaceSubClass));
ed = usbd_interface2endpoint_descriptor(iface, 0);
if (ed == NULL) {
logprintf("%s: could not read endpoint descriptor\n",
USBDEVNAME(sc->sc_dev));
USB_ATTACH_ERROR_RETURN;
}
dprintf(("", "ums_attach: bLength=%d bDescriptorType=%d "
"bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d"
" bInterval=%d\n",
ed->bLength, ed->bDescriptorType,
ed->bEndpointAddress & UE_ADDR,
UE_GET_DIR(ed->bEndpointAddress)==UE_DIR_IN? "in" : "out",
ed->bmAttributes & UE_XFERTYPE,
UGETW(ed->wMaxPacketSize), ed->bInterval));
if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_IN ||
(ed->bmAttributes & UE_XFERTYPE) != UE_INTERRUPT) {
logprintf("%s: unexpected endpoint\n",
USBDEVNAME(sc->sc_dev));
USB_ATTACH_ERROR_RETURN;
}
quirks = usbd_get_quirks(uaa->device)->uq_flags;
if (quirks & UQ_MS_REVZ)
sc->flags |= UMS_REVZ;
if (quirks & UQ_SPUR_BUT_UP)
sc->flags |= UMS_SPUR_BUT_UP;
err = usbd_read_report_desc(uaa->iface, &desc, &size, M_USBDEV);
if (err)
USB_ATTACH_ERROR_RETURN;
if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
0, hid_input, &sc->sc_loc_x, &flags)) {
logprintf("%s: mouse has no X report\n", USBDEVNAME(sc->sc_dev));
USB_ATTACH_ERROR_RETURN;
}
if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
logprintf("%s: X report 0x%04x not supported\n",
USBDEVNAME(sc->sc_dev), flags);
USB_ATTACH_ERROR_RETURN;
}
if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
0, hid_input, &sc->sc_loc_y, &flags)) {
logprintf("%s: mouse has no Y report\n", USBDEVNAME(sc->sc_dev));
USB_ATTACH_ERROR_RETURN;
}
if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
logprintf("%s: Y report 0x%04x not supported\n",
USBDEVNAME(sc->sc_dev), flags);
USB_ATTACH_ERROR_RETURN;
}
/* Try to guess the Z activator: first check Z, then WHEEL. */
wheel = 0;
if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Z),
0, hid_input, &sc->sc_loc_z, &flags) ||
(wheel = hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP,
HUG_WHEEL),
0, hid_input, &sc->sc_loc_z, &flags))) {
if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
sc->sc_loc_z.size = 0; /* Bad Z coord, ignore it */
} else {
sc->flags |= UMS_Z;
/* Wheels need the Z axis reversed. */
if (wheel)
sc->flags ^= UMS_REVZ;
}
}
/* figure out the number of buttons */
for (i = 1; i <= MAX_BUTTONS; i++)
if (!hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
0, hid_input, &loc_btn, 0))
break;
sc->nbuttons = i - 1;
sc->sc_loc_btn = malloc(sizeof(struct hid_location)*sc->nbuttons);
if (!sc->sc_loc_btn) {
logprintf("%s: no memory\n", USBDEVNAME(sc->sc_dev));
USB_ATTACH_ERROR_RETURN;
}
dprintf(("", "%s: %d buttons%s\n", USBDEVNAME(sc->sc_dev),
sc->nbuttons, sc->flags & UMS_Z ? " and Z dir." : ""));
for (i = 1; i <= sc->nbuttons; i++)
hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
0, hid_input, &sc->sc_loc_btn[i-1], 0);
sc->sc_isize = hid_report_size(desc, size, hid_input, 0);
sc->sc_ibuf = malloc(sc->sc_isize);
if (sc->sc_ibuf == NULL) {
logprintf("%s: no memory\n", USBDEVNAME(sc->sc_dev));
free(sc->sc_loc_btn);
USB_ATTACH_ERROR_RETURN;
}
sc->sc_ep_addr = ed->bEndpointAddress;
free(desc);
#ifdef USB_DEBUG
dprintf(("", "ums_attach: sc=%p\n", sc));
dprintf(("", "ums_attach: X\t%d/%d\n",
sc->sc_loc_x.pos, sc->sc_loc_x.size));
dprintf(("", "ums_attach: Y\t%d/%d\n",
sc->sc_loc_x.pos, sc->sc_loc_x.size));
if (sc->flags & UMS_Z)
dprintf(("", "ums_attach: Z\t%d/%d\n",
sc->sc_loc_z.pos, sc->sc_loc_z.size));
for (i = 1; i <= sc->nbuttons; i++) {
dprintf(("", "ums_attach: B%d\t%d/%d\n",
i, sc->sc_loc_btn[i-1].pos,sc->sc_loc_btn[i-1].size));
}
dprintf(("", "ums_attach: size=%d, id=%d\n", sc->sc_isize, sc->sc_iid));
#endif
usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
USBDEV(sc->sc_dev));
USB_ATTACH_SUCCESS_RETURN;
}
struct device* attach_mouse (struct device* parent, void* aux)
{
struct device* softc;
struct ums_softc* sc;
dprintf (("", "Trying match on usb mouse\n"));
/* First see if we match */
if ((*ums_ca.ca_match) (0, 0, aux) == UMATCH_NONE)
if (match_mouse (aux) == UMATCH_NONE)
{
dprintf (("", "Failed to match\n"));
return NULL;
}
/* If so, allocate memory for the device and attach ourselves. */
softc = malloc (ums_ca.ca_devsize);
softc = malloc (sizeof *sc);
if (softc == 0) {
dprintf (("", "Couldn't allocate memory for mouse device\n"));
return NULL;
}
memset (softc, 0, ums_ca.ca_devsize);
memset (softc, 0, sizeof *sc);
strcpy (softc->dv_xname, "USBMouse"Module_VersionString);
softc->dv_cfdata = (void*) 3; // mouse
(*ums_ca.ca_attach) (parent, softc, aux);
/* enable */
sc = (struct ums_softc*) softc;
do_attach_mouse (sc, aux);
dprintf (("", "Matched mouse\n"));
ums_enable (softc);
_swix (OS_Pointer, _INR(0,1), 1, PointerDevice_USB);
sc->sc_enabled = 1;
sc->sc_buttons = 0;
/* set idle rate to 0 */
usbd_set_idle (sc->sc_iface, 0, 0);
int err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr,
USBD_SHORT_XFER_OK, &sc->sc_intrpipe, sc,
sc->sc_ibuf, sc->sc_isize, ums_intr, USBD_DEFAULT_INTERVAL);
if (err) {
dprintf(("", "ums_enable: usbd_open_pipe_intr failed, error=%d\n",
err));
sc->sc_enabled = 0;
}
else
_swix (OS_Pointer, _INR(0,1), 1, PointerDevice_USB);
TAILQ_INSERT_TAIL (&allums, sc, link_ms);
return softc;
}
int detach_mouse (struct device* ms)
{
ums_disable (ms);
(*ums_ca.ca_detach) (ms, 0);
struct ums_softc* sc= (struct ums_softc*) ms;
int rv;
usbd_abort_pipe(sc->sc_intrpipe);
usbd_close_pipe(sc->sc_intrpipe);
dprintf (("", "detaching mouse, buttons = %x", sc->sc_buttons));
if (sc->sc_buttons & 1) {
dprintf (("", "releaseing 1\n"));
_swix (OS_CallAVector, _INR(0,1) | _IN(9),
KeyV_KeyUp, KeyNo_LeftMouse, KEYV);
}
if (sc->sc_buttons & 2)
{
dprintf (("", "releaseing 2\n"));
_swix (OS_CallAVector, _INR(0,1) | _IN(9),
KeyV_KeyUp, KeyNo_RightMouse, KEYV);
}
if (sc->sc_buttons & 4)
{
dprintf (("", "releaseing 4\n"));
_swix (OS_CallAVector, _INR(0,1) | _IN(9),
KeyV_KeyUp, KeyNo_CentreMouse, KEYV);
}
TAILQ_REMOVE (&allums, sc, link_ms);
/* No need to do reference counting of ums, wsmouse has all the goo. */
if (sc->sc_wsmousedev != NULL)
rv = config_detach(sc->sc_wsmousedev, 1);
if (rv == 0) {
free(sc->sc_loc_btn);
free(sc->sc_ibuf);
}
free (ms);
return 0;
}
......@@ -105,6 +393,7 @@ int pointerv (_kernel_swi_regs* r, void* pw)
}
break;
#define RECORD "\x0\x0\x0\x0\x0\x0\x0\x0\x7USB Mouse"
case PointerReason_Identify:
{
struct pointer_device {
......@@ -141,43 +430,97 @@ int pointerv (_kernel_swi_regs* r, void* pw)
return 1;
}
void wsmouse_input (struct device* dev, uint32_t b, int x, int y, int z, uint32_t flags)
static _kernel_oserror *zscroll_handler
(
_kernel_swi_regs * r,
void * pw,
void * h
)
{
(void) r;
(void) pw;
(void) h;
while (relz != 0)
{
int b[64];
_swix (Wimp_GetPointerInfo, _IN(1), b);
b[0] = b[3];
_swix (Wimp_GetWindowState, _IN(1), b);
b[8] = 0;
b[9] = relz > 0? -1: 1;
relz += relz > 0? -1: 1;
_swix (Wimp_SendMessage, _INR(0,2), 10, b, b[0]);
}
return NULL;
}
void ums_intr
(
usbd_xfer_handle xfer,
usbd_private_handle addr,
usbd_status status
)
{
struct ums_softc *sc = addr;
u_char *ibuf = sc->sc_ibuf;
int dx, dy, dz, i, b = 0;
uint8_t change;
relx += x;
rely -= y;
if (status == USBD_CANCELLED)
return;
if (status) {
dprintf(("", "ums_intr: status=%d\n", status));
usbd_clear_endpoint_stall_async(sc->sc_intrpipe);
return;
}
dx = hid_get_data(ibuf, &sc->sc_loc_x);
dy = -hid_get_data(ibuf, &sc->sc_loc_y);
dz = hid_get_data(ibuf, &sc->sc_loc_z);
if (sc->flags & UMS_REVZ)
dz = -dz;
relx += dx;
rely += dy;
relz += 5 * dz; /* 5 makes things move a bit faster */
if (enabled)
{
_swix(OS_CallAVector, _INR(0,3) | _IN(9),
PointerReason_Report, PointerDevice_USB,
x, y,
dx, dy,
PointerV);
if (relz != 0)
{
callx_add_callback (zscroll_handler, 0);
}
}
for (i = 0; i < sc->nbuttons; i++)
if (hid_get_data(ibuf, &sc->sc_loc_btn[i]))
b |= (1 << i);
#ifdef USB_DEBUG
if (umsdebug > 5) dprintf(("",
"data.relx = %d, data.rely = %d, relx = %d, rely = %d, buttons = %x\n",
x, y, relx, rely, b));
#endif
if ((change = buttons ^ b) != 0) {
buttons = b;
if ((change = sc->sc_buttons ^ b) != 0) {
sc->sc_buttons = b;
#ifdef USB_DEBUG
if (umsdebug > 5) dprintf (("", "change = %x, enabled = %d\n", change,
enabled));
#endif
if (enabled) {
if (change & 1) _swix (OS_CallAVector, _INR(0,1) | _IN(9),
1 + ((buttons & 1) == 1), KeyNo_LeftMouse, KEYV);
(b & 1)? KeyV_KeyDown: KeyV_KeyUp, KeyNo_LeftMouse, KEYV);
if (change & 2) _swix (OS_CallAVector, _INR(0,1) | _IN(9),
1 + ((buttons & 2) == 2), KeyNo_RightMouse, KEYV);
(b & 2)? KeyV_KeyDown: KeyV_KeyUp, KeyNo_RightMouse, KEYV);
if (change & 4) _swix (OS_CallAVector, _INR(0,1) | _IN(9),
1 + ((buttons & 4) == 4), KeyNo_CentreMouse, KEYV);
/* make the next button replicate menu */
if (change & 8) _swix (OS_CallAVector, _INR(0,1) | _IN(9),
1 + ((buttons & 8) == 8), KeyNo_CentreMouse, KEYV);
(b & 4)? KeyV_KeyDown: KeyV_KeyUp, KeyNo_CentreMouse, KEYV);
}
}
}
......
; Copyright 2004 Castle Technology Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
#include "Global/RISCOS.h"
#include "Global/Services.h"
#include "../Version"
initialisation-code: module_init
finalisation-code: module_final
service-call-handler: module_services &D2
title-string: EHCIDriver
help-string: EHCIDriver EHCIDriverModule_MajorVersion_CMHG
date-string: EHCIDriverModule_Module_Date_CMHG
#define HELPFILE(M) "Resources:$." #M
#define XHELPFILE(M) HELPFILE(M)
international-help-file: XHELPFILE(MSGLOC)
command-keyword-table: module_commands
EHCIRegs( min-args:0, max-args:0,
help-text: "*EHCIRegs reads the registers from the EHCI controller\n",
add-syntax:, invalid-syntax: "Syntax: *EHCIRegs"),
EHCIEDS(),
EHCIWrite( min-args:2, max-args:2,
help-text: "*EHCIWrite writes to a register in the EHCI controller.\n",
add-syntax:, invalid-syntax: "Syntax: *EHCIWrite <offset> <value>"),
EHCIDebug( min-args:1, max-args:2,
help-text: "*EHCIDebug sets the debug level for debuglib output, optionally also setting the debug level for output controlled by the usbdebug variable within the ohcidriver.\n",
add-syntax:, invalid-syntax: "Syntax: EHCIDebug <ehci> [<usb>]")
vector-handlers: usb_irq_entry/usb_irq_handler,
softintr_entry/softintr
generic-veneers: callout_entry/callout_handler,
#ifdef EHCI_DEBUG
driver_entry/driver,
#endif
new_entry/new_instance
......@@ -69,5 +69,6 @@ TargetFM( min-args:1, max-args:1,
event-handler: vsync_entry/vsync Event_VSync
#endif
vector-handlers: usb_irq_entry/usb_irq_handler
vector-handlers: usb_irq_entry/usb_irq_handler,
softintr_entry/softintr
generic-veneers: callout_entry/callout_handler
......@@ -76,7 +76,8 @@ swi-decoding-table: USBDriver,
RegisterBus,
DeRegisterBus,
InsertTransfer,
TransferComplete
TransferComplete,
ScheduleSoftInterrupt
; IOCtl,
; OpenPipe,
; ClosePipe,
......@@ -118,4 +119,5 @@ swi-decoding-table: USBDriver,
generic-veneers: driver_entry/driver
vector-handlers: pointerv_entry/pointerv,
keyv_entry/keyv
keyv_entry/keyv,
softintr_entry/softintr
......@@ -17,3 +17,4 @@
#define USBDriver_DeRegisterBus 0x054a41
#define USBDriver_InsertTransfer 0x054a42
#define USBDriver_TransferComplete 0x054a43
#define USBDriver_ScheduleSoftInterrupt 0x054a44
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