1 // SPDX-License-Identifier: GPL-2.0+
2 // Copyright 2017 IBM Corp.
3 #ifndef _OCXL_INTERNAL_H_
4 #define _OCXL_INTERNAL_H_
7 #include <linux/cdev.h>
8 #include <linux/list.h>
11 #define MAX_IRQ_PER_LINK 2000
12 #define MAX_IRQ_PER_CONTEXT MAX_IRQ_PER_LINK
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)
17 extern struct pci_driver ocxl_pci_driver;
23 struct ocxl_fn_config config;
24 struct list_head afu_list;
29 struct list_head pasid_list;
30 struct list_head actag_list;
36 struct list_head list;
39 struct ocxl_afu_config config;
41 int pasid_count; /* opened contexts */
42 int pasid_max; /* maximum number of contexts */
45 struct mutex contexts_lock;
46 struct idr contexts_idr;
47 struct mutex afu_control_lock;
48 u64 global_mmio_start;
50 void __iomem *global_mmio_ptr;
52 struct bin_attribute attr_global_mmio;
55 enum ocxl_context_status {
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
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;
80 u16 tidr; // Thread ID used for P9 wait implementation
83 struct ocxl_process_element {
92 __be32 software_state;
96 extern struct ocxl_afu *ocxl_afu_get(struct ocxl_afu *afu);
97 extern void ocxl_afu_put(struct ocxl_afu *afu);
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);
104 extern int ocxl_file_init(void);
105 extern void ocxl_file_exit(void);
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);
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);
122 extern int ocxl_sysfs_add_afu(struct ocxl_afu *afu);
123 extern void ocxl_sysfs_remove_afu(struct ocxl_afu *afu);
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,
130 extern u64 ocxl_afu_irq_get_addr(struct ocxl_context *ctx, u64 irq_offset);
132 #endif /* _OCXL_INTERNAL_H_ */