• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
i915_drm_get_device_id(int fd,unsigned int * device_id)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 int
i915_drm_aperture_size(struct i915_winsys * iws)32 i915_drm_aperture_size(struct i915_winsys *iws)
33 {
34    struct i915_drm_winsys *idws = i915_drm_winsys(iws);
35    size_t aper_size, mappable_size;
36 
37    drm_intel_get_aperture_sizes(idws->fd, &mappable_size, &aper_size);
38 
39    return aper_size >> 20;
40 }
41 
42 static void
i915_drm_winsys_destroy(struct i915_winsys * iws)43 i915_drm_winsys_destroy(struct i915_winsys *iws)
44 {
45    struct i915_drm_winsys *idws = i915_drm_winsys(iws);
46 
47    drm_intel_bufmgr_destroy(idws->gem_manager);
48 
49    FREE(idws);
50 }
51 
52 struct i915_winsys *
i915_drm_winsys_create(int drmFD)53 i915_drm_winsys_create(int drmFD)
54 {
55    struct i915_drm_winsys *idws;
56    unsigned int deviceID;
57 
58    idws = CALLOC_STRUCT(i915_drm_winsys);
59    if (!idws)
60       return NULL;
61 
62    i915_drm_get_device_id(drmFD, &deviceID);
63 
64    i915_drm_winsys_init_batchbuffer_functions(idws);
65    i915_drm_winsys_init_buffer_functions(idws);
66    i915_drm_winsys_init_fence_functions(idws);
67 
68    idws->fd = drmFD;
69    idws->base.pci_id = deviceID;
70    idws->max_batch_size = 1 * 4096;
71 
72    idws->base.aperture_size = i915_drm_aperture_size;
73    idws->base.destroy = i915_drm_winsys_destroy;
74 
75    idws->gem_manager = drm_intel_bufmgr_gem_init(idws->fd, idws->max_batch_size);
76    drm_intel_bufmgr_gem_enable_reuse(idws->gem_manager);
77    drm_intel_bufmgr_gem_enable_fenced_relocs(idws->gem_manager);
78 
79    idws->dump_cmd = debug_get_bool_option("I915_DUMP_CMD", FALSE);
80    idws->dump_raw_file = debug_get_option("I915_DUMP_RAW_FILE", NULL);
81    idws->send_cmd = !debug_get_bool_option("I915_NO_HW", FALSE);
82 
83    return &idws->base;
84 }
85