Lines Matching refs:pfdev
26 static int wait_ready(struct panfrost_device *pfdev, u32 as_nr) in wait_ready() argument
33 ret = readl_relaxed_poll_timeout_atomic(pfdev->iomem + AS_STATUS(as_nr), in wait_ready()
37 dev_err(pfdev->dev, "AS_ACTIVE bit stuck\n"); in wait_ready()
42 static int write_cmd(struct panfrost_device *pfdev, u32 as_nr, u32 cmd) in write_cmd() argument
47 status = wait_ready(pfdev, as_nr); in write_cmd()
49 mmu_write(pfdev, AS_COMMAND(as_nr), cmd); in write_cmd()
54 static void lock_region(struct panfrost_device *pfdev, u32 as_nr, in lock_region() argument
77 mmu_write(pfdev, AS_LOCKADDR_LO(as_nr), region & 0xFFFFFFFFUL); in lock_region()
78 mmu_write(pfdev, AS_LOCKADDR_HI(as_nr), (region >> 32) & 0xFFFFFFFFUL); in lock_region()
79 write_cmd(pfdev, as_nr, AS_COMMAND_LOCK); in lock_region()
83 static int mmu_hw_do_operation_locked(struct panfrost_device *pfdev, int as_nr, in mmu_hw_do_operation_locked() argument
90 lock_region(pfdev, as_nr, iova, size); in mmu_hw_do_operation_locked()
93 write_cmd(pfdev, as_nr, op); in mmu_hw_do_operation_locked()
96 return wait_ready(pfdev, as_nr); in mmu_hw_do_operation_locked()
99 static int mmu_hw_do_operation(struct panfrost_device *pfdev, in mmu_hw_do_operation() argument
105 spin_lock(&pfdev->as_lock); in mmu_hw_do_operation()
106 ret = mmu_hw_do_operation_locked(pfdev, mmu->as, iova, size, op); in mmu_hw_do_operation()
107 spin_unlock(&pfdev->as_lock); in mmu_hw_do_operation()
111 static void panfrost_mmu_enable(struct panfrost_device *pfdev, struct panfrost_mmu *mmu) in panfrost_mmu_enable() argument
118 mmu_hw_do_operation_locked(pfdev, as_nr, 0, ~0UL, AS_COMMAND_FLUSH_MEM); in panfrost_mmu_enable()
120 mmu_write(pfdev, AS_TRANSTAB_LO(as_nr), transtab & 0xffffffffUL); in panfrost_mmu_enable()
121 mmu_write(pfdev, AS_TRANSTAB_HI(as_nr), transtab >> 32); in panfrost_mmu_enable()
126 mmu_write(pfdev, AS_MEMATTR_LO(as_nr), memattr & 0xffffffffUL); in panfrost_mmu_enable()
127 mmu_write(pfdev, AS_MEMATTR_HI(as_nr), memattr >> 32); in panfrost_mmu_enable()
129 write_cmd(pfdev, as_nr, AS_COMMAND_UPDATE); in panfrost_mmu_enable()
132 static void panfrost_mmu_disable(struct panfrost_device *pfdev, u32 as_nr) in panfrost_mmu_disable() argument
134 mmu_hw_do_operation_locked(pfdev, as_nr, 0, ~0UL, AS_COMMAND_FLUSH_MEM); in panfrost_mmu_disable()
136 mmu_write(pfdev, AS_TRANSTAB_LO(as_nr), 0); in panfrost_mmu_disable()
137 mmu_write(pfdev, AS_TRANSTAB_HI(as_nr), 0); in panfrost_mmu_disable()
139 mmu_write(pfdev, AS_MEMATTR_LO(as_nr), 0); in panfrost_mmu_disable()
140 mmu_write(pfdev, AS_MEMATTR_HI(as_nr), 0); in panfrost_mmu_disable()
142 write_cmd(pfdev, as_nr, AS_COMMAND_UPDATE); in panfrost_mmu_disable()
145 u32 panfrost_mmu_as_get(struct panfrost_device *pfdev, struct panfrost_mmu *mmu) in panfrost_mmu_as_get() argument
149 spin_lock(&pfdev->as_lock); in panfrost_mmu_as_get()
156 list_move(&mmu->list, &pfdev->as_lru_list); in panfrost_mmu_as_get()
161 as = ffz(pfdev->as_alloc_mask); in panfrost_mmu_as_get()
162 if (!(BIT(as) & pfdev->features.as_present)) { in panfrost_mmu_as_get()
165 list_for_each_entry_reverse(lru_mmu, &pfdev->as_lru_list, list) { in panfrost_mmu_as_get()
169 WARN_ON(&lru_mmu->list == &pfdev->as_lru_list); in panfrost_mmu_as_get()
180 set_bit(as, &pfdev->as_alloc_mask); in panfrost_mmu_as_get()
182 list_add(&mmu->list, &pfdev->as_lru_list); in panfrost_mmu_as_get()
184 dev_dbg(pfdev->dev, "Assigned AS%d to mmu %p, alloc_mask=%lx", as, mmu, pfdev->as_alloc_mask); in panfrost_mmu_as_get()
186 panfrost_mmu_enable(pfdev, mmu); in panfrost_mmu_as_get()
189 spin_unlock(&pfdev->as_lock); in panfrost_mmu_as_get()
193 void panfrost_mmu_as_put(struct panfrost_device *pfdev, struct panfrost_mmu *mmu) in panfrost_mmu_as_put() argument
199 void panfrost_mmu_reset(struct panfrost_device *pfdev) in panfrost_mmu_reset() argument
203 spin_lock(&pfdev->as_lock); in panfrost_mmu_reset()
205 pfdev->as_alloc_mask = 0; in panfrost_mmu_reset()
207 list_for_each_entry_safe(mmu, mmu_tmp, &pfdev->as_lru_list, list) { in panfrost_mmu_reset()
213 spin_unlock(&pfdev->as_lock); in panfrost_mmu_reset()
215 mmu_write(pfdev, MMU_INT_CLEAR, ~0); in panfrost_mmu_reset()
216 mmu_write(pfdev, MMU_INT_MASK, ~0); in panfrost_mmu_reset()
227 static void panfrost_mmu_flush_range(struct panfrost_device *pfdev, in panfrost_mmu_flush_range() argument
234 pm_runtime_get_noresume(pfdev->dev); in panfrost_mmu_flush_range()
237 if (pm_runtime_active(pfdev->dev)) in panfrost_mmu_flush_range()
238 mmu_hw_do_operation(pfdev, mmu, iova, size, AS_COMMAND_FLUSH_PT); in panfrost_mmu_flush_range()
240 pm_runtime_put_sync_autosuspend(pfdev->dev); in panfrost_mmu_flush_range()
243 static int mmu_map_sg(struct panfrost_device *pfdev, struct panfrost_mmu *mmu, in mmu_map_sg() argument
255 dev_dbg(pfdev->dev, "map: as=%d, iova=%llx, paddr=%lx, len=%zx", mmu->as, iova, paddr, len); in mmu_map_sg()
267 panfrost_mmu_flush_range(pfdev, mmu, start_iova, iova - start_iova); in mmu_map_sg()
276 struct panfrost_device *pfdev = to_panfrost_device(obj->dev); in panfrost_mmu_map() local
290 mmu_map_sg(pfdev, mapping->mmu, mapping->mmnode.start << PAGE_SHIFT, in panfrost_mmu_map()
301 struct panfrost_device *pfdev = to_panfrost_device(obj->dev); in panfrost_mmu_unmap() local
310 dev_dbg(pfdev->dev, "unmap: as=%d, iova=%llx, len=%zx", in panfrost_mmu_unmap()
325 panfrost_mmu_flush_range(pfdev, mapping->mmu, in panfrost_mmu_unmap()
360 struct panfrost_device *pfdev = priv->pfdev; in panfrost_mmu_pgtable_alloc() local
367 .ias = FIELD_GET(0xff, pfdev->features.mmu_features), in panfrost_mmu_pgtable_alloc()
368 .oas = FIELD_GET(0xff00, pfdev->features.mmu_features), in panfrost_mmu_pgtable_alloc()
370 .iommu_dev = pfdev->dev, in panfrost_mmu_pgtable_alloc()
383 struct panfrost_device *pfdev = priv->pfdev; in panfrost_mmu_pgtable_free() local
386 spin_lock(&pfdev->as_lock); in panfrost_mmu_pgtable_free()
388 pm_runtime_get_noresume(pfdev->dev); in panfrost_mmu_pgtable_free()
389 if (pm_runtime_active(pfdev->dev)) in panfrost_mmu_pgtable_free()
390 panfrost_mmu_disable(pfdev, mmu->as); in panfrost_mmu_pgtable_free()
391 pm_runtime_put_autosuspend(pfdev->dev); in panfrost_mmu_pgtable_free()
393 clear_bit(mmu->as, &pfdev->as_alloc_mask); in panfrost_mmu_pgtable_free()
394 clear_bit(mmu->as, &pfdev->as_in_use_mask); in panfrost_mmu_pgtable_free()
397 spin_unlock(&pfdev->as_lock); in panfrost_mmu_pgtable_free()
403 addr_to_mapping(struct panfrost_device *pfdev, int as, u64 addr) in addr_to_mapping() argument
411 spin_lock(&pfdev->as_lock); in addr_to_mapping()
412 list_for_each_entry(mmu, &pfdev->as_lru_list, list) { in addr_to_mapping()
435 spin_unlock(&pfdev->as_lock); in addr_to_mapping()
441 static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as, in panfrost_mmu_map_fault_addr() argument
452 bomapping = addr_to_mapping(pfdev, as, addr); in panfrost_mmu_map_fault_addr()
458 dev_WARN(pfdev->dev, "matching BO is not heap type (GPU VA = %llx)", in panfrost_mmu_map_fault_addr()
515 if (!dma_map_sg(pfdev->dev, sgt->sgl, sgt->nents, DMA_BIDIRECTIONAL)) { in panfrost_mmu_map_fault_addr()
520 mmu_map_sg(pfdev, bomapping->mmu, addr, in panfrost_mmu_map_fault_addr()
525 dev_dbg(pfdev->dev, "mapped page fault @ AS%d %llx", as, addr); in panfrost_mmu_map_fault_addr()
540 static const char *access_type_name(struct panfrost_device *pfdev, in access_type_name() argument
545 if (panfrost_has_hw_feature(pfdev, HW_FEATURE_AARCH64_MMU)) in access_type_name()
563 struct panfrost_device *pfdev = data; in panfrost_mmu_irq_handler() local
565 if (!mmu_read(pfdev, MMU_INT_STAT)) in panfrost_mmu_irq_handler()
568 mmu_write(pfdev, MMU_INT_MASK, 0); in panfrost_mmu_irq_handler()
574 struct panfrost_device *pfdev = data; in panfrost_mmu_irq_handler_thread() local
575 u32 status = mmu_read(pfdev, MMU_INT_RAWSTAT); in panfrost_mmu_irq_handler_thread()
589 fault_status = mmu_read(pfdev, AS_FAULTSTATUS(i)); in panfrost_mmu_irq_handler_thread()
590 addr = mmu_read(pfdev, AS_FAULTADDRESS_LO(i)); in panfrost_mmu_irq_handler_thread()
591 addr |= (u64)mmu_read(pfdev, AS_FAULTADDRESS_HI(i)) << 32; in panfrost_mmu_irq_handler_thread()
602 ret = panfrost_mmu_map_fault_addr(pfdev, i, addr); in panfrost_mmu_irq_handler_thread()
604 mmu_write(pfdev, MMU_INT_CLEAR, BIT(i)); in panfrost_mmu_irq_handler_thread()
611 dev_err(pfdev->dev, in panfrost_mmu_irq_handler_thread()
623 exception_type, panfrost_exception_name(pfdev, exception_type), in panfrost_mmu_irq_handler_thread()
624 access_type, access_type_name(pfdev, fault_status), in panfrost_mmu_irq_handler_thread()
627 mmu_write(pfdev, MMU_INT_CLEAR, mask); in panfrost_mmu_irq_handler_thread()
632 mmu_write(pfdev, MMU_INT_MASK, ~0); in panfrost_mmu_irq_handler_thread()
636 int panfrost_mmu_init(struct panfrost_device *pfdev) in panfrost_mmu_init() argument
640 irq = platform_get_irq_byname(to_platform_device(pfdev->dev), "mmu"); in panfrost_mmu_init()
644 err = devm_request_threaded_irq(pfdev->dev, irq, panfrost_mmu_irq_handler, in panfrost_mmu_init()
646 IRQF_SHARED, "mmu", pfdev); in panfrost_mmu_init()
649 dev_err(pfdev->dev, "failed to request mmu irq"); in panfrost_mmu_init()
656 void panfrost_mmu_fini(struct panfrost_device *pfdev) in panfrost_mmu_fini() argument
658 mmu_write(pfdev, MMU_INT_MASK, 0); in panfrost_mmu_fini()