Subversion Repositories Kolibri OS

Rev

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