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 extern struct pci_driver ocxl_pci_driver
;
19 struct ocxl_fn_config config
;
20 struct list_head afu_list
;
25 struct list_head pasid_list
;
26 struct list_head actag_list
;
30 struct ocxl_file_info
{
34 struct bin_attribute attr_global_mmio
;
40 struct list_head list
;
41 struct ocxl_afu_config config
;
43 int pasid_count
; /* opened contexts */
44 int pasid_max
; /* maximum number of contexts */
47 struct mutex contexts_lock
;
48 struct idr contexts_idr
;
49 struct mutex afu_control_lock
;
50 u64 global_mmio_start
;
52 void __iomem
*global_mmio_ptr
;
57 enum ocxl_context_status
{
63 // Contains metadata about a translation fault
64 struct ocxl_xsl_error
{
65 u64 addr
; // The address that triggered the fault
66 u64 dsisr
; // the value of the dsisr register
67 u64 count
; // The number of times this fault has been triggered
73 struct mutex status_mutex
;
74 enum ocxl_context_status status
;
75 struct address_space
*mapping
;
76 struct mutex mapping_lock
;
77 wait_queue_head_t events_wq
;
78 struct mutex xsl_error_lock
;
79 struct ocxl_xsl_error xsl_error
;
80 struct mutex irq_lock
;
82 u16 tidr
; // Thread ID used for P9 wait implementation
85 struct ocxl_process_element
{
94 __be32 software_state
;
97 int ocxl_create_cdev(struct ocxl_afu
*afu
);
98 void ocxl_destroy_cdev(struct ocxl_afu
*afu
);
99 int ocxl_file_register_afu(struct ocxl_afu
*afu
);
100 void ocxl_file_unregister_afu(struct ocxl_afu
*afu
);
102 int ocxl_file_init(void);
103 void ocxl_file_exit(void);
105 int ocxl_pasid_afu_alloc(struct ocxl_fn
*fn
, u32 size
);
106 void ocxl_pasid_afu_free(struct ocxl_fn
*fn
, u32 start
, u32 size
);
107 int ocxl_actag_afu_alloc(struct ocxl_fn
*fn
, u32 size
);
108 void ocxl_actag_afu_free(struct ocxl_fn
*fn
, u32 start
, u32 size
);
111 * Get the max PASID value that can be used by the function
113 int ocxl_config_get_pasid_info(struct pci_dev
*dev
, int *count
);
116 * Check if an AFU index is valid for the given function.
118 * AFU indexes can be sparse, so a driver should check all indexes up
119 * to the maximum found in the function description
121 int ocxl_config_check_afu_index(struct pci_dev
*dev
,
122 struct ocxl_fn_config
*fn
, int afu_idx
);
125 * Update values within a Process Element
127 * link_handle: the link handle associated with the process element
128 * pasid: the PASID for the AFU context
129 * tid: the new thread id for the process element
131 int ocxl_link_update_pe(void *link_handle
, int pasid
, __u16 tid
);
133 int ocxl_context_mmap(struct ocxl_context
*ctx
,
134 struct vm_area_struct
*vma
);
135 void ocxl_context_detach_all(struct ocxl_afu
*afu
);
137 int ocxl_sysfs_register_afu(struct ocxl_file_info
*info
);
138 void ocxl_sysfs_unregister_afu(struct ocxl_file_info
*info
);
140 int ocxl_irq_offset_to_id(struct ocxl_context
*ctx
, u64 offset
);
141 u64
ocxl_irq_id_to_offset(struct ocxl_context
*ctx
, int irq_id
);
142 void ocxl_afu_irq_free_all(struct ocxl_context
*ctx
);
144 #endif /* _OCXL_INTERNAL_H_ */