2 * Mesa 3-D graphics library
4 * Copyright (C) 2014 LunarG, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Chia-I Wu <olv@lunarg.com>
28 #ifndef ILO_BUILDER_MI_H
29 #define ILO_BUILDER_MI_H
31 #include "genhw/genhw.h"
32 #include "intel_winsys.h"
34 #include "ilo_common.h"
35 #include "ilo_builder.h"
38 gen6_MI_STORE_DATA_IMM(struct ilo_builder
*builder
,
39 struct intel_bo
*bo
, uint32_t bo_offset
,
42 const uint8_t cmd_len
= (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) ? 6 : 5;
43 uint32_t reloc_flags
= INTEL_RELOC_WRITE
;
47 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
49 assert(bo_offset
% 8 == 0);
51 pos
= ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
53 dw
[0] = GEN6_MI_CMD(MI_STORE_DATA_IMM
) | (cmd_len
- 2);
54 /* must use GGTT on GEN6 as in PIPE_CONTROL */
55 if (ilo_dev_gen(builder
->dev
) == ILO_GEN(6)) {
56 dw
[0] |= GEN6_MI_STORE_DATA_IMM_DW0_USE_GGTT
;
57 reloc_flags
|= INTEL_RELOC_GGTT
;
62 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) {
63 dw
[4] = (uint32_t) val
;
64 dw
[5] = (uint32_t) (val
>> 32);
66 ilo_builder_batch_reloc64(builder
, pos
+ 2, bo
, bo_offset
, reloc_flags
);
68 dw
[3] = (uint32_t) val
;
69 dw
[4] = (uint32_t) (val
>> 32);
71 ilo_builder_batch_reloc(builder
, pos
+ 2, bo
, bo_offset
, reloc_flags
);
76 gen6_MI_LOAD_REGISTER_IMM(struct ilo_builder
*builder
,
77 uint32_t reg
, uint32_t val
)
79 const uint8_t cmd_len
= 3;
82 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
86 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
88 dw
[0] = GEN6_MI_CMD(MI_LOAD_REGISTER_IMM
) | (cmd_len
- 2);
94 gen6_MI_STORE_REGISTER_MEM(struct ilo_builder
*builder
, uint32_t reg
,
95 struct intel_bo
*bo
, uint32_t bo_offset
)
97 const uint8_t cmd_len
= (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) ? 4 : 3;
98 uint32_t reloc_flags
= INTEL_RELOC_WRITE
;
102 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
104 assert(reg
% 4 == 0 && bo_offset
% 4 == 0);
106 pos
= ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
108 dw
[0] = GEN6_MI_CMD(MI_STORE_REGISTER_MEM
) | (cmd_len
- 2);
111 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) {
112 ilo_builder_batch_reloc64(builder
, pos
+ 2, bo
, bo_offset
, reloc_flags
);
114 /* must use GGTT on Gen6 as in PIPE_CONTROL */
115 if (ilo_dev_gen(builder
->dev
) == ILO_GEN(6)) {
116 dw
[0] |= GEN6_MI_STORE_REGISTER_MEM_DW0_USE_GGTT
;
117 reloc_flags
|= INTEL_RELOC_GGTT
;
120 ilo_builder_batch_reloc(builder
, pos
+ 2, bo
, bo_offset
, reloc_flags
);
125 gen6_MI_FLUSH_DW(struct ilo_builder
*builder
)
127 const uint8_t cmd_len
= 4;
130 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
132 ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
134 dw
[0] = GEN6_MI_CMD(MI_FLUSH_DW
) | (cmd_len
- 2);
141 gen6_MI_REPORT_PERF_COUNT(struct ilo_builder
*builder
,
142 struct intel_bo
*bo
, uint32_t bo_offset
,
145 const uint8_t cmd_len
= 3;
146 uint32_t reloc_flags
= INTEL_RELOC_WRITE
;
150 ILO_DEV_ASSERT(builder
->dev
, 6, 7.5);
152 assert(bo_offset
% 64 == 0);
154 /* must use GGTT on GEN6 as in PIPE_CONTROL */
155 if (ilo_dev_gen(builder
->dev
) == ILO_GEN(6)) {
156 bo_offset
|= GEN6_MI_REPORT_PERF_COUNT_DW1_USE_GGTT
;
157 reloc_flags
|= INTEL_RELOC_GGTT
;
160 pos
= ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
162 dw
[0] = GEN6_MI_CMD(MI_REPORT_PERF_COUNT
) | (cmd_len
- 2);
165 ilo_builder_batch_reloc(builder
, pos
+ 1, bo
, bo_offset
, reloc_flags
);
169 gen7_MI_LOAD_REGISTER_MEM(struct ilo_builder
*builder
, uint32_t reg
,
170 struct intel_bo
*bo
, uint32_t bo_offset
)
172 const uint8_t cmd_len
= (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8)) ? 4 : 3;
176 ILO_DEV_ASSERT(builder
->dev
, 7, 8);
178 assert(reg
% 4 == 0 && bo_offset
% 4 == 0);
180 pos
= ilo_builder_batch_pointer(builder
, cmd_len
, &dw
);
182 dw
[0] = GEN7_MI_CMD(MI_LOAD_REGISTER_MEM
) | (cmd_len
- 2);
185 if (ilo_dev_gen(builder
->dev
) >= ILO_GEN(8))
186 ilo_builder_batch_reloc64(builder
, pos
+ 2, bo
, bo_offset
, 0);
188 ilo_builder_batch_reloc(builder
, pos
+ 2, bo
, bo_offset
, 0);
192 * Add a MI_BATCH_BUFFER_END to the batch buffer. Pad with MI_NOOP if
196 gen6_mi_batch_buffer_end(struct ilo_builder
*builder
)
199 * From the Sandy Bridge PRM, volume 1 part 1, page 107:
201 * "The batch buffer must be QWord aligned and a multiple of QWords in
204 const bool pad
= !(builder
->writers
[ILO_BUILDER_WRITER_BATCH
].used
& 0x7);
207 ILO_DEV_ASSERT(builder
->dev
, 6, 8);
210 ilo_builder_batch_pointer(builder
, 2, &dw
);
211 dw
[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_END
);
212 dw
[1] = GEN6_MI_CMD(MI_NOOP
);
214 ilo_builder_batch_pointer(builder
, 1, &dw
);
215 dw
[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_END
);
219 #endif /* ILO_BUILDER_MI_H */