+static bool
+get_bo_from_pool(struct gen_batch_decode_bo *ret,
+ struct anv_block_pool *pool,
+ uint64_t address)
+{
+ for (uint32_t i = 0; i < pool->nbos; i++) {
+ uint64_t bo_address = pool->bos[i].offset & (~0ull >> 16);
+ uint32_t bo_size = pool->bos[i].size;
+ if (address >= bo_address && address < (bo_address + bo_size)) {
+ *ret = (struct gen_batch_decode_bo) {
+ .addr = bo_address,
+ .size = bo_size,
+ .map = pool->bos[i].map,
+ };
+ return true;
+ }
+ }
+ return false;
+}
+
+/* Finding a buffer for batch decoding */
+static struct gen_batch_decode_bo
+decode_get_bo(void *v_batch, bool ppgtt, uint64_t address)
+{
+ struct anv_device *device = v_batch;
+ struct gen_batch_decode_bo ret_bo = {};
+
+ assert(ppgtt);
+
+ if (get_bo_from_pool(&ret_bo, &device->dynamic_state_pool.block_pool, address))
+ return ret_bo;
+ if (get_bo_from_pool(&ret_bo, &device->instruction_state_pool.block_pool, address))
+ return ret_bo;
+ if (get_bo_from_pool(&ret_bo, &device->binding_table_pool.block_pool, address))
+ return ret_bo;
+ if (get_bo_from_pool(&ret_bo, &device->surface_state_pool.block_pool, address))
+ return ret_bo;
+
+ if (!device->cmd_buffer_being_decoded)
+ return (struct gen_batch_decode_bo) { };
+
+ struct anv_batch_bo **bo;
+
+ u_vector_foreach(bo, &device->cmd_buffer_being_decoded->seen_bbos) {
+ /* The decoder zeroes out the top 16 bits, so we need to as well */
+ uint64_t bo_address = (*bo)->bo.offset & (~0ull >> 16);
+
+ if (address >= bo_address && address < bo_address + (*bo)->bo.size) {
+ return (struct gen_batch_decode_bo) {
+ .addr = bo_address,
+ .size = (*bo)->bo.size,
+ .map = (*bo)->bo.map,
+ };
+ }
+ }
+
+ return (struct gen_batch_decode_bo) { };
+}
+