@@ -531,6 +531,96 @@ static int ioc_bw_assign(struct file *filp, void __user *argp)
return ret;
}
+static int is_bw_unassignable(struct bb_info *bb_info, int cpu)
+{
+ u8 ppe;
+
+ if (!cpumask_test_and_clear_cpu(cpu, bb_info->assigned_pemask)) {
+ pr_err("This pe is not assigned: %u/%u/%d\n", bb_info->cmg, bb_info->bb, cpu);
+ return -EINVAL;
+ }
+
+ ppe = _hwinfo.core_map[cpu].ppe;
+ if (!test_bit(bb_info->bw[ppe], &_hwinfo.used_bw_bmap[cpu])) {
+ /* should not happen */
+ pr_crit("Logic error. This window is not assigned: %u/%u/%d\n",
+ bb_info->cmg, bb_info->bb, cpu);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void teardown_ctl_reg(struct bb_info *bb_info, int cpu)
+{
+ if (_hwinfo.used_bw_bmap[cpu] != 0)
+ /* Other window on this PE is still in use. Nothing todo */
+ return;
+
+ /*
+ * This is the last unassign on this PE.
+ * Clear all bits to disallow access to BST_SYNC/LBSY_SYNC from EL0
+ */
+ write_sysreg_s(0, FHWB_CTRL_EL1);
+
+ pr_debug("Teardown ctl reg. cpu: %d\n", cpu);
+}
+
+static void teardown_bw(struct bb_info *bb_info, int cpu)
+{
+ u8 window;
+ u8 ppe;
+
+ /* Just clear all bits */
+ ppe = _hwinfo.core_map[cpu].ppe;
+ window = bb_info->bw[ppe];
+ write_bw_reg(window, 0);
+
+ /* Update bitmap info */
+ clear_bit(window, &_hwinfo.used_bw_bmap[cpu]);
+ bb_info->bw[ppe] = -1;
+
+ pr_debug("Teardown bw. cpu: %d, window: %u, BB: %u, bw_bmap: %lx, assigned_pemask: %*pbl\n",
+ cpu, window, bb_info->bb,
+ _hwinfo.used_bw_bmap[cpu], cpumask_pr_args(bb_info->assigned_pemask));
+}
+
+static int ioc_bw_unassign(struct file *filp, void __user *argp)
+{
+ struct hwb_private_data *pdata = (struct hwb_private_data *)filp->private_data;
+ struct fujitsu_hwb_ioc_bw_ctl bw_ctl;
+ struct bb_info *bb_info;
+ int cpu;
+ int ret;
+ u8 cmg;
+
+ if (!is_bound_only_one_pe())
+ return -EPERM;
+
+ if (copy_from_user(&bw_ctl, (struct fujitsu_hwb_ioc_bw_ctl __user *)argp,
+ sizeof(struct fujitsu_hwb_ioc_bw_ctl)))
+ return -EFAULT;
+
+ cpu = smp_processor_id();
+ cmg = _hwinfo.core_map[cpu].cmg;
+ bb_info = get_bb_info(pdata, cmg, bw_ctl.bb);
+ if (IS_ERR(bb_info))
+ return PTR_ERR(bb_info);
+
+ /* See comments in ioc_bw_assign() */
+ preempt_disable();
+ ret = is_bw_unassignable(bb_info, cpu);
+ if (!ret) {
+ teardown_bw(bb_info, cpu);
+ teardown_ctl_reg(bb_info, cpu);
+ }
+ preempt_enable();
+
+ put_bb_info(bb_info);
+
+ return ret;
+}
+
static long fujitsu_hwb_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
void __user *argp = (void __user *)arg;
@@ -543,6 +633,9 @@ static long fujitsu_hwb_dev_ioctl(struct file *filp, unsigned int cmd, unsigned
case FUJITSU_HWB_IOC_BW_ASSIGN:
ret = ioc_bw_assign(filp, argp);
break;
+ case FUJITSU_HWB_IOC_BW_UNASSIGN:
+ ret = ioc_bw_unassign(filp, argp);
+ break;
default:
ret = -ENOTTY;
break;
@@ -26,5 +26,7 @@ struct fujitsu_hwb_ioc_bw_ctl {
0x00, struct fujitsu_hwb_ioc_bb_ctl)
#define FUJITSU_HWB_IOC_BW_ASSIGN _IOWR(__FUJITSU_IOCTL_MAGIC, \
0x01, struct fujitsu_hwb_ioc_bw_ctl)
+#define FUJITSU_HWB_IOC_BW_UNASSIGN _IOW(__FUJITSU_IOCTL_MAGIC, \
+ 0x02, struct fujitsu_hwb_ioc_bw_ctl)
#endif /* _UAPI_LINUX_FUJITSU_HPC_IOC_H */
IOC_BW_UNASSIGN resets what IOC_BW_ASSIGN did on each PE. This ioctl will also be called as many times as the number of PEs joining synchronization. Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com> --- drivers/soc/fujitsu/fujitsu_hwb.c | 93 ++++++++++++++++++++++++++ include/uapi/linux/fujitsu_hpc_ioctl.h | 2 + 2 files changed, 95 insertions(+)