Lines Matching refs:iommu
112 struct iommu_device iommu; member
120 struct rk_iommu *iommu; member
343 static void rk_iommu_command(struct rk_iommu *iommu, u32 command) in rk_iommu_command() argument
347 for (i = 0; i < iommu->num_mmu; i++) in rk_iommu_command()
348 writel(command, iommu->bases[i] + RK_MMU_COMMAND); in rk_iommu_command()
355 static void rk_iommu_zap_lines(struct rk_iommu *iommu, dma_addr_t iova_start, in rk_iommu_zap_lines() argument
364 for (i = 0; i < iommu->num_mmu; i++) { in rk_iommu_zap_lines()
368 rk_iommu_write(iommu->bases[i], RK_MMU_ZAP_ONE_LINE, iova); in rk_iommu_zap_lines()
372 static bool rk_iommu_is_stall_active(struct rk_iommu *iommu) in rk_iommu_is_stall_active() argument
377 for (i = 0; i < iommu->num_mmu; i++) in rk_iommu_is_stall_active()
378 active &= !!(rk_iommu_read(iommu->bases[i], RK_MMU_STATUS) & in rk_iommu_is_stall_active()
384 static bool rk_iommu_is_paging_enabled(struct rk_iommu *iommu) in rk_iommu_is_paging_enabled() argument
389 for (i = 0; i < iommu->num_mmu; i++) in rk_iommu_is_paging_enabled()
390 enable &= !!(rk_iommu_read(iommu->bases[i], RK_MMU_STATUS) & in rk_iommu_is_paging_enabled()
396 static bool rk_iommu_is_reset_done(struct rk_iommu *iommu) in rk_iommu_is_reset_done() argument
401 for (i = 0; i < iommu->num_mmu; i++) in rk_iommu_is_reset_done()
402 done &= rk_iommu_read(iommu->bases[i], RK_MMU_DTE_ADDR) == 0; in rk_iommu_is_reset_done()
407 static int rk_iommu_enable_stall(struct rk_iommu *iommu) in rk_iommu_enable_stall() argument
412 if (rk_iommu_is_stall_active(iommu)) in rk_iommu_enable_stall()
416 if (!rk_iommu_is_paging_enabled(iommu)) in rk_iommu_enable_stall()
419 rk_iommu_command(iommu, RK_MMU_CMD_ENABLE_STALL); in rk_iommu_enable_stall()
421 ret = readx_poll_timeout(rk_iommu_is_stall_active, iommu, val, in rk_iommu_enable_stall()
425 for (i = 0; i < iommu->num_mmu; i++) in rk_iommu_enable_stall()
426 dev_err(iommu->dev, "Enable stall request timed out, status: %#08x\n", in rk_iommu_enable_stall()
427 rk_iommu_read(iommu->bases[i], RK_MMU_STATUS)); in rk_iommu_enable_stall()
432 static int rk_iommu_disable_stall(struct rk_iommu *iommu) in rk_iommu_disable_stall() argument
437 if (!rk_iommu_is_stall_active(iommu)) in rk_iommu_disable_stall()
440 rk_iommu_command(iommu, RK_MMU_CMD_DISABLE_STALL); in rk_iommu_disable_stall()
442 ret = readx_poll_timeout(rk_iommu_is_stall_active, iommu, val, in rk_iommu_disable_stall()
446 for (i = 0; i < iommu->num_mmu; i++) in rk_iommu_disable_stall()
447 dev_err(iommu->dev, "Disable stall request timed out, status: %#08x\n", in rk_iommu_disable_stall()
448 rk_iommu_read(iommu->bases[i], RK_MMU_STATUS)); in rk_iommu_disable_stall()
453 static int rk_iommu_enable_paging(struct rk_iommu *iommu) in rk_iommu_enable_paging() argument
458 if (rk_iommu_is_paging_enabled(iommu)) in rk_iommu_enable_paging()
461 rk_iommu_command(iommu, RK_MMU_CMD_ENABLE_PAGING); in rk_iommu_enable_paging()
463 ret = readx_poll_timeout(rk_iommu_is_paging_enabled, iommu, val, in rk_iommu_enable_paging()
467 for (i = 0; i < iommu->num_mmu; i++) in rk_iommu_enable_paging()
468 dev_err(iommu->dev, "Enable paging request timed out, status: %#08x\n", in rk_iommu_enable_paging()
469 rk_iommu_read(iommu->bases[i], RK_MMU_STATUS)); in rk_iommu_enable_paging()
474 static int rk_iommu_disable_paging(struct rk_iommu *iommu) in rk_iommu_disable_paging() argument
479 if (!rk_iommu_is_paging_enabled(iommu)) in rk_iommu_disable_paging()
482 rk_iommu_command(iommu, RK_MMU_CMD_DISABLE_PAGING); in rk_iommu_disable_paging()
484 ret = readx_poll_timeout(rk_iommu_is_paging_enabled, iommu, val, in rk_iommu_disable_paging()
488 for (i = 0; i < iommu->num_mmu; i++) in rk_iommu_disable_paging()
489 dev_err(iommu->dev, "Disable paging request timed out, status: %#08x\n", in rk_iommu_disable_paging()
490 rk_iommu_read(iommu->bases[i], RK_MMU_STATUS)); in rk_iommu_disable_paging()
495 static int rk_iommu_force_reset(struct rk_iommu *iommu) in rk_iommu_force_reset() argument
501 if (iommu->reset_disabled) in rk_iommu_force_reset()
508 for (i = 0; i < iommu->num_mmu; i++) { in rk_iommu_force_reset()
510 rk_iommu_write(iommu->bases[i], RK_MMU_DTE_ADDR, dte_addr); in rk_iommu_force_reset()
512 if (dte_addr != rk_iommu_read(iommu->bases[i], RK_MMU_DTE_ADDR)) { in rk_iommu_force_reset()
513 dev_err(iommu->dev, "Error during raw reset. MMU_DTE_ADDR is not functioning\n"); in rk_iommu_force_reset()
518 rk_iommu_command(iommu, RK_MMU_CMD_FORCE_RESET); in rk_iommu_force_reset()
520 ret = readx_poll_timeout(rk_iommu_is_reset_done, iommu, val, in rk_iommu_force_reset()
524 dev_err(iommu->dev, "FORCE_RESET command timed out\n"); in rk_iommu_force_reset()
531 static void log_iova(struct rk_iommu *iommu, int index, dma_addr_t iova) in log_iova() argument
533 void __iomem *base = iommu->bases[index]; in log_iova()
570 dev_err(iommu->dev, "iova = %pad: dte_index: %#03x pte_index: %#03x page_offset: %#03x\n", in log_iova()
572 …dev_err(iommu->dev, "mmu_dte_addr: %pa dte@%pa: %#08x valid: %u pte@%pa: %#08x valid: %u page@%pa … in log_iova()
580 struct rk_iommu *iommu = dev_id; in rk_iommu_irq() local
587 err = pm_runtime_get_if_in_use(iommu->dev); in rk_iommu_irq()
591 if (WARN_ON(clk_bulk_enable(iommu->num_clocks, iommu->clocks))) in rk_iommu_irq()
594 for (i = 0; i < iommu->num_mmu; i++) { in rk_iommu_irq()
595 int_status = rk_iommu_read(iommu->bases[i], RK_MMU_INT_STATUS); in rk_iommu_irq()
600 iova = rk_iommu_read(iommu->bases[i], RK_MMU_PAGE_FAULT_ADDR); in rk_iommu_irq()
605 status = rk_iommu_read(iommu->bases[i], RK_MMU_STATUS); in rk_iommu_irq()
609 dev_err(iommu->dev, "Page fault at %pad of type %s\n", in rk_iommu_irq()
613 log_iova(iommu, i, iova); in rk_iommu_irq()
620 if (iommu->domain) in rk_iommu_irq()
621 report_iommu_fault(iommu->domain, iommu->dev, iova, in rk_iommu_irq()
624 dev_err(iommu->dev, "Page fault while iommu not attached to domain?\n"); in rk_iommu_irq()
626 rk_iommu_base_command(iommu->bases[i], RK_MMU_CMD_ZAP_CACHE); in rk_iommu_irq()
627 rk_iommu_base_command(iommu->bases[i], RK_MMU_CMD_PAGE_FAULT_DONE); in rk_iommu_irq()
631 dev_err(iommu->dev, "BUS_ERROR occurred at %pad\n", &iova); in rk_iommu_irq()
634 dev_err(iommu->dev, "unexpected int_status: %#08x\n", in rk_iommu_irq()
637 rk_iommu_write(iommu->bases[i], RK_MMU_INT_CLEAR, int_status); in rk_iommu_irq()
640 clk_bulk_disable(iommu->num_clocks, iommu->clocks); in rk_iommu_irq()
643 pm_runtime_put(iommu->dev); in rk_iommu_irq()
684 struct rk_iommu *iommu; in rk_iommu_zap_iova() local
687 iommu = list_entry(pos, struct rk_iommu, node); in rk_iommu_zap_iova()
690 ret = pm_runtime_get_if_in_use(iommu->dev); in rk_iommu_zap_iova()
694 WARN_ON(clk_bulk_enable(iommu->num_clocks, in rk_iommu_zap_iova()
695 iommu->clocks)); in rk_iommu_zap_iova()
696 rk_iommu_zap_lines(iommu, iova, size); in rk_iommu_zap_iova()
697 clk_bulk_disable(iommu->num_clocks, iommu->clocks); in rk_iommu_zap_iova()
698 pm_runtime_put(iommu->dev); in rk_iommu_zap_iova()
899 return data ? data->iommu : NULL; in rk_iommu_from_dev()
903 static void rk_iommu_disable(struct rk_iommu *iommu) in rk_iommu_disable() argument
908 WARN_ON(clk_bulk_enable(iommu->num_clocks, iommu->clocks)); in rk_iommu_disable()
909 rk_iommu_enable_stall(iommu); in rk_iommu_disable()
910 rk_iommu_disable_paging(iommu); in rk_iommu_disable()
911 for (i = 0; i < iommu->num_mmu; i++) { in rk_iommu_disable()
912 rk_iommu_write(iommu->bases[i], RK_MMU_INT_MASK, 0); in rk_iommu_disable()
913 rk_iommu_write(iommu->bases[i], RK_MMU_DTE_ADDR, 0); in rk_iommu_disable()
915 rk_iommu_disable_stall(iommu); in rk_iommu_disable()
916 clk_bulk_disable(iommu->num_clocks, iommu->clocks); in rk_iommu_disable()
920 static int rk_iommu_enable(struct rk_iommu *iommu) in rk_iommu_enable() argument
922 struct iommu_domain *domain = iommu->domain; in rk_iommu_enable()
926 ret = clk_bulk_enable(iommu->num_clocks, iommu->clocks); in rk_iommu_enable()
930 ret = rk_iommu_enable_stall(iommu); in rk_iommu_enable()
934 ret = rk_iommu_force_reset(iommu); in rk_iommu_enable()
938 for (i = 0; i < iommu->num_mmu; i++) { in rk_iommu_enable()
939 rk_iommu_write(iommu->bases[i], RK_MMU_DTE_ADDR, in rk_iommu_enable()
941 rk_iommu_base_command(iommu->bases[i], RK_MMU_CMD_ZAP_CACHE); in rk_iommu_enable()
942 rk_iommu_write(iommu->bases[i], RK_MMU_INT_MASK, RK_MMU_IRQ_MASK); in rk_iommu_enable()
945 ret = rk_iommu_enable_paging(iommu); in rk_iommu_enable()
948 rk_iommu_disable_stall(iommu); in rk_iommu_enable()
950 clk_bulk_disable(iommu->num_clocks, iommu->clocks); in rk_iommu_enable()
957 struct rk_iommu *iommu; in rk_iommu_detach_device() local
963 iommu = rk_iommu_from_dev(dev); in rk_iommu_detach_device()
964 if (!iommu) in rk_iommu_detach_device()
970 if (iommu->domain != domain) in rk_iommu_detach_device()
973 iommu->domain = NULL; in rk_iommu_detach_device()
976 list_del_init(&iommu->node); in rk_iommu_detach_device()
979 ret = pm_runtime_get_if_in_use(iommu->dev); in rk_iommu_detach_device()
982 rk_iommu_disable(iommu); in rk_iommu_detach_device()
983 pm_runtime_put(iommu->dev); in rk_iommu_detach_device()
990 struct rk_iommu *iommu; in rk_iommu_attach_device() local
999 iommu = rk_iommu_from_dev(dev); in rk_iommu_attach_device()
1000 if (!iommu) in rk_iommu_attach_device()
1006 if (iommu->domain == domain) in rk_iommu_attach_device()
1009 if (iommu->domain) in rk_iommu_attach_device()
1010 rk_iommu_detach_device(iommu->domain, dev); in rk_iommu_attach_device()
1012 iommu->domain = domain; in rk_iommu_attach_device()
1015 list_add_tail(&iommu->node, &rk_domain->iommus); in rk_iommu_attach_device()
1018 ret = pm_runtime_get_if_in_use(iommu->dev); in rk_iommu_attach_device()
1022 ret = rk_iommu_enable(iommu); in rk_iommu_attach_device()
1024 rk_iommu_detach_device(iommu->domain, dev); in rk_iommu_attach_device()
1026 pm_runtime_put(iommu->dev); in rk_iommu_attach_device()
1107 struct rk_iommu *iommu; in rk_iommu_probe_device() local
1113 iommu = rk_iommu_from_dev(dev); in rk_iommu_probe_device()
1115 data->link = device_link_add(dev, iommu->dev, in rk_iommu_probe_device()
1118 return &iommu->iommu; in rk_iommu_probe_device()
1130 struct rk_iommu *iommu; in rk_iommu_device_group() local
1132 iommu = rk_iommu_from_dev(dev); in rk_iommu_device_group()
1134 return iommu_group_ref_get(iommu->group); in rk_iommu_device_group()
1149 data->iommu = platform_get_drvdata(iommu_dev); in rk_iommu_of_xlate()
1175 struct rk_iommu *iommu; in rk_iommu_probe() local
1181 iommu = devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL); in rk_iommu_probe()
1182 if (!iommu) in rk_iommu_probe()
1185 platform_set_drvdata(pdev, iommu); in rk_iommu_probe()
1186 iommu->dev = dev; in rk_iommu_probe()
1187 iommu->num_mmu = 0; in rk_iommu_probe()
1200 iommu->bases = devm_kcalloc(dev, num_res, sizeof(*iommu->bases), in rk_iommu_probe()
1202 if (!iommu->bases) in rk_iommu_probe()
1209 iommu->bases[i] = devm_ioremap_resource(&pdev->dev, res); in rk_iommu_probe()
1210 if (IS_ERR(iommu->bases[i])) in rk_iommu_probe()
1212 iommu->num_mmu++; in rk_iommu_probe()
1214 if (iommu->num_mmu == 0) in rk_iommu_probe()
1215 return PTR_ERR(iommu->bases[0]); in rk_iommu_probe()
1217 iommu->num_irq = platform_irq_count(pdev); in rk_iommu_probe()
1218 if (iommu->num_irq < 0) in rk_iommu_probe()
1219 return iommu->num_irq; in rk_iommu_probe()
1221 iommu->reset_disabled = device_property_read_bool(dev, in rk_iommu_probe()
1224 iommu->num_clocks = ARRAY_SIZE(rk_iommu_clocks); in rk_iommu_probe()
1225 iommu->clocks = devm_kcalloc(iommu->dev, iommu->num_clocks, in rk_iommu_probe()
1226 sizeof(*iommu->clocks), GFP_KERNEL); in rk_iommu_probe()
1227 if (!iommu->clocks) in rk_iommu_probe()
1230 for (i = 0; i < iommu->num_clocks; ++i) in rk_iommu_probe()
1231 iommu->clocks[i].id = rk_iommu_clocks[i]; in rk_iommu_probe()
1238 err = devm_clk_bulk_get(iommu->dev, iommu->num_clocks, iommu->clocks); in rk_iommu_probe()
1240 iommu->num_clocks = 0; in rk_iommu_probe()
1244 err = clk_bulk_prepare(iommu->num_clocks, iommu->clocks); in rk_iommu_probe()
1248 iommu->group = iommu_group_alloc(); in rk_iommu_probe()
1249 if (IS_ERR(iommu->group)) { in rk_iommu_probe()
1250 err = PTR_ERR(iommu->group); in rk_iommu_probe()
1254 err = iommu_device_sysfs_add(&iommu->iommu, dev, NULL, dev_name(dev)); in rk_iommu_probe()
1258 err = iommu_device_register(&iommu->iommu, &rk_iommu_ops, dev); in rk_iommu_probe()
1274 for (i = 0; i < iommu->num_irq; i++) { in rk_iommu_probe()
1282 err = devm_request_irq(iommu->dev, irq, rk_iommu_irq, in rk_iommu_probe()
1283 IRQF_SHARED, dev_name(dev), iommu); in rk_iommu_probe()
1294 iommu_device_sysfs_remove(&iommu->iommu); in rk_iommu_probe()
1296 iommu_group_put(iommu->group); in rk_iommu_probe()
1298 clk_bulk_unprepare(iommu->num_clocks, iommu->clocks); in rk_iommu_probe()
1304 struct rk_iommu *iommu = platform_get_drvdata(pdev); in rk_iommu_shutdown() local
1307 for (i = 0; i < iommu->num_irq; i++) { in rk_iommu_shutdown()
1310 devm_free_irq(iommu->dev, irq, iommu); in rk_iommu_shutdown()
1318 struct rk_iommu *iommu = dev_get_drvdata(dev); in rk_iommu_suspend() local
1320 if (!iommu->domain) in rk_iommu_suspend()
1323 rk_iommu_disable(iommu); in rk_iommu_suspend()
1329 struct rk_iommu *iommu = dev_get_drvdata(dev); in rk_iommu_resume() local
1331 if (!iommu->domain) in rk_iommu_resume()
1334 return rk_iommu_enable(iommu); in rk_iommu_resume()