hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/include/linux/pci-epc.h
....@@ -53,29 +53,40 @@
5353 phys_addr_t addr);
5454 int (*set_msi)(struct pci_epc *epc, u8 func_no, u8 interrupts);
5555 int (*get_msi)(struct pci_epc *epc, u8 func_no);
56
- int (*set_msix)(struct pci_epc *epc, u8 func_no, u16 interrupts);
56
+ int (*set_msix)(struct pci_epc *epc, u8 func_no, u16 interrupts,
57
+ enum pci_barno, u32 offset);
5758 int (*get_msix)(struct pci_epc *epc, u8 func_no);
5859 int (*raise_irq)(struct pci_epc *epc, u8 func_no,
5960 enum pci_epc_irq_type type, u16 interrupt_num);
6061 int (*start)(struct pci_epc *epc);
6162 void (*stop)(struct pci_epc *epc);
63
+ const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
64
+ u8 func_no);
6265 struct module *owner;
6366 };
6467
6568 /**
69
+ * struct pci_epc_mem_window - address window of the endpoint controller
70
+ * @phys_base: physical base address of the PCI address window
71
+ * @size: the size of the PCI address window
72
+ * @page_size: size of each page
73
+ */
74
+struct pci_epc_mem_window {
75
+ phys_addr_t phys_base;
76
+ size_t size;
77
+ size_t page_size;
78
+};
79
+
80
+/**
6681 * struct pci_epc_mem - address space of the endpoint controller
67
- * @phys_base: physical base address of the PCI address space
68
- * @size: the size of the PCI address space
82
+ * @window: address window of the endpoint controller
6983 * @bitmap: bitmap to manage the PCI address space
7084 * @pages: number of bits representing the address region
71
- * @page_size: size of each page
7285 * @lock: mutex to protect bitmap
7386 */
7487 struct pci_epc_mem {
75
- phys_addr_t phys_base;
76
- size_t size;
88
+ struct pci_epc_mem_window window;
7789 unsigned long *bitmap;
78
- size_t page_size;
7990 int pages;
8091 /* mutex to protect against concurrent access for memory allocation*/
8192 struct mutex lock;
....@@ -86,30 +97,52 @@
8697 * @dev: PCI EPC device
8798 * @pci_epf: list of endpoint functions present in this EPC device
8899 * @ops: function pointers for performing endpoint operations
89
- * @mem: address space of the endpoint controller
100
+ * @windows: array of address space of the endpoint controller
101
+ * @mem: first window of the endpoint controller, which corresponds to
102
+ * default address space of the endpoint controller supporting
103
+ * single window.
104
+ * @num_windows: number of windows supported by device
90105 * @max_functions: max number of functions that can be configured in this EPC
91106 * @group: configfs group representing the PCI EPC device
92
- * @lock: spinlock to protect pci_epc ops
107
+ * @lock: mutex to protect pci_epc ops
108
+ * @function_num_map: bitmap to manage physical function number
109
+ * @notifier: used to notify EPF of any EPC events (like linkup)
93110 */
94111 struct pci_epc {
95112 struct device dev;
96113 struct list_head pci_epf;
97114 const struct pci_epc_ops *ops;
115
+ struct pci_epc_mem **windows;
98116 struct pci_epc_mem *mem;
117
+ unsigned int num_windows;
99118 u8 max_functions;
100119 struct config_group *group;
101
- /* spinlock to protect against concurrent access of EP controller */
102
- spinlock_t lock;
103
- unsigned int features;
120
+ /* mutex to protect against concurrent access of EP controller */
121
+ struct mutex lock;
122
+ unsigned long function_num_map;
123
+ struct atomic_notifier_head notifier;
104124 };
105125
106
-#define EPC_FEATURE_NO_LINKUP_NOTIFIER BIT(0)
107
-#define EPC_FEATURE_BAR_MASK (BIT(1) | BIT(2) | BIT(3))
108
-#define EPC_FEATURE_MSIX_AVAILABLE BIT(4)
109
-#define EPC_FEATURE_SET_BAR(features, bar) \
110
- (features |= (EPC_FEATURE_BAR_MASK & (bar << 1)))
111
-#define EPC_FEATURE_GET_BAR(features) \
112
- ((features & EPC_FEATURE_BAR_MASK) >> 1)
126
+/**
127
+ * struct pci_epc_features - features supported by a EPC device per function
128
+ * @linkup_notifier: indicate if the EPC device can notify EPF driver on link up
129
+ * @msi_capable: indicate if the endpoint function has MSI capability
130
+ * @msix_capable: indicate if the endpoint function has MSI-X capability
131
+ * @reserved_bar: bitmap to indicate reserved BAR unavailable to function driver
132
+ * @bar_fixed_64bit: bitmap to indicate fixed 64bit BARs
133
+ * @bar_fixed_size: Array specifying the size supported by each BAR
134
+ * @align: alignment size required for BAR buffer allocation
135
+ */
136
+struct pci_epc_features {
137
+ unsigned int linkup_notifier : 1;
138
+ unsigned int core_init_notifier : 1;
139
+ unsigned int msi_capable : 1;
140
+ unsigned int msix_capable : 1;
141
+ u8 reserved_bar;
142
+ u8 bar_fixed_64bit;
143
+ u64 bar_fixed_size[PCI_STD_NUM_BARS];
144
+ size_t align;
145
+};
113146
114147 #define to_pci_epc(device) container_of((device), struct pci_epc, dev)
115148
....@@ -117,9 +150,6 @@
117150 __pci_epc_create((dev), (ops), THIS_MODULE)
118151 #define devm_pci_epc_create(dev, ops) \
119152 __devm_pci_epc_create((dev), (ops), THIS_MODULE)
120
-
121
-#define pci_epc_mem_init(epc, phys_addr, size) \
122
- __pci_epc_mem_init((epc), (phys_addr), (size), PAGE_SIZE)
123153
124154 static inline void epc_set_drvdata(struct pci_epc *epc, void *data)
125155 {
....@@ -129,6 +159,12 @@
129159 static inline void *epc_get_drvdata(struct pci_epc *epc)
130160 {
131161 return dev_get_drvdata(&epc->dev);
162
+}
163
+
164
+static inline int
165
+pci_epc_register_notifier(struct pci_epc *epc, struct notifier_block *nb)
166
+{
167
+ return atomic_notifier_chain_register(&epc->notifier, nb);
132168 }
133169
134170 struct pci_epc *
....@@ -141,6 +177,7 @@
141177 void pci_epc_destroy(struct pci_epc *epc);
142178 int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf);
143179 void pci_epc_linkup(struct pci_epc *epc);
180
+void pci_epc_init_notify(struct pci_epc *epc);
144181 void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf);
145182 int pci_epc_write_header(struct pci_epc *epc, u8 func_no,
146183 struct pci_epf_header *hdr);
....@@ -155,17 +192,27 @@
155192 phys_addr_t phys_addr);
156193 int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 interrupts);
157194 int pci_epc_get_msi(struct pci_epc *epc, u8 func_no);
158
-int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts);
195
+int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts,
196
+ enum pci_barno, u32 offset);
159197 int pci_epc_get_msix(struct pci_epc *epc, u8 func_no);
160198 int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no,
161199 enum pci_epc_irq_type type, u16 interrupt_num);
162200 int pci_epc_start(struct pci_epc *epc);
163201 void pci_epc_stop(struct pci_epc *epc);
202
+const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
203
+ u8 func_no);
204
+enum pci_barno
205
+pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features);
206
+enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features
207
+ *epc_features, enum pci_barno bar);
164208 struct pci_epc *pci_epc_get(const char *epc_name);
165209 void pci_epc_put(struct pci_epc *epc);
166210
167
-int __pci_epc_mem_init(struct pci_epc *epc, phys_addr_t phys_addr, size_t size,
168
- size_t page_size);
211
+int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base,
212
+ size_t size, size_t page_size);
213
+int pci_epc_multi_mem_init(struct pci_epc *epc,
214
+ struct pci_epc_mem_window *window,
215
+ unsigned int num_windows);
169216 void pci_epc_mem_exit(struct pci_epc *epc);
170217 void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc,
171218 phys_addr_t *phys_addr, size_t size);