Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #define iowrite32(v, addr)      writel((v), (addr))
  3.  
  4. #include "drmP.h"
  5. #include "drm.h"
  6. #include "i915_drm.h"
  7. #include "i915_drv.h"
  8. #include "intel_drv.h"
  9.  
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/mod_devicetable.h>
  13. #include <errno-base.h>
  14. #include <linux/pci.h>
  15.  
  16. #include <syscall.h>
  17.  
  18. #include "bitmap.h"
  19.  
  20. typedef struct
  21. {
  22.     kobj_t     header;
  23.  
  24.     uint32_t  *data;
  25.     uint32_t   hot_x;
  26.     uint32_t   hot_y;
  27.  
  28.     struct list_head   list;
  29.     struct drm_i915_gem_object  *cobj;
  30. }cursor_t;
  31.  
  32. #define CURSOR_WIDTH 64
  33. #define CURSOR_HEIGHT 64
  34.  
  35.  
  36. struct tag_display
  37. {
  38.     int  x;
  39.     int  y;
  40.     int  width;
  41.     int  height;
  42.     int  bpp;
  43.     int  vrefresh;
  44.     int  pitch;
  45.     int  lfb;
  46.  
  47.     int  supported_modes;
  48.     struct drm_device    *ddev;
  49.     struct drm_connector *connector;
  50.     struct drm_crtc      *crtc;
  51.  
  52.     struct list_head   cursors;
  53.  
  54.     cursor_t   *cursor;
  55.     int       (*init_cursor)(cursor_t*);
  56.     cursor_t* (__stdcall *select_cursor)(cursor_t*);
  57.     void      (*show_cursor)(int show);
  58.     void      (__stdcall *move_cursor)(cursor_t *cursor, int x, int y);
  59.     void      (__stdcall *restore_cursor)(int x, int y);
  60.     void      (*disable_mouse)(void);
  61.     u32  mask_seqno;
  62.     u32  check_mouse;
  63.     u32  check_m_pixel;
  64.  
  65. };
  66.  
  67.  
  68. static display_t *os_display;
  69.  
  70. u32_t cmd_buffer;
  71. u32_t cmd_offset;
  72.  
  73. void init_render();
  74. int  sna_init();
  75.  
  76. int init_cursor(cursor_t *cursor);
  77. static cursor_t*  __stdcall select_cursor_kms(cursor_t *cursor);
  78. static void       __stdcall move_cursor_kms(cursor_t *cursor, int x, int y);
  79.  
  80. void __stdcall restore_cursor(int x, int y)
  81. {};
  82.  
  83. void disable_mouse(void)
  84. {};
  85.  
  86. static char *manufacturer_name(unsigned char *x)
  87. {
  88.     static char name[4];
  89.  
  90.     name[0] = ((x[0] & 0x7C) >> 2) + '@';
  91.     name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@';
  92.     name[2] = (x[1] & 0x1F) + '@';
  93.     name[3] = 0;
  94.  
  95.     return name;
  96. }
  97.  
  98. bool set_mode(struct drm_device *dev, struct drm_connector *connector,
  99.               videomode_t *reqmode, bool strict)
  100. {
  101.     drm_i915_private_t      *dev_priv   = dev->dev_private;
  102.     struct drm_fb_helper    *fb_helper  = &dev_priv->fbdev->helper;
  103.  
  104.     struct drm_mode_config  *config     = &dev->mode_config;
  105.     struct drm_display_mode *mode       = NULL, *tmpmode;
  106.     struct drm_framebuffer  *fb         = NULL;
  107.     struct drm_crtc         *crtc;
  108.     struct drm_encoder      *encoder;
  109.     struct drm_mode_set     set;
  110.     char *con_name;
  111.     char *enc_name;
  112.     unsigned hdisplay, vdisplay;
  113.     int ret;
  114.  
  115.     mutex_lock(&dev->mode_config.mutex);
  116.  
  117.     list_for_each_entry(tmpmode, &connector->modes, head)
  118.     {
  119.         if( (drm_mode_width(tmpmode)    == reqmode->width)  &&
  120.             (drm_mode_height(tmpmode)   == reqmode->height) &&
  121.             (drm_mode_vrefresh(tmpmode) == reqmode->freq) )
  122.         {
  123.             mode = tmpmode;
  124.             goto do_set;
  125.         }
  126.     };
  127.  
  128.     if( (mode == NULL) && (strict == false) )
  129.     {
  130.         list_for_each_entry(tmpmode, &connector->modes, head)
  131.         {
  132.             if( (drm_mode_width(tmpmode)  == reqmode->width)  &&
  133.                 (drm_mode_height(tmpmode) == reqmode->height) )
  134.             {
  135.                 mode = tmpmode;
  136.                 goto do_set;
  137.             }
  138.         };
  139.     };
  140.  
  141.     DRM_ERROR("%s failed\n", __FUNCTION__);
  142.  
  143.     return -1;
  144.  
  145. do_set:
  146.  
  147.     encoder = connector->encoder;
  148.     crtc = encoder->crtc;
  149.  
  150.     con_name = drm_get_connector_name(connector);
  151.     enc_name = drm_get_encoder_name(encoder);
  152.  
  153.     DRM_DEBUG_KMS("set mode %d %d: crtc %d connector %s encoder %s\n",
  154.               reqmode->width, reqmode->height, crtc->base.id,
  155.               con_name, enc_name);
  156.  
  157.     drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
  158.  
  159.     hdisplay = mode->hdisplay;
  160.     vdisplay = mode->vdisplay;
  161.  
  162.     if (crtc->invert_dimensions)
  163.         swap(hdisplay, vdisplay);
  164.  
  165.     fb = fb_helper->fb;
  166.  
  167.     fb->width  = reqmode->width;
  168.     fb->height = reqmode->height;
  169.     fb->pitches[0]  = ALIGN(reqmode->width * 4, 64);
  170.     fb->pitches[1]  = ALIGN(reqmode->width * 4, 64);
  171.     fb->pitches[2]  = ALIGN(reqmode->width * 4, 64);
  172.     fb->pitches[3]  = ALIGN(reqmode->width * 4, 64);
  173.  
  174.     fb->bits_per_pixel = 32;
  175.     fb->depth = 24;
  176.  
  177.     crtc->fb = fb;
  178.     crtc->enabled = true;
  179.     os_display->crtc = crtc;
  180.  
  181.     set.crtc = crtc;
  182.     set.x = 0;
  183.     set.y = 0;
  184.     set.mode = mode;
  185.     set.connectors = &connector;
  186.     set.num_connectors = 1;
  187.     set.fb = fb;
  188.     ret = crtc->funcs->set_config(&set);
  189.     mutex_unlock(&dev->mode_config.mutex);
  190.  
  191.     if ( !ret )
  192.     {
  193.         os_display->width    = fb->width;
  194.         os_display->height   = fb->height;
  195.         os_display->pitch    = fb->pitches[0];
  196.         os_display->vrefresh = drm_mode_vrefresh(mode);
  197.  
  198.         sysSetScreen(fb->width, fb->height, fb->pitches[0]);
  199.  
  200.         DRM_DEBUG_KMS("new mode %d x %d pitch %d\n",
  201.                        fb->width, fb->height, fb->pitches[0]);
  202.     }
  203.     else
  204.         DRM_ERROR("failed to set mode %d_%d on crtc %p\n",
  205.                    fb->width, fb->height, crtc);
  206.  
  207.  
  208.     return ret;
  209. }
  210.  
  211. static int count_connector_modes(struct drm_connector* connector)
  212. {
  213.     struct drm_display_mode  *mode;
  214.     int count = 0;
  215.  
  216.     list_for_each_entry(mode, &connector->modes, head)
  217.     {
  218.         count++;
  219.     };
  220.     return count;
  221. };
  222.  
  223. static struct drm_connector* get_def_connector(struct drm_device *dev)
  224. {
  225.     struct drm_connector  *connector;
  226.     struct drm_connector_helper_funcs *connector_funcs;
  227.  
  228.     struct drm_connector  *def_connector = NULL;
  229.  
  230.     list_for_each_entry(connector, &dev->mode_config.connector_list, head)
  231.     {
  232.         struct drm_encoder  *encoder;
  233.         struct drm_crtc     *crtc;
  234.  
  235.         if( connector->status != connector_status_connected)
  236.             continue;
  237.  
  238.         connector_funcs = connector->helper_private;
  239.         encoder = connector_funcs->best_encoder(connector);
  240.         if( encoder == NULL)
  241.             continue;
  242.  
  243.         connector->encoder = encoder;
  244.  
  245.         crtc = encoder->crtc;
  246.  
  247.         DRM_DEBUG_KMS("CONNECTOR %x ID:  %d status %d encoder %x\n crtc %x",
  248.                    connector, connector->base.id,
  249.                    connector->status, connector->encoder,
  250.                    crtc);
  251.  
  252. //        if (crtc == NULL)
  253. //            continue;
  254.  
  255.         def_connector = connector;
  256.  
  257.         break;
  258.     };
  259.  
  260.     return def_connector;
  261. };
  262.  
  263.  
  264. int init_display_kms(struct drm_device *dev)
  265. {
  266.     struct drm_connector    *connector;
  267.     struct drm_connector_helper_funcs *connector_funcs;
  268.     struct drm_encoder      *encoder;
  269.     struct drm_crtc         *crtc = NULL;
  270.     struct drm_framebuffer  *fb;
  271.  
  272.     cursor_t  *cursor;
  273.     u32_t      ifl;
  274.     int        err;
  275.  
  276.     list_for_each_entry(connector, &dev->mode_config.connector_list, head)
  277.     {
  278.         if( connector->status != connector_status_connected)
  279.             continue;
  280.  
  281.         connector_funcs = connector->helper_private;
  282.         encoder = connector_funcs->best_encoder(connector);
  283.         if( encoder == NULL)
  284.         {
  285.             DRM_DEBUG_KMS("CONNECTOR %x ID: %d no active encoders\n",
  286.                       connector, connector->base.id);
  287.             continue;
  288.         }
  289.         connector->encoder = encoder;
  290.         crtc = encoder->crtc;
  291.  
  292.         DRM_DEBUG_KMS("CONNECTOR %x ID:%d status:%d ENCODER %x CRTC %x ID:%d\n",
  293.                connector, connector->base.id,
  294.                connector->status, connector->encoder,
  295.                crtc, crtc->base.id );
  296.  
  297.         break;
  298.     };
  299.  
  300.     if(connector == NULL)
  301.     {
  302.         DRM_ERROR("No active connectors!\n");
  303.         return -1;
  304.     };
  305.  
  306.     if(crtc == NULL)
  307.     {
  308.         struct drm_crtc *tmp_crtc;
  309.         int crtc_mask = 1;
  310.  
  311.         list_for_each_entry(tmp_crtc, &dev->mode_config.crtc_list, head)
  312.         {
  313.             if (encoder->possible_crtcs & crtc_mask)
  314.             {
  315.                 crtc = tmp_crtc;
  316.                 encoder->crtc = crtc;
  317.                 break;
  318.             };
  319.             crtc_mask <<= 1;
  320.         };
  321.     };
  322.  
  323.     if(crtc == NULL)
  324.     {
  325.         DRM_ERROR("No CRTC for encoder %d\n", encoder->base.id);
  326.         return -1;
  327.     };
  328.  
  329.  
  330.     DRM_DEBUG_KMS("[Select CRTC:%d]\n", crtc->base.id);
  331.  
  332.     os_display = GetDisplay();
  333.     os_display->ddev = dev;
  334.     os_display->connector = connector;
  335.     os_display->crtc = crtc;
  336.  
  337.     os_display->supported_modes = count_connector_modes(connector);
  338.  
  339.  
  340.     ifl = safe_cli();
  341.     {
  342.         struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc);
  343.  
  344.         list_for_each_entry(cursor, &os_display->cursors, list)
  345.         {
  346.             init_cursor(cursor);
  347.         };
  348.  
  349.         os_display->restore_cursor(0,0);
  350.         os_display->init_cursor    = init_cursor;
  351.         os_display->select_cursor  = select_cursor_kms;
  352.         os_display->show_cursor    = NULL;
  353.         os_display->move_cursor    = move_cursor_kms;
  354.         os_display->restore_cursor = restore_cursor;
  355.         os_display->disable_mouse  = disable_mouse;
  356.  
  357.         intel_crtc->cursor_x = os_display->width/2;
  358.         intel_crtc->cursor_y = os_display->height/2;
  359.  
  360.         select_cursor_kms(os_display->cursor);
  361.     };
  362.     safe_sti(ifl);
  363.  
  364. #ifdef __HWA__
  365.     err = init_bitmaps();
  366. #endif
  367.  
  368.     return 0;
  369. };
  370.  
  371.  
  372. int get_videomodes(videomode_t *mode, int *count)
  373. {
  374.     int err = -1;
  375.  
  376. //    dbgprintf("mode %x count %d\n", mode, *count);
  377.  
  378.     if( *count == 0 )
  379.     {
  380.         *count = os_display->supported_modes;
  381.         err = 0;
  382.     }
  383.     else if( mode != NULL )
  384.     {
  385.         struct drm_display_mode  *drmmode;
  386.         int i = 0;
  387.  
  388.         if( *count > os_display->supported_modes)
  389.             *count = os_display->supported_modes;
  390.  
  391.         list_for_each_entry(drmmode, &os_display->connector->modes, head)
  392.         {
  393.             if( i < *count)
  394.             {
  395.                 mode->width  = drm_mode_width(drmmode);
  396.                 mode->height = drm_mode_height(drmmode);
  397.                 mode->bpp    = 32;
  398.                 mode->freq   = drm_mode_vrefresh(drmmode);
  399.                 i++;
  400.                 mode++;
  401.             }
  402.             else break;
  403.         };
  404.         *count = i;
  405.         err = 0;
  406.     };
  407.     return err;
  408. };
  409.  
  410. int set_user_mode(videomode_t *mode)
  411. {
  412.     int err = -1;
  413.  
  414. //    dbgprintf("width %d height %d vrefresh %d\n",
  415. //               mode->width, mode->height, mode->freq);
  416.  
  417.     if( (mode->width  != 0)  &&
  418.         (mode->height != 0)  &&
  419.         (mode->freq   != 0 ) &&
  420.         ( (mode->width   != os_display->width)  ||
  421.           (mode->height  != os_display->height) ||
  422.           (mode->freq    != os_display->vrefresh) ) )
  423.     {
  424.         if( set_mode(os_display->ddev, os_display->connector, mode, true) )
  425.             err = 0;
  426.     };
  427.  
  428.     return err;
  429. };
  430.  
  431. void __attribute__((regparm(1))) destroy_cursor(cursor_t *cursor)
  432. {
  433.     list_del(&cursor->list);
  434.  
  435.     i915_gem_object_unpin(cursor->cobj);
  436.  
  437.     mutex_lock(&main_device->struct_mutex);
  438.     drm_gem_object_unreference(&cursor->cobj->base);
  439.     mutex_unlock(&main_device->struct_mutex);
  440.  
  441.     __DestroyObject(cursor);
  442. };
  443.  
  444. int init_cursor(cursor_t *cursor)
  445. {
  446.     struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
  447.     struct drm_i915_gem_object *obj;
  448.     uint32_t *bits;
  449.     uint32_t *src;
  450.     void     *mapped;
  451.  
  452.     int       i,j;
  453.     int       ret;
  454.  
  455.     if (dev_priv->info->cursor_needs_physical)
  456.     {
  457.         bits = (uint32_t*)KernelAlloc(CURSOR_WIDTH*CURSOR_HEIGHT*4);
  458.         if (unlikely(bits == NULL))
  459.             return ENOMEM;
  460.         cursor->cobj = (struct drm_i915_gem_object *)GetPgAddr(bits);
  461.     }
  462.     else
  463.     {
  464.         obj = i915_gem_alloc_object(os_display->ddev, CURSOR_WIDTH*CURSOR_HEIGHT*4);
  465.         if (unlikely(obj == NULL))
  466.             return -ENOMEM;
  467.  
  468.         ret = i915_gem_obj_ggtt_pin(obj, CURSOR_WIDTH*CURSOR_HEIGHT*4, true, true);
  469.         if (ret) {
  470.             drm_gem_object_unreference(&obj->base);
  471.             return ret;
  472.         }
  473.  
  474.         ret = i915_gem_object_set_to_gtt_domain(obj, true);
  475.         if (ret)
  476.         {
  477.             i915_gem_object_unpin(obj);
  478.             drm_gem_object_unreference(&obj->base);
  479.             return ret;
  480.         }
  481. /* You don't need to worry about fragmentation issues.
  482.  * GTT space is continuous. I guarantee it.                           */
  483.  
  484.         mapped = bits = (u32*)MapIoMem(dev_priv->gtt.mappable_base + i915_gem_obj_ggtt_offset(obj),
  485.                     CURSOR_WIDTH*CURSOR_HEIGHT*4, PG_SW);
  486.  
  487.         if (unlikely(bits == NULL))
  488.         {
  489.             i915_gem_object_unpin(obj);
  490.             drm_gem_object_unreference(&obj->base);
  491.             return -ENOMEM;
  492.         };
  493.         cursor->cobj = obj;
  494.     };
  495.  
  496.     src = cursor->data;
  497.  
  498.     for(i = 0; i < 32; i++)
  499.     {
  500.         for(j = 0; j < 32; j++)
  501.             *bits++ = *src++;
  502.         for(j = 32; j < CURSOR_WIDTH; j++)
  503.             *bits++ = 0;
  504.     }
  505.     for(i = 0; i < CURSOR_WIDTH*(CURSOR_HEIGHT-32); i++)
  506.         *bits++ = 0;
  507.  
  508.     FreeKernelSpace(mapped);
  509.  
  510. // release old cursor
  511.  
  512.     KernelFree(cursor->data);
  513.  
  514.     cursor->data = bits;
  515.  
  516.     cursor->header.destroy = destroy_cursor;
  517.  
  518.     return 0;
  519. }
  520.  
  521.  
  522. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  523. {
  524.     struct drm_device *dev = crtc->dev;
  525.     struct drm_i915_private *dev_priv = dev->dev_private;
  526.     struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  527.     int pipe = intel_crtc->pipe;
  528.     bool visible = base != 0;
  529.  
  530.     if (intel_crtc->cursor_visible != visible) {
  531.         uint32_t cntl = I915_READ(CURCNTR(pipe));
  532.         if (base) {
  533.             cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  534.             cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  535.             cntl |= pipe << 28; /* Connect to correct pipe */
  536.         } else {
  537.             cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  538.             cntl |= CURSOR_MODE_DISABLE;
  539.         }
  540.         I915_WRITE(CURCNTR(pipe), cntl);
  541.  
  542.         intel_crtc->cursor_visible = visible;
  543.     }
  544.     /* and commit changes on next vblank */
  545.     I915_WRITE(CURBASE(pipe), base);
  546. }
  547.  
  548. void __stdcall move_cursor_kms(cursor_t *cursor, int x, int y)
  549. {
  550.     struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
  551.     struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc);
  552.     u32 base, pos;
  553.     bool visible;
  554.  
  555.     int pipe = intel_crtc->pipe;
  556.  
  557.     intel_crtc->cursor_x = x;
  558.     intel_crtc->cursor_y = y;
  559.  
  560.     x = x - cursor->hot_x;
  561.     y = y - cursor->hot_y;
  562.  
  563.  
  564.     pos = 0;
  565.  
  566.     base = intel_crtc->cursor_addr;
  567.     if (x >= os_display->width)
  568.         base = 0;
  569.  
  570.     if (y >= os_display->height)
  571.         base = 0;
  572.  
  573.     if (x < 0)
  574.     {
  575.         if (x + intel_crtc->cursor_width < 0)
  576.             base = 0;
  577.  
  578.         pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  579.         x = -x;
  580.     }
  581.     pos |= x << CURSOR_X_SHIFT;
  582.  
  583.     if (y < 0)
  584.     {
  585.         if (y + intel_crtc->cursor_height < 0)
  586.             base = 0;
  587.  
  588.         pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  589.         y = -y;
  590.     }
  591.     pos |= y << CURSOR_Y_SHIFT;
  592.  
  593.     visible = base != 0;
  594.     if (!visible && !intel_crtc->cursor_visible)
  595.         return;
  596.  
  597.     I915_WRITE(CURPOS(pipe), pos);
  598. //    if (IS_845G(dev) || IS_I865G(dev))
  599. //        i845_update_cursor(crtc, base);
  600. //    else
  601.         i9xx_update_cursor(os_display->crtc, base);
  602.  
  603. };
  604.  
  605.  
  606. cursor_t* __stdcall select_cursor_kms(cursor_t *cursor)
  607. {
  608.     struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
  609.     struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc);
  610.     cursor_t *old;
  611.  
  612.     old = os_display->cursor;
  613.     os_display->cursor = cursor;
  614.  
  615.     if (!dev_priv->info->cursor_needs_physical)
  616.        intel_crtc->cursor_addr = i915_gem_obj_ggtt_offset(cursor->cobj);
  617.     else
  618.         intel_crtc->cursor_addr = (addr_t)cursor->cobj;
  619.  
  620.     intel_crtc->cursor_width = 32;
  621.     intel_crtc->cursor_height = 32;
  622.  
  623.     move_cursor_kms(cursor, intel_crtc->cursor_x, intel_crtc->cursor_y);
  624.     return old;
  625. };
  626.  
  627. struct sna_fb
  628. {
  629.     uint32_t  width;
  630.     uint32_t  height;
  631.     uint32_t  pitch;
  632.     uint32_t  tiling;
  633. };
  634.  
  635. int i915_fbinfo(struct sna_fb *fb)
  636. {
  637.     fb->width  = os_display->width;
  638.     fb->height = os_display->height;
  639.     fb->pitch  = os_display->pitch;
  640.     fb->tiling = 0;
  641.  
  642.     return 0;
  643. };
  644.  
  645. typedef struct
  646. {
  647.     int left;
  648.     int top;
  649.     int right;
  650.     int bottom;
  651. }rect_t;
  652.  
  653. struct drm_i915_mask {
  654.     __u32 handle;
  655.     __u32 width;
  656.     __u32 height;
  657.     __u32 bo_size;
  658.     __u32 bo_pitch;
  659.     __u32 bo_map;
  660. };
  661.  
  662. #define CURRENT_TASK             (0x80003000)
  663.  
  664. static u32_t get_display_map()
  665. {
  666.     u32_t   addr;
  667.  
  668.     addr = (u32_t)os_display;
  669.     addr+= sizeof(display_t);            /*  shoot me  */
  670.     return *(u32_t*)addr;
  671. }
  672.  
  673. void  FASTCALL GetWindowRect(rect_t *rc)__asm__("GetWindowRect");
  674.  
  675. int i915_mask_update(struct drm_device *dev, void *data,
  676.             struct drm_file *file)
  677. {
  678.     struct drm_i915_mask *mask = data;
  679.     struct drm_gem_object *obj;
  680.     static unsigned int mask_seqno[256];
  681.     rect_t winrc;
  682.     u32    slot;
  683.     int    ret;
  684.  
  685.      if(mask->handle == -2)
  686.      {
  687.         printf("%s handle %d\n", __FUNCTION__, mask->handle);
  688.         return 0;
  689.      }
  690.  
  691.     obj = drm_gem_object_lookup(dev, file, mask->handle);
  692.     if (obj == NULL)
  693.         return -ENOENT;
  694.  
  695.     if (!obj->filp) {
  696.         drm_gem_object_unreference_unlocked(obj);
  697.         return -EINVAL;
  698.     }
  699.  
  700.     GetWindowRect(&winrc);
  701.     {
  702. //        static warn_count;
  703.  
  704.         mask->width    = winrc.right - winrc.left + 1;
  705.         mask->height   = winrc.bottom - winrc.top + 1;
  706.         mask->bo_pitch = (mask->width+15) & ~15;
  707.  
  708. #if 0
  709.         if(warn_count < 1)
  710.         {
  711.             printf("left %d top %d right %d bottom %d\n",
  712.                     winrc.left, winrc.top, winrc.right, winrc.bottom);
  713.             printf("mask pitch %d data %p\n", mask->bo_pitch, mask->bo_size);
  714.             warn_count++;
  715.         };
  716. #endif
  717.  
  718.      };
  719.  
  720.  
  721.     slot = *((u8*)CURRENT_TASK);
  722.  
  723.     if( mask_seqno[slot] != os_display->mask_seqno)
  724.     {
  725.         u8* src_offset;
  726.         u8* dst_offset;
  727.         u32 ifl;
  728.  
  729.         ret = i915_mutex_lock_interruptible(dev);
  730.         if (ret)
  731.             return ret;
  732.  
  733.         ret = i915_gem_object_set_to_cpu_domain(to_intel_bo(obj), true);
  734.         if(ret !=0 )
  735.         {
  736.             dbgprintf("%s fail\n", __FUNCTION__);
  737.             return ret;
  738.         };
  739.  
  740. //        printf("width %d height %d\n", winrc.right, winrc.bottom);
  741.  
  742. //        slot = 0x01;
  743.  
  744.  
  745.         src_offset = (u8*)( winrc.top*os_display->width + winrc.left);
  746.         src_offset+= get_display_map();
  747.         dst_offset = (u8*)mask->bo_map;
  748.  
  749.         u32_t tmp_h = mask->height;
  750.  
  751.         ifl = safe_cli();
  752.         {
  753.             mask_seqno[slot] = os_display->mask_seqno;
  754.  
  755.             slot|= (slot<<8)|(slot<<16)|(slot<<24);
  756.  
  757.             __asm__ __volatile__ (
  758.                 "movd       %[slot],   %%xmm6    \n"
  759.             "punpckldq  %%xmm6, %%xmm6            \n"
  760.             "punpcklqdq %%xmm6, %%xmm6            \n"
  761.             :: [slot]  "m" (slot)
  762.             :"xmm6");
  763.  
  764.             while( tmp_h--)
  765.             {
  766.                 int tmp_w = mask->bo_pitch;
  767.  
  768.                 u8* tmp_src = src_offset;
  769.                 u8* tmp_dst = dst_offset;
  770.  
  771.                 src_offset+= os_display->width;
  772.                 dst_offset+= mask->bo_pitch;
  773.  
  774.                 while(tmp_w >= 64)
  775.                 {
  776.                     __asm__ __volatile__ (
  777.                     "movdqu     (%0),   %%xmm0            \n"
  778.                     "movdqu   16(%0),   %%xmm1            \n"
  779.                     "movdqu   32(%0),   %%xmm2            \n"
  780.                     "movdqu   48(%0),   %%xmm3            \n"
  781.                     "pcmpeqb    %%xmm6, %%xmm0            \n"
  782.                     "pcmpeqb    %%xmm6, %%xmm1            \n"
  783.                     "pcmpeqb    %%xmm6, %%xmm2            \n"
  784.                     "pcmpeqb    %%xmm6, %%xmm3            \n"
  785.                     "movdqa     %%xmm0,   (%%edi)         \n"
  786.                     "movdqa     %%xmm1, 16(%%edi)         \n"
  787.                     "movdqa     %%xmm2, 32(%%edi)         \n"
  788.                     "movdqa     %%xmm3, 48(%%edi)         \n"
  789.  
  790.                     :: "r" (tmp_src), "D" (tmp_dst)
  791.                     :"xmm0","xmm1","xmm2","xmm3");
  792.                     tmp_w -= 64;
  793.                     tmp_src += 64;
  794.                     tmp_dst += 64;
  795.                 }
  796.  
  797.                 if( tmp_w >= 32 )
  798.                 {
  799.                     __asm__ __volatile__ (
  800.                     "movdqu     (%0),   %%xmm0            \n"
  801.                     "movdqu   16(%0),   %%xmm1            \n"
  802.                     "pcmpeqb    %%xmm6, %%xmm0            \n"
  803.                     "pcmpeqb    %%xmm6, %%xmm1            \n"
  804.                     "movdqa     %%xmm0,   (%%edi)         \n"
  805.                     "movdqa     %%xmm1, 16(%%edi)         \n"
  806.  
  807.                     :: "r" (tmp_src), "D" (tmp_dst)
  808.                     :"xmm0","xmm1");
  809.                     tmp_w -= 32;
  810.                     tmp_src += 32;
  811.                     tmp_dst += 32;
  812.                 }
  813.  
  814.                 while( tmp_w > 0 )
  815.                 {
  816.                     __asm__ __volatile__ (
  817.                     "movdqu     (%0),   %%xmm0            \n"
  818.                     "pcmpeqb    %%xmm6, %%xmm0            \n"
  819.                     "movdqa     %%xmm0,   (%%edi)         \n"
  820.                     :: "r" (tmp_src), "D" (tmp_dst)
  821.                     :"xmm0");
  822.                     tmp_w -= 16;
  823.                     tmp_src += 16;
  824.                     tmp_dst += 16;
  825.                 }
  826.             };
  827.         };
  828.         safe_sti(ifl);
  829.     }
  830.  
  831.     drm_gem_object_unreference(obj);
  832.  
  833.     mutex_unlock(&dev->struct_mutex);
  834.  
  835.     return 0;
  836. }
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849. #define NSEC_PER_SEC    1000000000L
  850.  
  851. void getrawmonotonic(struct timespec *ts)
  852. {
  853.     u32 tmp = GetTimerTicks();
  854.  
  855.     ts->tv_sec  = tmp/100;
  856.     ts->tv_nsec = (tmp - ts->tv_sec*100)*10000000;
  857. }
  858.  
  859. void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec)
  860. {
  861.     while (nsec >= NSEC_PER_SEC) {
  862.         /*
  863.          * The following asm() prevents the compiler from
  864.          * optimising this loop into a modulo operation. See
  865.          * also __iter_div_u64_rem() in include/linux/time.h
  866.          */
  867.         asm("" : "+rm"(nsec));
  868.         nsec -= NSEC_PER_SEC;
  869.         ++sec;
  870.     }
  871.     while (nsec < 0) {
  872.         asm("" : "+rm"(nsec));
  873.         nsec += NSEC_PER_SEC;
  874.         --sec;
  875.     }
  876.     ts->tv_sec = sec;
  877.     ts->tv_nsec = nsec;
  878. }
  879.  
  880. void
  881. prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state)
  882. {
  883.     unsigned long flags;
  884.  
  885. //    wait->flags &= ~WQ_FLAG_EXCLUSIVE;
  886.     spin_lock_irqsave(&q->lock, flags);
  887.     if (list_empty(&wait->task_list))
  888.             __add_wait_queue(q, wait);
  889.     spin_unlock_irqrestore(&q->lock, flags);
  890. }
  891.  
  892. /**
  893.  * finish_wait - clean up after waiting in a queue
  894.  * @q: waitqueue waited on
  895.  * @wait: wait descriptor
  896.  *
  897.  * Sets current thread back to running state and removes
  898.  * the wait descriptor from the given waitqueue if still
  899.  * queued.
  900.  */
  901. void finish_wait(wait_queue_head_t *q, wait_queue_t *wait)
  902. {
  903.     unsigned long flags;
  904.  
  905. //    __set_current_state(TASK_RUNNING);
  906.     /*
  907.      * We can check for list emptiness outside the lock
  908.      * IFF:
  909.      *  - we use the "careful" check that verifies both
  910.      *    the next and prev pointers, so that there cannot
  911.      *    be any half-pending updates in progress on other
  912.      *    CPU's that we haven't seen yet (and that might
  913.      *    still change the stack area.
  914.      * and
  915.      *  - all other users take the lock (ie we can only
  916.      *    have _one_ other CPU that looks at or modifies
  917.      *    the list).
  918.      */
  919.     if (!list_empty_careful(&wait->task_list)) {
  920.             spin_lock_irqsave(&q->lock, flags);
  921.             list_del_init(&wait->task_list);
  922.             spin_unlock_irqrestore(&q->lock, flags);
  923.     }
  924.  
  925.     DestroyEvent(wait->evnt);
  926. }
  927.  
  928. int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key)
  929. {
  930.     list_del_init(&wait->task_list);
  931.     return 1;
  932. }
  933.  
  934. unsigned int hweight16(unsigned int w)
  935. {
  936.     unsigned int res = w - ((w >> 1) & 0x5555);
  937.     res = (res & 0x3333) + ((res >> 2) & 0x3333);
  938.     res = (res + (res >> 4)) & 0x0F0F;
  939.     return (res + (res >> 8)) & 0x00FF;
  940. }
  941.  
  942.  
  943. unsigned long round_jiffies_up_relative(unsigned long j)
  944. {
  945.     unsigned long j0 = GetTimerTicks();
  946.  
  947.         /* Use j0 because jiffies might change while we run */
  948.     return round_jiffies_common(j + j0, true) - j0;
  949. }
  950.  
  951.  
  952.