1
2
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
17extern struct pci_driver ocxl_pci_driver;
18
19
20struct 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
34struct 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;
42 int pasid_max;
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
55enum ocxl_context_status {
56 CLOSED,
57 OPENED,
58 ATTACHED,
59};
60
61
62struct ocxl_xsl_error {
63 u64 addr;
64 u64 dsisr;
65 u64 count;
66};
67
68struct 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};
81
82struct ocxl_process_element {
83 __be64 config_state;
84 __be32 reserved1[11];
85 __be32 lpid;
86 __be32 tid;
87 __be32 pid;
88 __be32 reserved2[10];
89 __be64 amr;
90 __be32 reserved3[3];
91 __be32 software_state;
92};
93
94
95extern struct ocxl_afu *ocxl_afu_get(struct ocxl_afu *afu);
96extern void ocxl_afu_put(struct ocxl_afu *afu);
97
98extern int ocxl_create_cdev(struct ocxl_afu *afu);
99extern void ocxl_destroy_cdev(struct ocxl_afu *afu);
100extern int ocxl_register_afu(struct ocxl_afu *afu);
101extern void ocxl_unregister_afu(struct ocxl_afu *afu);
102
103extern int ocxl_file_init(void);
104extern void ocxl_file_exit(void);
105
106extern int ocxl_pasid_afu_alloc(struct ocxl_fn *fn, u32 size);
107extern void ocxl_pasid_afu_free(struct ocxl_fn *fn, u32 start, u32 size);
108extern int ocxl_actag_afu_alloc(struct ocxl_fn *fn, u32 size);
109extern void ocxl_actag_afu_free(struct ocxl_fn *fn, u32 start, u32 size);
110
111extern struct ocxl_context *ocxl_context_alloc(void);
112extern int ocxl_context_init(struct ocxl_context *ctx, struct ocxl_afu *afu,
113 struct address_space *mapping);
114extern int ocxl_context_attach(struct ocxl_context *ctx, u64 amr);
115extern int ocxl_context_mmap(struct ocxl_context *ctx,
116 struct vm_area_struct *vma);
117extern int ocxl_context_detach(struct ocxl_context *ctx);
118extern void ocxl_context_detach_all(struct ocxl_afu *afu);
119extern void ocxl_context_free(struct ocxl_context *ctx);
120
121extern int ocxl_sysfs_add_afu(struct ocxl_afu *afu);
122extern void ocxl_sysfs_remove_afu(struct ocxl_afu *afu);
123
124extern int ocxl_afu_irq_alloc(struct ocxl_context *ctx, u64 *irq_offset);
125extern int ocxl_afu_irq_free(struct ocxl_context *ctx, u64 irq_offset);
126extern void ocxl_afu_irq_free_all(struct ocxl_context *ctx);
127extern int ocxl_afu_irq_set_fd(struct ocxl_context *ctx, u64 irq_offset,
128 int eventfd);
129extern u64 ocxl_afu_irq_get_addr(struct ocxl_context *ctx, u64 irq_offset);
130
131#endif
132