cxllib.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright 2017 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. #ifndef _MISC_CXLLIB_H
  10. #define _MISC_CXLLIB_H
  11. #include <linux/pci.h>
  12. #include <asm/reg.h>
  13. /*
  14. * cxl driver exports a in-kernel 'library' API which can be called by
  15. * other drivers to help interacting with an IBM XSL.
  16. */
  17. /*
  18. * tells whether capi is supported on the PCIe slot where the
  19. * device is seated
  20. *
  21. * Input:
  22. * dev: device whose slot needs to be checked
  23. * flags: 0 for the time being
  24. */
  25. bool cxllib_slot_is_supported(struct pci_dev *dev, unsigned long flags);
  26. /*
  27. * Returns the configuration parameters to be used by the XSL or device
  28. *
  29. * Input:
  30. * dev: device, used to find PHB
  31. * Output:
  32. * struct cxllib_xsl_config:
  33. * version
  34. * capi BAR address, i.e. 0x2000000000000-0x2FFFFFFFFFFFF
  35. * capi BAR size
  36. * data send control (XSL_DSNCTL)
  37. * dummy read address (XSL_DRA)
  38. */
  39. #define CXL_XSL_CONFIG_VERSION1 1
  40. struct cxllib_xsl_config {
  41. u32 version; /* format version for register encoding */
  42. u32 log_bar_size;/* log size of the capi_window */
  43. u64 bar_addr; /* address of the start of capi window */
  44. u64 dsnctl; /* matches definition of XSL_DSNCTL */
  45. u64 dra; /* real address that can be used for dummy read */
  46. };
  47. int cxllib_get_xsl_config(struct pci_dev *dev, struct cxllib_xsl_config *cfg);
  48. /*
  49. * Activate capi for the pci host bridge associated with the device.
  50. * Can be extended to deactivate once we know how to do it.
  51. * Device must be ready to accept messages from the CAPP unit and
  52. * respond accordingly (TLB invalidates, ...)
  53. *
  54. * PHB is switched to capi mode through calls to skiboot.
  55. * CAPP snooping is activated
  56. *
  57. * Input:
  58. * dev: device whose PHB should switch mode
  59. * mode: mode to switch to i.e. CAPI or PCI
  60. * flags: options related to the mode
  61. */
  62. enum cxllib_mode {
  63. CXL_MODE_CXL,
  64. CXL_MODE_PCI,
  65. };
  66. #define CXL_MODE_NO_DMA 0
  67. #define CXL_MODE_DMA_TVT0 1
  68. #define CXL_MODE_DMA_TVT1 2
  69. int cxllib_switch_phb_mode(struct pci_dev *dev, enum cxllib_mode mode,
  70. unsigned long flags);
  71. /*
  72. * Set the device for capi DMA.
  73. * Define its dma_ops and dma offset so that allocations will be using TVT#1
  74. *
  75. * Input:
  76. * dev: device to set
  77. * flags: options. CXL_MODE_DMA_TVT1 should be used
  78. */
  79. int cxllib_set_device_dma(struct pci_dev *dev, unsigned long flags);
  80. /*
  81. * Get the Process Element structure for the given thread
  82. *
  83. * Input:
  84. * task: task_struct for the context of the translation
  85. * translation_mode: whether addresses should be translated
  86. * Output:
  87. * attr: attributes to fill up the Process Element structure from CAIA
  88. */
  89. struct cxllib_pe_attributes {
  90. u64 sr;
  91. u32 lpid;
  92. u32 tid;
  93. u32 pid;
  94. };
  95. #define CXL_TRANSLATED_MODE 0
  96. #define CXL_REAL_MODE 1
  97. int cxllib_get_PE_attributes(struct task_struct *task,
  98. unsigned long translation_mode, struct cxllib_pe_attributes *attr);
  99. /*
  100. * Handle memory fault.
  101. * Fault in all the pages of the specified buffer for the permissions
  102. * provided in ‘flags’
  103. *
  104. * Shouldn't be called from interrupt context
  105. *
  106. * Input:
  107. * mm: struct mm for the thread faulting the pages
  108. * addr: base address of the buffer to page in
  109. * size: size of the buffer to page in
  110. * flags: permission requested (DSISR_ISSTORE...)
  111. */
  112. int cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags);
  113. #endif /* _MISC_CXLLIB_H */