Lines Matching refs:dart

144 #define DART_TCR(dart, sid) ((dart)->hw->tcr + ((sid) << 2))  argument
146 #define DART_TTBR(dart, sid, idx) ((dart)->hw->ttbr + \ argument
147 (((dart)->hw->ttbr_count * (sid)) << 2) + \
245 struct apple_dart *dart; member
249 struct apple_dart *dart; member
294 i < MAX_DARTS_PER_DEVICE && stream_map->dart; \
308 struct apple_dart *dart = stream_map->dart; in apple_dart_hw_enable_translation() local
311 for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) in apple_dart_hw_enable_translation()
312 writel(dart->hw->tcr_enabled, dart->regs + DART_TCR(dart, sid)); in apple_dart_hw_enable_translation()
317 struct apple_dart *dart = stream_map->dart; in apple_dart_hw_disable_dma() local
320 for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) in apple_dart_hw_disable_dma()
321 writel(dart->hw->tcr_disabled, dart->regs + DART_TCR(dart, sid)); in apple_dart_hw_disable_dma()
327 struct apple_dart *dart = stream_map->dart; in apple_dart_hw_enable_bypass() local
330 WARN_ON(!stream_map->dart->supports_bypass); in apple_dart_hw_enable_bypass()
331 for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) in apple_dart_hw_enable_bypass()
332 writel(dart->hw->tcr_bypass, in apple_dart_hw_enable_bypass()
333 dart->regs + DART_TCR(dart, sid)); in apple_dart_hw_enable_bypass()
339 struct apple_dart *dart = stream_map->dart; in apple_dart_hw_set_ttbr() local
342 WARN_ON(paddr & ((1 << dart->hw->ttbr_shift) - 1)); in apple_dart_hw_set_ttbr()
343 for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) in apple_dart_hw_set_ttbr()
344 writel(dart->hw->ttbr_valid | in apple_dart_hw_set_ttbr()
345 (paddr >> dart->hw->ttbr_shift) << dart->hw->ttbr_addr_field_shift, in apple_dart_hw_set_ttbr()
346 dart->regs + DART_TTBR(dart, sid, idx)); in apple_dart_hw_set_ttbr()
352 struct apple_dart *dart = stream_map->dart; in apple_dart_hw_clear_ttbr() local
355 for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) in apple_dart_hw_clear_ttbr()
356 writel(0, dart->regs + DART_TTBR(dart, sid, idx)); in apple_dart_hw_clear_ttbr()
364 for (i = 0; i < stream_map->dart->hw->ttbr_count; ++i) in apple_dart_hw_clear_all_ttbrs()
376 spin_lock_irqsave(&stream_map->dart->lock, flags); in apple_dart_t8020_hw_stream_command()
378 writel(stream_map->sidmap[0], stream_map->dart->regs + DART_T8020_STREAM_SELECT); in apple_dart_t8020_hw_stream_command()
379 writel(command, stream_map->dart->regs + DART_T8020_STREAM_COMMAND); in apple_dart_t8020_hw_stream_command()
382 stream_map->dart->regs + DART_T8020_STREAM_COMMAND, command_reg, in apple_dart_t8020_hw_stream_command()
386 spin_unlock_irqrestore(&stream_map->dart->lock, flags); in apple_dart_t8020_hw_stream_command()
389 dev_err(stream_map->dart->dev, in apple_dart_t8020_hw_stream_command()
402 struct apple_dart *dart = stream_map->dart; in apple_dart_t8110_hw_tlb_command() local
407 spin_lock_irqsave(&dart->lock, flags); in apple_dart_t8110_hw_tlb_command()
409 for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) { in apple_dart_t8110_hw_tlb_command()
412 writel(val, dart->regs + DART_T8110_TLB_CMD); in apple_dart_t8110_hw_tlb_command()
415 dart->regs + DART_T8110_TLB_CMD, val, in apple_dart_t8110_hw_tlb_command()
424 spin_unlock_irqrestore(&dart->lock, flags); in apple_dart_t8110_hw_tlb_command()
427 dev_err(stream_map->dart->dev, in apple_dart_t8110_hw_tlb_command()
450 static int apple_dart_hw_reset(struct apple_dart *dart) in apple_dart_hw_reset() argument
456 config = readl(dart->regs + dart->hw->lock); in apple_dart_hw_reset()
457 if (config & dart->hw->lock_bit) { in apple_dart_hw_reset()
458 dev_err(dart->dev, "DART is locked down until reboot: %08x\n", in apple_dart_hw_reset()
463 stream_map.dart = dart; in apple_dart_hw_reset()
465 bitmap_set(stream_map.sidmap, 0, dart->num_streams); in apple_dart_hw_reset()
470 for (i = 0; i < BITS_TO_U32(dart->num_streams); i++) in apple_dart_hw_reset()
471 writel(U32_MAX, dart->regs + dart->hw->enable_streams + 4 * i); in apple_dart_hw_reset()
474 writel(readl(dart->regs + dart->hw->error), dart->regs + dart->hw->error); in apple_dart_hw_reset()
476 if (dart->hw->type == DART_T8110) in apple_dart_hw_reset()
477 writel(0, dart->regs + DART_T8110_ERROR_MASK); in apple_dart_hw_reset()
479 return dart->hw->invalidate_tlb(&stream_map); in apple_dart_hw_reset()
489 stream_map.dart = domain_stream_map->dart; in apple_dart_domain_flush_tlb()
491 for (j = 0; j < BITS_TO_LONGS(stream_map.dart->num_streams); j++) in apple_dart_domain_flush_tlb()
494 stream_map.dart->hw->invalidate_tlb(&stream_map); in apple_dart_domain_flush_tlb()
564 for (; i < stream_map->dart->hw->ttbr_count; ++i) in apple_dart_setup_translation()
568 stream_map->dart->hw->invalidate_tlb(stream_map); in apple_dart_setup_translation()
575 struct apple_dart *dart = cfg->stream_maps[0].dart; in apple_dart_finalize_domain() local
586 dart_domain->stream_maps[i].dart = cfg->stream_maps[i].dart; in apple_dart_finalize_domain()
587 for (j = 0; j < BITS_TO_LONGS(dart->num_streams); j++) in apple_dart_finalize_domain()
593 .pgsize_bitmap = dart->pgsize, in apple_dart_finalize_domain()
594 .ias = dart->ias, in apple_dart_finalize_domain()
595 .oas = dart->oas, in apple_dart_finalize_domain()
597 .iommu_dev = dart->dev, in apple_dart_finalize_domain()
601 alloc_io_pgtable_ops(dart->hw->fmt, &pgtbl_cfg, domain); in apple_dart_finalize_domain()
609 domain->geometry.aperture_end = (dma_addr_t)DMA_BIT_MASK(dart->ias); in apple_dart_finalize_domain()
627 if (domain_maps[i].dart != master_maps[i].dart) in apple_dart_mod_streams()
632 if (!domain_maps[i].dart) in apple_dart_mod_streams()
634 for (j = 0; j < BITS_TO_LONGS(domain_maps[i].dart->num_streams); j++) { in apple_dart_mod_streams()
662 if (cfg->stream_maps[0].dart->force_bypass && in apple_dart_attach_dev()
665 if (!cfg->stream_maps[0].dart->supports_bypass && in apple_dart_attach_dev()
707 dev, stream_map->dart->dev, in apple_dart_probe_device()
710 return &cfg->stream_maps[0].dart->iommu; in apple_dart_probe_device()
756 struct apple_dart *dart = platform_get_drvdata(iommu_pdev); in apple_dart_of_xlate() local
770 cfg_dart = cfg->stream_maps[0].dart; in apple_dart_of_xlate()
772 if (cfg_dart->supports_bypass != dart->supports_bypass) in apple_dart_of_xlate()
774 if (cfg_dart->force_bypass != dart->force_bypass) in apple_dart_of_xlate()
776 if (cfg_dart->pgsize != dart->pgsize) in apple_dart_of_xlate()
781 if (cfg->stream_maps[i].dart == dart) { in apple_dart_of_xlate()
787 if (!cfg->stream_maps[i].dart) { in apple_dart_of_xlate()
788 cfg->stream_maps[i].dart = dart; in apple_dart_of_xlate()
808 for_each_set_bit(sid, stream_map->sidmap, stream_map->dart->num_streams) in apple_dart_release_group()
809 stream_map->dart->sid2group[sid] = NULL; in apple_dart_release_group()
824 if (src->stream_maps[1].dart) in apple_dart_merge_master_cfg()
826 if (dst->stream_maps[1].dart) in apple_dart_merge_master_cfg()
828 if (src->stream_maps[0].dart != dst->stream_maps[0].dart) in apple_dart_merge_master_cfg()
834 dst->stream_maps[0].dart->num_streams); in apple_dart_merge_master_cfg()
850 for_each_set_bit(sid, stream_map->sidmap, stream_map->dart->num_streams) { in apple_dart_device_group()
852 stream_map->dart->sid2group[sid]; in apple_dart_device_group()
903 for_each_set_bit(sid, stream_map->sidmap, stream_map->dart->num_streams) in apple_dart_device_group()
904 stream_map->dart->sid2group[sid] = group; in apple_dart_device_group()
917 if (cfg->stream_maps[0].dart->force_bypass) in apple_dart_def_domain_type()
919 if (!cfg->stream_maps[0].dart->supports_bypass) in apple_dart_def_domain_type()
974 struct apple_dart *dart = dev; in apple_dart_t8020_irq() local
976 u32 error = readl(dart->regs + DART_T8020_ERROR); in apple_dart_t8020_irq()
978 u32 addr_lo = readl(dart->regs + DART_T8020_ERROR_ADDR_LO); in apple_dart_t8020_irq()
979 u32 addr_hi = readl(dart->regs + DART_T8020_ERROR_ADDR_HI); in apple_dart_t8020_irq()
1001 dart->dev, in apple_dart_t8020_irq()
1005 writel(error, dart->regs + DART_T8020_ERROR); in apple_dart_t8020_irq()
1011 struct apple_dart *dart = dev; in apple_dart_t8110_irq() local
1013 u32 error = readl(dart->regs + DART_T8110_ERROR); in apple_dart_t8110_irq()
1015 u32 addr_lo = readl(dart->regs + DART_T8110_ERROR_ADDR_LO); in apple_dart_t8110_irq()
1016 u32 addr_hi = readl(dart->regs + DART_T8110_ERROR_ADDR_HI); in apple_dart_t8110_irq()
1040 dart->dev, in apple_dart_t8110_irq()
1044 writel(error, dart->regs + DART_T8110_ERROR); in apple_dart_t8110_irq()
1053 struct apple_dart *dart; in apple_dart_probe() local
1056 dart = devm_kzalloc(dev, sizeof(*dart), GFP_KERNEL); in apple_dart_probe()
1057 if (!dart) in apple_dart_probe()
1060 dart->dev = dev; in apple_dart_probe()
1061 dart->hw = of_device_get_match_data(dev); in apple_dart_probe()
1062 spin_lock_init(&dart->lock); in apple_dart_probe()
1064 dart->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in apple_dart_probe()
1065 if (IS_ERR(dart->regs)) in apple_dart_probe()
1066 return PTR_ERR(dart->regs); in apple_dart_probe()
1073 dart->irq = platform_get_irq(pdev, 0); in apple_dart_probe()
1074 if (dart->irq < 0) in apple_dart_probe()
1077 ret = devm_clk_bulk_get_all(dev, &dart->clks); in apple_dart_probe()
1080 dart->num_clks = ret; in apple_dart_probe()
1082 ret = clk_bulk_prepare_enable(dart->num_clks, dart->clks); in apple_dart_probe()
1086 dart_params[0] = readl(dart->regs + DART_PARAMS1); in apple_dart_probe()
1087 dart_params[1] = readl(dart->regs + DART_PARAMS2); in apple_dart_probe()
1088 dart->pgsize = 1 << FIELD_GET(DART_PARAMS1_PAGE_SHIFT, dart_params[0]); in apple_dart_probe()
1089 dart->supports_bypass = dart_params[1] & DART_PARAMS2_BYPASS_SUPPORT; in apple_dart_probe()
1091 switch (dart->hw->type) { in apple_dart_probe()
1094 dart->ias = 32; in apple_dart_probe()
1095 dart->oas = dart->hw->oas; in apple_dart_probe()
1096 dart->num_streams = dart->hw->max_sid_count; in apple_dart_probe()
1100 dart_params[2] = readl(dart->regs + DART_T8110_PARAMS3); in apple_dart_probe()
1101 dart_params[3] = readl(dart->regs + DART_T8110_PARAMS4); in apple_dart_probe()
1102 dart->ias = FIELD_GET(DART_T8110_PARAMS3_VA_WIDTH, dart_params[2]); in apple_dart_probe()
1103 dart->oas = FIELD_GET(DART_T8110_PARAMS3_PA_WIDTH, dart_params[2]); in apple_dart_probe()
1104 dart->num_streams = FIELD_GET(DART_T8110_PARAMS4_NUM_SIDS, dart_params[3]); in apple_dart_probe()
1108 if (dart->num_streams > DART_MAX_STREAMS) { in apple_dart_probe()
1110 dart->num_streams, DART_MAX_STREAMS); in apple_dart_probe()
1115 dart->force_bypass = dart->pgsize > PAGE_SIZE; in apple_dart_probe()
1117 ret = apple_dart_hw_reset(dart); in apple_dart_probe()
1121 ret = request_irq(dart->irq, dart->hw->irq_handler, IRQF_SHARED, in apple_dart_probe()
1122 "apple-dart fault handler", dart); in apple_dart_probe()
1126 platform_set_drvdata(pdev, dart); in apple_dart_probe()
1128 ret = iommu_device_sysfs_add(&dart->iommu, dev, NULL, "apple-dart.%s", in apple_dart_probe()
1133 ret = iommu_device_register(&dart->iommu, &apple_dart_iommu_ops, dev); in apple_dart_probe()
1140 dart->pgsize, dart->num_streams, dart->supports_bypass, dart->force_bypass); in apple_dart_probe()
1144 iommu_device_sysfs_remove(&dart->iommu); in apple_dart_probe()
1146 free_irq(dart->irq, dart); in apple_dart_probe()
1148 clk_bulk_disable_unprepare(dart->num_clks, dart->clks); in apple_dart_probe()
1155 struct apple_dart *dart = platform_get_drvdata(pdev); in apple_dart_remove() local
1157 apple_dart_hw_reset(dart); in apple_dart_remove()
1158 free_irq(dart->irq, dart); in apple_dart_remove()
1160 iommu_device_unregister(&dart->iommu); in apple_dart_remove()
1161 iommu_device_sysfs_remove(&dart->iommu); in apple_dart_remove()
1163 clk_bulk_disable_unprepare(dart->num_clks, dart->clks); in apple_dart_remove()
1246 struct apple_dart *dart = dev_get_drvdata(dev); in apple_dart_suspend() local
1249 for (sid = 0; sid < dart->num_streams; sid++) { in apple_dart_suspend()
1250 dart->save_tcr[sid] = readl_relaxed(dart->regs + DART_TCR(dart, sid)); in apple_dart_suspend()
1251 for (idx = 0; idx < dart->hw->ttbr_count; idx++) in apple_dart_suspend()
1252 dart->save_ttbr[sid][idx] = in apple_dart_suspend()
1253 readl(dart->regs + DART_TTBR(dart, sid, idx)); in apple_dart_suspend()
1261 struct apple_dart *dart = dev_get_drvdata(dev); in apple_dart_resume() local
1265 ret = apple_dart_hw_reset(dart); in apple_dart_resume()
1271 for (sid = 0; sid < dart->num_streams; sid++) { in apple_dart_resume()
1272 for (idx = 0; idx < dart->hw->ttbr_count; idx++) in apple_dart_resume()
1273 writel(dart->save_ttbr[sid][idx], in apple_dart_resume()
1274 dart->regs + DART_TTBR(dart, sid, idx)); in apple_dart_resume()
1275 writel(dart->save_tcr[sid], dart->regs + DART_TCR(dart, sid)); in apple_dart_resume()