Subversion Repositories Kolibri OS

Rev

Rev 2340 | Rev 2344 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "drmP.h"
  2. #include "drm.h"
  3. #include "i915_drm.h"
  4. #include "i915_drv.h"
  5. #include "intel_drv.h"
  6.  
  7.  
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/mod_devicetable.h>
  11. #include <errno-base.h>
  12. #include <linux/pci.h>
  13. #include <syscall.h>
  14.  
  15. #include "bitmap.h"
  16.  
  17. void parse_cmdline(char *cmdline, char *log);
  18. int _stdcall display_handler(ioctl_t *io);
  19. int init_agp(void);
  20.  
  21. int create_video(int width, int height, u32_t *outp);
  22. int video_blit(uint64_t src_offset, int  x, int y,
  23.                     int w, int h, int pitch);
  24.  
  25. static char  log[256];
  26.  
  27. int i915_modeset = 1;
  28.  
  29. u32_t drvEntry(int action, char *cmdline)
  30. {
  31.     struct pci_device_id  *ent;
  32.  
  33.     int     err = 0;
  34.  
  35.     if(action != 1)
  36.         return 0;
  37.  
  38.     if( GetService("DISPLAY") != 0 )
  39.         return 0;
  40.  
  41.     if( cmdline && *cmdline )
  42.         parse_cmdline(cmdline, log);
  43.  
  44.     if(!dbg_open(log))
  45.     {
  46.         strcpy(log, "/RD/1/DRIVERS/i915.log");
  47.  
  48.         if(!dbg_open(log))
  49.         {
  50.             printf("Can't open %s\nExit\n", log);
  51.             return 0;
  52.         };
  53.     }
  54.     dbgprintf("i915 blitter preview\n cmdline: %s\n", cmdline);
  55.  
  56.     enum_pci_devices();
  57.  
  58.     err = i915_init();
  59.  
  60.     if(err)
  61.     {
  62.         dbgprintf("Epic Fail :(/n");
  63.  
  64.     };
  65.  
  66.     err = RegService("DISPLAY", display_handler);
  67.  
  68.     if( err != 0)
  69.         dbgprintf("Set DISPLAY handler\n");
  70.  
  71.     return err;
  72. };
  73.  
  74. #define API_VERSION     0x01000100
  75.  
  76. #define SRV_GETVERSION      0
  77. #define SRV_ENUM_MODES      1
  78. #define SRV_SET_MODE        2
  79.  
  80. #define SRV_CREATE_BITMAP  10
  81.  
  82. #define SRV_BLIT_VIDEO     20
  83.  
  84. #define check_input(size) \
  85.     if( unlikely((inp==NULL)||(io->inp_size != (size))) )   \
  86.         break;
  87.  
  88. #define check_output(size) \
  89.     if( unlikely((outp==NULL)||(io->out_size != (size))) )   \
  90.         break;
  91.  
  92. int _stdcall display_handler(ioctl_t *io)
  93. {
  94.     int    retval = -1;
  95.     u32_t *inp;
  96.     u32_t *outp;
  97.  
  98.     inp = io->input;
  99.     outp = io->output;
  100.  
  101.     switch(io->io_code)
  102.     {
  103.         case SRV_GETVERSION:
  104.             check_output(4);
  105.             *outp  = API_VERSION;
  106.             retval = 0;
  107.             break;
  108.  
  109.         case SRV_ENUM_MODES:
  110.             dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n",
  111.                        inp, io->inp_size, io->out_size );
  112.             check_output(4);
  113. //            check_input(*outp * sizeof(videomode_t));
  114.             if( i915_modeset)
  115.                 retval = get_videomodes((videomode_t*)inp, outp);
  116.             break;
  117.  
  118.         case SRV_SET_MODE:
  119.             dbgprintf("SRV_SET_MODE inp %x inp_size %x\n",
  120.                        inp, io->inp_size);
  121.             check_input(sizeof(videomode_t));
  122.             if( i915_modeset )
  123.                 retval = set_user_mode((videomode_t*)inp);
  124.             break;
  125.  
  126.         case SRV_CREATE_BITMAP:
  127.             check_input(5);
  128.             retval = create_bitmap((struct ubitmap*)inp);
  129.             break;
  130.  
  131.  
  132.         case SRV_BLIT_VIDEO:
  133.             blit_video( inp[0], inp[1], inp[2],
  134.                     inp[3], inp[4], inp[5], inp[6]);
  135.  
  136.             retval = 0;
  137.             break;
  138.     };
  139.  
  140.     return retval;
  141. }
  142.  
  143.  
  144. #define PCI_CLASS_REVISION      0x08
  145. #define PCI_CLASS_DISPLAY_VGA   0x0300
  146. #define PCI_CLASS_BRIDGE_HOST   0x0600
  147. #define PCI_CLASS_BRIDGE_ISA    0x0601
  148.  
  149. int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn)
  150. {
  151.     u16_t vendor, device;
  152.     u32_t class;
  153.     int   ret = 0;
  154.  
  155.     vendor   = id & 0xffff;
  156.     device   = (id >> 16) & 0xffff;
  157.  
  158.     if(vendor == 0x8086)
  159.     {
  160.         class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
  161.         class >>= 16;
  162.  
  163.         if( (class == PCI_CLASS_DISPLAY_VGA) ||
  164.             (class == PCI_CLASS_BRIDGE_HOST) ||
  165.             (class == PCI_CLASS_BRIDGE_ISA))
  166.             ret = 1;
  167.     }
  168.     return ret;
  169. };
  170.  
  171.  
  172. static char* parse_path(char *p, char *log)
  173. {
  174.     char  c;
  175.  
  176.     while( (c = *p++) == ' ');
  177.         p--;
  178.     while( (c = *log++ = *p++) && (c != ' '));
  179.     *log = 0;
  180.  
  181.     return p;
  182. };
  183.  
  184. void parse_cmdline(char *cmdline, char *log)
  185. {
  186.     char *p = cmdline;
  187.  
  188.     char c = *p++;
  189.  
  190.     while( c )
  191.     {
  192.         if( c == '-')
  193.         {
  194.             switch(*p++)
  195.             {
  196.                 case 'l':
  197.                     p = parse_path(p, log);
  198.                     break;
  199.             };
  200.         };
  201.         c = *p++;
  202.     };
  203. };
  204.  
  205.