Subversion Repositories Kolibri OS

Rev

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

  1. #include <drm/drmP.h>
  2. #include <drm.h>
  3. #include <drm/i915_drm.h>
  4. #include "i915_drv.h"
  5. //#include "intel_drv.h"
  6.  
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/mod_devicetable.h>
  10. #include <errno-base.h>
  11. #include <linux/pci.h>
  12. #include <syscall.h>
  13.  
  14. #include "bitmap.h"
  15.  
  16. struct pci_device {
  17.     uint16_t    domain;
  18.     uint8_t     bus;
  19.     uint8_t     dev;
  20.     uint8_t     func;
  21.     uint16_t    vendor_id;
  22.     uint16_t    device_id;
  23.     uint16_t    subvendor_id;
  24.     uint16_t    subdevice_id;
  25.     uint32_t    device_class;
  26.     uint8_t     revision;
  27. };
  28.  
  29. struct drm_device *main_device;
  30. struct drm_file   *drm_file_handlers[256];
  31.  
  32. void cpu_detect();
  33.  
  34. void parse_cmdline(char *cmdline, char *log);
  35. int _stdcall display_handler(ioctl_t *io);
  36. int init_agp(void);
  37.  
  38. int srv_blit_bitmap(u32 hbitmap, int  dst_x, int dst_y,
  39.                int src_x, int src_y, u32 w, u32 h);
  40.  
  41. int blit_textured(u32 hbitmap, int  dst_x, int dst_y,
  42.                int src_x, int src_y, u32 w, u32 h);
  43.  
  44. int blit_tex(u32 hbitmap, int  dst_x, int dst_y,
  45.              int src_x, int src_y, u32 w, u32 h);
  46.  
  47. void get_pci_info(struct pci_device *dev);
  48. int gem_getparam(struct drm_device *dev, void *data);
  49.  
  50. int i915_mask_update(struct drm_device *dev, void *data,
  51.             struct drm_file *file);
  52.  
  53.  
  54. static char  log[256];
  55.  
  56. struct workqueue_struct *system_wq;
  57. int driver_wq_state;
  58.  
  59. int x86_clflush_size;
  60. unsigned int tsc_khz;
  61.  
  62. int i915_modeset = 1;
  63.  
  64. u32_t  __attribute__((externally_visible)) drvEntry(int action, char *cmdline)
  65. {
  66.     int err = 0;
  67.  
  68.     if(action != 1)
  69.     {
  70.         driver_wq_state = 0;
  71.         return 0;
  72.     };
  73.  
  74.     if( GetService("DISPLAY") != 0 )
  75.         return 0;
  76.  
  77.     if( cmdline && *cmdline )
  78.         parse_cmdline(cmdline, log);
  79.  
  80.     if(!dbg_open(log))
  81.     {
  82. //        strcpy(log, "/tmp1/1/i915.log");
  83. //        strcpy(log, "/RD/1/DRIVERS/i915.log");
  84.         strcpy(log, "/BD1/4/i915.log");
  85.  
  86.         if(!dbg_open(log))
  87.         {
  88.             printf("Can't open %s\nExit\n", log);
  89.             return 0;
  90.         };
  91.     }
  92.     dbgprintf(" i915 v3.12-6\n cmdline: %s\n", cmdline);
  93.  
  94.     cpu_detect();
  95. //    dbgprintf("\ncache line size %d\n", x86_clflush_size);
  96.  
  97.     enum_pci_devices();
  98.  
  99.     err = i915_init();
  100.     if(err)
  101.     {
  102.         dbgprintf("Epic Fail :(\n");
  103.         return 0;
  104.     };
  105.     init_display_kms(main_device);
  106.  
  107.     err = RegService("DISPLAY", display_handler);
  108.  
  109.     if( err != 0)
  110.         dbgprintf("Set DISPLAY handler\n");
  111.  
  112.     struct drm_i915_private *dev_priv = main_device->dev_private;
  113.  
  114.     driver_wq_state = 1;
  115.  
  116.     run_workqueue(dev_priv->wq);
  117.  
  118.     return err;
  119. };
  120.  
  121.  
  122. #define CURRENT_API     0x0200      /*      2.00     */
  123. #define COMPATIBLE_API  0x0100      /*      1.00     */
  124.  
  125. #define API_VERSION     (COMPATIBLE_API << 16) | CURRENT_API
  126. #define DISPLAY_VERSION  API_VERSION
  127.  
  128.  
  129. #define SRV_GETVERSION          0
  130. #define SRV_ENUM_MODES          1
  131. #define SRV_SET_MODE            2
  132. #define SRV_GET_CAPS            3
  133.  
  134. #define SRV_CREATE_SURFACE      10
  135. #define SRV_DESTROY_SURFACE     11
  136. #define SRV_LOCK_SURFACE        12
  137. #define SRV_UNLOCK_SURFACE      13
  138. #define SRV_RESIZE_SURFACE      14
  139. #define SRV_BLIT_BITMAP         15
  140. #define SRV_BLIT_TEXTURE        16
  141. #define SRV_BLIT_VIDEO          17
  142.  
  143.  
  144. #define SRV_GET_PCI_INFO            20
  145. #define SRV_GET_PARAM               21
  146. #define SRV_I915_GEM_CREATE         22
  147. #define SRV_DRM_GEM_CLOSE           23
  148. #define SRV_I915_GEM_PIN            24
  149. #define SRV_I915_GEM_SET_CACHEING   25
  150. #define SRV_I915_GEM_GET_APERTURE   26
  151. #define SRV_I915_GEM_PWRITE         27
  152. #define SRV_I915_GEM_BUSY           28
  153. #define SRV_I915_GEM_SET_DOMAIN     29
  154. #define SRV_I915_GEM_MMAP           30
  155. #define SRV_I915_GEM_MMAP_GTT       31
  156. #define SRV_I915_GEM_THROTTLE       32
  157. #define SRV_FBINFO                  33
  158. #define SRV_I915_GEM_EXECBUFFER2    34
  159. #define SRV_MASK_UPDATE             35
  160.  
  161.  
  162.  
  163. #define check_input(size) \
  164.     if( unlikely((inp==NULL)||(io->inp_size != (size))) )   \
  165.         break;
  166.  
  167. #define check_output(size) \
  168.     if( unlikely((outp==NULL)||(io->out_size != (size))) )   \
  169.         break;
  170.  
  171. int _stdcall display_handler(ioctl_t *io)
  172. {
  173.     struct drm_file *file;
  174.  
  175.     int    retval = -1;
  176.     u32_t *inp;
  177.     u32_t *outp;
  178.  
  179.     inp = io->input;
  180.     outp = io->output;
  181.  
  182.     file = drm_file_handlers[0];
  183.  
  184.     switch(io->io_code)
  185.     {
  186.         case SRV_GETVERSION:
  187.             check_output(4);
  188.             *outp  = DISPLAY_VERSION;
  189.             retval = 0;
  190.             break;
  191.  
  192.         case SRV_ENUM_MODES:
  193. //            dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n",
  194. //                       inp, io->inp_size, io->out_size );
  195.             check_output(4);
  196. //            check_input(*outp * sizeof(videomode_t));
  197.             if( i915_modeset)
  198.                 retval = get_videomodes((videomode_t*)inp, outp);
  199.             break;
  200.  
  201.         case SRV_SET_MODE:
  202. //            dbgprintf("SRV_SET_MODE inp %x inp_size %x\n",
  203. //                       inp, io->inp_size);
  204.             check_input(sizeof(videomode_t));
  205.             if( i915_modeset )
  206.                 retval = set_user_mode((videomode_t*)inp);
  207.             break;
  208.  
  209.         case SRV_GET_CAPS:
  210.             retval = get_driver_caps((hwcaps_t*)inp);
  211.             break;
  212.  
  213.         case SRV_CREATE_SURFACE:
  214. //            check_input(8);
  215. //            retval = create_surface(main_device, (struct io_call_10*)inp);
  216.             break;
  217.  
  218.         case SRV_LOCK_SURFACE:
  219. //            retval = lock_surface((struct io_call_12*)inp);
  220.             break;
  221.  
  222.         case SRV_RESIZE_SURFACE:
  223. //            retval = resize_surface((struct io_call_14*)inp);
  224.             break;
  225.  
  226.         case SRV_BLIT_BITMAP:
  227. //            srv_blit_bitmap( inp[0], inp[1], inp[2],
  228. //                        inp[3], inp[4], inp[5], inp[6]);
  229.  
  230. //            blit_tex( inp[0], inp[1], inp[2],
  231. //                    inp[3], inp[4], inp[5], inp[6]);
  232.  
  233.             break;
  234.  
  235.         case SRV_GET_PCI_INFO:
  236.             get_pci_info((struct pci_device *)inp);
  237.             retval = 0;
  238.             break;
  239.  
  240.         case SRV_GET_PARAM:
  241.             retval = gem_getparam(main_device, inp);
  242.             break;
  243.  
  244.         case SRV_I915_GEM_CREATE:
  245.             retval = i915_gem_create_ioctl(main_device, inp, file);
  246.             break;
  247.  
  248.         case SRV_DRM_GEM_CLOSE:
  249.             retval = drm_gem_close_ioctl(main_device, inp, file);
  250.             break;
  251.  
  252.         case SRV_I915_GEM_PIN:
  253.             retval = i915_gem_pin_ioctl(main_device, inp, file);
  254.             break;
  255.  
  256.         case SRV_I915_GEM_SET_CACHEING:
  257.             retval = i915_gem_set_caching_ioctl(main_device, inp, file);
  258.             break;
  259.  
  260.         case SRV_I915_GEM_GET_APERTURE:
  261.             retval = i915_gem_get_aperture_ioctl(main_device, inp, file);
  262.             break;
  263.  
  264.         case SRV_I915_GEM_PWRITE:
  265.             retval = i915_gem_pwrite_ioctl(main_device, inp, file);
  266.             break;
  267.  
  268.         case SRV_I915_GEM_BUSY:
  269.             retval = i915_gem_busy_ioctl(main_device, inp, file);
  270.             break;
  271.  
  272.         case SRV_I915_GEM_SET_DOMAIN:
  273.             retval = i915_gem_set_domain_ioctl(main_device, inp, file);
  274.             break;
  275.  
  276.         case SRV_I915_GEM_THROTTLE:
  277.             retval = i915_gem_throttle_ioctl(main_device, inp, file);
  278.             break;
  279.  
  280.         case SRV_I915_GEM_MMAP:
  281.             retval = i915_gem_mmap_ioctl(main_device, inp, file);
  282.             break;
  283.  
  284.         case SRV_I915_GEM_MMAP_GTT:
  285.             retval = i915_gem_mmap_gtt_ioctl(main_device, inp, file);
  286.             break;
  287.  
  288.  
  289.         case SRV_FBINFO:
  290.             retval = i915_fbinfo(inp);
  291.             break;
  292.  
  293.         case SRV_I915_GEM_EXECBUFFER2:
  294.             retval = i915_gem_execbuffer2(main_device, inp, file);
  295.             break;
  296.  
  297.         case SRV_MASK_UPDATE:
  298.             retval = i915_mask_update(main_device, inp, file);
  299.             break;
  300.  
  301.     };
  302.  
  303.     return retval;
  304. }
  305.  
  306.  
  307. #define PCI_CLASS_REVISION      0x08
  308. #define PCI_CLASS_DISPLAY_VGA   0x0300
  309. #define PCI_CLASS_BRIDGE_HOST   0x0600
  310. #define PCI_CLASS_BRIDGE_ISA    0x0601
  311.  
  312. int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn)
  313. {
  314.     u16_t vendor, device;
  315.     u32_t class;
  316.     int   ret = 0;
  317.  
  318.     vendor   = id & 0xffff;
  319.     device   = (id >> 16) & 0xffff;
  320.  
  321.     if(vendor == 0x8086)
  322.     {
  323.         class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
  324.         class >>= 16;
  325.  
  326.         if( (class == PCI_CLASS_DISPLAY_VGA) ||
  327.             (class == PCI_CLASS_BRIDGE_HOST) ||
  328.             (class == PCI_CLASS_BRIDGE_ISA))
  329.             ret = 1;
  330.     }
  331.     return ret;
  332. };
  333.  
  334.  
  335. static char* parse_path(char *p, char *log)
  336. {
  337.     char  c;
  338.  
  339.     while( (c = *p++) == ' ');
  340.         p--;
  341.     while( (c = *log++ = *p++) && (c != ' '));
  342.     *log = 0;
  343.  
  344.     return p;
  345. };
  346.  
  347. void parse_cmdline(char *cmdline, char *log)
  348. {
  349.     char *p = cmdline;
  350.  
  351.     char c = *p++;
  352.  
  353.     while( c )
  354.     {
  355.         if( c == '-')
  356.         {
  357.             switch(*p++)
  358.             {
  359.                 case 'l':
  360.                     p = parse_path(p, log);
  361.                     break;
  362.             };
  363.         };
  364.         c = *p++;
  365.     };
  366. };
  367.  
  368.  
  369. static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
  370.                 unsigned int *ecx, unsigned int *edx)
  371. {
  372.     /* ecx is often an input as well as an output. */
  373.     asm volatile("cpuid"
  374.         : "=a" (*eax),
  375.           "=b" (*ebx),
  376.           "=c" (*ecx),
  377.           "=d" (*edx)
  378.         : "0" (*eax), "2" (*ecx)
  379.         : "memory");
  380. }
  381.  
  382.  
  383.  
  384. static inline void cpuid(unsigned int op,
  385.                          unsigned int *eax, unsigned int *ebx,
  386.                          unsigned int *ecx, unsigned int *edx)
  387. {
  388.         *eax = op;
  389.         *ecx = 0;
  390.         __cpuid(eax, ebx, ecx, edx);
  391. }
  392.  
  393. void cpu_detect()
  394. {
  395.     u32 junk, tfms, cap0, misc;
  396.  
  397.     cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
  398.  
  399.     if (cap0 & (1<<19))
  400.     {
  401.         x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  402.     }
  403.  
  404.     tsc_khz = (unsigned int)(GetCpuFreq()/1000);
  405. }
  406.  
  407.  
  408. int get_driver_caps(hwcaps_t *caps)
  409. {
  410.     int ret = 0;
  411.  
  412.     switch(caps->idx)
  413.     {
  414.         case 0:
  415.             caps->opt[0] = 0;
  416.             caps->opt[1] = 0;
  417.             break;
  418.  
  419.         case 1:
  420.             caps->cap1.max_tex_width  = 4096;
  421.             caps->cap1.max_tex_height = 4096;
  422.             break;
  423.         default:
  424.             ret = 1;
  425.     };
  426.     caps->idx = 1;
  427.     return ret;
  428. }
  429.  
  430.  
  431. void get_pci_info(struct pci_device *dev)
  432. {
  433.     struct pci_dev *pdev = main_device->pdev;
  434.  
  435.     memset(dev, sizeof(*dev), 0);
  436.  
  437.     dev->domain     = 0;
  438.     dev->bus        = pdev->busnr;
  439.     dev->dev        = pdev->devfn >> 3;
  440.     dev->func       = pdev->devfn & 7;
  441.     dev->vendor_id  = pdev->vendor;
  442.     dev->device_id  = pdev->device;
  443.     dev->revision   = pdev->revision;
  444. };
  445.