Subversion Repositories Kolibri OS

Rev

Rev 2344 | Rev 2352 | 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.  
  98. #define SRV_BLIT_VIDEO      20
  99.  
  100. #define check_input(size) \
  101.     if( unlikely((inp==NULL)||(io->inp_size != (size))) )   \
  102.         break;
  103.  
  104. #define check_output(size) \
  105.     if( unlikely((outp==NULL)||(io->out_size != (size))) )   \
  106.         break;
  107.  
  108. int _stdcall display_handler(ioctl_t *io)
  109. {
  110.     int    retval = -1;
  111.     u32_t *inp;
  112.     u32_t *outp;
  113.  
  114.     inp = io->input;
  115.     outp = io->output;
  116.  
  117.     switch(io->io_code)
  118.     {
  119.         case SRV_GETVERSION:
  120.             check_output(4);
  121.             *outp  = DISPLAY_VERSION;
  122.             retval = 0;
  123.             break;
  124.  
  125.         case SRV_ENUM_MODES:
  126.             dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n",
  127.                        inp, io->inp_size, io->out_size );
  128.             check_output(4);
  129. //            check_input(*outp * sizeof(videomode_t));
  130.             if( i915_modeset)
  131.                 retval = get_videomodes((videomode_t*)inp, outp);
  132.             break;
  133.  
  134.         case SRV_SET_MODE:
  135.             dbgprintf("SRV_SET_MODE inp %x inp_size %x\n",
  136.                        inp, io->inp_size);
  137.             check_input(sizeof(videomode_t));
  138.             if( i915_modeset )
  139.                 retval = set_user_mode((videomode_t*)inp);
  140.             break;
  141.  
  142.         case SRV_GET_CAPS:
  143.             retval = get_driver_caps((hwcaps_t*)inp);
  144.             break;
  145.  
  146.         case SRV_CREATE_SURFACE:
  147. //            check_input(8);
  148.             retval = create_surface((struct io_call_10*)inp);
  149.             break;
  150.  
  151.  
  152.         case SRV_BLIT_VIDEO:
  153. //            blit_video( inp[0], inp[1], inp[2],
  154. //                    inp[3], inp[4], inp[5], inp[6]);
  155.  
  156.             blit_textured( inp[0], inp[1], inp[2],
  157.                     inp[3], inp[4], inp[5], inp[6]);
  158.  
  159.             retval = 0;
  160.             break;
  161.     };
  162.  
  163.     return retval;
  164. }
  165.  
  166.  
  167. #define PCI_CLASS_REVISION      0x08
  168. #define PCI_CLASS_DISPLAY_VGA   0x0300
  169. #define PCI_CLASS_BRIDGE_HOST   0x0600
  170. #define PCI_CLASS_BRIDGE_ISA    0x0601
  171.  
  172. int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn)
  173. {
  174.     u16_t vendor, device;
  175.     u32_t class;
  176.     int   ret = 0;
  177.  
  178.     vendor   = id & 0xffff;
  179.     device   = (id >> 16) & 0xffff;
  180.  
  181.     if(vendor == 0x8086)
  182.     {
  183.         class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
  184.         class >>= 16;
  185.  
  186.         if( (class == PCI_CLASS_DISPLAY_VGA) ||
  187.             (class == PCI_CLASS_BRIDGE_HOST) ||
  188.             (class == PCI_CLASS_BRIDGE_ISA))
  189.             ret = 1;
  190.     }
  191.     return ret;
  192. };
  193.  
  194.  
  195. static char* parse_path(char *p, char *log)
  196. {
  197.     char  c;
  198.  
  199.     while( (c = *p++) == ' ');
  200.         p--;
  201.     while( (c = *log++ = *p++) && (c != ' '));
  202.     *log = 0;
  203.  
  204.     return p;
  205. };
  206.  
  207. void parse_cmdline(char *cmdline, char *log)
  208. {
  209.     char *p = cmdline;
  210.  
  211.     char c = *p++;
  212.  
  213.     while( c )
  214.     {
  215.         if( c == '-')
  216.         {
  217.             switch(*p++)
  218.             {
  219.                 case 'l':
  220.                     p = parse_path(p, log);
  221.                     break;
  222.             };
  223.         };
  224.         c = *p++;
  225.     };
  226. };
  227.  
  228.  
  229. static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
  230.                 unsigned int *ecx, unsigned int *edx)
  231. {
  232.     /* ecx is often an input as well as an output. */
  233.     asm volatile("cpuid"
  234.         : "=a" (*eax),
  235.           "=b" (*ebx),
  236.           "=c" (*ecx),
  237.           "=d" (*edx)
  238.         : "0" (*eax), "2" (*ecx)
  239.         : "memory");
  240. }
  241.  
  242.  
  243.  
  244. static inline void cpuid(unsigned int op,
  245.                          unsigned int *eax, unsigned int *ebx,
  246.                          unsigned int *ecx, unsigned int *edx)
  247. {
  248.         *eax = op;
  249.         *ecx = 0;
  250.         __cpuid(eax, ebx, ecx, edx);
  251. }
  252.  
  253. void cpu_detect()
  254. {
  255.     u32 junk, tfms, cap0, misc;
  256.  
  257.     cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
  258.  
  259.     if (cap0 & (1<<19))
  260.     {
  261.         x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  262.     }
  263. }
  264.  
  265.