mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: Joystick not found on Linux/amd64
       [not found] <Pine.LNX.4.58.0412200235440.6947@tuvok.enterprise>
@ 2004-12-20  3:07 ` Joshua Wise
  2004-12-20 22:34   ` Bernhard Ager
  0 siblings, 1 reply; 3+ messages in thread
From: Joshua Wise @ 2004-12-20  3:07 UTC (permalink / raw)
  To: Bernhard Ager; +Cc: linux-kernel

Bernhard Ager wrote:
> Hello,
> 
> I just tried out version 8.03 of X-Plane for Linux. Works really smoothly 
> for me, except that the joystick is not found :-( The joystick 
> itself should be working, as e.g. jstest tells me: 
> 
> Joystick (Analog 4-axis 4-button joystick) has 4 axes and 4 buttons. Driver version is 2.1.0.
> 
> The issue might be, that I am using Linux on the amd64 architecture and 
> letting run X-Plane in the 32bit "emulation", though I can't really see 
> why.
I've had a report of this problem in the past. I have a vague 
understanding of why it happens, but I'm not sure how to fix it.

As far as I can tell, the problem is that my code uses the joystick 
ioctls to get the version, passing it a 32-bit address to return the 
version into. This doesn't work out so hot in the 64-bit kernel, which 
decides that my 32-bit address is full of crap, and gives me an errno of 
-EFAULT, which means that I passed it a bad address. My code handles 
this by not detecting the joystick at all, thinking that the version is 
too old, since the kernel didn't change it.

So, basically, I think I know why it happens, but I'm not certain 
whether its my code at fault or the kernel's. This is a good question. 
I'm going to cc: this to LKML, in the hope that somebody there can 
provide some insight.

I am not subscribed to LKML - anyone on there who is responding, please 
cc: me in your responses.

joshua

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Joystick not found on Linux/amd64
  2004-12-20  3:07 ` Joystick not found on Linux/amd64 Joshua Wise
@ 2004-12-20 22:34   ` Bernhard Ager
  2004-12-21  1:37     ` Bernhard Ager
  0 siblings, 1 reply; 3+ messages in thread
From: Bernhard Ager @ 2004-12-20 22:34 UTC (permalink / raw)
  To: Joshua Wise; +Cc: linux-kernel

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2290 bytes --]

On Sun, 19 Dec 2004, Joshua Wise wrote:

> As far as I can tell, the problem is that my code uses the joystick 
> ioctls to get the version, passing it a 32-bit address to return the 
> version into. 

I have a long night behind me, and here is, what I found out:

It's about the ioctls, because they need to be marked compatible for a 
32bit call or a wrapper has to be written, otherwise the ioctl handler 
will not even be called.

Marking compatible can be done with this <patch> 

diff -ur linux-2.6.9-gentoo-r1/arch/x86_64/ia32/ia32_ioctl.c linux-2.6.9-gentoo-r1-js/arch/x86_64/ia32/ia32_ioctl.c
--- linux-2.6.9-gentoo-r1/arch/x86_64/ia32/ia32_ioctl.c 2004-12-20 22:58:20.000000000 +0100
+++ linux-2.6.9-gentoo-r1-js/arch/x86_64/ia32/ia32_ioctl.c      2004-12-20 22:19:36.000000000 +0100
@@ -174,6 +174,10 @@
 COMPATIBLE_IOCTL(0x4B50)   /* KDGHWCLK - not in the kernel, but don't complain */
 COMPATIBLE_IOCTL(0x4B51)   /* KDSHWCLK - not in the kernel, but don't complain */
 COMPATIBLE_IOCTL(FIOQSIZE)
+COMPATIBLE_IOCTL(JSIOCGVERSION)
+COMPATIBLE_IOCTL(JSIOCGAXES)
+COMPATIBLE_IOCTL(JSIOCGBUTTONS)
+COMPATIBLE_IOCTL(JSIOCGNAME(0x200))  /* for X-Plane 8.03 */
 
 /* And these ioctls need translation */
 HANDLE_IOCTL(TIOCGDEV, tiocgdev)
diff -ur linux-2.6.9-gentoo-r1/fs/compat_ioctl.c linux-2.6.9-gentoo-r1-js/fs/compat_ioctl.c
--- linux-2.6.9-gentoo-r1/fs/compat_ioctl.c     2004-12-20 22:58:20.000000000 +0100
+++ linux-2.6.9-gentoo-r1-js/fs/compat_ioctl.c  2004-12-20 21:48:37.000000000 +0100
@@ -11,6 +11,7 @@
  */
 
 #ifdef INCLUDES
+#include <linux/joystick.h>
 #include <linux/config.h>
 #include <linux/types.h>
 #include <linux/compat.h>

</patch>

Making a special case for JSIOCGNAME(0x200) is very nasty (0x200 is the
return buffer length, coded into the ioctl number), but I don't know how
to work around this in an elegant way.

As my test program (attached) shows, the patch actually works. (Compile 
with -m32 or in a 32bit chroot/on a real x86). However, X-Plane does not 
work correctly yet: It recognizes a joystick and the buttons are working, 
but the axes don't. Joshua: if you send me your joystick code, I'll gladly 
take a look at it.


Greetings,
  Bernhard
-- 
Isn't making a smoking section in a restaurant like making a peeing
section in a swimming pool?

[-- Attachment #2: Type: TEXT/x-csrc, Size: 2048 bytes --]

#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/joystick.h>

/*                                function                     3rd arg   */
/*       #define JSIOCGAXES       get number of axes           char      */
/*       #define JSIOCGBUTTONS    get number of buttons        char      */
/*       #define JSIOCGVERSION    get driver version           int       */
/*       #define JSIOCGNAME(len)  get identifier string        char      */
/*       #define JSIOCSCORR       set correction values        &js_corr  */
/*       #define JSIOCGCORR       get correction values        &js_corr  */


int main (int argc, char **argv) {
  char number_of_axes, number_of_buttons, js_name[0x200];
  int version;
  struct js_event e;
  size_t size; 
  int js;

/*   printf ("Value of JSIOCGAXES = %u\n", JSIOCGAXES); */
/*   printf ("Value of JSIOCGBUTTONS = %u\n", JSIOCGBUTTONS); */
/*   printf ("Value of JSIOCGVERSION = %u\n", JSIOCGVERSION); */
/*   printf ("Value of JSIOCGNAME(0x200) = %x\n", JSIOCGNAME(0x200)); */

  js = open ("/dev/js0", O_RDONLY);
  
  if (ioctl (js, JSIOCGAXES, &number_of_axes) == -1) {
    perror("JSIOCGAXES");
    number_of_axes = -1;
  }
  if (ioctl (js, JSIOCGBUTTONS, &number_of_buttons) == -1) {
    perror("JSIOCGBUTTONS");
    number_of_buttons = -1;
  }
  if (ioctl (js, JSIOCGVERSION, &version) == -1) {
    perror("JSIOCGVERSION");
    version = -1;
  }
  if (ioctl (js, JSIOCGNAME(0x200), js_name) == -1) {
    perror("JSIOCGNAME(0x200)");
    strcpy (js_name, "Unknown");
  }

  printf ("Axes: %3d  Buttons: %3d  Version: %d  Name: %s\n",
          number_of_axes, number_of_buttons, version, js_name);

  while (size = read (js, &e, sizeof(struct js_event))) {
    if (size != sizeof(struct js_event)) {
      printf ("read failed, data too small");
      break;
    }
    printf("time: %9u  value: %6d  type: %3u  number:  %2u\r",
           e.time, e.value, e.type, e.number);
    fflush(stdout);
  }
  
  close(js);

}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Joystick not found on Linux/amd64
  2004-12-20 22:34   ` Bernhard Ager
@ 2004-12-21  1:37     ` Bernhard Ager
  0 siblings, 0 replies; 3+ messages in thread
From: Bernhard Ager @ 2004-12-21  1:37 UTC (permalink / raw)
  To: Joshua Wise; +Cc: linux-kernel

On Mon, 20 Dec 2004, Bernhard Ager wrote:

> However, X-Plane does not work correctly yet: It recognizes a joystick
> and the buttons are working, but the axes don't.

Actually this was a problem with my sidewinder joystick in analog mode 
(digital sidewinder mode doesn't work). Using a USB Joystick, everything 
is fine.


Greetings,
  Bernhard
-- 
Isn't making a smoking section in a restaurant like making a peeing
section in a swimming pool?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-12-21  1:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <Pine.LNX.4.58.0412200235440.6947@tuvok.enterprise>
2004-12-20  3:07 ` Joystick not found on Linux/amd64 Joshua Wise
2004-12-20 22:34   ` Bernhard Ager
2004-12-21  1:37     ` Bernhard Ager

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®