neuwld

patched neuwld library (tracked)
git clone https://git.daat.foo/neuwld.git
Log | Files | Refs | README | LICENSE

batch.c (5692B)


      1 /* wld: intel/batch.c
      2  *
      3  * Copyright (c) 2013, 2014 Michael Forney
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining a copy
      6  * of this software and associated documentation files (the "Software"), to deal
      7  * in the Software without restriction, including without limitation the rights
      8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      9  * copies of the Software, and to permit persons to whom the Software is
     10  * furnished to do so, subject to the following conditions:
     11  *
     12  * The above copyright notice and this permission notice shall be included in
     13  * all copies or substantial portions of the Software.
     14  *
     15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     21  * SOFTWARE.
     22  */
     23 
     24 #include "batch.h"
     25 #include "mi.h"
     26 
     27 #include <i915_drm.h>
     28 #include <stdlib.h>
     29 
     30 static const struct intel_device_info device_info_i965 = { .gen = 4 };
     31 static const struct intel_device_info device_info_g4x = { .gen = 4 };
     32 static const struct intel_device_info device_info_ilk = { .gen = 5 };
     33 static const struct intel_device_info device_info_snb_gt1 = { .gen = 6 };
     34 static const struct intel_device_info device_info_snb_gt2 = { .gen = 6 };
     35 static const struct intel_device_info device_info_ivb_gt1 = { .gen = 7 };
     36 static const struct intel_device_info device_info_ivb_gt2 = { .gen = 7 };
     37 static const struct intel_device_info device_info_byt = { .gen = 7 };
     38 static const struct intel_device_info device_info_hsw_gt1 = { .gen = 7 };
     39 static const struct intel_device_info device_info_hsw_gt2 = { .gen = 7 };
     40 static const struct intel_device_info device_info_hsw_gt3 = { .gen = 7 };
     41 static const struct intel_device_info device_info_bdw_gt1 = { .gen = 8 };
     42 static const struct intel_device_info device_info_bdw_gt2 = { .gen = 8 };
     43 static const struct intel_device_info device_info_bdw_gt3 = { .gen = 8 };
     44 static const struct intel_device_info device_info_bdw_rsvd = { .gen = 8 };
     45 static const struct intel_device_info device_info_chv = { .gen = 8 };
     46 static const struct intel_device_info device_info_skl_gt1 = { .gen = 9 };
     47 static const struct intel_device_info device_info_skl_gt2 = { .gen = 9 };
     48 static const struct intel_device_info device_info_skl_gt3 = { .gen = 9 };
     49 static const struct intel_device_info device_info_skl_gt4 = { .gen = 9 };
     50 static const struct intel_device_info device_info_bxt = { .gen = 9 };
     51 static const struct intel_device_info device_info_bxt_2x6 = { .gen = 9 };
     52 static const struct intel_device_info device_info_kbl_gt1 = { .gen = 9 };
     53 static const struct intel_device_info device_info_kbl_gt1_5 = { .gen = 9 };
     54 static const struct intel_device_info device_info_kbl_gt2 = { .gen = 9 };
     55 static const struct intel_device_info device_info_kbl_gt3 = { .gen = 9 };
     56 static const struct intel_device_info device_info_kbl_gt4 = { .gen = 9 };
     57 static const struct intel_device_info device_info_glk = { .gen = 9 };
     58 static const struct intel_device_info device_info_glk_2x6 = { .gen = 9 };
     59 static const struct intel_device_info device_info_cfl_gt1 = { .gen = 9 };
     60 static const struct intel_device_info device_info_cfl_gt2 = { .gen = 9 };
     61 static const struct intel_device_info device_info_cfl_gt3 = { .gen = 9 };
     62 static const struct intel_device_info device_info_cnl_2x8 = { .gen = 10 };
     63 static const struct intel_device_info device_info_cnl_3x8 = { .gen = 10 };
     64 static const struct intel_device_info device_info_cnl_4x8 = { .gen = 10 };
     65 static const struct intel_device_info device_info_cnl_5x8 = { .gen = 10 };
     66 static const struct intel_device_info device_info_cnl = { .gen = 10 };
     67 static const struct intel_device_info device_info_icl = { .gen = 11 };
     68 static const struct intel_device_info device_info_ehl = { .gen = 11 };
     69 static const struct intel_device_info device_info_jpl = { .gen = 11 };
     70 static const struct intel_device_info device_info_gen12 = { .gen = 12 };
     71 
     72 static const struct intel_device_info *
     73 device_info(int device_id)
     74 {
     75 	switch (device_id) {
     76 #define CHIPSET(device_id, type, name) \
     77 	case device_id:                \
     78 		return &device_info_##type;
     79 #include "i965_pci_ids.h"
     80 #undef CHIPSET
     81 	default:
     82 		return NULL;
     83 	}
     84 }
     85 
     86 bool
     87 intel_batch_initialize(struct intel_batch *batch,
     88                        drm_intel_bufmgr *bufmgr)
     89 {
     90 	int device_id = drm_intel_bufmgr_gem_get_devid(bufmgr);
     91 
     92 	batch->command_count = 0;
     93 	batch->device_info = device_info(device_id);
     94 
     95 	if (!batch->device_info)
     96 		return false;
     97 
     98 	/* Alignment argument (4096) is not used */
     99 	batch->bo = drm_intel_bo_alloc(bufmgr, "batchbuffer", sizeof batch->commands, 4096);
    100 
    101 	if (!batch->bo)
    102 		return false;
    103 
    104 	return true;
    105 }
    106 
    107 void
    108 intel_batch_finalize(struct intel_batch *batch)
    109 {
    110 	drm_intel_bo_unreference(batch->bo);
    111 }
    112 
    113 void
    114 intel_batch_flush(struct intel_batch *batch)
    115 {
    116 	if (batch->command_count == 0)
    117 		return;
    118 
    119 	intel_batch_add_dword(batch, MI_BATCH_BUFFER_END);
    120 
    121 	/* Pad the batch buffer to the next quad-word. */
    122 	if (batch->command_count & 1)
    123 		intel_batch_add_dword(batch, MI_NOOP);
    124 
    125 	drm_intel_bo_subdata(batch->bo, 0, batch->command_count << 2,
    126 	                     batch->commands);
    127 	drm_intel_bo_mrb_exec(batch->bo, batch->command_count << 2, NULL, 0, 0,
    128 	                      GEN(batch, 6) ? I915_EXEC_BLT
    129 	                                    : I915_EXEC_DEFAULT);
    130 	drm_intel_gem_bo_clear_relocs(batch->bo, 0);
    131 	batch->command_count = 0;
    132 }