History

platform/x86: ISST: Add IOCTL to Translate Linux logical CPU to PUNIT CPU number

Add processing for IOCTL command ISST_IF_GET_PHY_ID. This converts from the Linux logical CPU to PUNIT CPU numbering scheme.

Srinivas Pandruvada committed 7 years ago

Commit fb5b36a1 parent 8fbfb6f2 files · +102 −0Browse files

Unified · Split

2 files
  1. drivers/platform/x86/intel_speed_select_if/isst_if_common.c +74 −0
  2. include/uapi/linux/isst_if.h +28 −0
drivers/platform/x86/intel_speed_select_if/isst_if_common.c+74−0
@@ -134,16 +134,90 @@ static void isst_if_cpu_info_exit(void) · 133 unmodified lines
134134 kfree(isst_cpu_info);
135135 };
136136
137+static long isst_if_proc_phyid_req(u8 *cmd_ptr, int *write_only, int resume)
138+{
139+ struct isst_if_cpu_map *cpu_map;
140+
141+ cpu_map = (struct isst_if_cpu_map *)cmd_ptr;
142+ if (cpu_map->logical_cpu >= nr_cpu_ids ||
143+ cpu_map->logical_cpu >= num_possible_cpus())
144+ return -EINVAL;
145+
146+ *write_only = 0;
147+ cpu_map->physical_cpu = isst_cpu_info[cpu_map->logical_cpu].punit_cpu_id;
148+
149+ return 0;
150+}
151+
152+static long isst_if_exec_multi_cmd(void __user *argp, struct isst_if_cmd_cb *cb)
153+{
154+ unsigned char __user *ptr;
155+ u32 cmd_count;
156+ u8 *cmd_ptr;
157+ long ret;
158+ int i;
159+
160+ /* Each multi command has u32 command count as the first field */
161+ if (copy_from_user(&cmd_count, argp, sizeof(cmd_count)))
162+ return -EFAULT;
163+
164+ if (!cmd_count || cmd_count > ISST_IF_CMD_LIMIT)
165+ return -EINVAL;
166+
167+ cmd_ptr = kmalloc(cb->cmd_size, GFP_KERNEL);
168+ if (!cmd_ptr)
169+ return -ENOMEM;
170+
171+ /* cb->offset points to start of the command after the command count */
172+ ptr = argp + cb->offset;
173+
174+ for (i = 0; i < cmd_count; ++i) {
175+ int wr_only;
176+
177+ if (signal_pending(current)) {
178+ ret = -EINTR;
179+ break;
180+ }
181+
182+ if (copy_from_user(cmd_ptr, ptr, cb->cmd_size)) {
183+ ret = -EFAULT;
184+ break;
185+ }
186+
187+ ret = cb->cmd_callback(cmd_ptr, &wr_only, 0);
188+ if (ret)
189+ break;
190+
191+ if (!wr_only && copy_to_user(ptr, cmd_ptr, cb->cmd_size)) {
192+ ret = -EFAULT;
193+ break;
194+ }
195+
196+ ptr += cb->cmd_size;
197+ }
198+
199+ kfree(cmd_ptr);
200+
201+ return i ? i : ret;
202+}
203+
137204 static long isst_if_def_ioctl(struct file *file, unsigned int cmd,
138205 unsigned long arg)
139206 {
140207 void __user *argp = (void __user *)arg;
208+ struct isst_if_cmd_cb cmd_cb;
141209 long ret = -ENOTTY;
142210
143211 switch (cmd) {
144212 case ISST_IF_GET_PLATFORM_INFO:
145213 ret = isst_if_get_platform_info(argp);
146214 break;
215+ case ISST_IF_GET_PHY_ID:
216+ cmd_cb.cmd_size = sizeof(struct isst_if_cpu_map);
217+ cmd_cb.offset = offsetof(struct isst_if_cpu_maps, cpu_map);
218+ cmd_cb.cmd_callback = isst_if_proc_phyid_req;
219+ ret = isst_if_exec_multi_cmd(argp, &cmd_cb);
220+ break;
147221 default:
148222 break;
149223 }
include/uapi/linux/isst_if.h+28−0
@@ -36,6 +36,34 @@ struct isst_if_platform_info { · 35 unmodified lines
3636 __u8 mmio_supported;
3737 };
3838
39+/**
40+ * struct isst_if_cpu_map - CPU mapping between logical and physical CPU
41+ * @logical_cpu: Linux logical CPU number
42+ * @physical_cpu: PUNIT CPU number
43+ *
44+ * Used to convert from Linux logical CPU to PUNIT CPU numbering scheme.
45+ * The PUNIT CPU number is different than APIC ID based CPU numbering.
46+ */
47+struct isst_if_cpu_map {
48+ __u32 logical_cpu;
49+ __u32 physical_cpu;
50+};
51+
52+/**
53+ * struct isst_if_cpu_maps - structure for CPU map IOCTL
54+ * @cmd_count: Number of CPU mapping command in cpu_map[]
55+ * @cpu_map[]: Holds one or more CPU map data structure
56+ *
57+ * This structure used with ioctl ISST_IF_GET_PHY_ID to send
58+ * one or more CPU mapping commands. Here IOCTL return value indicates
59+ * number of commands sent or error number if no commands have been sent.
60+ */
61+struct isst_if_cpu_maps {
62+ __u32 cmd_count;
63+ struct isst_if_cpu_map cpu_map[1];
64+};
65+
3966 #define ISST_IF_MAGIC 0xFE
4067 #define ISST_IF_GET_PLATFORM_INFO _IOR(ISST_IF_MAGIC, 0, struct isst_if_platform_info *)
68+#define ISST_IF_GET_PHY_ID _IOWR(ISST_IF_MAGIC, 1, struct isst_if_cpu_map *)
4169 #endif