2 * Copyright (C) 2017 Broadcom
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
8 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
9 * kind, whether express or implied; without even the implied warranty
10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
15 * This driver provides reset support for Broadcom FlexRM ring manager
19 #include <linux/delay.h>
20 #include <linux/device.h>
21 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
26 #include "../vfio_platform_private.h"
28 /* FlexRM configuration */
29 #define RING_REGS_SIZE 0x10000
30 #define RING_VER_MAGIC 0x76303031
32 /* Per-Ring register offsets */
33 #define RING_VER 0x000
34 #define RING_CONTROL 0x034
35 #define RING_FLUSH_DONE 0x038
37 /* Register RING_CONTROL fields */
38 #define CONTROL_FLUSH_SHIFT 5
40 /* Register RING_FLUSH_DONE fields */
41 #define FLUSH_DONE_MASK 0x1
43 static int vfio_platform_bcmflexrm_shutdown(void __iomem
*ring
)
47 /* Disable/inactivate ring */
48 writel_relaxed(0x0, ring
+ RING_CONTROL
);
50 /* Set ring flush state */
51 timeout
= 1000; /* timeout of 1s */
52 writel_relaxed(BIT(CONTROL_FLUSH_SHIFT
), ring
+ RING_CONTROL
);
54 if (readl_relaxed(ring
+ RING_FLUSH_DONE
) &
62 /* Clear ring flush state */
63 timeout
= 1000; /* timeout of 1s */
64 writel_relaxed(0x0, ring
+ RING_CONTROL
);
66 if (!(readl_relaxed(ring
+ RING_FLUSH_DONE
) &
77 static int vfio_platform_bcmflexrm_reset(struct vfio_platform_device
*vdev
)
80 int rc
= 0, ret
= 0, ring_num
= 0;
81 struct vfio_platform_region
*reg
= &vdev
->regions
[0];
83 /* Map FlexRM ring registers if not mapped */
85 reg
->ioaddr
= ioremap(reg
->addr
, reg
->size
);
90 /* Discover and shutdown each FlexRM ring */
91 for (ring
= reg
->ioaddr
;
92 ring
< (reg
->ioaddr
+ reg
->size
); ring
+= RING_REGS_SIZE
) {
93 if (readl_relaxed(ring
+ RING_VER
) == RING_VER_MAGIC
) {
94 rc
= vfio_platform_bcmflexrm_shutdown(ring
);
96 dev_warn(vdev
->device
,
97 "FlexRM ring%d shutdown error %d\n",
108 module_vfio_reset_handler("brcm,iproc-flexrm-mbox",
109 vfio_platform_bcmflexrm_reset
);
111 MODULE_LICENSE("GPL v2");
112 MODULE_AUTHOR("Anup Patel <anup.patel@broadcom.com>");
113 MODULE_DESCRIPTION("Reset support for Broadcom FlexRM VFIO platform device");