Subversion Repositories Kolibri OS

Rev

Rev 2351 | Rev 3031 | 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 cpu_detect();
  18.  
  19. void parse_cmdline(char *cmdline, char *log);
  20. int _stdcall display_handler(ioctl_t *io);
  21. int init_agp(void);
  22.  
  23. int blit_video(u32 hbitmap, int  dst_x, int dst_y,
  24.                int src_x, int src_y, u32 w, u32 h);
  25.  
  26. int blit_textured(u32 hbitmap, int  dst_x, int dst_y,
  27.                int src_x, int src_y, u32 w, u32 h);
  28.  
  29. static char  log[256];
  30.  
  31. int x86_clflush_size;
  32.  
  33. int i915_modeset = 1;
  34.  
  35. u32_t drvEntry(int action, char *cmdline)
  36. {
  37.     struct pci_device_id  *ent;
  38.  
  39.     int     err = 0;
  40.  
  41.     if(action != 1)
  42.         return 0;
  43.  
  44.     if( GetService("DISPLAY") != 0 )
  45.         return 0;
  46.  
  47.     if( cmdline && *cmdline )
  48.         parse_cmdline(cmdline, log);
  49.  
  50.     if(!dbg_open(log))
  51.     {
  52. //        strcpy(log, "/RD/1/DRIVERS/i915.log");
  53.         strcpy(log, "/HD1/2/i915.log");
  54.  
  55.         if(!dbg_open(log))
  56.         {
  57.             printf("Can't open %s\nExit\n", log);
  58.             return 0;
  59.         };
  60.     }
  61.     dbgprintf("i915 blitter preview\n cmdline: %s\n", cmdline);
  62.  
  63.     cpu_detect();
  64.     dbgprintf("\ncache line size %d\n", x86_clflush_size);
  65.  
  66.     enum_pci_devices();
  67.  
  68.     err = i915_init();
  69.  
  70.     if(err)
  71.     {
  72.         dbgprintf("Epic Fail :(/n");
  73.  
  74.     };
  75.  
  76.     err = RegService("DISPLAY", display_handler);
  77.  
  78.     if( err != 0)
  79.         dbgprintf("Set DISPLAY handler\n");
  80.  
  81.     return err;
  82. };
  83.  
  84. #define CURRENT_API     0x0200      /*      2.00     */
  85. #define COMPATIBLE_API  0x0100      /*      1.00     */
  86.  
  87. #define API_VERSION     (COMPATIBLE_API << 16) | CURRENT_API
  88. #define DISPLAY_VERSION  API_VERSION
  89.  
  90.  
  91. #define SRV_GETVERSION          0
  92. #define SRV_ENUM_MODES          1
  93. #define SRV_SET_MODE            2
  94. #define SRV_GET_CAPS            3
  95.  
  96. #define SRV_CREATE_SURFACE      10
  97. #define SRV_DESTROY_SURFACE     11
  98. #define SRV_LOCK_SURFACE        12
  99. #define SRV_UNLOCK_SURFACE      13
  100.  
  101. #define SRV_BLIT_VIDEO          20
  102.  
  103. #define check_input(size) \
  104.     if( unlikely((inp==NULL)||(io->inp_size != (size))) )   \
  105.         break;
  106.  
  107. #define check_output(size) \
  108.     if( unlikely((outp==NULL)||(io->out_size != (size))) )   \
  109.         break;
  110.  
  111. int _stdcall display_handler(ioctl_t *io)
  112. {
  113.     int    retval = -1;
  114.     u32_t *inp;
  115.     u32_t *outp;
  116.  
  117.     inp = io->input;
  118.     outp = io->output;
  119.  
  120.     switch(io->io_code)
  121.     {
  122.         case SRV_GETVERSION:
  123.             check_output(4);
  124.             *outp  = DISPLAY_VERSION;
  125.             retval = 0;
  126.             break;
  127.  
  128.         case SRV_ENUM_MODES:
  129.             dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n",
  130.                        inp, io->inp_size, io->out_size );
  131.             check_output(4);
  132. //            check_input(*outp * sizeof(videomode_t));
  133.             if( i915_modeset)
  134.                 retval = get_videomodes((videomode_t*)inp, outp);
  135.             break;
  136.  
  137.         case SRV_SET_MODE:
  138.             dbgprintf("SRV_SET_MODE inp %x inp_size %x\n",
  139.                        inp, io->inp_size);
  140.             check_input(sizeof(videomode_t));
  141.             if( i915_modeset )
  142.                 retval = set_user_mode((videomode_t*)inp);
  143.             break;
  144.  
  145.         case SRV_GET_CAPS:
  146.             retval = get_driver_caps((hwcaps_t*)inp);
  147.             break;
  148.  
  149.         case SRV_CREATE_SURFACE:
  150. //            check_input(8);
  151.             retval = create_surface((struct io_call_10*)inp);
  152.             break;
  153.  
  154.         case SRV_LOCK_SURFACE:
  155.             retval = lock_surface((struct io_call_12*)inp);
  156.             break;
  157.  
  158.         case SRV_BLIT_VIDEO:
  159. //            blit_video( inp[0], inp[1], inp[2],
  160. //                    inp[3], inp[4], inp[5], inp[6]);
  161.  
  162.             blit_textured( inp[0], inp[1], inp[2],
  163.                     inp[3], inp[4], inp[5], inp[6]);
  164.  
  165.  
  166.             retval = 0;
  167.             break;
  168.     };
  169.  
  170.     return retval;
  171. }
  172.  
  173.  
  174. #define PCI_CLASS_REVISION      0x08
  175. #define PCI_CLASS_DISPLAY_VGA   0x0300
  176. #define PCI_CLASS_BRIDGE_HOST   0x0600
  177. #define PCI_CLASS_BRIDGE_ISA    0x0601
  178.  
  179. int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn)
  180. {
  181.     u16_t vendor, device;
  182.     u32_t class;
  183.     int   ret = 0;
  184.  
  185.     vendor   = id & 0xffff;
  186.     device   = (id >> 16) & 0xffff;
  187.  
  188.     if(vendor == 0x8086)
  189.     {
  190.         class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
  191.         class >>= 16;
  192.  
  193.         if( (class == PCI_CLASS_DISPLAY_VGA) ||
  194.             (class == PCI_CLASS_BRIDGE_HOST) ||
  195.             (class == PCI_CLASS_BRIDGE_ISA))
  196.             ret = 1;
  197.     }
  198.     return ret;
  199. };
  200.  
  201.  
  202. static char* parse_path(char *p, char *log)
  203. {
  204.     char  c;
  205.  
  206.     while( (c = *p++) == ' ');
  207.         p--;
  208.     while( (c = *log++ = *p++) && (c != ' '));
  209.     *log = 0;
  210.  
  211.     return p;
  212. };
  213.  
  214. void parse_cmdline(char *cmdline, char *log)
  215. {
  216.     char *p = cmdline;
  217.  
  218.     char c = *p++;
  219.  
  220.     while( c )
  221.     {
  222.         if( c == '-')
  223.         {
  224.             switch(*p++)
  225.             {
  226.                 case 'l':
  227.                     p = parse_path(p, log);
  228.                     break;
  229.             };
  230.         };
  231.         c = *p++;
  232.     };
  233. };
  234.  
  235.  
  236. static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
  237.                 unsigned int *ecx, unsigned int *edx)
  238. {
  239.     /* ecx is often an input as well as an output. */
  240.     asm volatile("cpuid"
  241.         : "=a" (*eax),
  242.           "=b" (*ebx),
  243.           "=c" (*ecx),
  244.           "=d" (*edx)
  245.         : "0" (*eax), "2" (*ecx)
  246.         : "memory");
  247. }
  248.  
  249.  
  250.  
  251. static inline void cpuid(unsigned int op,
  252.                          unsigned int *eax, unsigned int *ebx,
  253.                          unsigned int *ecx, unsigned int *edx)
  254. {
  255.         *eax = op;
  256.         *ecx = 0;
  257.         __cpuid(eax, ebx, ecx, edx);
  258. }
  259.  
  260. void cpu_detect()
  261. {
  262.     u32 junk, tfms, cap0, misc;
  263.  
  264.     cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
  265.  
  266.     if (cap0 & (1<<19))
  267.     {
  268.         x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  269.     }
  270. }
  271.  
  272.