Home | History | Annotate | Download | only in drm
      1 #include <stdio.h>
      2 #include <sys/ioctl.h>
      3 
      4 #include "i915_drm.h"
      5 
      6 #include "state_tracker/drm_driver.h"
      7 
      8 #include "i915_drm_winsys.h"
      9 #include "i915_drm_public.h"
     10 #include "util/u_memory.h"
     11 
     12 
     13 /*
     14  * Helper functions
     15  */
     16 
     17 
     18 static void
     19 i915_drm_get_device_id(int fd, unsigned int *device_id)
     20 {
     21    int ret;
     22    struct drm_i915_getparam gp;
     23 
     24    gp.param = I915_PARAM_CHIPSET_ID;
     25    gp.value = (int *)device_id;
     26 
     27    ret = ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
     28    assert(ret == 0);
     29 }
     30 
     31 static void
     32 i915_drm_winsys_destroy(struct i915_winsys *iws)
     33 {
     34    struct i915_drm_winsys *idws = i915_drm_winsys(iws);
     35 
     36    drm_intel_bufmgr_destroy(idws->gem_manager);
     37 
     38    FREE(idws);
     39 }
     40 
     41 struct i915_winsys *
     42 i915_drm_winsys_create(int drmFD)
     43 {
     44    struct i915_drm_winsys *idws;
     45    unsigned int deviceID;
     46 
     47    idws = CALLOC_STRUCT(i915_drm_winsys);
     48    if (!idws)
     49       return NULL;
     50 
     51    i915_drm_get_device_id(drmFD, &deviceID);
     52 
     53    i915_drm_winsys_init_batchbuffer_functions(idws);
     54    i915_drm_winsys_init_buffer_functions(idws);
     55    i915_drm_winsys_init_fence_functions(idws);
     56 
     57    idws->fd = drmFD;
     58    idws->base.pci_id = deviceID;
     59    idws->max_batch_size = 16 * 4096;
     60 
     61    idws->base.destroy = i915_drm_winsys_destroy;
     62 
     63    idws->gem_manager = drm_intel_bufmgr_gem_init(idws->fd, idws->max_batch_size);
     64    drm_intel_bufmgr_gem_enable_reuse(idws->gem_manager);
     65    drm_intel_bufmgr_gem_enable_fenced_relocs(idws->gem_manager);
     66 
     67    idws->dump_cmd = debug_get_bool_option("I915_DUMP_CMD", FALSE);
     68    idws->dump_raw_file = debug_get_option("I915_DUMP_RAW_FILE", NULL);
     69    idws->send_cmd = !debug_get_bool_option("I915_NO_HW", FALSE);
     70 
     71    return &idws->base;
     72 }
     73