Subversion Repositories Kolibri OS

Rev

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