ocxl_internal.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // SPDX-License-Identifier: GPL-2.0+
  2. // Copyright 2017 IBM Corp.
  3. #ifndef _OCXL_INTERNAL_H_
  4. #define _OCXL_INTERNAL_H_
  5. #include <linux/pci.h>
  6. #include <linux/cdev.h>
  7. #include <linux/list.h>
  8. #include <misc/ocxl.h>
  9. #define MAX_IRQ_PER_LINK 2000
  10. #define MAX_IRQ_PER_CONTEXT MAX_IRQ_PER_LINK
  11. #define to_ocxl_function(d) container_of(d, struct ocxl_fn, dev)
  12. #define to_ocxl_afu(d) container_of(d, struct ocxl_afu, dev)
  13. extern struct pci_driver ocxl_pci_driver;
  14. struct ocxl_fn {
  15. struct device dev;
  16. int bar_used[3];
  17. struct ocxl_fn_config config;
  18. struct list_head afu_list;
  19. int pasid_base;
  20. int actag_base;
  21. int actag_enabled;
  22. int actag_supported;
  23. struct list_head pasid_list;
  24. struct list_head actag_list;
  25. void *link;
  26. };
  27. struct ocxl_afu {
  28. struct ocxl_fn *fn;
  29. struct list_head list;
  30. struct device dev;
  31. struct cdev cdev;
  32. struct ocxl_afu_config config;
  33. int pasid_base;
  34. int pasid_count; /* opened contexts */
  35. int pasid_max; /* maximum number of contexts */
  36. int actag_base;
  37. int actag_enabled;
  38. struct mutex contexts_lock;
  39. struct idr contexts_idr;
  40. struct mutex afu_control_lock;
  41. u64 global_mmio_start;
  42. u64 irq_base_offset;
  43. void __iomem *global_mmio_ptr;
  44. u64 pp_mmio_start;
  45. struct bin_attribute attr_global_mmio;
  46. };
  47. enum ocxl_context_status {
  48. CLOSED,
  49. OPENED,
  50. ATTACHED,
  51. };
  52. // Contains metadata about a translation fault
  53. struct ocxl_xsl_error {
  54. u64 addr; // The address that triggered the fault
  55. u64 dsisr; // the value of the dsisr register
  56. u64 count; // The number of times this fault has been triggered
  57. };
  58. struct ocxl_context {
  59. struct ocxl_afu *afu;
  60. int pasid;
  61. struct mutex status_mutex;
  62. enum ocxl_context_status status;
  63. struct address_space *mapping;
  64. struct mutex mapping_lock;
  65. wait_queue_head_t events_wq;
  66. struct mutex xsl_error_lock;
  67. struct ocxl_xsl_error xsl_error;
  68. struct mutex irq_lock;
  69. struct idr irq_idr;
  70. u16 tidr; // Thread ID used for P9 wait implementation
  71. };
  72. struct ocxl_process_element {
  73. __be64 config_state;
  74. __be32 reserved1[11];
  75. __be32 lpid;
  76. __be32 tid;
  77. __be32 pid;
  78. __be32 reserved2[10];
  79. __be64 amr;
  80. __be32 reserved3[3];
  81. __be32 software_state;
  82. };
  83. extern struct ocxl_afu *ocxl_afu_get(struct ocxl_afu *afu);
  84. extern void ocxl_afu_put(struct ocxl_afu *afu);
  85. extern int ocxl_create_cdev(struct ocxl_afu *afu);
  86. extern void ocxl_destroy_cdev(struct ocxl_afu *afu);
  87. extern int ocxl_register_afu(struct ocxl_afu *afu);
  88. extern void ocxl_unregister_afu(struct ocxl_afu *afu);
  89. extern int ocxl_file_init(void);
  90. extern void ocxl_file_exit(void);
  91. extern int ocxl_pasid_afu_alloc(struct ocxl_fn *fn, u32 size);
  92. extern void ocxl_pasid_afu_free(struct ocxl_fn *fn, u32 start, u32 size);
  93. extern int ocxl_actag_afu_alloc(struct ocxl_fn *fn, u32 size);
  94. extern void ocxl_actag_afu_free(struct ocxl_fn *fn, u32 start, u32 size);
  95. extern struct ocxl_context *ocxl_context_alloc(void);
  96. extern int ocxl_context_init(struct ocxl_context *ctx, struct ocxl_afu *afu,
  97. struct address_space *mapping);
  98. extern int ocxl_context_attach(struct ocxl_context *ctx, u64 amr);
  99. extern int ocxl_context_mmap(struct ocxl_context *ctx,
  100. struct vm_area_struct *vma);
  101. extern int ocxl_context_detach(struct ocxl_context *ctx);
  102. extern void ocxl_context_detach_all(struct ocxl_afu *afu);
  103. extern void ocxl_context_free(struct ocxl_context *ctx);
  104. extern int ocxl_sysfs_add_afu(struct ocxl_afu *afu);
  105. extern void ocxl_sysfs_remove_afu(struct ocxl_afu *afu);
  106. extern int ocxl_afu_irq_alloc(struct ocxl_context *ctx, u64 *irq_offset);
  107. extern int ocxl_afu_irq_free(struct ocxl_context *ctx, u64 irq_offset);
  108. extern void ocxl_afu_irq_free_all(struct ocxl_context *ctx);
  109. extern int ocxl_afu_irq_set_fd(struct ocxl_context *ctx, u64 irq_offset,
  110. int eventfd);
  111. extern u64 ocxl_afu_irq_get_addr(struct ocxl_context *ctx, u64 irq_offset);
  112. #endif /* _OCXL_INTERNAL_H_ */