Subversion Repositories Kolibri OS

Rev

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