Lines Matching +full:ctx +full:- +full:asid

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright 2016-2021 HabanaLabs, Ltd.
28 return -EBUSY; in hl_debugfs_i2c_read()
31 dev_err(hdev->dev, "I2C transaction length %u, exceeds maximum of %u\n", in hl_debugfs_i2c_read()
33 return -EINVAL; in hl_debugfs_i2c_read()
45 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_debugfs_i2c_read()
48 dev_err(hdev->dev, "Failed to read from I2C, error %d\n", rc); in hl_debugfs_i2c_read()
60 return -EBUSY; in hl_debugfs_i2c_write()
63 dev_err(hdev->dev, "I2C transaction length %u, exceeds maximum of %u\n", in hl_debugfs_i2c_write()
65 return -EINVAL; in hl_debugfs_i2c_write()
78 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_debugfs_i2c_write()
82 dev_err(hdev->dev, "Failed to write to I2C, error %d\n", rc); in hl_debugfs_i2c_write()
102 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_debugfs_led_set()
106 dev_err(hdev->dev, "Failed to set LED %d, error %d\n", led, rc); in hl_debugfs_led_set()
111 struct hl_debugfs_entry *entry = s->private; in command_buffers_show()
112 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in command_buffers_show()
116 spin_lock(&dev_entry->cb_spinlock); in command_buffers_show()
118 list_for_each_entry(cb, &dev_entry->cb_list, debugfs_list) { in command_buffers_show()
122 seq_puts(s, " CB ID CTX ID CB size CB RefCnt mmap? CS counter\n"); in command_buffers_show()
123 seq_puts(s, "---------------------------------------------------------------\n"); in command_buffers_show()
127 cb->buf->handle, cb->ctx->asid, cb->size, in command_buffers_show()
128 kref_read(&cb->buf->refcount), in command_buffers_show()
129 atomic_read(&cb->buf->mmap), atomic_read(&cb->cs_cnt)); in command_buffers_show()
132 spin_unlock(&dev_entry->cb_spinlock); in command_buffers_show()
142 struct hl_debugfs_entry *entry = s->private; in command_submission_show()
143 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in command_submission_show()
147 spin_lock(&dev_entry->cs_spinlock); in command_submission_show()
149 list_for_each_entry(cs, &dev_entry->cs_list, debugfs_list) { in command_submission_show()
153 seq_puts(s, " CS ID CS TYPE CTX ASID CS RefCnt Submitted Completed\n"); in command_submission_show()
154 seq_puts(s, "----------------------------------------------------------------\n"); in command_submission_show()
158 cs->sequence, cs->type, cs->ctx->asid, in command_submission_show()
159 kref_read(&cs->refcount), in command_submission_show()
160 cs->submitted, cs->completed); in command_submission_show()
163 spin_unlock(&dev_entry->cs_spinlock); in command_submission_show()
173 struct hl_debugfs_entry *entry = s->private; in command_submission_jobs_show()
174 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in command_submission_jobs_show()
178 spin_lock(&dev_entry->cs_job_spinlock); in command_submission_jobs_show()
180 list_for_each_entry(job, &dev_entry->cs_job_list, debugfs_list) { in command_submission_jobs_show()
184 seq_puts(s, " JOB ID CS ID CS TYPE CTX ASID JOB RefCnt H/W Queue\n"); in command_submission_jobs_show()
185 seq_puts(s, "---------------------------------------------------------------\n"); in command_submission_jobs_show()
187 if (job->cs) in command_submission_jobs_show()
190 job->id, job->cs->sequence, job->cs->type, in command_submission_jobs_show()
191 job->cs->ctx->asid, kref_read(&job->refcount), in command_submission_jobs_show()
192 job->hw_queue_id); in command_submission_jobs_show()
196 job->id, HL_KERNEL_ASID_ID, in command_submission_jobs_show()
197 kref_read(&job->refcount), job->hw_queue_id); in command_submission_jobs_show()
200 spin_unlock(&dev_entry->cs_job_spinlock); in command_submission_jobs_show()
210 struct hl_debugfs_entry *entry = s->private; in userptr_show()
211 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in userptr_show()
217 spin_lock(&dev_entry->userptr_spinlock); in userptr_show()
219 list_for_each_entry(userptr, &dev_entry->userptr_list, debugfs_list) { in userptr_show()
224 seq_puts(s, "----------------------------------------------------------\n"); in userptr_show()
226 seq_printf(s, " %-7d 0x%-14llx %-10llu %-30s\n", in userptr_show()
227 userptr->pid, userptr->addr, userptr->size, in userptr_show()
228 dma_dir[userptr->dir]); in userptr_show()
231 spin_unlock(&dev_entry->userptr_spinlock); in userptr_show()
241 struct hl_debugfs_entry *entry = s->private; in vm_show()
242 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in vm_show()
244 struct hl_ctx *ctx; in vm_show() local
256 mutex_lock(&dev_entry->ctx_mem_hash_mutex); in vm_show()
258 list_for_each_entry(ctx, &dev_entry->ctx_mem_hash_list, debugfs_list) { in vm_show()
260 seq_puts(s, "\n\n----------------------------------------------------"); in vm_show()
261 seq_puts(s, "\n----------------------------------------------------\n\n"); in vm_show()
262 seq_printf(s, "ctx asid: %u\n", ctx->asid); in vm_show()
266 seq_puts(s, "----------------------------------------------------\n"); in vm_show()
267 mutex_lock(&ctx->mem_hash_lock); in vm_show()
268 hash_for_each(ctx->mem_hash, i, hnode, node) { in vm_show()
269 vm_type = hnode->ptr; in vm_show()
272 userptr = hnode->ptr; in vm_show()
274 " 0x%-14llx %-10llu\n", in vm_show()
275 hnode->vaddr, userptr->size); in vm_show()
277 phys_pg_pack = hnode->ptr; in vm_show()
279 " 0x%-14llx %-10llu %-4u\n", in vm_show()
280 hnode->vaddr, phys_pg_pack->total_size, in vm_show()
281 phys_pg_pack->handle); in vm_show()
284 mutex_unlock(&ctx->mem_hash_lock); in vm_show()
286 if (ctx->asid != HL_KERNEL_ASID_ID && in vm_show()
287 !list_empty(&ctx->hw_block_mem_list)) { in vm_show()
292 "---------------------------------------------------------------\n"); in vm_show()
293 mutex_lock(&ctx->hw_block_list_lock); in vm_show()
294 list_for_each_entry(lnode, &ctx->hw_block_mem_list, node) { in vm_show()
296 " 0x%-14lx %-6u %-6u %-9u\n", in vm_show()
297 lnode->vaddr, lnode->block_size, lnode->mapped_size, in vm_show()
298 lnode->id); in vm_show()
300 mutex_unlock(&ctx->hw_block_list_lock); in vm_show()
303 vm = &ctx->hdev->vm; in vm_show()
304 spin_lock(&vm->idr_lock); in vm_show()
306 if (!idr_is_empty(&vm->phys_pg_pack_handles)) in vm_show()
309 idr_for_each_entry(&vm->phys_pg_pack_handles, phys_pg_pack, i) { in vm_show()
310 if (phys_pg_pack->asid != ctx->asid) in vm_show()
313 seq_printf(s, "\nhandle: %u\n", phys_pg_pack->handle); in vm_show()
315 phys_pg_pack->page_size); in vm_show()
317 seq_puts(s, "---------------------\n"); in vm_show()
318 for (j = 0 ; j < phys_pg_pack->npages ; j++) { in vm_show()
319 seq_printf(s, " 0x%-14llx\n", in vm_show()
320 phys_pg_pack->pages[j]); in vm_show()
323 spin_unlock(&vm->idr_lock); in vm_show()
327 mutex_unlock(&dev_entry->ctx_mem_hash_mutex); in vm_show()
329 ctx = hl_get_compute_ctx(dev_entry->hdev); in vm_show()
330 if (ctx) { in vm_show()
333 va_range = ctx->va_range[i]; in vm_show()
335 seq_puts(s, "---------------------\n"); in vm_show()
336 mutex_lock(&va_range->lock); in vm_show()
337 list_for_each_entry(va_block, &va_range->list, node) { in vm_show()
338 seq_printf(s, "%#16llx - %#16llx (%#llx)\n", in vm_show()
339 va_block->start, va_block->end, in vm_show()
340 va_block->size); in vm_show()
342 mutex_unlock(&va_range->lock); in vm_show()
345 hl_ctx_put(ctx); in vm_show()
356 struct hl_debugfs_entry *entry = s->private; in userptr_lookup_show()
357 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in userptr_lookup_show()
365 spin_lock(&dev_entry->userptr_spinlock); in userptr_lookup_show()
367 list_for_each_entry(userptr, &dev_entry->userptr_list, debugfs_list) { in userptr_lookup_show()
368 if (dev_entry->userptr_lookup >= userptr->addr && in userptr_lookup_show()
369 dev_entry->userptr_lookup < userptr->addr + userptr->size) { in userptr_lookup_show()
371 for_each_sgtable_dma_sg(userptr->sgt, sg, i) { in userptr_lookup_show()
373 sg_start = userptr->addr + in userptr_lookup_show()
375 sg_end = userptr->addr + in userptr_lookup_show()
378 if (dev_entry->userptr_lookup >= sg_start && in userptr_lookup_show()
379 dev_entry->userptr_lookup < sg_end) { in userptr_lookup_show()
380 dma_addr += (dev_entry->userptr_lookup - in userptr_lookup_show()
386 …seq_puts(s, "-------------------------------------------------------------------------------------… in userptr_lookup_show()
388 seq_printf(s, " 0x%-18llx 0x%-16llx %-8u 0x%-16llx %-12llu\n", in userptr_lookup_show()
389 dev_entry->userptr_lookup, in userptr_lookup_show()
390 (u64)dma_addr, userptr->pid, in userptr_lookup_show()
391 userptr->addr, userptr->size); in userptr_lookup_show()
398 spin_unlock(&dev_entry->userptr_spinlock); in userptr_lookup_show()
409 struct seq_file *s = file->private_data; in userptr_lookup_write()
410 struct hl_debugfs_entry *entry = s->private; in userptr_lookup_write()
411 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in userptr_lookup_write()
419 dev_entry->userptr_lookup = value; in userptr_lookup_write()
426 struct hl_debugfs_entry *entry = s->private; in mmu_show()
427 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in mmu_show()
428 struct hl_device *hdev = dev_entry->hdev; in mmu_show()
429 struct hl_ctx *ctx; in mmu_show() local
431 u64 virt_addr = dev_entry->mmu_addr, phys_addr; in mmu_show()
434 if (dev_entry->mmu_asid == HL_KERNEL_ASID_ID) in mmu_show()
435 ctx = hdev->kernel_ctx; in mmu_show()
437 ctx = hl_get_compute_ctx(hdev); in mmu_show()
439 if (!ctx) { in mmu_show()
440 dev_err(hdev->dev, "no ctx available\n"); in mmu_show()
444 if (hl_mmu_get_tlb_info(ctx, virt_addr, &hops_info)) { in mmu_show()
445 dev_err(hdev->dev, "virt addr 0x%llx is not mapped to phys addr\n", in mmu_show()
450 hl_mmu_va_to_pa(ctx, virt_addr, &phys_addr); in mmu_show()
453 (dev_entry->mmu_addr != hops_info.scrambled_vaddr)) in mmu_show()
455 …"asid: %u, virt_addr: 0x%llx, scrambled virt_addr: 0x%llx,\nphys_addr: 0x%llx, scrambled_phys_addr… in mmu_show()
456 dev_entry->mmu_asid, dev_entry->mmu_addr, in mmu_show()
461 "asid: %u, virt_addr: 0x%llx, phys_addr: 0x%llx\n", in mmu_show()
462 dev_entry->mmu_asid, dev_entry->mmu_addr, phys_addr); in mmu_show()
474 if (dev_entry->mmu_asid != HL_KERNEL_ASID_ID) in mmu_show()
475 hl_ctx_put(ctx); in mmu_show()
483 struct seq_file *s = file->private_data; in mmu_asid_va_write()
484 struct hl_debugfs_entry *entry = s->private; in mmu_asid_va_write()
485 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in mmu_asid_va_write()
486 struct hl_device *hdev = dev_entry->hdev; in mmu_asid_va_write()
491 if (count > sizeof(kbuf) - 1) in mmu_asid_va_write()
502 rc = kstrtouint(kbuf, 10, &dev_entry->mmu_asid); in mmu_asid_va_write()
508 rc = kstrtoull(c+3, 16, &dev_entry->mmu_addr); in mmu_asid_va_write()
515 dev_err(hdev->dev, "usage: echo <asid> <0xaddr> > mmu\n"); in mmu_asid_va_write()
517 return -EINVAL; in mmu_asid_va_write()
522 struct hl_debugfs_entry *entry = s->private; in mmu_ack_error()
523 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in mmu_ack_error()
524 struct hl_device *hdev = dev_entry->hdev; in mmu_ack_error()
527 if (!dev_entry->mmu_cap_mask) { in mmu_ack_error()
528 dev_err(hdev->dev, "mmu_cap_mask is not set\n"); in mmu_ack_error()
532 rc = hdev->asic_funcs->ack_mmu_errors(hdev, dev_entry->mmu_cap_mask); in mmu_ack_error()
538 return -EINVAL; in mmu_ack_error()
545 struct seq_file *s = file->private_data; in mmu_ack_error_value_write()
546 struct hl_debugfs_entry *entry = s->private; in mmu_ack_error_value_write()
547 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in mmu_ack_error_value_write()
548 struct hl_device *hdev = dev_entry->hdev; in mmu_ack_error_value_write()
552 if (count > sizeof(kbuf) - 1) in mmu_ack_error_value_write()
563 rc = kstrtoull(kbuf, 16, &dev_entry->mmu_cap_mask); in mmu_ack_error_value_write()
569 dev_err(hdev->dev, "usage: echo <0xmmu_cap_mask > > mmu_error\n"); in mmu_ack_error_value_write()
571 return -EINVAL; in mmu_ack_error_value_write()
576 struct hl_debugfs_entry *entry = s->private; in engines_show()
577 struct hl_dbg_device_entry *dev_entry = entry->dev_entry; in engines_show()
578 struct hl_device *hdev = dev_entry->hdev; in engines_show()
581 if (hdev->reset_info.in_reset) { in engines_show()
582 dev_warn_ratelimited(hdev->dev, in engines_show()
591 return -ENOMEM; in engines_show()
593 hdev->asic_funcs->is_device_idle(hdev, NULL, 0, &eng_data); in engines_show()
596 dev_err(hdev->dev, in engines_show()
600 return -ENOMEM; in engines_show()
613 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_memory_scrub()
614 struct hl_device *hdev = entry->hdev; in hl_memory_scrub()
615 u64 val = hdev->memory_scrub_val; in hl_memory_scrub()
619 dev_warn_ratelimited(hdev->dev, "Can't scrub memory, device is not operational\n"); in hl_memory_scrub()
620 return -EIO; in hl_memory_scrub()
623 mutex_lock(&hdev->fpriv_list_lock); in hl_memory_scrub()
624 if (hdev->is_compute_ctx_active) { in hl_memory_scrub()
625 mutex_unlock(&hdev->fpriv_list_lock); in hl_memory_scrub()
626 dev_err(hdev->dev, "can't scrub dram, context exist\n"); in hl_memory_scrub()
627 return -EBUSY; in hl_memory_scrub()
629 hdev->is_in_dram_scrub = true; in hl_memory_scrub()
630 mutex_unlock(&hdev->fpriv_list_lock); in hl_memory_scrub()
632 rc = hdev->asic_funcs->scrub_device_dram(hdev, val); in hl_memory_scrub()
634 mutex_lock(&hdev->fpriv_list_lock); in hl_memory_scrub()
635 hdev->is_in_dram_scrub = false; in hl_memory_scrub()
636 mutex_unlock(&hdev->fpriv_list_lock); in hl_memory_scrub()
645 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_is_device_va()
647 if (prop->dram_supports_virtual_memory && in hl_is_device_va()
648 (addr >= prop->dmmu.start_addr && addr < prop->dmmu.end_addr)) in hl_is_device_va()
651 if (addr >= prop->pmmu.start_addr && in hl_is_device_va()
652 addr < prop->pmmu.end_addr) in hl_is_device_va()
655 if (addr >= prop->pmmu_huge.start_addr && in hl_is_device_va()
656 addr < prop->pmmu_huge.end_addr) in hl_is_device_va()
665 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_is_device_internal_memory_va()
668 if (prop->dram_supports_virtual_memory) { in hl_is_device_internal_memory_va()
669 dram_start_addr = prop->dmmu.start_addr; in hl_is_device_internal_memory_va()
670 dram_end_addr = prop->dmmu.end_addr; in hl_is_device_internal_memory_va()
672 dram_start_addr = prop->dram_base_address; in hl_is_device_internal_memory_va()
673 dram_end_addr = prop->dram_end_address; in hl_is_device_internal_memory_va()
680 if (hl_mem_area_inside_range(addr, size, prop->sram_base_address, in hl_is_device_internal_memory_va()
681 prop->sram_end_address)) in hl_is_device_internal_memory_va()
691 struct hl_ctx *ctx; in device_va_to_pa() local
699 ctx = hl_get_compute_ctx(hdev); in device_va_to_pa()
701 if (!ctx) { in device_va_to_pa()
702 dev_err(hdev->dev, "no ctx available\n"); in device_va_to_pa()
703 return -EINVAL; in device_va_to_pa()
707 mutex_lock(&ctx->mem_hash_lock); in device_va_to_pa()
708 hash_for_each(ctx->mem_hash, i, hnode, node) { in device_va_to_pa()
709 vm_type = hnode->ptr; in device_va_to_pa()
712 userptr = hnode->ptr; in device_va_to_pa()
713 range_size = userptr->size; in device_va_to_pa()
715 phys_pg_pack = hnode->ptr; in device_va_to_pa()
716 range_size = phys_pg_pack->total_size; in device_va_to_pa()
720 if ((virt_addr >= hnode->vaddr) && in device_va_to_pa()
721 (end_address <= hnode->vaddr + range_size)) { in device_va_to_pa()
726 mutex_unlock(&ctx->mem_hash_lock); in device_va_to_pa()
729 dev_err(hdev->dev, in device_va_to_pa()
732 rc = -EINVAL; in device_va_to_pa()
736 rc = hl_mmu_va_to_pa(ctx, virt_addr, phys_addr); in device_va_to_pa()
738 dev_err(hdev->dev, in device_va_to_pa()
741 rc = -EINVAL; in device_va_to_pa()
745 hl_ctx_put(ctx); in device_va_to_pa()
759 mem_reg = &hdev->pci_mem_region[i]; in hl_access_dev_mem_by_region()
760 if (!mem_reg->used) in hl_access_dev_mem_by_region()
762 if (addr >= mem_reg->region_base && in hl_access_dev_mem_by_region()
763 addr <= mem_reg->region_base + mem_reg->region_size - acc_size) { in hl_access_dev_mem_by_region()
765 return hdev->asic_funcs->access_dev_mem(hdev, i, addr, val, acc_type); in hl_access_dev_mem_by_region()
774 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_access_host_mem()
775 u64 offset = prop->device_dma_offset_for_host_access; in hl_access_host_mem()
779 *val = *(u32 *) phys_to_virt(addr - offset); in hl_access_host_mem()
782 *(u32 *) phys_to_virt(addr - offset) = *val; in hl_access_host_mem()
785 *val = *(u64 *) phys_to_virt(addr - offset); in hl_access_host_mem()
788 *(u64 *) phys_to_virt(addr - offset) = *val; in hl_access_host_mem()
791 dev_err(hdev->dev, "hostmem access-type %d id not supported\n", acc_type); in hl_access_host_mem()
801 u64 host_start = hdev->asic_prop.host_base_address; in hl_access_mem()
802 u64 host_end = hdev->asic_prop.host_end_address; in hl_access_mem()
815 dev_err(hdev->dev, in hl_access_mem()
824 if (!user_address || device_iommu_mapped(&hdev->pdev->dev)) { in hl_access_mem()
825 rc = -EINVAL; in hl_access_mem()
829 if (addr >= host_start && addr <= host_end - acc_size) { in hl_access_mem()
832 rc = -EINVAL; in hl_access_mem()
838 dev_err(hdev->dev, "invalid addr %#llx\n", addr); in hl_access_mem()
845 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_data_read32()
846 struct hl_device *hdev = entry->hdev; in hl_data_read32()
847 u64 value64, addr = entry->addr; in hl_data_read32()
852 if (hdev->reset_info.in_reset) { in hl_data_read32()
853 dev_warn_ratelimited(hdev->dev, "Can't read during reset\n"); in hl_data_read32()
874 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_data_write32()
875 struct hl_device *hdev = entry->hdev; in hl_data_write32()
876 u64 value64, addr = entry->addr; in hl_data_write32()
880 if (hdev->reset_info.in_reset) { in hl_data_write32()
881 dev_warn_ratelimited(hdev->dev, "Can't write during reset\n"); in hl_data_write32()
900 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_data_read64()
901 struct hl_device *hdev = entry->hdev; in hl_data_read64()
902 u64 addr = entry->addr; in hl_data_read64()
907 if (hdev->reset_info.in_reset) { in hl_data_read64()
908 dev_warn_ratelimited(hdev->dev, "Can't read during reset\n"); in hl_data_read64()
927 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_data_write64()
928 struct hl_device *hdev = entry->hdev; in hl_data_write64()
929 u64 addr = entry->addr; in hl_data_write64()
933 if (hdev->reset_info.in_reset) { in hl_data_write64()
934 dev_warn_ratelimited(hdev->dev, "Can't write during reset\n"); in hl_data_write64()
952 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_dma_size_write()
953 struct hl_device *hdev = entry->hdev; in hl_dma_size_write()
954 u64 addr = entry->addr; in hl_dma_size_write()
958 if (hdev->reset_info.in_reset) { in hl_dma_size_write()
959 dev_warn_ratelimited(hdev->dev, "Can't DMA during reset\n"); in hl_dma_size_write()
967 dev_err(hdev->dev, "DMA read failed. size can't be 0\n"); in hl_dma_size_write()
968 return -EINVAL; in hl_dma_size_write()
972 dev_err(hdev->dev, in hl_dma_size_write()
974 return -EINVAL; in hl_dma_size_write()
978 dev_err(hdev->dev, in hl_dma_size_write()
981 return -EINVAL; in hl_dma_size_write()
985 entry->data_dma_blob_desc.size = 0; in hl_dma_size_write()
986 vfree(entry->data_dma_blob_desc.data); in hl_dma_size_write()
988 entry->data_dma_blob_desc.data = vmalloc(size); in hl_dma_size_write()
989 if (!entry->data_dma_blob_desc.data) in hl_dma_size_write()
990 return -ENOMEM; in hl_dma_size_write()
992 rc = hdev->asic_funcs->debugfs_read_dma(hdev, addr, size, in hl_dma_size_write()
993 entry->data_dma_blob_desc.data); in hl_dma_size_write()
995 dev_err(hdev->dev, "Failed to DMA from 0x%010llx\n", addr); in hl_dma_size_write()
996 vfree(entry->data_dma_blob_desc.data); in hl_dma_size_write()
997 entry->data_dma_blob_desc.data = NULL; in hl_dma_size_write()
998 return -EIO; in hl_dma_size_write()
1001 entry->data_dma_blob_desc.size = size; in hl_dma_size_write()
1009 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_monitor_dump_trigger()
1010 struct hl_device *hdev = entry->hdev; in hl_monitor_dump_trigger()
1014 if (hdev->reset_info.in_reset) { in hl_monitor_dump_trigger()
1015 dev_warn_ratelimited(hdev->dev, "Can't dump monitors during reset\n"); in hl_monitor_dump_trigger()
1023 dev_err(hdev->dev, "Must write 1 to trigger monitor dump\n"); in hl_monitor_dump_trigger()
1024 return -EINVAL; in hl_monitor_dump_trigger()
1030 entry->mon_dump_blob_desc.size = 0; in hl_monitor_dump_trigger()
1031 vfree(entry->mon_dump_blob_desc.data); in hl_monitor_dump_trigger()
1033 entry->mon_dump_blob_desc.data = vmalloc(size); in hl_monitor_dump_trigger()
1034 if (!entry->mon_dump_blob_desc.data) in hl_monitor_dump_trigger()
1035 return -ENOMEM; in hl_monitor_dump_trigger()
1037 rc = hdev->asic_funcs->get_monitor_dump(hdev, entry->mon_dump_blob_desc.data); in hl_monitor_dump_trigger()
1039 dev_err(hdev->dev, "Failed to dump monitors\n"); in hl_monitor_dump_trigger()
1040 vfree(entry->mon_dump_blob_desc.data); in hl_monitor_dump_trigger()
1041 entry->mon_dump_blob_desc.data = NULL; in hl_monitor_dump_trigger()
1042 return -EIO; in hl_monitor_dump_trigger()
1045 entry->mon_dump_blob_desc.size = size; in hl_monitor_dump_trigger()
1053 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_get_power_state()
1054 struct hl_device *hdev = entry->hdev; in hl_get_power_state()
1061 if (hdev->pdev->current_state == PCI_D0) in hl_get_power_state()
1063 else if (hdev->pdev->current_state == PCI_D3hot) in hl_get_power_state()
1069 "current power state: %d\n1 - D0\n2 - D3hot\n3 - Unknown\n", i); in hl_get_power_state()
1077 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_set_power_state()
1078 struct hl_device *hdev = entry->hdev; in hl_set_power_state()
1087 pci_set_power_state(hdev->pdev, PCI_D0); in hl_set_power_state()
1088 pci_restore_state(hdev->pdev); in hl_set_power_state()
1089 rc = pci_enable_device(hdev->pdev); in hl_set_power_state()
1093 pci_save_state(hdev->pdev); in hl_set_power_state()
1094 pci_disable_device(hdev->pdev); in hl_set_power_state()
1095 pci_set_power_state(hdev->pdev, PCI_D3hot); in hl_set_power_state()
1097 dev_dbg(hdev->dev, "invalid power state value %u\n", value); in hl_set_power_state()
1098 return -EINVAL; in hl_set_power_state()
1107 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_i2c_data_read()
1108 struct hl_device *hdev = entry->hdev; in hl_i2c_data_read()
1116 rc = hl_debugfs_i2c_read(hdev, entry->i2c_bus, entry->i2c_addr, in hl_i2c_data_read()
1117 entry->i2c_reg, entry->i2c_len, &val); in hl_i2c_data_read()
1119 dev_err(hdev->dev, in hl_i2c_data_read()
1121 entry->i2c_bus, entry->i2c_addr, entry->i2c_reg, entry->i2c_len); in hl_i2c_data_read()
1135 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_i2c_data_write()
1136 struct hl_device *hdev = entry->hdev; in hl_i2c_data_write()
1144 rc = hl_debugfs_i2c_write(hdev, entry->i2c_bus, entry->i2c_addr, in hl_i2c_data_write()
1145 entry->i2c_reg, entry->i2c_len, value); in hl_i2c_data_write()
1147 dev_err(hdev->dev, in hl_i2c_data_write()
1149 value, entry->i2c_bus, entry->i2c_addr, entry->i2c_reg, entry->i2c_len); in hl_i2c_data_write()
1159 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_led0_write()
1160 struct hl_device *hdev = entry->hdev; in hl_led0_write()
1178 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_led1_write()
1179 struct hl_device *hdev = entry->hdev; in hl_led1_write()
1197 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_led2_write()
1198 struct hl_device *hdev = entry->hdev; in hl_led2_write()
1224 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_device_write()
1225 struct hl_device *hdev = entry->hdev; in hl_device_write()
1235 hdev->disabled = true; in hl_device_write()
1237 hdev->disabled = false; in hl_device_write()
1239 hdev->asic_funcs->suspend(hdev); in hl_device_write()
1241 hdev->asic_funcs->resume(hdev); in hl_device_write()
1243 hdev->device_cpu_disabled = true; in hl_device_write()
1245 dev_err(hdev->dev, in hl_device_write()
1247 count = -EINVAL; in hl_device_write()
1268 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_stop_on_err_read()
1269 struct hl_device *hdev = entry->hdev; in hl_stop_on_err_read()
1273 if (!hdev->asic_prop.configurable_stop_on_err) in hl_stop_on_err_read()
1274 return -EOPNOTSUPP; in hl_stop_on_err_read()
1279 sprintf(tmp_buf, "%d\n", hdev->stop_on_err); in hl_stop_on_err_read()
1289 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_stop_on_err_write()
1290 struct hl_device *hdev = entry->hdev; in hl_stop_on_err_write()
1294 if (!hdev->asic_prop.configurable_stop_on_err) in hl_stop_on_err_write()
1295 return -EOPNOTSUPP; in hl_stop_on_err_write()
1297 if (hdev->reset_info.in_reset) { in hl_stop_on_err_write()
1298 dev_warn_ratelimited(hdev->dev, in hl_stop_on_err_write()
1307 hdev->stop_on_err = value ? 1 : 0; in hl_stop_on_err_write()
1317 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_security_violations_read()
1318 struct hl_device *hdev = entry->hdev; in hl_security_violations_read()
1320 hdev->asic_funcs->ack_protection_bits_errors(hdev); in hl_security_violations_read()
1328 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_state_dump_read()
1331 down_read(&entry->state_dump_sem); in hl_state_dump_read()
1332 if (!entry->state_dump[entry->state_dump_head]) in hl_state_dump_read()
1337 entry->state_dump[entry->state_dump_head], in hl_state_dump_read()
1338 strlen(entry->state_dump[entry->state_dump_head])); in hl_state_dump_read()
1339 up_read(&entry->state_dump_sem); in hl_state_dump_read()
1347 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_state_dump_write()
1348 struct hl_device *hdev = entry->hdev; in hl_state_dump_write()
1357 if (size <= 0 || size >= ARRAY_SIZE(entry->state_dump)) { in hl_state_dump_write()
1358 dev_err(hdev->dev, "Invalid number of dumps to skip\n"); in hl_state_dump_write()
1359 return -EINVAL; in hl_state_dump_write()
1362 if (entry->state_dump[entry->state_dump_head]) { in hl_state_dump_write()
1363 down_write(&entry->state_dump_sem); in hl_state_dump_write()
1365 vfree(entry->state_dump[entry->state_dump_head]); in hl_state_dump_write()
1366 entry->state_dump[entry->state_dump_head] = NULL; in hl_state_dump_write()
1367 if (entry->state_dump_head > 0) in hl_state_dump_write()
1368 entry->state_dump_head--; in hl_state_dump_write()
1370 entry->state_dump_head = in hl_state_dump_write()
1371 ARRAY_SIZE(entry->state_dump) - 1; in hl_state_dump_write()
1373 up_write(&entry->state_dump_sem); in hl_state_dump_write()
1382 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_timeout_locked_read()
1383 struct hl_device *hdev = entry->hdev; in hl_timeout_locked_read()
1391 jiffies_to_msecs(hdev->timeout_jiffies) / 1000); in hl_timeout_locked_read()
1401 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_timeout_locked_write()
1402 struct hl_device *hdev = entry->hdev; in hl_timeout_locked_write()
1411 hdev->timeout_jiffies = msecs_to_jiffies(value * 1000); in hl_timeout_locked_write()
1413 hdev->timeout_jiffies = MAX_SCHEDULE_TIMEOUT; in hl_timeout_locked_write()
1421 struct hl_dbg_device_entry *entry = file_inode(f)->i_private; in hl_check_razwi_happened()
1422 struct hl_device *hdev = entry->hdev; in hl_check_razwi_happened()
1424 hdev->asic_funcs->check_if_razwi_happened(hdev); in hl_check_razwi_happened()
1537 struct hl_debugfs_entry *node = inode->i_private; in hl_debugfs_open()
1539 return single_open(file, node->info_ent->show, node); in hl_debugfs_open()
1545 struct hl_debugfs_entry *node = file->f_inode->i_private; in hl_debugfs_write()
1547 if (node->info_ent->write) in hl_debugfs_write()
1548 return node->info_ent->write(file, buf, count, f_pos); in hl_debugfs_write()
1550 return -EINVAL; in hl_debugfs_write()
1568 &dev_entry->i2c_bus); in add_secured_nodes()
1573 &dev_entry->i2c_addr); in add_secured_nodes()
1578 &dev_entry->i2c_reg); in add_secured_nodes()
1583 &dev_entry->i2c_len); in add_secured_nodes()
1620 &hdev->memory_scrub_val); in add_files_to_device()
1631 &dev_entry->addr); in add_files_to_device()
1690 &dev_entry->data_dma_blob_desc); in add_files_to_device()
1701 &dev_entry->mon_dump_blob_desc); in add_files_to_device()
1706 &hdev->reset_info.skip_reset_on_timeout); in add_files_to_device()
1723 &hdev->device_release_watchdog_timeout_sec); in add_files_to_device()
1725 for (i = 0, entry = dev_entry->entry_arr ; i < count ; i++, entry++) { in add_files_to_device()
1731 entry->info_ent = &hl_debugfs_list[i]; in add_files_to_device()
1732 entry->dev_entry = dev_entry; in add_files_to_device()
1738 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_device_init()
1741 dev_entry->hdev = hdev; in hl_debugfs_device_init()
1742 dev_entry->entry_arr = kmalloc_array(count, sizeof(struct hl_debugfs_entry), GFP_KERNEL); in hl_debugfs_device_init()
1743 if (!dev_entry->entry_arr) in hl_debugfs_device_init()
1744 return -ENOMEM; in hl_debugfs_device_init()
1746 dev_entry->data_dma_blob_desc.size = 0; in hl_debugfs_device_init()
1747 dev_entry->data_dma_blob_desc.data = NULL; in hl_debugfs_device_init()
1748 dev_entry->mon_dump_blob_desc.size = 0; in hl_debugfs_device_init()
1749 dev_entry->mon_dump_blob_desc.data = NULL; in hl_debugfs_device_init()
1751 INIT_LIST_HEAD(&dev_entry->file_list); in hl_debugfs_device_init()
1752 INIT_LIST_HEAD(&dev_entry->cb_list); in hl_debugfs_device_init()
1753 INIT_LIST_HEAD(&dev_entry->cs_list); in hl_debugfs_device_init()
1754 INIT_LIST_HEAD(&dev_entry->cs_job_list); in hl_debugfs_device_init()
1755 INIT_LIST_HEAD(&dev_entry->userptr_list); in hl_debugfs_device_init()
1756 INIT_LIST_HEAD(&dev_entry->ctx_mem_hash_list); in hl_debugfs_device_init()
1757 mutex_init(&dev_entry->file_mutex); in hl_debugfs_device_init()
1758 init_rwsem(&dev_entry->state_dump_sem); in hl_debugfs_device_init()
1759 spin_lock_init(&dev_entry->cb_spinlock); in hl_debugfs_device_init()
1760 spin_lock_init(&dev_entry->cs_spinlock); in hl_debugfs_device_init()
1761 spin_lock_init(&dev_entry->cs_job_spinlock); in hl_debugfs_device_init()
1762 spin_lock_init(&dev_entry->userptr_spinlock); in hl_debugfs_device_init()
1763 mutex_init(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_device_init()
1770 struct hl_dbg_device_entry *entry = &hdev->hl_debugfs; in hl_debugfs_device_fini()
1773 mutex_destroy(&entry->ctx_mem_hash_mutex); in hl_debugfs_device_fini()
1774 mutex_destroy(&entry->file_mutex); in hl_debugfs_device_fini()
1776 vfree(entry->data_dma_blob_desc.data); in hl_debugfs_device_fini()
1777 vfree(entry->mon_dump_blob_desc.data); in hl_debugfs_device_fini()
1779 for (i = 0; i < ARRAY_SIZE(entry->state_dump); ++i) in hl_debugfs_device_fini()
1780 vfree(entry->state_dump[i]); in hl_debugfs_device_fini()
1782 kfree(entry->entry_arr); in hl_debugfs_device_fini()
1787 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_add_device()
1789 dev_entry->root = hdev->drm.accel->debugfs_root; in hl_debugfs_add_device()
1791 add_files_to_device(hdev, dev_entry, dev_entry->root); in hl_debugfs_add_device()
1793 if (!hdev->asic_prop.fw_security_enabled) in hl_debugfs_add_device()
1794 add_secured_nodes(dev_entry, dev_entry->root); in hl_debugfs_add_device()
1799 struct hl_dbg_device_entry *dev_entry = &hpriv->hdev->hl_debugfs; in hl_debugfs_add_file()
1801 mutex_lock(&dev_entry->file_mutex); in hl_debugfs_add_file()
1802 list_add(&hpriv->debugfs_list, &dev_entry->file_list); in hl_debugfs_add_file()
1803 mutex_unlock(&dev_entry->file_mutex); in hl_debugfs_add_file()
1808 struct hl_dbg_device_entry *dev_entry = &hpriv->hdev->hl_debugfs; in hl_debugfs_remove_file()
1810 mutex_lock(&dev_entry->file_mutex); in hl_debugfs_remove_file()
1811 list_del(&hpriv->debugfs_list); in hl_debugfs_remove_file()
1812 mutex_unlock(&dev_entry->file_mutex); in hl_debugfs_remove_file()
1817 struct hl_dbg_device_entry *dev_entry = &cb->hdev->hl_debugfs; in hl_debugfs_add_cb()
1819 spin_lock(&dev_entry->cb_spinlock); in hl_debugfs_add_cb()
1820 list_add(&cb->debugfs_list, &dev_entry->cb_list); in hl_debugfs_add_cb()
1821 spin_unlock(&dev_entry->cb_spinlock); in hl_debugfs_add_cb()
1826 struct hl_dbg_device_entry *dev_entry = &cb->hdev->hl_debugfs; in hl_debugfs_remove_cb()
1828 spin_lock(&dev_entry->cb_spinlock); in hl_debugfs_remove_cb()
1829 list_del(&cb->debugfs_list); in hl_debugfs_remove_cb()
1830 spin_unlock(&dev_entry->cb_spinlock); in hl_debugfs_remove_cb()
1835 struct hl_dbg_device_entry *dev_entry = &cs->ctx->hdev->hl_debugfs; in hl_debugfs_add_cs()
1837 spin_lock(&dev_entry->cs_spinlock); in hl_debugfs_add_cs()
1838 list_add(&cs->debugfs_list, &dev_entry->cs_list); in hl_debugfs_add_cs()
1839 spin_unlock(&dev_entry->cs_spinlock); in hl_debugfs_add_cs()
1844 struct hl_dbg_device_entry *dev_entry = &cs->ctx->hdev->hl_debugfs; in hl_debugfs_remove_cs()
1846 spin_lock(&dev_entry->cs_spinlock); in hl_debugfs_remove_cs()
1847 list_del(&cs->debugfs_list); in hl_debugfs_remove_cs()
1848 spin_unlock(&dev_entry->cs_spinlock); in hl_debugfs_remove_cs()
1853 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_add_job()
1855 spin_lock(&dev_entry->cs_job_spinlock); in hl_debugfs_add_job()
1856 list_add(&job->debugfs_list, &dev_entry->cs_job_list); in hl_debugfs_add_job()
1857 spin_unlock(&dev_entry->cs_job_spinlock); in hl_debugfs_add_job()
1862 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_remove_job()
1864 spin_lock(&dev_entry->cs_job_spinlock); in hl_debugfs_remove_job()
1865 list_del(&job->debugfs_list); in hl_debugfs_remove_job()
1866 spin_unlock(&dev_entry->cs_job_spinlock); in hl_debugfs_remove_job()
1871 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_add_userptr()
1873 spin_lock(&dev_entry->userptr_spinlock); in hl_debugfs_add_userptr()
1874 list_add(&userptr->debugfs_list, &dev_entry->userptr_list); in hl_debugfs_add_userptr()
1875 spin_unlock(&dev_entry->userptr_spinlock); in hl_debugfs_add_userptr()
1881 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_remove_userptr()
1883 spin_lock(&dev_entry->userptr_spinlock); in hl_debugfs_remove_userptr()
1884 list_del(&userptr->debugfs_list); in hl_debugfs_remove_userptr()
1885 spin_unlock(&dev_entry->userptr_spinlock); in hl_debugfs_remove_userptr()
1888 void hl_debugfs_add_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx) in hl_debugfs_add_ctx_mem_hash() argument
1890 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_add_ctx_mem_hash()
1892 mutex_lock(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_add_ctx_mem_hash()
1893 list_add(&ctx->debugfs_list, &dev_entry->ctx_mem_hash_list); in hl_debugfs_add_ctx_mem_hash()
1894 mutex_unlock(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_add_ctx_mem_hash()
1897 void hl_debugfs_remove_ctx_mem_hash(struct hl_device *hdev, struct hl_ctx *ctx) in hl_debugfs_remove_ctx_mem_hash() argument
1899 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_remove_ctx_mem_hash()
1901 mutex_lock(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_remove_ctx_mem_hash()
1902 list_del(&ctx->debugfs_list); in hl_debugfs_remove_ctx_mem_hash()
1903 mutex_unlock(&dev_entry->ctx_mem_hash_mutex); in hl_debugfs_remove_ctx_mem_hash()
1907 * hl_debugfs_set_state_dump - register state dump making it accessible via
1916 struct hl_dbg_device_entry *dev_entry = &hdev->hl_debugfs; in hl_debugfs_set_state_dump()
1918 down_write(&dev_entry->state_dump_sem); in hl_debugfs_set_state_dump()
1920 dev_entry->state_dump_head = (dev_entry->state_dump_head + 1) % in hl_debugfs_set_state_dump()
1921 ARRAY_SIZE(dev_entry->state_dump); in hl_debugfs_set_state_dump()
1922 vfree(dev_entry->state_dump[dev_entry->state_dump_head]); in hl_debugfs_set_state_dump()
1923 dev_entry->state_dump[dev_entry->state_dump_head] = data; in hl_debugfs_set_state_dump()
1925 up_write(&dev_entry->state_dump_sem); in hl_debugfs_set_state_dump()