Lines Matching refs:sdev

80 	struct sprd_iommu_device	*sdev;  member
91 sprd_iommu_write(struct sprd_iommu_device *sdev, unsigned int reg, u32 val) in sprd_iommu_write() argument
93 writel_relaxed(val, sdev->base + reg); in sprd_iommu_write()
97 sprd_iommu_read(struct sprd_iommu_device *sdev, unsigned int reg) in sprd_iommu_read() argument
99 return readl_relaxed(sdev->base + reg); in sprd_iommu_read()
103 sprd_iommu_update_bits(struct sprd_iommu_device *sdev, unsigned int reg, in sprd_iommu_update_bits() argument
106 u32 t = sprd_iommu_read(sdev, reg); in sprd_iommu_update_bits()
109 sprd_iommu_write(sdev, reg, t); in sprd_iommu_update_bits()
113 sprd_iommu_get_version(struct sprd_iommu_device *sdev) in sprd_iommu_get_version() argument
115 int ver = (sprd_iommu_read(sdev, SPRD_IOMMU_VERSION) & in sprd_iommu_get_version()
163 struct sprd_iommu_device *sdev = dom->sdev; in sprd_iommu_first_vpn() local
167 if (sdev->ver == SPRD_IOMMU_EX) in sprd_iommu_first_vpn()
173 sprd_iommu_write(sdev, reg, val); in sprd_iommu_first_vpn()
178 struct sprd_iommu_device *sdev = dom->sdev; in sprd_iommu_vpn_range() local
182 if (sdev->ver == SPRD_IOMMU_EX) in sprd_iommu_vpn_range()
189 sprd_iommu_write(sdev, reg, val); in sprd_iommu_vpn_range()
195 struct sprd_iommu_device *sdev = dom->sdev; in sprd_iommu_first_ppn() local
198 if (sdev->ver == SPRD_IOMMU_EX) in sprd_iommu_first_ppn()
203 sprd_iommu_write(sdev, reg, val); in sprd_iommu_first_ppn()
206 static void sprd_iommu_default_ppn(struct sprd_iommu_device *sdev) in sprd_iommu_default_ppn() argument
208 u32 val = sdev->prot_page_pa >> SPRD_IOMMU_PAGE_SHIFT; in sprd_iommu_default_ppn()
210 if (sdev->ver == SPRD_IOMMU_EX) { in sprd_iommu_default_ppn()
211 sprd_iommu_write(sdev, SPRD_EX_DEFAULT_PPN, val); in sprd_iommu_default_ppn()
212 } else if (sdev->ver == SPRD_IOMMU_VAU) { in sprd_iommu_default_ppn()
213 sprd_iommu_write(sdev, SPRD_VAU_DEFAULT_PPN_RD, val); in sprd_iommu_default_ppn()
214 sprd_iommu_write(sdev, SPRD_VAU_DEFAULT_PPN_WR, val); in sprd_iommu_default_ppn()
218 static void sprd_iommu_hw_en(struct sprd_iommu_device *sdev, bool en) in sprd_iommu_hw_en() argument
223 if (sdev->ver == SPRD_IOMMU_EX) in sprd_iommu_hw_en()
230 sprd_iommu_update_bits(sdev, reg_cfg, mask, 0, val); in sprd_iommu_hw_en()
236 struct sprd_iommu_device *sdev = dev_iommu_priv_get(dev); in sprd_iommu_attach_device() local
240 if (dom->sdev) { in sprd_iommu_attach_device()
245 dom->pgt_va = dma_alloc_coherent(sdev->dev, pgt_size, &dom->pgt_pa, GFP_KERNEL); in sprd_iommu_attach_device()
249 dom->sdev = sdev; in sprd_iommu_attach_device()
254 sprd_iommu_default_ppn(sdev); in sprd_iommu_attach_device()
255 sprd_iommu_hw_en(sdev, true); in sprd_iommu_attach_device()
264 struct sprd_iommu_device *sdev = dom->sdev; in sprd_iommu_detach_device() local
267 if (!sdev) in sprd_iommu_detach_device()
270 dma_free_coherent(sdev->dev, pgt_size, dom->pgt_va, dom->pgt_pa); in sprd_iommu_detach_device()
271 sprd_iommu_hw_en(sdev, false); in sprd_iommu_detach_device()
272 dom->sdev = NULL; in sprd_iommu_detach_device()
287 if (!dom->sdev) { in sprd_iommu_map()
293 dev_err(dom->sdev->dev, "(iova(0x%lx) + size(%zx)) are not in the range!\n", in sprd_iommu_map()
338 if (dom->sdev->ver == SPRD_IOMMU_EX) in sprd_iommu_sync_map()
344 sprd_iommu_write(dom->sdev, reg, 0xffffffff); in sprd_iommu_sync_map()
376 struct sprd_iommu_device *sdev; in sprd_iommu_probe_device() local
381 sdev = dev_iommu_priv_get(dev); in sprd_iommu_probe_device()
383 return &sdev->iommu; in sprd_iommu_probe_device()
398 struct sprd_iommu_device *sdev = dev_iommu_priv_get(dev); in sprd_iommu_device_group() local
400 return iommu_group_ref_get(sdev->group); in sprd_iommu_device_group()
446 static int sprd_iommu_clk_enable(struct sprd_iommu_device *sdev) in sprd_iommu_clk_enable() argument
450 eb = devm_clk_get_optional(sdev->dev, NULL); in sprd_iommu_clk_enable()
457 sdev->eb = eb; in sprd_iommu_clk_enable()
461 static void sprd_iommu_clk_disable(struct sprd_iommu_device *sdev) in sprd_iommu_clk_disable() argument
463 if (sdev->eb) in sprd_iommu_clk_disable()
464 clk_disable_unprepare(sdev->eb); in sprd_iommu_clk_disable()
469 struct sprd_iommu_device *sdev; in sprd_iommu_probe() local
474 sdev = devm_kzalloc(dev, sizeof(*sdev), GFP_KERNEL); in sprd_iommu_probe()
475 if (!sdev) in sprd_iommu_probe()
483 sdev->base = base; in sprd_iommu_probe()
485 sdev->prot_page_va = dma_alloc_coherent(dev, SPRD_IOMMU_PAGE_SIZE, in sprd_iommu_probe()
486 &sdev->prot_page_pa, GFP_KERNEL); in sprd_iommu_probe()
487 if (!sdev->prot_page_va) in sprd_iommu_probe()
490 platform_set_drvdata(pdev, sdev); in sprd_iommu_probe()
491 sdev->dev = dev; in sprd_iommu_probe()
494 sdev->group = iommu_group_alloc(); in sprd_iommu_probe()
495 if (IS_ERR(sdev->group)) { in sprd_iommu_probe()
496 ret = PTR_ERR(sdev->group); in sprd_iommu_probe()
500 ret = iommu_device_sysfs_add(&sdev->iommu, dev, NULL, dev_name(dev)); in sprd_iommu_probe()
504 ret = iommu_device_register(&sdev->iommu, &sprd_iommu_ops, dev); in sprd_iommu_probe()
511 ret = sprd_iommu_clk_enable(sdev); in sprd_iommu_probe()
515 ret = sprd_iommu_get_version(sdev); in sprd_iommu_probe()
520 sdev->ver = ret; in sprd_iommu_probe()
525 sprd_iommu_clk_disable(sdev); in sprd_iommu_probe()
527 iommu_device_unregister(&sdev->iommu); in sprd_iommu_probe()
529 iommu_device_sysfs_remove(&sdev->iommu); in sprd_iommu_probe()
531 iommu_group_put(sdev->group); in sprd_iommu_probe()
533 dma_free_coherent(sdev->dev, SPRD_IOMMU_PAGE_SIZE, sdev->prot_page_va, sdev->prot_page_pa); in sprd_iommu_probe()
539 struct sprd_iommu_device *sdev = platform_get_drvdata(pdev); in sprd_iommu_remove() local
541 dma_free_coherent(sdev->dev, SPRD_IOMMU_PAGE_SIZE, sdev->prot_page_va, sdev->prot_page_pa); in sprd_iommu_remove()
543 iommu_group_put(sdev->group); in sprd_iommu_remove()
544 sdev->group = NULL; in sprd_iommu_remove()
549 iommu_device_sysfs_remove(&sdev->iommu); in sprd_iommu_remove()
550 iommu_device_unregister(&sdev->iommu); in sprd_iommu_remove()