Bas Zoetekouw was puzzling over the PCI scanning function, which tries
to be OS-independent by accessing the PCI configuration hardware
directly.  We agreed it would be better to use the Linux procfs
interface to PCI configuration.  In your case we know that Linux is
correctly detecting the card and gatos ought to rely on that.

Here is a patch to gatos that should implement this behaviour.  I have
only tested it using the scanpci utility that gatos builds.  Please
could you build gatos with this patch and report whether this allows
xatitv to work.  If you are not able to rebuild it, Bas or I should be
able to provide you with a binary package.

Ben.

--- gatos-0.0.5/src/pci.c.orig  2006-10-17 23:05:04.000000000 +0000
+++ gatos-0.0.5/src/pci.c       2006-10-17 23:59:29.000000000 +0000
@@ -151,7 +151,7 @@
 
 #if defined(__GNUC__)
 
-#if !defined(__alpha__) && !defined(__powerpc__)
+#if !defined(linux) && !defined(__alpha__) && !defined(__powerpc__)
 #if defined(GCCUSESGAS)
 #define OUTB_GCC "outb %0,%1"
 #define OUTL_GCC "outl %0,%1"
@@ -248,39 +248,16 @@
 #endif /* __WATCOMC__ */
 
 
-#if defined(__GLIBC__) && __GLIBC__ >= 2
 #if defined(linux)
-#include <sys/perm.h>
-#endif
+#include <sys/fcntl.h>
 #endif
 
 #if defined(__alpha__)
-#if defined(linux)
-#include <asm/unistd.h>
-#define BUS(tag) (((tag)>>16)&0xff)
-#define DFN(tag) (((tag)>>8)&0xff)
-int pciconfig_read(
-          unsigned char bus,
-          unsigned char dfn,
-          unsigned char off,
-          unsigned char len,
-          void * buf)
-{
-  return syscall(__NR_pciconfig_read, bus, dfn, off, len, buf);
-}
-int pciconfig_write(
-          unsigned char bus,
-          unsigned char dfn,
-          unsigned char off,
-          unsigned char len,
-          void * buf)
-{
-  return syscall(__NR_pciconfig_write, bus, dfn, off, len, buf);
-}
-#else
+#if !defined(linux)
 Generate compiler error - scanpci unsupported on non-linux alpha platforms
 #endif /* linux */
 #endif /* __alpha__ */
+
 #if defined(Lynx) && defined(__powerpc__)
 /* let's mimick the Linux Alpha stuff for LynxOS so we don't have
  * to change too much code
@@ -296,14 +273,7 @@
        return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | (p[0] << 0));
 }
 
-
-#define BUS(tag) (((tag)>>16)&0xff)
-#define DFN(tag) (((tag)>>8)&0xff)
-
-#define PCIBIOS_DEVICE_NOT_FOUND       0x86
-#define PCIBIOS_SUCCESSFUL             0x00
-
-int pciconfig_read(
+void pciconfig_read(
           unsigned char bus,
           unsigned char dev,
           unsigned char offset,
@@ -316,34 +286,39 @@
        dev >>= 3;
        if (bus || dev >= 16) {
                *val = 0xFFFFFFFF;
-               return PCIBIOS_DEVICE_NOT_FOUND;
        } else {
                ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset));
                _val = swapl(*ptr);
        }
        *val = _val;
-       return PCIBIOS_SUCCESSFUL;
 }
+#endif
 
-int pciconfig_write(
-          unsigned char bus,
-          unsigned char dev,
-          unsigned char offset,
-          int len,             /* unused, alway 4 */
-          unsigned long val)
+#if defined(linux)
+#include <asm/byteorder.h>
+void pciconfig_read(
+         unsigned char bus,
+         unsigned char dev,
+         unsigned char offset,
+         int len,              /* unused, always 4 */
+         unsigned long *val)
 {
-       unsigned long _val;
-       unsigned long *ptr;
-
-       dev >>= 3;
-       _val = swapl(val);
-       if (bus || dev >= 16) {
-               return PCIBIOS_DEVICE_NOT_FOUND;
+       char file_name[21+1];
+       int fd;
+       unsigned val_le32; /* should be 32-bit on all archs */
+       int result;
+
+       sprintf(file_name, "/proc/bus/pci/%02x/%02x.%d",
+               (unsigned)bus, (unsigned)dev >> 3, dev & 7);
+       if ((fd = open(file_name, O_RDONLY)) >= 0
+           && lseek(fd, offset, 0) == offset
+           && read(fd, &val_le32, sizeof(val_le32)) == 4) {
+               *val = __le32_to_cpu(val_le32);
        } else {
-               ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset));
-               *ptr = _val;
+               *val = 0xFFFFFFFF; /* fake bus pull-up */
        }
-       return PCIBIOS_SUCCESSFUL;
+       if (fd >= 0)
+               close(fd);
 }
 #endif
 
@@ -637,7 +612,7 @@
 #define MAX_PCI_DEVICES         64
 #define NF ((void (*)())NULL), { 0.0, 0, 0, NULL }
 #define PCI_MULTIFUNC_DEV      0x80
-#if defined(__alpha__) || defined(__powerpc__)
+#if defined(linux) || defined(__alpha__) || defined(__powerpc__)
 #define PCI_ID_REG              0x00
 #define PCI_CMD_STAT_REG        0x04
 #define PCI_CLASS_REG           0x08
@@ -1281,7 +1256,7 @@
 
     enable_os_io();
 
-#if !defined(__alpha__) && !defined(__powerpc__)
+#if !defined(linux) && !defined(__alpha__) && !defined(__powerpc__)
     pcr._configtype = 0;
 
     outb(PCI_MODE2_ENABLE_REG, 0x00);
@@ -1329,7 +1304,7 @@
                pcr._cardnum += 0x1) {
          func = 0;
          do { /* loop over the different functions, if present */
-#if !defined(__alpha__) && !defined(__powerpc__)
+#if !defined(linux) && !defined(__alpha__) && !defined(__powerpc__)
            config_cmd = PCI_EN | (pcr._pcibuses[pcr._pcibusidx]<<16) |
                                   (pcr._cardnum<<11) | (func<<8);
 
@@ -1349,7 +1324,7 @@
            pcibus = pcr._pcibuses[pcr._pcibusidx] ;
            pcicard = pcr._cardnum ; pcifunc = func ;
 
-#if !defined(__alpha__) && !defined(__powerpc__)
+#if !defined(linux) && !defined(__alpha__) && !defined(__powerpc__)
             outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x04);
            pcr._status_command  = inl(PCI_MODE1_DATA_REG);
             outl(PCI_MODE1_ADDRESS_REG, config_cmd | 0x08);
@@ -1437,7 +1412,7 @@
     } while (++pcr._pcibusidx < pcr._pcinumbus);
     }
 
-#if !defined(__alpha__) && !defined(__powerpc__)
+#if !defined(linux) && !defined(__alpha__) && !defined(__powerpc__)
     /* Now try pci config 2 probe (deprecated) */
 
     if ((pcr._configtype == 2) || do_mode2_scan) {
@@ -1654,7 +1629,7 @@
     memset(gatos.aticard[gatos.aticards].r128mminfo,0,12) ;
     gatos.aticard[gatos.aticards].m64i2cinfo = 0xFFFF ;
 
-#if !defined(__alpha__) && !defined(__powerpc__)
+#if !defined(linux) && !defined(__alpha__) && !defined(__powerpc__)
 
     /* Assume PCI configuration type 1 */
     config_cmd = PCI_EN | (pcibus<<16) | (pcicard<<11) | (pcifunc<<8) ;
@@ -1851,9 +1826,6 @@
     sysi86(SI86V86, V86SC_IOPL, PS_IOPL);
 #endif
 #endif
-#if defined(linux)
-    iopl(3);
-#endif
 #if defined(__FreeBSD__)  || defined(__386BSD__) || defined(__bsdi__)
     if ((io_fd = open("/dev/console", O_RDWR, 0)) < 0) {
         perror("/dev/console");
@@ -1955,9 +1927,6 @@
     sysi86(SI86V86, V86SC_IOPL, 0);
 #endif
 #endif
-#if defined(linux)
-    iopl(0);
-#endif
 #if defined(__FreeBSD__)  || defined(__386BSD__)
     if (ioctl(io_fd, KDDISABIO, 0) < 0) {
         perror("ioctl(KDDISABIO)");
-- END --

-- 
Ben Hutchings -- [EMAIL PROTECTED] shortened to [EMAIL PROTECTED]
If you've signed my GPG key, please send a signature on and to the new uid.
Unix is many things to many people,
but it's never been everything to anybody.

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to