api.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /*
  2. * Copyright 2014 IBM Corp.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/pci.h>
  10. #include <linux/slab.h>
  11. #include <linux/file.h>
  12. #include <misc/cxl.h>
  13. #include <linux/msi.h>
  14. #include <linux/module.h>
  15. #include <linux/mount.h>
  16. #include <linux/sched/mm.h>
  17. #include <linux/mmu_context.h>
  18. #include "cxl.h"
  19. /*
  20. * Since we want to track memory mappings to be able to force-unmap
  21. * when the AFU is no longer reachable, we need an inode. For devices
  22. * opened through the cxl user API, this is not a problem, but a
  23. * userland process can also get a cxl fd through the cxl_get_fd()
  24. * API, which is used by the cxlflash driver.
  25. *
  26. * Therefore we implement our own simple pseudo-filesystem and inode
  27. * allocator. We don't use the anonymous inode, as we need the
  28. * meta-data associated with it (address_space) and it is shared by
  29. * other drivers/processes, so it could lead to cxl unmapping VMAs
  30. * from random processes.
  31. */
  32. #define CXL_PSEUDO_FS_MAGIC 0x1697697f
  33. static int cxl_fs_cnt;
  34. static struct vfsmount *cxl_vfs_mount;
  35. static const struct dentry_operations cxl_fs_dops = {
  36. .d_dname = simple_dname,
  37. };
  38. static struct dentry *cxl_fs_mount(struct file_system_type *fs_type, int flags,
  39. const char *dev_name, void *data)
  40. {
  41. return mount_pseudo(fs_type, "cxl:", NULL, &cxl_fs_dops,
  42. CXL_PSEUDO_FS_MAGIC);
  43. }
  44. static struct file_system_type cxl_fs_type = {
  45. .name = "cxl",
  46. .owner = THIS_MODULE,
  47. .mount = cxl_fs_mount,
  48. .kill_sb = kill_anon_super,
  49. };
  50. void cxl_release_mapping(struct cxl_context *ctx)
  51. {
  52. if (ctx->kernelapi && ctx->mapping)
  53. simple_release_fs(&cxl_vfs_mount, &cxl_fs_cnt);
  54. }
  55. static struct file *cxl_getfile(const char *name,
  56. const struct file_operations *fops,
  57. void *priv, int flags)
  58. {
  59. struct file *file;
  60. struct inode *inode;
  61. int rc;
  62. /* strongly inspired by anon_inode_getfile() */
  63. if (fops->owner && !try_module_get(fops->owner))
  64. return ERR_PTR(-ENOENT);
  65. rc = simple_pin_fs(&cxl_fs_type, &cxl_vfs_mount, &cxl_fs_cnt);
  66. if (rc < 0) {
  67. pr_err("Cannot mount cxl pseudo filesystem: %d\n", rc);
  68. file = ERR_PTR(rc);
  69. goto err_module;
  70. }
  71. inode = alloc_anon_inode(cxl_vfs_mount->mnt_sb);
  72. if (IS_ERR(inode)) {
  73. file = ERR_CAST(inode);
  74. goto err_fs;
  75. }
  76. file = alloc_file_pseudo(inode, cxl_vfs_mount, name,
  77. flags & (O_ACCMODE | O_NONBLOCK), fops);
  78. if (IS_ERR(file))
  79. goto err_inode;
  80. file->private_data = priv;
  81. return file;
  82. err_inode:
  83. iput(inode);
  84. err_fs:
  85. simple_release_fs(&cxl_vfs_mount, &cxl_fs_cnt);
  86. err_module:
  87. module_put(fops->owner);
  88. return file;
  89. }
  90. struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
  91. {
  92. struct cxl_afu *afu;
  93. struct cxl_context *ctx;
  94. int rc;
  95. afu = cxl_pci_to_afu(dev);
  96. if (IS_ERR(afu))
  97. return ERR_CAST(afu);
  98. ctx = cxl_context_alloc();
  99. if (!ctx)
  100. return ERR_PTR(-ENOMEM);
  101. ctx->kernelapi = true;
  102. /* Make it a slave context. We can promote it later? */
  103. rc = cxl_context_init(ctx, afu, false);
  104. if (rc)
  105. goto err_ctx;
  106. return ctx;
  107. err_ctx:
  108. kfree(ctx);
  109. return ERR_PTR(rc);
  110. }
  111. EXPORT_SYMBOL_GPL(cxl_dev_context_init);
  112. struct cxl_context *cxl_get_context(struct pci_dev *dev)
  113. {
  114. return dev->dev.archdata.cxl_ctx;
  115. }
  116. EXPORT_SYMBOL_GPL(cxl_get_context);
  117. int cxl_release_context(struct cxl_context *ctx)
  118. {
  119. if (ctx->status >= STARTED)
  120. return -EBUSY;
  121. cxl_context_free(ctx);
  122. return 0;
  123. }
  124. EXPORT_SYMBOL_GPL(cxl_release_context);
  125. static irq_hw_number_t cxl_find_afu_irq(struct cxl_context *ctx, int num)
  126. {
  127. __u16 range;
  128. int r;
  129. for (r = 0; r < CXL_IRQ_RANGES; r++) {
  130. range = ctx->irqs.range[r];
  131. if (num < range) {
  132. return ctx->irqs.offset[r] + num;
  133. }
  134. num -= range;
  135. }
  136. return 0;
  137. }
  138. int _cxl_next_msi_hwirq(struct pci_dev *pdev, struct cxl_context **ctx, int *afu_irq)
  139. {
  140. if (*ctx == NULL || *afu_irq == 0) {
  141. *afu_irq = 1;
  142. *ctx = cxl_get_context(pdev);
  143. } else {
  144. (*afu_irq)++;
  145. if (*afu_irq > cxl_get_max_irqs_per_process(pdev)) {
  146. *ctx = list_next_entry(*ctx, extra_irq_contexts);
  147. *afu_irq = 1;
  148. }
  149. }
  150. return cxl_find_afu_irq(*ctx, *afu_irq);
  151. }
  152. /* Exported via cxl_base */
  153. int cxl_set_priv(struct cxl_context *ctx, void *priv)
  154. {
  155. if (!ctx)
  156. return -EINVAL;
  157. ctx->priv = priv;
  158. return 0;
  159. }
  160. EXPORT_SYMBOL_GPL(cxl_set_priv);
  161. void *cxl_get_priv(struct cxl_context *ctx)
  162. {
  163. if (!ctx)
  164. return ERR_PTR(-EINVAL);
  165. return ctx->priv;
  166. }
  167. EXPORT_SYMBOL_GPL(cxl_get_priv);
  168. int cxl_allocate_afu_irqs(struct cxl_context *ctx, int num)
  169. {
  170. int res;
  171. irq_hw_number_t hwirq;
  172. if (num == 0)
  173. num = ctx->afu->pp_irqs;
  174. res = afu_allocate_irqs(ctx, num);
  175. if (res)
  176. return res;
  177. if (!cpu_has_feature(CPU_FTR_HVMODE)) {
  178. /* In a guest, the PSL interrupt is not multiplexed. It was
  179. * allocated above, and we need to set its handler
  180. */
  181. hwirq = cxl_find_afu_irq(ctx, 0);
  182. if (hwirq)
  183. cxl_map_irq(ctx->afu->adapter, hwirq, cxl_ops->psl_interrupt, ctx, "psl");
  184. }
  185. if (ctx->status == STARTED) {
  186. if (cxl_ops->update_ivtes)
  187. cxl_ops->update_ivtes(ctx);
  188. else WARN(1, "BUG: cxl_allocate_afu_irqs must be called prior to starting the context on this platform\n");
  189. }
  190. return res;
  191. }
  192. EXPORT_SYMBOL_GPL(cxl_allocate_afu_irqs);
  193. void cxl_free_afu_irqs(struct cxl_context *ctx)
  194. {
  195. irq_hw_number_t hwirq;
  196. unsigned int virq;
  197. if (!cpu_has_feature(CPU_FTR_HVMODE)) {
  198. hwirq = cxl_find_afu_irq(ctx, 0);
  199. if (hwirq) {
  200. virq = irq_find_mapping(NULL, hwirq);
  201. if (virq)
  202. cxl_unmap_irq(virq, ctx);
  203. }
  204. }
  205. afu_irq_name_free(ctx);
  206. cxl_ops->release_irq_ranges(&ctx->irqs, ctx->afu->adapter);
  207. }
  208. EXPORT_SYMBOL_GPL(cxl_free_afu_irqs);
  209. int cxl_map_afu_irq(struct cxl_context *ctx, int num,
  210. irq_handler_t handler, void *cookie, char *name)
  211. {
  212. irq_hw_number_t hwirq;
  213. /*
  214. * Find interrupt we are to register.
  215. */
  216. hwirq = cxl_find_afu_irq(ctx, num);
  217. if (!hwirq)
  218. return -ENOENT;
  219. return cxl_map_irq(ctx->afu->adapter, hwirq, handler, cookie, name);
  220. }
  221. EXPORT_SYMBOL_GPL(cxl_map_afu_irq);
  222. void cxl_unmap_afu_irq(struct cxl_context *ctx, int num, void *cookie)
  223. {
  224. irq_hw_number_t hwirq;
  225. unsigned int virq;
  226. hwirq = cxl_find_afu_irq(ctx, num);
  227. if (!hwirq)
  228. return;
  229. virq = irq_find_mapping(NULL, hwirq);
  230. if (virq)
  231. cxl_unmap_irq(virq, cookie);
  232. }
  233. EXPORT_SYMBOL_GPL(cxl_unmap_afu_irq);
  234. /*
  235. * Start a context
  236. * Code here similar to afu_ioctl_start_work().
  237. */
  238. int cxl_start_context(struct cxl_context *ctx, u64 wed,
  239. struct task_struct *task)
  240. {
  241. int rc = 0;
  242. bool kernel = true;
  243. pr_devel("%s: pe: %i\n", __func__, ctx->pe);
  244. mutex_lock(&ctx->status_mutex);
  245. if (ctx->status == STARTED)
  246. goto out; /* already started */
  247. /*
  248. * Increment the mapped context count for adapter. This also checks
  249. * if adapter_context_lock is taken.
  250. */
  251. rc = cxl_adapter_context_get(ctx->afu->adapter);
  252. if (rc)
  253. goto out;
  254. if (task) {
  255. ctx->pid = get_task_pid(task, PIDTYPE_PID);
  256. kernel = false;
  257. ctx->real_mode = false;
  258. /* acquire a reference to the task's mm */
  259. ctx->mm = get_task_mm(current);
  260. /* ensure this mm_struct can't be freed */
  261. cxl_context_mm_count_get(ctx);
  262. if (ctx->mm) {
  263. /* decrement the use count from above */
  264. mmput(ctx->mm);
  265. /* make TLBIs for this context global */
  266. mm_context_add_copro(ctx->mm);
  267. }
  268. }
  269. /*
  270. * Increment driver use count. Enables global TLBIs for hash
  271. * and callbacks to handle the segment table
  272. */
  273. cxl_ctx_get();
  274. /* See the comment in afu_ioctl_start_work() */
  275. smp_mb();
  276. if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) {
  277. put_pid(ctx->pid);
  278. ctx->pid = NULL;
  279. cxl_adapter_context_put(ctx->afu->adapter);
  280. cxl_ctx_put();
  281. if (task) {
  282. cxl_context_mm_count_put(ctx);
  283. if (ctx->mm)
  284. mm_context_remove_copro(ctx->mm);
  285. }
  286. goto out;
  287. }
  288. ctx->status = STARTED;
  289. out:
  290. mutex_unlock(&ctx->status_mutex);
  291. return rc;
  292. }
  293. EXPORT_SYMBOL_GPL(cxl_start_context);
  294. int cxl_process_element(struct cxl_context *ctx)
  295. {
  296. return ctx->external_pe;
  297. }
  298. EXPORT_SYMBOL_GPL(cxl_process_element);
  299. /* Stop a context. Returns 0 on success, otherwise -Errno */
  300. int cxl_stop_context(struct cxl_context *ctx)
  301. {
  302. return __detach_context(ctx);
  303. }
  304. EXPORT_SYMBOL_GPL(cxl_stop_context);
  305. void cxl_set_master(struct cxl_context *ctx)
  306. {
  307. ctx->master = true;
  308. }
  309. EXPORT_SYMBOL_GPL(cxl_set_master);
  310. int cxl_set_translation_mode(struct cxl_context *ctx, bool real_mode)
  311. {
  312. if (ctx->status == STARTED) {
  313. /*
  314. * We could potentially update the PE and issue an update LLCMD
  315. * to support this, but it doesn't seem to have a good use case
  316. * since it's trivial to just create a second kernel context
  317. * with different translation modes, so until someone convinces
  318. * me otherwise:
  319. */
  320. return -EBUSY;
  321. }
  322. ctx->real_mode = real_mode;
  323. return 0;
  324. }
  325. EXPORT_SYMBOL_GPL(cxl_set_translation_mode);
  326. /* wrappers around afu_* file ops which are EXPORTED */
  327. int cxl_fd_open(struct inode *inode, struct file *file)
  328. {
  329. return afu_open(inode, file);
  330. }
  331. EXPORT_SYMBOL_GPL(cxl_fd_open);
  332. int cxl_fd_release(struct inode *inode, struct file *file)
  333. {
  334. return afu_release(inode, file);
  335. }
  336. EXPORT_SYMBOL_GPL(cxl_fd_release);
  337. long cxl_fd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  338. {
  339. return afu_ioctl(file, cmd, arg);
  340. }
  341. EXPORT_SYMBOL_GPL(cxl_fd_ioctl);
  342. int cxl_fd_mmap(struct file *file, struct vm_area_struct *vm)
  343. {
  344. return afu_mmap(file, vm);
  345. }
  346. EXPORT_SYMBOL_GPL(cxl_fd_mmap);
  347. __poll_t cxl_fd_poll(struct file *file, struct poll_table_struct *poll)
  348. {
  349. return afu_poll(file, poll);
  350. }
  351. EXPORT_SYMBOL_GPL(cxl_fd_poll);
  352. ssize_t cxl_fd_read(struct file *file, char __user *buf, size_t count,
  353. loff_t *off)
  354. {
  355. return afu_read(file, buf, count, off);
  356. }
  357. EXPORT_SYMBOL_GPL(cxl_fd_read);
  358. #define PATCH_FOPS(NAME) if (!fops->NAME) fops->NAME = afu_fops.NAME
  359. /* Get a struct file and fd for a context and attach the ops */
  360. struct file *cxl_get_fd(struct cxl_context *ctx, struct file_operations *fops,
  361. int *fd)
  362. {
  363. struct file *file;
  364. int rc, flags, fdtmp;
  365. char *name = NULL;
  366. /* only allow one per context */
  367. if (ctx->mapping)
  368. return ERR_PTR(-EEXIST);
  369. flags = O_RDWR | O_CLOEXEC;
  370. /* This code is similar to anon_inode_getfd() */
  371. rc = get_unused_fd_flags(flags);
  372. if (rc < 0)
  373. return ERR_PTR(rc);
  374. fdtmp = rc;
  375. /*
  376. * Patch the file ops. Needs to be careful that this is rentrant safe.
  377. */
  378. if (fops) {
  379. PATCH_FOPS(open);
  380. PATCH_FOPS(poll);
  381. PATCH_FOPS(read);
  382. PATCH_FOPS(release);
  383. PATCH_FOPS(unlocked_ioctl);
  384. PATCH_FOPS(compat_ioctl);
  385. PATCH_FOPS(mmap);
  386. } else /* use default ops */
  387. fops = (struct file_operations *)&afu_fops;
  388. name = kasprintf(GFP_KERNEL, "cxl:%d", ctx->pe);
  389. file = cxl_getfile(name, fops, ctx, flags);
  390. kfree(name);
  391. if (IS_ERR(file))
  392. goto err_fd;
  393. cxl_context_set_mapping(ctx, file->f_mapping);
  394. *fd = fdtmp;
  395. return file;
  396. err_fd:
  397. put_unused_fd(fdtmp);
  398. return NULL;
  399. }
  400. EXPORT_SYMBOL_GPL(cxl_get_fd);
  401. struct cxl_context *cxl_fops_get_context(struct file *file)
  402. {
  403. return file->private_data;
  404. }
  405. EXPORT_SYMBOL_GPL(cxl_fops_get_context);
  406. void cxl_set_driver_ops(struct cxl_context *ctx,
  407. struct cxl_afu_driver_ops *ops)
  408. {
  409. WARN_ON(!ops->fetch_event || !ops->event_delivered);
  410. atomic_set(&ctx->afu_driver_events, 0);
  411. ctx->afu_driver_ops = ops;
  412. }
  413. EXPORT_SYMBOL_GPL(cxl_set_driver_ops);
  414. void cxl_context_events_pending(struct cxl_context *ctx,
  415. unsigned int new_events)
  416. {
  417. atomic_add(new_events, &ctx->afu_driver_events);
  418. wake_up_all(&ctx->wq);
  419. }
  420. EXPORT_SYMBOL_GPL(cxl_context_events_pending);
  421. int cxl_start_work(struct cxl_context *ctx,
  422. struct cxl_ioctl_start_work *work)
  423. {
  424. int rc;
  425. /* code taken from afu_ioctl_start_work */
  426. if (!(work->flags & CXL_START_WORK_NUM_IRQS))
  427. work->num_interrupts = ctx->afu->pp_irqs;
  428. else if ((work->num_interrupts < ctx->afu->pp_irqs) ||
  429. (work->num_interrupts > ctx->afu->irqs_max)) {
  430. return -EINVAL;
  431. }
  432. rc = afu_register_irqs(ctx, work->num_interrupts);
  433. if (rc)
  434. return rc;
  435. rc = cxl_start_context(ctx, work->work_element_descriptor, current);
  436. if (rc < 0) {
  437. afu_release_irqs(ctx, ctx);
  438. return rc;
  439. }
  440. return 0;
  441. }
  442. EXPORT_SYMBOL_GPL(cxl_start_work);
  443. void __iomem *cxl_psa_map(struct cxl_context *ctx)
  444. {
  445. if (ctx->status != STARTED)
  446. return NULL;
  447. pr_devel("%s: psn_phys%llx size:%llx\n",
  448. __func__, ctx->psn_phys, ctx->psn_size);
  449. return ioremap(ctx->psn_phys, ctx->psn_size);
  450. }
  451. EXPORT_SYMBOL_GPL(cxl_psa_map);
  452. void cxl_psa_unmap(void __iomem *addr)
  453. {
  454. iounmap(addr);
  455. }
  456. EXPORT_SYMBOL_GPL(cxl_psa_unmap);
  457. int cxl_afu_reset(struct cxl_context *ctx)
  458. {
  459. struct cxl_afu *afu = ctx->afu;
  460. int rc;
  461. rc = cxl_ops->afu_reset(afu);
  462. if (rc)
  463. return rc;
  464. return cxl_ops->afu_check_and_enable(afu);
  465. }
  466. EXPORT_SYMBOL_GPL(cxl_afu_reset);
  467. void cxl_perst_reloads_same_image(struct cxl_afu *afu,
  468. bool perst_reloads_same_image)
  469. {
  470. afu->adapter->perst_same_image = perst_reloads_same_image;
  471. }
  472. EXPORT_SYMBOL_GPL(cxl_perst_reloads_same_image);
  473. ssize_t cxl_read_adapter_vpd(struct pci_dev *dev, void *buf, size_t count)
  474. {
  475. struct cxl_afu *afu = cxl_pci_to_afu(dev);
  476. if (IS_ERR(afu))
  477. return -ENODEV;
  478. return cxl_ops->read_adapter_vpd(afu->adapter, buf, count);
  479. }
  480. EXPORT_SYMBOL_GPL(cxl_read_adapter_vpd);
  481. int cxl_set_max_irqs_per_process(struct pci_dev *dev, int irqs)
  482. {
  483. struct cxl_afu *afu = cxl_pci_to_afu(dev);
  484. if (IS_ERR(afu))
  485. return -ENODEV;
  486. if (irqs > afu->adapter->user_irqs)
  487. return -EINVAL;
  488. /* Limit user_irqs to prevent the user increasing this via sysfs */
  489. afu->adapter->user_irqs = irqs;
  490. afu->irqs_max = irqs;
  491. return 0;
  492. }
  493. EXPORT_SYMBOL_GPL(cxl_set_max_irqs_per_process);
  494. int cxl_get_max_irqs_per_process(struct pci_dev *dev)
  495. {
  496. struct cxl_afu *afu = cxl_pci_to_afu(dev);
  497. if (IS_ERR(afu))
  498. return -ENODEV;
  499. return afu->irqs_max;
  500. }
  501. EXPORT_SYMBOL_GPL(cxl_get_max_irqs_per_process);
  502. /*
  503. * This is a special interrupt allocation routine called from the PHB's MSI
  504. * setup function. When capi interrupts are allocated in this manner they must
  505. * still be associated with a running context, but since the MSI APIs have no
  506. * way to specify this we use the default context associated with the device.
  507. *
  508. * The Mellanox CX4 has a hardware limitation that restricts the maximum AFU
  509. * interrupt number, so in order to overcome this their driver informs us of
  510. * the restriction by setting the maximum interrupts per context, and we
  511. * allocate additional contexts as necessary so that we can keep the AFU
  512. * interrupt number within the supported range.
  513. */
  514. int _cxl_cx4_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
  515. {
  516. struct cxl_context *ctx, *new_ctx, *default_ctx;
  517. int remaining;
  518. int rc;
  519. ctx = default_ctx = cxl_get_context(pdev);
  520. if (WARN_ON(!default_ctx))
  521. return -ENODEV;
  522. remaining = nvec;
  523. while (remaining > 0) {
  524. rc = cxl_allocate_afu_irqs(ctx, min(remaining, ctx->afu->irqs_max));
  525. if (rc) {
  526. pr_warn("%s: Failed to find enough free MSIs\n", pci_name(pdev));
  527. return rc;
  528. }
  529. remaining -= ctx->afu->irqs_max;
  530. if (ctx != default_ctx && default_ctx->status == STARTED) {
  531. WARN_ON(cxl_start_context(ctx,
  532. be64_to_cpu(default_ctx->elem->common.wed),
  533. NULL));
  534. }
  535. if (remaining > 0) {
  536. new_ctx = cxl_dev_context_init(pdev);
  537. if (IS_ERR(new_ctx)) {
  538. pr_warn("%s: Failed to allocate enough contexts for MSIs\n", pci_name(pdev));
  539. return -ENOSPC;
  540. }
  541. list_add(&new_ctx->extra_irq_contexts, &ctx->extra_irq_contexts);
  542. ctx = new_ctx;
  543. }
  544. }
  545. return 0;
  546. }
  547. /* Exported via cxl_base */
  548. void _cxl_cx4_teardown_msi_irqs(struct pci_dev *pdev)
  549. {
  550. struct cxl_context *ctx, *pos, *tmp;
  551. ctx = cxl_get_context(pdev);
  552. if (WARN_ON(!ctx))
  553. return;
  554. cxl_free_afu_irqs(ctx);
  555. list_for_each_entry_safe(pos, tmp, &ctx->extra_irq_contexts, extra_irq_contexts) {
  556. cxl_stop_context(pos);
  557. cxl_free_afu_irqs(pos);
  558. list_del(&pos->extra_irq_contexts);
  559. cxl_release_context(pos);
  560. }
  561. }
  562. /* Exported via cxl_base */