home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / mondello / misc.c < prev    next >
C/C++ Source or Header  |  1996-05-27  |  2KB  |  83 lines

  1. /*
  2.   file: misc.c
  3. */
  4.  
  5. #include "mondello/compiler.h"  /* outb(), outw(), outl(), inb(), inw(), inl() */
  6. #include "mondello/misc.h"
  7.  
  8. /*
  9.  * PCI code gratuitously stolen from XF86's 
  10.  * xc/programs/Xserver/hw/xf86/etc/scanpci.c. 
  11.  * Original code written by Robin Cutshaw (robin@xfree86.org)
  12.  * Adapted (read: ripped) by Peter McDermott for Mesa's Mondello driver
  13.  * in Mesa 3.1.8.
  14.  */
  15.  
  16. /*----------------------------------------------------------------------------
  17.   PCILock - locks the PCI bus from stray writes
  18. -----------------------------------------------------------------------------*/
  19. void PCILock()
  20. {
  21.   outl(0xcf8,0x00000000);
  22. }
  23.  
  24. #include <unistd.h>
  25.  
  26. /*----------------------------------------------------------------------------
  27.   PCIUnlock - unlocks the PCI bus to allow configuration info to be read
  28. -----------------------------------------------------------------------------*/
  29. void PCIUnlock()
  30. {
  31.   long tmp1;
  32.   long tmp2;
  33.  
  34.  
  35. /*
  36.   outb(0xcf8,0x00);        
  37.   outb(0xcfa,0x00);
  38.   tmp1 = inb(0xcf8);
  39.   tmp2 = inb(0xcfa);
  40.   if ((tmp1==0x00) && (tmp2==0x00)) {
  41.     printf("PCI says configuration type 2\n");
  42.   }
  43. */
  44.   
  45.   tmp1=inl(0xcf8);
  46.   outl(0xcf8,0x80000000);
  47.   tmp2=inl(0xcf8);
  48.   outl(0xcf8,tmp1);
  49.   if (tmp2!=0x80000000) {
  50.     printf("PCIUnlock: No PCI available!");
  51.   }
  52.  
  53. }
  54.  
  55. /*----------------------------------------------------------------------------
  56.   PCIOut - sends an int at an address to the PCI bus (device=card #)
  57. -----------------------------------------------------------------------------*/
  58. void PCIOut(int device, int address, int data)
  59. {
  60.   int data_out;
  61.  
  62.   data_out=0x80000000;
  63.   data_out|=device << 11;
  64.   data_out|=(address & 0x3f);
  65.   outl(0xcf8,data_out);
  66.   outl(0xcfc,data);
  67.  
  68. }
  69.  
  70. /*----------------------------------------------------------------------------
  71.   PCIIn - reads an int at an address from the PCI bus (device=card #)
  72. -----------------------------------------------------------------------------*/
  73. int PCIIn(int device, int address) 
  74. {
  75.   int data_out;
  76.  
  77.   data_out=0x80000000;
  78.   data_out|=device << 11;
  79.   data_out|=(address & 0x3f);
  80.   outl(0xcf8,data_out);
  81.   return inl(0xcfc);
  82. }
  83.