Lines Matching +full:enable +full:- +full:soft +full:- +full:reset

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2017-2018 Intel Corporation, Inc.
20 #include <linux/fpga-dfl.h>
22 #include "dfl-afu.h"
28 * __afu_port_enable - enable a port by clear reset
31 * Enable Port by clear the port soft reset bit, which is set by default.
32 * The AFU is unable to respond to any MMIO access while in reset.
40 struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev); in __afu_port_enable()
44 WARN_ON(!pdata->disable_count); in __afu_port_enable()
46 if (--pdata->disable_count != 0) in __afu_port_enable()
49 base = dfl_get_feature_ioaddr_by_id(&pdev->dev, PORT_FEATURE_ID_HEADER); in __afu_port_enable()
51 /* Clear port soft reset */ in __afu_port_enable()
58 * of reset. in __afu_port_enable()
63 dev_err(&pdev->dev, "timeout, failure to enable device\n"); in __afu_port_enable()
64 return -ETIMEDOUT; in __afu_port_enable()
71 * __afu_port_disable - disable a port by hold reset
74 * Disable Port by setting the port soft reset bit, it puts the port into reset.
80 struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev); in __afu_port_disable()
84 if (pdata->disable_count++ != 0) in __afu_port_disable()
87 base = dfl_get_feature_ioaddr_by_id(&pdev->dev, PORT_FEATURE_ID_HEADER); in __afu_port_disable()
89 /* Set port soft reset */ in __afu_port_disable()
96 * on this port and minimum soft reset pulse width has elapsed. in __afu_port_disable()
97 * Driver polls port_soft_reset_ack to determine if reset done by HW. in __afu_port_disable()
102 dev_err(&pdev->dev, "timeout, failure to disable device\n"); in __afu_port_disable()
103 return -ETIMEDOUT; in __afu_port_disable()
111 * __port_disable and __port_enable (set port soft reset bit and then clear
112 * it). Userspace can do Port reset at any time, e.g. during DMA or Partial
117 * Note: the accelerator (AFU) is not accessible when its port is in reset
118 * (disabled). Any attempts on MMIO access to AFU while in reset, will
134 struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev); in port_reset()
137 mutex_lock(&pdata->lock); in port_reset()
139 mutex_unlock(&pdata->lock); in port_reset()
148 base = dfl_get_feature_ioaddr_by_id(&pdev->dev, PORT_FEATURE_ID_HEADER); in port_get_id()
171 mutex_lock(&pdata->lock); in ltr_show()
173 mutex_unlock(&pdata->lock); in ltr_show()
188 return -EINVAL; in ltr_store()
192 mutex_lock(&pdata->lock); in ltr_store()
197 mutex_unlock(&pdata->lock); in ltr_store()
212 mutex_lock(&pdata->lock); in ap1_event_show()
214 mutex_unlock(&pdata->lock); in ap1_event_show()
228 return -EINVAL; in ap1_event_store()
232 mutex_lock(&pdata->lock); in ap1_event_store()
234 mutex_unlock(&pdata->lock); in ap1_event_store()
250 mutex_lock(&pdata->lock); in ap2_event_show()
252 mutex_unlock(&pdata->lock); in ap2_event_show()
266 return -EINVAL; in ap2_event_store()
270 mutex_lock(&pdata->lock); in ap2_event_store()
272 mutex_unlock(&pdata->lock); in ap2_event_store()
287 mutex_lock(&pdata->lock); in power_state_show()
289 mutex_unlock(&pdata->lock); in power_state_show()
304 return -EINVAL; in userclk_freqcmd_store()
308 mutex_lock(&pdata->lock); in userclk_freqcmd_store()
310 mutex_unlock(&pdata->lock); in userclk_freqcmd_store()
325 return -EINVAL; in userclk_freqcntrcmd_store()
329 mutex_lock(&pdata->lock); in userclk_freqcntrcmd_store()
331 mutex_unlock(&pdata->lock); in userclk_freqcntrcmd_store()
347 mutex_lock(&pdata->lock); in userclk_freqsts_show()
349 mutex_unlock(&pdata->lock); in userclk_freqsts_show()
365 mutex_lock(&pdata->lock); in userclk_freqcntrsts_show()
367 mutex_unlock(&pdata->lock); in userclk_freqcntrsts_show()
391 umode_t mode = attr->mode; in port_hdr_attrs_visible()
436 ret = -EINVAL; in port_hdr_ioctl()
439 dev_dbg(&pdev->dev, "%x cmd not handled", cmd); in port_hdr_ioctl()
440 ret = -ENODEV; in port_hdr_ioctl()
465 mutex_lock(&pdata->lock); in afu_id_show()
466 if (pdata->disable_count) { in afu_id_show()
467 mutex_unlock(&pdata->lock); in afu_id_show()
468 return -EBUSY; in afu_id_show()
473 mutex_unlock(&pdata->lock); in afu_id_show()
496 return attr->mode; in port_afu_attrs_visible()
507 struct resource *res = &pdev->resource[feature->resource_index]; in port_afu_init()
509 return afu_mmio_region_add(dev_get_platdata(&pdev->dev), in port_afu_init()
511 resource_size(res), res->start, in port_afu_init()
528 struct resource *res = &pdev->resource[feature->resource_index]; in port_stp_init()
530 return afu_mmio_region_add(dev_get_platdata(&pdev->dev), in port_stp_init()
532 resource_size(res), res->start, in port_stp_init()
556 dev_dbg(&pdev->dev, "%x cmd not handled", cmd); in port_uint_ioctl()
557 return -ENODEV; in port_uint_ioctl()
602 pdata = dev_get_platdata(&fdev->dev); in afu_open()
604 return -ENODEV; in afu_open()
606 mutex_lock(&pdata->lock); in afu_open()
607 ret = dfl_feature_dev_use_begin(pdata, filp->f_flags & O_EXCL); in afu_open()
609 dev_dbg(&fdev->dev, "Device File Opened %d Times\n", in afu_open()
611 filp->private_data = fdev; in afu_open()
613 mutex_unlock(&pdata->lock); in afu_open()
620 struct platform_device *pdev = filp->private_data; in afu_release()
624 dev_dbg(&pdev->dev, "Device File Release\n"); in afu_release()
626 pdata = dev_get_platdata(&pdev->dev); in afu_release()
628 mutex_lock(&pdata->lock); in afu_release()
634 feature->nr_irqs, NULL); in afu_release()
638 mutex_unlock(&pdata->lock); in afu_release()
660 return -EFAULT; in afu_ioctl_get_info()
663 return -EINVAL; in afu_ioctl_get_info()
665 mutex_lock(&pdata->lock); in afu_ioctl_get_info()
668 info.num_regions = afu->num_regions; in afu_ioctl_get_info()
669 info.num_umsgs = afu->num_umsgs; in afu_ioctl_get_info()
670 mutex_unlock(&pdata->lock); in afu_ioctl_get_info()
673 return -EFAULT; in afu_ioctl_get_info()
689 return -EFAULT; in afu_ioctl_get_region_info()
692 return -EINVAL; in afu_ioctl_get_region_info()
703 return -EFAULT; in afu_ioctl_get_region_info()
718 return -EFAULT; in afu_ioctl_dma_map()
721 return -EINVAL; in afu_ioctl_dma_map()
729 return -EFAULT; in afu_ioctl_dma_map()
732 dev_dbg(&pdata->dev->dev, "dma map: ua=%llx, len=%llx, iova=%llx\n", in afu_ioctl_dma_map()
749 return -EFAULT; in afu_ioctl_dma_unmap()
752 return -EINVAL; in afu_ioctl_dma_unmap()
759 struct platform_device *pdev = filp->private_data; in afu_ioctl()
764 dev_dbg(&pdev->dev, "%s cmd 0x%x\n", __func__, cmd); in afu_ioctl()
766 pdata = dev_get_platdata(&pdev->dev); in afu_ioctl()
783 * Let sub-feature's ioctl function to handle the cmd in afu_ioctl()
784 * Sub-feature's ioctl returns -ENODEV when cmd is not in afu_ioctl()
789 if (f->ops && f->ops->ioctl) { in afu_ioctl()
790 ret = f->ops->ioctl(pdev, f, cmd, arg); in afu_ioctl()
791 if (ret != -ENODEV) in afu_ioctl()
796 return -EINVAL; in afu_ioctl()
807 struct platform_device *pdev = filp->private_data; in afu_mmap()
809 u64 size = vma->vm_end - vma->vm_start; in afu_mmap()
814 if (!(vma->vm_flags & VM_SHARED)) in afu_mmap()
815 return -EINVAL; in afu_mmap()
817 pdata = dev_get_platdata(&pdev->dev); in afu_mmap()
819 offset = vma->vm_pgoff << PAGE_SHIFT; in afu_mmap()
825 return -EINVAL; in afu_mmap()
827 if ((vma->vm_flags & VM_READ) && !(region.flags & DFL_PORT_REGION_READ)) in afu_mmap()
828 return -EPERM; in afu_mmap()
830 if ((vma->vm_flags & VM_WRITE) && in afu_mmap()
832 return -EPERM; in afu_mmap()
835 vma->vm_ops = &afu_vma_ops; in afu_mmap()
837 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); in afu_mmap()
839 return remap_pfn_range(vma, vma->vm_start, in afu_mmap()
840 (region.phys + (offset - region.offset)) >> PAGE_SHIFT, in afu_mmap()
841 size, vma->vm_page_prot); in afu_mmap()
854 struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev); in afu_dev_init()
857 afu = devm_kzalloc(&pdev->dev, sizeof(*afu), GFP_KERNEL); in afu_dev_init()
859 return -ENOMEM; in afu_dev_init()
861 mutex_lock(&pdata->lock); in afu_dev_init()
865 mutex_unlock(&pdata->lock); in afu_dev_init()
872 struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev); in afu_dev_destroy()
874 mutex_lock(&pdata->lock); in afu_dev_destroy()
878 mutex_unlock(&pdata->lock); in afu_dev_destroy()
883 static int port_enable_set(struct platform_device *pdev, bool enable) in port_enable_set() argument
885 struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev); in port_enable_set()
888 mutex_lock(&pdata->lock); in port_enable_set()
889 if (enable) in port_enable_set()
893 mutex_unlock(&pdata->lock); in port_enable_set()
909 dev_dbg(&pdev->dev, "%s\n", __func__); in afu_probe()
935 dev_dbg(&pdev->dev, "%s\n", __func__); in afu_remove()
984 MODULE_ALIAS("platform:dfl-port");