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