1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for FPGA Accelerated Function Unit (AFU)
5 * Copyright (C) 2017-2018 Intel Corporation, Inc.
8 * Wu Hao <hao.wu@intel.com>
9 * Xiao Guangrong <guangrong.xiao@linux.intel.com>
10 * Joseph Grecco <joe.grecco@intel.com>
11 * Enno Luebbers <enno.luebbers@intel.com>
12 * Tim Whisonant <tim.whisonant@intel.com>
13 * Ananda Ravuri <ananda.ravuri@intel.com>
14 * Henry Mitchel <henry.mitchel@intel.com>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/uaccess.h>
20 #include <linux/fpga-dfl.h>
25 * __afu_port_enable - enable a port by clear reset
26 * @pdev: port platform device.
28 * Enable Port by clear the port soft reset bit, which is set by default.
29 * The AFU is unable to respond to any MMIO access while in reset.
30 * __afu_port_enable function should only be used after __afu_port_disable
33 * The caller needs to hold lock for protection.
35 void __afu_port_enable(struct platform_device
*pdev
)
37 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
41 WARN_ON(!pdata
->disable_count
);
43 if (--pdata
->disable_count
!= 0)
46 base
= dfl_get_feature_ioaddr_by_id(&pdev
->dev
, PORT_FEATURE_ID_HEADER
);
48 /* Clear port soft reset */
49 v
= readq(base
+ PORT_HDR_CTRL
);
50 v
&= ~PORT_CTRL_SFTRST
;
51 writeq(v
, base
+ PORT_HDR_CTRL
);
54 #define RST_POLL_INVL 10 /* us */
55 #define RST_POLL_TIMEOUT 1000 /* us */
58 * __afu_port_disable - disable a port by hold reset
59 * @pdev: port platform device.
61 * Disable Port by setting the port soft reset bit, it puts the port into reset.
63 * The caller needs to hold lock for protection.
65 int __afu_port_disable(struct platform_device
*pdev
)
67 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
71 if (pdata
->disable_count
++ != 0)
74 base
= dfl_get_feature_ioaddr_by_id(&pdev
->dev
, PORT_FEATURE_ID_HEADER
);
76 /* Set port soft reset */
77 v
= readq(base
+ PORT_HDR_CTRL
);
78 v
|= PORT_CTRL_SFTRST
;
79 writeq(v
, base
+ PORT_HDR_CTRL
);
82 * HW sets ack bit to 1 when all outstanding requests have been drained
83 * on this port and minimum soft reset pulse width has elapsed.
84 * Driver polls port_soft_reset_ack to determine if reset done by HW.
86 if (readq_poll_timeout(base
+ PORT_HDR_CTRL
, v
, v
& PORT_CTRL_SFTRST
,
87 RST_POLL_INVL
, RST_POLL_TIMEOUT
)) {
88 dev_err(&pdev
->dev
, "timeout, fail to reset device\n");
96 * This function resets the FPGA Port and its accelerator (AFU) by function
97 * __port_disable and __port_enable (set port soft reset bit and then clear
98 * it). Userspace can do Port reset at any time, e.g. during DMA or Partial
99 * Reconfiguration. But it should never cause any system level issue, only
100 * functional failure (e.g. DMA or PR operation failure) and be recoverable
103 * Note: the accelerator (AFU) is not accessible when its port is in reset
104 * (disabled). Any attempts on MMIO access to AFU while in reset, will
105 * result errors reported via port error reporting sub feature (if present).
107 static int __port_reset(struct platform_device
*pdev
)
111 ret
= __afu_port_disable(pdev
);
113 __afu_port_enable(pdev
);
118 static int port_reset(struct platform_device
*pdev
)
120 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
123 mutex_lock(&pdata
->lock
);
124 ret
= __port_reset(pdev
);
125 mutex_unlock(&pdata
->lock
);
130 static int port_get_id(struct platform_device
*pdev
)
134 base
= dfl_get_feature_ioaddr_by_id(&pdev
->dev
, PORT_FEATURE_ID_HEADER
);
136 return FIELD_GET(PORT_CAP_PORT_NUM
, readq(base
+ PORT_HDR_CAP
));
140 id_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
142 int id
= port_get_id(to_platform_device(dev
));
144 return scnprintf(buf
, PAGE_SIZE
, "%d\n", id
);
146 static DEVICE_ATTR_RO(id
);
149 ltr_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
151 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(dev
);
155 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_HEADER
);
157 mutex_lock(&pdata
->lock
);
158 v
= readq(base
+ PORT_HDR_CTRL
);
159 mutex_unlock(&pdata
->lock
);
161 return sprintf(buf
, "%x\n", (u8
)FIELD_GET(PORT_CTRL_LATENCY
, v
));
165 ltr_store(struct device
*dev
, struct device_attribute
*attr
,
166 const char *buf
, size_t count
)
168 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(dev
);
173 if (kstrtobool(buf
, <r
))
176 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_HEADER
);
178 mutex_lock(&pdata
->lock
);
179 v
= readq(base
+ PORT_HDR_CTRL
);
180 v
&= ~PORT_CTRL_LATENCY
;
181 v
|= FIELD_PREP(PORT_CTRL_LATENCY
, ltr
? 1 : 0);
182 writeq(v
, base
+ PORT_HDR_CTRL
);
183 mutex_unlock(&pdata
->lock
);
187 static DEVICE_ATTR_RW(ltr
);
190 ap1_event_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
192 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(dev
);
196 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_HEADER
);
198 mutex_lock(&pdata
->lock
);
199 v
= readq(base
+ PORT_HDR_STS
);
200 mutex_unlock(&pdata
->lock
);
202 return sprintf(buf
, "%x\n", (u8
)FIELD_GET(PORT_STS_AP1_EVT
, v
));
206 ap1_event_store(struct device
*dev
, struct device_attribute
*attr
,
207 const char *buf
, size_t count
)
209 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(dev
);
213 if (kstrtobool(buf
, &clear
) || !clear
)
216 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_HEADER
);
218 mutex_lock(&pdata
->lock
);
219 writeq(PORT_STS_AP1_EVT
, base
+ PORT_HDR_STS
);
220 mutex_unlock(&pdata
->lock
);
224 static DEVICE_ATTR_RW(ap1_event
);
227 ap2_event_show(struct device
*dev
, struct device_attribute
*attr
,
230 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(dev
);
234 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_HEADER
);
236 mutex_lock(&pdata
->lock
);
237 v
= readq(base
+ PORT_HDR_STS
);
238 mutex_unlock(&pdata
->lock
);
240 return sprintf(buf
, "%x\n", (u8
)FIELD_GET(PORT_STS_AP2_EVT
, v
));
244 ap2_event_store(struct device
*dev
, struct device_attribute
*attr
,
245 const char *buf
, size_t count
)
247 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(dev
);
251 if (kstrtobool(buf
, &clear
) || !clear
)
254 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_HEADER
);
256 mutex_lock(&pdata
->lock
);
257 writeq(PORT_STS_AP2_EVT
, base
+ PORT_HDR_STS
);
258 mutex_unlock(&pdata
->lock
);
262 static DEVICE_ATTR_RW(ap2_event
);
265 power_state_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
267 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(dev
);
271 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_HEADER
);
273 mutex_lock(&pdata
->lock
);
274 v
= readq(base
+ PORT_HDR_STS
);
275 mutex_unlock(&pdata
->lock
);
277 return sprintf(buf
, "0x%x\n", (u8
)FIELD_GET(PORT_STS_PWR_STATE
, v
));
279 static DEVICE_ATTR_RO(power_state
);
282 userclk_freqcmd_store(struct device
*dev
, struct device_attribute
*attr
,
283 const char *buf
, size_t count
)
285 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(dev
);
286 u64 userclk_freq_cmd
;
289 if (kstrtou64(buf
, 0, &userclk_freq_cmd
))
292 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_HEADER
);
294 mutex_lock(&pdata
->lock
);
295 writeq(userclk_freq_cmd
, base
+ PORT_HDR_USRCLK_CMD0
);
296 mutex_unlock(&pdata
->lock
);
300 static DEVICE_ATTR_WO(userclk_freqcmd
);
303 userclk_freqcntrcmd_store(struct device
*dev
, struct device_attribute
*attr
,
304 const char *buf
, size_t count
)
306 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(dev
);
307 u64 userclk_freqcntr_cmd
;
310 if (kstrtou64(buf
, 0, &userclk_freqcntr_cmd
))
313 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_HEADER
);
315 mutex_lock(&pdata
->lock
);
316 writeq(userclk_freqcntr_cmd
, base
+ PORT_HDR_USRCLK_CMD1
);
317 mutex_unlock(&pdata
->lock
);
321 static DEVICE_ATTR_WO(userclk_freqcntrcmd
);
324 userclk_freqsts_show(struct device
*dev
, struct device_attribute
*attr
,
327 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(dev
);
331 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_HEADER
);
333 mutex_lock(&pdata
->lock
);
334 userclk_freqsts
= readq(base
+ PORT_HDR_USRCLK_STS0
);
335 mutex_unlock(&pdata
->lock
);
337 return sprintf(buf
, "0x%llx\n", (unsigned long long)userclk_freqsts
);
339 static DEVICE_ATTR_RO(userclk_freqsts
);
342 userclk_freqcntrsts_show(struct device
*dev
, struct device_attribute
*attr
,
345 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(dev
);
346 u64 userclk_freqcntrsts
;
349 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_HEADER
);
351 mutex_lock(&pdata
->lock
);
352 userclk_freqcntrsts
= readq(base
+ PORT_HDR_USRCLK_STS1
);
353 mutex_unlock(&pdata
->lock
);
355 return sprintf(buf
, "0x%llx\n",
356 (unsigned long long)userclk_freqcntrsts
);
358 static DEVICE_ATTR_RO(userclk_freqcntrsts
);
360 static struct attribute
*port_hdr_attrs
[] = {
363 &dev_attr_ap1_event
.attr
,
364 &dev_attr_ap2_event
.attr
,
365 &dev_attr_power_state
.attr
,
366 &dev_attr_userclk_freqcmd
.attr
,
367 &dev_attr_userclk_freqcntrcmd
.attr
,
368 &dev_attr_userclk_freqsts
.attr
,
369 &dev_attr_userclk_freqcntrsts
.attr
,
373 static umode_t
port_hdr_attrs_visible(struct kobject
*kobj
,
374 struct attribute
*attr
, int n
)
376 struct device
*dev
= kobj_to_dev(kobj
);
377 umode_t mode
= attr
->mode
;
380 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_HEADER
);
382 if (dfl_feature_revision(base
) > 0) {
384 * userclk sysfs interfaces are only visible in case port
385 * revision is 0, as hardware with revision >0 doesn't
388 if (attr
== &dev_attr_userclk_freqcmd
.attr
||
389 attr
== &dev_attr_userclk_freqcntrcmd
.attr
||
390 attr
== &dev_attr_userclk_freqsts
.attr
||
391 attr
== &dev_attr_userclk_freqcntrsts
.attr
)
398 static const struct attribute_group port_hdr_group
= {
399 .attrs
= port_hdr_attrs
,
400 .is_visible
= port_hdr_attrs_visible
,
403 static int port_hdr_init(struct platform_device
*pdev
,
404 struct dfl_feature
*feature
)
412 port_hdr_ioctl(struct platform_device
*pdev
, struct dfl_feature
*feature
,
413 unsigned int cmd
, unsigned long arg
)
418 case DFL_FPGA_PORT_RESET
:
420 ret
= port_reset(pdev
);
425 dev_dbg(&pdev
->dev
, "%x cmd not handled", cmd
);
432 static const struct dfl_feature_id port_hdr_id_table
[] = {
433 {.id
= PORT_FEATURE_ID_HEADER
,},
437 static const struct dfl_feature_ops port_hdr_ops
= {
438 .init
= port_hdr_init
,
439 .ioctl
= port_hdr_ioctl
,
443 afu_id_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
445 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(dev
);
449 base
= dfl_get_feature_ioaddr_by_id(dev
, PORT_FEATURE_ID_AFU
);
451 mutex_lock(&pdata
->lock
);
452 if (pdata
->disable_count
) {
453 mutex_unlock(&pdata
->lock
);
457 guidl
= readq(base
+ GUID_L
);
458 guidh
= readq(base
+ GUID_H
);
459 mutex_unlock(&pdata
->lock
);
461 return scnprintf(buf
, PAGE_SIZE
, "%016llx%016llx\n", guidh
, guidl
);
463 static DEVICE_ATTR_RO(afu_id
);
465 static struct attribute
*port_afu_attrs
[] = {
466 &dev_attr_afu_id
.attr
,
470 static umode_t
port_afu_attrs_visible(struct kobject
*kobj
,
471 struct attribute
*attr
, int n
)
473 struct device
*dev
= kobj_to_dev(kobj
);
476 * sysfs entries are visible only if related private feature is
479 if (!dfl_get_feature_by_id(dev
, PORT_FEATURE_ID_AFU
))
485 static const struct attribute_group port_afu_group
= {
486 .attrs
= port_afu_attrs
,
487 .is_visible
= port_afu_attrs_visible
,
490 static int port_afu_init(struct platform_device
*pdev
,
491 struct dfl_feature
*feature
)
493 struct resource
*res
= &pdev
->resource
[feature
->resource_index
];
495 return afu_mmio_region_add(dev_get_platdata(&pdev
->dev
),
496 DFL_PORT_REGION_INDEX_AFU
,
497 resource_size(res
), res
->start
,
498 DFL_PORT_REGION_MMAP
| DFL_PORT_REGION_READ
|
499 DFL_PORT_REGION_WRITE
);
502 static const struct dfl_feature_id port_afu_id_table
[] = {
503 {.id
= PORT_FEATURE_ID_AFU
,},
507 static const struct dfl_feature_ops port_afu_ops
= {
508 .init
= port_afu_init
,
511 static int port_stp_init(struct platform_device
*pdev
,
512 struct dfl_feature
*feature
)
514 struct resource
*res
= &pdev
->resource
[feature
->resource_index
];
516 return afu_mmio_region_add(dev_get_platdata(&pdev
->dev
),
517 DFL_PORT_REGION_INDEX_STP
,
518 resource_size(res
), res
->start
,
519 DFL_PORT_REGION_MMAP
| DFL_PORT_REGION_READ
|
520 DFL_PORT_REGION_WRITE
);
523 static const struct dfl_feature_id port_stp_id_table
[] = {
524 {.id
= PORT_FEATURE_ID_STP
,},
528 static const struct dfl_feature_ops port_stp_ops
= {
529 .init
= port_stp_init
,
532 static struct dfl_feature_driver port_feature_drvs
[] = {
534 .id_table
= port_hdr_id_table
,
535 .ops
= &port_hdr_ops
,
538 .id_table
= port_afu_id_table
,
539 .ops
= &port_afu_ops
,
542 .id_table
= port_err_id_table
,
543 .ops
= &port_err_ops
,
546 .id_table
= port_stp_id_table
,
547 .ops
= &port_stp_ops
,
554 static int afu_open(struct inode
*inode
, struct file
*filp
)
556 struct platform_device
*fdev
= dfl_fpga_inode_to_feature_dev(inode
);
557 struct dfl_feature_platform_data
*pdata
;
560 pdata
= dev_get_platdata(&fdev
->dev
);
564 ret
= dfl_feature_dev_use_begin(pdata
);
568 dev_dbg(&fdev
->dev
, "Device File Open\n");
569 filp
->private_data
= fdev
;
574 static int afu_release(struct inode
*inode
, struct file
*filp
)
576 struct platform_device
*pdev
= filp
->private_data
;
577 struct dfl_feature_platform_data
*pdata
;
579 dev_dbg(&pdev
->dev
, "Device File Release\n");
581 pdata
= dev_get_platdata(&pdev
->dev
);
583 mutex_lock(&pdata
->lock
);
585 afu_dma_region_destroy(pdata
);
586 mutex_unlock(&pdata
->lock
);
588 dfl_feature_dev_use_end(pdata
);
593 static long afu_ioctl_check_extension(struct dfl_feature_platform_data
*pdata
,
596 /* No extension support for now */
601 afu_ioctl_get_info(struct dfl_feature_platform_data
*pdata
, void __user
*arg
)
603 struct dfl_fpga_port_info info
;
607 minsz
= offsetofend(struct dfl_fpga_port_info
, num_umsgs
);
609 if (copy_from_user(&info
, arg
, minsz
))
612 if (info
.argsz
< minsz
)
615 mutex_lock(&pdata
->lock
);
616 afu
= dfl_fpga_pdata_get_private(pdata
);
618 info
.num_regions
= afu
->num_regions
;
619 info
.num_umsgs
= afu
->num_umsgs
;
620 mutex_unlock(&pdata
->lock
);
622 if (copy_to_user(arg
, &info
, sizeof(info
)))
628 static long afu_ioctl_get_region_info(struct dfl_feature_platform_data
*pdata
,
631 struct dfl_fpga_port_region_info rinfo
;
632 struct dfl_afu_mmio_region region
;
636 minsz
= offsetofend(struct dfl_fpga_port_region_info
, offset
);
638 if (copy_from_user(&rinfo
, arg
, minsz
))
641 if (rinfo
.argsz
< minsz
|| rinfo
.padding
)
644 ret
= afu_mmio_region_get_by_index(pdata
, rinfo
.index
, ®ion
);
648 rinfo
.flags
= region
.flags
;
649 rinfo
.size
= region
.size
;
650 rinfo
.offset
= region
.offset
;
652 if (copy_to_user(arg
, &rinfo
, sizeof(rinfo
)))
659 afu_ioctl_dma_map(struct dfl_feature_platform_data
*pdata
, void __user
*arg
)
661 struct dfl_fpga_port_dma_map map
;
665 minsz
= offsetofend(struct dfl_fpga_port_dma_map
, iova
);
667 if (copy_from_user(&map
, arg
, minsz
))
670 if (map
.argsz
< minsz
|| map
.flags
)
673 ret
= afu_dma_map_region(pdata
, map
.user_addr
, map
.length
, &map
.iova
);
677 if (copy_to_user(arg
, &map
, sizeof(map
))) {
678 afu_dma_unmap_region(pdata
, map
.iova
);
682 dev_dbg(&pdata
->dev
->dev
, "dma map: ua=%llx, len=%llx, iova=%llx\n",
683 (unsigned long long)map
.user_addr
,
684 (unsigned long long)map
.length
,
685 (unsigned long long)map
.iova
);
691 afu_ioctl_dma_unmap(struct dfl_feature_platform_data
*pdata
, void __user
*arg
)
693 struct dfl_fpga_port_dma_unmap unmap
;
696 minsz
= offsetofend(struct dfl_fpga_port_dma_unmap
, iova
);
698 if (copy_from_user(&unmap
, arg
, minsz
))
701 if (unmap
.argsz
< minsz
|| unmap
.flags
)
704 return afu_dma_unmap_region(pdata
, unmap
.iova
);
707 static long afu_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
709 struct platform_device
*pdev
= filp
->private_data
;
710 struct dfl_feature_platform_data
*pdata
;
711 struct dfl_feature
*f
;
714 dev_dbg(&pdev
->dev
, "%s cmd 0x%x\n", __func__
, cmd
);
716 pdata
= dev_get_platdata(&pdev
->dev
);
719 case DFL_FPGA_GET_API_VERSION
:
720 return DFL_FPGA_API_VERSION
;
721 case DFL_FPGA_CHECK_EXTENSION
:
722 return afu_ioctl_check_extension(pdata
, arg
);
723 case DFL_FPGA_PORT_GET_INFO
:
724 return afu_ioctl_get_info(pdata
, (void __user
*)arg
);
725 case DFL_FPGA_PORT_GET_REGION_INFO
:
726 return afu_ioctl_get_region_info(pdata
, (void __user
*)arg
);
727 case DFL_FPGA_PORT_DMA_MAP
:
728 return afu_ioctl_dma_map(pdata
, (void __user
*)arg
);
729 case DFL_FPGA_PORT_DMA_UNMAP
:
730 return afu_ioctl_dma_unmap(pdata
, (void __user
*)arg
);
733 * Let sub-feature's ioctl function to handle the cmd
734 * Sub-feature's ioctl returns -ENODEV when cmd is not
735 * handled in this sub feature, and returns 0 and other
736 * error code if cmd is handled.
738 dfl_fpga_dev_for_each_feature(pdata
, f
)
739 if (f
->ops
&& f
->ops
->ioctl
) {
740 ret
= f
->ops
->ioctl(pdev
, f
, cmd
, arg
);
749 static int afu_mmap(struct file
*filp
, struct vm_area_struct
*vma
)
751 struct platform_device
*pdev
= filp
->private_data
;
752 struct dfl_feature_platform_data
*pdata
;
753 u64 size
= vma
->vm_end
- vma
->vm_start
;
754 struct dfl_afu_mmio_region region
;
758 if (!(vma
->vm_flags
& VM_SHARED
))
761 pdata
= dev_get_platdata(&pdev
->dev
);
763 offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
764 ret
= afu_mmio_region_get_by_offset(pdata
, offset
, size
, ®ion
);
768 if (!(region
.flags
& DFL_PORT_REGION_MMAP
))
771 if ((vma
->vm_flags
& VM_READ
) && !(region
.flags
& DFL_PORT_REGION_READ
))
774 if ((vma
->vm_flags
& VM_WRITE
) &&
775 !(region
.flags
& DFL_PORT_REGION_WRITE
))
778 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
780 return remap_pfn_range(vma
, vma
->vm_start
,
781 (region
.phys
+ (offset
- region
.offset
)) >> PAGE_SHIFT
,
782 size
, vma
->vm_page_prot
);
785 static const struct file_operations afu_fops
= {
786 .owner
= THIS_MODULE
,
788 .release
= afu_release
,
789 .unlocked_ioctl
= afu_ioctl
,
793 static int afu_dev_init(struct platform_device
*pdev
)
795 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
798 afu
= devm_kzalloc(&pdev
->dev
, sizeof(*afu
), GFP_KERNEL
);
804 mutex_lock(&pdata
->lock
);
805 dfl_fpga_pdata_set_private(pdata
, afu
);
806 afu_mmio_region_init(pdata
);
807 afu_dma_region_init(pdata
);
808 mutex_unlock(&pdata
->lock
);
813 static int afu_dev_destroy(struct platform_device
*pdev
)
815 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
817 mutex_lock(&pdata
->lock
);
818 afu_mmio_region_destroy(pdata
);
819 afu_dma_region_destroy(pdata
);
820 dfl_fpga_pdata_set_private(pdata
, NULL
);
821 mutex_unlock(&pdata
->lock
);
826 static int port_enable_set(struct platform_device
*pdev
, bool enable
)
828 struct dfl_feature_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
831 mutex_lock(&pdata
->lock
);
833 __afu_port_enable(pdev
);
835 ret
= __afu_port_disable(pdev
);
836 mutex_unlock(&pdata
->lock
);
841 static struct dfl_fpga_port_ops afu_port_ops
= {
842 .name
= DFL_FPGA_FEATURE_DEV_PORT
,
843 .owner
= THIS_MODULE
,
844 .get_id
= port_get_id
,
845 .enable_set
= port_enable_set
,
848 static int afu_probe(struct platform_device
*pdev
)
852 dev_dbg(&pdev
->dev
, "%s\n", __func__
);
854 ret
= afu_dev_init(pdev
);
858 ret
= dfl_fpga_dev_feature_init(pdev
, port_feature_drvs
);
862 ret
= dfl_fpga_dev_ops_register(pdev
, &afu_fops
, THIS_MODULE
);
864 dfl_fpga_dev_feature_uinit(pdev
);
871 afu_dev_destroy(pdev
);
876 static int afu_remove(struct platform_device
*pdev
)
878 dev_dbg(&pdev
->dev
, "%s\n", __func__
);
880 dfl_fpga_dev_ops_unregister(pdev
);
881 dfl_fpga_dev_feature_uinit(pdev
);
882 afu_dev_destroy(pdev
);
887 static const struct attribute_group
*afu_dev_groups
[] = {
894 static struct platform_driver afu_driver
= {
896 .name
= DFL_FPGA_FEATURE_DEV_PORT
,
897 .dev_groups
= afu_dev_groups
,
900 .remove
= afu_remove
,
903 static int __init
afu_init(void)
907 dfl_fpga_port_ops_add(&afu_port_ops
);
909 ret
= platform_driver_register(&afu_driver
);
911 dfl_fpga_port_ops_del(&afu_port_ops
);
916 static void __exit
afu_exit(void)
918 platform_driver_unregister(&afu_driver
);
920 dfl_fpga_port_ops_del(&afu_port_ops
);
923 module_init(afu_init
);
924 module_exit(afu_exit
);
926 MODULE_DESCRIPTION("FPGA Accelerated Function Unit driver");
927 MODULE_AUTHOR("Intel Corporation");
928 MODULE_LICENSE("GPL v2");
929 MODULE_ALIAS("platform:dfl-port");