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
;
82 struct ocxl_process_element
{
91 __be32 software_state
;
95 extern struct ocxl_afu
*ocxl_afu_get(struct ocxl_afu
*afu
);
96 extern void ocxl_afu_put(struct ocxl_afu
*afu
);
98 extern int ocxl_create_cdev(struct ocxl_afu
*afu
);
99 extern void ocxl_destroy_cdev(struct ocxl_afu
*afu
);
100 extern int ocxl_register_afu(struct ocxl_afu
*afu
);
101 extern void ocxl_unregister_afu(struct ocxl_afu
*afu
);
103 extern int ocxl_file_init(void);
104 extern void ocxl_file_exit(void);
106 extern int ocxl_pasid_afu_alloc(struct ocxl_fn
*fn
, u32 size
);
107 extern void ocxl_pasid_afu_free(struct ocxl_fn
*fn
, u32 start
, u32 size
);
108 extern int ocxl_actag_afu_alloc(struct ocxl_fn
*fn
, u32 size
);
109 extern void ocxl_actag_afu_free(struct ocxl_fn
*fn
, u32 start
, u32 size
);
111 extern struct ocxl_context
*ocxl_context_alloc(void);
112 extern int ocxl_context_init(struct ocxl_context
*ctx
, struct ocxl_afu
*afu
,
113 struct address_space
*mapping
);
114 extern int ocxl_context_attach(struct ocxl_context
*ctx
, u64 amr
);
115 extern int ocxl_context_mmap(struct ocxl_context
*ctx
,
116 struct vm_area_struct
*vma
);
117 extern int ocxl_context_detach(struct ocxl_context
*ctx
);
118 extern void ocxl_context_detach_all(struct ocxl_afu
*afu
);
119 extern void ocxl_context_free(struct ocxl_context
*ctx
);
121 extern int ocxl_sysfs_add_afu(struct ocxl_afu
*afu
);
122 extern void ocxl_sysfs_remove_afu(struct ocxl_afu
*afu
);
124 extern int ocxl_afu_irq_alloc(struct ocxl_context
*ctx
, u64
*irq_offset
);
125 extern int ocxl_afu_irq_free(struct ocxl_context
*ctx
, u64 irq_offset
);
126 extern void ocxl_afu_irq_free_all(struct ocxl_context
*ctx
);
127 extern int ocxl_afu_irq_set_fd(struct ocxl_context
*ctx
, u64 irq_offset
,
129 extern u64
ocxl_afu_irq_get_addr(struct ocxl_context
*ctx
, u64 irq_offset
);
131 #endif /* _OCXL_INTERNAL_H_ */