0004-ipts.patch 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606
  1. From 8f4c7d7e1c3614f7dbc5ee8aba92e88000fd4aad Mon Sep 17 00:00:00 2001
  2. From: Dorian Stoll <dorian.stoll@tmsp.io>
  3. Date: Thu, 30 Jul 2020 13:21:53 +0200
  4. Subject: [PATCH] misc: mei: Add missing IPTS device IDs
  5. Patchset: ipts
  6. ---
  7. drivers/misc/mei/hw-me-regs.h | 1 +
  8. drivers/misc/mei/pci-me.c | 1 +
  9. 2 files changed, 2 insertions(+)
  10. diff --git a/drivers/misc/mei/hw-me-regs.h b/drivers/misc/mei/hw-me-regs.h
  11. index 15e8e2b322b1..91587b808323 100644
  12. --- a/drivers/misc/mei/hw-me-regs.h
  13. +++ b/drivers/misc/mei/hw-me-regs.h
  14. @@ -92,6 +92,7 @@
  15. #define MEI_DEV_ID_CDF 0x18D3 /* Cedar Fork */
  16. #define MEI_DEV_ID_ICP_LP 0x34E0 /* Ice Lake Point LP */
  17. +#define MEI_DEV_ID_ICP_LP_3 0x34E4 /* Ice Lake Point LP 3 (iTouch) */
  18. #define MEI_DEV_ID_ICP_N 0x38E0 /* Ice Lake Point N */
  19. #define MEI_DEV_ID_JSP_N 0x4DE0 /* Jasper Lake Point N */
  20. diff --git a/drivers/misc/mei/pci-me.c b/drivers/misc/mei/pci-me.c
  21. index 5435604327a7..1165ee4f5928 100644
  22. --- a/drivers/misc/mei/pci-me.c
  23. +++ b/drivers/misc/mei/pci-me.c
  24. @@ -97,6 +97,7 @@ static const struct pci_device_id mei_me_pci_tbl[] = {
  25. {MEI_PCI_DEVICE(MEI_DEV_ID_CMP_H_3, MEI_ME_PCH8_ITOUCH_CFG)},
  26. {MEI_PCI_DEVICE(MEI_DEV_ID_ICP_LP, MEI_ME_PCH12_CFG)},
  27. + {MEI_PCI_DEVICE(MEI_DEV_ID_ICP_LP_3, MEI_ME_PCH12_CFG)},
  28. {MEI_PCI_DEVICE(MEI_DEV_ID_ICP_N, MEI_ME_PCH12_CFG)},
  29. {MEI_PCI_DEVICE(MEI_DEV_ID_TGP_LP, MEI_ME_PCH15_CFG)},
  30. --
  31. 2.38.1
  32. From 3abd40f113583709382d83f8f0a1f73c8acfd4e5 Mon Sep 17 00:00:00 2001
  33. From: Dorian Stoll <dorian.stoll@tmsp.io>
  34. Date: Thu, 6 Aug 2020 11:20:41 +0200
  35. Subject: [PATCH] misc: Add support for Intel Precise Touch & Stylus
  36. Based on linux-surface/intel-precise-touch@3f362c
  37. Signed-off-by: Dorian Stoll <dorian.stoll@tmsp.io>
  38. Patchset: ipts
  39. ---
  40. drivers/misc/Kconfig | 1 +
  41. drivers/misc/Makefile | 3 +-
  42. drivers/misc/ipts/Kconfig | 17 ++
  43. drivers/misc/ipts/Makefile | 12 ++
  44. drivers/misc/ipts/context.h | 47 +++++
  45. drivers/misc/ipts/control.c | 113 +++++++++++
  46. drivers/misc/ipts/control.h | 24 +++
  47. drivers/misc/ipts/mei.c | 125 ++++++++++++
  48. drivers/misc/ipts/protocol.h | 347 ++++++++++++++++++++++++++++++++++
  49. drivers/misc/ipts/receiver.c | 224 ++++++++++++++++++++++
  50. drivers/misc/ipts/receiver.h | 16 ++
  51. drivers/misc/ipts/resources.c | 128 +++++++++++++
  52. drivers/misc/ipts/resources.h | 17 ++
  53. drivers/misc/ipts/uapi.c | 208 ++++++++++++++++++++
  54. drivers/misc/ipts/uapi.h | 47 +++++
  55. 15 files changed, 1328 insertions(+), 1 deletion(-)
  56. create mode 100644 drivers/misc/ipts/Kconfig
  57. create mode 100644 drivers/misc/ipts/Makefile
  58. create mode 100644 drivers/misc/ipts/context.h
  59. create mode 100644 drivers/misc/ipts/control.c
  60. create mode 100644 drivers/misc/ipts/control.h
  61. create mode 100644 drivers/misc/ipts/mei.c
  62. create mode 100644 drivers/misc/ipts/protocol.h
  63. create mode 100644 drivers/misc/ipts/receiver.c
  64. create mode 100644 drivers/misc/ipts/receiver.h
  65. create mode 100644 drivers/misc/ipts/resources.c
  66. create mode 100644 drivers/misc/ipts/resources.h
  67. create mode 100644 drivers/misc/ipts/uapi.c
  68. create mode 100644 drivers/misc/ipts/uapi.h
  69. diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
  70. index 94e9fb4cdd76..12230c71fcf3 100644
  71. --- a/drivers/misc/Kconfig
  72. +++ b/drivers/misc/Kconfig
  73. @@ -513,4 +513,5 @@ source "drivers/misc/cardreader/Kconfig"
  74. source "drivers/misc/habanalabs/Kconfig"
  75. source "drivers/misc/uacce/Kconfig"
  76. source "drivers/misc/pvpanic/Kconfig"
  77. +source "drivers/misc/ipts/Kconfig"
  78. endmenu
  79. diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
  80. index 2be8542616dd..9e1a97b8c57e 100644
  81. --- a/drivers/misc/Makefile
  82. +++ b/drivers/misc/Makefile
  83. @@ -60,4 +60,5 @@ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o
  84. obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o
  85. obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o
  86. obj-$(CONFIG_OPEN_DICE) += open-dice.o
  87. -obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o
  88. \ No newline at end of file
  89. +obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o
  90. +obj-$(CONFIG_MISC_IPTS) += ipts/
  91. diff --git a/drivers/misc/ipts/Kconfig b/drivers/misc/ipts/Kconfig
  92. new file mode 100644
  93. index 000000000000..83e2a930c396
  94. --- /dev/null
  95. +++ b/drivers/misc/ipts/Kconfig
  96. @@ -0,0 +1,17 @@
  97. +# SPDX-License-Identifier: GPL-2.0-or-later
  98. +
  99. +config MISC_IPTS
  100. + tristate "Intel Precise Touch & Stylus"
  101. + depends on INTEL_MEI
  102. + help
  103. + Say Y here if your system has a touchscreen using Intels
  104. + Precise Touch & Stylus (IPTS) technology.
  105. +
  106. + If unsure say N.
  107. +
  108. + To compile this driver as a module, choose M here: the
  109. + module will be called ipts.
  110. +
  111. + Building this driver alone will not give you a working touchscreen.
  112. + It only exposed a userspace API that can be used by a daemon to
  113. + receive and process data from the touchscreen hardware.
  114. diff --git a/drivers/misc/ipts/Makefile b/drivers/misc/ipts/Makefile
  115. new file mode 100644
  116. index 000000000000..8f58b9adbc94
  117. --- /dev/null
  118. +++ b/drivers/misc/ipts/Makefile
  119. @@ -0,0 +1,12 @@
  120. +# SPDX-License-Identifier: GPL-2.0-or-later
  121. +#
  122. +# Makefile for the IPTS touchscreen driver
  123. +#
  124. +
  125. +obj-$(CONFIG_MISC_IPTS) += ipts.o
  126. +ipts-objs := control.o
  127. +ipts-objs += mei.o
  128. +ipts-objs += receiver.o
  129. +ipts-objs += resources.o
  130. +ipts-objs += uapi.o
  131. +
  132. diff --git a/drivers/misc/ipts/context.h b/drivers/misc/ipts/context.h
  133. new file mode 100644
  134. index 000000000000..f4b06a2d3f72
  135. --- /dev/null
  136. +++ b/drivers/misc/ipts/context.h
  137. @@ -0,0 +1,47 @@
  138. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  139. +/*
  140. + * Copyright (c) 2016 Intel Corporation
  141. + * Copyright (c) 2020 Dorian Stoll
  142. + *
  143. + * Linux driver for Intel Precise Touch & Stylus
  144. + */
  145. +
  146. +#ifndef _IPTS_CONTEXT_H_
  147. +#define _IPTS_CONTEXT_H_
  148. +
  149. +#include <linux/cdev.h>
  150. +#include <linux/device.h>
  151. +#include <linux/mei_cl_bus.h>
  152. +#include <linux/types.h>
  153. +
  154. +#include "protocol.h"
  155. +
  156. +enum ipts_host_status {
  157. + IPTS_HOST_STATUS_STARTING,
  158. + IPTS_HOST_STATUS_STARTED,
  159. + IPTS_HOST_STATUS_STOPPING,
  160. + IPTS_HOST_STATUS_STOPPED,
  161. +};
  162. +
  163. +struct ipts_buffer_info {
  164. + u8 *address;
  165. + dma_addr_t dma_address;
  166. +};
  167. +
  168. +struct ipts_context {
  169. + struct mei_cl_device *cldev;
  170. + struct device *dev;
  171. +
  172. + bool restart;
  173. + enum ipts_host_status status;
  174. + struct ipts_get_device_info_rsp device_info;
  175. +
  176. + struct ipts_buffer_info data[IPTS_BUFFERS];
  177. + struct ipts_buffer_info doorbell;
  178. +
  179. + struct ipts_buffer_info feedback[IPTS_BUFFERS];
  180. + struct ipts_buffer_info workqueue;
  181. + struct ipts_buffer_info host2me;
  182. +};
  183. +
  184. +#endif /* _IPTS_CONTEXT_H_ */
  185. diff --git a/drivers/misc/ipts/control.c b/drivers/misc/ipts/control.c
  186. new file mode 100644
  187. index 000000000000..a1d1f97a13d7
  188. --- /dev/null
  189. +++ b/drivers/misc/ipts/control.c
  190. @@ -0,0 +1,113 @@
  191. +// SPDX-License-Identifier: GPL-2.0-or-later
  192. +/*
  193. + * Copyright (c) 2016 Intel Corporation
  194. + * Copyright (c) 2020 Dorian Stoll
  195. + *
  196. + * Linux driver for Intel Precise Touch & Stylus
  197. + */
  198. +
  199. +#include <linux/mei_cl_bus.h>
  200. +
  201. +#include "context.h"
  202. +#include "protocol.h"
  203. +#include "resources.h"
  204. +#include "uapi.h"
  205. +
  206. +int ipts_control_send(struct ipts_context *ipts, u32 code, void *payload,
  207. + size_t size)
  208. +{
  209. + int ret;
  210. + struct ipts_command cmd;
  211. +
  212. + memset(&cmd, 0, sizeof(struct ipts_command));
  213. + cmd.code = code;
  214. +
  215. + if (payload && size > 0)
  216. + memcpy(&cmd.payload, payload, size);
  217. +
  218. + ret = mei_cldev_send(ipts->cldev, (u8 *)&cmd, sizeof(cmd.code) + size);
  219. + if (ret >= 0)
  220. + return 0;
  221. +
  222. + /*
  223. + * During shutdown the device might get pulled away from below our feet.
  224. + * Dont log an error in this case, because it will confuse people.
  225. + */
  226. + if (ret != -ENODEV || ipts->status != IPTS_HOST_STATUS_STOPPING)
  227. + dev_err(ipts->dev, "Error while sending: 0x%X:%d\n", code, ret);
  228. +
  229. + return ret;
  230. +}
  231. +
  232. +int ipts_control_send_feedback(struct ipts_context *ipts, u32 buffer)
  233. +{
  234. + struct ipts_feedback_cmd cmd;
  235. +
  236. + memset(&cmd, 0, sizeof(struct ipts_feedback_cmd));
  237. + cmd.buffer = buffer;
  238. +
  239. + return ipts_control_send(ipts, IPTS_CMD_FEEDBACK, &cmd,
  240. + sizeof(struct ipts_feedback_cmd));
  241. +}
  242. +
  243. +int ipts_control_set_feature(struct ipts_context *ipts, u8 report, u8 value)
  244. +{
  245. + struct ipts_feedback_buffer *feedback;
  246. +
  247. + memset(ipts->host2me.address, 0, ipts->device_info.feedback_size);
  248. + feedback = (struct ipts_feedback_buffer *)ipts->host2me.address;
  249. +
  250. + feedback->cmd_type = IPTS_FEEDBACK_CMD_TYPE_NONE;
  251. + feedback->data_type = IPTS_FEEDBACK_DATA_TYPE_SET_FEATURES;
  252. + feedback->buffer = IPTS_HOST2ME_BUFFER;
  253. + feedback->size = 2;
  254. + feedback->payload[0] = report;
  255. + feedback->payload[1] = value;
  256. +
  257. + return ipts_control_send_feedback(ipts, IPTS_HOST2ME_BUFFER);
  258. +}
  259. +
  260. +int ipts_control_start(struct ipts_context *ipts)
  261. +{
  262. + if (ipts->status != IPTS_HOST_STATUS_STOPPED)
  263. + return -EBUSY;
  264. +
  265. + dev_info(ipts->dev, "Starting IPTS\n");
  266. + ipts->status = IPTS_HOST_STATUS_STARTING;
  267. + ipts->restart = false;
  268. +
  269. + ipts_uapi_link(ipts);
  270. + return ipts_control_send(ipts, IPTS_CMD_GET_DEVICE_INFO, NULL, 0);
  271. +}
  272. +
  273. +int ipts_control_stop(struct ipts_context *ipts)
  274. +{
  275. + int ret;
  276. +
  277. + if (ipts->status == IPTS_HOST_STATUS_STOPPING)
  278. + return -EBUSY;
  279. +
  280. + if (ipts->status == IPTS_HOST_STATUS_STOPPED)
  281. + return -EBUSY;
  282. +
  283. + dev_info(ipts->dev, "Stopping IPTS\n");
  284. + ipts->status = IPTS_HOST_STATUS_STOPPING;
  285. +
  286. + ipts_uapi_unlink();
  287. + ipts_resources_free(ipts);
  288. +
  289. + ret = ipts_control_send_feedback(ipts, 0);
  290. + if (ret == -ENODEV)
  291. + ipts->status = IPTS_HOST_STATUS_STOPPED;
  292. +
  293. + return ret;
  294. +}
  295. +
  296. +int ipts_control_restart(struct ipts_context *ipts)
  297. +{
  298. + if (ipts->restart)
  299. + return -EBUSY;
  300. +
  301. + ipts->restart = true;
  302. + return ipts_control_stop(ipts);
  303. +}
  304. diff --git a/drivers/misc/ipts/control.h b/drivers/misc/ipts/control.h
  305. new file mode 100644
  306. index 000000000000..2c44e9e0e99f
  307. --- /dev/null
  308. +++ b/drivers/misc/ipts/control.h
  309. @@ -0,0 +1,24 @@
  310. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  311. +/*
  312. + * Copyright (c) 2016 Intel Corporation
  313. + * Copyright (c) 2020 Dorian Stoll
  314. + *
  315. + * Linux driver for Intel Precise Touch & Stylus
  316. + */
  317. +
  318. +#ifndef _IPTS_CONTROL_H_
  319. +#define _IPTS_CONTROL_H_
  320. +
  321. +#include <linux/types.h>
  322. +
  323. +#include "context.h"
  324. +
  325. +int ipts_control_send(struct ipts_context *ipts, u32 cmd, void *payload,
  326. + size_t size);
  327. +int ipts_control_send_feedback(struct ipts_context *ipts, u32 buffer);
  328. +int ipts_control_set_feature(struct ipts_context *ipts, u8 report, u8 value);
  329. +int ipts_control_start(struct ipts_context *ipts);
  330. +int ipts_control_restart(struct ipts_context *ipts);
  331. +int ipts_control_stop(struct ipts_context *ipts);
  332. +
  333. +#endif /* _IPTS_CONTROL_H_ */
  334. diff --git a/drivers/misc/ipts/mei.c b/drivers/misc/ipts/mei.c
  335. new file mode 100644
  336. index 000000000000..59ecf13e00d2
  337. --- /dev/null
  338. +++ b/drivers/misc/ipts/mei.c
  339. @@ -0,0 +1,125 @@
  340. +// SPDX-License-Identifier: GPL-2.0-or-later
  341. +/*
  342. + * Copyright (c) 2016 Intel Corporation
  343. + * Copyright (c) 2020 Dorian Stoll
  344. + *
  345. + * Linux driver for Intel Precise Touch & Stylus
  346. + */
  347. +
  348. +#include <linux/delay.h>
  349. +#include <linux/dma-mapping.h>
  350. +#include <linux/mei_cl_bus.h>
  351. +#include <linux/mod_devicetable.h>
  352. +#include <linux/module.h>
  353. +#include <linux/slab.h>
  354. +
  355. +#include "context.h"
  356. +#include "control.h"
  357. +#include "protocol.h"
  358. +#include "receiver.h"
  359. +#include "uapi.h"
  360. +
  361. +static int ipts_mei_set_dma_mask(struct mei_cl_device *cldev)
  362. +{
  363. + int ret;
  364. +
  365. + ret = dma_coerce_mask_and_coherent(&cldev->dev, DMA_BIT_MASK(64));
  366. + if (!ret)
  367. + return 0;
  368. +
  369. + return dma_coerce_mask_and_coherent(&cldev->dev, DMA_BIT_MASK(32));
  370. +}
  371. +
  372. +static int ipts_mei_probe(struct mei_cl_device *cldev,
  373. + const struct mei_cl_device_id *id)
  374. +{
  375. + int ret;
  376. + struct ipts_context *ipts;
  377. +
  378. + if (ipts_mei_set_dma_mask(cldev)) {
  379. + dev_err(&cldev->dev, "Failed to set DMA mask for IPTS\n");
  380. + return -EFAULT;
  381. + }
  382. +
  383. + ret = mei_cldev_enable(cldev);
  384. + if (ret) {
  385. + dev_err(&cldev->dev, "Failed to enable MEI device: %d\n", ret);
  386. + return ret;
  387. + }
  388. +
  389. + ipts = kzalloc(sizeof(*ipts), GFP_KERNEL);
  390. + if (!ipts) {
  391. + mei_cldev_disable(cldev);
  392. + return -ENOMEM;
  393. + }
  394. +
  395. + ipts->cldev = cldev;
  396. + ipts->dev = &cldev->dev;
  397. + ipts->status = IPTS_HOST_STATUS_STOPPED;
  398. +
  399. + mei_cldev_set_drvdata(cldev, ipts);
  400. + mei_cldev_register_rx_cb(cldev, ipts_receiver_callback);
  401. +
  402. + return ipts_control_start(ipts);
  403. +}
  404. +
  405. +static void ipts_mei_remove(struct mei_cl_device *cldev)
  406. +{
  407. + int i;
  408. + struct ipts_context *ipts = mei_cldev_get_drvdata(cldev);
  409. +
  410. + ipts_control_stop(ipts);
  411. +
  412. + for (i = 0; i < 20; i++) {
  413. + if (ipts->status == IPTS_HOST_STATUS_STOPPED)
  414. + break;
  415. +
  416. + msleep(25);
  417. + }
  418. +
  419. + mei_cldev_disable(cldev);
  420. + kfree(ipts);
  421. +}
  422. +
  423. +static struct mei_cl_device_id ipts_mei_device_id_table[] = {
  424. + { "", IPTS_MEI_UUID, MEI_CL_VERSION_ANY },
  425. + {},
  426. +};
  427. +MODULE_DEVICE_TABLE(mei, ipts_mei_device_id_table);
  428. +
  429. +static struct mei_cl_driver ipts_mei_driver = {
  430. + .id_table = ipts_mei_device_id_table,
  431. + .name = "ipts",
  432. + .probe = ipts_mei_probe,
  433. + .remove = ipts_mei_remove,
  434. +};
  435. +
  436. +static int __init ipts_mei_init(void)
  437. +{
  438. + int ret;
  439. +
  440. + ret = ipts_uapi_init();
  441. + if (ret)
  442. + return ret;
  443. +
  444. + ret = mei_cldev_driver_register(&ipts_mei_driver);
  445. + if (ret) {
  446. + ipts_uapi_free();
  447. + return ret;
  448. + }
  449. +
  450. + return 0;
  451. +}
  452. +
  453. +static void __exit ipts_mei_exit(void)
  454. +{
  455. + mei_cldev_driver_unregister(&ipts_mei_driver);
  456. + ipts_uapi_free();
  457. +}
  458. +
  459. +MODULE_DESCRIPTION("IPTS touchscreen driver");
  460. +MODULE_AUTHOR("Dorian Stoll <dorian.stoll@tmsp.io>");
  461. +MODULE_LICENSE("GPL");
  462. +
  463. +module_init(ipts_mei_init);
  464. +module_exit(ipts_mei_exit);
  465. diff --git a/drivers/misc/ipts/protocol.h b/drivers/misc/ipts/protocol.h
  466. new file mode 100644
  467. index 000000000000..c3458904a94d
  468. --- /dev/null
  469. +++ b/drivers/misc/ipts/protocol.h
  470. @@ -0,0 +1,347 @@
  471. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  472. +/*
  473. + * Copyright (c) 2016 Intel Corporation
  474. + * Copyright (c) 2020 Dorian Stoll
  475. + *
  476. + * Linux driver for Intel Precise Touch & Stylus
  477. + */
  478. +
  479. +#ifndef _IPTS_PROTOCOL_H_
  480. +#define _IPTS_PROTOCOL_H_
  481. +
  482. +#include <linux/types.h>
  483. +
  484. +/*
  485. + * The MEI client ID for IPTS functionality.
  486. + */
  487. +#define IPTS_MEI_UUID \
  488. + UUID_LE(0x3e8d0870, 0x271a, 0x4208, 0x8e, 0xb5, 0x9a, 0xcb, 0x94, \
  489. + 0x02, 0xae, 0x04)
  490. +
  491. +/*
  492. + * Queries the device for vendor specific information.
  493. + *
  494. + * The command must not contain any payload.
  495. + * The response will contain struct ipts_get_device_info_rsp as payload.
  496. + */
  497. +#define IPTS_CMD_GET_DEVICE_INFO 0x00000001
  498. +#define IPTS_RSP_GET_DEVICE_INFO 0x80000001
  499. +
  500. +/*
  501. + * Sets the mode that IPTS will operate in.
  502. + *
  503. + * The command must contain struct ipts_set_mode_cmd as payload.
  504. + * The response will not contain any payload.
  505. + */
  506. +#define IPTS_CMD_SET_MODE 0x00000002
  507. +#define IPTS_RSP_SET_MODE 0x80000002
  508. +
  509. +/*
  510. + * Configures the memory buffers that the ME will use
  511. + * for passing data to the host.
  512. + *
  513. + * The command must contain struct ipts_set_mem_window_cmd as payload.
  514. + * The response will not contain any payload.
  515. + */
  516. +#define IPTS_CMD_SET_MEM_WINDOW 0x00000003
  517. +#define IPTS_RSP_SET_MEM_WINDOW 0x80000003
  518. +
  519. +/*
  520. + * Signals that the host is ready to receive data to the ME.
  521. + *
  522. + * The command must not contain any payload.
  523. + * The response will not contain any payload.
  524. + */
  525. +#define IPTS_CMD_READY_FOR_DATA 0x00000005
  526. +#define IPTS_RSP_READY_FOR_DATA 0x80000005
  527. +
  528. +/*
  529. + * Signals that a buffer can be refilled to the ME.
  530. + *
  531. + * The command must contain struct ipts_feedback_cmd as payload.
  532. + * The response will not contain any payload.
  533. + */
  534. +#define IPTS_CMD_FEEDBACK 0x00000006
  535. +#define IPTS_RSP_FEEDBACK 0x80000006
  536. +
  537. +/*
  538. + * Resets the data flow from the ME to the hosts and
  539. + * clears the buffers that were set with SET_MEM_WINDOW.
  540. + *
  541. + * The command must not contain any payload.
  542. + * The response will not contain any payload.
  543. + */
  544. +#define IPTS_CMD_CLEAR_MEM_WINDOW 0x00000007
  545. +#define IPTS_RSP_CLEAR_MEM_WINDOW 0x80000007
  546. +
  547. +/*
  548. + * Instructs the ME to reset the touch sensor.
  549. + *
  550. + * The command must contain struct ipts_reset_sensor_cmd as payload.
  551. + * The response will not contain any payload.
  552. + */
  553. +#define IPTS_CMD_RESET_SENSOR 0x0000000B
  554. +#define IPTS_RSP_RESET_SENSOR 0x8000000B
  555. +
  556. +/**
  557. + * enum ipts_status - Possible status codes returned by IPTS commands.
  558. + * @IPTS_STATUS_SUCCESS: Operation completed successfully.
  559. + * @IPTS_STATUS_INVALID_PARAMS: Command contained a payload with invalid parameters.
  560. + * @IPTS_STATUS_ACCESS_DENIED: ME could not validate buffer addresses supplied by host.
  561. + * @IPTS_STATUS_CMD_SIZE_ERROR: Command contains an invalid payload.
  562. + * @IPTS_STATUS_NOT_READY: Buffer addresses have not been set.
  563. + * @IPTS_STATUS_REQUEST_OUTSTANDING: There is an outstanding command of the same type.
  564. + * The host must wait for a response before sending another
  565. + * command of the same type.
  566. + * @IPTS_STATUS_NO_SENSOR_FOUND: No sensor could be found. Either no sensor is connected, it
  567. + * has not been initialized yet, or the system is improperly
  568. + * configured.
  569. + * @IPTS_STATUS_OUT_OF_MEMORY: Not enough free memory for requested operation.
  570. + * @IPTS_STATUS_INTERNAL_ERROR: An unexpected error occurred.
  571. + * @IPTS_STATUS_SENSOR_DISABLED: The sensor has been disabled and must be reinitialized.
  572. + * @IPTS_STATUS_COMPAT_CHECK_FAIL: Compatibility revision check between sensor and ME failed.
  573. + * The host can ignore this error and attempt to continue.
  574. + * @IPTS_STATUS_SENSOR_EXPECTED_RESET: The sensor went through a reset initiated by ME or host.
  575. + * @IPTS_STATUS_SENSOR_UNEXPECTED_RESET: The sensor went through an unexpected reset.
  576. + * @IPTS_STATUS_RESET_FAILED: Requested sensor reset failed to complete.
  577. + * @IPTS_STATUS_TIMEOUT: The operation timed out.
  578. + * @IPTS_STATUS_TEST_MODE_FAIL: Test mode pattern did not match expected values.
  579. + * @IPTS_STATUS_SENSOR_FAIL_FATAL: The sensor reported a fatal error during reset sequence.
  580. + * Further progress is not possible.
  581. + * @IPTS_STATUS_SENSOR_FAIL_NONFATAL: The sensor reported a fatal error during reset sequence.
  582. + * The host can attempt to continue.
  583. + * @IPTS_STATUS_INVALID_DEVICE_CAPS: The device reported invalid capabilities.
  584. + * @IPTS_STATUS_QUIESCE_IO_IN_PROGRESS: Command cannot be completed until Quiesce IO is done.
  585. + */
  586. +enum ipts_status {
  587. + IPTS_STATUS_SUCCESS = 0,
  588. + IPTS_STATUS_INVALID_PARAMS = 1,
  589. + IPTS_STATUS_ACCESS_DENIED = 2,
  590. + IPTS_STATUS_CMD_SIZE_ERROR = 3,
  591. + IPTS_STATUS_NOT_READY = 4,
  592. + IPTS_STATUS_REQUEST_OUTSTANDING = 5,
  593. + IPTS_STATUS_NO_SENSOR_FOUND = 6,
  594. + IPTS_STATUS_OUT_OF_MEMORY = 7,
  595. + IPTS_STATUS_INTERNAL_ERROR = 8,
  596. + IPTS_STATUS_SENSOR_DISABLED = 9,
  597. + IPTS_STATUS_COMPAT_CHECK_FAIL = 10,
  598. + IPTS_STATUS_SENSOR_EXPECTED_RESET = 11,
  599. + IPTS_STATUS_SENSOR_UNEXPECTED_RESET = 12,
  600. + IPTS_STATUS_RESET_FAILED = 13,
  601. + IPTS_STATUS_TIMEOUT = 14,
  602. + IPTS_STATUS_TEST_MODE_FAIL = 15,
  603. + IPTS_STATUS_SENSOR_FAIL_FATAL = 16,
  604. + IPTS_STATUS_SENSOR_FAIL_NONFATAL = 17,
  605. + IPTS_STATUS_INVALID_DEVICE_CAPS = 18,
  606. + IPTS_STATUS_QUIESCE_IO_IN_PROGRESS = 19,
  607. +};
  608. +
  609. +/*
  610. + * The amount of buffers that is used for IPTS
  611. + */
  612. +#define IPTS_BUFFERS 16
  613. +
  614. +/*
  615. + * The special buffer ID that is used for direct host2me feedback.
  616. + */
  617. +#define IPTS_HOST2ME_BUFFER IPTS_BUFFERS
  618. +
  619. +/**
  620. + * enum ipts_mode - Operation mode for IPTS hardware
  621. + * @IPTS_MODE_SINGLETOUCH: Fallback that supports only one finger and no stylus.
  622. + * The data is received as a HID report with ID 64.
  623. + * @IPTS_MODE_MULTITOUCH: The "proper" operation mode for IPTS. It will return
  624. + * stylus data as well as capacitive heatmap touch data.
  625. + * This data needs to be processed in userspace.
  626. + */
  627. +enum ipts_mode {
  628. + IPTS_MODE_SINGLETOUCH = 0,
  629. + IPTS_MODE_MULTITOUCH = 1,
  630. +};
  631. +
  632. +/**
  633. + * struct ipts_set_mode_cmd - Payload for the SET_MODE command.
  634. + * @mode: The mode that IPTS should operate in.
  635. + */
  636. +struct ipts_set_mode_cmd {
  637. + enum ipts_mode mode;
  638. + u8 reserved[12];
  639. +} __packed;
  640. +
  641. +#define IPTS_WORKQUEUE_SIZE 8192
  642. +#define IPTS_WORKQUEUE_ITEM_SIZE 16
  643. +
  644. +/**
  645. + * struct ipts_set_mem_window_cmd - Payload for the SET_MEM_WINDOW command.
  646. + * @data_buffer_addr_lower: Lower 32 bits of the data buffer addresses.
  647. + * @data_buffer_addr_upper: Upper 32 bits of the data buffer addresses.
  648. + * @workqueue_addr_lower: Lower 32 bits of the workqueue buffer address.
  649. + * @workqueue_addr_upper: Upper 32 bits of the workqueue buffer address.
  650. + * @doorbell_addr_lower: Lower 32 bits of the doorbell buffer address.
  651. + * @doorbell_addr_upper: Upper 32 bits of the doorbell buffer address.
  652. + * @feedback_buffer_addr_lower: Lower 32 bits of the feedback buffer addresses.
  653. + * @feedback_buffer_addr_upper: Upper 32 bits of the feedback buffer addresses.
  654. + * @host2me_addr_lower: Lower 32 bits of the host2me buffer address.
  655. + * @host2me_addr_upper: Upper 32 bits of the host2me buffer address.
  656. + * @workqueue_item_size: Magic value. (IPTS_WORKQUEUE_ITEM_SIZE)
  657. + * @workqueue_size: Magic value. (IPTS_WORKQUEUE_SIZE)
  658. + *
  659. + * The data buffers are buffers that get filled with touch data by the ME.
  660. + * The doorbell buffer is a u32 that gets incremented by the ME once a data
  661. + * buffer has been filled with new data.
  662. + *
  663. + * The other buffers are required for using GuC submission with binary
  664. + * firmware. Since support for GuC submission has been dropped from i915,
  665. + * they are not used anymore, but they need to be allocated and passed,
  666. + * otherwise the hardware will refuse to start.
  667. + */
  668. +struct ipts_set_mem_window_cmd {
  669. + u32 data_buffer_addr_lower[IPTS_BUFFERS];
  670. + u32 data_buffer_addr_upper[IPTS_BUFFERS];
  671. + u32 workqueue_addr_lower;
  672. + u32 workqueue_addr_upper;
  673. + u32 doorbell_addr_lower;
  674. + u32 doorbell_addr_upper;
  675. + u32 feedback_buffer_addr_lower[IPTS_BUFFERS];
  676. + u32 feedback_buffer_addr_upper[IPTS_BUFFERS];
  677. + u32 host2me_addr_lower;
  678. + u32 host2me_addr_upper;
  679. + u32 host2me_size;
  680. + u8 reserved1;
  681. + u8 workqueue_item_size;
  682. + u16 workqueue_size;
  683. + u8 reserved[32];
  684. +} __packed;
  685. +
  686. +/**
  687. + * struct ipts_feedback_cmd - Payload for the FEEDBACK command.
  688. + * @buffer: The buffer that the ME should refill.
  689. + */
  690. +struct ipts_feedback_cmd {
  691. + u32 buffer;
  692. + u8 reserved[12];
  693. +} __packed;
  694. +
  695. +/**
  696. + * enum ipts_feedback_cmd_type - Commands that can be executed on the sensor through feedback.
  697. + */
  698. +enum ipts_feedback_cmd_type {
  699. + IPTS_FEEDBACK_CMD_TYPE_NONE = 0,
  700. + IPTS_FEEDBACK_CMD_TYPE_SOFT_RESET = 1,
  701. + IPTS_FEEDBACK_CMD_TYPE_GOTO_ARMED = 2,
  702. + IPTS_FEEDBACK_CMD_TYPE_GOTO_SENSING = 3,
  703. + IPTS_FEEDBACK_CMD_TYPE_GOTO_SLEEP = 4,
  704. + IPTS_FEEDBACK_CMD_TYPE_GOTO_DOZE = 5,
  705. + IPTS_FEEDBACK_CMD_TYPE_HARD_RESET = 6,
  706. +};
  707. +
  708. +/**
  709. + * enum ipts_feedback_data_type - Describes the data that a feedback buffer contains.
  710. + * @IPTS_FEEDBACK_DATA_TYPE_VENDOR: The buffer contains vendor specific feedback.
  711. + * @IPTS_FEEDBACK_DATA_TYPE_SET_FEATURES: The buffer contains a HID set features command.
  712. + * @IPTS_FEEDBACK_DATA_TYPE_GET_FEATURES: The buffer contains a HID get features command.
  713. + * @IPTS_FEEDBACK_DATA_TYPE_OUTPUT_REPORT: The buffer contains a HID output report.
  714. + * @IPTS_FEEDBACK_DATA_TYPE_STORE_DATA: The buffer contains calibration data for the sensor.
  715. + */
  716. +enum ipts_feedback_data_type {
  717. + IPTS_FEEDBACK_DATA_TYPE_VENDOR = 0,
  718. + IPTS_FEEDBACK_DATA_TYPE_SET_FEATURES = 1,
  719. + IPTS_FEEDBACK_DATA_TYPE_GET_FEATURES = 2,
  720. + IPTS_FEEDBACK_DATA_TYPE_OUTPUT_REPORT = 3,
  721. + IPTS_FEEDBACK_DATA_TYPE_STORE_DATA = 4,
  722. +};
  723. +
  724. +/**
  725. + * struct ipts_feedback_buffer - The contents of an IPTS feedback buffer.
  726. + * @cmd_type: A command that should be executed on the sensor.
  727. + * @size: The size of the payload to be written.
  728. + * @buffer: The ID of the buffer that contains this feedback data.
  729. + * @protocol: The protocol version of the EDS.
  730. + * @data_type: The type of payload that the buffer contains.
  731. + * @spi_offset: The offset at which to write the payload data.
  732. + * @payload: Payload for the feedback command, or 0 if no payload is sent.
  733. + */
  734. +struct ipts_feedback_buffer {
  735. + enum ipts_feedback_cmd_type cmd_type;
  736. + u32 size;
  737. + u32 buffer;
  738. + u32 protocol;
  739. + enum ipts_feedback_data_type data_type;
  740. + u32 spi_offset;
  741. + u8 reserved[40];
  742. + u8 payload[];
  743. +} __packed;
  744. +
  745. +/**
  746. + * enum ipts_reset_type - Possible ways of resetting the touch sensor
  747. + * @IPTS_RESET_TYPE_HARD: Perform hardware reset using GPIO pin.
  748. + * @IPTS_RESET_TYPE_SOFT: Perform software reset using SPI interface.
  749. + */
  750. +enum ipts_reset_type {
  751. + IPTS_RESET_TYPE_HARD = 0,
  752. + IPTS_RESET_TYPE_SOFT = 1,
  753. +};
  754. +
  755. +/**
  756. + * struct ipts_reset_sensor_cmd - Payload for the RESET_SENSOR command.
  757. + * @type: What type of reset should be performed.
  758. + */
  759. +struct ipts_reset_sensor_cmd {
  760. + enum ipts_reset_type type;
  761. + u8 reserved[4];
  762. +} __packed;
  763. +
  764. +/**
  765. + * struct ipts_command - A message sent from the host to the ME.
  766. + * @code: The message code describing the command. (see IPTS_CMD_*)
  767. + * @payload: Payload for the command, or 0 if no payload is required.
  768. + */
  769. +struct ipts_command {
  770. + u32 code;
  771. + u8 payload[320];
  772. +} __packed;
  773. +
  774. +/**
  775. + * struct ipts_device_info - Payload for the GET_DEVICE_INFO response.
  776. + * @vendor_id: Vendor ID of the touch sensor.
  777. + * @device_id: Device ID of the touch sensor.
  778. + * @hw_rev: Hardware revision of the touch sensor.
  779. + * @fw_rev: Firmware revision of the touch sensor.
  780. + * @data_size: Required size of one data buffer.
  781. + * @feedback_size: Required size of one feedback buffer.
  782. + * @mode: Current operation mode of IPTS.
  783. + * @max_contacts: The amount of concurrent touches supported by the sensor.
  784. + */
  785. +struct ipts_get_device_info_rsp {
  786. + u16 vendor_id;
  787. + u16 device_id;
  788. + u32 hw_rev;
  789. + u32 fw_rev;
  790. + u32 data_size;
  791. + u32 feedback_size;
  792. + enum ipts_mode mode;
  793. + u8 max_contacts;
  794. + u8 reserved[19];
  795. +} __packed;
  796. +
  797. +/**
  798. + * struct ipts_feedback_rsp - Payload for the FEEDBACK response.
  799. + * @buffer: The buffer that has received feedback.
  800. + */
  801. +struct ipts_feedback_rsp {
  802. + u32 buffer;
  803. +} __packed;
  804. +
  805. +/**
  806. + * struct ipts_response - A message sent from the ME to the host.
  807. + * @code: The message code describing the response. (see IPTS_RSP_*)
  808. + * @status: The status code returned by the command.
  809. + * @payload: Payload returned by the command.
  810. + */
  811. +struct ipts_response {
  812. + u32 code;
  813. + enum ipts_status status;
  814. + u8 payload[80];
  815. +} __packed;
  816. +
  817. +#endif /* _IPTS_PROTOCOL_H_ */
  818. diff --git a/drivers/misc/ipts/receiver.c b/drivers/misc/ipts/receiver.c
  819. new file mode 100644
  820. index 000000000000..23dca13c2139
  821. --- /dev/null
  822. +++ b/drivers/misc/ipts/receiver.c
  823. @@ -0,0 +1,224 @@
  824. +// SPDX-License-Identifier: GPL-2.0-or-later
  825. +/*
  826. + * Copyright (c) 2016 Intel Corporation
  827. + * Copyright (c) 2020 Dorian Stoll
  828. + *
  829. + * Linux driver for Intel Precise Touch & Stylus
  830. + */
  831. +
  832. +#include <linux/mei_cl_bus.h>
  833. +#include <linux/moduleparam.h>
  834. +#include <linux/types.h>
  835. +
  836. +#include "context.h"
  837. +#include "control.h"
  838. +#include "protocol.h"
  839. +#include "resources.h"
  840. +
  841. +/*
  842. + * Temporary parameter to guard gen7 multitouch mode.
  843. + * Remove once gen7 has stable iptsd support.
  844. + */
  845. +static bool gen7mt;
  846. +module_param(gen7mt, bool, 0644);
  847. +
  848. +static int ipts_receiver_handle_get_device_info(struct ipts_context *ipts,
  849. + struct ipts_response *rsp)
  850. +{
  851. + struct ipts_set_mode_cmd cmd;
  852. +
  853. + memcpy(&ipts->device_info, rsp->payload,
  854. + sizeof(struct ipts_get_device_info_rsp));
  855. +
  856. + memset(&cmd, 0, sizeof(struct ipts_set_mode_cmd));
  857. + cmd.mode = IPTS_MODE_MULTITOUCH;
  858. +
  859. + return ipts_control_send(ipts, IPTS_CMD_SET_MODE, &cmd,
  860. + sizeof(struct ipts_set_mode_cmd));
  861. +}
  862. +
  863. +static int ipts_receiver_handle_set_mode(struct ipts_context *ipts)
  864. +{
  865. + int i, ret;
  866. + struct ipts_set_mem_window_cmd cmd;
  867. +
  868. + ret = ipts_resources_alloc(ipts);
  869. + if (ret) {
  870. + dev_err(ipts->dev, "Failed to allocate resources\n");
  871. + return ret;
  872. + }
  873. +
  874. + memset(&cmd, 0, sizeof(struct ipts_set_mem_window_cmd));
  875. +
  876. + for (i = 0; i < IPTS_BUFFERS; i++) {
  877. + cmd.data_buffer_addr_lower[i] =
  878. + lower_32_bits(ipts->data[i].dma_address);
  879. +
  880. + cmd.data_buffer_addr_upper[i] =
  881. + upper_32_bits(ipts->data[i].dma_address);
  882. +
  883. + cmd.feedback_buffer_addr_lower[i] =
  884. + lower_32_bits(ipts->feedback[i].dma_address);
  885. +
  886. + cmd.feedback_buffer_addr_upper[i] =
  887. + upper_32_bits(ipts->feedback[i].dma_address);
  888. + }
  889. +
  890. + cmd.workqueue_addr_lower = lower_32_bits(ipts->workqueue.dma_address);
  891. + cmd.workqueue_addr_upper = upper_32_bits(ipts->workqueue.dma_address);
  892. +
  893. + cmd.doorbell_addr_lower = lower_32_bits(ipts->doorbell.dma_address);
  894. + cmd.doorbell_addr_upper = upper_32_bits(ipts->doorbell.dma_address);
  895. +
  896. + cmd.host2me_addr_lower = lower_32_bits(ipts->host2me.dma_address);
  897. + cmd.host2me_addr_upper = upper_32_bits(ipts->host2me.dma_address);
  898. +
  899. + cmd.workqueue_size = IPTS_WORKQUEUE_SIZE;
  900. + cmd.workqueue_item_size = IPTS_WORKQUEUE_ITEM_SIZE;
  901. +
  902. + return ipts_control_send(ipts, IPTS_CMD_SET_MEM_WINDOW, &cmd,
  903. + sizeof(struct ipts_set_mem_window_cmd));
  904. +}
  905. +
  906. +static int ipts_receiver_handle_set_mem_window(struct ipts_context *ipts)
  907. +{
  908. + int ret;
  909. +
  910. + dev_info(ipts->dev, "Device %04hX:%04hX ready\n",
  911. + ipts->device_info.vendor_id, ipts->device_info.device_id);
  912. + ipts->status = IPTS_HOST_STATUS_STARTED;
  913. +
  914. + ret = ipts_control_send(ipts, IPTS_CMD_READY_FOR_DATA, NULL, 0);
  915. + if (ret)
  916. + return ret;
  917. +
  918. + if (!gen7mt)
  919. + return 0;
  920. +
  921. + return ipts_control_set_feature(ipts, 0x5, 0x1);
  922. +}
  923. +
  924. +static int ipts_receiver_handle_feedback(struct ipts_context *ipts,
  925. + struct ipts_response *rsp)
  926. +{
  927. + struct ipts_feedback_rsp feedback;
  928. +
  929. + if (ipts->status != IPTS_HOST_STATUS_STOPPING)
  930. + return 0;
  931. +
  932. + memcpy(&feedback, rsp->payload, sizeof(feedback));
  933. +
  934. + if (feedback.buffer < IPTS_BUFFERS - 1)
  935. + return ipts_control_send_feedback(ipts, feedback.buffer + 1);
  936. +
  937. + return ipts_control_send(ipts, IPTS_CMD_CLEAR_MEM_WINDOW, NULL, 0);
  938. +}
  939. +
  940. +static int ipts_receiver_handle_clear_mem_window(struct ipts_context *ipts)
  941. +{
  942. + ipts->status = IPTS_HOST_STATUS_STOPPED;
  943. +
  944. + if (ipts->restart)
  945. + return ipts_control_start(ipts);
  946. +
  947. + return 0;
  948. +}
  949. +
  950. +static bool ipts_receiver_sensor_was_reset(u32 status)
  951. +{
  952. + return status == IPTS_STATUS_SENSOR_EXPECTED_RESET ||
  953. + status == IPTS_STATUS_SENSOR_UNEXPECTED_RESET;
  954. +}
  955. +
  956. +static bool ipts_receiver_handle_error(struct ipts_context *ipts,
  957. + struct ipts_response *rsp)
  958. +{
  959. + bool error;
  960. +
  961. + switch (rsp->status) {
  962. + case IPTS_STATUS_SUCCESS:
  963. + case IPTS_STATUS_COMPAT_CHECK_FAIL:
  964. + error = false;
  965. + break;
  966. + case IPTS_STATUS_INVALID_PARAMS:
  967. + error = rsp->code != IPTS_RSP_FEEDBACK;
  968. + break;
  969. + case IPTS_STATUS_SENSOR_DISABLED:
  970. + error = ipts->status != IPTS_HOST_STATUS_STOPPING;
  971. + break;
  972. + default:
  973. + error = true;
  974. + break;
  975. + }
  976. +
  977. + if (!error)
  978. + return false;
  979. +
  980. + dev_err(ipts->dev, "Command 0x%08x failed: %d\n", rsp->code,
  981. + rsp->status);
  982. +
  983. + if (ipts_receiver_sensor_was_reset(rsp->status)) {
  984. + dev_err(ipts->dev, "Sensor was reset\n");
  985. +
  986. + if (ipts_control_restart(ipts))
  987. + dev_err(ipts->dev, "Failed to restart IPTS\n");
  988. + }
  989. +
  990. + return true;
  991. +}
  992. +
  993. +static void ipts_receiver_handle_response(struct ipts_context *ipts,
  994. + struct ipts_response *rsp)
  995. +{
  996. + int ret;
  997. +
  998. + if (ipts_receiver_handle_error(ipts, rsp))
  999. + return;
  1000. +
  1001. + switch (rsp->code) {
  1002. + case IPTS_RSP_GET_DEVICE_INFO:
  1003. + ret = ipts_receiver_handle_get_device_info(ipts, rsp);
  1004. + break;
  1005. + case IPTS_RSP_SET_MODE:
  1006. + ret = ipts_receiver_handle_set_mode(ipts);
  1007. + break;
  1008. + case IPTS_RSP_SET_MEM_WINDOW:
  1009. + ret = ipts_receiver_handle_set_mem_window(ipts);
  1010. + break;
  1011. + case IPTS_RSP_FEEDBACK:
  1012. + ret = ipts_receiver_handle_feedback(ipts, rsp);
  1013. + break;
  1014. + case IPTS_RSP_CLEAR_MEM_WINDOW:
  1015. + ret = ipts_receiver_handle_clear_mem_window(ipts);
  1016. + break;
  1017. + default:
  1018. + ret = 0;
  1019. + break;
  1020. + }
  1021. +
  1022. + if (!ret)
  1023. + return;
  1024. +
  1025. + dev_err(ipts->dev, "Error while handling response 0x%08x: %d\n",
  1026. + rsp->code, ret);
  1027. +
  1028. + if (ipts_control_stop(ipts))
  1029. + dev_err(ipts->dev, "Failed to stop IPTS\n");
  1030. +}
  1031. +
  1032. +void ipts_receiver_callback(struct mei_cl_device *cldev)
  1033. +{
  1034. + int ret;
  1035. + struct ipts_response rsp;
  1036. + struct ipts_context *ipts;
  1037. +
  1038. + ipts = mei_cldev_get_drvdata(cldev);
  1039. +
  1040. + ret = mei_cldev_recv(cldev, (u8 *)&rsp, sizeof(struct ipts_response));
  1041. + if (ret <= 0) {
  1042. + dev_err(ipts->dev, "Error while reading response: %d\n", ret);
  1043. + return;
  1044. + }
  1045. +
  1046. + ipts_receiver_handle_response(ipts, &rsp);
  1047. +}
  1048. diff --git a/drivers/misc/ipts/receiver.h b/drivers/misc/ipts/receiver.h
  1049. new file mode 100644
  1050. index 000000000000..7f075afa7ef8
  1051. --- /dev/null
  1052. +++ b/drivers/misc/ipts/receiver.h
  1053. @@ -0,0 +1,16 @@
  1054. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  1055. +/*
  1056. + * Copyright (c) 2016 Intel Corporation
  1057. + * Copyright (c) 2020 Dorian Stoll
  1058. + *
  1059. + * Linux driver for Intel Precise Touch & Stylus
  1060. + */
  1061. +
  1062. +#ifndef _IPTS_RECEIVER_H_
  1063. +#define _IPTS_RECEIVER_H_
  1064. +
  1065. +#include <linux/mei_cl_bus.h>
  1066. +
  1067. +void ipts_receiver_callback(struct mei_cl_device *cldev);
  1068. +
  1069. +#endif /* _IPTS_RECEIVER_H_ */
  1070. diff --git a/drivers/misc/ipts/resources.c b/drivers/misc/ipts/resources.c
  1071. new file mode 100644
  1072. index 000000000000..8e3a2409e438
  1073. --- /dev/null
  1074. +++ b/drivers/misc/ipts/resources.c
  1075. @@ -0,0 +1,128 @@
  1076. +// SPDX-License-Identifier: GPL-2.0-or-later
  1077. +/*
  1078. + * Copyright (c) 2016 Intel Corporation
  1079. + * Copyright (c) 2020 Dorian Stoll
  1080. + *
  1081. + * Linux driver for Intel Precise Touch & Stylus
  1082. + */
  1083. +
  1084. +#include <linux/dma-mapping.h>
  1085. +
  1086. +#include "context.h"
  1087. +
  1088. +void ipts_resources_free(struct ipts_context *ipts)
  1089. +{
  1090. + int i;
  1091. + struct ipts_buffer_info *buffers;
  1092. +
  1093. + u32 data_buffer_size = ipts->device_info.data_size;
  1094. + u32 feedback_buffer_size = ipts->device_info.feedback_size;
  1095. +
  1096. + buffers = ipts->data;
  1097. + for (i = 0; i < IPTS_BUFFERS; i++) {
  1098. + if (!buffers[i].address)
  1099. + continue;
  1100. +
  1101. + dma_free_coherent(ipts->dev, data_buffer_size,
  1102. + buffers[i].address, buffers[i].dma_address);
  1103. +
  1104. + buffers[i].address = NULL;
  1105. + buffers[i].dma_address = 0;
  1106. + }
  1107. +
  1108. + buffers = ipts->feedback;
  1109. + for (i = 0; i < IPTS_BUFFERS; i++) {
  1110. + if (!buffers[i].address)
  1111. + continue;
  1112. +
  1113. + dma_free_coherent(ipts->dev, feedback_buffer_size,
  1114. + buffers[i].address, buffers[i].dma_address);
  1115. +
  1116. + buffers[i].address = NULL;
  1117. + buffers[i].dma_address = 0;
  1118. + }
  1119. +
  1120. + if (ipts->doorbell.address) {
  1121. + dma_free_coherent(ipts->dev, sizeof(u32),
  1122. + ipts->doorbell.address,
  1123. + ipts->doorbell.dma_address);
  1124. +
  1125. + ipts->doorbell.address = NULL;
  1126. + ipts->doorbell.dma_address = 0;
  1127. + }
  1128. +
  1129. + if (ipts->workqueue.address) {
  1130. + dma_free_coherent(ipts->dev, sizeof(u32),
  1131. + ipts->workqueue.address,
  1132. + ipts->workqueue.dma_address);
  1133. +
  1134. + ipts->workqueue.address = NULL;
  1135. + ipts->workqueue.dma_address = 0;
  1136. + }
  1137. +
  1138. + if (ipts->host2me.address) {
  1139. + dma_free_coherent(ipts->dev, feedback_buffer_size,
  1140. + ipts->host2me.address,
  1141. + ipts->host2me.dma_address);
  1142. +
  1143. + ipts->host2me.address = NULL;
  1144. + ipts->host2me.dma_address = 0;
  1145. + }
  1146. +}
  1147. +
  1148. +int ipts_resources_alloc(struct ipts_context *ipts)
  1149. +{
  1150. + int i;
  1151. + struct ipts_buffer_info *buffers;
  1152. +
  1153. + u32 data_buffer_size = ipts->device_info.data_size;
  1154. + u32 feedback_buffer_size = ipts->device_info.feedback_size;
  1155. +
  1156. + buffers = ipts->data;
  1157. + for (i = 0; i < IPTS_BUFFERS; i++) {
  1158. + buffers[i].address =
  1159. + dma_alloc_coherent(ipts->dev, data_buffer_size,
  1160. + &buffers[i].dma_address, GFP_KERNEL);
  1161. +
  1162. + if (!buffers[i].address)
  1163. + goto release_resources;
  1164. + }
  1165. +
  1166. + buffers = ipts->feedback;
  1167. + for (i = 0; i < IPTS_BUFFERS; i++) {
  1168. + buffers[i].address =
  1169. + dma_alloc_coherent(ipts->dev, feedback_buffer_size,
  1170. + &buffers[i].dma_address, GFP_KERNEL);
  1171. +
  1172. + if (!buffers[i].address)
  1173. + goto release_resources;
  1174. + }
  1175. +
  1176. + ipts->doorbell.address =
  1177. + dma_alloc_coherent(ipts->dev, sizeof(u32),
  1178. + &ipts->doorbell.dma_address, GFP_KERNEL);
  1179. +
  1180. + if (!ipts->doorbell.address)
  1181. + goto release_resources;
  1182. +
  1183. + ipts->workqueue.address =
  1184. + dma_alloc_coherent(ipts->dev, sizeof(u32),
  1185. + &ipts->workqueue.dma_address, GFP_KERNEL);
  1186. +
  1187. + if (!ipts->workqueue.address)
  1188. + goto release_resources;
  1189. +
  1190. + ipts->host2me.address =
  1191. + dma_alloc_coherent(ipts->dev, feedback_buffer_size,
  1192. + &ipts->host2me.dma_address, GFP_KERNEL);
  1193. +
  1194. + if (!ipts->workqueue.address)
  1195. + goto release_resources;
  1196. +
  1197. + return 0;
  1198. +
  1199. +release_resources:
  1200. +
  1201. + ipts_resources_free(ipts);
  1202. + return -ENOMEM;
  1203. +}
  1204. diff --git a/drivers/misc/ipts/resources.h b/drivers/misc/ipts/resources.h
  1205. new file mode 100644
  1206. index 000000000000..fdac0eee9156
  1207. --- /dev/null
  1208. +++ b/drivers/misc/ipts/resources.h
  1209. @@ -0,0 +1,17 @@
  1210. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  1211. +/*
  1212. + * Copyright (c) 2016 Intel Corporation
  1213. + * Copyright (c) 2020 Dorian Stoll
  1214. + *
  1215. + * Linux driver for Intel Precise Touch & Stylus
  1216. + */
  1217. +
  1218. +#ifndef _IPTS_RESOURCES_H_
  1219. +#define _IPTS_RESOURCES_H_
  1220. +
  1221. +#include "context.h"
  1222. +
  1223. +int ipts_resources_alloc(struct ipts_context *ipts);
  1224. +void ipts_resources_free(struct ipts_context *ipts);
  1225. +
  1226. +#endif /* _IPTS_RESOURCES_H_ */
  1227. diff --git a/drivers/misc/ipts/uapi.c b/drivers/misc/ipts/uapi.c
  1228. new file mode 100644
  1229. index 000000000000..598f0710ad64
  1230. --- /dev/null
  1231. +++ b/drivers/misc/ipts/uapi.c
  1232. @@ -0,0 +1,208 @@
  1233. +// SPDX-License-Identifier: GPL-2.0-or-later
  1234. +/*
  1235. + * Copyright (c) 2016 Intel Corporation
  1236. + * Copyright (c) 2020 Dorian Stoll
  1237. + *
  1238. + * Linux driver for Intel Precise Touch & Stylus
  1239. + */
  1240. +
  1241. +#include <linux/cdev.h>
  1242. +#include <linux/delay.h>
  1243. +#include <linux/device.h>
  1244. +#include <linux/fs.h>
  1245. +#include <linux/types.h>
  1246. +#include <linux/uaccess.h>
  1247. +
  1248. +#include "context.h"
  1249. +#include "control.h"
  1250. +#include "protocol.h"
  1251. +#include "uapi.h"
  1252. +
  1253. +struct ipts_uapi uapi;
  1254. +
  1255. +static ssize_t ipts_uapi_read(struct file *file, char __user *buf, size_t count,
  1256. + loff_t *offset)
  1257. +{
  1258. + int buffer;
  1259. + int maxbytes;
  1260. + struct ipts_context *ipts = uapi.ipts;
  1261. +
  1262. + buffer = MINOR(file->f_path.dentry->d_inode->i_rdev);
  1263. +
  1264. + if (!ipts || ipts->status != IPTS_HOST_STATUS_STARTED)
  1265. + return -ENODEV;
  1266. +
  1267. + maxbytes = ipts->device_info.data_size - *offset;
  1268. + if (maxbytes <= 0 || count > maxbytes)
  1269. + return -EINVAL;
  1270. +
  1271. + if (copy_to_user(buf, ipts->data[buffer].address + *offset, count))
  1272. + return -EFAULT;
  1273. +
  1274. + return count;
  1275. +}
  1276. +
  1277. +static long ipts_uapi_ioctl_get_device_ready(struct ipts_context *ipts,
  1278. + unsigned long arg)
  1279. +{
  1280. + void __user *buffer = (void __user *)arg;
  1281. + u8 ready = 0;
  1282. +
  1283. + if (ipts)
  1284. + ready = ipts->status == IPTS_HOST_STATUS_STARTED;
  1285. +
  1286. + if (copy_to_user(buffer, &ready, sizeof(u8)))
  1287. + return -EFAULT;
  1288. +
  1289. + return 0;
  1290. +}
  1291. +
  1292. +static long ipts_uapi_ioctl_get_device_info(struct ipts_context *ipts,
  1293. + unsigned long arg)
  1294. +{
  1295. + struct ipts_device_info info;
  1296. + void __user *buffer = (void __user *)arg;
  1297. +
  1298. + if (!ipts || ipts->status != IPTS_HOST_STATUS_STARTED)
  1299. + return -ENODEV;
  1300. +
  1301. + info.vendor = ipts->device_info.vendor_id;
  1302. + info.product = ipts->device_info.device_id;
  1303. + info.version = ipts->device_info.fw_rev;
  1304. + info.buffer_size = ipts->device_info.data_size;
  1305. + info.max_contacts = ipts->device_info.max_contacts;
  1306. +
  1307. + if (copy_to_user(buffer, &info, sizeof(struct ipts_device_info)))
  1308. + return -EFAULT;
  1309. +
  1310. + return 0;
  1311. +}
  1312. +
  1313. +static long ipts_uapi_ioctl_get_doorbell(struct ipts_context *ipts,
  1314. + unsigned long arg)
  1315. +{
  1316. + void __user *buffer = (void __user *)arg;
  1317. +
  1318. + if (!ipts || ipts->status != IPTS_HOST_STATUS_STARTED)
  1319. + return -ENODEV;
  1320. +
  1321. + if (copy_to_user(buffer, ipts->doorbell.address, sizeof(u32)))
  1322. + return -EFAULT;
  1323. +
  1324. + return 0;
  1325. +}
  1326. +
  1327. +static long ipts_uapi_ioctl_send_feedback(struct ipts_context *ipts,
  1328. + struct file *file)
  1329. +{
  1330. + int ret;
  1331. + u32 buffer;
  1332. +
  1333. + if (!ipts || ipts->status != IPTS_HOST_STATUS_STARTED)
  1334. + return -ENODEV;
  1335. +
  1336. + buffer = MINOR(file->f_path.dentry->d_inode->i_rdev);
  1337. +
  1338. + ret = ipts_control_send_feedback(ipts, buffer);
  1339. + if (ret)
  1340. + return -EFAULT;
  1341. +
  1342. + return 0;
  1343. +}
  1344. +
  1345. +static long ipts_uapi_ioctl_send_reset(struct ipts_context *ipts)
  1346. +{
  1347. + int ret;
  1348. + struct ipts_reset_sensor_cmd cmd;
  1349. +
  1350. + if (!ipts || ipts->status != IPTS_HOST_STATUS_STARTED)
  1351. + return -ENODEV;
  1352. +
  1353. + memset(&cmd, 0, sizeof(struct ipts_reset_sensor_cmd));
  1354. + cmd.type = IPTS_RESET_TYPE_SOFT;
  1355. +
  1356. + ret = ipts_control_send(ipts, IPTS_CMD_RESET_SENSOR, &cmd,
  1357. + sizeof(struct ipts_reset_sensor_cmd));
  1358. +
  1359. + if (ret)
  1360. + return -EFAULT;
  1361. +
  1362. + return 0;
  1363. +}
  1364. +
  1365. +static long ipts_uapi_ioctl(struct file *file, unsigned int cmd,
  1366. + unsigned long arg)
  1367. +{
  1368. + struct ipts_context *ipts = uapi.ipts;
  1369. +
  1370. + switch (cmd) {
  1371. + case IPTS_IOCTL_GET_DEVICE_READY:
  1372. + return ipts_uapi_ioctl_get_device_ready(ipts, arg);
  1373. + case IPTS_IOCTL_GET_DEVICE_INFO:
  1374. + return ipts_uapi_ioctl_get_device_info(ipts, arg);
  1375. + case IPTS_IOCTL_GET_DOORBELL:
  1376. + return ipts_uapi_ioctl_get_doorbell(ipts, arg);
  1377. + case IPTS_IOCTL_SEND_FEEDBACK:
  1378. + return ipts_uapi_ioctl_send_feedback(ipts, file);
  1379. + case IPTS_IOCTL_SEND_RESET:
  1380. + return ipts_uapi_ioctl_send_reset(ipts);
  1381. + default:
  1382. + return -ENOTTY;
  1383. + }
  1384. +}
  1385. +
  1386. +static const struct file_operations ipts_uapi_fops = {
  1387. + .owner = THIS_MODULE,
  1388. + .read = ipts_uapi_read,
  1389. + .unlocked_ioctl = ipts_uapi_ioctl,
  1390. +#ifdef CONFIG_COMPAT
  1391. + .compat_ioctl = ipts_uapi_ioctl,
  1392. +#endif
  1393. +};
  1394. +
  1395. +void ipts_uapi_link(struct ipts_context *ipts)
  1396. +{
  1397. + uapi.ipts = ipts;
  1398. +}
  1399. +
  1400. +void ipts_uapi_unlink(void)
  1401. +{
  1402. + uapi.ipts = NULL;
  1403. +}
  1404. +
  1405. +int ipts_uapi_init(void)
  1406. +{
  1407. + int i, major;
  1408. +
  1409. + alloc_chrdev_region(&uapi.dev, 0, IPTS_BUFFERS, "ipts");
  1410. + uapi.class = class_create(THIS_MODULE, "ipts");
  1411. +
  1412. + major = MAJOR(uapi.dev);
  1413. +
  1414. + cdev_init(&uapi.cdev, &ipts_uapi_fops);
  1415. + uapi.cdev.owner = THIS_MODULE;
  1416. + cdev_add(&uapi.cdev, MKDEV(major, 0), IPTS_BUFFERS);
  1417. +
  1418. + for (i = 0; i < IPTS_BUFFERS; i++) {
  1419. + device_create(uapi.class, NULL, MKDEV(major, i), NULL,
  1420. + "ipts/%d", i);
  1421. + }
  1422. +
  1423. + return 0;
  1424. +}
  1425. +
  1426. +void ipts_uapi_free(void)
  1427. +{
  1428. + int i;
  1429. + int major;
  1430. +
  1431. + major = MAJOR(uapi.dev);
  1432. +
  1433. + for (i = 0; i < IPTS_BUFFERS; i++)
  1434. + device_destroy(uapi.class, MKDEV(major, i));
  1435. +
  1436. + cdev_del(&uapi.cdev);
  1437. +
  1438. + unregister_chrdev_region(MKDEV(major, 0), MINORMASK);
  1439. + class_destroy(uapi.class);
  1440. +}
  1441. diff --git a/drivers/misc/ipts/uapi.h b/drivers/misc/ipts/uapi.h
  1442. new file mode 100644
  1443. index 000000000000..53fb86a88f97
  1444. --- /dev/null
  1445. +++ b/drivers/misc/ipts/uapi.h
  1446. @@ -0,0 +1,47 @@
  1447. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  1448. +/*
  1449. + * Copyright (c) 2016 Intel Corporation
  1450. + * Copyright (c) 2020 Dorian Stoll
  1451. + *
  1452. + * Linux driver for Intel Precise Touch & Stylus
  1453. + */
  1454. +
  1455. +#ifndef _IPTS_UAPI_H_
  1456. +#define _IPTS_UAPI_H_
  1457. +
  1458. +#include <linux/types.h>
  1459. +
  1460. +#include "context.h"
  1461. +
  1462. +struct ipts_uapi {
  1463. + dev_t dev;
  1464. + struct class *class;
  1465. + struct cdev cdev;
  1466. +
  1467. + struct ipts_context *ipts;
  1468. +};
  1469. +
  1470. +struct ipts_device_info {
  1471. + __u16 vendor;
  1472. + __u16 product;
  1473. + __u32 version;
  1474. + __u32 buffer_size;
  1475. + __u8 max_contacts;
  1476. +
  1477. + /* For future expansion */
  1478. + __u8 reserved[19];
  1479. +};
  1480. +
  1481. +#define IPTS_IOCTL_GET_DEVICE_READY _IOR(0x86, 0x01, __u8)
  1482. +#define IPTS_IOCTL_GET_DEVICE_INFO _IOR(0x86, 0x02, struct ipts_device_info)
  1483. +#define IPTS_IOCTL_GET_DOORBELL _IOR(0x86, 0x03, __u32)
  1484. +#define IPTS_IOCTL_SEND_FEEDBACK _IO(0x86, 0x04)
  1485. +#define IPTS_IOCTL_SEND_RESET _IO(0x86, 0x05)
  1486. +
  1487. +void ipts_uapi_link(struct ipts_context *ipts);
  1488. +void ipts_uapi_unlink(void);
  1489. +
  1490. +int ipts_uapi_init(void);
  1491. +void ipts_uapi_free(void);
  1492. +
  1493. +#endif /* _IPTS_UAPI_H_ */
  1494. --
  1495. 2.38.1
  1496. From 07bec5cb1bc6283d4ee40cd258e81f6065bd0fc2 Mon Sep 17 00:00:00 2001
  1497. From: Liban Hannan <liban.p@gmail.com>
  1498. Date: Tue, 12 Apr 2022 23:31:12 +0100
  1499. Subject: [PATCH] iommu: ipts: use IOMMU passthrough mode for IPTS
  1500. Adds a quirk so that IOMMU uses passthrough mode for the IPTS device.
  1501. Otherwise, when IOMMU is enabled, IPTS produces DMAR errors like:
  1502. DMAR: [DMA Read NO_PASID] Request device [00:16.4] fault addr
  1503. 0x104ea3000 [fault reason 0x06] PTE Read access is not set
  1504. This is very similar to the bug described at:
  1505. https://bugs.launchpad.net/bugs/1958004
  1506. Fixed with the following patch which this patch basically copies:
  1507. https://launchpadlibrarian.net/586396847/43255ca.diff
  1508. Patchset: ipts
  1509. ---
  1510. drivers/iommu/intel/iommu.c | 24 ++++++++++++++++++++++++
  1511. 1 file changed, 24 insertions(+)
  1512. diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
  1513. index ecc0b05b2796..4c895b5f7e2d 100644
  1514. --- a/drivers/iommu/intel/iommu.c
  1515. +++ b/drivers/iommu/intel/iommu.c
  1516. @@ -37,6 +37,8 @@
  1517. #define IS_GFX_DEVICE(pdev) ((pdev->class >> 16) == PCI_BASE_CLASS_DISPLAY)
  1518. #define IS_USB_DEVICE(pdev) ((pdev->class >> 8) == PCI_CLASS_SERIAL_USB)
  1519. #define IS_ISA_DEVICE(pdev) ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA)
  1520. +#define IS_IPTS(pdev) ((pdev)->vendor == PCI_VENDOR_ID_INTEL && \
  1521. + ((pdev)->device == 0x9d3e))
  1522. #define IS_AZALIA(pdev) ((pdev)->vendor == 0x8086 && (pdev)->device == 0x3a3e)
  1523. #define IOAPIC_RANGE_START (0xfee00000)
  1524. @@ -281,12 +283,14 @@ int intel_iommu_enabled = 0;
  1525. EXPORT_SYMBOL_GPL(intel_iommu_enabled);
  1526. static int dmar_map_gfx = 1;
  1527. +static int dmar_map_ipts = 1;
  1528. static int intel_iommu_superpage = 1;
  1529. static int iommu_identity_mapping;
  1530. static int iommu_skip_te_disable;
  1531. #define IDENTMAP_GFX 2
  1532. #define IDENTMAP_AZALIA 4
  1533. +#define IDENTMAP_IPTS 16
  1534. const struct iommu_ops intel_iommu_ops;
  1535. @@ -2603,6 +2607,9 @@ static int device_def_domain_type(struct device *dev)
  1536. if ((iommu_identity_mapping & IDENTMAP_GFX) && IS_GFX_DEVICE(pdev))
  1537. return IOMMU_DOMAIN_IDENTITY;
  1538. +
  1539. + if ((iommu_identity_mapping & IDENTMAP_IPTS) && IS_IPTS(pdev))
  1540. + return IOMMU_DOMAIN_IDENTITY;
  1541. }
  1542. return 0;
  1543. @@ -2992,6 +2999,9 @@ static int __init init_dmars(void)
  1544. if (!dmar_map_gfx)
  1545. iommu_identity_mapping |= IDENTMAP_GFX;
  1546. + if (!dmar_map_ipts)
  1547. + iommu_identity_mapping |= IDENTMAP_IPTS;
  1548. +
  1549. check_tylersburg_isoch();
  1550. ret = si_domain_init(hw_pass_through);
  1551. @@ -4793,6 +4803,17 @@ static void quirk_iommu_igfx(struct pci_dev *dev)
  1552. dmar_map_gfx = 0;
  1553. }
  1554. +static void quirk_iommu_ipts(struct pci_dev *dev)
  1555. +{
  1556. + if (!IS_IPTS(dev))
  1557. + return;
  1558. +
  1559. + if (risky_device(dev))
  1560. + return;
  1561. +
  1562. + pci_info(dev, "Passthrough IOMMU for IPTS\n");
  1563. + dmar_map_ipts = 0;
  1564. +}
  1565. /* G4x/GM45 integrated gfx dmar support is totally busted. */
  1566. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2a40, quirk_iommu_igfx);
  1567. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2e00, quirk_iommu_igfx);
  1568. @@ -4828,6 +4849,9 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x1632, quirk_iommu_igfx);
  1569. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x163A, quirk_iommu_igfx);
  1570. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x163D, quirk_iommu_igfx);
  1571. +/* disable IPTS dmar support */
  1572. +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9D3E, quirk_iommu_ipts);
  1573. +
  1574. static void quirk_iommu_rwbf(struct pci_dev *dev)
  1575. {
  1576. if (risky_device(dev))
  1577. --
  1578. 2.38.1