Subversion Repositories Kolibri OS

Rev

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